optimized text screen clear/fill and scrolling on c64

This commit is contained in:
Irmen de Jong 2020-12-06 01:07:57 +01:00
parent 00071d53d5
commit 4b53641e1d
4 changed files with 83 additions and 93 deletions

View File

@ -38,13 +38,13 @@ asmsub clear_screenchars (ubyte char @ A) clobbers(Y) {
; ---- clear the character screen with the given fill character (leaves colors) ; ---- clear the character screen with the given fill character (leaves colors)
; (assumes screen matrix is at the default address) ; (assumes screen matrix is at the default address)
%asm {{ %asm {{
ldy #0 ldy #250
_loop sta c64.Screen,y - sta c64.Screen+250*0-1,y
sta c64.Screen+$0100,y sta c64.Screen+250*1-1,y
sta c64.Screen+$0200,y sta c64.Screen+250*2-1,y
sta c64.Screen+$02e8,y sta c64.Screen+250*3-1,y
iny dey
bne _loop bne -
rts rts
}} }}
} }
@ -53,13 +53,13 @@ asmsub clear_screencolors (ubyte color @ A) clobbers(Y) {
; ---- clear the character screen colors with the given color (leaves characters). ; ---- clear the character screen colors with the given color (leaves characters).
; (assumes color matrix is at the default address) ; (assumes color matrix is at the default address)
%asm {{ %asm {{
ldy #0 ldy #250
_loop sta c64.Colors,y - sta c64.Colors+250*0-1,y
sta c64.Colors+$0100,y sta c64.Colors+250*1-1,y
sta c64.Colors+$0200,y sta c64.Colors+250*2-1,y
sta c64.Colors+$02e8,y sta c64.Colors+250*3-1,y
iny dey
bne _loop bne -
rts rts
}} }}
} }
@ -83,29 +83,31 @@ asmsub scroll_left (ubyte alsocolors @ Pc) clobbers(A, Y) {
%asm {{ %asm {{
stx P8ZP_SCRATCH_REG stx P8ZP_SCRATCH_REG
bcs + bcc _scroll_screen
jmp _scroll_screen
+ ; scroll the color memory + ; scroll the screen and the color memory
ldx #0 ldx #0
ldy #38 ldy #38
- -
.for row=0, row<=24, row+=1 .for row=0, row<=24, row+=1
lda c64.Colors + 40*row + 1,x lda c64.Screen + 40*row + 1,x
sta c64.Colors + 40*row,x sta c64.Screen + 40*row + 0,x
.next lda c64.Colors + 40*row + 1,x
sta c64.Colors + 40*row + 0,x
.next
inx inx
dey dey
bpl - bpl -
rts
_scroll_screen ; scroll the screen memory _scroll_screen ; scroll only the screen memory
ldx #0 ldx #0
ldy #38 ldy #38
- -
.for row=0, row<=24, row+=1 .for row=0, row<=24, row+=1
lda c64.Screen + 40*row + 1,x lda c64.Screen + 40*row + 1,x
sta c64.Screen + 40*row,x sta c64.Screen + 40*row + 0,x
.next .next
inx inx
dey dey
bpl - bpl -
@ -121,26 +123,28 @@ asmsub scroll_right (ubyte alsocolors @ Pc) clobbers(A) {
; Carry flag determines if screen color data must be scrolled too ; Carry flag determines if screen color data must be scrolled too
%asm {{ %asm {{
stx P8ZP_SCRATCH_REG stx P8ZP_SCRATCH_REG
bcs + bcc _scroll_screen
jmp _scroll_screen
+ ; scroll the color memory + ; scroll the screen and the color memory
ldx #38 ldx #38
- -
.for row=0, row<=24, row+=1 .for row=0, row<=24, row+=1
lda c64.Colors + 40*row + 0,x lda c64.Screen + 40*row + 0,x
sta c64.Colors + 40*row + 1,x sta c64.Screen + 40*row + 1,x
.next lda c64.Colors + 40*row + 0,x
sta c64.Colors + 40*row + 1,x
.next
dex dex
bpl - bpl -
rts
_scroll_screen ; scroll the screen memory _scroll_screen ; scroll only the screen memory
ldx #38 ldx #38
- -
.for row=0, row<=24, row+=1 .for row=0, row<=24, row+=1
lda c64.Screen + 40*row + 0,x lda c64.Screen + 40*row + 0,x
sta c64.Screen + 40*row + 1,x sta c64.Screen + 40*row + 1,x
.next .next
dex dex
bpl - bpl -
@ -155,26 +159,28 @@ asmsub scroll_up (ubyte alsocolors @ Pc) clobbers(A) {
; Carry flag determines if screen color data must be scrolled too ; Carry flag determines if screen color data must be scrolled too
%asm {{ %asm {{
stx P8ZP_SCRATCH_REG stx P8ZP_SCRATCH_REG
bcs + bcc _scroll_screen
jmp _scroll_screen
+ ; scroll the color memory + ; scroll the screen and the color memory
ldx #39 ldx #39
- -
.for row=1, row<=24, row+=1 .for row=1, row<=24, row+=1
lda c64.Colors + 40*row,x lda c64.Screen + 40*row,x
sta c64.Colors + 40*(row-1),x sta c64.Screen + 40*(row-1),x
.next lda c64.Colors + 40*row,x
sta c64.Colors + 40*(row-1),x
.next
dex dex
bpl - bpl -
rts
_scroll_screen ; scroll the screen memory _scroll_screen ; scroll only the screen memory
ldx #39 ldx #39
- -
.for row=1, row<=24, row+=1 .for row=1, row<=24, row+=1
lda c64.Screen + 40*row,x lda c64.Screen + 40*row,x
sta c64.Screen + 40*(row-1),x sta c64.Screen + 40*(row-1),x
.next .next
dex dex
bpl - bpl -
@ -189,26 +195,28 @@ asmsub scroll_down (ubyte alsocolors @ Pc) clobbers(A) {
; Carry flag determines if screen color data must be scrolled too ; Carry flag determines if screen color data must be scrolled too
%asm {{ %asm {{
stx P8ZP_SCRATCH_REG stx P8ZP_SCRATCH_REG
bcs + bcc _scroll_screen
jmp _scroll_screen
+ ; scroll the color memory + ; scroll the screen and the color memory
ldx #39 ldx #39
- -
.for row=23, row>=0, row-=1 .for row=23, row>=0, row-=1
lda c64.Colors + 40*row,x lda c64.Colors + 40*row,x
sta c64.Colors + 40*(row+1),x sta c64.Colors + 40*(row+1),x
.next lda c64.Screen + 40*row,x
sta c64.Screen + 40*(row+1),x
.next
dex dex
bpl - bpl -
rts
_scroll_screen ; scroll the screen memory _scroll_screen ; scroll only the screen memory
ldx #39 ldx #39
- -
.for row=23, row>=0, row-=1 .for row=23, row>=0, row-=1
lda c64.Screen + 40*row,x lda c64.Screen + 40*row,x
sta c64.Screen + 40*(row+1),x sta c64.Screen + 40*(row+1),x
.next .next
dex dex
bpl - bpl -

View File

@ -17,7 +17,7 @@ main {
c64.SCROLX &= %11110111 ; 38 column mode c64.SCROLX &= %11110111 ; 38 column mode
c64.set_rasterirq(1) ; enable animation c64.set_rasterirq(40) ; enable animation
ubyte target_height = 10 ubyte target_height = 10
ubyte active_height = 24 ubyte active_height = 24

View File

@ -41,7 +41,7 @@ main {
rect(10, 10, 10, 10, false) rect(10, 10, 10, 10, false)
rect(6, 0, 16, 20, true) rect(6, 0, 16, 20, true)
; test_stack.test() test_stack.test()
sub rect(ubyte x1, ubyte y1, ubyte x2, ubyte y2, ubyte fill) { sub rect(ubyte x1, ubyte y1, ubyte x2, ubyte y2, ubyte fill) {
@ -140,21 +140,17 @@ main {
ubyte xx ubyte xx
while x>=y { while x>=y {
for xx in cx to cx+x { xx = cx-x
txt.setcc(xx, cy + y as ubyte, 81, 1) repeat 2*x+1 {
txt.setcc(xx, cy - y as ubyte, 81, 2) txt.setcc(xx, cy + y as ubyte, 81, 11)
txt.setcc(xx, cy - y as ubyte, 81, 12)
xx++
} }
for xx in cx-x to cx-1 { xx = cx-y
txt.setcc(xx, cy + y as ubyte, 81, 3) repeat 2*y+1 {
txt.setcc(xx, cy - y as ubyte, 81, 4) txt.setcc(xx, cy + x as ubyte, 81, 13)
} txt.setcc(xx, cy - x as ubyte, 81, 14)
for xx in cx to cx+y { xx++
txt.setcc(xx, cy + x as ubyte, 81, 5)
txt.setcc(xx, cy - x as ubyte, 81, 6)
}
for xx in cx-y to cx {
txt.setcc(xx, cy + x as ubyte, 81, 7)
txt.setcc(xx, cy - x as ubyte, 81, 8)
} }
y++ y++
if decisionOver2<=0 if decisionOver2<=0

View File

@ -7,27 +7,13 @@ main {
sub start() { sub start() {
txt.fill_screen('.',2) txt.fill_screen('.',2)
ubyte xx
ubyte yy = 0
for xx in 0 to txt.DEFAULT_WIDTH-1 {
txt.setcc(xx, 0, xx, 1)
txt.setcc(xx, txt.DEFAULT_HEIGHT-1, xx, 1)
}
for yy in 0 to txt.DEFAULT_HEIGHT-1 {
txt.setcc(0, yy, yy,1)
txt.setcc(txt.DEFAULT_WIDTH-1, yy, yy, 1)
}
repeat { repeat {
delay()
txt.scroll_left(false)
} }
} }
sub delay () { sub delay () {
ubyte tt ubyte tt
repeat 255 { repeat 55 {
repeat 255 { repeat 255 {
tt++ tt++
} }