diff --git a/GenerateTrigTables.py b/GenerateTrigTables.py index 6ebf7c4..eb96fba 100755 --- a/GenerateTrigTables.py +++ b/GenerateTrigTables.py @@ -7,12 +7,12 @@ import math def twosCompliment(value): return (value^65535)+1 -def toFixed(flt): # Floating point to 8.8 fixed point - whole = max(-128, min(127, math.trunc(flt))) # Clamp to signed range +def toFixed(flt): # Floating point to 12.4 fixed point + whole = max(-2048, min(2047, math.trunc(flt))) # Clamp to signed range frac = abs(flt)%1 - binary = (abs(whole)<<8) + math.trunc(256*frac) + binary = (abs(whole)<<4) + math.trunc(16*frac) - if (flt<0 and abs(flt)>0.000001): + if (flt<0 and abs(flt)>0.06): binary = twosCompliment(binary) return binary @@ -20,7 +20,7 @@ def toFixed(flt): # Floating point to 8.8 fixed point def main(argv): - print ("sineTable:",end="") + print ("sineTable:\t\t; 8.8 fixed point",end="") rowCount = 7 for v in range(0,512): @@ -34,7 +34,7 @@ def main(argv): print (",", end="") - print ("\n\nangleToVectorX:\t\t; Counterclockwise angle, +x=(1,0)",end="") + print ("\n\nangleToVectorX:\t\t; 12.4 fixed point, counterclockwise angle, +x=(1,0)",end="") rowCount = 11 for v in range(0,360): @@ -48,7 +48,7 @@ def main(argv): print (",", end="") - print ("\n\nangleToVectorY:\t\t; Counterclockwise angle, +x=(1,0)",end="") + print ("\n\nangleToVectorY:\t\t; 12.4 fixed point, counterclockwise angle, +x=(1,0)",end="") rowCount = 11 for v in range(0,360): diff --git a/gscats.2mg b/gscats.2mg index 3e57b2c..9843832 100644 Binary files a/gscats.2mg and b/gscats.2mg differ diff --git a/projectile.s b/projectile.s index c6be334..24220fb 100644 --- a/projectile.s +++ b/projectile.s @@ -11,10 +11,10 @@ projectileData: .word -1 ; Pos X in pixels (from left terrain edge) .word 0 ; Pos Y in pixels (from bottom terrain edge) - .word 0 ; Pos X (8.8 fixed point) - .word 0 ; Pos Y (8.8 fixed point) - .word 0 ; Velocity X (8.8 fixed point) - .word 0 ; Velocity Y (8.8 fixed point) + .word 0 ; Pos X (12.4 fixed point) + .word 0 ; Pos Y (12.4 fixed point) + .word 0 ; Velocity X (12.4 fixed point) + .word 0 ; Velocity Y (12.4 fixed point) JD_POSX = 0 ; Byte offsets into projectile data structure JD_POSY = 2 @@ -54,13 +54,19 @@ fireProjectile: iny lda projectileParams ; Fixed point version of X pos - xba + asl + asl + asl + asl sta (SCRATCHL),y iny iny lda projectileParams+2 ; Fixed point version of Y pos - xba + asl + asl + asl + asl sta (SCRATCHL),y iny iny @@ -105,10 +111,6 @@ updateProjectiles: lsr lsr lsr - lsr - lsr - lsr - lsr sta projectileData+JD_POSX ; Integrate Y velocity over position @@ -122,10 +124,6 @@ updateProjectiles: lsr lsr lsr - lsr - lsr - lsr - lsr sta projectileData+JD_POSY brk updateProjectilesDone: diff --git a/tables.s b/tables.s index 8f3a3fa..13aae63 100644 --- a/tables.s +++ b/tables.s @@ -1,4 +1,4 @@ -sineTable: +sineTable: ; 8.8 fixed point .word $0080,$0083,$0086,$0089,$008c,$008f,$0092,$0095 .word $0098,$009c,$009f,$00a2,$00a5,$00a8,$00ab,$00ae .word $00b0,$00b3,$00b6,$00b9,$00bc,$00bf,$00c1,$00c4 @@ -64,69 +64,69 @@ sineTable: .word $004f,$0051,$0054,$0057,$005a,$005d,$0060,$0063 .word $0067,$006a,$006d,$0070,$0073,$0076,$0079,$007c -angleToVectorX: ; Counterclockwise angle, +x=(1,0) - .word $0100,$00ff,$00ff,$00ff,$00ff,$00ff,$00fe,$00fe,$00fd,$00fc,$00fc,$00fb - .word $00fa,$00f9,$00f8,$00f7,$00f6,$00f4,$00f3,$00f2,$00f0,$00ee,$00ed,$00eb - .word $00e9,$00e8,$00e6,$00e4,$00e2,$00df,$00dd,$00db,$00d9,$00d6,$00d4,$00d1 - .word $00cf,$00cc,$00c9,$00c6,$00c4,$00c1,$00be,$00bb,$00b8,$00b5,$00b1,$00ae - .word $00ab,$00a7,$00a4,$00a1,$009d,$009a,$0096,$0092,$008f,$008b,$0087,$0083 - .word $0080,$007c,$0078,$0074,$0070,$006c,$0068,$0064,$005f,$005b,$0057,$0053 - .word $004f,$004a,$0046,$0042,$003d,$0039,$0035,$0030,$002c,$0028,$0023,$001f - .word $001a,$0016,$0011,$000d,$0008,$0004,$0000,$fffc,$fff8,$fff3,$ffef,$ffea - .word $ffe6,$ffe1,$ffdd,$ffd8,$ffd4,$ffd0,$ffcb,$ffc7,$ffc3,$ffbe,$ffba,$ffb6 - .word $ffb1,$ffad,$ffa9,$ffa5,$ffa1,$ff9c,$ff98,$ff94,$ff90,$ff8c,$ff88,$ff84 - .word $ff81,$ff7d,$ff79,$ff75,$ff71,$ff6e,$ff6a,$ff66,$ff63,$ff5f,$ff5c,$ff59 - .word $ff55,$ff52,$ff4f,$ff4b,$ff48,$ff45,$ff42,$ff3f,$ff3c,$ff3a,$ff37,$ff34 - .word $ff31,$ff2f,$ff2c,$ff2a,$ff27,$ff25,$ff23,$ff21,$ff1e,$ff1c,$ff1a,$ff18 - .word $ff17,$ff15,$ff13,$ff12,$ff10,$ff0e,$ff0d,$ff0c,$ff0a,$ff09,$ff08,$ff07 - .word $ff06,$ff05,$ff04,$ff04,$ff03,$ff02,$ff02,$ff01,$ff01,$ff01,$ff01,$ff01 - .word $ff00,$ff01,$ff01,$ff01,$ff01,$ff01,$ff02,$ff02,$ff03,$ff04,$ff04,$ff05 - .word $ff06,$ff07,$ff08,$ff09,$ff0a,$ff0c,$ff0d,$ff0e,$ff10,$ff12,$ff13,$ff15 - .word $ff17,$ff18,$ff1a,$ff1c,$ff1e,$ff21,$ff23,$ff25,$ff27,$ff2a,$ff2c,$ff2f - .word $ff31,$ff34,$ff37,$ff3a,$ff3c,$ff3f,$ff42,$ff45,$ff48,$ff4b,$ff4f,$ff52 - .word $ff55,$ff59,$ff5c,$ff5f,$ff63,$ff66,$ff6a,$ff6e,$ff71,$ff75,$ff79,$ff7d - .word $ff80,$ff84,$ff88,$ff8c,$ff90,$ff94,$ff98,$ff9c,$ffa1,$ffa5,$ffa9,$ffad - .word $ffb1,$ffb6,$ffba,$ffbe,$ffc3,$ffc7,$ffcb,$ffd0,$ffd4,$ffd8,$ffdd,$ffe1 - .word $ffe6,$ffea,$ffef,$fff3,$fff8,$fffc,$0000,$0004,$0008,$000d,$0011,$0016 - .word $001a,$001f,$0023,$0028,$002c,$0030,$0035,$0039,$003d,$0042,$0046,$004a - .word $004f,$0053,$0057,$005b,$005f,$0064,$0068,$006c,$0070,$0074,$0078,$007c - .word $0080,$0083,$0087,$008b,$008f,$0092,$0096,$009a,$009d,$00a1,$00a4,$00a7 - .word $00ab,$00ae,$00b1,$00b5,$00b8,$00bb,$00be,$00c1,$00c4,$00c6,$00c9,$00cc - .word $00cf,$00d1,$00d4,$00d6,$00d9,$00db,$00dd,$00df,$00e2,$00e4,$00e6,$00e8 - .word $00e9,$00eb,$00ed,$00ee,$00f0,$00f2,$00f3,$00f4,$00f6,$00f7,$00f8,$00f9 - .word $00fa,$00fb,$00fc,$00fc,$00fd,$00fe,$00fe,$00ff,$00ff,$00ff,$00ff,$00ff +angleToVectorX: ; 12.4 fixed point, counterclockwise angle, +x=(1,0) + .word $0010,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f + .word $000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000e,$000e,$000e + .word $000e,$000e,$000e,$000e,$000e,$000d,$000d,$000d,$000d,$000d,$000d,$000d + .word $000c,$000c,$000c,$000c,$000c,$000c,$000b,$000b,$000b,$000b,$000b,$000a + .word $000a,$000a,$000a,$000a,$0009,$0009,$0009,$0009,$0008,$0008,$0008,$0008 + .word $0008,$0007,$0007,$0007,$0007,$0006,$0006,$0006,$0005,$0005,$0005,$0005 + .word $0004,$0004,$0004,$0004,$0003,$0003,$0003,$0003,$0002,$0002,$0002,$0001 + .word $0001,$0001,$0001,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$ffff,$ffff + .word $ffff,$ffff,$fffe,$fffe,$fffe,$fffd,$fffd,$fffd,$fffd,$fffc,$fffc,$fffc + .word $fffc,$fffb,$fffb,$fffb,$fffb,$fffa,$fffa,$fffa,$fff9,$fff9,$fff9,$fff9 + .word $fff9,$fff8,$fff8,$fff8,$fff8,$fff7,$fff7,$fff7,$fff7,$fff6,$fff6,$fff6 + .word $fff6,$fff6,$fff5,$fff5,$fff5,$fff5,$fff5,$fff4,$fff4,$fff4,$fff4,$fff4 + .word $fff4,$fff3,$fff3,$fff3,$fff3,$fff3,$fff3,$fff3,$fff2,$fff2,$fff2,$fff2 + .word $fff2,$fff2,$fff2,$fff2,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1 + .word $fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1 + .word $fff0,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1 + .word $fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff2,$fff2,$fff2 + .word $fff2,$fff2,$fff2,$fff2,$fff2,$fff3,$fff3,$fff3,$fff3,$fff3,$fff3,$fff3 + .word $fff4,$fff4,$fff4,$fff4,$fff4,$fff4,$fff5,$fff5,$fff5,$fff5,$fff5,$fff6 + .word $fff6,$fff6,$fff6,$fff6,$fff7,$fff7,$fff7,$fff7,$fff8,$fff8,$fff8,$fff8 + .word $fff8,$fff9,$fff9,$fff9,$fff9,$fffa,$fffa,$fffa,$fffb,$fffb,$fffb,$fffb + .word $fffc,$fffc,$fffc,$fffc,$fffd,$fffd,$fffd,$fffd,$fffe,$fffe,$fffe,$ffff + .word $ffff,$ffff,$ffff,$0000,$0000,$0000,$0000,$0000,$0000,$0000,$0001,$0001 + .word $0001,$0001,$0002,$0002,$0002,$0003,$0003,$0003,$0003,$0004,$0004,$0004 + .word $0004,$0005,$0005,$0005,$0005,$0006,$0006,$0006,$0007,$0007,$0007,$0007 + .word $0008,$0008,$0008,$0008,$0008,$0009,$0009,$0009,$0009,$000a,$000a,$000a + .word $000a,$000a,$000b,$000b,$000b,$000b,$000b,$000c,$000c,$000c,$000c,$000c + .word $000c,$000d,$000d,$000d,$000d,$000d,$000d,$000d,$000e,$000e,$000e,$000e + .word $000e,$000e,$000e,$000e,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f + .word $000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f -angleToVectorY: ; Counterclockwise angle, +x=(1,0) - .word $0000,$0004,$0008,$000d,$0011,$0016,$001a,$001f,$0023,$0028,$002c,$0030 - .word $0035,$0039,$003d,$0042,$0046,$004a,$004f,$0053,$0057,$005b,$005f,$0064 - .word $0068,$006c,$0070,$0074,$0078,$007c,$007f,$0083,$0087,$008b,$008f,$0092 - .word $0096,$009a,$009d,$00a1,$00a4,$00a7,$00ab,$00ae,$00b1,$00b5,$00b8,$00bb - .word $00be,$00c1,$00c4,$00c6,$00c9,$00cc,$00cf,$00d1,$00d4,$00d6,$00d9,$00db - .word $00dd,$00df,$00e2,$00e4,$00e6,$00e8,$00e9,$00eb,$00ed,$00ee,$00f0,$00f2 - .word $00f3,$00f4,$00f6,$00f7,$00f8,$00f9,$00fa,$00fb,$00fc,$00fc,$00fd,$00fe - .word $00fe,$00ff,$00ff,$00ff,$00ff,$00ff,$0100,$00ff,$00ff,$00ff,$00ff,$00ff - .word $00fe,$00fe,$00fd,$00fc,$00fc,$00fb,$00fa,$00f9,$00f8,$00f7,$00f6,$00f4 - .word $00f3,$00f2,$00f0,$00ee,$00ed,$00eb,$00e9,$00e8,$00e6,$00e4,$00e2,$00df - .word $00dd,$00db,$00d9,$00d6,$00d4,$00d1,$00cf,$00cc,$00c9,$00c6,$00c4,$00c1 - .word $00be,$00bb,$00b8,$00b5,$00b1,$00ae,$00ab,$00a7,$00a4,$00a1,$009d,$009a - .word $0096,$0092,$008f,$008b,$0087,$0083,$007f,$007c,$0078,$0074,$0070,$006c - .word $0068,$0064,$005f,$005b,$0057,$0053,$004f,$004a,$0046,$0042,$003d,$0039 - .word $0035,$0030,$002c,$0028,$0023,$001f,$001a,$0016,$0011,$000d,$0008,$0004 - .word $0000,$fffc,$fff8,$fff3,$ffef,$ffea,$ffe6,$ffe1,$ffdd,$ffd8,$ffd4,$ffd0 - .word $ffcb,$ffc7,$ffc3,$ffbe,$ffba,$ffb6,$ffb1,$ffad,$ffa9,$ffa5,$ffa1,$ff9c - .word $ff98,$ff94,$ff90,$ff8c,$ff88,$ff84,$ff80,$ff7d,$ff79,$ff75,$ff71,$ff6e - .word $ff6a,$ff66,$ff63,$ff5f,$ff5c,$ff59,$ff55,$ff52,$ff4f,$ff4b,$ff48,$ff45 - .word $ff42,$ff3f,$ff3c,$ff3a,$ff37,$ff34,$ff31,$ff2f,$ff2c,$ff2a,$ff27,$ff25 - .word $ff23,$ff21,$ff1e,$ff1c,$ff1a,$ff18,$ff17,$ff15,$ff13,$ff12,$ff10,$ff0e - .word $ff0d,$ff0c,$ff0a,$ff09,$ff08,$ff07,$ff06,$ff05,$ff04,$ff04,$ff03,$ff02 - .word $ff02,$ff01,$ff01,$ff01,$ff01,$ff01,$ff00,$ff01,$ff01,$ff01,$ff01,$ff01 - .word $ff02,$ff02,$ff03,$ff04,$ff04,$ff05,$ff06,$ff07,$ff08,$ff09,$ff0a,$ff0c - .word $ff0d,$ff0e,$ff10,$ff12,$ff13,$ff15,$ff17,$ff18,$ff1a,$ff1c,$ff1e,$ff21 - .word $ff23,$ff25,$ff27,$ff2a,$ff2c,$ff2f,$ff31,$ff34,$ff37,$ff3a,$ff3c,$ff3f - .word $ff42,$ff45,$ff48,$ff4b,$ff4f,$ff52,$ff55,$ff59,$ff5c,$ff5f,$ff63,$ff66 - .word $ff6a,$ff6e,$ff71,$ff75,$ff79,$ff7d,$ff80,$ff84,$ff88,$ff8c,$ff90,$ff94 - .word $ff98,$ff9c,$ffa1,$ffa5,$ffa9,$ffad,$ffb1,$ffb6,$ffba,$ffbe,$ffc3,$ffc7 - .word $ffcb,$ffd0,$ffd4,$ffd8,$ffdd,$ffe1,$ffe6,$ffea,$ffef,$fff3,$fff8,$fffc +angleToVectorY: ; 12.4 fixed point, counterclockwise angle, +x=(1,0) + .word $0000,$0000,$0000,$0000,$0001,$0001,$0001,$0001,$0002,$0002,$0002,$0003 + .word $0003,$0003,$0003,$0004,$0004,$0004,$0004,$0005,$0005,$0005,$0005,$0006 + .word $0006,$0006,$0007,$0007,$0007,$0007,$0007,$0008,$0008,$0008,$0008,$0009 + .word $0009,$0009,$0009,$000a,$000a,$000a,$000a,$000a,$000b,$000b,$000b,$000b + .word $000b,$000c,$000c,$000c,$000c,$000c,$000c,$000d,$000d,$000d,$000d,$000d + .word $000d,$000d,$000e,$000e,$000e,$000e,$000e,$000e,$000e,$000e,$000f,$000f + .word $000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f + .word $000f,$000f,$000f,$000f,$000f,$000f,$0010,$000f,$000f,$000f,$000f,$000f + .word $000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f + .word $000f,$000f,$000f,$000e,$000e,$000e,$000e,$000e,$000e,$000e,$000e,$000d + .word $000d,$000d,$000d,$000d,$000d,$000d,$000c,$000c,$000c,$000c,$000c,$000c + .word $000b,$000b,$000b,$000b,$000b,$000a,$000a,$000a,$000a,$000a,$0009,$0009 + .word $0009,$0009,$0008,$0008,$0008,$0008,$0007,$0007,$0007,$0007,$0007,$0006 + .word $0006,$0006,$0005,$0005,$0005,$0005,$0004,$0004,$0004,$0004,$0003,$0003 + .word $0003,$0003,$0002,$0002,$0002,$0001,$0001,$0001,$0001,$0000,$0000,$0000 + .word $0000,$0000,$0000,$0000,$ffff,$ffff,$ffff,$ffff,$fffe,$fffe,$fffe,$fffd + .word $fffd,$fffd,$fffd,$fffc,$fffc,$fffc,$fffc,$fffb,$fffb,$fffb,$fffb,$fffa + .word $fffa,$fffa,$fff9,$fff9,$fff9,$fff9,$fff8,$fff8,$fff8,$fff8,$fff8,$fff7 + .word $fff7,$fff7,$fff7,$fff6,$fff6,$fff6,$fff6,$fff6,$fff5,$fff5,$fff5,$fff5 + .word $fff5,$fff4,$fff4,$fff4,$fff4,$fff4,$fff4,$fff3,$fff3,$fff3,$fff3,$fff3 + .word $fff3,$fff3,$fff2,$fff2,$fff2,$fff2,$fff2,$fff2,$fff2,$fff2,$fff1,$fff1 + .word $fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1 + .word $fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff0,$fff1,$fff1,$fff1,$fff1,$fff1 + .word $fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1,$fff1 + .word $fff1,$fff1,$fff1,$fff2,$fff2,$fff2,$fff2,$fff2,$fff2,$fff2,$fff2,$fff3 + .word $fff3,$fff3,$fff3,$fff3,$fff3,$fff3,$fff4,$fff4,$fff4,$fff4,$fff4,$fff4 + .word $fff5,$fff5,$fff5,$fff5,$fff5,$fff6,$fff6,$fff6,$fff6,$fff6,$fff7,$fff7 + .word $fff7,$fff7,$fff8,$fff8,$fff8,$fff8,$fff8,$fff9,$fff9,$fff9,$fff9,$fffa + .word $fffa,$fffa,$fffb,$fffb,$fffb,$fffb,$fffc,$fffc,$fffc,$fffc,$fffd,$fffd + .word $fffd,$fffd,$fffe,$fffe,$fffe,$ffff,$ffff,$ffff,$ffff,$0000,$0000,$0000 vramRowEndsMinusOne: .word $209f,$213f,$21df,$227f,$231f,$23bf,$245f,$24ff,$259f,$263f,$26df,$277f,$281f,$28bf,$295f,$29ff,$2a9f,$2b3f,$2bdf,$2c7f