bubble: generate cosine table too

This commit is contained in:
Vince Weaver 2024-03-03 01:16:06 -05:00
parent fc3ab7444c
commit f58040b071
2 changed files with 50 additions and 6 deletions

View File

@ -20,6 +20,7 @@
; 1436 bytes -- call clear screen from page flip code
; 1434 bytes -- optimize HPLOT
; 1131 bytes -- generate SINE table from 65 entry lookup
; 633 bytes -- generate COSINE table from SINE table
; soft-switches
@ -368,7 +369,8 @@ log_lookup:
sines = $6c00
sines2 = $6d00
cosines = $6e00
cosines2= $6f00
;===================================
;
@ -403,6 +405,15 @@ setup_sine_loop:
dey
bpl setup_sine_loop
ldy #0
cosine_loop:
lda sines+192,Y
sta cosines,Y
sta cosines2,Y
iny
bne cosine_loop
rts
sines_base:
@ -456,26 +467,28 @@ sines2:
.byte $0A,$0B,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0E,$0F,$10,$10,$11,$12,$12
.byte $13,$14,$14,$15,$16,$17,$18,$18,$19,$1A,$1B,$1C,$1D,$1E,$1E,$1F
.byte $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F
.endif
; floor(s*cos((x-96)*PI*2/256.0)+48.5);
.align $100
cosines:
; sine[64]
.byte $59,$59,$59,$59,$59,$59,$59,$58,$58,$58,$58,$58,$57,$57,$57,$56
.byte $56,$55,$55,$55,$54,$54,$53,$53,$52,$52,$51,$50,$50,$4F,$4E,$4E
.byte $4D,$4C,$4C,$4B,$4A,$49,$48,$48,$47,$46,$45,$44,$43,$42,$42,$41
.byte $40,$3F,$3E,$3D,$3C,$3B,$3A,$39,$38,$37,$36,$35,$34,$33,$32,$31
; sine[128]
.byte $30,$2F,$2E,$2D,$2C,$2B,$2A,$29,$28,$27,$26,$25,$24,$23,$22,$21
.byte $20,$1F,$1E,$1E,$1D,$1C,$1B,$1A,$19,$18,$18,$17,$16,$15,$14,$14
.byte $13,$12,$12,$11,$10,$10,$0F,$0E,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0B
.byte $0A,$0A,$09,$09,$09,$08,$08,$08,$08,$08,$07,$07,$07,$07,$07,$07
; sine[192]
.byte $07,$07,$07,$07,$07,$07,$07,$08,$08,$08,$08,$08,$09,$09,$09,$0A
.byte $0A,$0B,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0E,$0F,$10,$10,$11,$12,$12
.byte $13,$14,$14,$15,$16,$17,$18,$18,$19,$1A,$1B,$1C,$1D,$1E,$1E,$1F
.byte $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F
; sine[0]
.byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F
.byte $40,$41,$42,$42,$43,$44,$45,$46,$47,$48,$48,$49,$4A,$4B,$4C,$4C
.byte $4D,$4E,$4E,$4F,$50,$50,$51,$52,$52,$53,$53,$54,$54,$55,$55,$55
@ -500,3 +513,4 @@ cosines2:
.byte $40,$41,$42,$42,$43,$44,$45,$46,$47,$48,$48,$49,$4A,$4B,$4C,$4C
.byte $4D,$4E,$4E,$4F,$50,$50,$51,$52,$52,$53,$53,$54,$54,$55,$55,$55
.byte $56,$56,$57,$57,$57,$58,$58,$58,$58,$58,$59,$59,$59,$59,$59,$59
.endif

View File

@ -21,6 +21,25 @@ static unsigned char const good_sine[256]={
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
};
static unsigned char const good_cosine[256]={
0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x58,0x58,0x58,0x58,0x58,0x57,0x57,0x57,0x56,
0x56,0x55,0x55,0x55,0x54,0x54,0x53,0x53,0x52,0x52,0x51,0x50,0x50,0x4F,0x4E,0x4E,
0x4D,0x4C,0x4C,0x4B,0x4A,0x49,0x48,0x48,0x47,0x46,0x45,0x44,0x43,0x42,0x42,0x41,
0x40,0x3F,0x3E,0x3D,0x3C,0x3B,0x3A,0x39,0x38,0x37,0x36,0x35,0x34,0x33,0x32,0x31,
0x30,0x2F,0x2E,0x2D,0x2C,0x2B,0x2A,0x29,0x28,0x27,0x26,0x25,0x24,0x23,0x22,0x21,
0x20,0x1F,0x1E,0x1E,0x1D,0x1C,0x1B,0x1A,0x19,0x18,0x18,0x17,0x16,0x15,0x14,0x14,
0x13,0x12,0x12,0x11,0x10,0x10,0x0F,0x0E,0x0E,0x0D,0x0D,0x0C,0x0C,0x0B,0x0B,0x0B,
0x0A,0x0A,0x09,0x09,0x09,0x08,0x08,0x08,0x08,0x08,0x07,0x07,0x07,0x07,0x07,0x07,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x08,0x08,0x08,0x08,0x08,0x09,0x09,0x09,0x0A,
0x0A,0x0B,0x0B,0x0B,0x0C,0x0C,0x0D,0x0D,0x0E,0x0E,0x0F,0x10,0x10,0x11,0x12,0x12,
0x13,0x14,0x14,0x15,0x16,0x17,0x18,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1E,0x1F,
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
0x40,0x41,0x42,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x48,0x49,0x4A,0x4B,0x4C,0x4C,
0x4D,0x4E,0x4E,0x4F,0x50,0x50,0x51,0x52,0x52,0x53,0x53,0x54,0x54,0x55,0x55,0x55,
0x56,0x56,0x57,0x57,0x57,0x58,0x58,0x58,0x58,0x58,0x59,0x59,0x59,0x59,0x59,0x59,
};
static unsigned char const quarter_sine[65]={
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
0x40,0x41,0x42,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x48,0x49,0x4A,0x4B,0x4C,0x4C,
@ -29,6 +48,7 @@ static unsigned char const quarter_sine[65]={
};
static unsigned char final_sine[256];
static unsigned char final_cosine[256];
int main(int argc, char **argv) {
@ -48,7 +68,17 @@ int main(int argc, char **argv) {
}
}
printf("Total Errors=%d\n",errors);
printf("Total Sine Errors=%d\n",errors);
for(i=0;i<256;i++) {
if (good_cosine[i]!=final_cosine[i]) {
printf("%d: %d!=%d\n",i,good_cosine[i],final_cosine[i]);
errors++;
}
}
printf("Total Cosine Errors=%d\n",errors);
return 0;
}