Advertisement
aaaaaa123456789

Prism BSP source

Dec 25th, 2016
279
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; NOTE: this is outdated! This was the version in use on 2016-12-25.
  2.  
  3. define zero, 0
  4. define source, 249
  5. define target, 250
  6. define message, 251
  7. define address, 251
  8. define banks, 252
  9. define length, 253
  10. define temp, 254
  11. define result, 255
  12.  
  13. define BANK_SIZE, 0x4000
  14. define BANKS, 128
  15. define ROM_SIZE, 0x200000
  16. define HASH_SIZE, 20
  17.  
  18. Main:
  19. call PrintInitialMessage
  20. call DetectBase
  21. call SelectTarget
  22. callnz #source, ConvertCrystalVersion
  23. call ApplyPrismPatch
  24. callnz #target, MakeDebugVersion
  25. length #length
  26. ifne #length, ROM_SIZE, .patching_error
  27. multiply #temp, #target, HASH_SIZE
  28. add #temp, PrismHashes
  29. checksha1 #result, #temp
  30. jumpnz #result, .patching_error
  31. print .completed
  32. exit 0
  33. .patching_error
  34. print .error
  35. exit 1
  36.  
  37. .completed
  38. string "Patching completed!"
  39. .error
  40. string "An error occurred while applying the patch. Please ensure that the base ROM and the patch are correct and try again."
  41.  
  42. PrintInitialMessage:
  43. bufstring .pokemon_prism_string
  44. add #address, VersionInfo, 2
  45. getbyteinc #temp, #address
  46. bufnumber #temp
  47. bufchar 0x2e ;0x2e is ASCII for '.'
  48. getbytedec #temp, #address
  49. bufnumber #temp
  50. decrement #address
  51. bufstring .comma_build_string
  52. ; build number is big endian
  53. getbytedec #temp, #address
  54. getbyte #result, #address
  55. multiply #result, 0x100
  56. add #1, #result, #temp
  57. set #2, 4
  58. call PrintWithLeadingZeros
  59. bufstring .parenthesis_asterisks_string
  60. printbuf
  61. return
  62.  
  63. .pokemon_prism_string
  64. string "*** Pokémon Prism patch (version "
  65. .comma_build_string
  66. string ", build "
  67. .parenthesis_asterisks_string
  68. string ") ***"
  69.  
  70. DetectBase:
  71. length #result
  72. ifne #result, ROM_SIZE, .error
  73. checksha1 #result, .crystal10
  74. set #source, 1
  75. set #message, .crystal10_message
  76. jumpz #result, .done
  77. checksha1 #result, .crystal11
  78. decrement #source
  79. set #message, .crystal11_message
  80. jumpz #result, .done
  81. .error
  82. print .error_message
  83. exit 1
  84. .done
  85. print #message
  86. return
  87.  
  88. .crystal10_message
  89. string "Detected base: Pokémon Crystal v1.0"
  90. .crystal11_message
  91. string "Detected base: Pokémon Crystal v1.1"
  92. .error_message
  93. string "Invalid base ROM. Please use a US version of Pokémon Crystal v1.0 or v1.1."
  94.  
  95. .crystal10
  96. hexdata f4cd194bdee0d04ca4eac29e09b8e4e9d818c133
  97. .crystal11
  98. hexdata f2f52230b536214ef7c9924f483392993e226cfb
  99.  
  100. SelectTarget:
  101. print .select_target
  102. menu #target, .target_menu
  103. retz #target
  104. print .confirm_debug_1
  105. print .confirm_debug_2
  106. menu #result, .confirm_menu
  107. retz #result
  108. jump SelectTarget
  109.  
  110. .select_target
  111. string "Select the ROM you want to build:"
  112.  
  113. .target_menu
  114. dw .release_target
  115. dw .debug_target
  116. dw -1
  117. .release_target
  118. string "Release version"
  119. .debug_target
  120. string "Debug version"
  121.  
  122. .confirm_debug_1
  123. string "The debug version contains no additional game features, other than debug options intended to aid the development of the game."
  124. .confirm_debug_2
  125. string "Are you sure you want to build the debug version?"
  126.  
  127. .confirm_menu
  128. dw .yes
  129. dw .no
  130. dw -1
  131. .yes
  132. string "Yes"
  133. .no
  134. string "No"
  135.  
  136. ConvertCrystalVersion:
  137. set #address, CrystalPatch
  138. jump ApplyIPSPatch
  139.  
  140. MakeDebugVersion:
  141. set #address, DebugPatch
  142. ; fallthrough
  143.  
  144. ApplyIPSPatch:
  145. seek #zero
  146. ipspatch #result, #address
  147. return
  148.  
  149. ApplyPrismPatch:
  150. seek #zero
  151. set #address, PrismPatch
  152. set #banks, BANKS
  153. .loop
  154. gethalfwordinc #length, #address
  155. xordata #address, #length
  156. add #address, #length
  157. subtract #length, BANK_SIZE, #length
  158. fillbyte #length, 0xff
  159. decrement #banks
  160. jumpnz #banks, .loop
  161. truncatepos
  162. return
  163.  
  164. PrintWithLeadingZeros:
  165. ; prints number #1 in #2 digits, with leading zeros
  166. push -0x30 ;so it will become 0 when 0x30 is added to it
  167. increment #2
  168. jump .handle_loop
  169. .push_loop
  170. remainder #temp, #1, 10
  171. divide #1, 10
  172. push #temp
  173. .handle_loop
  174. decrement #2
  175. jumpnz #2, .push_loop
  176. .pop_loop
  177. pop #temp
  178. add #temp, 0x30 ;0x30 is ASCII for '0'
  179. retz #temp
  180. bufchar #temp
  181. jump .pop_loop
  182.  
  183. CrystalPatch: incbin "crystal.ips"
  184. DebugPatch: incbin "debug.ips"
  185. PrismPatch: incbin "xorpatch.bin"
  186.  
  187. VersionInfo: include "version.txt"
  188.  
  189. PrismHashes: include "hashes.txt"
Advertisement
RAW Paste Data Copied
Advertisement