Some event data setting routine

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
Seeks a new thread to run.
Start from currently running thread (0x80174038) and check the running flag (0x48)
 - If the thread is running, changes all the registers values (r16 to r31)
 - If there's no running thread after the current one switch to thread 0x00
-----------------------------------------------------------------------------------------
0014ca80: 3c018017 lui r1,0x8017            |
0014ca84: 00200821 addu r1,r1,r0            |
0014ca88: 8c284038 lw r8,0x4038(r1)         |r8 = Currently running thread  0x80174038
0014ca8c: 00000000 nop                      |
0014ca90: 00084280 sll r8,r8,0x0a           |r8 = Currently running thread * 0x400
0014ca94: 3c018016 lui r1,0x8016            |
0014ca98: 00200821 addu r1,r1,r0            |
0014ca9c: 8c295f98 lw r9,0x5f98(r1)         |r3 = 8016986c - Thread array data pointer (EVTCHR)  0x80165f98
0014caa0: 00000000 nop                      |
0014caa4: 01094021 addu r8,r8,r9            |r8 = Currently running thread data pointer
0014caa8: ad100010 sw r16,0x0010(r8)        |Store all register in currently running thread
0014caac: ad110014 sw r17,0x0014(r8)        |
0014cab0: ad120018 sw r18,0x0018(r8)        |
0014cab4: ad13001c sw r19,0x001c(r8)        |
0014cab8: ad140020 sw r20,0x0020(r8)        |
0014cabc: ad150024 sw r21,0x0024(r8)        |
0014cac0: ad160028 sw r22,0x0028(r8)        |
0014cac4: ad17002c sw r23,0x002c(r8)        |
0014cac8: ad1a0030 sw r26,0x0030(r8)        |
0014cacc: ad1b0034 sw r27,0x0034(r8)        |
0014cad0: ad1c0038 sw r28,0x0038(r8)        |
0014cad4: ad1d003c sw r29,0x003c(r8)        |
0014cad8: ad1e0040 sw r30,0x0040(r8)        |
0014cadc: ad1f0044 sw r31,0x0044(r8)        |
0014cae0: 25080400 addiu r8,r8,0x0400       @LOOP r8 = Next thread data pointer Seek a running thread after current thread
0014cae4: 3c018017 lui r1,0x8017                 |
0014cae8: 00200821 addu r1,r1,r0                 |
0014caec: 8c2a4038 lw r10,0x4038(r1)             |r10 = Currently running thread ID
0014caf0: 00000000 nop                           |
0014caf4: 254a0001 addiu r10,r10,0x0001          |r10 = Next Thread ID
0014caf8: 3c018017 lui r1,0x8017                 |
0014cafc: 00200821 addu r1,r1,r0                 |
0014cb00: ac2a4038 sw r10,0x4038(r1)             |Store next Thread ID in Currently running thread
0014cb04: 340b0010 ori r11,r0,0x0010             |r11 = 0x10
0014cb08: 114b0007 beq r10,r11,0x0014cb28        #If Next Thread ID <> 0x10 (Last Thread)
0014cb0c: 00000000 nop                               |
0014cb10: 8d0b0048 lw r11,0x0048(r8)                 |r11 = Thread's Is Running flag
0014cb14: 00000000 nop                               |
0014cb18: 140b0009 bne r0,r11,0x0014cb40             #If T his thread is not running loop /If thread is running, branch avoiding return to 1st thread
0014cb1c: 00000000 nop                               |
0014cb20: 080532b8 j 0x0014cae0             Λ LOOP while not at the last Thread
0014cb24: 00000000 nop    
                  
                                     Last thread is reached and not running
0014cb28: 3c018016 lui r1,0x8016                 |r1 = 0x80160000
0014cb2c: 00200821 addu r1,r1,r0                 |
0014cb30: 8c285f98 lw r8,0x5f98(r1)              |r8 = 8016986c - 1st Thread array data pointer (EVTCHR)  0x80165f98
0014cb34: 3c018017 lui r1,0x8017                 |
0014cb38: 00200821 addu r1,r1,r0                 |
0014cb3c: ac204038 sw r0,0x4038(r1)              |set 0x00 in currently running thread ID

                                     Thread is set (0x00 or New ID)
0014cb40: 0c050b2a jal 0x00142ca8           |-->00142ca8_-_00142d28  Store value at 0x801697d0 (based on thread task) - Might nullify 0x8016d9b8
0014cb44: 00000000 nop                      |
0014cb48: 3c018017 lui r1,0x8017            |
0014cb4c: 00200821 addu r1,r1,r0            |
0014cb50: 8c284038 lw r8,0x4038(r1)         |r8 = Currently running thread ID
0014cb54: 00000000 nop                      |
0014cb58: 00084280 sll r8,r8,0x0a           |r8 = Currently running thread ID x 0x400
0014cb5c: 3c018016 lui r1,0x8016            |
0014cb60: 00200821 addu r1,r1,r0            |
0014cb64: 8c295f98 lw r9,0x5f98(r1)         |r9 = 8016986c - 1st Thread array data pointer (EVTCHR)
0014cb68: 00000000 nop                      |
0014cb6c: 01094021 addu r8,r8,r9            |r8 = New thread data pointer
0014cb70: 8d100010 lw r16,0x0010(r8)        |load all register from new thread
0014cb74: 8d110014 lw r17,0x0014(r8)        |
0014cb78: 8d120018 lw r18,0x0018(r8)        |
0014cb7c: 8d13001c lw r19,0x001c(r8)        |
0014cb80: 8d140020 lw r20,0x0020(r8)        |
0014cb84: 8d150024 lw r21,0x0024(r8)        |
0014cb88: 8d160028 lw r22,0x0028(r8)        |
0014cb8c: 8d17002c lw r23,0x002c(r8)        |
0014cb90: 8d1a0030 lw r26,0x0030(r8)        |
0014cb94: 8d1b0034 lw r27,0x0034(r8)        |
0014cb98: 8d1c0038 lw r28,0x0038(r8)        |
0014cb9c: 8d1d003c lw r29,0x003c(r8)        |
0014cba0: 8d1e0040 lw r30,0x0040(r8)        |
0014cba4: 8d1f0044 lw r31,0x0044(r8)        |Might load a different return address
0014cba8: 00000000 nop                      
0014cbac: 03e00008 jr r31                   
0014cbb0: 00000000 nop                      

Return locations

Battle.bin
0012dbf8:
0012dc48:
0012dda4:
0012de7c:
0012dea4:
0012efe0:
0012f7b4:
001306f8:
001316a4:
001316c4:
00131a78:
00131b44:
00131bd4:
00131c94:
00131cfc:
00131d58:
00131f30:
00132028:
001320d0:
00132188:
00132198:
00132230:
001327e8:
00132b80:
00132cb4:
00132da8:
00132fb4:
001345b4:
001346b8:
00136068:
001360c0:
001362d4:
001362dc:
00136354:
0013635c:
001367ac:
00136ab4:
00136f18:
00137070:
0013713c:
001375bc:
00137754:
001377d0:
001377d8:
00137af0:
00138e24:
00138e9c:
00138fa4:
0013907c:
0013a27c:
0013a34c:
0013a844:
0013ae78:
0013b100:
0013b23c:
0013b3d0:
0013b4bc:
0013b524:
0013b55c:
0013bbac:
0013bc38:
0013bc78:
0013bce0:
0013bd20:
0013bff8:
0013c04c:
0013c0d0:
0013c150:
0013c358:
0013c428:
0013c6c8:
0013c6d0:
0013c818:
0013c848:
0013c878:
0013c8e4:
0013c914:
0013c9a0:
0013c9e4:
0013ca18:
0013cd50:
0013d208:
0013d218:
0013df64:
0013e5a4:
0013e7f8:
0013e84c:
0013e8a8:
0013ef24:
001407d8:
00141520:
00142c08:
001431b0:
00143ed4:
0014400c:
001440bc:
001440d8:
001440e0:
00144218:
00144234:
0014423c:
001442cc:
001442e4:
001442fc:
00144674:
001447b4:
001447d8:
00144820:
00144844:
001449dc:
00144a14:
00144b68:
00144d94:
00144dbc:
001453e4:
0014540c:
0014542c:
00145490:
001454b0:
001454d0:
001454f0:
00145524:
00145544:
00145594:
001458c4:
001458f0:
0014597c:
001459d8:
00145a54:
00145d0c:
00145d14:
00145db8:
00145f94:
001460c0:
001465a0:
00146678:
00146760:
00146854:
0014685c:
00146910:
00146918:
00146b20:
00146eb0:
00146ff4:
0014991c:
00149980:
00149ab4:
0014a444:
0014a500:
0014c87c:
0014c984: 0014c958_-_0014c990
0014c9e8: