51
Completely Unrelated / Re: Post Your Avatar!
« on: 2014-05-21 20:26:05 »
Clearly!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I want to explain why I wrote it the way I did, NFITC1. From my own experience, the Wiki is quite heavy on technical terms which can be tough to follow for folk like me who don't have a background in programming
Apparently, fixing the problems that caused is not as simple as re-running PC with the .dll in the same directory.
.open "BATTLE",0x800A0000
.psx
.org 0x800ADA28
.area $9C
//check_long_range_attack
lw v1, $0050(a1)
nop
andi v1, v1, $0020
bgtz v1, check_self_backrow ; if short range attack, check self/target backrow
nop
j 0x800ADAC8 ; else skip to next sub
check_self_backrow:
lw v0, $0000(a1)
nop
sll v1, v0, 1
addu v1, v1, v0
sll v1, v1, 2
addu v1, v1, v0
sll v1, v1, 3
lui at, $8010
addu at, at, v1
lw v0, $83E4(at)
lw v1, $0208(a1) ; start loading word for check_target_backrow (save space)
andi v0, v0, $0040 ;v0 now contains self.isBackRow
//check_target_backrow
sll at, v1, 1
addu at, at, v1
sll at, at, 2
addu at, at, v1
sll at, at, 3
lui v1, $8010
addu v1, v1, at ;v1 contains address for lookup
lw at, $83E4(v1)
nop
andi v1, at, $0040 ;v1 now contains target.isBackRow
//do_comparison
or at, v0, v1
bgtz at, reduceDmg ; if target.isBackRow || self.isBackRow, go to reduceDmg branch
nop
j 0x000ADAC8 ;skip to next sub
nop
reduceDmg:
j 0x000ADABC ; sends to damage reduction subfunction
nop
.endarea
.close
// Start at DA28
// R4 contains result of first damage equation
R3 = load word from [r5 + 208] // gets value of offset 208 from temporary scenario array stored in R5
R2 = R3 * 2
R2 = R2 + R3
R2 = R2 * 4
R2 = R2 + R3
R2 = R2 * 8
R1 = 8010 0000
R1 = R1 + R2
R2 = load word from R1 + 83E4
// this seems to get the target unit flags specified at http://sourceforge.net/p/q-gears/code/ci/default/tree/reversing/ffvii/ffvii_battle/ffvii_address.txt#l655
// I *think* these are flags for the target rather than the actor
R3 = load word from [R5 + 0050] // get attack target flags
R2 = R2 && 0040 // R2 = target.isBackRow
R3 = R3 && 0020 // R3 = attack.isShortRange
R6 = (0 < R2) // reducedDamageFlag = target.isInBackRow
IF R3 != 0, BRANCH TO DA74
// DA64
R3 = load word from [r5 + 28] // get attack type data
R2 = 0 || 20 // 'enemy attack' command
IF R3 != R2, BRANCH TO DAB4
// DA74
R2 = load word from [r5 + 0]
R3 = R2 * 2
R3 = R2 + R3
R3 = R3 * 4
R3 = R3 + R2
R3 = R3 * 8
R1 = 8010 0000
R1 = R1 + R3
R2 = load word from [R1 + 83E4]
// seems to be unit flags for actor
R2 = R2 && 0040 // R2 = self.isBackRow
IF R2 = 0, BRANCH TO DAB8
R6 = 1 // reducedDamageFlag = true
JUMP TO DAB8
// DAB4
R6 = 0
// DAB8
R2 = R4 >> 1F
// right shift R4 - current damage - by 31 places, leaving upper bit
IF R6 = 0, BRANCH TO DAC8
R2 = R2 + R4
// add upper bit to get negative damage to bitshift divide properly?
R4 = R2 / 2
// DAC8
// Seems to be start of ‘target defend’ check
applyDamageReduction = target.isBackRow;
if (attack.shortRange) {
checkActorRow();
}
else {
// if attack is long range
if (attack.enemyCommand == false) {
applyDamageReduction = false;
}
else {
checkActorRow();
}
}
function checkActorRow() {
if (actor.isBackRow) {
applyDamageReduction = true;
}
}
if (applyDamageReduction) {
divideCurrentDamageByTwo();
}
// Check for long range attack
LW R1, $0028 (R5) ;load R5+28 (target flags?) into R1
ORI R2, R0, $0020 ;don't know why the original code used this method, but I'll preserve it
BNE R1, R2, $0000DAC8 ;goto defend script
NOP ;do I need to include these after jumps?
// Load self.backRow into R1
LW R1 $0000 (R5) ;load R5+0 (self unit flags?) into R1
NOP ;apparently loads are delayed by one cycle
SLL R2, R1, $1
ADDU R2, R2, R1
SLL R2, R2, $2
ADDU R2, R2, R1
SLL R2, R2, $3
LW R1 $83E4 (R2) ;get offset and load
NOP
ANDI R1, R1, $0040 ;this should put the AND of R1 && 0x0040 into R1
// Load target.backRow into R2
LW R2 $0208 (R5) ; load R5+208 (target unit flags?) into R2
NOP
SLL R3, R2, $1
ADDU R3, R3, R2
SLL R3, R3, $2
ADDU R3, R3, R2
SLL R3, R3, $3
LW R2 $83E4 (R3) ;get offset and load
NOP
ANDI R2, R2, $0040 ;this should put the AND of R2 && 0x0040 into R2
// Do comparison
// If either self or target are back row, their register should contain 0x0040
OR R3, R2, R1 ;will contain 0x0040 if either party in back row, should contain 0x0000 if not
BLEZ R3, $0000DAC8 ;skip to defending script if zero
// Continue with existing 'reduce damage' implementation, ignoring test for R6 != 0
.open "BATTLE",0x800A0000
.psx
.org 0x800ADA28
.area $9C
//check_long_range_attack
lw v1, $0050(a1)
nop
andi v1, v1, $0020
bgtz v1, check_self_backrow ; if short range attack, check self/target backrow
nop
j 0x800ADAC8 ; else skip to next sub
check_self_backrow:
lw v0, $0000(a1)
nop
sll v1, v0, 1
addu v1, v1, v0
sll v1, v1, 2
addu v1, v1, v0
sll v1, v1, 3
lui at, $8010
addu at, at, v1
lw v0, $83E4(at)
lw v1, $0208(a1) ; start loading word for check_target_backrow (save space)
andi v0, v0, $0040 ;v0 now contains self.isBackRow
//check_target_backrow
sll at, v1, 1
addu at, at, v1
sll at, at, 2
addu at, at, v1
sll at, at, 3
lui v1, $8010
addu v1, v1, at ;v1 contains address for lookup
lw at, $83E4(v1)
nop
andi v1, at, $0040 ;v1 now contains target.isBackRow
//do_comparison
or at, v0, v1
bgtz at, reduceDmg ; if target.isBackRow || self.isBackRow, go to reduceDmg branch
nop
j 0x000ADAC8 ;skip to next sub
nop
reduceDmg:
j 0x000ADABC ; sends to damage reduction subfunction
nop
.endarea
.close