Users browsing this thread: 1 Guest(s)
ASM hack: improved Gale Hairpin; please help

#1
Posts: 281
Threads: 18
Thanks Received: 13
Thanks Given: 8
Joined: Mar 2014
Reputation: 8
Status
None
Hello,

I present for your titillation:

(This code deals with initializing ATB timers. Check the offset in Assassin's C2 disassembly for orientation.)
Code:
C2/25C1: A5 B0        LDA $B0
C2/25C3: 4C yy xx     JMP $xxyy     (jump to new routine)

New routine at xxyy (21 bytes):
C2/xx00: 0A           ASL
C2/xx01: 30 0C        BMI $xx0F      (skip to next target if Preemptive Attack)
C2/xx03: A9 E2        LDA #$E2
C2/xx05: D9 D0 3C     CMP $3CD0,Y
C2/xx08: F0 05        BEQ $xx0F      (Branch if item #226 (Gale Hairpin) equipped in relic slot 1)
C2/xx0A: D9 D1 3C     CMP $3CD1,Y    (Check Slot 2)
C2/xx0D: D0 03        BNE $xx12      (Branch if Gale Hairpin not equipped)
C2/xx0F: 4C FA 25     JMP $25FA      (Skip to next target)
C2/xx12: 4C C6 25     JMP $25C6      return to where we jumped from

This is a quick and dirty hack that makes item #226 (Gale Hairpin) grant a full ATB bar at the start of battle for the character wearing it, much like the ability called Initiative in FFVIII (or First Strike in FFX).

You see the problem, right? Hardcoding effects to item numbers is pretty lame. It may be excusable in the case of Tintinabar, Moogle Suit etc. since those are pretty unique items, but in this case, I would really like it if I could use the "Raise preemptive atk." bit in Item Special Effects byte 1 to trigger this effect.

Check this out. $3C44 is populated with item effects, but according to Assassin, only bit 0, 1 and 7 are actually checked elsewhere. So what I'd like to do is flip an unused bit in $3C44 and check for that bit instead of an item number. So far what I've come up with is to add a routine with a conditional branch that checks for the original Gale Hairpin bit, then flips bit 3 in $3C44 if it is set:

Code:
Original:
C2/28E7: 9D 44 3C     STA $3C44,X    (load and shift around some item property bytes, then save it in this variable)

Modified:
C2/28E7: 20 yy xx     JSR $xxyy

New routine at C2/xxyy:

C2/xx00: 9D 44 3C   STA $3C44,X
C2/xx03: AD D6 11   LDA $11D6         (load special byte 1)
C2/xx06: 4A         LSR               (shift out least byte into carry)
C2/xx07: 90 09      BCC $xx12         (if no Gale Hairpin, exit)
C2/xx09: A9 04 00   LDA #$0004
C2/xx0C: 1D 44 3C   ORA $3C44,X       (flip bit 3, unused "hp+25%")
C2/xx0F: 9D 44 3C   STA $3C44,X
C2/xx12: 60         RTS

If you look at C2/0FBA, it seems that $11D6 is initialized as the byte detailing the Gale Hairpin effect (among others) from $D8500A,X.

And if you look at C2/28D7, it also seems that $11D6 is partially used to populate $3C44 (actually just bit 7, which represents the Dragon Horn effect).

It also seems to be copied to $3A6D, which is a global variable checked by the "raise preemptive rate" and "disable back/pincer attacks" parts of the code). $3A6D is not an array indexed by actor ID, just the one byte.

The problem is, I can't get this conditional branch to work! If I leave it out and just do the ORA unconditionally, the bit seems indeed flipped because writing code to check for it instead of the item number does indeed cause (every) character to gain a full ATB bar.
I've tried checking $D8500A,X instead, no dice.
I've tried using BIT #$01 and BEQ instead of LSR/BCC, no dice. I'm at my wit's end. Maybe I misunderstand what the index register signifies in this part of the code. Maybe I'm checking the wrong byte. Help me troubleshoot, please?
  Find
Quote  

#2
Posts: 2,769
Threads: 88
Thanks Received: 24
Thanks Given: 87
Joined: Jun 2009
Reputation: 25
Status
None
there is no need for a double post, it may have been an accident so don't sweat it

the other post has now been deleted (since its the exact same thing)


"Sometimes ninjas do wrong to each other, and in dat way the force of tha earf' comes around da moon - and at that presence, da dirt, it overshadows the grass, so you're like, I can't cut dis grass, there's no sun comin' through. So in order to enable each other the two fruits have to look each other in da eye and understand we can only be right, as da ripe is wrong, you know what I mean?"

-HNIC
Quote  

#3
Posts: 290
Threads: 3
Thanks Received: 40
Thanks Given: 1
Joined: Apr 2012
Reputation: 9
Status
None
Your direct page register isn't zero (see C2/286E). What you might try doing is changing your LDA $11D6 to just LDA $D6.

It shouldn't mess with anything else you're doing, but if it does, you may need to zero the D register for the purposes of your custom function.

On second thought, that may not make a difference. It's worth a shot though, if for nothing else than added efficiency.


GET A SILK BAG FROM THE GRAVEYARD DUCK TO LIVE LONGER.

Brave New World
  Find
Quote  

#4
Posts: 259
Threads: 3
Thanks Received: 5
Thanks Given: 1
Joined: Jun 2013
Reputation: 6
Status
None
Oooh... BTB likes this idea.

BTB is also now apparently talking in the third person.


"You don't have to be a vampire to die like one... b*t*h." -Simon Belmont
Quote  

#5
Posts: 281
Threads: 18
Thanks Received: 13
Thanks Given: 8
Joined: Mar 2014
Reputation: 8
Status
None
Thanks for the reply, Synchysi. I tried changing the LDA $11D6 to LDA $D6. Unfortunately it makes no difference. It still causes all party members to gain Initiative even though only one is wearing the relic. I guess $11D6 bit 1 is set globally whenever anyone equips a Gale Hairpin. I'm putting this on the backburner for now since it seems I'm at a frustrating dead-end.

BTB, you're welcome to use my ugly version of the hack in BNW until I can get the proper version working. I think this hack doesn't really get interesting until you can set it as a property on a couple different items. It'd be nice to have on a few weapons, for example.

The idea is to combine this with another hack of mine that combines the Gale Hairpin and Back Guard bits into one, thus freeing up the original "raise preemptive atk." bit for this purpose. It's a simple fix that can be done inline, and it only has the unfortunate side effect of making pre-emptive attacks very slightly less common.

By the way, Synchysi, did you ever get around to commenting and collating the bugfixes and tweaks you coded for BNW? I'm still waiting to see that Sketch code and many other cool things you've done. You've done some astounding work on FFVI and I'd hate to see it locked away in an ips file. It would be cool to see some of your bugfixes released as standalone patches. Off the top of my head, the Heal Rod targeting, earrings not affecting healing spells, the poison counter not resetting with removal, etc.
  Find
Quote  

#6
Posts: 259
Threads: 3
Thanks Received: 5
Thanks Given: 1
Joined: Jun 2013
Reputation: 6
Status
None
I'd rather just wait and see where this hack takes you, especially since I think we're done screwing with BNW for a little while outside of fixing any bugs that get reported.


"You don't have to be a vampire to die like one... b*t*h." -Simon Belmont
Quote  

#7
Posts: 175
Threads: 11
Thanks Received: 10
Thanks Given: 8
Joined: May 2013
Reputation: 13
Status
Well-Fed
What about using an additional bit? $11D7/1 is used as part of the Earrings functionality, so it doesn't appear to actually be free, but it looks like there are two free bits on $11D9 (bits 5 and 6, between x2 GP and 'make body cold'), and $11D8/7 may be free as well.

I'll be the first to admit that I've only barely delved into this part of the code, but if it works it also offers the advantage of separating out the Initiative ability from the Gale Hairpin's existing preemptive attack boost, which probably makes it more appealing in a general sense.


Current Project: FF6: Tensei | Discord ID: TristanGrayse
  Find
Quote  

#8
Posts: 281
Threads: 18
Thanks Received: 13
Thanks Given: 8
Joined: Mar 2014
Reputation: 8
Status
None
Hi GrayShadows and thank you for your suggestion. I tried abandoning the approach to check for $3C44,X altogether, and instead put in a check for bit 5 of $11D9 directly (that is, instead of checking for a matching item number in either relic slot, I just check for bit 5 of $11D9). This works in a strange way: if the party leader has a Gale Hairpin equipped, the entire party will gain Initiative. If a character has Gale Hairpin equipped but is not the party leader, it has no effect at all.

I also tried adding in a check for a matching item number to flip the bit in $3C44,X (which then triggers the Initiative effect) which had no effect at all.

As I keep trying more things that don't work, I feel like I'm at least narrowing down the problem, but I have to conclude that I don't quite understand how the code for battle effects from items works just yet. Or admittedly, the loop that deals with initializing battle timers.
  Find
Quote  

#9
Posts: 290
Threads: 3
Thanks Received: 40
Thanks Given: 1
Joined: Apr 2012
Reputation: 9
Status
None
(03-03-2014, 09:00 PM)seibaby Wrote: By the way, Synchysi, did you ever get around to commenting and collating the bugfixes and tweaks you coded for BNW? I'm still waiting to see that Sketch code and many other cool things you've done. You've done some astounding work on FFVI and I'd hate to see it locked away in an ips file. It would be cool to see some of your bugfixes released as standalone patches. Off the top of my head, the Heal Rod targeting, earrings not affecting healing spells, the poison counter not resetting with removal, etc.

I haven't. I'm an exceptionally lazy person. Sweat

The only one I've actually put out for public consumption is the esper restrictions hack. I still intend to clean up the rest, but I don't know when I'll get around to doing so.

(03-04-2014, 09:51 AM)seibaby Wrote: I tried abandoning the approach to check for $3C44,X altogether, and instead put in a check for bit 5 of $11D9 directly (that is, instead of checking for a matching item number in either relic slot, I just check for bit 5 of $11D9). This works in a strange way: if the party leader has a Gale Hairpin equipped, the entire party will gain Initiative. If a character has Gale Hairpin equipped but is not the party leader, it has no effect at all.

If I get a chance, I'll poke around at this later and see if I can figure something out.


GET A SILK BAG FROM THE GRAVEYARD DUCK TO LIVE LONGER.

Brave New World
  Find
Quote  

#10
Posts: 290
Threads: 3
Thanks Received: 40
Thanks Given: 1
Joined: Apr 2012
Reputation: 9
Status
None
I got it working, though I couldn't find a way to use the Gale Hairpin bit - likely because it's a global effect, so the game doesn't store that particular bit on a character-by-character basis. The bit I used is the last one under the "Special 3" header in usME (right under "Protect weak allies").

I also changed the jump point purely for testing purposes. It should be easy to readjust to how you had it/want it.

Finally, it could probably be made more efficient somewhere, but I'm not going to be able to mess with that tonight.

Code:
org $C225F7
JSR $A65A

org $C2A65A
STA $3219,Y
LDA $3C58,Y
ASL
BCC Exit
LDA #$FF
STA $3219,Y

Exit:
RTS


GET A SILK BAG FROM THE GRAVEYARD DUCK TO LIVE LONGER.

Brave New World
  Find
Quote  



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite