Users browsing this thread: 2 Guest(s)
A Guide to Ability Learning

#35
Posts: 383
Threads: 34
Thanks Received: 10
Thanks Given: 13
Joined: Dec 2018
Reputation: 18
Status
Moog
Sorry I was being too technical about the carry.  There's a much easier way to explain it, if the number you're comparing against is larger than your current number, the carry is set.  If it's smaller, the carry is not set.  This won't be important for natural learning, but does come up in other ways, like if you want to check if it's at LEAST a certain character number (the code does this often to handle guests).

After a CMP, you can throw all sorts of conditional situations at your code.

BEQ (Branch if Equal) = The compared number and your number are the same.  In this case, we've found the character we're looking for.
BNE (Branch if Unequal) = The compared number and your number are different.  For instance, if the game is running Celes's check, it will skip the Terra code.
BCC (Branch if Carry Clear) = The compared number is smaller than your number.  Or put another way, your number is bigger than the checked number.  In this context, it could be used to check if the character is a guest.  Not really important to your current goal, though.
BCS (Branch if Carry Set) = The compared number is larger than your number.  Sometimes used by the spell learning system to distinguish between Attack, Effect, and Healing spells, and has lots of uses elsewhere.  Again, not so important to your current goal.

As for your question, we'll be putting all of the relevant code to your tweak in the same space (this makes it easier to document, rather than having it all over the rom in bits and pieces), but the C0 jump will be going to a different spot than the C2 jump will.
Let's build a learning dance subroutine!
Code:
{Pointers}
*D0/95FC: 5C AA 96 D0     JML $D096A2    {Locke's dance learning on Recruit}
...
*D0/9608: 5C D4 96 D0      JML $D096D4  {Locke's dance learning on Level Up}
...
{Locke's dance learning on Recruit}
D0/96A2:    01 04 0A 0E 12 1C 2C 46              DATA  {Levels at which dances are learned}
            {I just grabbed the swordtech levels from my project, you'll want to tweak these}

D0/96AA:    64 1B        STZ $1B
D0/96AC:    A6 00        LDX $00
D0/96AE:    BF A2 96 D0    LDA $D096A2,X    (Natural Dances)    [We made this table up above]
D0/96B2:    D9 08 16      CMP $1608,Y        {Character's current level}
D0/96B5:    F0 02        BEQ $96B9   {Skip the next line}
D0/96B7:    B0 0A        BCS {If level is lower, exit}
D0/96B9:    E6 1B        INC $1B
D0/96BB:    E8          INX    {Increase our counter by one}
D0/96BC:    E0 08 00      CPX #$0008  {Have we checked 8 dances?}
D0/96BF:    F0 02        BEQ $96C3   {If so, skip the next line}
D0/96C1:    80 EB        BRA $96AE   {Otherwise, check another dance}
D0/96C3:    A5 1B        LDA $1B
D0/96C5:    AA          TAX
D0/96C6:    AD 4C 1D      LDA $1D4C      (known Dances)
D0/96C9:    1F 2C A2 C0    ORA $C0A22C,X   {This is a bitfield table for Blitzes and SwdTechs, but it'll work here too}
D0/96CD:    8D 4C 1D      STA $1D4C      (new known Dances)
D0/96D0:    5C 95 A1 C0 JML $C0A195 (This goes back up to the RTS 60)
{This is basically copied verbatim from the SwdTech learning code, save which table and variable is referenced.  There's no reason it shouldn't work for Dance}
{Locke's dance learning on Level Up}
{This one's a lot trickier, because we can't use the subroutine that was shared by Blitz and SwdTech... for several reasons}
D0/96D4:    A9 01        LDA #$01
D0/96D6:     85 EE        STA $EE        (start by marking Dance #0)
D0/96D8:     EB           XBA            (get current level from top of A?)
D0/96D9:     DF A2 96 D0  CMP $D096A2,X  (does level match the one in our Dance table?)
D0/96DD:    F0 05        BEQ $6232      (if so, branch)
D0/96DF:    E8           INX            (otherwise, move to check next level)
D0/96E0:    06 EE        ASL $EE        (mark the next Dance as learned instead)
D0/96E2:    90 F5        BCC $96D9      (loop for all 8 bits.  if Carry is set, we've
                                     checked all 8 to no avail, and $EE will be 0,
                                     indicating no Dance is learned)
D0/96E4:    A5 EE        LDA $EE        (get the Dance bitfield.. where the number
                                     of the bit that is set represents the number of
                                     the SwdTech/Blitz to learn)
D0/96E6:    D0 04        BNE $96EC      (if a Dance is learned this level, skip the next line)
D0/96E8:    5C 21 62 C2     JML $C0A195    (This is our Return to Sender!)
                        (It goes to an RTS in the C2 bank, one used by Terra's learning so we know we won't touch it)
D0/96EC:    0C 4C 1D     TSB $1D4C      (if so, enable the newly learnt Dance)
D0/96EF:    D0 F7        BNE $96E8      (if it was already enabled, return to sender)
                        [If a crash occurs, try changing this value "F7".  It's supposed to be -9, but I have trouble with these]
D0/96F1:    A9 40        LDA #$40
D0/96F3:    04 F0        TSB $F0
D0/96F5:    D0 F1        BNE $96E8      (branch to RTS if we already learned another Dance.)
                        [If that other number doesn't fix a crash, check this one "F1".  It's supposed to be -F, to branch back F bytes]
D0/96F7:    A9 40        LDA #$40
D0/96F9:    5C D4 5F C2  JML $C25FD4      (buffer and display "Mastered a new dance!" message)
D0/96FD:    EA            NOP            [Just here to mark we're done with our custom code, you can leave this off if you wish]
{Herein we see some trouble with using freespace that isn't in the bank of the existing code.}
{If we had used freespace in C2, we could have relocated the SwdTech/Blitz table and expanded it with another 8 entries for dance}
{Then, we could reuse the subroutine to check for 'blitz learned this level' that was already present in C2}
{In the D0 bank, we are forced to recreate the essence of this subroutine}
I'm not sure this code will work, but I'm hopeful.  You should try it and see if it does what you want; it's built on the principles I learned from GrayShadows' work (and from Assassin's and NovaliaSpirit's disassemblies).  You'll also want to try counting the bytes for branches... when you see a D0 04, count the next four bytes to see that it's pointing to the command you want it to land on.  For branches higher than $80, count up to $100 as you move backwards; when you hit $100 that's the byte the branch should be pointing to.

Also... be ABSOLUTELY sure you have a copy of your ROM from before you started hexing stuff like this.  You'll need it to make a difference patch to repair damages if something unexpected happens.  In fact, once you think you've got it working, you should probably make that reversal patch right away.  Using LunarIPS, select the hexed ROM as the original and your previous version as the "patch", and it'll give you a nice reversal patch that'll work so long as you don't do other stuff in that same section of the ROM.
  Find
Quote  
[-] The following 1 user says Thank You to C-Dude for this post:
  • Mutteo (07-20-2020)



Messages In This Thread
A Guide to Ability Learning - by Sutebenukun - 10-18-2010, 05:10 PM
RE: Hacking: A Guide to Ability Learning - by Mudkippower1 - 02-05-2012, 07:05 PM
RE: Hacking: A Guide to Ability Learning - by Mudkippower1 - 02-06-2012, 08:57 AM
RE: Hacking: A Guide to Ability Learning - by Mudkippower1 - 02-06-2012, 05:26 PM
RE: Hacking: A Guide to Ability Learning - by Mudkippower1 - 02-07-2012, 07:57 AM
RE: Hacking: A Guide to Ability Learning - by Mudkippower1 - 02-07-2012, 08:48 AM
RE: A Guide to Ability Learning - by Mutteo - 07-09-2020, 03:00 PM
RE: A Guide to Ability Learning - by madsiur - 07-10-2020, 10:46 PM
RE: A Guide to Ability Learning - by GrayShadows - 07-11-2020, 10:39 PM
RE: A Guide to Ability Learning - by Mutteo - 07-18-2020, 08:40 PM
RE: A Guide to Ability Learning - by C-Dude - 07-19-2020, 01:49 PM
RE: A Guide to Ability Learning - by Mutteo - 07-19-2020, 08:52 PM
RE: A Guide to Ability Learning - by C-Dude - 07-20-2020, 12:56 AM
RE: A Guide to Ability Learning - by Mutteo - 07-20-2020, 09:55 PM
RE: A Guide to Ability Learning - by C-Dude - 07-20-2020, 10:57 PM

Forum Jump:

Users browsing this thread: 2 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite