Users browsing this thread: 4 Guest(s)
Condensing Spell List in Battle

#19
Posts: 175
Threads: 11
Thanks Received: 10
Thanks Given: 8
Joined: May 2013
Reputation: 13
Status
Well-Fed
Well, I mean, BNE would work just as well, but BRA is working as intended there -- .checkLoreLoop is self-contained, and will ALWAYS loop unless it meets one of its two exit requirements: X/Y = #$0138 (and therefore we've checked every single slot), or, in .findNextSpell, Y = #$013C, in which case there are no more spells to shuffle up to fill empty slots with.

The other suggestions are definitely good, though! CondenseSpellLists is now down to 87 bytes, and with that and a little other tidying up, calculateMPDeduction is now down to 97.


Code:
hirom
;header

!freespace_C2_0 = $C2A65A        ; 90 bytes needed
!freespace_C2_1 = $C2FAB0        ; 103 bytes needed

org $C2256D                
JSR condenseSpellLists ; this was originally a JSR to modify available commands; we'll be JMPing to that
                            ; at the end of the modified code so that RTS comes back to the right spot


                            
org $C24F11
REP #$10
LDA $3A7B                ; (get attack #) -- the new code will do this again in a bit, but
CPX #$0008                ; we need it in A now or we'll break monster casting
BCS fka_4F47            ; (branch if it's a monster attacker.  they don't have
                        ; menus containing MP data, nor relics that can
                        ; alter MP costs.)
                        ; This was originally in the middle of the code, but
                        ; there shouldn't be any issues doing this check first,
                        ; and it makes the new code MUCH smoother.
JMP calculateMPDeduction

org $C24F47
fka_4F47:

                            
org !freespace_C2_0
print "New code CondenseSpellLists starts at: ",pc
reset bytes

condenseSpellLists:
PHX                ; This is our character ID coming in
PHP
LDY #$04        ; this is the index of the first Spell slot in the character's spell list
TYX                ; X is going to be our 'write-space' indexREP
REP #$10

    .checkLoreLoop        ; don't need to actually check the last slot of either list
    LDA ($F2),Y
    INC
    BNE .checkNextLore

        .findNextLore
        INY #4
        CPY #$00DC    ; if we've hit the first Lore slot, there are no more spells to copy back
        BEQ .noMoreSpells    ; so jump out, reset $F0 to start our lores
        CPY #$013C    ; this is after the last Lore slot, so if we've gone that far, there are no more spells to copy back
        BEQ .noMoreLores
        LDA ($F2),Y
        INC
        BEQ .findNextLore

    PHY            ; we'll be pushing and pulling within the loop, but we need to know
                ; where it started so we can blank out the slot we copied from
    CLC
    REP #$20
    
        .copyNextLore
        LDA ($F2),Y    ; Yes, we just did this, but we need to do it within this loop, too
        PHY            ; this stores our Y location, i.e. the next slot with a spell learned
        TXY
        STA ($F2),Y
        PLY            ; back to our 'write from' location
        INY    #2        ; and gets the next byte
        INX #2
        BCS .doneCopy
        SEC
        BPL .copyNextLore    ; if we haven't done four bytes, loop back and grab the next
        .doneCopy
        
    SEP #$20    
    PLY            ; this is the first byte of the slot we copied from
    TDC
    STA ($F4),Y    ; this zeroes out the MP cost
    DEC
    STA ($F2),Y    ; and blanks out the spell we copied from
        
    BRA .weCopiedALore
    .checkNextLore
    INX #4
    .weCopiedALore
    TXY                ; and then copy it over to Y for our next loop through
    CPY #$00D8        ; if this is the last spell slot
    BEQ .checkNextLore    ;loop back up and INX again so we skip over it and point at our first Lore slot
    CPY #$0138
    BEQ .noMoreLores
    BRA .checkLoreLoop
    
.noMoreLores
PLP    
PLX
JMP $532C

.noMoreSpells
TYX            ; reset our write-space index for the first Lore slot
BRA .checkLoreLoop

print "CondenseSpellLists ends at: ",pc," and used ",bytes," bytes of space."



org !freespace_C2_1
calculateMPDeduction:

print "New code CalculateMPDeduction starts at: ",pc
reset bytes

REP #$10            ; (Set 16-bit X and Y)
LDA $3A7A            ; (get command #)
CMP #$19
BEQ .calculateSummon    ; (branch if it's Summon)
CMP #$0C
BEQ .calculateLore    ; (branch if it's Lore)
CMP #$02
BEQ .calculateMagic    ; (branch if it's Magic)
CMP #$17
BNE fka_4F53        ; (branch if it's not X-Magic)

.calculateMagic
LDA $3A7B            ; (get attack #)
STA $F0                        ; save our spell ID in scratch memory
LDA #$04                    ; four bytes per index

.loreEntersHere
REP #$20
CLC
ADC $302C,X                 ; get the start of our character's magic list (index #0 is esper)
STA $F2                        ; this points out our first Magic slot
INC #3
STA $F4                        ; and this points at our first MP cost slot
SEP #$20
PHY
LDY $00

    .findSpell
    LDA ($F2),Y
    CMP $F0
    BEQ .getMPCost
    INC
    BEQ fka_4F53
    INY #4
    BRA .findSpell
    
.getMPCost
LDA ($F4),Y
PLY
BRA fka_4F45

.calculateLore
LDA $3A7B                    ; (get attack #)
SEC
SBC #$8B                    ; turn our raw spell ID into a 0-23 Lore ID
STA $F0
LDA #$DC                    ; this is our first Lore slot in the character's spell list
BRA .loreEntersHere

.calculateSummon            ; rather than looking for the spell ID, I'm operating under
REP #$20                    ; the assumption that if someone is using Summon, it's already
LDA $302C,X                    ; checked for the equipped Esper, so I'm just loading the MP cost
TAX                            ; from the first entry in the character's list
SEP #$20
LDA $0003,X
BRA fka_4F45


fka_4F45: JMP $4F54            ; (clean up stack and exit)
fka_4F53: JMP $4F53

print "CalculateMPDeduction ends at: ",pc," and used ",bytes," bytes of space."


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



Messages In This Thread
Condensing Spell List in Battle - by GrayShadows - 09-14-2017, 06:27 PM
RE: Condensing Spell List in Battle - by madsiur - 09-14-2017, 07:22 PM
RE: Condensing Spell List in Battle - by Warrax - 09-14-2017, 08:09 PM
RE: Condensing Spell List in Battle - by assassin - 09-14-2017, 08:42 PM
RE: Condensing Spell List in Battle - by Warrax - 09-15-2017, 12:33 AM
RE: Condensing Spell List in Battle - by assassin - 09-15-2017, 04:33 AM
RE: Condensing Spell List in Battle - by assassin - 09-17-2017, 04:01 AM
RE: Condensing Spell List in Battle - by assassin - 09-17-2017, 05:34 PM
RE: Condensing Spell List in Battle - by BTB - 09-17-2017, 04:05 AM
RE: Condensing Spell List in Battle - by assassin - 09-18-2017, 04:28 AM
RE: Condensing Spell List in Battle - by GrayShadows - 09-18-2017, 10:59 AM
RE: Condensing Spell List in Battle - by assassin - 09-18-2017, 12:45 PM
RE: Condensing Spell List in Battle - by assassin - 09-18-2017, 10:15 PM
RE: Condensing Spell List in Battle - by BTB - 09-19-2017, 08:32 PM
RE: Condensing Spell List in Battle - by Warrax - 09-20-2017, 11:16 AM
RE: Condensing Spell List in Battle - by Warrax - 09-21-2017, 01:06 AM
RE: Condensing Spell List in Battle - by seibaby - 09-20-2017, 06:00 PM
RE: Condensing Spell List in Battle - by assassin - 09-20-2017, 10:39 PM
RE: Condensing Spell List in Battle - by assassin - 09-21-2017, 12:59 PM
RE: Condensing Spell List in Battle - by Warrax - 09-21-2017, 04:35 PM
RE: Condensing Spell List in Battle - by Warrax - 09-23-2017, 12:12 AM
RE: Condensing Spell List in Battle - by assassin - 09-23-2017, 01:21 AM
RE: Condensing Spell List in Battle - by Warrax - 09-23-2017, 07:45 AM
RE: Condensing Spell List in Battle - by Warrax - 09-23-2017, 03:04 PM
RE: Condensing Spell List in Battle - by seibaby - 09-23-2017, 05:38 PM
RE: Condensing Spell List in Battle - by assassin - 09-23-2017, 05:50 PM
RE: Condensing Spell List in Battle - by Warrax - 09-23-2017, 06:04 PM
RE: Condensing Spell List in Battle - by Warrax - 09-24-2017, 01:47 PM
RE: Condensing Spell List in Battle - by Warrax - 10-04-2017, 05:29 PM
RE: Condensing Spell List in Battle - by assassin - 10-04-2017, 06:43 PM
RE: Condensing Spell List in Battle - by assassin - 10-04-2017, 08:44 PM
RE: Condensing Spell List in Battle - by Warrax - 10-04-2017, 10:01 PM
RE: Condensing Spell List in Battle - by Warrax - 10-04-2017, 11:11 PM
RE: Condensing Spell List in Battle - by assassin - 10-04-2017, 11:46 PM
RE: Condensing Spell List in Battle - by assassin - 10-05-2017, 03:51 AM
RE: Condensing Spell List in Battle - by assassin - 10-05-2017, 09:27 PM
RE: Condensing Spell List in Battle - by assassin - 10-05-2017, 09:51 PM
RE: Condensing Spell List in Battle - by assassin - 10-06-2017, 08:20 PM
RE: Condensing Spell List in Battle - by assassin - 10-07-2017, 01:08 AM
RE: Condensing Spell List in Battle - by seibaby - 10-24-2017, 03:36 PM
RE: Condensing Spell List in Battle - by assassin - 10-30-2017, 07:38 PM
RE: Condensing Spell List in Battle - by assassin - 10-31-2017, 01:23 AM
RE: Condensing Spell List in Battle - by assassin - 10-31-2017, 02:42 PM
RE: Condensing Spell List in Battle - by BTB - 11-23-2017, 11:42 PM
RE: Condensing Spell List in Battle - by Warrax - 11-24-2017, 12:15 AM
RE: Condensing Spell List in Battle - by fw4210 - 07-23-2021, 03:48 AM
RE: Condensing Spell List in Battle - by fw4210 - 07-24-2021, 02:05 PM
RE: Condensing Spell List in Battle - by fw4210 - 07-25-2021, 06:32 PM
RE: Condensing Spell List in Battle - by fw4210 - 07-25-2021, 08:58 PM
RE: Condensing Spell List in Battle - by Warrax - 07-25-2021, 08:43 PM
RE: Condensing Spell List in Battle - by fw4210 - 08-02-2021, 08:13 PM
RE: Condensing Spell List in Battle - by fw4210 - 08-10-2021, 02:51 PM

Forum Jump:

Users browsing this thread: 4 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite