Difference between revisions of "Rand16 (Events)"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Confirm suspicion of this being an RNG function and explain what it is.)
Line 1: Line 1:
 
<font face='Courier New'>
 
<font face='Courier New'>
   
+
  #  ROUTINE: rand16
 +
#  SUMMARY: 16-bit linear congruential pseudorandom number generator, using well-known constants made (in)famous by Peter Grogono in 1978.
 +
 +
#  nextRNG = (prevRNG * 25173 + 13849) mod 2^16
 +
#
 
  0014a48c: 3c048017 lui r4,0x8017
 
  0014a48c: 3c048017 lui r4,0x8017
  0014a490: 8c843c7c lw r4,0x3c7c(r4) 2 words after next event(?). some really weird rng call?
+
  0014a490: 8c843c7c lw r4,0x3c7c(r4) 2 words after next event(?). Previous RNG value, might be specific to events.
 
  0014a494: 00000000 nop
 
  0014a494: 00000000 nop
 
  0014a498: 00041840 sll r3,r4,0x01 r4 * 2
 
  0014a498: 00041840 sll r3,r4,0x01 r4 * 2
Line 12: Line 16:
 
  0014a4b0: 00031140 sll r2,r3,0x05 r4 * 6496
 
  0014a4b0: 00031140 sll r2,r3,0x05 r4 * 6496
 
  0014a4b4: 00431023 subu r2,r2,r3 r4 * 6293
 
  0014a4b4: 00431023 subu r2,r2,r3 r4 * 6293
  0014a4b8: 00021080 sll r2,r2,0x02 r4 * 25172
+
  0014a4b8: 00021080 sll r2,r2,0x02 r4 * 25172             # No idea what the purpose of building this constant this way is.
  0014a4bc: 00441021 addu r2,r2,r4 r4 * 25173
+
  0014a4bc: 00441021 addu r2,r2,r4 r4 * 25173             # Perhaps to intentionally waste cycles to slow this down?
 
  0014a4c0: 24423619 addiu r2,r2,0x3619 r4 * 0x6254 + 0x3619
 
  0014a4c0: 24423619 addiu r2,r2,0x3619 r4 * 0x6254 + 0x3619
  0014a4c4: 3042ffff andi r2,r2,0xffff clear excess data
+
  0014a4c4: 3042ffff andi r2,r2,0xffff efficient modulo via bitmask
 
  0014a4c8: 3c018017 lui r1,0x8017
 
  0014a4c8: 3c018017 lui r1,0x8017
  0014a4cc: ac223c7c sw r2,0x3c7c(r1) save new value here
+
  0014a4cc: ac223c7c sw r2,0x3c7c(r1) update the RNG seed
 
  0014a4d0: 03e00008 jr r31
 
  0014a4d0: 03e00008 jr r31
 
  0014a4d4: 00000000 nop
 
  0014a4d4: 00000000 nop
 
</font>
 
</font>

Revision as of 19:54, 27 February 2024

#   ROUTINE: rand16
#   SUMMARY: 16-bit linear congruential pseudorandom number generator, using well-known constants made (in)famous by Peter Grogono in 1978.
#   
#   nextRNG = (prevRNG * 25173 + 13849) mod 2^16
#
0014a48c: 3c048017 lui r4,0x8017
0014a490: 8c843c7c lw r4,0x3c7c(r4)			2 words after next event(?). Previous RNG value, might be specific to events.
0014a494: 00000000 nop
0014a498: 00041840 sll r3,r4,0x01			r4 * 2
0014a49c: 00641821 addu r3,r3,r4			r4 * 3
0014a4a0: 00031100 sll r2,r3,0x04			r4 * 30
0014a4a4: 00621821 addu r3,r3,r2			r4 * 33
0014a4a8: 00031880 sll r3,r3,0x02			r4 * 204
0014a4ac: 00641823 subu r3,r3,r4			r4 * 203
0014a4b0: 00031140 sll r2,r3,0x05			r4 * 6496
0014a4b4: 00431023 subu r2,r2,r3			r4 * 6293
0014a4b8: 00021080 sll r2,r2,0x02			r4 * 25172             # No idea what the purpose of building this constant this way is.
0014a4bc: 00441021 addu r2,r2,r4			r4 * 25173             # Perhaps to intentionally waste cycles to slow this down?
0014a4c0: 24423619 addiu r2,r2,0x3619			r4 * 0x6254 + 0x3619
0014a4c4: 3042ffff andi r2,r2,0xffff			efficient modulo via bitmask
0014a4c8: 3c018017 lui r1,0x8017
0014a4cc: ac223c7c sw r2,0x3c7c(r1)			update the RNG seed
0014a4d0: 03e00008 jr r31
0014a4d4: 00000000 nop