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 6 of $B8 = 1: make both sides eligible to target ; Y = # of times to toggle targeted party, 0 or even # gives normal characters, ; odd gives monsters and characters acting as enemies ) ; 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..) org $C2593C STZ $B8 ; we need Bit 6 to start at 0 PHY ROL TAY ; start Toggle Incrementor at 0 if character caster/reflector, ; 1 if monster LDA $BA BIT #$10 ; this bit only seems to be set by Reflection BNE 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 iny 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 iny notControlled: LDA $3395,X ; is anybody Charming this entity? BMI notCharmed ; branch if not iny notCharmed: 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 bpl skip ; branch if neither or both are the case reflect_entry: iny skip: tya ; get toggle count PLY lsr ; is it odd or even? tdc ror ; A = 00h if toggle count zero/even, 80h if odd ; bcc noToggle ; LDA #$80 ORA $B8 ; put Bit 6 of $B8 into A, and keep Bit 7 of A. ; EOR would also work here. ; STA $B8 ; toggle top bit of $B8 ; noToggle: rep 12 : NOP ; 12 bytes to spare! nicer! print pc