Advertisement
aaaaaa123456789

GB/GBC SP + e8 test ROM

Aug 7th, 2020
49
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rLCDC EQU $ff40
  2. rSTAT EQU $ff41
  3. rSCX EQU $ff42
  4. rSCY EQU $ff43
  5. rVBK EQU $ff4f
  6. rBCPS EQU $ff68
  7. rBCPD EQU $ff69
  8. rOCPS EQU $ff6a
  9. rOCPD EQU $ff6b
  10. rIE EQU $ffff
  11.  
  12. SECTION "ROM", ROM0[0]
  13.  
  14. Main:
  15. call ScreenOff
  16. MainContinue:
  17. xor a
  18. ldh [rSCX], a
  19. ldh [rSCY], a
  20. ldh [rIE], a
  21. dec a
  22. ld hl, $9c00
  23. .clear_tilemap_loop
  24. ld [hli], a
  25. bit 5, h
  26. jr z, .clear_tilemap_loop
  27. ld hl, $8ff0
  28. xor a
  29. .clear_tile_loop
  30. ld [hli], a
  31. bit 4, h
  32. jr z, .clear_tile_loop
  33. ld de, Font
  34. ld c, 160
  35. .load_font_loop
  36. ld a, [de]
  37. inc de
  38. ld [hli], a
  39. ld [hli], a
  40. dec c
  41. jr nz, .load_font_loop
  42. call Calculate
  43. ld a, $89
  44. ldh [rLCDC], a
  45. ei
  46. .halts
  47. db $76, $76, $76 ;triple halt
  48. jr .halts
  49.  
  50. Font:
  51. db $7C, $C6, $CE, $DE, $F6, $E6, $7C, $00 ;0
  52. db $30, $70, $30, $30, $30, $30, $FC, $00 ;1
  53. db $78, $CC, $0C, $38, $60, $CC, $FC, $00 ;2
  54. db $78, $CC, $0C, $38, $0C, $CC, $78, $00 ;3
  55. db $1C, $3C, $6C, $CC, $FE, $0C, $1E, $00 ;4
  56. db $FC, $C0, $F8, $0C, $0C, $CC, $78, $00 ;5
  57. db $38, $60, $C0, $F8, $CC, $CC, $78, $00 ;6
  58. db $FC, $CC, $0C, $18, $30, $30, $30, $00 ;7
  59. db $78, $CC, $CC, $78, $CC, $CC, $78, $00 ;8
  60. db $78, $CC, $CC, $7C, $0C, $18, $70, $00 ;9
  61. db $30, $78, $CC, $CC, $FC, $CC, $CC, $00 ;A
  62. db $FC, $66, $66, $7C, $66, $66, $FC, $00 ;B
  63. db $3C, $66, $C0, $C0, $C0, $66, $3C, $00 ;C
  64. db $F8, $6C, $66, $66, $66, $6C, $F8, $00 ;D
  65. db $FE, $62, $68, $78, $68, $62, $FE, $00 ;E
  66. db $FE, $62, $68, $78, $68, $60, $F0, $00 ;F
  67. db $FE, $C6, $8C, $18, $32, $66, $FE, $00 ;Z
  68. db $00, $00, $FC, $00, $00, $FC, $00, $00 ;=
  69. db $00, $00, $00, $FC, $00, $00, $00, $00 ;-
  70. db $00, $30, $30, $FC, $30, $30, $00, $00 ;+
  71.  
  72. ScreenOff:
  73. ldh a, [rSTAT]
  74. and 3
  75. cp 1
  76. jr nz, ScreenOff
  77. di
  78. xor a
  79. ldh [rLCDC], a
  80. ret
  81.  
  82. LoadColor:
  83. ld a, l
  84. ldh [rBCPD], a
  85. ldh [rOCPD], a
  86. ld a, h
  87. ldh [rBCPD], a
  88. ldh [rOCPD], a
  89. ret
  90.  
  91. PrintByte:
  92. ; in: a: byte, de: destination
  93. push af
  94. swap a
  95. and $f
  96. ld [de], a
  97. inc de
  98. pop af
  99. and $f
  100. ld [de], a
  101. inc de
  102. ret
  103.  
  104. rept $100 - @
  105. db $ff
  106. endr
  107.  
  108. ; entry point
  109. dec a
  110. jr nz, LoadPalettes
  111. rst 0
  112.  
  113. rept $134 - @
  114. nop
  115. endr
  116.  
  117. ; header data - encoded here so it's consistent across builds
  118. db "SP TEST ROM" ;title
  119. db "TEST" ;manufacturer
  120. db $80 ;CGB + DMG
  121. db "XX" ;new licensee
  122. db 0 ;no SGB
  123. db 0 ;cart type: ROM only
  124. db 0 ;32K ROM
  125. db 0 ;no RAM
  126. db 1 ;destination: not Japan
  127. db $33 ;old licensee (must be $33)
  128. db 1 ;ROM version
  129. db 0 ;checksum (must fix)
  130. dw 0 ;global checksum (must fix)
  131.  
  132. LoadPalettes:
  133. call ScreenOff
  134. ld a, 1
  135. ldh [rVBK], a
  136. ld hl, $9c00
  137. xor a
  138. .loop
  139. ld [hli], a
  140. bit 5, h
  141. jr z, .loop
  142. ldh [rVBK], a
  143. ld a, $80
  144. ldh [rBCPS], a
  145. ldh [rOCPS], a
  146. ld hl, $7fff
  147. call LoadColor
  148. ld hl, $56b5
  149. call LoadColor
  150. ld hl, $294a
  151. call LoadColor
  152. ld hl, 0
  153. call LoadColor
  154. jp MainContinue
  155.  
  156. GeneratedCode:
  157. ; in: hl: target sp, a: target addend
  158. ; out: hl: result, a: flags
  159. cp a ;reset flags to a known state
  160. ldh [$ff80 + (.add_instruction - GeneratedCode) + 1], a
  161. ld [$ffe0], sp
  162. ld sp, hl
  163. .add_instruction
  164. add sp, 0
  165. ld [$ffe2], sp
  166. ld sp, $ffe6
  167. push af
  168. ld hl, $ffe0
  169. ld a, [hli]
  170. ld h, [hl]
  171. ld l, a
  172. ld sp, hl
  173. ld hl, $ffe2
  174. ld a, [hli]
  175. ld h, [hl]
  176. ld l, a
  177. ldh a, [$ffe4]
  178. ret
  179. .end
  180.  
  181. Calculate:
  182. ld bc, ((GeneratedCode.end - GeneratedCode) << 8) + $80
  183. ld hl, GeneratedCode
  184. .copy_loop
  185. ld a, [hli]
  186. ldh [c], a
  187. inc c
  188. dec b
  189. jr nz, .copy_loop
  190. ld bc, Addends
  191. ld de, $9c00
  192. .loop
  193. ld a, [bc]
  194. inc bc
  195. ld h, a
  196. call PrintByte
  197. ld a, [bc]
  198. inc bc
  199. ld l, a
  200. call PrintByte
  201. inc de
  202. ld a, [bc]
  203. inc bc
  204. push bc
  205. ld c, a
  206. add a, a
  207. sbc a
  208. add a, $13
  209. ld [de], a
  210. inc de
  211. inc de
  212. ld a, c
  213. bit 7, c
  214. jr z, .not_negative
  215. cpl
  216. inc a
  217. .not_negative
  218. call PrintByte
  219. inc de
  220. ld a, $11
  221. ld [de], a
  222. inc de
  223. inc de
  224. ld a, c
  225. call $ff80
  226. ld c, a
  227. ld a, h
  228. call PrintByte
  229. ld a, l
  230. call PrintByte
  231. inc de
  232. inc de
  233. ld a, c
  234. add a, a
  235. sbc a
  236. add a, a
  237. add a, $12
  238. ld [de], a
  239. inc de
  240. swap c
  241. srl c
  242. sbc a
  243. and $c - $12
  244. add a, $12
  245. ld [de], a
  246. set 2, e
  247. set 3, e
  248. inc de
  249. pop bc
  250. ld a, c
  251. cp LOW(Addends.end)
  252. jr nz, .loop
  253. ret
  254.  
  255. addends: MACRO
  256. db HIGH(\1)
  257. db LOW(\1)
  258. db \2
  259. ENDM
  260.  
  261. Addends:
  262. addends $0000, +$00
  263. addends $ffff, +$01
  264. addends $ff80, -$80
  265. addends $0080, -$80
  266. addends $0002, -$02
  267. addends $ffcf, +$30
  268. addends $ffbd, +$53
  269. addends $ff96, +$76
  270. addends $000e, -$0e
  271. addends $000e, +$0e
  272. addends $00ff, +$01
  273. addends $0042, +$42
  274. addends $fea2, +$5e
  275. .end
  276.  
Advertisement
RAW Paste Data Copied
Advertisement