Users browsing this thread: 1 Guest(s)
Equipment Check Event Command

#1
Posts: 3,966
Threads: 279
Thanks Received: 234
Thanks Given: 56
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
Equipment Check Event Command
version 1.1
released on 04/28/2016
Apply to a FF3us
wiki entry
Download


Files

equipcheckEE.asm: For implementation in another bank than $C0
equipcheckC0.asm: For implementation in bank $C0

Apply with xkas 0.06
Command example: xkas equipcheckEE.asm romname.smc

Space used

$C0 implementation: 0xC1 bytes (bank $C0)
$XX implementation: 0x07 bytes (bank $C0), 0xBD bytes (bank $XX)

Description

This event command ($66) allows to check equipment on party member(s).

There are 5 parameters to the command:

Code:
Param A:
    0x00-0x0F: Check specific character (must be in party otherwise condition fail).
    0x10: Check if at least 1 character meet the condition (has the equipment).
    0x20: Check if party leader meet the condition (has the equipment).
    0x40: Check if all party members meet the condition (have the equipment).
    anything else: condition may fail or succeed. Use at your own risk.

Param B: Equipment piece to check (0x00 to 0xFF)

Param C, D, E: Offset EEDDCC where (CA/0000 + EEDDCC) is offset to jump to if condition is met.


Examples

66 0C C9 10 EF 02: If gogo has one hero ring (or more) equipped, jump to CC/EF10 otherwise continue.
66 40 C9 B8 48 00: If all party members have 1 hero ring (or more) equipped, jump to CA/48B8 otherwise continue.

Implementation ($C0)
Code:
;For implementation in bank $C0

hirom           ;do not touch
;header         ;uncomment if your ROM has a header

org $C09926     ;command 66 jump table entry.
DB $13, $D6     ;jump to C0/D613.

org $C0D613     ;Don't forget to change this if you need to relocate.
               ;following code require 0xC1 free bytes.
equipCheck:
LDA #$20        ;when comparing $1A to char battle order further down, this ensure
               ;we have at least one party leader, i.e. first comparison will always branch.
STA $1A
LDY $00         ;zero Y
TYX             ;zero X
STX $1C         ;zero $1C-$1D (temp variables)
mainLoop:
LDA $1850,Y     ;load character battle setup
AND #$07        ;isolate character's party bit
CMP $1A6D       ;compare with active party
BNE nextActor   ;branch if character is not in active party
INC $1D         ;increment party counter
LDA $EB         ;load first command parameter
CMP #$10
BCS notActor    ;branch if we are not checking a character
TYA
CMP $EB
BNE nextActor   ;branch if we don't have a character match
JSR getBlockOff ;get char equip block offset
loopEquip:
LDA $161F,X     ;get equipment
CMP $EC
BEQ goToOffset  ;if equip found, branch to jump to offset given in command params
INX
DEY
BNE loopEquip   ;loop for 6 equipment pieces
BRA exit
notActor:       ;if we are here first command param should be $10, $20 or $40
TYA
PHY             ;we are in a loop so we don't want to lose X and Y
PHX
JSR getBlockOff ;get char equip block offset
loopEquipB:
LDA $161F,X     ;get equipment
CMP $EC
BEQ incCounter  ;if equip found, increment equipment counter.
INX
DEY
BEQ endLoopB    ;branch if 6 equipment pieces are checked
BRA loopEquipB  ;otherwise check next equip piece
incCounter:
INC $1C
endLoopB:
PLX             ;restore X and Y
PLY
LDA $1850,Y     ;load character battle setup
AND #$18        ;isolate battle order
CMP $1A         ;compare to previous lowest battle order
BCS nextActor   ;branch if current char is "less leader" than the one we already have.
STA $1A         ;store battle order
STX $1E         ;store (temp) party leader
nextActor:
INX
INY
CPY #$0010
BNE mainLoop    ;loop for all 16 chars
LDA $EB
CMP #$10
BEQ partyChar   ;branch if we are checking for one party member
CMP #$40
BEQ allParty    ;branch if we are checking all party
CMP #$20
BEQ partyLead   ;branch if we are checking party leader
BRA exit        ;invalid command falls here

partyChar:
LDA $1C
CMP #$00
BNE goToOffset  ;branch if equip counter > 0
BRA exit

allParty:
LDA $1C
CMP #$00
BEQ exit        ;brand if equip counter == 0
CMP $1D         ;compare equip counter to number of party members
BEQ goToOffset  ;branch if number of same equipment == number of party members
               ;even if a char has twice the same relic equipped, only first one is counted
BRA exit

partyLead:
LDA $1E         ;load real party leader
JSR getBlockOff ;get equip block offset
loopEquipC:
LDA $161F,X     ;get equipment
CMP $EC
BEQ goToOffset  ;equipment piece found
INX
DEY
BNE loopEquipC  ;loop for 6 equipment pieces if needed

exit:           ;we are continuing after the event command
REP #$21        ;16-bit accum./memory + cary flag
LDA $E5
ADC #$0006
STA $E5
TDC
SEP #$20        ;8-bit accum./memory
ADC $E7
STA $E7
JMP $9A6D       ;event command "ending routine".

goToOffset:     ;we are jumping to offset specified in $ED-$EF
LDX $ED
STX $E5
LDA $EF
CLC
ADC #$CA
STA $E7
JMP $9A6D       ;event command "ending routine".

getBlockOff:
STA $4202       ;store character ID for multiplication
LDA #$25        ;size of character block
STA $4203       ;store block size for multiplication
NOP
NOP
LDX $4216       ;X <- index * 37
LDY #$0006      ;there's 6 slots
RTS
  Find
Quote  

#2
Posts: 178
Threads: 2
Thanks Received: 23
Thanks Given: 4
Joined: Apr 2015
Reputation: 18
Status
None
This is cool!

Just FYI, it will probably never be an issue since this is an SNES patch, but event command $66 is already used by the GBA version of the game. I'm not sure what it does. I dug through the ff6a event script a while ago and found some "new" event commands. Here's what I found, with the number of parameters and pointers to their code.

I figured out what a couple of them do. Maybe someone else knows what the others are for?

Code:
66                     08009060     (ff6a only)
67                     0800907C     (ff6a only)
68 xx                  08009190     (ff6a only)
69 xx yy bbbb          080091B8     b: battle index (ff6a only)
83 xxxx                0800B2A0     Add item xxxx to the inventory (ff6a only)
E5 xx                  0800E044     (ff6a only)
E6 xx                  0800E0A8     (ff6a only)
  Find
Quote  

#3
Posts: 81
Threads: 4
Thanks Received: 6
Thanks Given: 6
Joined: Nov 2009
Reputation: 14
Status
Weakness
New and unused event commands are a wonderful thing. I haven't done any hacking on FF6A, but I know that vanilla FF6 has an unused command (no pointer entry jumps to it) which apparently was to teach spell XX to character YY. And in Pandora's Box, we made a few new commands as well, although I can't remember all of them. I believe two of them that we added were status-related: one to check for status on a certain character (this is really needed to properly fix a few bugs) and one to set/clear status on a certain character.

Also, my fix for adding/removing HP (and MP) to characters also includes changes which check for the big 3 bad statuses (death, stone, zombie) which fixes at least 2 bugs in event code and simultaneously makes the event command have a larger range for hacks.


I appreciate the prayers and good wishes. Those who don't know, I was diagnosed with stage 4 melanoma in 2019, and I have done well with the treatment, but eventually treatments stop working and you change.  I recently had a seizure at work, now I am healing but not able to work or really do much at all. The focus is just to get better. Again, thanks for the support and if I can help you I will.  I've forgotten more about this game than most people should ever learn, lol.
  Find
Quote  

#4
Posts: 3,966
Threads: 279
Thanks Received: 234
Thanks Given: 56
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
(05-04-2016, 06:26 PM)Imzogelmo Wrote: I believe two of them that we added were status-related: one to check for status on a certain character (this is really needed to properly fix a few bugs) and one to set/clear status on a certain character.

I did take my inspiration from PB to code an event command that can check if a certain status is set on the party leader and branch to an event subroutine if it's the case. It was one of my first ASM coding. Your work and the work of all the PB team has been an inspiration for me and I'm sure other folks as well.
  Find
Quote  



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite