dos33fsprogs/graphics/hgr/plasma/oval.s

173 lines
2.6 KiB
ArmAsm
Raw Normal View History

2021-10-25 18:10:44 +00:00
; Ovals
2021-10-25 19:47:41 +00:00
; 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
2021-10-25 18:10:44 +00:00
; zero page
GBASL = $26
GBASH = $27
YY = $69
ROW_SUM = $70
HGR_X = $E0
HGR_XH = $E1
HGR_Y = $E2
HGR_COLOR = $E4
HGR_PAGE = $E6
FRAME = $FC
SUM = $FD
SAVEX = $FE
SAVEY = $FF
; soft-switches
FULLGR = $C052
PAGE1 = $C054
; ROM routines
HGR2 = $F3D8
HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y)
;================================
; Clear screen and setup graphics
;================================
oval:
jsr HGR2 ; set hi-res 140x192, page2, fullscreen
2021-10-25 19:47:41 +00:00
;====================
; create sinetable
ldy #0
sinetable_loop:
tya ; 2
and #$3f ; wrap sine at 63 entries ; 2
cmp #$20
2021-10-25 20:58:31 +00:00
php ; save pos/negative for later
2021-10-25 19:47:41 +00:00
and #$1f
cmp #$10
2021-10-25 20:58:31 +00:00
bcc sin_left
2021-10-25 19:47:41 +00:00
sin_right:
2021-10-25 20:58:31 +00:00
; sec carry should be set?
2021-10-25 19:47:41 +00:00
eor #$FF
adc #$20 ; 32-X
2021-10-25 20:58:31 +00:00
sin_left:
2021-10-25 19:47:41 +00:00
tax
lda sinetable_base,X ; 4+
plp
bcc sin_done
sin_negate:
2021-10-25 20:58:31 +00:00
; carry set here
2021-10-25 19:47:41 +00:00
eor #$ff
2021-10-25 20:58:31 +00:00
adc #0
2021-10-25 19:47:41 +00:00
sin_done:
sta sinetable,Y
2021-10-25 20:58:31 +00:00
2021-10-25 19:47:41 +00:00
iny
bne sinetable_loop
2021-10-25 20:58:31 +00:00
; NOTE: making gbash/gbasl table wasn't worth it
2021-10-25 19:47:41 +00:00
;============================
; main loop
;============================
2021-10-25 18:10:44 +00:00
draw_oval:
inc FRAME
ldx #191 ; YY
stx HGR_Y
create_yloop:
lda HGR_Y
2021-10-25 20:58:31 +00:00
; ldx #39 ; X is don't care?
2021-10-25 18:10:44 +00:00
ldy #0
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
; restore values
ldy #39 ; XX
lda HGR_Y ; YY
2021-10-25 19:47:41 +00:00
calcsine_div2:
lsr ; 2
2021-10-25 18:10:44 +00:00
tax
2021-10-25 19:47:41 +00:00
clc
lda sinetable,X
adc FRAME
sta row_sum_smc+1
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
ldx HGR_Y ; YY
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
create_xloop:
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
;=====================
; critical inner loop
; every cycle here is 40x192 cycles
;=====================
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
lda sinetable,Y ; 4+
clc ; 2
row_sum_smc:
adc #$dd ; row base value ; 2
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
lsr ; double colors ; 2
2021-10-25 20:58:31 +00:00
; also puts bit in carry
; which helps make blue
2021-10-25 19:47:41 +00:00
and #$7 ; mask ; 2
tax ; 2
lda colorlookup,X ; lookup in table ; 5
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
ror_nop_smc:
ror ; $6A/$EA ; 2
; and #$7f ; make all purple
sta (GBASL),Y ; 6
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
lda ror_nop_smc ; toggle ror/nop ; 4
eor #$80 ; 2
sta ror_nop_smc ; 4
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
dey ; 2
bpl create_xloop ; 2/3
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
dec HGR_Y
bne create_yloop
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
; we skip drawing line 0 as it makes it easier
2021-10-25 18:10:44 +00:00
2021-10-25 19:47:41 +00:00
beq draw_oval
2021-10-25 18:10:44 +00:00
colorlookup:
.byte $11,$55,$5d,$7f,$5d,$55,$11 ; use 00 from sinetable
;.byte $00
2021-10-25 20:58:31 +00:00
2021-10-25 19:47:41 +00:00
sinetable_base:
2021-10-25 18:10:44 +00:00
; this is actually (32*sin(x))
.byte $00,$03,$06,$09,$0C,$0F,$11,$14
.byte $16,$18,$1A,$1C,$1D,$1E,$1F,$1F
2021-10-25 19:47:41 +00:00
.byte $20
;,$1F,$1F,$1E,$1D,$1C,$1A,$18
;.byte $16,$14,$11,$0F,$0C,$09,$06,$03
sinetable=$6000
2021-10-25 20:58:31 +00:00
gbasl = $6100
gbash = $6200