Final Fantasy Hacktics

Modding => PSX FFT Hacking => Topic started by: formerdeathcorps on June 28, 2011, 12:36:06 am

Title: Floating Point Multiplication
Post by: formerdeathcorps on June 28, 2011, 12:36:06 am
OK, here's a way to implement floating point multiplication in FFT.  Here's a basic outline from me (SA, feel free to improve this routine's register use efficiency):

r1 = numerator
r2 = denominator
r3 = FFFFFFFF
r4 = INT PART
r5 = FRAC PART
IF r1 < r2, r3 = r3 / r2 * r1 + 1
ELSE:
  r3 = r3 / r2 + 1
  r2 = 1
DO r4 * r3
r4 = MFHI
r6 = MFLO
DO r5 * r3
r3 = MFHI
r5 = r3 + r6
If r5 < r3, then r4 = r4 + 1 (carry-over)
If r2 = 1, then:
  DO r4 * r1
 r4 = MFLO
  DO r5 * r1
 r6 = MFHI
 r5 = MFLO
 r4 = r4 + r6.

Anyone care to code this?
Title: Re: Floating Point Multiplication
Post by: Glain on June 29, 2011, 09:55:33 am
I'm starting to wonder if we can get away with something like...

r2 = (numerator)
r3 = (denominator)

and if you want to multiply fractions, just multiply (numerator) * (numerator) and (denominator) * (denominator) and then at the very end, just do (r2 / r3).

Seems like it'd be way simpler but I'm not sure how high r2 and r3 might get. Then again you've got 32 bits and you're probably only working with a final damage number that's a halfword anyway. I don't know... it's a thought. Seems like less work if we can get away with it.