sine: optimize a bit more
This commit is contained in:
parent
22a9c81d36
commit
f67e8bc7cc
|
@ -152,6 +152,9 @@ noc2:
|
|||
bne right_lines_loop
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;=========================================
|
||||
; draw line
|
||||
; from x1,y1 to x2,y2
|
||||
|
|
|
@ -5,22 +5,22 @@ TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft
|
|||
LINKERSCRIPTS = ../../../linker_scripts
|
||||
EMPTYDISK = ../../../empty_disk/empty.dsk
|
||||
|
||||
all: plasma_hgr.dsk
|
||||
all: sines.dsk
|
||||
|
||||
plasma_hgr.dsk: HELLO APPROX_SINE THICK_SINE THICK_COS TABLE_SINE ROM_SINE \
|
||||
sines.dsk: HELLO APPROX_SINE THICK_SINE THICK_COS TABLE_SINE ROM_SINE \
|
||||
OOPS_COS OOPS2_COS OOPS3_COS OOPS4_COS ROTATE
|
||||
cp $(EMPTYDISK) plasma_hgr.dsk
|
||||
$(DOS33) -y plasma_hgr.dsk SAVE A HELLO
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 APPROX_SINE
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 TABLE_SINE
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 ROM_SINE
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 THICK_SINE
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 THICK_COS
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 OOPS_COS
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 OOPS2_COS
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0x3f5 OOPS3_COS
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0x3f5 OOPS4_COS
|
||||
$(DOS33) -y plasma_hgr.dsk BSAVE -a 0x3f5 ROTATE
|
||||
cp $(EMPTYDISK) sines.dsk
|
||||
$(DOS33) -y sines.dsk SAVE A HELLO
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0xc00 APPROX_SINE
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0xc00 TABLE_SINE
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0xc00 ROM_SINE
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0xc00 THICK_SINE
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0xc00 THICK_COS
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0xc00 OOPS_COS
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0xc00 OOPS2_COS
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0x3f5 OOPS3_COS
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0x3f5 OOPS4_COS
|
||||
$(DOS33) -y sines.dsk BSAVE -a 0x3f5 ROTATE
|
||||
|
||||
|
||||
###
|
||||
|
|
|
@ -28,11 +28,11 @@ force_zero:
|
|||
sta sinetable+$30,X
|
||||
sta sinetable+$20,Y
|
||||
|
||||
lda #0
|
||||
|
||||
inx
|
||||
dey
|
||||
|
||||
tya ; force a zero at end
|
||||
|
||||
beq force_zero
|
||||
bpl sinetable_loop
|
||||
end:
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
; thick sine
|
||||
; table look up sine
|
||||
|
||||
; trying to make a 64 entry 32*sin() in the zero page
|
||||
; want to beat 35 bytes (that's what the cos/ROM does)
|
||||
|
||||
; 57 bytes -- original
|
||||
; 48 bytes -- optimize
|
||||
; 46 bytes -- zero page
|
||||
|
||||
; zero page
|
||||
GBASL = $26
|
||||
GBASH = $27
|
||||
YY = $69
|
||||
ROW_SUM = $70
|
||||
|
||||
|
||||
HGR_X = $E0
|
||||
HGR_XH = $E1
|
||||
|
@ -17,46 +21,35 @@ SUM = $FD
|
|||
SAVEX = $FE
|
||||
SAVEY = $FF
|
||||
|
||||
sinetable=$70
|
||||
|
||||
thick_sine:
|
||||
|
||||
table_sine:
|
||||
|
||||
;==================
|
||||
; create sinetable
|
||||
|
||||
ldy #0 ; Y is 0
|
||||
ldx #0 ; Y is 0
|
||||
ldy #$10
|
||||
|
||||
sinetable_loop:
|
||||
tya ; 2
|
||||
and #$3f ; wrap sine at 63 entries ; 2
|
||||
|
||||
cmp #$20
|
||||
php ; save pos/negative for later
|
||||
|
||||
and #$1f
|
||||
|
||||
cmp #$10
|
||||
bcc sin_left ; blt
|
||||
|
||||
sin_right:
|
||||
; sec carry should be set here
|
||||
eor #$FF
|
||||
adc #$20 ; 32-X
|
||||
sin_left:
|
||||
tax
|
||||
lda sinetable_base,X ; 4+
|
||||
|
||||
plp
|
||||
bcc sin_done
|
||||
sta sinetable+$10,X
|
||||
sta sinetable+$00,Y
|
||||
|
||||
sin_negate:
|
||||
; carry set here
|
||||
eor #$ff
|
||||
adc #0 ; FIXME: this makes things off by 1
|
||||
|
||||
sin_done:
|
||||
sta sinetable,Y
|
||||
sec ; these maybe not needed
|
||||
adc #$0
|
||||
|
||||
iny
|
||||
bne sinetable_loop
|
||||
sta sinetable+$30,X
|
||||
sta sinetable+$20,Y
|
||||
|
||||
inx
|
||||
dey
|
||||
|
||||
bpl sinetable_loop
|
||||
|
||||
; Y is 0 at this point?
|
||||
|
||||
|
@ -66,10 +59,9 @@ done:
|
|||
|
||||
sinetable_base:
|
||||
; this is actually (32*sin(x))
|
||||
.byte $00,$03,$06,$09,$0C,$0F,$11,$14
|
||||
.byte $16,$18,$1A,$1C,$1D,$1E,$1F,$1F
|
||||
.byte $20
|
||||
;.byte $00,$03,$06,$09,$0C,$0F,$11,$14
|
||||
;.byte $16,$18,$1A,$1C,$1D,$1E,$1F,$1F,$20
|
||||
|
||||
|
||||
sinetable=$6000
|
||||
.byte $20,$1F,$1F,$1E,$1D,$1C,$1A,$18,$16
|
||||
.byte $14,$11,$0F,$0C,$09,$06,$03,$00
|
||||
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
; 72 bytes -- depend on X being 0 at end of loop
|
||||
; 71 bytes -- rerrange so can beq rather than jmp
|
||||
; 70 bytes -- update the sine table division
|
||||
; 69 bytes -- optimize sine routine
|
||||
|
||||
; zero page
|
||||
sinetable=$70
|
||||
sinetable=$60
|
||||
HGR_X = $E0
|
||||
HGR_XH = $E1
|
||||
HGR_Y = $E2
|
||||
|
@ -52,23 +53,24 @@ sinetable_loop:
|
|||
lda costable_base+1,Y
|
||||
force_zero:
|
||||
lsr ; rom value is *256
|
||||
lsr ; we want *32
|
||||
; lsr
|
||||
lsr ; we want *64
|
||||
|
||||
sta sinetable+$10,Y
|
||||
sta sinetable+$00,X
|
||||
eor #$FF
|
||||
|
||||
sec
|
||||
adc #$0
|
||||
|
||||
sta sinetable+$30,Y
|
||||
sta sinetable+$20,X
|
||||
|
||||
lda #0 ; hack, ROM cosine table doesn't
|
||||
; have a good zero for some reason
|
||||
|
||||
iny
|
||||
dex
|
||||
|
||||
txa ; hack, ROM cosine table doesn't
|
||||
; have a good zero for some reason
|
||||
|
||||
beq force_zero
|
||||
bpl sinetable_loop
|
||||
|
||||
|
@ -107,11 +109,11 @@ circle_loop:
|
|||
|
||||
lda FRAME
|
||||
and #$3f ; wrap value to 0..63
|
||||
|
||||
tay
|
||||
lda sinetable,Y
|
||||
|
||||
; multiply by 2 and center on screen $60 is midscreen
|
||||
; asl
|
||||
; center on screen $60 is midscreen
|
||||
clc
|
||||
adc #$60
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
; Tiny Tiny
|
||||
; Tiny Cool - 32B demo
|
||||
|
||||
; makes a pretty neat spinning pattern
|
||||
; not necessarily repeatable, it's walking through each memory page
|
||||
; and grabbing offset 32 or so as a shape table
|
||||
; what you get depends on contents of RAM
|
||||
|
||||
; zero page locations
|
||||
HGR_SHAPE = $1A
|
||||
|
@ -24,11 +29,11 @@ tiny_tiny:
|
|||
jsr HGR2 ; Hi-res graphics, no text at bottom
|
||||
; Y=0, A=0 after this call
|
||||
|
||||
lda #1
|
||||
sta HGR_SCALE
|
||||
iny
|
||||
sty HGR_SCALE
|
||||
|
||||
tiny_loop:
|
||||
; setup X and Y co-ords
|
||||
; setup X and Y co-ords for center of screen
|
||||
ldy #0 ; Y always 0
|
||||
ldx #140
|
||||
lda #96
|
||||
|
@ -42,7 +47,8 @@ rot_smc:
|
|||
jsr XDRAW0 ; XDRAW 1 AT X,Y
|
||||
; Both A and X are 0 at exit
|
||||
|
||||
inc rot_smc+1
|
||||
; increment rotation
|
||||
inc rot_smc+1 ; oops also increments high byte of shape table
|
||||
jmp tiny_loop
|
||||
|
||||
shape_table:
|
||||
|
|
Loading…
Reference in New Issue