Difference between revisions of "Generate Treasure"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Re-formatted routine documentation)
(More notes on section 3)
 
(One intermediate revision by one other user not shown)
Line 40: Line 40:
 
  00180a68: 00000000 nop  
 
  00180a68: 00000000 nop  
  
  # SECTION 3 : NO VALID ITEMS : FIND USABLE ITEM? (POTION, ETC?)
+
  # SECTION 3 : NO VALID ITEMS : FIND USABLE CHEMIST ITEM (EXCEPT ELIXIR)
  
 
  00180a6c: 16000014 bne r16,r0,0x00180ac0            #  IF ([Valid item count] = 0)
 
  00180a6c: 16000014 bne r16,r0,0x00180ac0            #  IF ([Valid item count] = 0)
Line 46: Line 46:
 
  00180a74: 0c0088c3 jal 0x0002230c                  #      r2 = [Random number]
 
  00180a74: 0c0088c3 jal 0x0002230c                  #      r2 = [Random number]
 
  00180a78: 00000000 nop
 
  00180a78: 00000000 nop
  00180a7c: 00021840 sll r3,r2,0x01
+
  00180a7c: 00021840 sll r3,r2,0x01                   #      r2 = [Random number] * 13
 
  00180a80: 00621821 addu r3,r3,r2
 
  00180a80: 00621821 addu r3,r3,r2
 
  00180a84: 00031880 sll r3,r3,0x02
 
  00180a84: 00031880 sll r3,r3,0x02
 
  00180a88: 00621021 addu r2,r3,r2                     
 
  00180a88: 00621021 addu r2,r3,r2                     
  00180a8c: 04410002 bgez r2,0x00180a98               
+
  00180a8c: 04410002 bgez r2,0x00180a98              #      [Unnecessary negative check?]
 
  00180a90: 00000000 nop                               
 
  00180a90: 00000000 nop                               
 
  00180a94: 24427fff addiu r2,r2,0x7fff               
 
  00180a94: 24427fff addiu r2,r2,0x7fff               
  00180a98: 000213c3 sra r2,r2,0x0f                   
+
  00180a98: 000213c3 sra r2,r2,0x0f                  #      r2 = roll(00,0D) #not including 0D
  00180a9c: 2442fff0 addiu r2,r2,0xfff0              #      r2 = [Random usable item]
+
  00180a9c: 2442fff0 addiu r2,r2,0xfff0              #      r2 = roll(F0,FD) #random Item except Phoenix Down.
 
  00180aa0: a3a20010 sb r2,0x0010(r29)                #      ValidItems[0] (STACK[0x10]) = r2
 
  00180aa0: a3a20010 sb r2,0x0010(r29)                #      ValidItems[0] (STACK[0x10]) = r2
 
  00180aa4: 93a30010 lbu r3,0x0010(r29)              #      r3 = r2
 
  00180aa4: 93a30010 lbu r3,0x0010(r29)              #      r3 = r2
  00180aa8: 00000000 nop                              #      IF (r3 >= 0xf5) (We found a usable item?)
+
  00180aa8: 00000000 nop                              #      ValidItemCount (r16) = 1
  00180aac: 2c6200f5 sltiu r2,r3,0x00f5              #     
+
  00180aac: 2c6200f5 sltiu r2,r3,0x00f5              #      IF (r3 >= 0xf5) #F5 is Elixir
  00180ab0: 14400003 bne r2,r0,0x00180ac0            #           ValidItemCount (r16) = 1
+
  00180ab0: 14400003 bne r2,r0,0x00180ac0            #       {  # Shift up by 1 to skip Elixir.
  00180ab4: 34100001 ori r16,r0,0x0001                #          r2 = r3 + 1
+
  00180ab4: 34100001 ori r16,r0,0x0001                #          r2 = r3 + 1 #Elixir-Remedy -> Antidote-Phoenix
 
  00180ab8: 24620001 addiu r2,r3,0x0001              #          ValidItems[0] = r2
 
  00180ab8: 24620001 addiu r2,r3,0x0001              #          ValidItems[0] = r2
 
  00180abc: a3a20010 sb r2,0x0010(r29)                #      }
 
  00180abc: a3a20010 sb r2,0x0010(r29)                #      }
Line 81: Line 81:
 
  00180af4: 03e00008 jr r31                          #  RETURN r2
 
  00180af4: 03e00008 jr r31                          #  RETURN r2
 
  00180af8: 00000000 nop
 
  00180af8: 00000000 nop
 +
 +
 +
== Return Locations ==
 +
 +
001805d8: [[Generate Crystal or Treasure]]

Latest revision as of 16:40, 11 October 2019

# ROUTINE : GENERATE TREASURE FOR TREASURE CHEST
#
#    PARAMETERS:
#        r4  =   [Treasure unit]
#        
#    RETURNS:
#        r2  =   [Item]
# SECTION 1 : SET UP
00180a08: 3c028019 lui r2,0x8019
00180a0c: 8c42f5fc lw r2,-0x0a04(r2)                #   r2 = MEM[0x18f5fc]
00180a10: 27bdffe0 addiu r29,r29,0xffe0
00180a14: afbf001c sw r31,0x001c(r29)               #   IF (r2 != 0)
00180a18: 14400033 bne r2,r0,0x00180ae8             #       RETURN r2
00180a1c: afb00018 sw r16,0x0018(r29)
00180a20: 00008021 addu r16,r0,r0                   #   r16 = 0 [Count of valid items]
00180a24: 00003021 addu r6,r0,r0                    #   r6 = 0  [Current equipment slot index]
00180a28: 27a50010 addiu r5,r29,0x0010              #   r5 =    [Valid item array pointer]  
# SECTION 2 : FIND VALID ITEMS ON TREASURE UNIT (EQUIPMENT) 
                                                    #   DO {
00180a2c: 00861021 addu r2,r4,r6                    #       
00180a30: 9042001a lbu r2,0x001a(r2)                #       r2 = MEM[r4+r6+0x1a) [Equip] (Equipment in current slot of treasure unit)
00180a34: 00000000 nop
00180a38: a0a20000 sb r2,0x0000(r5)                 #       ValidItems[i] (MEM[r5]) = [Equip]
00180a3c: 90a30000 lbu r3,0x0000(r5)
00180a40: 00000000 nop                              #       r6++ (LoopCount++)
00180a44: 2c6200fe sltiu r2,r3,0x00fe               #       IF ([Equip] >= 0xFE) (empty)
00180a48: 10400005 beq r2,r0,0x00180a60             #           CONTINUE (skip this item)
00180a4c: 24c60001 addiu r6,r6,0x0001
00180a50: 10600004 beq r3,r0,0x00180a64             #       IF ([Equip] == 0x00)
00180a54: 28c20007 slti r2,r6,0x0007                #           CONTINUE (skip this item)
00180a58: 24a50001 addiu r5,r5,0x0001               #       r5++ 
00180a5c: 26100001 addiu r16,r16,0x0001             #       r16++ (ValidItemCount++)
00180a60: 28c20007 slti r2,r6,0x0007
00180a64: 1440fff1 bne r2,r0,0x00180a2c             #   } WHILE (r6 < 7)
00180a68: 00000000 nop 
# SECTION 3 : NO VALID ITEMS : FIND USABLE CHEMIST ITEM (EXCEPT ELIXIR)
00180a6c: 16000014 bne r16,r0,0x00180ac0            #   IF ([Valid item count] = 0)
00180a70: 00000000 nop                              #   {   
00180a74: 0c0088c3 jal 0x0002230c                   #       r2 = [Random number]
00180a78: 00000000 nop
00180a7c: 00021840 sll r3,r2,0x01                   #       r2 = [Random number] * 13
00180a80: 00621821 addu r3,r3,r2
00180a84: 00031880 sll r3,r3,0x02
00180a88: 00621021 addu r2,r3,r2                    
00180a8c: 04410002 bgez r2,0x00180a98               #       [Unnecessary negative check?]
00180a90: 00000000 nop                              
00180a94: 24427fff addiu r2,r2,0x7fff               
00180a98: 000213c3 sra r2,r2,0x0f                   #       r2 = roll(00,0D) #not including 0D
00180a9c: 2442fff0 addiu r2,r2,0xfff0               #       r2 = roll(F0,FD) #random Item except Phoenix Down.
00180aa0: a3a20010 sb r2,0x0010(r29)                #       ValidItems[0] (STACK[0x10]) = r2
00180aa4: 93a30010 lbu r3,0x0010(r29)               #       r3 = r2
00180aa8: 00000000 nop                              #       ValidItemCount (r16) = 1
00180aac: 2c6200f5 sltiu r2,r3,0x00f5               #       IF (r3 >= 0xf5) #F5 is Elixir
00180ab0: 14400003 bne r2,r0,0x00180ac0             #       {   # Shift up by 1 to skip Elixir.
00180ab4: 34100001 ori r16,r0,0x0001                #           r2 = r3 + 1 #Elixir-Remedy -> Antidote-Phoenix
00180ab8: 24620001 addiu r2,r3,0x0001               #           ValidItems[0] = r2
00180abc: a3a20010 sb r2,0x0010(r29)                #       }
# SECTION 4 : RETURN RANDOM ITEM FROM VALID ITEMS LIST
00180ac0: 0c0088c3 jal 0x0002230c                   #   r2 = [Random number]
00180ac4: 00000000 nop
00180ac8: 00500018 mult r2,r16
00180acc: 00001012 mflo r2                          #   r2 = [Random index]
00180ad0: 04410003 bgez r2,0x00180ae0
00180ad4: 000233c3 sra r6,r2,0x0f
00180ad8: 24427fff addiu r2,r2,0x7fff
00180adc: 000233c3 sra r6,r2,0x0f
00180ae0: 03a61021 addu r2,r29,r6                   
00180ae4: 90420010 lbu r2,0x0010(r2)                #   r2 = ValidItems[RandomIndex]
00180ae8: 8fbf001c lw r31,0x001c(r29)
00180aec: 8fb00018 lw r16,0x0018(r29)
00180af0: 27bd0020 addiu r29,r29,0x0020
00180af4: 03e00008 jr r31                           #   RETURN r2
00180af8: 00000000 nop


Return Locations

001805d8: Generate Crystal or Treasure