Advertisement
Guest User

Hextator

a guest
Mar 25th, 2010
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.34 KB | None | 0 0
  1. .set noreorder
  2.  
  3. ;.org 0x800B5000
  4. SD T3, 0x0070 (K0) ;
  5. SD T4, 0x0078 (K0) ;
  6. SD T5, 0x0080 (K0) ;
  7. SD T6, 0x0088 (K0) ;
  8. SD T7, 0x0090 (K0) ;
  9. SD S0, 0x0098 (K0) ;
  10. SD S1, 0x00A0 (K0) ;
  11. SD S2, 0x00A8 (K0) ;
  12. SD S3, 0x00B0 (K0) ;
  13. SD S4, 0x00B8 (K0) ;
  14. SD S5, 0x00C0 (K0) ;
  15. SD S6, 0x00C8 (K0) ;
  16. SD S7, 0x00D0 (K0) ;
  17. SD T8, 0x00D8 (K0) ;
  18. SD T9, 0x00E0 (K0) ;
  19.  
  20. ;;; Begin trainer ;;;
  21. ; V0-A3 and above stored regs are available
  22.  
  23. ; Clears 0x800750C4 to 0x800750F0
  24. ; if and only if [0x800750C4] != 0
  25. LUI V0, 0x8007 ;
  26. ORI V0, V0, 0x50C4 ;
  27. LW V1, 0x0000 (V0) ;
  28. BEQZ V1, No_Clear
  29. ORI V1, R0, 0x0024 ;Bytes to clear - 4 (storing words)
  30. Clear_Loop:
  31. SW R0, 0x0000 (V0) ;
  32. ADDIU V0, V0, 0x0004 ;
  33. BNEZL V1, Clear_Loop
  34. ADDIU V1, V1, -0x0004 ;
  35. ;-------------------------------;End clearing of trainer loading code
  36. ;-------------------------------;If this code is being executed then it must be loaded anyway
  37. No_Clear:
  38. LUI V0, 0x800B ;Code base
  39. ORI V0, V0, 0x6000 ;=0x800B6000
  40. Interpret_Loop:
  41. LW V1, 0x0000 (V0) ;First word
  42. ADDIU A1, R0, -0x0001 ;
  43. BEQ V1, A1, Exit
  44. SRL A0, V1, 0x18 ;Code type
  45. ;ANDI A0, A0, 0x00FF ;Should be unnecessary
  46. ANDI A1, A0, 0x00F0 ;Code type without sub type
  47. LUI A3, 0x0100 ;
  48. ADDIU A3, A3, -0x0001 ;
  49. AND V1, V1, A3 ;Address (for most code types)
  50. LUI A3, 0x8000 ;
  51. OR V1, V1, A3 ;Address with top bit set
  52. ORI A2, R0, 0x0080 ;
  53. BEQ A1, A2, Type_8X
  54. ORI A2, R0, 0x00D0 ;
  55. BEQ A1, A2, Type_DX
  56. ORI A2, R0, 0x00C0 ;
  57. BEQ A1, A2, Type_CX
  58. NOP
  59. J 0x000B5000 + Interpret_Loop
  60. ADDIU V0, V0, 0x0008 ;Invalid code type
  61.  
  62. ;Currently:
  63. ;V0 is interpreter pointer
  64. ;V1 is X - Address
  65. ;A0 is code type
  66.  
  67. ;Interface
  68. ;S0 is I - Increment (amount to increment data)
  69. ;S1 is M - Mask
  70. ;S2 is N - Count
  71. ;S3 is O - Offset (increment amount for address)
  72. ;S4 is ? - Scratch (execution status (0 == false; anything else == true))
  73. ;S5 is Y - Data
  74. ;S6 is ? - Scratch (data at address)
  75. ;S7 is ? - Scratch (current data of code to process)
  76.  
  77. ;-------------------------------;
  78. ; WRITE CODES ;
  79. ;-------------------------------;
  80. Type_8X:
  81. LW S5, 0x0004 (V0) ;Data extracted
  82. LW S6, 0x0000 (V1) ;Data at address extracted
  83. ADDIU V0, V0, 0x0008 ;Interpreter pointer on next code line
  84. ;-------------------------------;
  85. ORI A1, R0, 0x0080 ;Code 80?
  86. BEQL A0, A1, Interpret_Loop
  87. SB S5, 0x0000 (V1) ;Code 80 done
  88. ;-------------------------------;
  89. ORI A1, R0, 0x0081 ;Code 81?
  90. BEQL A0, A1, Interpret_Loop
  91. SH S5, 0x0000 (V1) ;Code 81 done
  92. ;-------------------------------;
  93. ORI A1, R0, 0x0082 ;Code 82?
  94. BEQL A0, A1, Interpret_Loop
  95. SW S5, 0x0000 (V1) ;Code 82 done
  96. ;-------------------------------;
  97. OR T8, S5, S6 ;T8 = Data at address OR data
  98. AND T9, S5, S6 ;T9 = Data at address AND data
  99. ;-------------------------------;
  100. ORI A1, R0, 0x0083 ;Code 83?
  101. BEQL A0, A1, Interpret_Loop
  102. SW T8, 0x0000 (V1) ;Code 83 done
  103. ;-------------------------------;
  104. ORI A1, R0, 0x0084 ;Code 84?
  105. BEQL A0, A1, Interpret_Loop
  106. SW T9, 0x0000 (V1) ;Code 84 done
  107. ;-------------------------------;
  108. ORI A1, R0, 0x0085 ;Code 85?
  109. BNE A0, A1, Code_86
  110. OR S2, S5, R0 ;Count extracted
  111. Type_85_Loop:
  112. BEQZ S2, Interpret_Loop
  113. LD S5, 0x0000 (V0) ;
  114. SD S5, 0x0000 (V1) ;
  115. ADDIU V0, V0, 0x0008 ;
  116. ADDIU V1, V1, 0x0008 ;
  117. J 0x000B5000 + Type_85_Loop
  118. ADDIU S2, S2, -0x0001 ;Code 85 done
  119. ;-------------------------------;
  120. Code_86:
  121. ORI A1, R0, 0x0086 ;Code 86?
  122. BNE A0, A1, Code_87
  123. ;-------------------------------;
  124. LB A1, 0x0000 (V0) ;Check code type of next line
  125. ANDI A1, A1, 0x00F0 ;
  126. ORI A2, R0, 0x0090 ;Compare to code type 9
  127. BNE A1, A2, Interpret_Loop
  128. ;-------------------------------;
  129. LW S7, 0x0004 (V0) ;Latter half of next code line loaded
  130. ANDI S0, S7, 0xFFFF ;Increment extracted
  131. SLL S0, S0, 0x10 ;
  132. SRA S0, S0, 0x10 ;Increment is now signed halfword
  133. SRA S3, S7, 0x10 ;Offset extracted as signed halfword
  134. LW S7, 0x0000 (V0) ;First half of next code line loaded
  135. ANDI S2, S7, 0xFFFF ;Count extracted
  136. SRL S7, S7, 0x10 ;
  137. ANDI S1, S7, 0x0003 ;Mask extracted
  138. ORI T8, R0, 0x0003 ;Check if mask is invalid
  139. BEQL S1, T8, Code_86_Invalid_Mask
  140. ORI S1, R0, 0x0000 ;Mask fixed
  141. Code_86_Invalid_Mask:
  142. ;-------------------------------;
  143. Type_86_Loop:
  144. BEQZL S2, Interpret_Loop
  145. ADDIU V0, V0, 0x0008 ;Interpreter pointer updated
  146. ;-------------------------------;
  147. ORI T8, R0, 0x0000 ;Check for byte write
  148. BEQL S1, T8, Code_86_Write_Byte
  149. SB S5, 0x0000 (V1) ;Handle byte repeats
  150. Code_86_Write_Byte:
  151. ;-------------------------------;
  152. ORI T8, R0, 0x0001 ;Check for halfword write
  153. BEQL S1, T8, Code_86_Write_Halfword
  154. SH S5, 0x0000 (V1) ;Handle halfword repeats
  155. Code_86_Write_Halfword:
  156. ;-------------------------------;
  157. ORI T8, R0, 0x0002 ;Check for word write
  158. BEQL S1, T8, Code_86_Write_Word
  159. SW S5, 0x0000 (V1) ;Handle word repeats
  160. Code_86_Write_Word:
  161. ;-------------------------------;
  162. ADDU V1, V1, S3 ;Increment address by offset
  163. ADDU S5, S5, S0 ;Increment data by increment
  164. J 0x000B5000 + Type_86_Loop
  165. ADDIU S2, S2, -0x0001 ;Code 86 done
  166. Code_87:
  167. ORI A1, R0, 0x0087 ;
  168. BNE A0, A1, Interpret_Loop
  169. SRL S5, V0, 0x02 ;
  170. LUI S7, 0x2800 ;
  171. XOR S5, S5, S7 ;S5 = J instruction to next code line
  172. J 0x000B5000 + Skip_Until_Terminator
  173. SW S5, 0x0000 (V1) ;J instruction written
  174. ;-------------------------------;Next instruction is safe to execute in delay slot
  175. ;-------------------------------;
  176. ; CONDITION CODES ;
  177. ;-------------------------------;
  178. Type_DX:
  179. LW S5, 0x0004 (V0) ;Data extracted
  180. ANDI A1, A0, 0x0003 ;Extract width bits from code type
  181. ORI A2, R0, 0x0003 ;Check for invalid width
  182. BEQ A1, A2, Type_DX_Invalid_Width
  183. ORI S4, R0, 0x0001 ;Execution state set to true
  184. SLL T8, S5, 0x10 ;
  185. SRA T8, T8, 0x10 ;T8 is signed halfword data
  186. SLL T9, S5, 0x18 ;
  187. SRA T9, T9, 0x18 ;T9 is signed byte data
  188. SLL S0, S6, 0x10 ;
  189. SRA S0, S0, 0x10 ;S0 is signed halfword data at address
  190. SLL S1, S6, 0x18 ;
  191. SRA S1, S1, 0x18 ;S1 is signed byte data at address
  192. ORI A2, R0, 0x0002 ;
  193. BEQ A1, A2, Type_DX_Word
  194. LW S6, 0x0000 (V1) ;
  195. ORI A2, R0, 0x0001 ;
  196. BNE A1, A2, Type_DX_Byte
  197. NOP
  198. ;-------------------------------;Halfword:
  199. OR S5, T8, R0 ;Data = halfword:data
  200. J 0x000B5000 + Type_DX_Halfword
  201. LH S6, 0x0000 (V1) ;Data at address = halfword:data at address
  202. Type_DX_Byte:
  203. OR S5, T9, R0 ;Data = byte:data
  204. LB S6, 0x0000 (V1) ;Data at address = byte:data at address
  205. Type_DX_Halfword:
  206. Type_DX_Word:
  207. ;-------------------------------;Data and data at address are appropriately formatted
  208. ANDI A1, A0, 0x000C ;Extract compare type bits from code type
  209. BEQZ A1, Must_Be_Equal
  210. ORI A2, R0, 0x0004 ;
  211. BEQ A1, A2, Must_Be_Different
  212. ORI A2, R0, 0x0008 ;
  213. BEQ A1, A2, Must_Be_Less
  214. NOP
  215. J 0x000B5000 + Must_Be_More
  216. NOP
  217. Must_Be_Equal:
  218. BNEL S5, S6, Execution_Status_Analysis
  219. OR S4, R0, R0 ;
  220. J 0x000B5000 + Execution_Status_Analysis
  221. NOP
  222. Must_Be_Different:
  223. BEQL S5, S6, Execution_Status_Analysis
  224. OR S4, R0, R0 ;
  225. J 0x000B5000 + Execution_Status_Analysis
  226. NOP
  227. Must_Be_Less:
  228. SUB S5, S5, S6 ;
  229. BGEZL S5, Execution_Status_Analysis
  230. OR S4, R0, R0 ;
  231. J 0x000B5000 + Execution_Status_Analysis
  232. NOP
  233. Must_Be_More:
  234. SUB S5, S5, S6 ;
  235. BLEZL S5, Execution_Status_Analysis
  236. OR S4, R0, R0 ;
  237. J 0x000B5000 + Execution_Status_Analysis
  238. ;-------------------------------;
  239. Type_DX_Invalid_Width:
  240. Mask_Compare_Codes:
  241. SRL S1, S5, 0x10 ;Mask extracted
  242. AND S5, S5, S1 ;Data masked
  243. LH S6, 0x0000 (V1) ;Data at address loaded as halfword
  244. AND S6, S6, S1 ;Data at address masked
  245. ANDI A1, A0, 0x000C ;Extract mask compare execution requirement type bits from code type
  246. BEQZ A1, Must_Be_Equal
  247. ORI A2, R0, 0x0004 ;
  248. BEQ A1, A2, Must_Be_Different
  249. NOP
  250. J 0x000B5000 + Interpret_Loop
  251. ADDIU V0, V0, 0x0008 ;Invalid code type
  252. ;-------------------------------;
  253. Execution_Status_Analysis:
  254. BNEZ S4, Interpret_Loop
  255. ADDIU V0, V0, 0x0008 ;Interpreter pointer updated
  256. J 0x000B5000 + Code_Skip_Init
  257. ORI S7, R0, 0x0001 ;Set "can increment terminator count" to true
  258. ;-------------------------------;These next few lines are for special codes which use terminators
  259. ;-------------------------------;but ignore potential conditional codes in between
  260. Skip_Until_Terminator:
  261. ORI S4, R0, 0x0000 ;Set execution status to false
  262. J 0x000B5000 + Code_Skip_Init
  263. ORI S7, R0, 0x0000 ;Set "can increment terminator count" to false
  264. ;-------------------------------;
  265. Code_Skip_Init:
  266. ADDIU A3, R0, -0x0001 ;Code list terminator
  267. ORI S0, R0, 0x000D ;Conditional type
  268. LUI S3, 0xE000 ;Terminator code value
  269. ORI S4, R0, 0x0001 ;Number of terminators to reach
  270. ORI T8, R0, 0x00DB ;First invalid conditional type
  271. ORI T9, R0, 0x00DF ;Second invalid conditional type
  272. ;-------------------------------;V0 points to next code
  273. False_Exec_Next_Code_Loop:
  274. LW S6, 0x0000 (V0) ;
  275. BEQ S6, A3, Exit
  276. NOP
  277. BEQZ S7, Only_Check_For_Terminator
  278. SRL S1, S6, 0x1C ;
  279. BNE S0, S1, Not_Conditional
  280. SRL S1, S6, 0x18 ;
  281. BEQ S1, T8, Not_Conditional
  282. NOP
  283. BEQ S1, T9, Not_Conditional
  284. NOP
  285. ;-------------------------------;Is conditional; increment S4
  286. ADDIU S4, S4, 0x0001 ;
  287. Only_Check_For_Terminator:
  288. Not_Conditional:
  289. BEQL S3, S6, Terminator_Encountered
  290. ADDIU S4, S4, -0x0001 ;Decrement number of terminators that must be encountered
  291. Terminator_Encountered:
  292. BEQZL S4, Interpret_Loop
  293. ADDIU V0, V0, 0x0008 ;
  294. J 0x000B5000 + False_Exec_Next_Code_Loop
  295. ADDIU V0, V0, 0x0008 ;
  296. ;-------------------------------;
  297. ; SPECIAL CODES ;
  298. ;-------------------------------;
  299. Type_CX:
  300. ADDIU V0, V0, 0x0008 ;Interpreter pointer updated
  301. LA S5, 0x800B5000 + Data
  302. SD V0, 0x0000 (S5) ;Back up interpreter pointer
  303. SD RA, 0x0008 (S5) ;Back up return address
  304. LUI RA, %hi(0x800B5000 + Type_CX_Return)
  305. JR V0 ;Jump to user's code
  306. ADDIU RA, RA, %lo(0x800B5000 + Type_CX_Return)
  307. Type_CX_Return:
  308. LA S5, 0x800B5000 + Data
  309. LD V0, 0x0000 (S5) ;Interpreter pointer restored
  310. J 0x000B5000 + Skip_Until_Terminator
  311. LD RA, 0x0008 (S5) ;Return address restored
  312.  
  313. ;;; End trainer ;;;
  314.  
  315. Exit:
  316. LD V0, 0x0028 (K0) ;
  317. LD V1, 0x0030 (K0) ;
  318. LD A0, 0x0038 (K0) ;
  319. LD A1, 0x0040 (K0) ;
  320. LD A2, 0x0048 (K0) ;
  321. LD A3, 0x0050 (K0) ;
  322. LD T3, 0x0070 (K0) ;
  323. LD T4, 0x0078 (K0) ;
  324. LD T5, 0x0080 (K0) ;
  325. LD T6, 0x0088 (K0) ;
  326. LD T7, 0x0090 (K0) ;
  327. LD S0, 0x0098 (K0) ;
  328. LD S1, 0x00A0 (K0) ;
  329. LD S2, 0x00A8 (K0) ;
  330. LD S3, 0x00B0 (K0) ;
  331. LD S4, 0x00B8 (K0) ;
  332. LD S5, 0x00C0 (K0) ;
  333. LD S6, 0x00C8 (K0) ;
  334. LD S7, 0x00D0 (K0) ;
  335. LD T8, 0x00D8 (K0) ;
  336. J 0x00075100
  337. LD T9, 0x00E0 (K0) ;
  338. Data:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement