6.Find one or more ways to decrease the time taken to fill the screen with a solid colour. Calculate the execution time of the fastest version of this program that you can create. Challenge: the fastest version is nearly twice as fast as the original version shown above!
Modifying the Code
7. Change the code to fill the display with light blue instead of yellow. (Tip: you can find the colour codes on the 6502 Emulator page).
Changed the color code of the lda#$07 to
- $6: Blue
- lda #$00 ; set a pointer in memory location $40 to point to $0200sta $40 ; ... low byte ($00) goes in address $40lda #$02sta $41 ; ... high byte ($02) goes into address $41lda #$e ; colour number change to blueldy #$00 ; set index to 0loop: sta ($40),y ; set pixel colour at the address (pointer)+Yiny ; increment indexbne loop ; continue until done the page (256 pixels)inc $41 ; increment the pageldx $41 ; get the current page numbercpx #$06 ; compare with 6bne loop ; continue until done all pages
8. Change the code to fill the display with a different colour on each page (each “page” will be one-quarter of the bitmapped display).
sta $40 ; Low byte ($00) goes in address $40
lda #$02 ; High byte ($02) for page $0200
sta $41 ; Store high byte in $41
lda #$02 ; Initial color number
ldy #$00 ; Set index to 0
loop_pixel:
sta ($40),y ; Set pixel color at the address (pointer)+Y
iny ; Increment index
bne loop_pixel ; Continue until done with the page (256 pixels)
inc $41 ; Increment the page
adc #$01 ; Increment the color for the next page
ldx $41 ; Get the current page number
cpx #$06 ; Compare with 6
bne loop_pixel ; Continue until done all pages
9. Make each pixel a random colour. (Hint: use the psudo-random number generator mentioned on the 6502 Emulator page).
- instead of using the fixed colour lda#$07 we use the pseudo random number generator mentioned on the Emulator page, which is lda #$fe
- uses and #$0F to make sure the color stays the previously given code does not need any masking since it uses the fixed color schem.
- More over we put the pseudo-random generator inside of the loop therefore we get all the pixels are different color.
lda #$00 ; Set a pointer in memory location $40 to point to $0200
sta $40 ; Low byte ($00) goes in address $40
lda #$02 ; High byte ($02) for page $0200
sta $41 ; Store high byte in $41
lda #$02 ; Initial color number
ldy #$00 ; Set index to 0
loop_pixel:
sta ($40),y ; Set pixel color at the address (pointer)+Y
iny ; Increment index
bne loop_pixel ; Continue until done with the page (256 pixels)
inc $41 ; Increment the page
adc #$01 ; Increment the color for the next page
ldx $41 ; Get the current page number
cpx #$06 ; Compare with 6
bne loop_pixel ; Continue until done all pages
rts ; Return from the program
In many old-school systems, the color of a pixel is not stored as a full 8-bit number but instead uses only a few bits (for example, 1 bits for 16 colors)
Experiments
Go back to the bitmap code above, and try these experiments:
- Add this instruction after the
loop:
label and before thesta ($40),y
instruction:tya
- What visual effect does this cause, and how many colours are on the screen? Why?
- Add this instruction after the
tya
:lsr
- What visual effect does this cause, and how many colours are on the screen? Why?
However, because the video system only “sees” a limited number of color bits, the raw Y value already produces a repeating pattern of color “stripes” on screen. (In our experiment the unshifted value produces 32 narrow stripes.) When you add one LSR, you shift the bits one place right so that the effective colour value becomes Y÷2
- Repeat the above tests with two, three, four, and five
lsr
instructions in a row. Describe and explain the effect in each case.
When Two lsr instructions : The value in A becomes divided 4 (2^2)
- Repeat the tests using
asl
instructions instead oflsr
instructions. Describe and explain the effect in each case.
Because the A register is 8 bits the result :wraps around" modulo 256 when it gets too high.
- Revert to the original code.
The original code includes oneiny
instruction. Test with one to five consecutiveiny
instructions. Describe and explain the effect in each case. Note: it is helpful to place the Speed slider is on its lowest setting (left) for these experiments.
The values will go on 0, 3, 6... and so on. and since 3 and 256 are relatively prime adding 3 repeatedly will eventually hit every value in the 0-255 range but not in order(scrambled).
No comments:
Post a Comment