hirom header ; (Randomize Targets function. selects entire monster or character parties (or both) at a time. ; calling function will later refine the targeting.) ; (calling the character side 0 and the monster side 1, it looks like this up through C2/598A: ; side chosen = (monster caster) XOR Controlled XOR Charmed XOR "Cursor start on opposition" ; XOR Muddled ) ; (values DURING function -- not coming in or leaving it: ; bit 7 of $B8 = side to target. characters = 0, monsters = 1, special/opposing(?) characters = 1 ; bit 6 of $B8 = 1: make both sides eligible to target) ; C2/5937: 64 B9 STZ $B9 (clear enemy targets) ; C2/5939: 7B TDC (Accumulator = 0) ; C2/593A: E0 08 CPX #$08 (carry set if caster is monster? note that "caster" can ; also mean "reflector", in which cases a good part of ; this function will be skipped..) ; C2/593C: 6A ROR ; C2/593D: 85 B8 STA $B8 (Bits 0-6 = 0. Bit 7 = 1 if monster caster, 0 if character) org $C2593F LDA $BA ASL ASL ASL ; bit 5 only seems to be set by Reflection BMI reflect_entry ; if it's set, branch. once the spell's already hit the ; Wall Ring, we (generally) don't care about the reflector's ; status, and they're not necessarily the caster anyway. LDA $32B9,X ; who's Controlling this entity? CMP #$FF BEQ notControlled ; branch if nobody controls them TDC ; don't let pending Control removal count against it notControlled: EOR $3395,X ; Bit 7 will hold: (NOT Controlled) XOR (NOT Charmed), ; aka Controlled XOR Charmed AND #$80 ; isolate Bit 7: 1 = Toggle, 0 = Don't EOR $B8 STA $B8 ; possibly toggle top bit of $B8 LDA $3018,X BIT $3A40 ; is caster a special type of character? ; from all i've seen, this means a character acting as ; an enemy, like Gau returning from a Veldt leap, or ; Shadow in the Colosseum. BEQ noCharEnemy ; if not, branch LDA #$80 ; if so.. here comes another toggle! EOR $B8 STA $B8 ; toggle top bit of $B8 noCharEnemy: LDA $BB ; targeting byte AND #$0C ; isolate "Autoselect both parties" and "Autoselect one party" CMP #$04 ; is "autoselect both parties" the only bit of these two set? BEQ targetBoth ; if so, branch LDA $3EE4,X ; Status byte 1 LSR LSR BCC notBoth ; Branch if not Zombie targetBoth: LDA #$40 TSB $B8 ; make both monsters and characters targetable notBoth: LDA $BB ; targeting byte ASL ; put into top bit of A AND #$80 ; isolate "cursor start on enemy" (read: OPPOSITION, not monster) EOR $B8 STA $B8 ; toggle top bit yet again LDA $3EE5,X ; Status byte 2, with Muddled in Bit 5 ASL ASL reflect_entry: AND #$80 EOR $B8 ; possibly toggle top bit from $B8 ; STA $B8 (no longer need these two instructions ...) ; LDA $B8 (... as A holds needed value) rep 4 : NOP ; 4 bytes to spare. nice. print pc