Advertisement
luckytyphlosion

GS VC ACE Bootstrap code beta.

Nov 29th, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. INCLUDE "charmap.asm"
  2.  
  3. ; bit 0-1: sram bank
  4. ; bit 2: bootstrap or execute
  5. ; bit 3: specify bootstrap mail buffer scratch dest
  6. ; bit 4: base16 or hex encoding. base16 assumes little endian, hex encoding assumes big endian
  7. ; if upper 7 bits are %1110001 (- or /), execute directly. bit 4 corresponds to jump encoding
  8.  
  9. wBoxNames EQU $d8bf
  10. OpenSRAM EQU $30e1
  11. CloseSRAM EQU $30f1
  12. jp_de EQU $30fd
  13. CopyBytes EQU $311a
  14. wOverworldMap EQU $c700
  15. _ComposeMailMessage EQU $6242
  16. wJumptableIndex EQU $ce63
  17.  
  18. SECTION "Bootstrap", ROM0
  19.  
  20. callw: MACRO
  21. if _NARG == 1
  22. call \1 + $d6f3
  23. else
  24. call \1, \2 + $d6f3
  25. endc
  26. ENDM
  27.  
  28. Bootstrap::
  29. ld a, [wJumptableIndex]
  30. push af
  31. callw _Bootstrap
  32. pop af
  33. ld [wJumptableIndex], a
  34. ret
  35.  
  36. _Bootstrap:
  37. ld hl, wBoxNames
  38. ld a, [hli]
  39. ld b, a
  40. callw DecodeCharPairPointer
  41. ld h, d
  42. ld l, e ; hl = bootstrap dest or execute src
  43. ld a, b
  44. and "-"
  45. cp "-"
  46. jr nz, .notDirectExecute
  47. jp hl
  48. .notDirectExecute
  49. bit 2, b
  50. jr z, .bootstrap
  51. ld a, b
  52. and $3
  53. call OpenSRAM
  54. ld a, [hli]
  55. ld b, a
  56. ld a, [hli]
  57. ld c, a
  58. ld a, [hli]
  59. ld e, a
  60. ld a, [hli]
  61. ld d, a
  62. push de ; execute dest
  63. call CopyBytes
  64. call jp_de + 1 ; skip push de as de is already pushed
  65. jr .closeSRAM
  66. .bootstrap
  67. push bc ; save flags for later
  68. push de ; save dest for later
  69. bit 3, b
  70. ld de, wOverworldMap + $55 ; mail buffer dest
  71. ld hl, wBoxNames + 9
  72. callw nz, DecodeCharPairPointer
  73. push de ; save mail buffer dest for later
  74. .getBootstrapCharsLoop
  75. ld hl, _ComposeMailMessage
  76. ld a, $4
  77. rst $08
  78. dec de
  79. ld a, [de]
  80. inc de
  81. cp "!"
  82. jr nz, .getBootstrapCharsLoop
  83. pop hl ; mail buffer
  84. pop de ; dest
  85. pop af ; save a byte here as b goes into a
  86. and $3 ; bank
  87. call OpenSRAM
  88. callw CharPairDecode
  89. ld [de], a
  90. inc de
  91. callw CharPairDecode
  92. ld [de], a
  93. inc de
  94. push de ; save count dest for later
  95. inc de
  96. inc de
  97. ld bc, 0
  98. .bootstrapCopyLoop
  99. callw CharPairDecode
  100. ld [de], a
  101. inc de
  102. inc bc
  103. ld a, [hl]
  104. cp "!"
  105. jr nz, .bootstrapCopyLoop
  106. pop hl
  107. ld a, b
  108. ld [hli], a
  109. ld [hl], c
  110. .closeSRAM
  111. jp CloseSRAM
  112.  
  113. DecodeCharPairPointer:
  114. callw CharPairDecode
  115. ld d, a
  116. callw CharPairDecode
  117. ld e, a
  118. ret
  119.  
  120. CharPairDecode:
  121. push bc
  122. ld a, [wBoxNames]
  123. bit 4, a
  124. jr nz, .HexDecode
  125. ; fallthrough
  126.  
  127. .Base16Decode:
  128. callw ReadAndFilterChar
  129. add a
  130. add a
  131. add a
  132. add a
  133. ld b, a
  134. callw ReadAndFilterChar
  135. and $f
  136. jr .orPopAndReturn
  137.  
  138. .HexDecode:
  139. callw HexDecodeChar
  140. add a
  141. add a
  142. add a
  143. add a
  144. ld b, a
  145. callw HexDecodeChar
  146. .orPopAndReturn
  147. or b
  148. pop bc
  149. ret
  150.  
  151. HexDecodeChar:
  152. ; saves 1 byte
  153. callw ReadAndFilterChar
  154. sub "0"
  155. ret nc
  156. add ("0" - "A" + $0a)
  157. ret
  158.  
  159. ReadAndFilterChar:
  160. ld a, [hli]
  161. cp $4e
  162. ret nz
  163. ld a, [hli]
  164. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement