pt3: visualizer: optimize inner loop from 50 to 30 cycles (x800)

This commit is contained in:
Vince Weaver 2019-05-16 14:26:43 -04:00
parent 78ddbae171
commit 1a895382f2
2 changed files with 49 additions and 34 deletions

View File

@ -232,16 +232,14 @@ fire_update_done:
;===============================
lda #<fire_framebuffer ; 2
sta FIRE_FB_L ; 3
sta fire_smc_fb+1 ; 5
lda #>fire_framebuffer ; 2
sta FIRE_FB_H ; 3
sta fire_smc_fb+2 ; 5
lda #<(fire_framebuffer+40) ; 2
sta FIRE_FB2_L ; 3
sta fire_smc_fb2+1 ; 5
lda #>(fire_framebuffer+40) ; 2
sta FIRE_FB2_H ; 3
sta fire_smc_fb2+2 ; 5
lda #16 ; 2
sta FIRE_FB_LINE ; 3
@ -255,55 +253,61 @@ fire_fb_copy:
iny ; 2
sty FIRE_FB_LINE ; 3
; Set up output, self-modifying code
lda gr_offsets,Y ; 4+
sta OUTL ; 3
sta fire_smc_outl+1 ; 4
lda gr_offsets+1,Y ; 4+
clc ; 2
adc DRAW_PAGE ; 3
sta OUTH ; 3
sta fire_smc_outl+2 ; 4
; FIXME: below, can we do this better? self-modifying code?
; FIXME: below, can we do this better?
; 50: original code
; 39: move to big lookup table
; 33: move save/restore X outside inner loop
; 30: self-modifying code
ldy #39 ; 2
stx FIRE_X ; 3
fire_fb_copy_loop:
txa ; 2
pha ; 3
; get top byte
lda (FIRE_FB_L),Y ; 5+
tax ; 2
lda fire_colors_low,X ; 4+
pha ; 3
; note, seems backwards, apple II LORES bottom byte is on top
fire_smc_fb2:
lda $1234,Y ; 4+
asl ; 2
asl ; 2
asl ; 2
; get bottom byte
lda (FIRE_FB2_L),Y ; 5+
tax ; 2
pla ; 4
ora fire_colors_high,X ; 4+
sta (OUTL),Y ; store out ; 6
pla ; 4
fire_smc_fb:
ora $1234,Y ; 4+
tax ; 2
lda fire_colors,X ; 4+
fire_smc_outl:
sta $1234,Y ; store out ; 5
dey ; 2
bpl fire_fb_copy_loop ; 2/3
done_fire_fb_copy_loop:
ldx FIRE_X ; 3
; complicated adjustment
clc ; 2
lda FIRE_FB_L ; 3
lda fire_smc_fb+1 ; 4
adc #80 ; 2
sta FIRE_FB_L ; 3
lda FIRE_FB_H ; 3
sta fire_smc_fb+1 ; 5
lda fire_smc_fb+2 ; 4
adc #0 ; 2
sta FIRE_FB_H ; 3
sta fire_smc_fb+2 ; 5
clc ; 2
lda FIRE_FB2_L ; 3
lda fire_smc_fb2+1 ; 4
adc #80 ; 2
sta FIRE_FB2_L ; 3
lda FIRE_FB2_H ; 3
sta fire_smc_fb2+1 ; 5
lda fire_smc_fb2+2 ; 4
adc #0 ; 2
sta FIRE_FB2_H ; 3
sta fire_smc_fb2+2 ; 5
dex ; 2
bne fire_fb_copy ; 2/3
@ -311,10 +315,20 @@ done_fire_fb_copy_loop:
rts ; 6
fire_colors_low: .byte $00,$00,$03,$02,$06,$07,$0E,$0F
fire_colors_high: .byte $00,$00,$30,$20,$60,$70,$E0,$F0
;fire_colors_low: .byte $00,$00,$03,$02,$06,$07,$0E,$0F
;fire_colors_high: .byte $00,$00,$30,$20,$60,$70,$E0,$F0
fire_colors:
; 0 1 2 3 4 5 6 7
; 0 0 3 2 6 7 e f
.byte $00,$00,$03,$02,$06,$07,$0e,$0f ; 0
.byte $00,$00,$03,$02,$06,$07,$0e,$0f ; 0
.byte $30,$30,$33,$32,$36,$37,$3e,$3f ; 3
.byte $20,$20,$23,$22,$26,$27,$2e,$2f ; 2
.byte $60,$60,$63,$62,$66,$67,$6e,$6f ; 6
.byte $70,$70,$73,$72,$76,$77,$7e,$7f ; 7
.byte $e0,$e0,$e3,$e2,$e6,$e7,$ee,$ef ; e
.byte $f0,$f0,$f3,$f2,$f6,$f7,$fe,$ff ; f
; FIXME: just reserve space in our memory map
fire_framebuffer:

View File

@ -126,6 +126,7 @@ FIRE_FB_LINE EQU $A8
FIRE_Q EQU $A9
FIRE_VOLUME EQU $AA
FIRE_Y EQU $AB
FIRE_X EQU $AC
; More zero-page addresses
; we try not to conflict with anything DOS, MONITOR or BASIC related