---------- Formation disabling routine: ;Thanx to Assassin for this section. ;This disables formations based on bit masks, Back Guard, and number of characters. ;M and X flags are set going into this routine. C2/2E3A: AD 6D 3A LDA $3A6D C2/2E3D: 4A LSR C2/2E3E: 4A LSR (check Back Guard effect) C2/2E3F: AD 48 2F LDA $2F48 (get extra enemy formation data, byte 0, top half inverted) C2/2E42: 90 0C BCC $2E50 (branch if no Back Guard) C2/2E44: 89 B0 BIT #$B0 (are any of Side, Back, or Normal attacks allowed?) C2/2E46: F0 02 BEQ $2E4A (if not, branch) C2/2E48: 29 B0 AND #$B0 (if so, disable Pincer) C2/2E4A: 89 D0 BIT #$D0 (are any of Side, Pincer, or Normal attacks allowed?) C2/2E4C: F0 02 BEQ $2E50 (if not, branch) C2/2E4E: 29 D0 AND #$D0 (if so, disable Back) C2/2E50: 48 PHA C2/2E51: AD 76 3A LDA $3A76 (# characters in party) C2/2E54: C9 03 CMP #$03 C2/2E56: 68 PLA C2/2E57: B0 06 BCS $2E5F (if 3 or more, branch) C2/2E59: 89 70 BIT #$70 (are any of Normal, Back, or Pincer allowed?) C2/2E5B: F0 02 BEQ $2E5F (if not, branch) C2/2E5D: 29 70 AND #$70 (if so, disable Side attack) C2/2E5F: A2 10 LDX #$10 C2/2E61: 20 47 52 JSR $5247 C2/2E64: 8E 1F 20 STX $201F (save encounter type? 0 = front, 1 = back, 2 = pincer, 3 = side) C2/2E67: 60 RTS ---------- ---------- Formation deciding routine: ;Coming into this routine, all available formations are in A. X = 10h, or 16 dec. ;Also, the M and X flags are set. C2/5247: 5A PHY C2/5248: EB XBA C2/5249: A9 00 LDA #$00 ;zero the high byte of A. C2/524B: A0 03 LDY #$03 ;load Y with 3 for impending loop. C2/524D: EB XBA C2/524E: 0A ASL ;Shift left, put high bit in Carry. High bit = different available formations, starting with Side, Pincer, Back, Normal. C2/524F: EB XBA C2/5250: 90 04 BCC $5256 ;branch if carry not set. This happens if a formation is masked. C2/5252: 7F 69 52 C2 ADC $C25269,X ;table of values below. Adds value listed below + 1. C2/5256: 99 FC 00 STA $00FC,Y ;stores given values at 7E:00FF to 7E:00FC. FF to FC = Side, Pincer, Back, Normal respectfully. C2/5259: E8 INX C2/525A: 88 DEY C2/525B: 10 F0 BPL $524D ;loop back to C2/524D until Y < 0, or rather, FFh. C2/525D: 20 65 4B JSR $4B65 ;loads A with random value from 0 to current value of A - 1. Thanks, Terii, for deciphering this subroutine already. ;) C2/5260: A2 04 LDX #$04 C2/5262: CA DEX ;cycles through available formations until value assigned above is more than the accumulator. C2/5263: D5 FC CMP $FC,X C2/5265: B0 FB BCS $5262 C2/5267: 7A PLY C2/5268: 60 RTS ;If accumulator < 7E:00FF, Side attack. If masked, 7E:00FF will be 0, unable to clear Carry. ;If accumulator < 7E:00FE, Pincer attack. If masked, 7E:00FE == 7E:00FF, so if you don't get a Side attack, you won't get a Pincer attack either. ;If accumulator < 7E:00FD, Back attack. If masked, 7E:00FD == 7E:00FE, so if you don't get a Pincer attack, you won't get a Back attack either. ;If accumulator < 7E:00FC, normal attack. This will always hold true normally, so if X drops to 0 you will get a normal attack. ;Needless to say, Side attacks are the rarest, if they are even available. All odds depend on the masks. ;If no formations are masked, odds for side attack are 30 in 255, Pincer 38 in 255, Back 46 in 255. ;With Back Guard in a fight where Side attack and normal attack are not masked, odds are 30 in 238 for Side attack. ;If you would like to check my odds, do so. Remember though, if the result of the comparison is 0, it will not clear Carry. Subroutines (titles originally by Terii Senshi): Random Number Generator 3 (0 to accumulator - 1) C2/4B65: DA PHX C2/4B66: 08 PHP C2/4B67: E2 30 SEP #$30 C2/4B69: EB XBA C2/4B6A: 48 PHA C2/4B6B: E6 BE INC $BE C2/4B6D: A6 BE LDX $BE C2/4B6F: BF 00 FD C0 LDA $C0FD00,X C2/4B73: 20 81 47 JSR $4781 C2/4B76: 68 PLA C2/4B77: EB XBA C2/4B78: 28 PLP C2/4B79: FA PLX C2/4B7A: 60 RTS Multiplication Function Multiplies low bit of A * high bit of A. Stores result in 16-bit A. C2/4781: 08 PHP C2/4782: C2 20 REP #$20 C2/4784: 8F 02 42 00 STA $004202 C2/4788: EA NOP C2/4789: EA NOP C2/478A: EA NOP C2/478B: EA NOP C2/478C: AF 16 42 00 LDA $004216 C2/4790: 28 PLP C2/4791: 60 RTS Miscellaneous: Table of relevant values at C2/5269, starting at C2/5279 (all values in hex): 1E 07 07 CF ---------- ---------- Preemptive attack routine: ;M and X flags are set coming in. X = formation type, either normal (00) or Side (06) C2:2E9B A5 B1 LDA $B1 C2:2E9D 30 21 BMI $2EC0 ;If bit 7 of $B1 set, no Preemptive. Not sure what this is C2:2E9F AD 4B 2F LDA $2F4B C2:2EA2 89 04 BIT #$04 C2:2EA4 D0 1A BNE $2EC0 ;No Preemptive if no startup messages for special formations (anything but normal attacks) C2:2EA6 8A TXA ;Load A with formation type C2:2EA7 0A ASL C2:2EA8 0A ASL C2:2EA9 09 20 ORA #$20 C2:2EAB 85 EE STA $EE ;Will either equal 20h or 38h C2:2EAD AD 6D 3A LDA $3A6D C2:2EB0 4A LSR C2:2EB1 90 02 BCC $2EB5 ;Branch if no Gale Hairpin C2:2EB3 06 EE ASL $EE ;If Gale Hairpin is equipped, double (result is either 40h or 70h) C2:2EB5 20 5A 4B JSR $4B5A ;Load Accumulator with random number from 0 to 255 C2:2EB8 C5 EE CMP $EE C2:2EBA B0 04 BCS $2EC0 ;No Preemptive if Accumulator >= 7E:00EE C2:2EBC A9 40 LDA #$40 C2:2EBE 04 B0 TSB $B0 ;Set Preemptive attack C2:2EC0 60 RTS ;Preemptive attack odds: ;1 in 8 for normal attack Preemptive ;56 in 256 for Side attack Preemptive ;1 in 4 for normal attack Preemptive w/ Gale Hairpin ;112 in 256 for Side attack Preemptive w/ Gale Hairpin ----------