Hello everyone and welcome to my blog.
In previous blog post regarding lab 4 I talked about how our group started working on option 4 - Screen Colour Selector. Last week we managed to understand how to print out the messages, and how to show the color. This week we tried to create subroutines to enable moving with an arrow through lines and call the subroutine that shows the color. With help of some example code and logic provided by our teacher we were able to build screen color selection.
;Option 4;
define CHROUT $ffd2 ; output character to screen
define PLOT $fff0 ; get/set cursor coordinates
define COLOUR $20
define PAGENUM $41 ; needs to be 41...?
define ZEROS $26
define SETFLAG $28 ; checks if the first highlight was initialized
define CURZERO $2A
lda #$00
sta SETFLAG
sta COLOUR
ldy #$00
ldx #$00
fill:
lda COLOUR
ldx #$02
stx PAGENUM
draw:
sta ($40),y ; set pixel
iny ; increment index
bne draw ; continue until done the page
inc PAGENUM ; increment the page
ldx PAGENUM ; get the page
cpx #$06 ; compare with 6
bne draw ; continue until done all pages
ldy #$FF ; y will overflow to start at 0 after initlines runs
initlines:
lda ZEROS
cmp #16 ;check if we've drawn 15 lines
bpl setpos0 ;skip printing again if so
inc ZEROS
iny
print:
lda colours,y
cmp #$00
beq initlines
jsr CHROUT
iny
bne print ;if y = 0, jumps to getkey
setpos0:
lda SETFLAG
cmp #$01
beq getkey
inc SETFLAG
clc ;prepares for PLOT subroutine
ldx #$00
ldy #$00
jsr PLOT
ldy #$00
ldx #$00
jsr highlight
jmp getkey
highlight:
lda CURZERO
cmp COLOUR
bpl reverse ;if null terminators >= current colour, highlight
lda colours,y
jsr CHROUT
iny
cmp #$00 ;if not null terminator, continue writing
bne highlight
inc CURZERO
jmp highlight
reverse:
lda colours,y
cmp #$00
beq inczero
cmp #13
beq h2write ;Checks if next char is carriage return for CHROUT
eor #$80 ;flips whatever character is stored to reverse video
h2write:
jsr CHROUT
iny
jmp reverse
inczero:
inc CURZERO
findraw:
lda CURZERO
cmp #16
bpl endhighlight
lda colours,y
jsr CHROUT
iny
cmp #$00 ;if not null terminator, continue writing
bne findraw
inc CURZERO
jmp findraw
endhighlight:
rts
getkey:
lda $FF
ldx #$00
ldy #$00
stx $FF
cmp #$82 ;down arrow
beq deccolour
cmp #$80 ;up arrow
beq inccolour
jmp getkey
reset:
lda #$00
ldy #$00
ldx #$00
sta CURZERO
jmp fill
deccolour:
ldy COLOUR
iny
cpy #15 ;guard against scrolling too high
beq reset
sty COLOUR
ldy #$00
jmp prephighlight
prephighlight: ;set carry, read PLOT, tya, clc, adc #$50, clc, PLOT
sec
ldy #$00
ldx #$00
clc
jsr PLOT
ldy #$00
ldx #$00
stx CURZERO
jsr highlight
jmp reset
inccolour:
ldy COLOUR
dey
cpy #$FF ;guard against scrolling too low
beq reset
sty COLOUR
ldy #$00
jmp prephighlight
colours:
dcb "B","l","a","c","k",00,13
dcb "W","h","i","t","e",00,13
dcb "R","e","d",00,13
dcb "C","y","a","n",00,13
dcb "P","u","r","p","l","e",00,13
dcb "G","r","e","e","n",00,13
dcb "B","l","u","e",00,13
dcb "Y","e","l","l","o","w",00,13
dcb "O","r","a","n","g","e",00,13
dcb "B","r","o","w","n",00,13
dcb "L","i","g","h","t",32,"r","e","d",00,13
dcb "D","a","r","k",32,"g","r","e","y",00,13
dcb "G","r","e","y",00,13
dcb "L","i","g","h","t",32,"g","r","e","e","n",00,13
dcb "L","i","g","h","t",32,"g","r","e","y",00,13
To sum everything up, overall, I enjoyed working with strings very much, it was challenging but interesting.
In previous blog post regarding lab 4 I talked about how our group started working on option 4 - Screen Colour Selector. Last week we managed to understand how to print out the messages, and how to show the color. This week we tried to create subroutines to enable moving with an arrow through lines and call the subroutine that shows the color. With help of some example code and logic provided by our teacher we were able to build screen color selection.
;Option 4;
define CHROUT $ffd2 ; output character to screen
define PLOT $fff0 ; get/set cursor coordinates
define COLOUR $20
define PAGENUM $41 ; needs to be 41...?
define ZEROS $26
define SETFLAG $28 ; checks if the first highlight was initialized
define CURZERO $2A
lda #$00
sta SETFLAG
sta COLOUR
ldy #$00
ldx #$00
fill:
lda COLOUR
ldx #$02
stx PAGENUM
draw:
sta ($40),y ; set pixel
iny ; increment index
bne draw ; continue until done the page
inc PAGENUM ; increment the page
ldx PAGENUM ; get the page
cpx #$06 ; compare with 6
bne draw ; continue until done all pages
ldy #$FF ; y will overflow to start at 0 after initlines runs
initlines:
lda ZEROS
cmp #16 ;check if we've drawn 15 lines
bpl setpos0 ;skip printing again if so
inc ZEROS
iny
print:
lda colours,y
cmp #$00
beq initlines
jsr CHROUT
iny
bne print ;if y = 0, jumps to getkey
setpos0:
lda SETFLAG
cmp #$01
beq getkey
inc SETFLAG
clc ;prepares for PLOT subroutine
ldx #$00
ldy #$00
jsr PLOT
ldy #$00
ldx #$00
jsr highlight
jmp getkey
highlight:
lda CURZERO
cmp COLOUR
bpl reverse ;if null terminators >= current colour, highlight
lda colours,y
jsr CHROUT
iny
cmp #$00 ;if not null terminator, continue writing
bne highlight
inc CURZERO
jmp highlight
reverse:
lda colours,y
cmp #$00
beq inczero
cmp #13
beq h2write ;Checks if next char is carriage return for CHROUT
eor #$80 ;flips whatever character is stored to reverse video
h2write:
jsr CHROUT
iny
jmp reverse
inczero:
inc CURZERO
findraw:
lda CURZERO
cmp #16
bpl endhighlight
lda colours,y
jsr CHROUT
iny
cmp #$00 ;if not null terminator, continue writing
bne findraw
inc CURZERO
jmp findraw
endhighlight:
rts
getkey:
lda $FF
ldx #$00
ldy #$00
stx $FF
cmp #$82 ;down arrow
beq deccolour
cmp #$80 ;up arrow
beq inccolour
jmp getkey
reset:
lda #$00
ldy #$00
ldx #$00
sta CURZERO
jmp fill
deccolour:
ldy COLOUR
iny
cpy #15 ;guard against scrolling too high
beq reset
sty COLOUR
ldy #$00
jmp prephighlight
prephighlight: ;set carry, read PLOT, tya, clc, adc #$50, clc, PLOT
sec
ldy #$00
ldx #$00
clc
jsr PLOT
ldy #$00
ldx #$00
stx CURZERO
jsr highlight
jmp reset
inccolour:
ldy COLOUR
dey
cpy #$FF ;guard against scrolling too low
beq reset
sty COLOUR
ldy #$00
jmp prephighlight
colours:
dcb "B","l","a","c","k",00,13
dcb "W","h","i","t","e",00,13
dcb "R","e","d",00,13
dcb "C","y","a","n",00,13
dcb "P","u","r","p","l","e",00,13
dcb "G","r","e","e","n",00,13
dcb "B","l","u","e",00,13
dcb "Y","e","l","l","o","w",00,13
dcb "O","r","a","n","g","e",00,13
dcb "B","r","o","w","n",00,13
dcb "L","i","g","h","t",32,"r","e","d",00,13
dcb "D","a","r","k",32,"g","r","e","y",00,13
dcb "G","r","e","y",00,13
dcb "L","i","g","h","t",32,"g","r","e","e","n",00,13
dcb "L","i","g","h","t",32,"g","r","e","y",00,13
To sum everything up, overall, I enjoyed working with strings very much, it was challenging but interesting.
Comments
Post a Comment