dos33fsprogs/graphics/hgr/sine/thick_cos.s

132 lines
2.2 KiB
ArmAsm
Raw Normal View History

2022-01-25 20:44:27 +00:00
; thick sine
; 105 bytes -- original with table sine
; 89 bytes -- use ROM cosine table to generate sine table
; 86 bytes -- put sine table in zero page
2022-01-25 21:42:56 +00:00
; 89 bytes -- adjust to add #1 to avoid thick line at middle
; 87 bytes -- Y is 0 after HGR2
; 83 bytes -- optimize color flip
; 79 bytes -- use X
; 74 bytes -- optimize frame
; 72 bytes -- depend on X being 0 at end of loop
2022-01-25 22:03:41 +00:00
; 71 bytes -- rerrange so can beq rather than jmp
; 70 bytes -- update the sine table division
2022-01-26 05:06:20 +00:00
; 69 bytes -- optimize sine routine
2022-01-25 20:44:27 +00:00
; zero page
2022-01-26 05:06:20 +00:00
sinetable=$60
2022-01-25 20:44:27 +00:00
HGR_X = $E0
HGR_XH = $E1
HGR_Y = $E2
HGR_COLOR = $E4
HGR_PAGE = $E6
2022-01-25 21:42:56 +00:00
FRAME = $FF
2022-01-25 20:44:27 +00:00
; ROM routines
HGR2 = $F3D8
HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y)
HPLOT0 = $F457 ; plot at (Y,X), (A)
costable_base = $F5BA
;================================
; Clear screen and setup graphics
;================================
thick_sine:
jsr HGR2 ; set hi-res 140x192, page2, fullscreen
; A and Y both 0 at end
; try to get sine table from ROM
rom_sine:
;==========================================
; create sinetable using ROM cosine table
2022-01-25 22:03:41 +00:00
; ldy #0 ; from HGR2
2022-01-25 21:42:56 +00:00
ldx #$f
2022-01-25 20:44:27 +00:00
sinetable_loop:
2022-01-25 21:42:56 +00:00
lda costable_base+1,Y
2022-01-25 20:44:27 +00:00
force_zero:
lsr ; rom value is *256
2022-01-26 05:06:20 +00:00
lsr ; we want *64
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
sta sinetable+$10,Y
sta sinetable+$00,X
2022-01-25 20:44:27 +00:00
eor #$FF
2022-01-26 05:06:20 +00:00
2022-01-25 21:42:56 +00:00
sec
adc #$0
2022-01-26 05:06:20 +00:00
2022-01-25 21:42:56 +00:00
sta sinetable+$30,Y
sta sinetable+$20,X
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
iny
dex
2022-01-25 20:44:27 +00:00
2022-01-26 05:06:20 +00:00
txa ; hack, ROM cosine table doesn't
; have a good zero for some reason
2022-01-25 20:44:27 +00:00
beq force_zero
bpl sinetable_loop
2022-01-25 21:42:56 +00:00
; x is FF at this point
2022-01-25 20:44:27 +00:00
;============================
; main loop
;============================
2022-01-25 21:42:56 +00:00
inx
draw_sine:
; X is 0 here, either from above, or from end of loop
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
; ldx #0 ; HGR_X
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
; offset next time through
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
inc FRAME
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
; X is zero here
2022-01-25 20:44:27 +00:00
2022-01-25 22:03:41 +00:00
; 9 bytes to flip color (was 14)
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
txa
; lda #$FF
bit FRAME
2022-01-25 22:03:41 +00:00
bvs color_black
2022-01-25 21:42:56 +00:00
eor #$FF
2022-01-25 22:03:41 +00:00
color_black:
2022-01-25 21:42:56 +00:00
sta HGR_COLOR
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
circle_loop:
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
; get sine value
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
lda FRAME
and #$3f ; wrap value to 0..63
2022-01-26 05:06:20 +00:00
2022-01-25 21:42:56 +00:00
tay
lda sinetable,Y
2022-01-25 20:44:27 +00:00
2022-01-26 05:06:20 +00:00
; center on screen $60 is midscreen
2022-01-25 22:03:41 +00:00
clc
2022-01-25 21:42:56 +00:00
adc #$60
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
; ldx HGR_X ; saved in HGR_X
ldy #0 ; saved in HGR_XH
jsr HPLOT0 ; plot at (Y,X), (A)
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
inc FRAME
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
ldx HGR_X
inx ; HGR_X
2022-01-25 20:44:27 +00:00
2022-01-25 21:42:56 +00:00
bne circle_loop
2022-01-25 20:44:27 +00:00
2022-01-25 22:03:41 +00:00
beq draw_sine ; bra