SPO600 Lab1 (Pt.4) - Challenges
Two challenges regarding 6502 processor instruction will be completed.
Challenge 1 - fill in the screen with one color while the middle four pixel will be filled in with another color.
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 #$07 ; 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 lda #$02 ; second colour number sta $03ef ; set pixel colour to the middle four pixels sta $03f0 sta $040f sta $0410
Challenge 2 - Write a program which draws lines around the edge of the display:
A red line across the top
A green line across the bottom
A blue line across the right side.
A purple line across the left side.
Solution:
;add a purple line accrose left side lda #$00 ; set pointer $0200 to address $40 sta $40 lda #$02 sta $41 lda #$20 sta $42 ldy #$00 ; set index to 0 leftloop: lda $40 clc adc $42 sta $40 lda #$04 ;purple sta ($40),y ldx $40 bne leftloop inc $41 ldx $41 cpx #$06 bne leftloop ;add a blue line across right side lda #$00 ; set pointer $0200 to address $40 sta $40 lda #$02 sta $41 lda #$20 sta $42 ldy #$1f ; set index to 0 rightloop: lda $40 clc adc $42 sta $40 lda #$06 ; blue color sta ($40),y ldx $40 bne rightloop inc $41 ldx $41 cpx #$06 bne rightloop ;add a red line across top ;and a green line across bottom ldy #$00 ; set index to 0 xloop: lda #$02 ; red colour number sta $0200,y ; set pixel colour at the top lda #$05 ; green colour number sta $05e0,y ; set pixel colour at the address $0000 +Y iny ; increment index cpy #$20 bne xloop ; continue until done the page (256 pixels)
The solution first draw line on the left. Then, draw line on the right. Finally, draw line on top and at the bottom.

Comments
Post a Comment