Difference between revisions of "Get Variable's Word Pointer from Variable's ID"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
m (correcting notes)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
  #Input r4 (0x00 from Run script variable) - keep r4 unchanged
+
  Parameters : r4 = Variable ID
  #Return r2  
+
    as 0x0005771c + r4 * 4 if r4 < 0x80  (steal gil leads here)
+
  Returns: r2 = Pointer to the word containing the variable (if variable ID < 0x400)
    as 0x0005771c + 0x200 + ((r4-0x80) /32)*4 if r4 is between 0x80 and 0x359
+
          r2 = Some data from a new thread of Variable ID >= 0x400 (events ?)
    as 0x0005771c + 0x25c + ((r4 - 0x360)/8)*4 if r4 is between 0x360 and 0x3FF
+
  -------------------------------------------------------------------------------------------------
    as ? If r4>= 0x400 (via [[0014c958_-_0014c990]] - not investigated)
+
  0014a2ec: 27bdffe8 addiu r29,r29,-0x0018   |
  ------------------------------------------------------------------------------------
+
  0014a2f0: 28820080 slti r2,r4,0x0080       |{{f/std|<nowiki>r2 = 0x01 if Variable ID < 0x80</nowiki>}}
  0014a2ec: 27bdffe8 addiu r29,r29,-0x0018        
+
  0014a2f4: afbf0014 sw r31,0x0014(r29)       |
  0014a2f0: 28820080 slti r2,r4,0x0080             |r2 = 1 if Input < 0x80  
+
  0014a2f8: 10400006 beq r2,r0,0x0014a314     {{f/Cond|If Variable ID < 0x80}} {{f/Cond|([[Variables#Miscellaneous_Words|Miscellaneous_Words]] from 0x00 to 0x7f are words)}}
  0014a2f4: afbf0014 sw r31,0x0014(r29)           |
+
  0014a2fc: afb00010 sw r16,0x0010(r29)           |{{f/store| }}
  0014a2f8: 10400006 beq r2,r0,0x0014a314         #'''Input < 0x80''' (r2=1)
+
  0014a300: 3c038016 lui r3,0x8016               |
  0014a2fc: afb00010 sw r16,0x0010(r29)          
+
  0014a304: 8c635f9c lw r3,0x5f9c(r3)             |{{f/adr|<nowiki>£r3 = 0x0005771c - start of variables data</nowiki>}}
  0014a300: 3c038016 lui r3,0x8016                
+
  0014a308: 00041080 sll r2,r4,0x02               |{{f/std|<nowiki>r2 = Variable ID Value * 4</nowiki>}}
  0014a304: 8c635f9c lw r3,0x5f9c(r3)                 |<span style="color:limegreen">r3 = 0x80165f9c (host 0005771c - start of main (map?) data?)</span>
+
  0014a30c: 080528e1 j 0x0014a384                 {{f/jump|Jump to {{f/loc| END }}<nowiki> (return r2 = r16)</nowiki>}}
  0014a308: 00041080 sll r2,r4,0x02                   |r2 = r4 * 4  
+
  0014a310: 00438021 addu r16,r2,r3               |r16 = Miscellaneous word pointer
  0014a30c: 080528e1 j 0x0014a384                     >>'''jump to almost end'''
+
   
  0014a310: 00438021 addu r16,r2,r3                   |r16 = Main (map ?) data start + offset (r4*4)
+
                                            '''#Else Variable ID >= 0x80'''
  0014a314: 28820360 slti r2,r4,0x0360             |r2 = 1 if input < 0x360  
+
  0014a314: 28820360 slti r2,r4,0x0360           |{{f/std|<nowiki>r2 = 0x01 if Variable ID value < 0x360</nowiki>}}
  0014a318: 1040000b beq r2,r0,0x0014a348         #'''If r2 = 1 (r4 between 0x80 and 0x35F)''' branch if r2 = 0
+
  0014a318: 1040000b beq r2,r0,0x0014a348         {{f/Cond|If Variable ID is between 0x80 and 0x35f (From miscellaneous Bytes to unexplored land)}}
  0014a31c: 2482ff80 addiu r2,r4,-0x0080               |r2 = input - 0x80 (0x00 to 2DF)
+
  0014a31c: 2482ff80 addiu r2,r4,-0x0080             |{{f/std|<nowiki>r2 = Variable ID - 0x80 </nowiki>}}
  0014a320: 04410003 bgez r2,0x0014a330               #'''If r2 < 0''' never true ?  
+
  0014a320: 04410003 bgez r2,0x0014a330               {{f/Cond|If r2 < 0 (never true ?)}}
  0014a324: 00021143 sra r2,r2,0x05                   |r2 = r2 /32 any value under 0x20 is 0x00 (for input = 0x80 to 0xA0)
+
  0014a324: 00021143 sra r2,r2,0x05                   |{{f/std|<nowiki>r2 = r2 /32 </nowiki>}} {{f/std| 32 variables per words in this section}}
  0014a328: 2482ff9f addiu r2,r4,-0x0061                   |r2 = input-0x61
+
  0014a328: 2482ff9f addiu r2,r4,-0x0061                 |{{f/std|<nowiki>r2 = Variable ID-0x61</nowiki>}}
  0014a32c: 00021143 sra r2,r2,0x05                       |r2 = r2/32
+
  0014a32c: 00021143 sra r2,r2,0x05                       |{{f/std|<nowiki>r2 = r2/32</nowiki>}}
  0014a330: 00021080 sll r2,r2,0x02                   |r2 = r2*4
+
  0014a330: 00021080 sll r2,r2,0x02                   |{{f/std|<nowiki>r2 = r2*4</nowiki>}} {{f/std| Offset of the word with the desired flag (from 0x80)}}
  0014a334: 3c038016 lui r3,0x8016                     |
+
  0014a334: 3c038016 lui r3,0x8016                   |
  0014a338: 8c635f9c lw r3,0x5f9c(r3)                 |<span style="color:limegreen">r3 = 0x80165f9c (host 0005771c - start of main (map?) data?)</span>
+
  0014a338: 8c635f9c lw r3,0x5f9c(r3)                 |{{f/adr|<nowiki>£r3 = 0x0005771c - start of main data</nowiki>}}
  0014a33c: 24420200 addiu r2,r2,0x0200               |r2 = r2 + 0x200
+
  0014a33c: 24420200 addiu r2,r2,0x0200               |{{f/std|<nowiki>r2 = r2 + 0x200</nowiki>}} {{f/std|<nowiki>*0x5771c + 0x200 = 0x5791c (start of Variable from 0x80)</nowiki>}}
  0014a340: 080528e1 j 0x0014a384                     >>'''jump to almost end'''
+
  0014a340: 080528e1 j 0x0014a384                     {{f/jump|Jump to {{f/loc| END }}<nowiki> (return r2 = r16)</nowiki>}}
  0014a344: 00438021 addu r16,r2,r3                   |r16 = Main (map ?data start + offset
+
  0014a344: 00438021 addu r16,r2,r3                   |r16 = Pointer to the word containing the Variable (from r4)
  0014a348: 28820400 slti r2,r4,0x0400             |r2 = 1 if input < 0x400
+
   
  0014a34c: 1040000b beq r2,r0,0x0014a37c         #'''If input < 0x400 and >= 0x360 '''
+
                                            '''#Else Variable ID >= 0x360'''
  0014a350: 2482fca0 addiu r2,r4,-0x0360               |r2 = input - 0x360)
+
  0014a348: 28820400 slti r2,r4,0x0400           |{{f/std|<nowiki>r2 = 1 if Variable ID < 0x400</nowiki>}}
  0014a354: 04410003 bgez r2,0x0014a364               #'''If r2<0 (never true ?)'''
+
  0014a34c: 1040000b beq r2,r0,0x0014a37c         {{f/Cond|<nowiki>If Variable ID < 0x400 and >= 0x360 </nowiki>}}
  0014a358: 000210c3 sra r2,r2,0x03                   |r2 = r2/8
+
  0014a350: 2482fca0 addiu r2,r4,-0x0360             |{{f/std|<nowiki>r2 = Variable ID - 0x360 </nowiki>}}
  0014a35c: 2482fca7 addiu r2,r4,-0x0359                   |r2 = input - 0x359
+
  0014a354: 04410003 bgez r2,0x0014a364               {{f/Cond|If r2<0 (never true ?)}}
  0014a360: 000210c3 sra r2,r2,0x03                       |r2 = r2/8
+
  0014a358: 000210c3 sra r2,r2,0x03                   |{{f/std|<nowiki>r2 = r2/8</nowiki>}} {{f/std|8 Variables per words in this section}}
  0014a364: 00021080 sll r2,r2,0x02                   |r2 = r2 * 4  
+
  0014a35c: 2482fca7 addiu r2,r4,-0x0359                 |{{f/std|<nowiki>r2 = Variable ID - 0x359</nowiki>}}
  0014a368: 3c038016 lui r3,0x8016                     |
+
  0014a360: 000210c3 sra r2,r2,0x03                       |{{f/std|<nowiki>r2 = r2/8</nowiki>}}
  0014a36c: 8c635f9c lw r3,0x5f9c(r3)                 |<span style="color:limegreen">r3 = 0x80165f9c (host 0005771c - start of main (map?) data?)</span>
+
  0014a364: 00021080 sll r2,r2,0x02                   |{{f/std|<nowiki>r2 = r2 * 4</nowiki>}} {{f/std| Offset of the word with the desired flag (from 0x360)}}
  0014a370: 2442025c addiu r2,r2,0x025c               |r2 = r2 + 0x25c
+
  0014a368: 3c038016 lui r3,0x8016                   |
  0014a374: 080528e1 j 0x0014a384                     >>'''jump to almost end'''
+
  0014a36c: 8c635f9c lw r3,0x5f9c(r3)                 |{{f/adr|<nowiki>£r3 = 0x0005771c - start of main data</nowiki>}}
  0014a378: 00438021 addu r16,r2,r3                   |r16 = Main (map ?data + offset ?
+
  0014a370: 2442025c addiu r2,r2,0x025c               |{{f/std|<nowiki>r2 = r2 + 0x25c</nowiki>}} {{f/std|<nowiki>*0x5771c + 0x25c = 0x57978 (start of Variable from 0x360)</nowiki>}}
  0014a37c: 0c053256 jal 0x0014c958               |-->[[0014c958_-_0014c990|<span style="color:blue">jal 0x0014c958 (input > 0x400)</span>]] 
+
  0014a374: 080528e1 j 0x0014a384                     {{f/jump|Jump to {{f/loc| END }}<nowiki> (return r2 = r16)</nowiki>}}
  0014a380: 00000000 nop                           |
+
  0014a378: 00438021 addu r16,r2,r3                   |r16 = Pointer to the word containing the Variable (from r4)
  0014a384: 02001021 addu r2,r16,r0               |r2 = r16 (jumps landing site)
+
  0014a388: 8fbf0014 lw r31,0x0014(r29)          
+
                                            '''#Else Variable ID >= 0x400 ''' [[Variables#New_Instructions|Events new instruction]]
  0014a38c: 8fb00010 lw r16,0x0010(r29)          
+
  0014a37c: 0c053256 jal 0x0014c958               |{{f/jal|0014c958_-_0014c990|0014c958_-_0014c990}} Close running thread and seek a new one - r16 is loaded from new thread (0x10)
  0014a390: 27bd0018 addiu r29,r29,0x0018        
+
  0014a380: 00000000 nop                         |
  0014a394: 03e00008 jr r31                      
+
  0014a384: 02001021 addu r2,r16,r0           Returns r2 = r16 (Variable ID word data pointer)
 +
  0014a388: 8fbf0014 lw r31,0x0014(r29)          
 +
  0014a38c: 8fb00010 lw r16,0x0010(r29)          
 +
  0014a390: 27bd0018 addiu r29,r29,0x0018        
 +
  0014a394: 03e00008 jr r31                      
 
  0014a398: 00000000 nop
 
  0014a398: 00000000 nop
 
+
=== Return locations ===
==Returns location==
+
'''Battle.bin'''
 +
0014a084: [[Run_Script_Variable_Command]]
 
  0014a0cc: [[Run_Script_Variable_Command]]
 
  0014a0cc: [[Run_Script_Variable_Command]]

Latest revision as of 12:46, 6 March 2022

Parameters : r4 = Variable ID

Returns: r2 = Pointer to the word containing the variable (if variable ID < 0x400)
         r2 = Some data from a new thread of Variable ID >= 0x400 (events ?)
-------------------------------------------------------------------------------------------------
0014a2ec: 27bdffe8 addiu r29,r29,-0x0018    |
0014a2f0: 28820080 slti r2,r4,0x0080        |r2 = 0x01 if Variable ID < 0x80
0014a2f4: afbf0014 sw r31,0x0014(r29)       |
0014a2f8: 10400006 beq r2,r0,0x0014a314     #If Variable ID < 0x80 #(Miscellaneous_Words from 0x00 to 0x7f are words)
0014a2fc: afb00010 sw r16,0x0010(r29)           | 
0014a300: 3c038016 lui r3,0x8016                |
0014a304: 8c635f9c lw r3,0x5f9c(r3)             |£r3 = 0x0005771c - start of variables data
0014a308: 00041080 sll r2,r4,0x02               |r2 = Variable ID Value * 4
0014a30c: 080528e1 j 0x0014a384                 >>Jump to  END  (return r2 = r16)
0014a310: 00438021 addu r16,r2,r3               |r16 = Miscellaneous word pointer

                                            #Else Variable ID >= 0x80
0014a314: 28820360 slti r2,r4,0x0360            |r2 = 0x01 if Variable ID value < 0x360
0014a318: 1040000b beq r2,r0,0x0014a348         #If Variable ID is between 0x80 and 0x35f (From miscellaneous Bytes to unexplored land)
0014a31c: 2482ff80 addiu r2,r4,-0x0080              |r2 = Variable ID - 0x80 
0014a320: 04410003 bgez r2,0x0014a330               #If r2 < 0 (never true ?)
0014a324: 00021143 sra r2,r2,0x05                   |r2 = r2 /32   32 variables per words in this section
0014a328: 2482ff9f addiu r2,r4,-0x0061                  |r2 = Variable ID-0x61
0014a32c: 00021143 sra r2,r2,0x05                       |r2 = r2/32
0014a330: 00021080 sll r2,r2,0x02                   |r2 = r2*4  Offset of the word with the desired flag (from 0x80)
0014a334: 3c038016 lui r3,0x8016                    |
0014a338: 8c635f9c lw r3,0x5f9c(r3)                 |£r3 = 0x0005771c - start of main data
0014a33c: 24420200 addiu r2,r2,0x0200               |r2 = r2 + 0x200 *0x5771c + 0x200 = 0x5791c (start of Variable from 0x80)
0014a340: 080528e1 j 0x0014a384                     >>Jump to  END  (return r2 = r16)
0014a344: 00438021 addu r16,r2,r3                   |r16 = Pointer to the word containing the Variable (from r4)

                                            #Else Variable ID >= 0x360
0014a348: 28820400 slti r2,r4,0x0400            |r2 = 1 if Variable ID < 0x400
0014a34c: 1040000b beq r2,r0,0x0014a37c         #If Variable ID < 0x400 and >= 0x360 
0014a350: 2482fca0 addiu r2,r4,-0x0360              |r2 = Variable ID - 0x360 
0014a354: 04410003 bgez r2,0x0014a364               #If r2<0 (never true ?)
0014a358: 000210c3 sra r2,r2,0x03                   |r2 = r2/8 8 Variables per words in this section
0014a35c: 2482fca7 addiu r2,r4,-0x0359                  |r2 = Variable ID - 0x359
0014a360: 000210c3 sra r2,r2,0x03                       |r2 = r2/8
0014a364: 00021080 sll r2,r2,0x02                   |r2 = r2 * 4  Offset of the word with the desired flag (from 0x360)
0014a368: 3c038016 lui r3,0x8016                    |
0014a36c: 8c635f9c lw r3,0x5f9c(r3)                 |£r3 = 0x0005771c - start of main data
0014a370: 2442025c addiu r2,r2,0x025c               |r2 = r2 + 0x25c *0x5771c + 0x25c = 0x57978 (start of Variable from 0x360)
0014a374: 080528e1 j 0x0014a384                     >>Jump to  END  (return r2 = r16)
0014a378: 00438021 addu r16,r2,r3                   |r16 = Pointer to the word containing the Variable (from r4)

                                            #Else Variable ID >= 0x400   Events new instruction
0014a37c: 0c053256 jal 0x0014c958               |-->0014c958_-_0014c990 Close running thread and seek a new one - r16 is loaded from new thread (0x10)
0014a380: 00000000 nop                          |
0014a384: 02001021 addu r2,r16,r0           Returns r2 = r16 (Variable ID word data pointer)
0014a388: 8fbf0014 lw r31,0x0014(r29)           
0014a38c: 8fb00010 lw r16,0x0010(r29)           
0014a390: 27bd0018 addiu r29,r29,0x0018         
0014a394: 03e00008 jr r31                       
0014a398: 00000000 nop

Return locations

Battle.bin
0014a084: Run_Script_Variable_Command
0014a0cc: Run_Script_Variable_Command