Advertisement
aaaaaa123456789

GB frame counter ROM

Feb 15th, 2020
148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. BGTiles EQU $8000
  2. BGTileMap EQU $9800
  3. BGTileMapDigits EQU $98e0
  4.  
  5. hDigitsStaging EQU $ff80
  6.  
  7. rNR52 EQU $ff26
  8. rLCDC EQU $ff40
  9. rSTAT EQU $ff41
  10. rSCX EQU $ff42
  11. rSCY EQU $ff43
  12. rIE EQU $ffff
  13.  
  14. IncrementCounter EQU $00
  15. AdjustDEbyA EQU $18
  16. CopyLineOfTiles EQU $20
  17. DelayFrame EQU $28
  18. ClearStaging EQU $30
  19.  
  20. SECTION "ROM", ROM0[0]
  21.  
  22. _IncrementCounter:
  23. ; as a tribute to the original, use daa here
  24. ; (instead of dividing by 10 to display)
  25. ld a, e
  26. add a, 1
  27. daa
  28. ld e, a
  29. ret nc
  30. ld a, d
  31. add a, 1
  32. daa
  33. ld d, a
  34. ret nc
  35. ld a, c
  36. add a, 1
  37. daa
  38. ld c, a
  39. ret nc
  40. ld a, b
  41. add a, 1
  42. daa
  43. ld b, a
  44. ret
  45.  
  46. _AdjustDEbyA:
  47. add a, a
  48. add a, a
  49. add a, a
  50. add a, e
  51. ld e, a
  52. ret nc
  53. inc d
  54. ret
  55.  
  56. _CopyLineOfTiles:
  57. ld a, [de]
  58. inc de
  59. ld [hli], a
  60. ld a, [de]
  61. inc de
  62. ld [hli], a
  63. add hl, bc
  64. ret
  65.  
  66. _DelayFrame:
  67. and a
  68. .loop
  69. halt
  70. jr nc, .loop
  71. ret
  72.  
  73. ds 2 ; padding up to $0030
  74.  
  75. _ClearStaging:
  76. ld bc, 80 * $100 + LOW(hDigitsStaging) ; b = 80, c = LOW(hDigitsStaging)
  77. xor a
  78. .loop
  79. ld [c], a
  80. inc c
  81. dec b
  82. jr nz, .loop
  83. ret
  84.  
  85. ds 6 ; padding up to $0040
  86.  
  87. VBlank:
  88. push bc
  89. push de
  90. ld bc, 10 * $100 + LOW(hDigitsStaging) ; b = 10, c = LOW(hDigitsStaging)
  91. ld hl, BGTileMapDigits
  92. ld de, 12
  93. ; copy 4 rows of 20 tiles
  94. ; the lazy way
  95. rept 3
  96. .loop\@
  97. ld a, [c]
  98. inc c
  99. ld [hli], a
  100. ld a, [c]
  101. inc c
  102. ld [hli], a
  103. dec b
  104. jr nz, .loop\@
  105. add hl, de
  106. ld b, 10
  107. endr
  108. .final_loop
  109. ld a, [c]
  110. inc c
  111. ld [hli], a
  112. ld a, [c]
  113. inc c
  114. ld [hli], a
  115. dec b
  116. jr nz, .final_loop
  117. ; done, pop everything and set carry
  118. pop de
  119. pop bc
  120. scf
  121. reti
  122.  
  123. DisplayDigit:
  124. rst AdjustDEbyA
  125. push bc
  126. ld bc, 18
  127. rst CopyLineOfTiles
  128. rst CopyLineOfTiles
  129. rst CopyLineOfTiles
  130. rst CopyLineOfTiles
  131. pop bc
  132. ret
  133.  
  134. DisplayByte:
  135. push de
  136. push hl
  137. push af
  138. swap a
  139. and $f
  140. ld de, LeftDigits
  141. call DisplayDigit
  142. pop af
  143. and $f
  144. ld de, RightDigits
  145. pop hl
  146. inc hl
  147. inc hl
  148. inc hl
  149. call DisplayDigit
  150. pop de
  151. ret
  152.  
  153. Main:
  154. ld a, $51
  155. ldh [rLCDC], a
  156. ld de, Tiles
  157. ld c, 31
  158. ld hl, BGTiles
  159. .tile_copy_loop
  160. ld b, 8
  161. .inner_copy_loop
  162. ld a, [de]
  163. inc de
  164. ld [hli], a
  165. ld [hli], a
  166. dec b
  167. jr nz, .inner_copy_loop
  168. dec c
  169. jr nz, .tile_copy_loop
  170. xor a
  171. ldh [rSCX], a
  172. ldh [rSCY], a
  173. ldh [rNR52], a
  174. ld hl, BGTileMap
  175. ld de, 12
  176. ld b, 18
  177. .tilemap_fill_loop
  178. ld c, 20
  179. .inner_fill_loop
  180. ld [hli], a
  181. dec c
  182. jr nz, .inner_fill_loop
  183. add hl, de
  184. dec b
  185. jr nz, .tilemap_fill_loop
  186. ; bc = 0 here
  187. ld d, a
  188. inc a
  189. ld e, a
  190. ldh [rIE], a
  191. ld hl, rLCDC
  192. set 7, [hl]
  193. ei
  194. rst DelayFrame
  195. .main_loop
  196. ld a, b
  197. ld hl, hDigitsStaging
  198. call DisplayByte
  199. ld a, c
  200. ld hl, hDigitsStaging + 5
  201. call DisplayByte
  202. ld a, d
  203. ld hl, hDigitsStaging + 10
  204. call DisplayByte
  205. ld a, e
  206. ld hl, hDigitsStaging + 15
  207. call DisplayByte
  208. rst DelayFrame
  209. rst IncrementCounter
  210. jr .main_loop
  211.  
  212. ; $0100 is here
  213.  
  214. Init:
  215. di
  216. rst ClearStaging
  217. jr Main
  218.  
  219. rept $4c
  220. db 0
  221. endr
  222.  
  223. Tiles:
  224. db $00, $00, $00, $00, $00, $00, $00, $00 ;00
  225. db $00, $00, $00, $00, $00, $00, $0f, $0f ;01
  226. db $00, $00, $00, $00, $00, $00, $0c, $0c ;02
  227. db $00, $00, $00, $00, $00, $00, $ff, $ff ;03
  228. db $0c, $0c, $0c, $0c, $0c, $0c, $0c, $0f ;04
  229. db $0c, $0c, $0c, $0c, $0c, $0c, $0c, $0c ;05
  230. db $00, $00, $00, $00, $00, $00, $00, $0f ;06
  231. db $0f, $0c, $0c, $0c, $0c, $0c, $0c, $0c ;07
  232. db $0f, $00, $00, $00, $00, $00, $00, $00 ;08
  233. db $0f, $0f, $00, $00, $00, $00, $00, $00 ;09
  234. db $03, $03, $03, $03, $03, $03, $03, $ff ;10
  235. db $00, $00, $00, $00, $00, $00, $00, $ff ;11
  236. db $03, $03, $03, $03, $03, $03, $03, $03 ;12
  237. db $03, $03, $00, $00, $00, $00, $00, $00 ;13
  238. db $ff, $ff, $00, $00, $00, $00, $00, $00 ;14
  239. db $ff, $03, $03, $03, $03, $03, $03, $03 ;15
  240. db $ff, $00, $00, $00, $00, $00, $00, $00 ;16
  241. db $00, $00, $00, $00, $00, $00, $c0, $c0 ;17
  242. db $c0, $c0, $c0, $c0, $c0, $c0, $c0, $ff ;18
  243. db $c0, $c0, $c0, $c0, $c0, $c0, $c0, $c0 ;19
  244. db $00, $00, $00, $00, $00, $00, $f0, $f0 ;20
  245. db $00, $00, $00, $00, $00, $00, $30, $30 ;21
  246. db $30, $30, $30, $30, $30, $30, $30, $f0 ;22
  247. db $30, $30, $30, $30, $30, $30, $30, $30 ;23
  248. db $00, $00, $00, $00, $00, $00, $00, $f0 ;24
  249. db $f0, $30, $30, $30, $30, $30, $30, $30 ;25
  250. db $f0, $00, $00, $00, $00, $00, $00, $00 ;26
  251. db $f0, $f0, $00, $00, $00, $00, $00, $00 ;27
  252. db $30, $30, $00, $00, $00, $00, $00, $00 ;28
  253. db $00, $00, $00, $00, $00, $00, $03, $03 ;29
  254. db $ff, $c0, $c0, $c0, $c0, $c0, $c0, $c0 ;30
  255.  
  256. LeftDigits:
  257. db 1, 3, 5, 12, 5, 12, 9, 14 ;0
  258. db 0, 29, 0, 12, 0, 12, 0, 13 ;1
  259. db 1, 3, 6, 10, 7, 16, 9, 14 ;2
  260. db 1, 3, 6, 10, 8, 15, 9, 14 ;3
  261. db 2, 29, 4, 10, 8, 15, 0, 13 ;4
  262. db 1, 3, 4, 11, 8, 15, 9, 14 ;5
  263. db 1, 3, 4, 11, 7, 15, 9, 14 ;6
  264. db 1, 3, 0, 12, 0, 12, 0, 13 ;7
  265. db 1, 3, 4, 10, 7, 15, 9, 14 ;8
  266. db 1, 3, 4, 10, 8, 15, 9, 14 ;9
  267.  
  268. RightDigits:
  269. db 3, 20, 19, 23, 19, 23, 14, 27 ;0
  270. db 0, 21, 0, 23, 0, 23, 0, 28 ;1
  271. db 3, 20, 11, 22, 30, 26, 14, 27 ;2
  272. db 3, 20, 11, 22, 16, 25, 14, 27 ;3
  273. db 17, 21, 18, 22, 16, 25, 0, 28 ;4
  274. db 3, 20, 18, 24, 16, 25, 14, 27 ;5
  275. db 3, 20, 18, 24, 30, 25, 14, 27 ;6
  276. db 3, 20, 0, 23, 0, 23, 0, 28 ;7
  277. db 3, 20, 18, 22, 30, 25, 14, 27 ;8
  278. db 3, 20, 18, 22, 16, 25, 14, 27 ;9
Advertisement
RAW Paste Data Copied
Advertisement