Difference between revisions of "Fire Emblem"

From NES Hacker Wiki
Jump to: navigation, search
(Created page with "==Code== ===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...")
(No difference)

Revision as of 15:54, 16 March 2017

Code

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