Advertisement
Leap_

Untitled

Aug 11th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. ;get constants
  2. INCLUDE "constants.asm"
  3. ; unused vectors
  4.  
  5. SECTION "rst 00", ROM0 [$00]
  6. rst $38
  7. SECTION "rst 08", ROM0 [$08]
  8. rst $38
  9. SECTION "rst 10", ROM0 [$10]
  10. rst $38
  11. SECTION "rst 18", ROM0 [$18]
  12. rst $38
  13. SECTION "rst 28", ROM0 [$20]
  14. rst $38
  15. SECTION "rst 30", ROM0 [$30]
  16. rst $38
  17. SECTION "rst 38", ROM0 [$38]
  18. rst $38
  19.  
  20. ; hardware interrupts
  21.  
  22. SECTION "vblank", ROM0 [$40]
  23. jp VBlank
  24. SECTION "hblank", ROM0 [$48]
  25. rst $38
  26. SECTION "timer", ROM0 [$50]
  27. reti
  28. SECTION "serial", ROM0 [$58]
  29. reti
  30. SECTION "joypad", ROM0 [$60]
  31. reti
  32.  
  33.  
  34. SECTION "Entry", ROM0 [$100]
  35. nop ;go through one cpu cycle
  36. jp Start ;and jump to start
  37.  
  38. SECTION "Header", ROM0 [$104]
  39.  
  40.  
  41. ds $150 - $104 ;rgbfix fixes the header for us.
  42.  
  43. SECTION "Main", ROM0 [$150]
  44. Start::
  45. di
  46.  
  47. ; palettes
  48. ld a, %11100100
  49. ld [rBGP], a
  50. ld a, %11010000
  51. ld [rOBP0], a
  52.  
  53. xor a
  54. ld [rSCX], a ;scrlx
  55. ld [rSCY], a ;scrly
  56.  
  57. ld a, %11000111 ; lcdc status
  58. ld [rLCDC], a
  59.  
  60. ei
  61.  
  62.  
  63.  
  64. ; set up stack pointer
  65. ld sp, $dffe
  66.  
  67.  
  68. call WriteDMACodeToHRAM ;dma must be done in HRAM
  69.  
  70. ; vblank copy offsets
  71. lda [H_FIRSTVBLANK], 1
  72.  
  73.  
  74. ;title screen
  75. ld hl, Title
  76. ld de, $9000 ;location
  77. ld bc, $800
  78. call CopyData
  79. ld hl, Title+$800
  80. ld de, $8800 ;location
  81. ld bc, $100
  82. call CopyData
  83.  
  84. ;tileset
  85. ld hl, TitleTilemap
  86. ld de, W_TILEMAP
  87. ld bc, TitleTilemapEnd-TitleTilemap
  88. call CopyData
  89.  
  90.  
  91.  
  92. ld [$ffff], a
  93. ld a, %00000001
  94. ld [$ffff], a
  95. ei
  96. halt
  97. xor a
  98. ld [H_FIRSTVBLANK], a
  99.  
  100. call waitForKey ; wait for A or START to be pressed.
  101.  
  102.  
  103.  
  104. ; Now we will begin the game.
  105. ; Load up the map and sprites.
  106.  
  107. .debugLoop
  108. jp .debugLoop
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. waitForKey::
  120. .loop
  121. halt ;save battery life! <3
  122. ld a, [H_JOYNEW]
  123. and a, %00001001 ; A or START
  124. jr z, .loop
  125. ret
  126.  
  127.  
  128.  
  129. VBlank::
  130. di
  131. push af
  132. call DMARoutine
  133. pop af
  134. ei
  135. reti
  136.  
  137. ; ---------
  138. ; lcd functions
  139. ; ---------
  140. DisableLCD::
  141. xor a
  142. ld [$ff0f], a
  143. ld a, [$ffff]
  144. ld b, a
  145. res 0, a
  146. ld [$ffff], a
  147. .waitvblank
  148. ld a, [$ff44]
  149. cp a, $91
  150. jr nz, .waitvblank
  151. ld a, [$ff40]
  152. and a, $7f
  153. ld [$ff40], a
  154. ld a, b
  155. ld [$ffff], a
  156. ret
  157.  
  158. EnableLCD::
  159. ld a, [$ff40]
  160. set 7, a
  161. ld [$ff40], a
  162. ret
  163. ; -------------
  164. ; memory functions
  165. ; -------------
  166.  
  167. ReadJoypad: ;;;
  168. ld a, [H_JOY]
  169. ld [H_JOYOLD], a
  170. ld a,%00100000 ; select direction keys
  171. ld c,$00
  172. ld [rJOYP],a
  173. ld a,[rJOYP]
  174. ld a,[rJOYP]
  175. ld a,[rJOYP]
  176. ld a,[rJOYP]
  177. ld a,[rJOYP]
  178. ld a,[rJOYP]
  179. cpl ; complement the result so that a set bit indicates a pressed key
  180. and a,%00001111
  181. swap a ; put direction keys in upper nibble
  182. ld b,a
  183. ld a,%00010000 ; select button keys
  184. ld [rJOYP],a
  185. ld a,[rJOYP]
  186. ld a,[rJOYP]
  187. ld a,[rJOYP]
  188. ld a,[rJOYP]
  189. ld a,[rJOYP]
  190. ld a,[rJOYP]
  191. ld a,[rJOYP]
  192. ld a,[rJOYP]
  193. ld a,[rJOYP]
  194. ld a,[rJOYP]
  195. cpl ; complement the result so that a set bit indicates a pressed key
  196. and a,%00001111
  197. or b ; put button keys in lower nibble
  198. ld [$fff8],a ; save joypad state
  199. ld a,%00110000 ; unselect all keys
  200. ld [rJOYP],a
  201.  
  202. ld a, [H_JOY]
  203. ld b, a
  204. ld a, [H_JOYOLD]
  205. xor $ff
  206. and b
  207. ld [H_JOYNEW], a
  208.  
  209. ret
  210.  
  211. WriteDMACodeToHRAM::
  212. ld c, $80
  213. ld b, $a
  214. ld hl, DMARoutine
  215. .copyLoop
  216. ld a, [hli]
  217. ld [$ff00+c], a
  218. inc c
  219. dec b
  220. jr nz, .copyLoop
  221. ret
  222.  
  223. DMARoutine::
  224. ld a, W_OAM >> 8
  225. ld [$ff00+$46], a ; start DMA
  226. ld a, $28
  227. .waitLoop
  228. dec a
  229. jr nz, .waitLoop
  230. ret
  231.  
  232.  
  233. CopyData:: ;memcpy routine
  234. ld a, [hli]
  235. ld [de], a
  236. inc de
  237. dec bc
  238. ld a, c
  239. or b
  240. jr nz, CopyData
  241. ret
  242.  
  243. FillMemory::
  244. .loop
  245. ld [hli], a
  246. dec b
  247. jr nz, .loop
  248. ret
  249.  
  250. ClearOAM::
  251. xor a
  252. ld hl, W_OAM
  253. ld b, 4*$28
  254. call FillMemory
  255. ret
  256.  
  257.  
  258.  
  259.  
  260. ;includes
  261.  
  262. INCLUDE "title.z80"
  263. INCLUDE "tileset.z80"
  264.  
  265.  
  266.  
  267. ;internal RAM
  268. SECTION "IntRAM",BSS[$C000]
  269.  
  270. player_xpos
  271. ds 1
  272. player_ypos
  273. ds 1
  274. player_tile:
  275. ds 1
  276. player_flags:
  277. ds 1
  278.  
  279.  
  280. SECTION "highRAM",BSS[$C0A0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement