Advertisement
luckytyphlosion

GS VC ACE Bootstrap code v0.3

Nov 30th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. IF 0
  2. ld a, [wJumptableIndex]
  3. push af
  4. callw _Bootstrap
  5. pop af
  6. ld [wJumptableIndex], a
  7. ret
  8. ENDC
  9.  
  10. _Bootstrap:
  11. ld hl, wBoxNames
  12. ld a, [hli]
  13. ld b, a
  14. add a
  15. jr c, .headerNotInMail
  16. push hl
  17. ld de, wc1d5
  18. push de
  19. callba $4, _ComposeMailMessage
  20. pop de
  21. ld a, [de]
  22. res 7, a
  23. ld [de], a
  24. ld b, a
  25. ld hl, wBoxNames
  26. call CopyName2
  27. pop hl
  28. .headerNotInMail
  29. callw DecodeCharPairPointer
  30. ld h, d
  31. ld l, e ; hl = bootstrap dest or execute src
  32. ld a, b
  33. cp "-"
  34. jr nz, .notDirectExecute
  35. jp hl
  36. .notDirectExecute
  37. bit 2, b
  38. jr z, .bootstrap
  39. and $3
  40. call OpenSRAM
  41. ld a, [hli]
  42. ld b, a
  43. ld a, [hli]
  44. ld c, a
  45. ld a, [hli]
  46. ld d, a
  47. ld a, [hli]
  48. ld e, a
  49. push de ; execute dest
  50. call CopyBytes
  51. call jp_de + 1 ; skip push de as de is already pushed
  52. jr .closeSRAM
  53. .bootstrap
  54. push bc ; save flags for later
  55. push de ; save dest for later
  56. bit 3, b
  57. ld de, wOverworldMap + $55 ; mail buffer dest
  58. ld hl, wBoxNames + 9
  59. callw nz, DecodeCharPairPointer
  60. push de ; save mail buffer dest for later
  61. .getBootstrapCharsLoop
  62. push de ; push mail buffer
  63. .retryMail
  64. callba $4, _ComposeMailMessage
  65. pop hl
  66. push de
  67. ld d, h
  68. ld e, l
  69. ld bc, 0
  70. ; hl & de = original mail buffer
  71. .checksumMsgLoop
  72. callw CharPairDecode
  73. ld [de], a
  74. inc de
  75. add c
  76. ld c, a
  77. jr nc, .noCarry
  78. inc b
  79. .noCarry
  80. ld a, [hl]
  81. cp "@"
  82. jr z, .doneChecksum
  83. cp "!"
  84. jr nz, .checksumMsgLoop
  85. .doneChecksum
  86. push af ; "!" flag
  87. push de ; end of compiled message
  88. push bc ; checksum
  89. ld hl, sp+$0
  90. ld d, h
  91. ld e, l
  92. coord hl, 5, 0
  93. ld c, PRINTNUM_LEADINGZEROS | PRINTNUM_LEFTALIGN | 2
  94. call PrintBCDNumber
  95. call YesNoBox
  96. pop bc
  97. pop de
  98. pop bc
  99. jr c, .retryMail
  100. pop de
  101. ld a, b
  102. cp "!"
  103. jr nz, .getBootstrapCharsLoop
  104. .bootstrapFinished
  105. pop hl ; mail buffer
  106. ld a, e
  107. sub l
  108. ld c, a
  109. ld a, d
  110. sbc h
  111. ld b, a ; get count
  112. dec bc
  113. dec bc
  114. pop de ; dest
  115. pop af ; save a byte here as b goes into a
  116. and $3 ; bank
  117. call OpenSRAM
  118. ; copy bootstrap dest
  119. ld a, [hli]
  120. ld [de], a
  121. inc de
  122. ld a, [hli]
  123. ld [de], a
  124. inc de
  125. ld a, b
  126. ld [de], a
  127. inc de
  128. ld a, c
  129. ld [de], a
  130. inc de
  131. call CopyBytes
  132. .closeSRAM
  133. jp CloseSRAM
  134.  
  135. DecodeCharPairPointer:
  136. callw CharPairDecode
  137. ld d, a
  138. callw CharPairDecode
  139. ld e, a
  140. ret
  141.  
  142. CharPairDecode:
  143. push bc
  144. callw ReadAndFilterChar
  145. add a
  146. add a
  147. add a
  148. add a
  149. ld b, a
  150. callw ReadAndFilterChar
  151. and $f
  152. or b
  153. pop bc
  154. ret
  155.  
  156. ReadAndFilterChar:
  157. ld a, [hl]
  158. cp $4e
  159. jr nz, .notNewline
  160. inc hl
  161. .notNewline
  162. ld a, [wBoxNames]
  163. bit 4, a
  164. ld a, [hli]
  165. ret z
  166. add a, 10
  167. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement