main.asm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. ; This program is free software: you can redistribute it and/or modify
  2. ; it under the terms of the GNU General Public License as published by
  3. ; the Free Software Foundation, either version 3 of the License, or
  4. ; (at your option) any later version.
  5. ;
  6. ; This program is distributed in the hope that it will be useful,
  7. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. ; GNU General Public License for more details.
  10. ;
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. INCLUDE "gbhw.inc" ; import file definitions
  14. ;Variables
  15. _NUMBER EQU _RAM
  16. ; Constants
  17. _POS_CRONOM EQU _SCRN0+32*4+6 ; screen position
  18. ; VBlank interruption
  19. SECTION "Vblank",HOME[$0040]
  20. call DrawingNumbers
  21. reti
  22. ; The program begins here:
  23. SECTION "start",HOME[$0100]
  24. nop
  25. jp start
  26. ROM_HEADER ROM_NOMBC, ROM_SIZE_32KBYTE, RAM_SIZE_0KBYTE
  27. start:
  28. nop
  29. di ; disables interrupts
  30. ld sp, $ffff ; We aim pile atop the ram initialization:
  31. init:
  32. ;set Variables
  33. ld a, 0
  34. ld [_NUMBER], a
  35. ld a, %11100100 ; Pallet
  36. ld [rBGP], a ; write background pallet
  37. ld [rOBP0], a ; write sprite pallet
  38. ld a, 0
  39. ld [rSCX], a
  40. ld [rSCY], a
  41. call Shutdown_LCD ; turn off LCD
  42. ; Load Tiles into memory
  43. ld hl, Tiles
  44. ld de, _VRAM
  45. ld bc, FinTiles-Tiles ; number of bytes to copy
  46. call CopyMemory
  47. ;clean map
  48. ld de, _SCRN0 ; map 0
  49. ld bc, 32*32
  50. ld l, 11 ; empty tile
  51. call FillMemory
  52. ; sprite attribute memory
  53. ld de, _OAMRAM ; sprite attribute memory
  54. ld bc, 40*4 ; 40 sprites x 4 bytes each
  55. ld l, 0 ; we will start fresh, so the sprites
  56. call FillMemory ; Unused remain off-screen
  57. call DrawingNumbers ; Draw stopwatch
  58. ; setup and activate display
  59. ld a, LCDCF_ON|LCDCF_BG8000|LCDCF_BG9800|LCDCF_BGON|LCDCF_OBJ8
  60. ld [rLCDC], a
  61. ; main loop
  62. main:
  63. ld bc, 15000
  64. call delay
  65. call WaitVBlank
  66. call DrawingNumbers
  67. call IncrementNumber
  68. cp 9
  69. jr z, ResetNumber
  70. jr main
  71. IncrementNumber:
  72. ld a, [_NUMBER]
  73. inc a
  74. ld [_NUMBER], a
  75. ret
  76. ResetNumber:
  77. ld a, 0
  78. ret
  79. DrawingNumbers:
  80. ld a, [_NUMBER]
  81. ld [_POS_CRONOM], a
  82. ret
  83. ; LCD shutdown routine
  84. Shutdown_LCD:
  85. ld a,[rLCDC]
  86. rlca ;It sets the high bit of LCDC in the carry flag
  87. ret nc ; Display is already off, again.
  88. ; We VBlank hope to, because we can not turn off the screen
  89. ; some other time
  90. call WaitVBlank
  91. ; we are in VBlank, we turn off the LCD
  92. ld a,[rLCDC] ; in A, the contents of the LCDC
  93. res 7,a ; we zero bit 7 (on the LCD)
  94. ld [rLCDC],a ; We wrote in the LCDC register content A
  95. ret ; return
  96. WaitVBlank:
  97. ld a, [rLY]
  98. cp 145
  99. jr nz, WaitVBlank
  100. ret
  101. delay:
  102. .delay:
  103. dec bc ; decrement
  104. ld a, b ; see if zero
  105. or c
  106. jr z, .fin_delay
  107. nop
  108. jr .delay
  109. .fin_delay:
  110. ret
  111. ; memory copy routine
  112. ; copy a number of bytes from one direction to another
  113. ; expects the parameters:
  114. ; hl - copying data address
  115. ; of - destination address
  116. ; bc - amount of data to be copied
  117. ; destroys the contents of A
  118. CopyMemory:
  119. ld a, [hl] ; To load the data in A
  120. ld [de], a ; copy the data to the destination
  121. dec bc ; least one copy
  122. ; We check if bc is zero
  123. ld a, c
  124. or b
  125. ret z ; If zero, we return
  126. ; if not, we still
  127. inc hl
  128. inc de
  129. jr CopyMemory
  130. FillMemory:
  131. ld a, l
  132. ld [de], a ; puts the data in the destination
  133. dec bc ; least one fill
  134. ld a, c
  135. or b ; We check if bc is zero
  136. ret z ; If zero return
  137. inc de ; if not, we still
  138. jr FillMemory
  139. Tiles:
  140. ; 0
  141. DW `00000000
  142. DW `00333300
  143. DW `03000330
  144. DW `03003030
  145. DW `03030030
  146. DW `03300030
  147. DW `00333300
  148. DW `00000000
  149. ; 1
  150. DW `00000000
  151. DW `00003000
  152. DW `00033000
  153. DW `00003000
  154. DW `00003000
  155. DW `00003000
  156. DW `00333300
  157. DW `00000000
  158. ; 2
  159. DW `00000000
  160. DW `00333300
  161. DW `03000030
  162. DW `00003300
  163. DW `00030000
  164. DW `00300000
  165. DW `03333330
  166. DW `00000000
  167. ; 3
  168. DW `00000000
  169. DW `00333300
  170. DW `03000030
  171. DW `00003300
  172. DW `00000030
  173. DW `03000030
  174. DW `00333300
  175. DW `00000000
  176. ; 4
  177. DW `00000000
  178. DW `00000300
  179. DW `00003300
  180. DW `00030300
  181. DW `00333300
  182. DW `00000300
  183. DW `00000300
  184. DW `00000000
  185. ; 5
  186. DW `00000000
  187. DW `03333330
  188. DW `03000000
  189. DW `00333300
  190. DW `00000030
  191. DW `03000030
  192. DW `00333300
  193. DW `00000000
  194. ; 6
  195. DW `00000000
  196. DW `00003000
  197. DW `00030000
  198. DW `00300000
  199. DW `03333300
  200. DW `03000030
  201. DW `00333300
  202. DW `00000000
  203. ; 7
  204. DW `00000000
  205. DW `03333330
  206. DW `00000300
  207. DW `00003000
  208. DW `00030000
  209. DW `00300000
  210. DW `00300000
  211. DW `00000000
  212. ; 8
  213. DW `00000000
  214. DW `00333300
  215. DW `03000030
  216. DW `00333300
  217. DW `03000030
  218. DW `03000030
  219. DW `00333300
  220. DW `00000000
  221. ; 9
  222. DW `00000000
  223. DW `00333300
  224. DW `03000030
  225. DW `03000030
  226. DW `00333300
  227. DW `00003000
  228. DW `00330000
  229. DW `03000000
  230. ; :
  231. DW `00000000
  232. DW `00033000
  233. DW `00033000
  234. DW `00000000
  235. DW `00033000
  236. DW `00033000
  237. DW `00000000
  238. DW `00000000
  239. ; empty tile
  240. DW `00000000
  241. DW `00000000
  242. DW `00000000
  243. DW `00000000
  244. DW `00000000
  245. DW `00000000
  246. DW `00000000
  247. DW `00000000
  248. FinTiles: