improved scroll_down and scroll_up to use VERA dual data ports instead of a copybuffer

This commit is contained in:
Irmen de Jong 2020-09-22 00:18:00 +02:00
parent 8d82fb6d8f
commit ffa38955d6
2 changed files with 73 additions and 111 deletions

View File

@ -251,100 +251,49 @@ asmsub scroll_up (ubyte dummy @ Pc) clobbers(A, Y) {
; ---- scroll the whole screen 1 character up ; ---- scroll the whole screen 1 character up
; contents of the bottom row are unchanged, you should refill/clear this yourself ; contents of the bottom row are unchanged, you should refill/clear this yourself
; Carry flag is a dummy on the cx16 ; Carry flag is a dummy on the cx16
; TODO use the VERA dual data port
%asm {{ %asm {{
phx phx
jsr c64.SCREEN jsr c64.SCREEN
txa stx _nextline+1
lsr a
lsr a
dea
sta P8ZP_SCRATCH_REG ; number of columns / 4 due to loop unroll
dey dey
sty P8ZP_SCRATCH_B1 ; number of lines to scroll up sty P8ZP_SCRATCH_B1
stz cx16.VERA_CTRL stz cx16.VERA_CTRL ; data port 0 is source
lda #1
sta cx16.VERA_ADDR_M ; start at second line
stz cx16.VERA_ADDR_L
lda #%00010000 lda #%00010000
sta cx16.VERA_ADDR_H ; enable auto increment by 1, bank 0. sta cx16.VERA_ADDR_H ; enable auto increment by 1, bank 0.
lda #1
sta cx16.VERA_ADDR_M ; start at (0, 1)
- jsr _copy_line_to_buffer lda #1
; now copy the linebuffer back to the line above this one sta cx16.VERA_CTRL ; data port 1 is destination
dec cx16.VERA_ADDR_M stz cx16.VERA_ADDR_M ; start at top line
jsr _copy_buffer_to_line stz cx16.VERA_ADDR_L
; next line to copy lda #%00010000
inc cx16.VERA_ADDR_M sta cx16.VERA_ADDR_H ; enable auto increment by 1, bank 0.
inc cx16.VERA_ADDR_M
dec P8ZP_SCRATCH_B1 _nextline
ldx #80 ; modified
- lda cx16.VERA_DATA0
sta cx16.VERA_DATA1 ; copy char
lda cx16.VERA_DATA0
sta cx16.VERA_DATA1 ; copy color
dex
bne - bne -
dec P8ZP_SCRATCH_B1
beq +
stz cx16.VERA_CTRL ; data port 0
stz cx16.VERA_ADDR_L
inc cx16.VERA_ADDR_M
lda #1
sta cx16.VERA_CTRL ; data port 1
stz cx16.VERA_ADDR_L
inc cx16.VERA_ADDR_M
bra _nextline
+ lda #0
sta cx16.VERA_CTRL
plx plx
rts rts
_copy_line_to_buffer:
ldy #0
stz cx16.VERA_ADDR_L
ldx P8ZP_SCRATCH_REG
- lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
lda cx16.VERA_DATA0
sta _scrollbuffer,y
iny
dex
bpl -
rts
_copy_buffer_to_line
ldy #0
stz cx16.VERA_ADDR_L
ldx P8ZP_SCRATCH_REG
- lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
lda _scrollbuffer,y
sta cx16.VERA_DATA0
iny
dex
bpl -
rts
_scrollbuffer .fill 160, 0
}} }}
} }
@ -352,32 +301,48 @@ asmsub scroll_down (ubyte dummy @ Pc) clobbers(A, Y) {
; ---- scroll the whole screen 1 character down ; ---- scroll the whole screen 1 character down
; contents of the top row are unchanged, you should refill/clear this yourself ; contents of the top row are unchanged, you should refill/clear this yourself
; Carry flag is a dummy on the cx16 ; Carry flag is a dummy on the cx16
; TODO use the VERA dual data port
%asm {{ %asm {{
phx phx
jsr c64.SCREEN jsr c64.SCREEN
txa stx _nextline+1
lsr a
lsr a
dea
sta P8ZP_SCRATCH_REG ; number of columns / 4 due to loop unroll
dey dey
sty P8ZP_SCRATCH_B1 ; number of lines to scroll up sty P8ZP_SCRATCH_B1
stz cx16.VERA_CTRL ; data port 0 is source
dey dey
stz cx16.VERA_CTRL
sty cx16.VERA_ADDR_M ; start at line before bottom line sty cx16.VERA_ADDR_M ; start at line before bottom line
stz cx16.VERA_ADDR_L
lda #%00010000 lda #%00010000
sta cx16.VERA_ADDR_H ; enable auto increment by 1, bank 0. sta cx16.VERA_ADDR_H ; enable auto increment by 1, bank 0.
- jsr scroll_up._copy_line_to_buffer lda #1
; now copy the linebuffer back to the line below this one sta cx16.VERA_CTRL ; data port 1 is destination
inc cx16.VERA_ADDR_M iny
jsr scroll_up._copy_buffer_to_line sty cx16.VERA_ADDR_M ; start at bottom line
; next line to copy stz cx16.VERA_ADDR_L
dec cx16.VERA_ADDR_M lda #%00010000
dec cx16.VERA_ADDR_M sta cx16.VERA_ADDR_H ; enable auto increment by 1, bank 0.
dec P8ZP_SCRATCH_B1
_nextline
ldx #80 ; modified
- lda cx16.VERA_DATA0
sta cx16.VERA_DATA1 ; copy char
lda cx16.VERA_DATA0
sta cx16.VERA_DATA1 ; copy color
dex
bne - bne -
dec P8ZP_SCRATCH_B1
beq +
stz cx16.VERA_CTRL ; data port 0
stz cx16.VERA_ADDR_L
dec cx16.VERA_ADDR_M
lda #1
sta cx16.VERA_CTRL ; data port 1
stz cx16.VERA_ADDR_L
dec cx16.VERA_ADDR_M
bra _nextline
+ lda #0
sta cx16.VERA_CTRL
plx plx
rts rts
}} }}

View File

@ -8,24 +8,21 @@ main {
sub start() { sub start() {
cx16.screen_set_mode(128) ; cx16.screen_set_mode(128)
ubyte width = txt.width() ubyte width = txt.width()
ubyte height = txt.height() ubyte height = txt.height()
ubyte x ubyte x
ubyte y
for y in 0 to height-1 {
for x in 0 to width-1 {
txt.setchr(x,y,x+y)
}
}
repeat width { repeat 999 {
txt.setcc(0, rnd() % height, 81, 2) ubyte xpos = rnd() % (width-1)
txt.scroll_right(true) txt.setcc(xpos, 0, 81, 6)
ubyte ypos = rnd() % (height-1)+1
repeat 1000 { txt.setcc(width-1, ypos, 81, 2)
txt.scroll_left(true)
txt.scroll_down(true)
repeat 2000 {
x++ x++
} }
} }