we were provided the following code
lda #$00 ; set a pointer at $40 to point to $0200
sta $40
lda #$02
sta $41
lda #$07 ; colour
ldy #$00 ; set index to 0
loop: sta ($40),y ; set pixel
iny ; increment index
bne loop ; continue until done the page
inc $41 ; increment the page
ldx $41 ; get the page
cpx #$06 ; compare with 6
bne loop ; continue until done all pages
This code will Fill the page with the colour Yellow by looping through the each address of a
page and setting it to yellow, and then incriminating the page until the screen is filled.
When we insert the command tya into the code at the start of the loop the screen fills with
strips of colour. This is because that command will transfer the value of y into a, this value
will loop every 16 colours since there are only 16 colour values, and the screen is 32 pixels so
it loops perfectly and lines up. this is also why the colours repeat.
Adding in the lsr command now will shift the bits in the colour to the right, and as such
remove the least significant digit. This results in an effective division by 2 and so the colours
appear twice as thick. Adding more will result in further division and as such further thickening
instead using asl we will multiply by two instead this reduces the unique values which the
colours can be but they remain 1 pixel thick.
Next we will see what happens when we add more iny. This will result in an interesting
change in which the y values skips ahead 5 times each loop. this will miss the esacpe value
and overflow and will continue doing so until the page is filled in an interesting grainy way.
The final experiment which was done in this lab was to see if we could get 4 lines drawn
across the edges of the screen
lda #$00 ; set a pointer at $40 to point to $0200
sta $40
lda #$02
sta $41
lda #$05 ; colour
ldy #$00 ; set index to 0
loopa:
sta ($40),y ; set pixel
iny ; increment index
cpy #$20 ; compare with 32
bne loopa ; continue until done the page
ldy #$00
loops:
CLC
lda #$07
sta ($40),y ; set pixel
TYA
adc #$1f
TAY
lda #$04
sta ($40),y ; set pixel
iny
cpy #$00
bne loops
inc $41 ; increment the page
ldx $41 ; get the page
cpx #$06 ; compare with 6
bne loops ; continue until done all pages
ldy #$E0
lda #$0e
dec $41
loopb:
sta ($40),y ; set pixel
iny ; increment index
cpy #$00 ; compare with 32
bne loopb ; continue until done the page
This code will write 4 lines across the 4 edges of the screen. It does so with 3 loops.
The first loop will loop across the addresses at the top of the screen inserting the colour into
those addresses
the second loop which is also the most involved will insert a pixel into the first address of a
line and then add to the cursor the 31 which brings it to the last pixel of the line, drawing a
different colour and then adding one again to start at the beginning once more. Once it has
gotten to the end of a page it will increment to the next page, resulting in two vertical lines.
lastly now that we are on the last page we can draw the final line at the bottom by starting at
the first pixel on the last line and looping through till the end of the line.
These tree loops result in the three lines being successfully drawn.
No comments:
Post a Comment