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 $3EE5,X ; Status byte 2, holds Muddled in Bit 5. ASL EOR $BB ; "cursor start on enemy" (read: OPPOSITION, not monster) is ; held in Bit 6 ASL PHA 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 $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 $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 EOR $01,S ; above XOR (Muddled XOR "Cursor start on enemy") reflect_entry: AND #$80 ; isolate Bit 7 of our calculations: 1 = Toggle, 0 = Don't EOR $B8 STA $01,S ; possibly toggle top bit from $B8 PLA ; could drop the "STA $01,S" if i was willing to put this ; blasted instruction at the end of the function, and ; shift 29 bytes of code in the process. or i could use ; $B9 instead of the stack as a scratch variable, and ; push down the opening "STZ $B9" to near the "STZ $B8". rep 11 : NOP ; 11 bytes to spare! nicer! print pc