bubble: size optimize a bit, under 2k now

This commit is contained in:
Vince Weaver 2024-03-01 14:49:34 -05:00
parent 6ce85e34ca
commit a021e824b3
3 changed files with 150 additions and 2 deletions

View File

@ -39,7 +39,7 @@ bubble.o: bubble.s hgr_clear_part.s sin_unrolled.s
BUBBLE_TINY: bubble_tiny.o
ld65 -o BUBBLE_TINY bubble_tiny.o -C $(LINKER_SCRIPTS)/apple2_c00.inc
bubble_tiny.o: bubble_tiny.s hgr_clear_part.s sin_unrolled.s
bubble_tiny.o: bubble_tiny.s hgr_clear_part.s sin_unrolled.s hgr_clear_codegen.s
ca65 -o bubble_tiny.o bubble_tiny.s -l bubble_tiny.lst
###

View File

@ -15,6 +15,7 @@
; 2560 bytes -- full version with keypress to adjust
; 2326 bytes -- alignment turned off
; 2311 bytes -- optimize mod table generation
; 1447 bytes -- first attempt at hgr_clear codegen
; soft-switches
@ -49,6 +50,11 @@ V = $D9
HGR_PAGE = $E6
INL = $FC
INH = $FD
OUTL = $FE
OUTH = $FF
; const
;NUM = 32
@ -61,6 +67,8 @@ bubble:
jsr hgr_make_tables
jsr hgr_clear_codegen
;=======================
; init graphics
@ -90,7 +98,20 @@ next_frame:
; "fast" clear screen
.include "hgr_clear_part.s"
;.include "hgr_clear_part.s"
lda #0 ; color
ldy HGR_PAGE
cpy #$40
beq do_clear_page2
do_clear_page1: ; replace with jump table?
jsr hgr_page1_clearscreen
jmp done_clear_page
do_clear_page2:
jsr hgr_page2_clearscreen
done_clear_page:
; reset I*T
@ -366,6 +387,9 @@ log_lookup:
; floor(s*sin((x-96)*PI*2/256.0)+48.5);
.include "hgr_clear_codegen.s"
.align $100
sines:
.byte $13,$12,$12,$11,$10,$10,$0F,$0E,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0B

View File

@ -0,0 +1,124 @@
hgr_page1_clearscreen = $7000
hgr_page2_clearscreen = $7300
hgr_clear_codegen:
;========================
; set up output pointers
lda #<(hgr_page1_clearscreen)
sta OUTL
sta INL
lda #>(hgr_page1_clearscreen)
sta OUTH
lda #>(hgr_page2_clearscreen)
sta INH
;=====================
; set up prolog
lda #$A0 ; ldy
jsr write_both
lda #8 ; only part of screen
jsr write_both
ldx #0
hgr_clear_codegen_loop:
lda #$99 ; STA
jsr write_both
lda hposn_low,X
jsr write_both
lda hposn_high,X
ora #$20
pha
jsr write_p1
pla
eor #$60
jsr write_p2
inx
cpx #192
bne hgr_clear_codegen_loop
;======================================
; write epilog
; TODO: replace with memcpy of some sort?
lda #$C8 ; INY
jsr write_both
lda #$C0 ; CPY
jsr write_both
lda #32 ; end value
jsr write_both
lda #$F0 ; beq
jsr write_both
lda #$03 ; +3
jsr write_both
lda #$4C ; JMP
jsr write_both
lda #<(hgr_page1_clearscreen+2)
jsr write_both
lda #>(hgr_page1_clearscreen+2)
jsr write_p1
lda #>(hgr_page2_clearscreen+2)
jsr write_p2
lda #$60 ; RTS
jsr write_both
rts ; tail call
;=============================
;
write_both:
pha
jsr write_p2
pla
; fallthrough
write_p1:
ldy #0
sta (OUTL),Y
clc
lda OUTL
adc #1
sta OUTL
lda #0
adc OUTH
sta OUTH
rts
write_p2:
ldy #0
sta (INL),Y
clc
lda INL
adc #1
sta INL
lda #0
adc INH
sta INH
rts