Fire Emblem

From NES Hacker Wiki
Revision as of 00:04, 20 March 2017 by MKnightDH (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Code

Battle stats establishing

This subroutine is called to establish battle stats.

CBAD:20 CF CB  JSR $CBCF        ; Checks if Triangle Attack works, auto-clears $0483 if Javelin or Thunder Sword is used
CBB0:20 4D CC  JSR $CC4D        ; Stores Attack Speed values in $0338 and $0339
CBB3:20 2F CD  JSR $CD2F        ; Stores Luck values in $0342 and $0343
CBB6:20 E5 CB  JSR $CBE5        ; Stores Net Hit values in $033A and $033B
CBB9:20 F0 CC  JSR $CCF0        ; Stores Used Defense values in $033E and $033F
CBBC:20 64 CC  JSR $CC64        ; Stores Damage Per Hit values in $033C and $033D
CBBF:20 16 CD  JSR $CD16        ; Stores Net Crit values in $0340 and $0341
CBC2:20 3B CD  JSR $CD3B        ; Stores 1st Hit Check in $0344 and $0345, and 2nd Hit Check in $0346 and $0347
CBC5:20 D4 CD  JSR $CDD4        ; Stores 1st Crit Check in $034B and $034C, and 2nd Hit Check in $034D and $034E
CBC8:20 12 CE  JSR $CE12        ; Stores Devil weapon's backfire check in $0355 and backfire damage in $0356
CBCB:20 62 CE  JSR $CE62        ; Attack Sealing Check, seal causes affected player's Hit Check to be emptied
CBCE:60        RTS              ; Return From Subroutine

Damage per hit

This subroutine is called to set the damage that each of the 2 units in combat deals when they land a hit on the other.

CC64:A0 01     LDY #$01         ; Enemy stats stuff; skipped when this subroutine is redone later
CC66:B9 12 03  LDA $0312,Y      ; A = unit's Strength
CC69:BE 20 03  LDX $0320,Y      ; X = unit's Weapon
CC6C:E0 08     CPX #$08         ; Is the weapon the Thunder Sword?
CC6E:F0 4F     BEQ $CCBF        ; Branch if it is.
CC70:E0 2A     CPX #$2A         ; Is the weapon a tome?
CC72:B0 4B     BCS $CCBF        ; Branch if it is.
CC74:7D 57 D6  ADC $D657,X      ; Adds Weapon's Might to A
CC77:85 08     STA $0008        ; Store A, ($08)
CC79:BD 57 D6  LDA $D657,X      ; A = Might
CC7C:99 49 03  STA $0349,Y      ; Store A, ($0349+Y)
CC7F:BD DB D8  LDA $D8DB,X      ; A = Weapon's Class Effectiveness
CC82:F0 1D     BEQ $CCA1        ; Branch past Effective process if weapon isn't effective VS anything
CC84:20 EE D2  JSR $D2EE        ; Subroutine that has Carry Flag set by weapon being Effective VS enemy's class
CC87:90 18     BCC $CCA1        ; Branch past rest of Effective process if weapon isn't Effective
CC89:A5 08     LDA $0008        ; A = Strength + Might
CC8B:18        CLC              ; Clear Carry
CC8C:7D 57 D6  ADC $D657,X      ; Add Might
CC8F:7D 57 D6  ADC $D657,X      ; Done again
CC92:85 08     STA $0008        ; ($08) = Strength + Might x 3
CC94:B9 49 03  LDA $0349,Y      ; A = Might
CC97:18        CLC              ; Clear Carry
CC98:7D 57 D6  ADC $D657,X      ; Add Might
CC9B:7D 57 D6  ADC $D657,X      ; Yet again
CC9E:99 49 03  STA $0349,Y      ; ($0349+Y) = Might x 3, Effective process ends here
CCA1:A5 08     LDA $0008        ; A = ATK
CCA3:8D 60 03  STA $0360        ; ($0360) = ATK
CCA6:20 70 CE  JSR $CE70        ; Subroutine sets Y for opposing unit
CCA9:B9 3E 03  LDA $033E,Y      ; A = enemy's DEF stat
CCAC:8D 5F 03  STA $035F        ; ($035F) = enemy's DEF stat
CCAF:20 70 CE  JSR $CE70        ; Subroutine sets Y for current unit
CCB2:AD 60 03  LDA $0360        ; A = ATK
CCB5:38        SEC              ; Set Carry
CCB6:ED 5F 03  SBC $035F        ; A = ATK - DEF
CCB9:10 18     BPL $CCD3        ; Branch with Physical portion done if A is positive
CCBB:A9 00     LDA #$00         ; Done to minimize A to 0
CCBD:F0 14     BEQ $CCD3        ; Physical portion done
CCBF:BD 57 D6  LDA $D657,X      ; Magic uses only Might
CCC2:99 49 03  STA $0349,Y      ; ($0349) = Might
CCC5:20 70 CE  JSR $CE70        ; Subroutine sets Y for opposing unit
CCC8:38        SEC              ; Set Carry
CCC9:F9 26 03  SBC $0326,Y      ; A = Might - enemy's Magic DEF
CCCC:10 02     BPL $CCD0        ; Branch for avoiding minimization if A is positive
CCCE:A9 00     LDA #$00         ; Minimization
CCD0:20 70 CE  JSR $CE70        ; Subroutine sets Y for current unit
CCD3:48        PHA              ; Physical portion returns here
CCD4:AD 20 03  LDA $0320        ; A = Weapon
CCD7:C9 0A     CMP #$0A         ; Check if the weapon is the Falchion
CCD9:D0 04     BNE $CCDF        ; Skip next 2 lines if that's not the case
CCDB:68        PLA              ; Pull A to counterbalance Push for Falchion
CCDC:4C E6 CC  JMP $CCE6        ; Skip Base Damage cap portion if weapon is Falchion
CCDF:68        PLA              ; Pull A to counter balance Push for non-Falchion
CCE0:C9 28     CMP #$28         ; Check if Base Damage exceeds 40
CCE2:90 02     BCC $CCE6        ; If not, skip next line
CCE4:A9 28     LDA #$28         ; Caps Base Damage at 40
CCE6:99 3C 03  STA $033C,Y      ; ($033C+Y) = Base Damage
CCE9:88        DEY              ; Y decremented
CCEA:30 03     BMI $CCEF        ; If Player's Base Damage was calculated, Branch to Return
CCEC:4C 66 CC  JMP $CC66        ; Redo whole thing for player if it was done for enemy
CCEF:60        RTS              ; Return from Subroutine