SPO600 Lab1 (Pt.2) - Modifying the code
In this part, I have to revise the code to fulfill the task.
task 1: Change the code to fill the display with light blue instead of yellow.
Solution:
lda #$00 ; set a pointer in memory location $40 to point to $0200 sta $40 ; ... low byte ($00) goes in address $40 lda #$02 sta $41 ; ... high byte ($02) goes into address $41 lda #$e ; colour number ldy #$00 ; set index to 0 loop: sta ($40),y ; set pixel colour at the address (pointer)+Y iny ; increment index bne loop ; continue until done the page (256 pixels) inc $41 ; increment the page ldx $41 ; get the current page number cpx #$06 ; compare with 6 bne loop ; continue until done all pages
task 2. Change the code to fill the display with a different colour on each page
The idea of my solution is to store the selected color code in four consecutive memory. Then, use a pointer to reach those color code. Of course, another way to do this is to load the color code to the Accumulate manually and jump to the loop for 4 times. But, I like to set the color at the beginner more since I feel like the program is more readable this way.
Solution:
lda #$00 ; set a pointer in memory location $40 to point to $0200 sta $40 ; ... low byte ($00) goes in address $40 lda #$02 sta $41 ; ... high byte ($02) goes into address $41 lda #$e ;light blue color sta $42 ; #$e goes into address $42 lda #$2 ;red color sta $43 ; #$2 goes into address $43 lda #$5 ;Green color sta $44 ; #$5 goes into address $44 lda #$7 ;Yellow color sta $45 ; #$7 goes into address $45 lda #$42 ; set a pointer of the color code in memory location $46 to $47 sta $46; lda #$00; sta $47; ldy #$00 ; set index to 0 Colorloop: lda ($46),y ; get colour code thru the pointer, y is zero loop: sta ($40),y ; set pixel colour at the address (pointer)+Y iny ; increment index bne loop ; continue until done the page (256 pixels) inc $46 ; increment the color pointer inc $41 ; increment the page ldx $41 ; get the current page number cpx #$06 ; compare with 6 bne Colorloop ; continue until done all pages
task 3. Make each pixel a random colour.
We can get a random bit with the one-byte pseudo-random number generator (PRNG) at $fe and assign it to a pixel. Repeat it till the entire bitmapped display is filled.
Solution:
lda #$00 ; set a pointer in memory location $40 to point to $0200 sta $40 ; ... low byte ($00) goes in address $40 lda #$02 sta $41 ; ... high byte ($02) goes into address $41 ldy #$00 ; set index to 0 loop: lda $fe ; get from colour number PRNG sta ($40),y ; set pixel colour at the address (pointer)+Y iny ; increment index bne loop ; continue until done the page (256 pixels) inc $41 ; increment the page ldx $41 ; get the current page number cpx #$06 ; compare with 6 bne loop ; continue until done all pages
Comments
Post a Comment