mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-02-12 23:31:43 +00:00
hgr: oval: more optimization
This commit is contained in:
parent
ccdae6d1fb
commit
9c6e0cb5ce
@ -1,5 +1,10 @@
|
|||||||
; Ovals
|
; Ovals
|
||||||
|
|
||||||
|
|
||||||
|
; inner loop after lots of ops = 49 cycles (376320) = 2.6fps
|
||||||
|
; optimized to 38 (256-entry sine table) = (291840) = 3.4fps
|
||||||
|
; optimized to 37 (row_sum smc) = (284160) = 3.5fps
|
||||||
|
|
||||||
; zero page
|
; zero page
|
||||||
GBASL = $26
|
GBASL = $26
|
||||||
GBASH = $27
|
GBASH = $27
|
||||||
@ -33,6 +38,76 @@ oval:
|
|||||||
|
|
||||||
jsr HGR2 ; set hi-res 140x192, page2, fullscreen
|
jsr HGR2 ; set hi-res 140x192, page2, fullscreen
|
||||||
|
|
||||||
|
;====================
|
||||||
|
; create sinetable
|
||||||
|
|
||||||
|
.if 0
|
||||||
|
ldy #0
|
||||||
|
sinetable_loop:
|
||||||
|
tya ; 2
|
||||||
|
and #$3f ; wrap sine at 63 entries ; 2
|
||||||
|
|
||||||
|
tax ; 2
|
||||||
|
cmp #$20 ; see if negative ; 2
|
||||||
|
bcc sin_pos ; 2/3
|
||||||
|
|
||||||
|
sin_neg:
|
||||||
|
lda #0 ; 2
|
||||||
|
sbc sinetable_base-32,X ; 4+
|
||||||
|
jmp sin_done ; 3
|
||||||
|
|
||||||
|
sin_pos:
|
||||||
|
; carry already clear
|
||||||
|
lda sinetable_base,X ; 4+
|
||||||
|
|
||||||
|
sin_done:
|
||||||
|
sta sinetable,Y
|
||||||
|
iny
|
||||||
|
bne sinetable_loop
|
||||||
|
.endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ldy #0
|
||||||
|
sinetable_loop:
|
||||||
|
tya ; 2
|
||||||
|
and #$3f ; wrap sine at 63 entries ; 2
|
||||||
|
|
||||||
|
cmp #$20
|
||||||
|
php
|
||||||
|
|
||||||
|
and #$1f
|
||||||
|
|
||||||
|
cmp #$10
|
||||||
|
bcc sin_blah
|
||||||
|
|
||||||
|
sin_right:
|
||||||
|
sec
|
||||||
|
eor #$FF
|
||||||
|
adc #$20 ; 32-X
|
||||||
|
sin_blah:
|
||||||
|
tax
|
||||||
|
lda sinetable_base,X ; 4+
|
||||||
|
|
||||||
|
plp
|
||||||
|
bcc sin_done
|
||||||
|
|
||||||
|
sin_negate:
|
||||||
|
clc
|
||||||
|
eor #$ff
|
||||||
|
adc #1
|
||||||
|
|
||||||
|
sin_done:
|
||||||
|
sta sinetable,Y
|
||||||
|
iny
|
||||||
|
bne sinetable_loop
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;============================
|
||||||
|
; main loop
|
||||||
|
;============================
|
||||||
|
|
||||||
draw_oval:
|
draw_oval:
|
||||||
inc FRAME
|
inc FRAME
|
||||||
|
|
||||||
@ -50,91 +125,73 @@ create_yloop:
|
|||||||
|
|
||||||
ldy #39 ; XX
|
ldy #39 ; XX
|
||||||
|
|
||||||
lda FRAME
|
|
||||||
sta SUM
|
|
||||||
|
|
||||||
lda HGR_Y ; YY
|
lda HGR_Y ; YY
|
||||||
jsr calcsine_div2
|
|
||||||
|
calcsine_div2:
|
||||||
|
lsr ; 2
|
||||||
|
tax
|
||||||
|
clc
|
||||||
|
lda sinetable,X
|
||||||
|
adc FRAME
|
||||||
|
sta row_sum_smc+1
|
||||||
|
|
||||||
ldx HGR_Y ; YY
|
ldx HGR_Y ; YY
|
||||||
|
|
||||||
sta ROW_SUM
|
|
||||||
create_xloop:
|
create_xloop:
|
||||||
lda ROW_SUM
|
|
||||||
sta SUM
|
|
||||||
|
|
||||||
tya ; XX
|
;=====================
|
||||||
jsr calcsine
|
; critical inner loop
|
||||||
|
; every cycle here is 40x192 cycles
|
||||||
|
;=====================
|
||||||
|
|
||||||
lsr ; double colors
|
lda sinetable,Y ; 4+
|
||||||
and #$7 ; mask
|
clc ; 2
|
||||||
tax
|
row_sum_smc:
|
||||||
lda colorlookup,X
|
adc #$dd ; row base value ; 2
|
||||||
sta SAVEY
|
|
||||||
|
|
||||||
tya
|
lsr ; double colors ; 2
|
||||||
ror
|
and #$7 ; mask ; 2
|
||||||
bcc noshift
|
tax ; 2
|
||||||
ror SAVEY
|
lda colorlookup,X ; lookup in table ; 5
|
||||||
noshift:
|
|
||||||
lda SAVEY
|
|
||||||
; and #$7f
|
|
||||||
sta (GBASL),Y
|
|
||||||
|
|
||||||
dey
|
ror_nop_smc:
|
||||||
bpl create_xloop
|
ror ; $6A/$EA ; 2
|
||||||
|
; and #$7f ; make all purple
|
||||||
|
sta (GBASL),Y ; 6
|
||||||
|
|
||||||
|
lda ror_nop_smc ; toggle ror/nop ; 4
|
||||||
|
eor #$80 ; 2
|
||||||
|
sta ror_nop_smc ; 4
|
||||||
|
|
||||||
|
dey ; 2
|
||||||
|
bpl create_xloop ; 2/3
|
||||||
|
|
||||||
dec HGR_Y
|
dec HGR_Y
|
||||||
bne create_yloop
|
bne create_yloop
|
||||||
|
|
||||||
; X and Y both $FF
|
; we skip drawing line 0 as it makes it easier
|
||||||
|
|
||||||
beq draw_oval
|
beq draw_oval
|
||||||
|
|
||||||
|
|
||||||
;==============================
|
|
||||||
; calcsine
|
|
||||||
;==============================
|
|
||||||
; looks up sine of value in A
|
|
||||||
; accumulates it with SUM
|
|
||||||
; returns result in A
|
|
||||||
; Y preserved
|
|
||||||
|
|
||||||
calcsine_div2:
|
|
||||||
lsr ; 2
|
|
||||||
calcsine:
|
|
||||||
and #$3f ; wrap sine at 63 entries ; 2
|
|
||||||
|
|
||||||
tax ; 2
|
|
||||||
rol ; 2
|
|
||||||
rol ; 2
|
|
||||||
rol ; 2
|
|
||||||
bcc sinadd ; 2/3
|
|
||||||
|
|
||||||
sinsub:
|
|
||||||
lda SUM ; 3
|
|
||||||
; sec
|
|
||||||
sbc sinetable-32,X ; 4+
|
|
||||||
jmp sindone ; 3
|
|
||||||
|
|
||||||
sinadd:
|
|
||||||
lda SUM ; 3
|
|
||||||
; clc
|
|
||||||
adc sinetable,X ; 4+
|
|
||||||
|
|
||||||
sindone:
|
|
||||||
rts ; 6
|
|
||||||
|
|
||||||
|
|
||||||
colorlookup:
|
colorlookup:
|
||||||
|
|
||||||
.byte $11,$55,$5d,$7f,$5d,$55,$11 ; use 00 from sinetable
|
.byte $11,$55,$5d,$7f,$5d,$55,$11 ; use 00 from sinetable
|
||||||
;.byte $00
|
;.byte $00
|
||||||
|
|
||||||
sinetable:
|
sinetable_base:
|
||||||
; this is actually (32*sin(x))
|
; this is actually (32*sin(x))
|
||||||
|
|
||||||
.byte $00,$03,$06,$09,$0C,$0F,$11,$14
|
.byte $00,$03,$06,$09,$0C,$0F,$11,$14
|
||||||
.byte $16,$18,$1A,$1C,$1D,$1E,$1F,$1F
|
.byte $16,$18,$1A,$1C,$1D,$1E,$1F,$1F
|
||||||
.byte $20,$1F,$1F,$1E,$1D,$1C,$1A,$18
|
.byte $20
|
||||||
.byte $16,$14,$11,$0F,$0C,$09,$06,$03
|
;,$1F,$1F,$1E,$1D,$1C,$1A,$18
|
||||||
|
;.byte $16,$14,$11,$0F,$0C,$09,$06,$03
|
||||||
|
|
||||||
|
|
||||||
|
; for bot
|
||||||
|
|
||||||
|
jmp oval
|
||||||
|
|
||||||
|
sinetable=$6000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user