;Notes for Math: ;The game assumes up (-Y) is angle 0000, right (+X) is 4000, down (+Y) is 8000, and left (-X) is C000. ;A0C0AE is called after storing X in $12 and Y in $14. The result will be in A upon RTL. ;Super Metroid only needs 1/256 resolution for its own stuff, so I 'trim' the result in the routine. So this is overkill, but meh. org $A0C0AE PHX PHY PHP PHB PHK PLB REP #$30 LDX #$0000 TXY LDA $12 BPL + LDX #$0004 EOR #$FFFF INC A STA $12 + LDA $14 BPL + INX INX EOR #$FFFF INC A STA $14 + SEP #$20 XBA LDA $12 CMP $14 BCS ++ ;Branch if $14 is not bigger than $12 XBA INX ++ STZ $4204 REP #$20 STA $4205 PHX TYX LDA #$00B8 STA $14 JSR GetAngleAdjustment PLX BIT.w AngleSign-1,X BPL + EOR #$FFFF INC + CLC ADC #$0080 ;0000 + 00C0 = 01, 0000 - 0140 = FF, 0000 + 0040 = 00, 0000 - 0040 = 00 STA $12 LDA.w AngleStart-1,X AND #$FF00 CLC ADC $12 XBA AND #$00FF PLB PLP PLY PLX RTL GetAngleAdjustment: LDA $4214 LDY #$0009 - DEY ASL BCC - - DEY BEQ + LSR INX INX BRA - + XBA AND #$00FF ASL TAY LDA.w AngleIndexes,X STA $12 LDA [$12],Y RTS AngleStart: DB $40,$80,$40,$00,$C0,$80,$C0,$00 AngleSign: DB $00,$80,$80,$00,$80,$00,$00,$80 AngleIndexes: ; DW $FFFC,$FFF4,$FFE4,$FFC4,$FF84,$FF04,$FE04,$FC04 DW $FC04,$FE04,$FF04,$FF84,$FFC4,$FFE4,$FFF4,$FFFC EndCheck: org $B8FC04 incbin AnglesT.bin ;AnglesT.bin is just these following values. I have them seperated according to the 'AngleIndexes' above. ;0020EC1FD71FC31FAF1F9B1F871F731F601F4C1F381F251F111FFE1EEA1ED71EC41EB11E9E1E8B1E781E651E531E401E2D1E1B1E081EF61DE41DD11DBF1DAD1D9B1D891D771D661D541D421D301D1F1D0D1DFC1CEB1CD91CC81CB71CA61C951C841C731C621C521C411C301C201C0F1CFF1BEF1BDE1BCE1BBE1BAE1B9E1B8E1B7E1B6E1B5E1B4E1B3F1B2F1B1F1B101B011BF11AE21AD31AC31AB41AA51A961A871A781A691A5A1A4C1A3D1A2E1A201A111A031AF419E619D719C919BB19AD199F19911982197519671959194B193D192F19221914190719F918EC18DE18D118C418B618A9189C188F188218751868185B184E184118341828181B180E180218F517E917DC17D017C317B717AB179E17921786177A176E17621756174A173E17321726171B170F170317F716EC16E016D516C916BE16B216A7169C16901685167A166F16641659164E16421638162D16221617160C160116F615EC15E115D615CC15C115B715AC15A21597158D15831578156E15641559154F1545153B15311527151D1513150915FF14F514EB14E214D814CE14C414BB14B114A7149E1494148B14811478146E1465145B1452144914401436142D1424141B1412140914FF13F613ED13E413DC13D313CA13C113B813AF13A6139E1395138C1384137B1372136A1361135913501348133F1337132E1326131E1315130D130513FD12F412EC12 ;E412C412A41284126512461228120912EC11CE11B111951178115C11411125110A11F010D510BB10A11088106E1055103D1024100C10F40FDD0FC50FAE0F970F810F6A0F540F3E0F290F130FFE0EE90ED40EC00EAC0E970E840E700E5C0E490E360E230E100EFE0DEB0DD90DC70DB50DA30D920D810D6F0D5E0D4E0D3D0D2C0D1C0D0C0DFC0CEC0CDC0CCC0CBD0CAE0C9E0C8F0C800C720C630C540C460C380C290C1B0C0E0C000CF20BE40BD70BCA0BBD0BAF0BA20B960B890B7C0B700B630B570B4B0B3E0B320B260B1B0B0F0B030BF80AEC0AE10AD50ACA0ABF0AB40AA90A9E0A930A890A7E0A740A690A5F0A540A4A0A400A360A2C0A220A180A0F0A050A ;FB09D509B1098D096A09490928090809E908CB08AD089008740859083E0824080B08F207DA07C207AB0795077F07690754073F072B0717070407F106DF06CC06BB06A906980687067706670657064706380629061B060C06FE05F005E305D505C805BB05AE05A20596058A057E05720567055B05500545053A05300525051B05 ;1105EA04C504A3048204630446042A041004F603DE03C703B2039D03890376036303520341033003210312030303F502E802DB02CE02C202B602AB02A0029502 ;8B026502430224020902F001DA01C501B201A10191018201740168015C015001 ;460122010501ED00D900C900BA00AE00 ;A30082006D005D00 ;51003600