Difference between revisions of "Random Process"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Created page with " Random Process (gives a random based on r4 (MOD) and checks against r5 (chance to work)) 0018eed8: 27bdffe0 addiu r29,r29,0xffe0 0018eedc: afb00010 sw r16,0x0010(r29) 0018...")
 
m
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
  Random Process (gives a random based on r4 (MOD) and checks against r5 (chance to work))
+
                                          Same as [[Check_if_Random_is_greater/equal_to_Chance]]
  0018eed8: 27bdffe0 addiu r29,r29,0xffe0
+
  '''Parameters''' : r4 = Random Max Limit
  0018eedc: afb00010 sw r16,0x0010(r29)
+
              r5 = Threshold value
  0018eee0: 00808021 addu r16,r4,r0 r16 = Random MOD
+
  0018eee4: afb10014 sw r17,0x0014(r29)
+
'''Returns''' : r2 = 0x00 if Random number between 0x00 and r4 is < r5
  0018eee8: afbf0018 sw r31,0x0018(r29)
+
          r2 = 0x01 if Random number between 0x00 and r4 is > r5
  0018eeec: 0c063ba8 jal 0x0018eea0 Random Procees (returns 0-7FFF)
+
--------------------------------------------------------------------------------------------------
  0018eef0: 00a08821 addu r17,r5,r0 r17 = Chance
+
  0018eed8: 27bdffe0 addiu r29,r29,-0x0020    |
  0018eef4: 00500018 mult r2,r16 Random * MOD
+
  0018eedc: afb00010 sw r16,0x0010(r29)       |
  0018eef8: 00001012 mflo r2 r2 = Random * MOD
+
  0018eee0: 00808021 addu r16,r4,r0           |{{f/std|<nowiki>r16 = Random limit (max value)</nowiki>}}
  0018eefc: 04410002 bgez r2,0x0018ef08 Branch if Random * MOD >= 0
+
  0018eee4: afb10014 sw r17,0x0014(r29)       |
  0018ef00: 00000000 nop
+
  0018eee8: afbf0018 sw r31,0x0018(r29)       |
  0018ef04: 24427fff addiu r2,r2,0x7fff r2 + 7FFF (makes Random * MOD positive)
+
  0018eeec: 0c063ba8 jal 0x0018eea0           |{{f/jal|Random Process, gives a number between 0-7fff|Random Number}} Returns r2 = Random number between 0x00 and 0x7fff  (see [[RNG]])
  0018ef08: 000213c3 sra r2,r2,0x0f Random * MOD / 8000h
+
  0018eef0: 00a08821 addu r17,r5,r0           |{{f/std|<nowiki>r17 = Threshold value</nowiki>}}
  0018ef0c: 0051102a slt r2,r2,r17 r2 = 1 IF Random < chance
+
  0018eef4: 00500018 mult r2,r16             |{{f/std|Random * Limit}}
  0018ef10: 38420001 xori r2,r2,0x0001 r2 = 0 IF Random < chance
+
  0018eef8: 00001012 mflo r2                 |{{f/std|<nowiki>r2 = Random * Limit</nowiki>}}
  0018ef14: 8fbf0018 lw r31,0x0018(r29)
+
  0018eefc: 04410002 bgez r2,0x0018ef08       {{f/Cond|If Random * Limit < 0x00}}
  0018ef18: 8fb10014 lw r17,0x0014(r29)
+
  0018ef00: 00000000 nop                         |
  0018ef1c: 8fb00010 lw r16,0x0010(r29)
+
  0018ef04: 24427fff addiu r2,r2,0x7fff           |{{f/std|<nowiki>r2 = Positive Random*limit</nowiki>}}
  0018ef20: 27bd0020 addiu r29,r29,0x0020
+
  0018ef08: 000213c3 sra r2,r2,0x0f           |{{f/std|<nowiki>r2 = Random Number between 0x00 and Limit</nowiki>}} {{f/std|<nowiki> =  Limit * Random/0x8000 (Max random) </nowiki>}}
  0018ef24: 03e00008 jr r31
+
  0018ef0c: 0051102a slt r2,r2,r17           |{{f/std|<nowiki>r2 = 0x01 if Random is < Threshold value</nowiki>}}
  0018ef28: 00000000 nop
+
  0018ef10: 38420001 xori r2,r2,0x0001       |r2 = 0x00 if Random is < Threshold value / Else = 0x01
 +
  0018ef14: 8fbf0018 lw r31,0x0018(r29)      
 +
  0018ef18: 8fb10014 lw r17,0x0014(r29)      
 +
  0018ef1c: 8fb00010 lw r16,0x0010(r29)      
 +
  0018ef20: 27bd0020 addiu r29,r29,0x0020    
 +
  0018ef24: 03e00008 jr r31                  
 +
  0018ef28: 00000000 nop                    
 +
=== Return location ===
 +
'''Battle.bin'''
 +
0018650c: [[Critical_Hit_Calculation]]

Latest revision as of 20:04, 27 March 2022

                                         Same as Check_if_Random_is_greater/equal_to_Chance
Parameters : r4 = Random Max Limit 
             r5 = Threshold value

Returns : r2 = 0x00 if Random number between 0x00 and r4 is < r5
          r2 = 0x01 if Random number between 0x00 and r4 is > r5
--------------------------------------------------------------------------------------------------
0018eed8: 27bdffe0 addiu r29,r29,-0x0020    |
0018eedc: afb00010 sw r16,0x0010(r29)       |
0018eee0: 00808021 addu r16,r4,r0           |r16 = Random limit (max value)
0018eee4: afb10014 sw r17,0x0014(r29)       |
0018eee8: afbf0018 sw r31,0x0018(r29)       |
0018eeec: 0c063ba8 jal 0x0018eea0           |-->Random Number Returns r2 = Random number between 0x00 and 0x7fff  (see RNG)
0018eef0: 00a08821 addu r17,r5,r0           |r17 = Threshold value
0018eef4: 00500018 mult r2,r16              |Random * Limit
0018eef8: 00001012 mflo r2                  |r2 = Random * Limit
0018eefc: 04410002 bgez r2,0x0018ef08       #If Random * Limit < 0x00
0018ef00: 00000000 nop                          |
0018ef04: 24427fff addiu r2,r2,0x7fff           |r2 = Positive Random*limit
0018ef08: 000213c3 sra r2,r2,0x0f           |r2 = Random Number between 0x00 and Limit  =  Limit * Random/0x8000 (Max random) 
0018ef0c: 0051102a slt r2,r2,r17            |r2 = 0x01 if Random is < Threshold value
0018ef10: 38420001 xori r2,r2,0x0001        |r2 = 0x00 if Random is < Threshold value / Else = 0x01
0018ef14: 8fbf0018 lw r31,0x0018(r29)       
0018ef18: 8fb10014 lw r17,0x0014(r29)       
0018ef1c: 8fb00010 lw r16,0x0010(r29)       
0018ef20: 27bd0020 addiu r29,r29,0x0020     
0018ef24: 03e00008 jr r31                   
0018ef28: 00000000 nop                      

Return location

Battle.bin
0018650c: Critical_Hit_Calculation