Lab 1 - Modifying Code

 7. Change the code to fill the display with light blue instead of yellow.


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 #$06	; colour changes to blue from yellow
 	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


 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).


This program fills the screen with alternating colors using indexed addressing and loops. It begins by setting up a pointer at $40-$41 to start at the memory location $0200 and storing four color codes in addresses $42-$45. A second pointer, $46-$47, is used to reference the current color.

In the Colorloop, the code fetches the current color using the $46-$47 pointer and writes it to the screen at the location specified by $40-$41 + Y. The Y register increments to move to the next pixel on the current page. Once a page (256 pixels) is complete, the high byte of the pointer ($41) is incremented to move to the next page, while $46 updates to the next color code, creating a cycling color effect. The loop continues until all six pages are filled, efficiently alternating colors across the screen.


lda #$00        ; Load low byte of the address $0200 into the accumulator
sta $40         ; Store low byte ($00) in memory address $40
lda #$02        ; Load high byte of the address $0200 into the accumulator
sta $41         ; Store high byte ($02) in memory address $41
lda #$e         ; Load light blue color code (#$e) into the accumulator
sta $42         ; Store light blue color code in memory address $42
lda #$2         ; Load red color code (#$2) into the accumulator
sta $43         ; Store red color code in memory address $43
lda #$5         ; Load green color code (#$5) into the accumulator
sta $44         ; Store green color code in memory address $44
lda #$7         ; Load yellow color code (#$7) into the accumulator
sta $45         ; Store yellow color code in memory address $45
lda #$42        ; Load the high byte of the color pointer into the accumulator
sta $46         ; Store the high byte in memory address $46
lda #$00        ; Load the low byte of the color pointer into the accumulator
sta $47         ; Store the low byte in memory address $47
ldy #$00        ; Initialize the index register Y to 0

Colorloop:
lda ($46),y     ; Load the current color code using the pointer at $46-$47, offset by Y

loop:
sta ($40),y     ; Store the color code at the current pixel address (pointer $40-$41 + Y)
iny             ; Increment the index register Y
bne loop        ; If Y hasn’t overflowed, continue the loop for the current page
inc $46         ; Increment the color pointer (move to the next color)
inc $41         ; Increment the page number (high byte of the address pointer)
ldx $41         ; Load the current page number into the index register X
cpx #$06        ; Compare the current page number with 6 (stop condition)
bne Colorloop   ; If not done with all pages, repeat the color loop



9. Make each pixel a random colour. (Hint: use the psudo-random number generator mentioned on the 6502 Emulator page).

lda #$00        ; Load the low byte of the address $0200 into the accumulator
sta $40         ; Store the low byte ($00) in memory address $40
lda #$02        ; Load the high byte of the address $0200 into the accumulator
sta $41         ; Store the high byte ($02) in memory address $41

ldy #$00        ; Initialize the index register Y to 0
loop:
lda $fe         ; Fetch a random color number from the PRNG at memory address $fe
sta ($40),y     ; Store the fetched color at the current pixel address (pointer $40-$41 + Y)
iny             ; Increment the index register Y
bne loop        ; If Y hasn’t overflowed, continue setting pixels for the current page
inc $41         ; Increment the page number (high byte of the address pointer)
ldx $41         ; Load the current page number into the index register X
cpx #$06        ; Compare the current page number with 6 (stop condition)
bne loop        ; If not done with all pages, repeat the loop for the next page
This code was designed to efficiently fill the screen with random colors on a 6502 processor. First, the pointer at $40-$41 is set to start at the screen's memory address, $0200. A random color is fetched from the pseudo-random number generator at $fe and stored at the current pixel's address. The Y register is used to navigate through each page of 256 pixels, looping until the page is complete. Once a page is filled, the high byte of the pointer ($41) is updated to move to the next page. This process continues for all six pages, ensuring the entire screen is filled with random colors. It’s a simple yet efficient approach that leverages the PRNG and structured looping for dynamic results.

Comments

Popular posts from this blog

Project Stage 1

Lab 2 - Lab Results

Lab 5 - Part 1 - Aarch 64