hirom header !tempData = $00E8 org $c223e0 jmp relocated ; -------------- org $c2fac0 relocated: CMP #$20 ; any Golem or Dog flag active? BCC equipMain ; if not, embark on a minor detour to choose animation ; based on gear (and character base) stats JSR $51F0 ; X = position of highest (and only) bit that is set ; displaced Square instruction jmp $23E3 ; return to caller to store dodge animation equipMain: PLY ; restore original target 0, 2, 4, 6 index PHY ldx #$04 clearLoop: stz !tempData,X ; zero our array that holds the total Evades/MBlocks ; associated with each equipment dodge animation ; (and no animation). dex bpl clearLoop LDA $3ED9,Y ; 0-15 roster position of this party member rep #$10 phy ; save target's 0, 2, 4, 6 index jsr $30DD ; Get ID of character in roster slot A XBA LDA #$16 ; 22 startup bytes per character JSR $4781 TAX ; X indexes character startup block lda $11A2 lsr ; is attack physical or magical? LDA $ED7CAD,X ; character's base Evade bcs saveBase ; branch if physical attack. ; NOP this if trying to reflect an Evade-bugged vanilla. LDA $ED7CAE,X ; character's base MBlock saveBase: sta !tempData ; in start of array, initialize the Evade/MBlock ; associated with no equipment dodge animation. ldy #$0005 equipLoop: rep #$21 ; Set 16-bit A, clear Carry lda $01,s tax ; X = initial Y index of target tya ; 0-5 equipment slot iterator ; clc adc $3010,X ; ...plus offset to character info block tax sep #$20 lda $161F,X ; get item ID in this relic/equip slot XBA LDA #$1E JSR $4781 ; multiply index by size of item data block TAX phy ; preserve 0-5 equipment slot iterator ldy $11D0 phy ; save variables that a function call will overwrite. ; might be safe to clobber them. tdc tay ; we need Y=0 for an index below, so this works ... sty $11D0 ; ... nicely for a 16-bit zeroing. LDA $D8501B,X ; item byte 1B, special action jsr helper_108E ; fill $11D0-$11D1 with equipment parry/dodge animation ; flags lda $11A2 lsr ; magical or physical attack? rep #$20 LDA $D8501A,X ; equipment or relic Evade/MBlock byte in bottom of A ;phx bcc doMBlock ; branch if magical ; bra evadeBugEntry ; OVEWRITE next instruction with these two if... ; NOP ; ...trying to reflect an Evade-bugged vanilla. AND #$000F ; isolate evade ASL TAX ; evade nibble * 2, turn into pointer bra getBoost doMBlock: iny ; index magical dodge animation flags evadeBugEntry: AND #$00F0 ; isolate mblock LSR LSR LSR TAX ; mblock nibble * 2, turn into pointer getBoost: LDA $C21105,X ; get actual evade boost/reduction of item pha ldx #$0000 ; default to 0 index for tempData array lda $11D0,Y ; get our block/parry animation flag for current piece of ; equipment. $11D0 has physical flags, and $11D1 magical. and #$00ff beq noAnimFlag jsr $51F2 ; get position of highest bit set inx ; convert index from 0-3 to 1-4 noAnimFlag: pla sep #$20 bmi noAdd ; don't even bother to count it if the Evade/MBlock ; is a reduction (FFNNh) as opposed to a boost. clc adc !tempData,X ; add to overall Evade or MBlock of gear having this ; block/parry category sta !tempData,X noAdd: ply sty $11D0 ; restore variables overwritten by C2/108E call. ply ; restore 0-5 equipment/relic slot dey ; point to next one bpl equipLoop ply ; restore target's 0, 2, 4, 6 index sep #$10 ; set 8-bit X and Y ldx #$00 ; point to start of our probabilities block for function ; call jsr clone_5247 ; choose between Evade/MBlock -weighted equipment dodge ; animations and lack thereof (i.e. plain "Miss"). ; 0-4 result in X. txa ; refresh the CPU flags beq exit ; branch if result = 0, i.e. plain "Miss" chosen TYA LSR TAY ; Y = Y DIV 2, so it won't matter if Y was incremented ; above. it now holds a 0-3 character #. TXA ; INC STA $00AA,Y ; save the dodge animation type for this character exit: PLY rts ; =============== helper_108E: phx ; balance off the PLX that's late in the partial function ; we're executing jmp $108E ; set up equipment miss animation flags in $11D0 and $11D1 ; based on our current, single piece of equipent / relic. ; =============== ; Choose dodge/parry animation (or lack thereof) based on the provided list ; of total Evades or MBlocks of equipment/relics with each animation ; (or for animation-less gear, combined with character base Evade/MBlock). ; Returns dodge/parry animation in X: 0 = None (plain "Miss"), ; 1 = Knife parry, 2 = Sword parry, 3 = Shield block, 4 = Cape wave clone_5247: PHY lda #$00 ;LDY #$00 tay typeLoop1: clc adc !tempData,X ; add chance to get this dodge/parry type STA $00FB,Y ; build an array that determines which ranges of ; random numbers will result in which dodge/parry ; animations. INX ;DEY INY CPY #$05 BNE typeLoop1 ; Check for all 5 types, including no animation JSR $4B65 ; random #: 0 to A - 1 , where A is the denominator ; of our probabilities ;LDX #$05 LDX #$FF ; first read will be from $FB,0 typeLoop2: ;DEX INX CMP $FB,X BCS typeLoop2 ; Check next type if A >= $FB,X PLY RTS ; Return X = Dodge / Parry type to use