plasmag: merge in fac tables

This commit is contained in:
Vince Weaver 2023-09-07 02:14:32 -04:00
parent 241706414a
commit 2aca9de337
3 changed files with 232 additions and 36 deletions

View File

@ -32,7 +32,7 @@ plasmag.o: plasmag.s
PLASMAG_TINY: plasmag_tiny.o
ld65 -o PLASMAG_TINY plasmag_tiny.o -C $(LINKERSCRIPTS)/apple2_4000.inc
plasmag_tiny.o: plasmag_tiny.s gr_gbascalc.s
plasmag_tiny.o: plasmag_tiny.s gr_gbascalc.s make_tables.s
ca65 -o plasmag_tiny.o plasmag_tiny.s -l plasmag_tiny.lst
###

View File

@ -0,0 +1,222 @@
; code to use the FAC (floating point accumulator)
; to generate plasmagoria sine tables
; 232 bytes = initial implementation
; 218 bytes = increment high byte of destination instead of loading
; 208 bytes = modify 1->4 on the fly
; 205 bytes = make page increment common code
; 198 bytes = convert thirty-two to twenty-four on fly
; 188 bytes = convert forty-seven to thirty-eight with one byte
; 173 bytes = assume constants on same page
; 171 bytes = optimize save/load of loop index
; 169 bytes = optimize multiply by 8
; 166 bytes = separate common sin code
; 164 bytes = move more to common sin code
; 162 bytes = move more to common sin code
qint = $EBF2 ; convert FAC to 32-bit int?
fadd = $E7BE ; FAC = (Y:A)+FAC
movmf = $EB2B ; move fac to mem: round FAC and store at Y:X
fmult = $E97F ; FAC = (Y:A) * FAC
float = $EB93 ; signed value in A to FAC
sin = $EFF1
ARG = $A5 ; A5-AA
FAC = $9D ; 9D-A2
; code uses: 5E/5F "index" in load arg from Y:A
; uses ARG (A5-AA) for argument
; uses FAC (9D-A2)
TEMP1 = $FE
OURX = $FF
sin1 = $2000
sin2 = $2100
sin3 = $2200
save = $2300
HGR = $F3E2
make_tables:
;====================================================
; sin1[i]=round(47.0+
; 32.0*sin(i*(PI*2.0/256.0))+
; 16.0*sin(2.0*i*(PI*2.0/256.0)));
; sin1[i]=round(47.0+
; 16*(2.0*sin(i*(PI*2.0/256.0))+
; sin(2.0*i*(PI*2.0/256.0)));
; already set up for this one
jsr make_sin_table
;===================================================
; sin2[i]=round(47.0+
; 32.0*sin(4.0*i*(PI*2.0/256.0))+
; 16.0*sin(3.0*i*(PI*2.0/256.0)));
; 47 is same, 32 is same, 16 is same
; convert one to four
lda #$7d ; only one byte different
sta one_input
; load 3 instead of 2 (assume on same page)
lda #<three_input
sta sin_table_input3_smc+1
jsr make_sin_table
;======================================================
; sin3[i]=round(38.0+
; 24.0*sin(3.0*i*(PI*2.0/256.0))+
; 16.0*sin(8.0*i*(PI*2.0/256.0)));
; convert 47 to 38
lda #$18
sta forty_seven+1
; convert 32 to 24
dec thirty_two
lda #$40
sta thirty_two+1
; ideally, convert 4->3
; load 3 input (assume on same page)
lda #<three_input
sta sin_table_input1_smc+1
; convert four to eight
inc one_input ; increment power of two
; load 8 input (assume on same page)
lda #<one_input
sta sin_table_input3_smc+1
jmp make_sin_table
;===============================
;===============================
;===============================
;===============================
;===============================
make_sin_table:
ldx #0
sin_loop:
stx OURX
sin_table_input1_smc:
lda #<one_input
; thirtytwo or twentyfour
ldx #<thirty_two
jsr sin_common
jsr movmf ; save FAC to mem
sin_table_input3_smc:
lda #<two_input
; always 16
ldx #<sixteen
jsr sin_common
; add first sine
txa
jsr fadd ; FAC=FAC+(previous result)
; add constant 47 or 38
lda #<forty_seven
ldy #>forty_seven
jsr fadd ; FAC=FAC+constant
jsr qint ; convert to integer
lda FAC+4 ; get bottom byte
ldx OURX
sin_table_dest_smc:
sta sin1,X ; save to memory
inx ; move to next
bne sin_loop ; loop until done
inc sin_table_dest_smc+2 ; point to next location
rts
;==============================
; sin_common
;==============================
; A = low byte for input multiplier
; X = low byte for result multiplier
sin_common:
stx TEMP1
pha
lda OURX
jsr float ; FAC = float(OURX) (again)
pla
ldy #>one_input ; high byte, assume always same
jsr fmult ; FAC=FAC*(constant from RAM)
jsr sin ; FAC=sin(FAC)
ldy #>thirty_two ; high byte, assume always same
lda TEMP1
jsr fmult ; FAC=constant*FAC
ldy #>save
ldx #<save
rts
sixteen:
.byte $85,$00,$00,$00,$00
;twenty_four:
; .byte $85,$40,$00,$00,$00
thirty_two:
.byte $86,$00,$00,$00,$00
;thirty_eight:
; .byte $86,$18,$00,$00,$00
; 2^5 = 32, 1.0011 0000 = 1/8+1/16
forty_seven:
.byte $86,$3C,$00,$00,$00
; 32 * 1.0111 10000 = 1/4+1/8+1/16+1/32
one_input:
; 1*2*pi/256 = .0736310778
.byte $7b,$49,$0F,$da,$a2
two_input:
; 2*2*pi/256 = .0736310778
.byte $7c,$49,$0F,$da,$a2
three_input:
; 3*2*pi/256 = .0736310778
.byte $7d,$16,$cb,$e3,$f9
;four_input:
; ; 4*2*pi/256 = .0736310778
; .byte $7d,$49,$0F,$da,$a2
;eight_input:
; ; 8*2*pi/256 = .196349541
; .byte $7E,$49,$0F,$da,$a2

View File

@ -32,8 +32,13 @@ PARAM4 = $63
; =============================================================================
plasma_debut:
bit PAGE1 ; set page 1
bit SET_GR ; set graphics
jsr HGR
bit FULLGR
jsr make_tables
; bit PAGE1 ; set page 1
; bit SET_GR ; set graphics
bit LORES ; set lo-res
jsr init_lores_colors
@ -149,6 +154,7 @@ lores_colors_fine=$8100
init_lores_colors:
ldx #0
ldy #0
; 347
init_lores_colors_loop:
lda lores_colors_lookup,X
sta lores_colors_fine,Y
@ -172,38 +178,6 @@ lores_colors_lookup:
.byte $00,$88,$55,$99,$ff,$bb,$33,$22,$66,$77,$44,$cc,$ee,$dd,$99,$11
.align 256
.include "make_tables.s"
; This appears to be roughly 47+32*sin(x)+16*sin(2x)
sin1: ; 256
.byte $2E,$30,$32,$34,$35,$36,$38,$3A,$3C,$3C,$3E,$40,$41,$42,$44,$45,$47,$47,$49,$4A,$4B,$4C,$4D,$4E,$4F,$50,$51,$52,$53,$53,$54,$54
.byte $55,$55,$56,$57,$57,$58,$58,$57,$58,$58,$58,$58,$58,$58,$58,$58,$58,$57,$57,$57,$56,$56,$55,$54,$55,$54,$53,$52,$52,$51,$50,$4F
.byte $4E,$4E,$4D,$4C,$4B,$4B,$4A,$49,$48,$47,$46,$45,$45,$44,$42,$42,$41,$41,$3F,$3F,$3D,$3D,$3C,$3B,$3B,$39,$39,$39,$38,$38,$37,$36
.byte $36,$35,$35,$34,$34,$33,$32,$32,$32,$31,$31,$31,$30,$31,$30,$30,$30,$30,$2F,$2F,$30,$2F,$2F,$2F,$2F,$2F,$2F,$2F,$2E,$2F,$2F,$2F
.byte $2E,$2F,$2F,$2F,$2F,$2E,$2F,$2F,$2F,$2E,$2F,$2F,$2E,$2E,$2F,$2E,$2E,$2D,$2E,$2D,$2D,$2D,$2C,$2C,$2C,$2B,$2B,$2B,$2A,$2A,$29,$28
.byte $28,$27,$27,$26,$26,$25,$25,$23,$23,$22,$21,$21,$20,$1F,$1F,$1D,$1D,$1C,$1B,$1A,$19,$19,$17,$16,$16,$15,$14,$13,$13,$12,$11,$10
.byte $0F,$0F,$0E,$0D,$0C,$0C,$0B,$0A,$09,$09,$08,$08,$08,$07,$06,$07,$06,$06,$06,$06,$05,$06,$05,$05,$06,$05,$06,$06,$07,$07,$08,$08
.byte $09,$09,$0A,$0B,$0B,$0C,$0C,$0D,$0F,$0F,$10,$12,$12,$14,$15,$16,$17,$19,$1A,$1B,$1D,$1E,$20,$21,$22,$24,$26,$27,$28,$2A,$2C,$2E
; This appears to be roughly 47+32*sin(4x)+16*sin(3x)
sin2: ; 256
.byte $2E,$33,$38,$3C,$40,$43,$47,$4B,$4E,$51,$54,$56,$59,$5A,$5C,$5D,$5D,$5E,$5E,$5D,$5C,$5A,$59,$57,$55,$53,$4F,$4C,$49,$46,$42,$3E
.byte $3A,$36,$32,$2E,$2A,$26,$23,$1F,$1C,$18,$15,$12,$10,$0E,$0C,$0A,$09,$08,$07,$07,$07,$07,$09,$0A,$0B,$0D,$0F,$11,$13,$16,$19,$1C
.byte $1F,$22,$26,$29,$2C,$2F,$32,$36,$38,$3B,$3E,$3F,$42,$44,$46,$47,$48,$49,$4B,$4B,$4B,$4A,$4A,$49,$49,$48,$46,$44,$43,$41,$3F,$3C
.byte $3A,$38,$35,$33,$30,$2E,$2C,$2A,$28,$26,$24,$22,$21,$20,$1F,$1F,$1E,$1E,$1D,$1D,$1E,$1E,$1F,$20,$21,$22,$24,$25,$27,$29,$2B,$2D
.byte $2E,$30,$33,$35,$37,$38,$3A,$3C,$3D,$3E,$3F,$3F,$40,$40,$41,$40,$40,$3F,$3F,$3E,$3D,$3B,$3A,$38,$36,$34,$31,$2F,$2D,$2B,$29,$25
.byte $23,$21,$1F,$1D,$1B,$19,$18,$16,$15,$14,$14,$13,$13,$13,$13,$14,$16,$17,$18,$1A,$1C,$1D,$20,$23,$26,$28,$2C,$2E,$32,$35,$38,$3B
.byte $3E,$41,$45,$48,$4B,$4C,$4F,$51,$53,$54,$55,$55,$57,$57,$57,$56,$55,$53,$52,$50,$4E,$4B,$49,$45,$42,$3F,$3B,$37,$34,$30,$2C,$27
.byte $23,$1F,$1C,$18,$14,$11,$0E,$0B,$09,$07,$05,$03,$02,$01,$00,$00,$01,$01,$02,$03,$05,$07,$0A,$0D,$10,$13,$17,$1A,$1E,$22,$26,$2A
; This appears to be roughly 38+24*sin(3x)+16*sin(8x)
sin3: ; 256
.byte $26,$2C,$31,$35,$39,$3D,$40,$42,$44,$45,$45,$46,$45,$43,$42,$40,$3C,$3A,$38,$36,$33,$31,$30,$2F,$2F,$2E,$2F,$2F,$30,$33,$33,$36
.byte $37,$3A,$3C,$3C,$3E,$3E,$3D,$3D,$3B,$39,$36,$34,$30,$2B,$28,$23,$1D,$19,$14,$11,$0C,$09,$07,$04,$03,$03,$03,$03,$04,$07,$09,$0C
.byte $0F,$13,$16,$18,$1B,$1E,$20,$22,$22,$23,$24,$24,$23,$22,$21,$20,$1D,$1C,$1B,$1A,$19,$19,$19,$1A,$1C,$1E,$20,$23,$27,$2B,$2F,$33
.byte $37,$3D,$40,$44,$47,$4A,$4C,$4D,$4E,$4E,$4D,$4C,$4A,$47,$45,$41,$3C,$39,$35,$32,$2E,$2B,$28,$26,$25,$23,$23,$22,$22,$24,$24,$25
.byte $26,$29,$2A,$2A,$2B,$2C,$2B,$2B,$29,$28,$25,$23,$20,$1C,$19,$15,$10,$0D,$09,$07,$04,$02,$01,$00,$00,$00,$02,$03,$06,$0A,$0D,$11
.byte $15,$1B,$1F,$23,$27,$2B,$2D,$30,$32,$33,$34,$35,$35,$33,$33,$32,$30,$2E,$2D,$2C,$2B,$2A,$2A,$2A,$2B,$2C,$2E,$30,$32,$36,$38,$3B
.byte $3E,$42,$45,$47,$49,$4B,$4B,$4B,$4A,$49,$47,$45,$42,$3D,$3A,$35,$30,$2B,$26,$22,$1E,$1A,$17,$14,$13,$11,$10,$10,$10,$12,$12,$14
.byte $15,$18,$1A,$1B,$1D,$1E,$1F,$1F,$1F,$1F,$1E,$1D,$1B,$18,$16,$14,$10,$0E,$0C,$0B,$09,$08,$08,$09,$0A,$0C,$0E,$11,$14,$19,$1D,$22