Users browsing this thread: 1 Guest(s)
Changing Damage formulas
(11-10-2014, 10:03 PM)Odal Wrote: So say, for example, the magic calculation divides by 32 and I want to change it to something else, let's say 64 for the sake of ease. How would I actually change this line of code to do that? I've searched everywhere and nothing seems to explain how to actually change this. I've found where it does this, but I have no idea how to modify the function the way I want to:
Code:C2/2B90: 20 D1 0D JSR $0DD1 (Divide 24-bit Damage by 32. [note the
division operates on 4 bytes] )
If you look at C2/0DD1, the commentary will tell you what's going on. This multiplication is actually part of a larger function, but if entered at C2/0DD1, it's a bit more generalized arithmetic:
Code:
(if entered at C2/0DD1, does a more general division of a 32-bit value
[though most callers assume it's 24-bit] by 2^(A+1).)
What it doesn't tell you is what the base value being modified is, but you can discern that by looking at the function (it's the values stored in $E8 - $EA, typically, so a 24-bit value).
So the commentary says it's dividing that by 2^(A+1). If you look back at the caller, you can see an LDA #$04 instruction at C2/2B8C. So using that, we can figure out what the divisor is:
2^(4+1) = 2^5 = 32
To change the divisor to 64, you'd just need to change that LDA instruction to LDA #$05.
(11-10-2014, 10:03 PM)Odal Wrote: As for more in-depth formula changing, the meat of the formula seems to be here:
With that /32 tacked on later (mentioned above). But I just don't see how one would go about changing any of that. I guess the first one references $4781, which is where the multiplication functions are, but I don't see how that literally calculates Magic power * Spell power.Code:C2/2B86: 20 81 47 JSR $4781 (Multiplication Function:
A = Magic Power * Spell Power)
C2/2B89: 20 B7 47 JSR $47B7 (Multiplication Function 2:
24-bit $E8 = (Mag Pwr * Spell Power) * Level)
Same thing, take a look at the commentary for the function being called. At C2/4781:
Code:
Multiplication Function
Multiplies low bit of A * high bit of A. Stores result in 16-bit A.
Calling the operands the "low bit" and "high bit" is misleading; more accurately, it should be "low byte" and "high byte." These simply refers to each 8-bit portion of a 16-bit A.
For example, if A contains 13BD (5053 in decimal), then this function will multiply 13 * BD.
And at C2/47B7:
Code:
Multiplication Function 2
Results:
16-bit A = (8-bit $E8 * 16-bit A) / 256
24-bit $E8 = 3 byte (8-bit $E8 * 16-bit A)
16-bit $EC = 8-bit $E8 * high byte of A
This one is easier to understand, and a bit more versatile. As you can tell, it will give you three different results for three different sets of arithmetic.
One result will be stored in 16-bit A.
One result will be stored in 24-bit $E8 (that is, $E8 - $EA)
The last result will be stored in 16-bit $EC ($EC - $ED)
(11-10-2014, 10:03 PM)Odal Wrote: And now that I look at it, I don't see where Spell power * 4 (first part of the formula) is calculated at all.
This one's a bit less obvious than calling a multiplication function.
Code:
C2/2B71: AD A6 11 LDA $11A6 (Spell Power)
C2/2B74: C2 20 REP #$20 (Set 16-bit Accumulator)
C2/2B76: 90 02 BCC $2B7A (If Level > 0, Spell Power *= 4)
C2/2B78: 0A ASL
C2/2B79: 0A ASL
The key is in the ASL instructions. These shift all bits in the operand left by one bit, which effectively doubles it. This instruction has more uses than just a quick (operand * 2), but that's all it's used for in this case.
It starts by loading the caster's spell power into A, then doubling that (A * 2), then doubling THAT (A * 4).
Of note, the LSR instruction has a similar usage in that it shifts all bits in the operand to the right by one bit, effectively halving it.
ASL = Arithmetic Shift Left
LSR = Logical Shift Right
(11-10-2014, 10:03 PM)Odal Wrote: Ugh, this is hurting my brain. I apologize if this is really basic stuff. There doesn't seem to be much dumbed-down detail on this anywhere and it's been really hard to wrap my brain around what little I have managed to understand so far.
This is about familiarity with ASM more than anything else. How basic it is depends on how comfortable the hacker is with the language. I implemented a fully custom physical damage formula in my hack, so I was hanging around these damn formulas for way too long.
« Next Oldest | Next Newest »
|
||||
Users browsing this thread: 1 Guest(s)