Simple SNES shoot-'em-up game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

861 lines
18 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. .INCLUDE "header.asm"
  2. .INCLUDE "init.asm"
  3. .INCLUDE "registers.asm"
  4. .INCLUDE "memory.asm"
  5. ; Sets A to 8-bit (& enables 8-bit "B" register).
  6. .MACRO SetA8Bit
  7. sep #%00100000 ; 8-bit A/B.
  8. .ENDM
  9. ; Sets A to 16-bit.
  10. .MACRO SetA16Bit
  11. rep #%00100000 ; 16-bit A.
  12. .ENDM
  13. ; Sets X/Y to 16-bit.
  14. .MACRO SetXY16Bit
  15. rep #%00010000 ; 16-bit X/Y.
  16. .ENDM
  17. ; Stores result to A.
  18. ; Assumes 16-bit X & 8-bit A.
  19. ; Modifies X.
  20. ; Updates randomBytePtr.
  21. .MACRO GetRandomByte
  22. ldx randomBytePtr
  23. lda $028000, X ; $028000: beginning of ROM bank 2.
  24. inx
  25. cpx #$8000 ; This is the size of the entire ROM bank.
  26. bne +++
  27. ldx #0
  28. +++
  29. stx randomBytePtr
  30. .ENDM
  31. .BANK 0 SLOT 0
  32. .ORG 0
  33. .SECTION "MainCode"
  34. Start:
  35. InitSNES
  36. ; By default we assume 16-bit X/Y and 8-bit A.
  37. ; If any code wants to change this, it's expected to do so itself,
  38. ; and to change them back to the defaults before returning.
  39. SetXY16Bit
  40. SetA8Bit
  41. jsr LoadPaletteAndTileData
  42. jsr InitWorld
  43. ; Set screen mode: 16x16 tiles for backgrounds, mode 1.
  44. lda #%11000001
  45. sta BGMODE
  46. ; Set sprite size to 16x16 (small) and 32x32 (large).
  47. lda #%01100000
  48. sta OAMSIZE
  49. ; Main screen: enable sprites & BG3.
  50. lda #%00010100
  51. sta MSENABLE
  52. ; Turn on the screen.
  53. ; Format: x000bbbb
  54. ; x: 0 = screen on, 1 = screen off, bbbb: Brightness ($0-$F)
  55. lda #%00001111
  56. sta INIDISP
  57. jmp MainLoop
  58. LoadPaletteAndTileData:
  59. ; For more details on DMA, see:
  60. ; http://wiki.superfamicom.org/snes/show/Grog%27s+Guide+to+DMA+and+HDMA+on+the+SNES
  61. ; http://wiki.superfamicom.org/snes/show/Making+a+Small+Game+-+Tic-Tac-Toe
  62. ;
  63. ; A lot of the graphics-related registers are explained in Qwertie's doc:
  64. ; http://emu-docs.org/Super%20NES/General/snesdoc.html
  65. ; ... but be careful, because there are some errors in this doc.
  66. ;
  67. ; bazz's tutorial (available from http://wiki.superfamicom.org/snes/) is
  68. ; quite helpful with palette / sprites / DMA, especially starting at
  69. ; http://wiki.superfamicom.org/snes/show/Working+with+VRAM+-+Loading+the+Palette
  70. ; Initialize the palette memory in a loop.
  71. ; We could also do this with a DMA transfer (like we do with the tile data
  72. ; below), but it seems overkill for just a few bytes. :)
  73. ; TODO(mcmillen): do it with a DMA transfer.
  74. ; First, sprite palette data:
  75. ldx #0
  76. lda #128 ; Palette entries for sprites start at 128.
  77. sta CGADDR
  78. -
  79. lda.l SpritePalette, X
  80. sta CGDATA
  81. inx
  82. cpx #32 ; 32 bytes of palette data.
  83. bne -
  84. ; Now, BG3 palette data.
  85. ; Palette entries for BG3 start at 0.
  86. ldx #0
  87. lda #0
  88. sta CGADDR
  89. -
  90. lda.l TilePalette, X
  91. sta CGDATA
  92. inx
  93. cpx #8 ; 8 bytes of palette data.
  94. bne -
  95. ; TODO(mcmillen): make the "DMA stuff into VRAM" a macro or function.
  96. ; Set VMADDR to where we want the DMA to start. We'll store sprite data
  97. ; at the beginning of VRAM.
  98. ldx #$0000
  99. stx VMADDR
  100. ; DMA 0 source address & bank.
  101. ldx #SpriteData
  102. stx DMA0SRC
  103. lda #:SpriteData
  104. sta DMA0SRCBANK
  105. ; DMA 0 transfer size. Equal to the size of sprites32.pic.
  106. ldx #2048
  107. stx DMA0SIZE
  108. ; DMA 0 control register.
  109. ; Transfer type 001 = 2 addresses, LH.
  110. lda #%00000001
  111. sta DMA0CTRL
  112. ; DMA 0 destination.
  113. lda #$18 ; The upper byte is assumed to be $21, so this is $2118 & $2119.
  114. sta DMA0DST
  115. ; Enable DMA channel 0.
  116. lda #%00000001
  117. sta DMAENABLE
  118. ; Store background tile data at byte $2000 of VRAM.
  119. ; (VMADDR is a word address, so multiply by 2 to get the byte address.)
  120. ldx #$1000
  121. stx VMADDR
  122. ; DMA 0 source address & bank.
  123. ldx #TileData
  124. stx DMA0SRC
  125. lda #:TileData
  126. sta DMA0SRCBANK
  127. ; DMA 0 transfer size. Equal to the size of tiles.pic.
  128. ldx #512
  129. stx DMA0SIZE
  130. ; DMA 0 control register.
  131. ; Transfer type 001 = 2 addresses, LH.
  132. lda #%00000001
  133. sta DMA0CTRL
  134. ; DMA 0 destination.
  135. lda #$18 ; The upper byte is assumed to be $21, so this is $2118 & $2119.
  136. sta DMA0DST
  137. ; Enable DMA channel 0.
  138. lda #%00000001
  139. sta DMAENABLE
  140. ; Tell the system that the BG3 tilemap starts at $4000.
  141. lda #%00100000
  142. sta BG3TILEMAP
  143. ; ... and that the background tile data for BG3 starts at $2000.
  144. lda #%00000001
  145. sta BG34NBA
  146. ; Set up the BG3 tilemap.
  147. ; VRAM write mode: increments the address every time we write a word.
  148. lda #%10000000
  149. sta VMAIN
  150. ; Set word address for accessing VRAM.
  151. ldx #$2000 ; BG 3 tilemap starts here. (Byte address $4000.)
  152. stx VMADDR
  153. ; Now write entries into the tile map.
  154. ldy #0
  155. -
  156. GetRandomByte
  157. sta $00
  158. ldx #$0000 ; This is a blank tile.
  159. ; 1 in 8 chance that we choose a non-blank tile.
  160. bit #%00000111
  161. bne +
  162. ldx #$0002
  163. bit #%10000000
  164. bne +
  165. ldx #$8002 ; Flip vertically.
  166. +
  167. stx VMDATA
  168. iny
  169. ; The tile map is 32x32 (1024 entries).
  170. cpy #1024
  171. bne -
  172. rts
  173. InitWorld:
  174. ; Start the background color as a dark blue.
  175. lda #4
  176. sta backgroundBlue
  177. ; Player's initial starting location.
  178. lda #(256 / 4)
  179. sta playerX
  180. lda #((224 - 32) / 2)
  181. sta playerY
  182. ; (x-velocity, y-velocity) of 4 different player shot patterns.
  183. lda #6
  184. sta shotVelocityTable
  185. lda #0
  186. sta shotVelocityTable + 1
  187. lda #3
  188. sta shotVelocityTable + 2
  189. lda #3
  190. sta shotVelocityTable + 3
  191. lda #0
  192. sta shotVelocityTable + 4
  193. lda #6
  194. sta shotVelocityTable + 5
  195. lda #-3
  196. sta shotVelocityTable + 6
  197. lda #3
  198. sta shotVelocityTable + 7
  199. lda #-6
  200. sta shotVelocityTable + 8
  201. lda #0
  202. sta shotVelocityTable + 9
  203. lda #-3
  204. sta shotVelocityTable + 10
  205. lda #-3
  206. sta shotVelocityTable + 11
  207. lda #0
  208. sta shotVelocityTable + 12
  209. lda #-6
  210. sta shotVelocityTable + 13
  211. lda #3
  212. sta shotVelocityTable + 14
  213. lda #-3
  214. sta shotVelocityTable + 15
  215. rts
  216. MainLoop:
  217. lda #%10000001 ; Enable NMI interrupt & auto joypad read.
  218. sta NMITIMEN
  219. wai ; Wait for interrupt.
  220. lda #%00000001 ; Disable NMI interrupt while processing.
  221. sta NMITIMEN
  222. jsr JoypadRead
  223. jsr JoypadHandler
  224. jsr UpdateWorld
  225. jsr UpdateSprites
  226. jsr FillSecondarySpriteTable
  227. jsr SetBackgroundColor
  228. bra MainLoop
  229. JoypadRead:
  230. ; Load joypad registers into RAM for easy inspection & manipulation.
  231. -
  232. lda HVBJOY
  233. bit #$01 ; If auto-joypad read is happening, loop.
  234. bne -
  235. ldx JOY1L
  236. stx joy1
  237. ldx JOY2L
  238. stx joy2
  239. rts
  240. JoypadHandler:
  241. JoypadUp:
  242. lda joy1 + 1
  243. bit #$08 ; Up
  244. beq JoypadDown ; Button not pressed.
  245. lda playerY
  246. cmp #0
  247. beq JoypadDown ; Value saturated.
  248. dec playerY
  249. dec playerY
  250. JoypadDown:
  251. lda joy1 + 1
  252. bit #$04 ; Down
  253. beq JoypadLeft ; Button not pressed.
  254. lda playerY
  255. cmp #(224 - 32)
  256. beq JoypadLeft ; Value saturated.
  257. inc playerY
  258. inc playerY
  259. JoypadLeft:
  260. lda joy1 + 1
  261. bit #$02 ; Left
  262. beq JoypadRight ; Button not pressed.
  263. lda playerX
  264. cmp #0
  265. beq JoypadRight ; Value saturated.
  266. dec playerX
  267. dec playerX
  268. JoypadRight:
  269. lda joy1 + 1
  270. bit #$01 ; Right
  271. beq JoypadStart ; Button not pressed.
  272. lda playerX
  273. cmp #(256 - 32)
  274. beq JoypadStart ; Value saturated.
  275. inc playerX
  276. inc playerX
  277. JoypadStart:
  278. lda joy1 + 1
  279. bit #$10 ; Start
  280. beq JoypadSelect ; Button not pressed.
  281. lda backgroundRed
  282. cmp #31
  283. beq JoypadSelect ; Value saturated.
  284. inc backgroundRed
  285. JoypadSelect:
  286. lda joy1 + 1
  287. bit #$20 ; Select
  288. beq JoypadY ; Button not pressed.
  289. lda backgroundRed
  290. cmp #0
  291. beq JoypadY ; Value saturated.
  292. dec backgroundRed
  293. JoypadY:
  294. lda joy1 + 1
  295. bit #$40 ; Y
  296. beq JoypadX ; Button not pressed.
  297. lda backgroundGreen
  298. cmp #0
  299. beq JoypadX ; Value saturated.
  300. dec backgroundGreen
  301. JoypadX:
  302. lda joy1
  303. bit #$40 ; X
  304. beq JoypadL ; Button not pressed.
  305. lda backgroundGreen
  306. cmp #31
  307. beq JoypadL ; Value saturated.
  308. inc backgroundGreen
  309. JoypadL:
  310. lda joy1
  311. bit #$20 ; L
  312. beq JoypadR ; Button not pressed.
  313. lda backgroundBlue
  314. cmp #0
  315. beq JoypadR ; Value saturated.
  316. dec backgroundBlue
  317. JoypadR:
  318. lda joy1
  319. bit #$10 ; R
  320. beq JoypadB ; Button not pressed.
  321. lda backgroundBlue
  322. cmp #31
  323. beq JoypadB ; Value saturated.
  324. inc backgroundBlue
  325. JoypadB:
  326. lda joy1 + 1
  327. bit #$80 ; B
  328. beq JoypadDone
  329. jsr MaybeShoot
  330. JoypadDone:
  331. rts
  332. MaybeShoot:
  333. ; If the cooldown timer is non-zero, don't shoot.
  334. lda shotCooldown
  335. cmp #0
  336. bne MaybeShootDone
  337. ; Find the first empty spot in the shots array.
  338. ldx #playerShotArray
  339. -
  340. lda 0, X
  341. cmp #0
  342. beq +
  343. .rept shotSize
  344. inx
  345. .endr
  346. ; If we went all the way to the end, bail out.
  347. cpx #(playerShotArray + playerShotArrayLength * shotSize)
  348. beq MaybeShootDone
  349. bra -
  350. +
  351. ; Enable shot; set its position based on player position.
  352. ; TODO(mcmillen): it might be easier/faster to keep N arrays: one for each
  353. ; field of shot (shotSpriteArray, shotXArray, shotYArray, ...)
  354. lda #8 ; Sprite number.
  355. sta 0, X
  356. lda playerX
  357. clc
  358. adc #20
  359. sta 1, X
  360. lda playerY
  361. sta 2, X
  362. ; Get x- and y-velocity out of shotVelocityTable.
  363. lda nextShotState
  364. and #%00000111 ; 8 possibilities.
  365. ldy #0
  366. -
  367. cmp #0
  368. beq +
  369. .rept 2
  370. iny
  371. .endr
  372. dec A
  373. bra -
  374. +
  375. inc nextShotState
  376. ; x-velocity.
  377. lda shotVelocityTable, Y
  378. sta 3, X
  379. ; y-velocity.
  380. lda shotVelocityTable + 1, Y
  381. sta 4, X
  382. ; Set cooldown timer.
  383. lda #8
  384. sta shotCooldown
  385. MaybeShootDone:
  386. rts
  387. UpdateWorld:
  388. jsr UpdateShotCooldown
  389. jsr SpawnEnemyShots
  390. jsr UpdateShotPositions
  391. jsr UpdateBackgroundScroll
  392. rts
  393. UpdateShotCooldown:
  394. ; Update shot cooldown.
  395. lda shotCooldown
  396. cmp #0
  397. beq +
  398. dec A
  399. sta shotCooldown
  400. +
  401. rts
  402. SpawnEnemyShots:
  403. lda vBlankCounter
  404. bit #%00001111
  405. beq +
  406. rts
  407. +
  408. ldy #0
  409. -
  410. lda enemyShotArray, Y
  411. cmp #0
  412. beq +
  413. .rept 6
  414. iny
  415. .endr
  416. cpy #(enemyShotArrayLength * shotSize)
  417. bne -
  418. rts ; Too many shots; bail.
  419. +
  420. lda #12 ; Sprite number.
  421. sta enemyShotArray, Y
  422. lda #254
  423. sta enemyShotArray + 1, Y ; x.
  424. lda #((224 - 32) / 2)
  425. and #%01111111
  426. sta enemyShotArray + 2, Y ; y.
  427. lda #-4
  428. sta enemyShotArray + 3, Y ; x-velocity.
  429. GetRandomByte
  430. and #%00000111 ; [0, 7]
  431. clc
  432. adc #-3 ; [-3, 4]
  433. cmp #4
  434. bne +
  435. lda #0 ; [-3, 3] with 2x chance of zero.
  436. +
  437. sta enemyShotArray + 4, Y ; y-velocity.
  438. rts
  439. UpdateShotPositions:
  440. ldx #0
  441. UpdateShot: ; Updates position of one shot.
  442. lda playerShotArray, X
  443. cmp #0
  444. beq ShotDone
  445. ; Add to the x-coordinate. If the carry bit is set, we went off the edge
  446. ; of the screen, so disable the shot.
  447. lda playerShotArray + 3, X ; x-velocity.
  448. sta $00
  449. bit #%10000000 ; Check whether the velocity is negative.
  450. bne UpdateShotWithNegativeXVelocity
  451. lda playerShotArray + 1, X
  452. clc
  453. adc $00
  454. bcs DisableShot
  455. sta playerShotArray + 1, X ; Store new x-coord.
  456. bra UpdateShotY
  457. UpdateShotWithNegativeXVelocity:
  458. ; TODO(mcmillen): wrap sprites when they go negative here, like we do
  459. ; with y-velocities.
  460. lda playerShotArray + 1, X ; Current x.
  461. clc
  462. adc $00
  463. bcc DisableShot
  464. sta playerShotArray + 1, X
  465. UpdateShotY:
  466. ; Add to the y-coordinate.
  467. lda playerShotArray + 4, X ; y-velocity.
  468. sta $00
  469. bit #%10000000 ; Check whether the velocity is negative.
  470. bne UpdateShotWithNegativeYVelocity
  471. lda playerShotArray + 2, X
  472. clc
  473. adc $00
  474. cmp #224
  475. bcs DisableShot
  476. sta playerShotArray + 2, X ; Store new y-coord.
  477. bra ShotDone
  478. UpdateShotWithNegativeYVelocity:
  479. lda playerShotArray + 2, X ; Current y.
  480. cmp #224
  481. bcs + ; If the shot was "off the top" before moving, maybe we'll reap it.
  482. adc $00 ; Otherwise, just update it,
  483. sta playerShotArray + 2, X ; save the result,
  484. bra ShotDone ; and we know it shouldn't be reaped.
  485. +
  486. clc
  487. adc $00
  488. cmp #224
  489. bcc DisableShot ; If it's now wrapped around, reap it.
  490. sta playerShotArray + 2, X
  491. bra ShotDone
  492. DisableShot:
  493. stz playerShotArray, X
  494. ShotDone:
  495. ; TODO(mcmillen): in places where we .rept inx (etc), is it faster to use
  496. ; actual addition?
  497. .rept shotSize
  498. inx
  499. .endr
  500. cpx #(playerShotArrayLength * enemyShotArrayLength * shotSize)
  501. bne UpdateShot
  502. rts
  503. UpdateBackgroundScroll:
  504. ; Make the background scroll. Horizontal over time; vertical depending on
  505. ; player's y-coordinate.
  506. lda vBlankCounter
  507. sta BG3HOFS
  508. lda vBlankCounter + 1
  509. sta BG3HOFS
  510. lda playerY
  511. .rept 3
  512. lsr
  513. .endr
  514. sta BG3VOFS
  515. stz BG3VOFS
  516. rts
  517. UpdateSprites:
  518. ; This page is a good reference on SNES sprite formats:
  519. ; http://wiki.superfamicom.org/snes/show/SNES+Sprites
  520. ; It uses the same approach we're using, in which we keep a buffer of the
  521. ; sprite tables in RAM, and DMA the sprite tables to the system's OAM
  522. ; during VBlank.
  523. ; Sprite table 1 has 4 bytes per sprite, laid out as follows:
  524. ; Byte 1: xxxxxxxx x: X coordinate
  525. ; Byte 2: yyyyyyyy y: Y coordinate
  526. ; Byte 3: cccccccc c: Starting tile #
  527. ; Byte 4: vhoopppc v: vertical flip h: horizontal flip o: priority bits
  528. ; p: palette #
  529. ; Sprite table 2 has 2 bits per sprite, like so:
  530. ; bits 0,2,4,6 - High bit of the sprite's x-coordinate.
  531. ; bits 1,3,5,7 - Toggle Sprite size: 0 - small size 1 - large size
  532. ; Setting all the high bits keeps the sprites offscreen.
  533. ; Zero out the scratch space for the secondary sprite table.
  534. ldx #0
  535. -
  536. stz spriteTableScratchStart, X
  537. inx
  538. cpx #numSprites
  539. bne -
  540. ldx #0 ; Index into sprite table 1.
  541. ldy #0 ; Index into sprite table 2.
  542. ; Copy player coords into sprite table.
  543. lda playerX
  544. sta spriteTableStart, X
  545. lda playerY
  546. sta spriteTableStart + 1, X
  547. lda #0
  548. sta spriteTableStart + 2, X
  549. ; Set priority bits so that the sprite is drawn in front.
  550. lda #%00110000
  551. sta spriteTableStart + 3, X
  552. lda #%11000000 ; Enable large sprite.
  553. sta spriteTableScratchStart, Y
  554. .rept 4
  555. inx
  556. .endr
  557. iny
  558. ; Now add shots.
  559. sty $00 ; Save sprite table 2 index.
  560. ldy #0 ; Index into playerShotArray.
  561. -
  562. lda playerShotArray, Y
  563. cmp #0
  564. beq + ; If not enabled, skip to next shot.
  565. ; Update sprite table 1.
  566. sta spriteTableStart + 2, X ; sprite number
  567. lda playerShotArray + 1, Y
  568. sta spriteTableStart, X ; x
  569. lda playerShotArray + 2, Y
  570. sta spriteTableStart + 1, X ; y
  571. ; Update secondary sprite table.
  572. phy ; Save playerShotArray index.
  573. ldy $00
  574. lda #%11000000
  575. sta spriteTableScratchStart, Y
  576. iny
  577. sty $00
  578. ply ; Restore playerShotArrayIndex.
  579. .rept 4
  580. inx
  581. .endr
  582. +
  583. .rept shotSize
  584. iny
  585. .endr
  586. cpy #((playerShotArrayLength + enemyShotArrayLength) * shotSize)
  587. bne -
  588. ; Now clear out the unused entries in the sprite table.
  589. -
  590. cpx #spriteTable1Size
  591. beq +
  592. lda #1
  593. sta spriteTableStart, X
  594. .rept 4
  595. inx
  596. .endr
  597. bra -
  598. +
  599. rts
  600. FillSecondarySpriteTable:
  601. ; The secondary sprite table wants 2 bits for each sprite: one to set the
  602. ; sprite's size, and one that's the high bit of the sprite's x-coordinate.
  603. ; It's annoying to deal with bitfields when thinking about business logic,
  604. ; so the spriteTableScratch array contains one byte for each sprite, in
  605. ; which the two most significant bits are the "size" and "upper x" bits.
  606. ; This function is meant to be called after UpdateWorld, and packs those
  607. ; bytes into the actual bitfield that the OAM wants for the secondary
  608. ; sprite table.
  609. ;
  610. ; The expected format of every byte in the scratch sprite table is:
  611. ; sx------ s = size (0 = small, 1 = large)
  612. ; x = flipped high x-coordinate (so 1 behaves like "enable").
  613. ldx #0 ; Index into input table.
  614. ldy #0 ; Index into output table.
  615. -
  616. stz $00 ; Current byte; filled out by a set of 4 input table entries.
  617. .rept 4
  618. ; For each byte, the lower-order bits correspond to the lower-numbered
  619. ; sprites; therefore we insert the current sprite's bits "at the top"
  620. ; and shift them right for each successive sprite.
  621. lsr $00
  622. lsr $00
  623. lda spriteTableScratchStart, X
  624. ora $00
  625. sta $00
  626. inx
  627. .endr
  628. lda $00
  629. eor #%01010101
  630. sta spriteTable2Start, Y
  631. iny
  632. cpx #numSprites
  633. bne -
  634. rts
  635. SetBackgroundColor:
  636. ; The background-color bytes are (R, G, B), each ranging from [0-31].
  637. ; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr]
  638. ; Set the background color.
  639. ; Entry 0 corresponds to the SNES background color.
  640. stz CGADDR
  641. ; Compute and the low-order byte and store it in CGDATA.
  642. lda backgroundGreen
  643. .rept 5
  644. asl
  645. .endr
  646. ora backgroundRed
  647. sta CGDATA
  648. ; Compute the high-order byte and store it in CGDATA.
  649. lda backgroundBlue
  650. .rept 2
  651. asl
  652. .endr
  653. sta $00
  654. lda backgroundGreen
  655. .rept 3
  656. lsr
  657. .endr
  658. ora $00
  659. sta CGDATA
  660. rts
  661. VBlankHandler:
  662. jsr VBlankCounter
  663. jsr DMASpriteTables
  664. rti
  665. VBlankCounter:
  666. ; Increment a counter of how many VBlanks we've done.
  667. ; This is a 24-bit counter. At 60 vblanks/second, this will take
  668. ; 77 hours to wrap around; that's good enough for me :)
  669. inc vBlankCounter
  670. bne +
  671. inc vBlankCounter + 1
  672. bne +
  673. inc vBlankCounter + 2
  674. +
  675. rts
  676. DMASpriteTables:
  677. ; Store at the base OAM address.
  678. ldx #$0000
  679. stx OAMADDR
  680. ; Default DMA control; destination $2104 (OAM data register).
  681. stz DMA0CTRL
  682. lda #$04
  683. sta DMA0DST
  684. ; Our sprites start at $0100 in bank 0 and are #$220 bytes long.
  685. ldx #spriteTableStart
  686. stx DMA0SRC
  687. stz DMA0SRCBANK
  688. ldx #spriteTableSize
  689. stx DMA0SIZE
  690. ; Kick off the DMA transfer.
  691. lda #%00000001
  692. sta DMAENABLE
  693. rts
  694. .ENDS
  695. ; Bank 1 is used for our graphics assets.
  696. .BANK 1 SLOT 0
  697. .ORG 0
  698. .SECTION "GraphicsData"
  699. SpriteData:
  700. .INCBIN "sprites32.pic"
  701. SpritePalette:
  702. .INCBIN "sprites32.clr"
  703. TileData:
  704. .INCBIN "tiles.pic"
  705. TilePalette:
  706. .INCBIN "tiles.clr"
  707. .ENDS
  708. ; Fill an entire bank with random numbers.
  709. .SEED 1
  710. .BANK 2 SLOT 0
  711. .ORG 0
  712. .SECTION "RandomBytes"
  713. .DBRND 32 * 1024, 0, 255
  714. .ENDS