Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RAM_ARM9:0203F040 @ =============== S U B R O U T I N E =======================================
- RAM_ARM9:0203F040
- RAM_ARM9:0203F040
- RAM_ARM9:0203F040 sub_203F040:
- RAM_ARM9:0203F040 00 C0 9F E5 LDR R12, =sub_208CDAC
- RAM_ARM9:0203F044 1C FF 2F E1 BX R12 ; sub_208CDAC @ THUMB veneer
- RAM_ARM9:0203F044 @ End of function sub_203F040
- RAM_ARM9:0203F044
- RAM_ARM9:0203F044 @ ---------------------------------------------------------------------------
- RAM_ARM9:0203F048 AC CD 08 02 off_203F048: .long sub_208CDAC @ DATA XREF: sub_203F040r
- RAM_ARM9:0203F04C
- RAM_ARM9:0203F04C @ =============== S U B R O U T I N E =======================================
- RAM_ARM9:0203F04C
- RAM_ARM9:0203F04C
- RAM_ARM9:0203F04C setMT__: @ CODE XREF: setRands__+10p
- RAM_ARM9:0203F04C @ sub_203AE38+78p ...
- RAM_ARM9:0203F04C 08 40 2D E9 STMFD SP!, {R3,LR}
- RAM_ARM9:0203F050 60 10 9F E5 LDR R1, =0x2146A18 @ pointer to MT table
- RAM_ARM9:0203F054 01 20 A0 E3 MOV R2, #1
- RAM_ARM9:0203F058 00 30 91 E5 LDR R3, [R1] @ location of table from pointer
- RAM_ARM9:0203F05C 00 00 83 E5 STR R0, [R3] @ store rng >> 32 as the first 32-bit seed in the first table
- RAM_ARM9:0203F060 00 00 91 E5 LDR R0, [R1] @ location of table from pointer
- RAM_ARM9:0203F064 C0 29 80 E5 STR R2, [R0,#0x9C0] @ set the table counter to 1
- RAM_ARM9:0203F068 00 00 91 E5 LDR R0, [R1] @ location of table from pointer
- RAM_ARM9:0203F06C C0 E9 90 E5 LDR LR, [R0,#0x9C0] @ load the value we just stored (1) into r14...
- RAM_ARM9:0203F070 27 0E 5E E3 CMP LR, #0x270 @ and compare against 0x270 (should always be less than)
- RAM_ARM9:0203F074 08 80 BD A8 LDMFDGE SP!, {R3,PC} @ pop back if greater than or equal 0x270 (this should never happen)
- RAM_ARM9:0203F074 @ End of function setMT__
- RAM_ARM9:0203F074
- RAM_ARM9:0203F078
- RAM_ARM9:0203F078 @ =============== S U B R O U T I N E =======================================
- RAM_ARM9:0203F078
- RAM_ARM9:0203F078
- RAM_ARM9:0203F078 buildTempMT__:
- RAM_ARM9:0203F078 3C 00 9F E5 LDR R0, =0x6C078965 @ this is step 1 in the MT -> initialization sequence for the seed table
- RAM_ARM9:0203F07C
- RAM_ARM9:0203F07C loc_203F07C: @ CODE XREF: buildTempMT__+38j
- RAM_ARM9:0203F07C 00 C0 91 E5 LDR R12, [R1] @ location of the MT table top
- RAM_ARM9:0203F080 0E 21 8C E0 ADD R2, R12, LR,LSL#2 @ r2 = ((table counter * 4) + table top)
- RAM_ARM9:0203F084 04 20 12 E5 LDR R2, [R2,#-4] @ r2 = value of the current address pointed to in r2
- RAM_ARM9:0203F088 22 2F 22 E0 EOR R2, R2, R2,LSR#30 @ r2 = r2 ^ (r2 >> 30)
- RAM_ARM9:0203F08C 92 E0 23 E0 MLA R3, R2, R0, LR @ r3 = (r2 * r0) + r14
- RAM_ARM9:0203F090 0E 31 8C E7 STR R3, [R12,LR,LSL#2] @ store result to ((table counter * 4) + table top)
- RAM_ARM9:0203F094 00 30 91 E5 LDR R3, [R1] @ r3 = location of the MT table top
- RAM_ARM9:0203F098 C0 29 93 E5 LDR R2, [R3,#0x9C0] @ r2 = table counter
- RAM_ARM9:0203F09C 01 20 82 E2 ADD R2, R2, #1 @ counter++
- RAM_ARM9:0203F0A0 C0 29 83 E5 STR R2, [R3,#0x9C0] @ store back new counter value
- RAM_ARM9:0203F0A4 00 20 91 E5 LDR R2, [R1] @ r2 = location of the MT table top
- RAM_ARM9:0203F0A8 C0 E9 92 E5 LDR LR, [R2,#0x9C0] @ r14 = current counter
- RAM_ARM9:0203F0AC 27 0E 5E E3 CMP LR, #0x270 @ have we set up the full temp MT table yet?
- RAM_ARM9:0203F0B0 F1 FF FF BA BLT loc_203F07C @ if less, it's not done, so go back for the next iteration
- RAM_ARM9:0203F0B4 08 80 BD E8 LDMFD SP!, {R3,PC}
- RAM_ARM9:0203F0B4 @ End of function buildTempMT__
- RAM_ARM9:0203F0B4
- RAM_ARM9:0203F0B4 @ ---------------------------------------------------------------------------
- RAM_ARM9:0203F0B8 18 6A 14 02 dword_203F0B8: .long 0x2146A18 @ DATA XREF: setMT__+4r
- RAM_ARM9:0203F0BC 65 89 07 6C dword_203F0BC: .long 0x6C078965 @ DATA XREF: buildTempMT__r
- RAM_ARM9:0203F0C0
- RAM_ARM9:0203F0C0 @ =============== S U B R O U T I N E =======================================
- RAM_ARM9:0203F0C0
- RAM_ARM9:0203F0C0
- RAM_ARM9:0203F0C0 mtHandler__: @ CODE XREF: sub_2011D34+2p
- RAM_ARM9:0203F0C0 @ sub_2011D34+6p ...
- RAM_ARM9:0203F0C0 10 40 2D E9 STMFD SP!, {R4,LR}
- RAM_ARM9:0203F0C4 34 41 9F E5 LDR R4, =0x2146A18 @ pointer to MT table start
- RAM_ARM9:0203F0C8 00 00 94 E5 LDR R0, [R4] @ load actual offset of pointer table into r0
- RAM_ARM9:0203F0CC C0 19 90 E5 LDR R1, [R0,#0x9C0] @ load value @ top of table+ 0x9C0(this is the table pointer, word-aligned)
- RAM_ARM9:0203F0D0 27 0E 51 E3 CMP R1, #0x270 @ Is the table pointer maxed out?
- RAM_ARM9:0203F0D4 3A 00 00 BA BLT getNextValue__ @ If not go to 0x203F1C4 and advance once
- RAM_ARM9:0203F0D8 24 01 9F E5 LDR R0, =0x271 @ if r1 isn't less than 0x270, r0 = 0x271
- RAM_ARM9:0203F0DC 00 00 51 E1 CMP R1, R0 @ current counter value - 0x271
- RAM_ARM9:0203F0E0 01 00 00 1A BNE loc_203F0EC @ if the value isn't equal to 0x271, branch to 0x203F0EC- at this point, it must be @ 0x270, so make a new table up
- RAM_ARM9:0203F0E4 13 0C 80 E2 ADD R0, R0, #0x1300 @ r0 +=0x1300 (arg to pass to setMT() )
- RAM_ARM9:0203F0E8 D7 FF FF EB BL setMT__ @ set up each iteration of the MT table
- RAM_ARM9:0203F0EC
- RAM_ARM9:0203F0EC loc_203F0EC: @ CODE XREF: reseedMTTable__+20j
- RAM_ARM9:0203F0EC 00 10 A0 E3 MOV R1, #0 @ value @ 0x203F0DC was 0x270, let's set up a new table
- RAM_ARM9:0203F0F0
- RAM_ARM9:0203F0F0 loc_203F0F0: @ CODE XREF: reseedMTTable__+70j
- RAM_ARM9:0203F0F0 00 00 94 E5 LDR R0, [R4] @ load actual offset of pointer table into r0
- RAM_ARM9:0203F0F4 01 31 80 E0 ADD R3, R0, R1,LSL#2 @ r3 = table top + (counter * 4) (current table position/offset, basically)
- RAM_ARM9:0203F0F8 04 20 93 E5 LDR R2, [R3,#4] @ load the next 32-bit seed into r2
- RAM_ARM9:0203F0FC 01 C1 90 E7 LDR R12, [R0,R1,LSL#2] @ r12 = *(table top + (counter * 4)) (current seed, basically)
- RAM_ARM9:0203F100 02 21 C2 E3 BIC R2, R2, #0x80000000 @ clear the highest bit(bit 31, 32nd bit) on the seed in r2(next seed)
- RAM_ARM9:0203F104 02 C1 0C E2 AND R12, R12, #0x80000000 @ AND the highest bit(bit 31, 32nd bit) on the seed in r12(current seed)
- RAM_ARM9:0203F108 02 C0 8C E1 ORR R12, R12, R2 @ r12 = (AND-ed current seed) | (bit-cleared next seed)
- RAM_ARM9:0203F10C 8C 2F A0 E1 MOV R2, R12,LSL#31 @ r2 = (r2 << 31) (set the lowest bit to the highest position- either 0 if even or 0x80000000 if seed was odd)
- RAM_ARM9:0203F110 A2 2E 80 E0 ADD R2, R0, R2,LSR#29 @ r2 = r0 + (r2 >> 29)
- RAM_ARM9:0203F114 34 36 93 E5 LDR R3, [R3,#0x634] @ r3 = 397th array element(seed) from the current seed- if current is mt[i], r3 = mt[i+397]
- RAM_ARM9:0203F118 C4 29 92 E5 LDR R2, [R2,#0x9C4] @ r2 = 0x9908B0DF - constant vector
- RAM_ARM9:0203F11C AC 30 23 E0 EOR R3, R3, R12,LSR#1 @ r3 = r3 ^ (r12 >> 1)
- RAM_ARM9:0203F120 02 20 23 E0 EOR R2, R3, R2 @ r2 = r3 ^ 0x9908B0DF
- RAM_ARM9:0203F124 01 21 80 E7 STR R2, [R0,R1,LSL#2] @ store the result of the constant vector to (table top + (counter * 4))
- RAM_ARM9:0203F128 01 10 81 E2 ADD R1, R1, #1 @ counter++
- RAM_ARM9:0203F12C E3 00 51 E3 CMP R1, #0xE3 @ 'p' @ is counter less than 227?
- RAM_ARM9:0203F130 EE FF FF BA BLT loc_203F0F0 @ yes? jump back to the top and keep looping until counter(r1) is at 227, then continue
- RAM_ARM9:0203F134 CC 20 9F E5 LDR R2, =0x26F
- RAM_ARM9:0203F138 02 00 51 E1 CMP R1, R2 @ at this point, the counter has to be 0xE3, so this is 0xE3- 0x26F, so r1 is not greater than r2, it can't happen
- RAM_ARM9:0203F13C 10 00 00 AA BGE loc_203F184 @ this doesn't seem like it should be able to happen
- RAM_ARM9:0203F140
- RAM_ARM9:0203F140 loc_203F140: @ CODE XREF: reseedMTTable__+C0j
- RAM_ARM9:0203F140 00 00 94 E5 LDR R0, [R4] @ load actual offset of pointer table into r0
- RAM_ARM9:0203F144 01 C1 80 E0 ADD R12, R0, R1,LSL#2 @ r12 = table top + (counter * 4) (current table position/offset, basically)
- RAM_ARM9:0203F148 01 E1 90 E7 LDR LR, [R0,R1,LSL#2] @ r14 = *(table top + (counter * 4)) (current seed, basically)
- RAM_ARM9:0203F14C 04 30 9C E5 LDR R3, [R12,#4] @ r3 = next seed
- RAM_ARM9:0203F150 02 E1 0E E2 AND LR, LR, #0x80000000 @ current seed AND 0x80000000
- RAM_ARM9:0203F154 02 31 C3 E3 BIC R3, R3, #0x80000000 @ clear the highest bit of the next seed
- RAM_ARM9:0203F158 03 E0 8E E1 ORR LR, LR, R3 @ (current seed & 0x80000000) | (next seed, cleared highest bit)
- RAM_ARM9:0203F15C 8E 3F A0 E1 MOV R3, LR,LSL#31 @ r3 = (current seed AND 0x80000000) << 31- basically set r3 with the lowest bit from the current manipulated seed in r14- either 0 or 0x80000000 if it's odd
- RAM_ARM9:0203F160 A3 3E 80 E0 ADD R3, R0, R3,LSR#29 @ r3 = (address of top of table) + (r3 >> 29)
- RAM_ARM9:0203F164 8C C3 1C E5 LDR R12, [R12,#-0x38C] @ current table/array position - 0xE3(227d) slots
- RAM_ARM9:0203F168 C4 39 93 E5 LDR R3, [R3,#0x9C4] @ r3 = 0x9908B0DF
- RAM_ARM9:0203F16C AE C0 2C E0 EOR R12, R12, LR,LSR#1 @ r12 = r12 ^ (r14 >> 1)
- RAM_ARM9:0203F170 03 30 2C E0 EOR R3, R12, R3 @ r3 = r12 ^ 0x9908B0DF
- RAM_ARM9:0203F174 01 31 80 E7 STR R3, [R0,R1,LSL#2] @ store r3 back as the current seed
- RAM_ARM9:0203F178 01 10 81 E2 ADD R1, R1, #1 @ counter++
- RAM_ARM9:0203F17C 02 00 51 E1 CMP R1, R2 @ while counter < 0x26F..
- RAM_ARM9:0203F180 EE FF FF BA BLT loc_203F140 @ keep repeating this loop
- RAM_ARM9:0203F184
- RAM_ARM9:0203F184 loc_203F184: @ CODE XREF: reseedMTTable__+7Cj
- RAM_ARM9:0203F184 00 C0 94 E5 LDR R12, [R4] @ load actual offset of pointer table into r12
- RAM_ARM9:0203F188 00 10 A0 E3 MOV R1, #0
- RAM_ARM9:0203F18C BC 29 9C E5 LDR R2, [R12,#0x9BC] @ r2 = last seed in the array/table
- RAM_ARM9:0203F190 00 00 9C E5 LDR R0, [R12] @ r0 = current seed
- RAM_ARM9:0203F194 02 21 02 E2 AND R2, R2, #0x80000000 @ r2 = last seed & 0x80000000
- RAM_ARM9:0203F198 02 01 C0 E3 BIC R0, R0, #0x80000000 @ clear the highest bit on the current seed
- RAM_ARM9:0203F19C 00 30 82 E1 ORR R3, R2, R0 @ r3 = (last seed & 0x80000000) | (bit-cleared current seed)
- RAM_ARM9:0203F1A0 83 0F A0 E1 MOV R0, R3,LSL#31 @ r0 = r3 << 31; r0 = lowest bit of r3, so 0 or 0x80000000
- RAM_ARM9:0203F1A4 A0 0E 8C E0 ADD R0, R12, R0,LSR#29 @ r0 = (table location) + (r0 >> 29)
- RAM_ARM9:0203F1A8 30 26 9C E5 LDR R2, [R12,#0x630] @ load the 397th seed into r2
- RAM_ARM9:0203F1AC C4 09 90 E5 LDR R0, [R0,#0x9C4] @ r0 = 0x9908B0DF
- RAM_ARM9:0203F1B0 A3 20 22 E0 EOR R2, R2, R3,LSR#1 @ r2 = (397th seed) ^ (((last seed & 0x80000000) | (bit-cleared current seed)) >> 1)
- RAM_ARM9:0203F1B4 00 00 22 E0 EOR R0, R2, R0 @ r0 = 0x9908B0DF ^ ((397th seed) ^ (((last seed & 0x80000000) | (bit-cleared current seed)) >> 1))
- RAM_ARM9:0203F1B8 BC 09 8C E5 STR R0, [R12,#0x9BC] @ store result as the last seed in the table
- RAM_ARM9:0203F1BC 00 00 94 E5 LDR R0, [R4] @ r0 = address of table top
- RAM_ARM9:0203F1C0 C0 19 80 E5 STR R1, [R0,#0x9C0] @ store the current counter back
- RAM_ARM9:0203F1C4
- RAM_ARM9:0203F1C4 getNextValue__: @ CODE XREF: reseedMTTable__+14j
- RAM_ARM9:0203F1C4 00 C0 94 E5 LDR R12, [R4] @ load the address of the top of the table into r12
- RAM_ARM9:0203F1C8 3C 00 9F E5 LDR R0, =0x9D2C5680 @ tempering mask A
- RAM_ARM9:0203F1CC C0 39 9C E5 LDR R3, [R12,#0x9C0] @ load the current word-aligned table pointer value into r3(we already know it's below 0x270, so still insde the current table)
- RAM_ARM9:0203F1D0 38 10 9F E5 LDR R1, =0xEFC60000 @ tempering mask B
- RAM_ARM9:0203F1D4 01 20 83 E2 ADD R2, R3, #1 @ counter++
- RAM_ARM9:0203F1D8 C0 29 8C E5 STR R2, [R12,#0x9C0] @ now that 1 is added to the counter, the current position in our table is updated. store the new value away for safe keeping.
- RAM_ARM9:0203F1DC 00 20 94 E5 LDR R2, [R4] @ load the address of the top of the table into r2
- RAM_ARM9:0203F1E0 03 21 92 E7 LDR R2, [R2,R3,LSL#2] @ load into r2 the value of the top of the table + the table counter *4(word-aligned, so ((value*4) +top of table) gives you the current table position)
- RAM_ARM9:0203F1E4 A2 25 22 E0 EOR R2, R2, R2,LSR#11 @ r2 = r2 ^ (r2 >> 11)
- RAM_ARM9:0203F1E8 82 03 00 E0 AND R0, R0, R2,LSL#7 @ r0(currently 0x9D2C5680) = (r2 << 7) & 0x9D2C5680
- RAM_ARM9:0203F1EC 00 20 22 E0 EOR R2, R2, R0 @ r2 = ((r2 << 7) & 0x9D2C5680) ^ r2
- RAM_ARM9:0203F1F0 82 07 01 E0 AND R0, R1, R2,LSL#15 @ r0 = (r2 <<15) & 0xEFC60000 - eliminates the bottom half of the number
- RAM_ARM9:0203F1F4 00 00 22 E0 EOR R0, R2, R0 @ r0 = r2 ^ r0
- RAM_ARM9:0203F1F8 20 09 20 E0 EOR R0, R0, R0,LSR#18 @ r0 = r0 ^ (r0 >> 18)
- RAM_ARM9:0203F1FC 10 80 BD E8 LDMFD SP!, {R4,PC} @ return the seed in r0
- RAM_ARM9:0203F1FC @ End of function reseedMTTable__
- RAM_ARM9:0203F1FC
- RAM_ARM9:0203F1FC @ ---------------------------------------------------------------------------
- RAM_ARM9:0203F200 18 6A 14 02 dword_203F200: .long 0x2146A18 @ DATA XREF: reseedMTTable__+4r
- RAM_ARM9:0203F204 71 02 00 00 dword_203F204: .long 0x271 @ DATA XREF: reseedMTTable__+18r
- RAM_ARM9:0203F208 6F 02 00 00 dword_203F208: .long 0x26F @ DATA XREF: reseedMTTable__+74r
- RAM_ARM9:0203F20C 80 56 2C 9D dword_203F20C: .long 0x9D2C5680 @ DATA XREF: reseedMTTable__+108r
- RAM_ARM9:0203F210 00 00 C6 EF dword_203F210: .long 0xEFC60000 @ DATA XREF: reseedMTTable__+110r
Advertisement