From e63b2977db28d496d43c7d75811d85dbd5bcde4e Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 10 Mar 2023 00:28:36 -0500 Subject: [PATCH] sb: urgh Y must be 0 --- games/sb/Makefile | 3 +- games/sb/duck_pond.s | 13 +++- games/sb/gr_copy.s | 161 ++++++++++++++++++++++++++++++++++++++++++ games/sb/gr_offsets.s | 5 ++ games/sb/zp.inc | 22 ++---- games/sb/zx02_optim.s | 35 ++++----- 6 files changed, 204 insertions(+), 35 deletions(-) create mode 100644 games/sb/gr_copy.s create mode 100644 games/sb/gr_offsets.s diff --git a/games/sb/Makefile b/games/sb/Makefile index 29f3ab8b..17943d6b 100644 --- a/games/sb/Makefile +++ b/games/sb/Makefile @@ -32,7 +32,8 @@ DUCK_POND: duck_pond.o ld65 -o DUCK_POND duck_pond.o -C $(LINKER_SCRIPTS)/apple2_1000.inc duck_pond.o: duck_pond.s zx02_optim.s \ - zp.inc hardware.inc + zp.inc hardware.inc \ + gr_copy.s ca65 -o duck_pond.o duck_pond.s -l duck_pond.lst diff --git a/games/sb/duck_pond.s b/games/sb/duck_pond.s index 67c92075..2a8cc6e9 100644 --- a/games/sb/duck_pond.s +++ b/games/sb/duck_pond.s @@ -31,6 +31,9 @@ duck_pond: bit SET_GR bit PAGE0 + lda #$0 + sta DRAW_PAGE + ;=================== ; Load graphics @@ -51,10 +54,12 @@ load_image: lda #>title_data sta ZX0_src+1 - lda #$4 + lda #$C ; load at $c00 jsr full_decomp + jsr gr_copy_to_current + wait_until_keypress: lda KEYPRESS ; 4 @@ -68,10 +73,11 @@ which_ok: lda #>main_data sta ZX0_src+1 - lda #$4 + lda #$C jsr full_decomp + jsr gr_copy_to_current wait_until_keypress2: lda KEYPRESS ; 4 @@ -84,7 +90,8 @@ wait_until_keypress2: .include "zx02_optim.s" - + .include "gr_copy.s" + .include "gr_offsets.s" title_data: .incbin "graphics/a2_duckpond_title.gr.zx02" diff --git a/games/sb/gr_copy.s b/games/sb/gr_copy.s new file mode 100644 index 00000000..a657400b --- /dev/null +++ b/games/sb/gr_copy.s @@ -0,0 +1,161 @@ + ;========================================================= + ; gr_copy_to_current, 40x48 version + ;========================================================= + ; copy 0xc00 to DRAW_PAGE + ; + ; 45 + 2 + 120*(8*9 + 5) -1 + 6 = 9292 +;.align $100 +gr_copy_to_current: + + lda DRAW_PAGE ; 3 + clc ; 2 + adc #$4 ; 2 + sta gr_copy_line+5 ; 4 + sta gr_copy_line+11 ; 4 + adc #$1 ; 2 + sta gr_copy_line+17 ; 4 + sta gr_copy_line+23 ; 4 + adc #$1 ; 2 + sta gr_copy_line+29 ; 4 + sta gr_copy_line+35 ; 4 + adc #$1 ; 2 + sta gr_copy_line+41 ; 4 + sta gr_copy_line+47 ; 4 + ;=========== + ; 45 + + ldy #119 ; for early ones, copy 120 bytes ; 2 + +gr_copy_line: + lda $C00,Y ; load a byte (self modified) ; 4 + sta $400,Y ; store a byte (self modified) ; 5 + + lda $C80,Y ; load a byte (self modified) ; 4 + sta $480,Y ; store a byte (self modified) ; 5 + + lda $D00,Y ; load a byte (self modified) ; 4 + sta $500,Y ; store a byte (self modified) ; 5 + + lda $D80,Y ; load a byte (self modified) ; 4 + sta $580,Y ; store a byte (self modified) ; 5 + + lda $E00,Y ; load a byte (self modified) ; 4 + sta $600,Y ; store a byte (self modified) ; 5 + + lda $E80,Y ; load a byte (self modified) ; 4 + sta $680,Y ; store a byte (self modified) ; 5 + + lda $F00,Y ; load a byte (self modified) ; 4 + sta $700,Y ; store a byte (self modified) ; 5 + + lda $F80,Y ; load a byte (self modified) ; 4 + sta $780,Y ; store a byte (self modified) ; 5 + + dey ; decrement pointer ; 2 + bpl gr_copy_line ; ; 2nt/3 + + rts ; 6 + + + + ;========================================================= + ; gr_copy_to_current, 40x48 version + ;========================================================= + ; copy 0x1000 to DRAW_PAGE + +gr_copy_to_current_1000: + + lda DRAW_PAGE ; 3 + clc ; 2 + adc #$4 ; 2 + sta gr_copy_line_40+5 ; 4 + sta gr_copy_line_40+11 ; 4 + adc #$1 ; 2 + sta gr_copy_line_40+17 ; 4 + sta gr_copy_line_40+23 ; 4 + adc #$1 ; 2 + sta gr_copy_line_40+29 ; 4 + sta gr_copy_line_40+35 ; 4 + adc #$1 ; 2 + sta gr_copy_line_40+41 ; 4 + sta gr_copy_line_40+47 ; 4 + ;=========== + ; 45 + + ldy #119 ; for early ones, copy 120 bytes ; 2 + +gr_copy_line_40: + lda $1000,Y ; load a byte (self modified) ; 4 + sta $400,Y ; store a byte (self modified) ; 5 + + lda $1080,Y ; load a byte (self modified) ; 4 + sta $480,Y ; store a byte (self modified) ; 5 + + lda $1100,Y ; load a byte (self modified) ; 4 + sta $500,Y ; store a byte (self modified) ; 5 + + lda $1180,Y ; load a byte (self modified) ; 4 + sta $580,Y ; store a byte (self modified) ; 5 + + lda $1200,Y ; load a byte (self modified) ; 4 + sta $600,Y ; store a byte (self modified) ; 5 + + lda $1280,Y ; load a byte (self modified) ; 4 + sta $680,Y ; store a byte (self modified) ; 5 + + lda $1300,Y ; load a byte (self modified) ; 4 + sta $700,Y ; store a byte (self modified) ; 5 + + lda $1380,Y ; load a byte (self modified) ; 4 + sta $780,Y ; store a byte (self modified) ; 5 + + dey ; decrement pointer ; 2 + bpl gr_copy_line_40 ; ; 2nt/3 + + rts ; 6 + + + + ;========================================================= + ; gr_copy_to_current_40x40 + ;========================================================= + ; Take image in 0xc00 + ; Copy to DRAW_PAGE + ; Actually copy lines 0..39 + ; Don't over-write bottom 4 lines of text +gr_copy_to_current_40x40: + + ldx #0 +gc_40x40_loop: + lda gr_offsets,x + sta OUTL + sta INL + lda gr_offsets+1,x + clc + adc DRAW_PAGE + sta OUTH + + lda gr_offsets+1,x + clc + adc #$8 + sta INH + + ldy #39 +gc_40x40_inner: + lda (INL),Y + sta (OUTL),Y + + dey + bpl gc_40x40_inner + + inx + inx + + cpx #40 + bne gc_40x40_loop + + rts ; 6 + + + + diff --git a/games/sb/gr_offsets.s b/games/sb/gr_offsets.s new file mode 100644 index 00000000..d3af91f7 --- /dev/null +++ b/games/sb/gr_offsets.s @@ -0,0 +1,5 @@ +gr_offsets: + .word $400,$480,$500,$580,$600,$680,$700,$780 + .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 + .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 + diff --git a/games/sb/zp.inc b/games/sb/zp.inc index 311a38ff..8760309c 100644 --- a/games/sb/zp.inc +++ b/games/sb/zp.inc @@ -1,22 +1,14 @@ ;; Zero Page -FRAMEBUFFER = $00 ; $00 - $0F +;; ZX02 addresses -;; LZ4 addresses +ZP=$00 -FLAME_STATE = $00 -FLAME1 = $01 -FLAME2 = $02 -FLAME3 = $03 -FLAME4 = $04 -FLAME5 = $05 - - -LZ4_SRC = $00 -LZ4_DST = $02 -LZ4_END = $04 -COUNT = $06 -DELTA = $08 +offset = ZP+0 +ZX0_src = ZP+2 +ZX0_dst = ZP+4 +bitr = ZP+6 +pntr = ZP+7 ;; Zero page monitor routines addresses diff --git a/games/sb/zx02_optim.s b/games/sb/zx02_optim.s index 1ef24174..8b88caf8 100644 --- a/games/sb/zx02_optim.s +++ b/games/sb/zx02_optim.s @@ -11,22 +11,22 @@ ; Code under MIT license, see LICENSE file. -ZP=$80 +;ZP=$80 -offset = ZP+0 -ZX0_src = ZP+2 -ZX0_dst = ZP+4 -bitr = ZP+6 -pntr = ZP+7 +;offset = ZP+0 +;ZX0_src = ZP+2 +;ZX0_dst = ZP+4 +;bitr = ZP+6 +;pntr = ZP+7 ; Initial values for offset, source, destination and bitr ;zx0_ini_block: -; .byte $00, $00 +; .byte $00, $00 ; offset ;comp_data: -; .byte $0, $0 +; .byte $0, $0 ; zx0_src ;out_addr: -; .byte $0, $0 -; .byte $80 +; .byte $0, $0 ; zx0_dst +; .byte $80 ; bitr ;-------------------------------------------------- ; Decompress ZX0 data (6502 optimized format) @@ -35,13 +35,16 @@ pntr = ZP+7 full_decomp: sta ZX0_dst+1 - lda #0 - sta ZX0_dst - sta offset - sta offset+1 + ldy #$80 + sty bitr - lda #$80 - sta bitr + ldy #0 ; always on page boundary + sty ZX0_dst + + sty offset + sty offset+1 + + ; Y needs to be 0 here ; Get initialization block ; ldy #7