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.

847 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 #%00111111
  405. beq +
  406. rts
  407. +
  408. lda #8 ; Sprite number.
  409. sta enemyShotArray
  410. lda #254
  411. sta enemyShotArray + 1 ; x.
  412. lda #((224 - 32) / 2)
  413. and #%01111111
  414. sta enemyShotArray + 2 ; y.
  415. lda #-6
  416. sta enemyShotArray + 3 ; x-velocity.
  417. GetRandomByte
  418. and #%00000111 ; [0, 7]
  419. clc
  420. adc #-3 ; [-3, 4]
  421. cmp #4
  422. bne +
  423. lda #0 ; [-3, 3] with 2x chance of zero.
  424. +
  425. sta enemyShotArray + 4 ; y-velocity.
  426. rts
  427. UpdateShotPositions:
  428. ldx #0
  429. UpdateShot: ; Updates position of one shot.
  430. lda playerShotArray, X
  431. cmp #0
  432. beq ShotDone
  433. ; Add to the x-coordinate. If the carry bit is set, we went off the edge
  434. ; of the screen, so disable the shot.
  435. lda playerShotArray + 3, X ; x-velocity.
  436. sta $00
  437. bit #%10000000 ; Check whether the velocity is negative.
  438. bne UpdateShotWithNegativeXVelocity
  439. lda playerShotArray + 1, X
  440. clc
  441. adc $00
  442. bcs DisableShot
  443. sta playerShotArray + 1, X ; Store new x-coord.
  444. bra UpdateShotY
  445. UpdateShotWithNegativeXVelocity:
  446. ; TODO(mcmillen): wrap sprites when they go negative here, like we do
  447. ; with y-velocities.
  448. lda playerShotArray + 1, X ; Current x.
  449. clc
  450. adc $00
  451. bcc DisableShot
  452. sta playerShotArray + 1, X
  453. UpdateShotY:
  454. ; Add to the y-coordinate.
  455. lda playerShotArray + 4, X ; y-velocity.
  456. sta $00
  457. bit #%10000000 ; Check whether the velocity is negative.
  458. bne UpdateShotWithNegativeYVelocity
  459. lda playerShotArray + 2, X
  460. clc
  461. adc $00
  462. cmp #224
  463. bcs DisableShot
  464. sta playerShotArray + 2, X ; Store new y-coord.
  465. bra ShotDone
  466. UpdateShotWithNegativeYVelocity:
  467. lda playerShotArray + 2, X ; Current y.
  468. cmp #224
  469. bcs + ; If the shot was "off the top" before moving, maybe we'll reap it.
  470. adc $00 ; Otherwise, just update it,
  471. sta playerShotArray + 2, X ; save the result,
  472. bra ShotDone ; and we know it shouldn't be reaped.
  473. +
  474. clc
  475. adc $00
  476. cmp #224
  477. bcc DisableShot ; If it's now wrapped around, reap it.
  478. sta playerShotArray + 2, X
  479. bra ShotDone
  480. DisableShot:
  481. stz playerShotArray, X
  482. ShotDone:
  483. ; TODO(mcmillen): in places where we .rept inx (etc), is it faster to use
  484. ; actual addition?
  485. .rept shotSize
  486. inx
  487. .endr
  488. cpx #(playerShotArrayLength * enemyShotArrayLength * shotSize)
  489. bne UpdateShot
  490. rts
  491. UpdateBackgroundScroll:
  492. ; Make the background scroll. Horizontal over time; vertical depending on
  493. ; player's y-coordinate.
  494. lda vBlankCounter
  495. sta BG3HOFS
  496. lda vBlankCounter + 1
  497. sta BG3HOFS
  498. lda playerY
  499. .rept 3
  500. lsr
  501. .endr
  502. sta BG3VOFS
  503. stz BG3VOFS
  504. rts
  505. UpdateSprites:
  506. ; This page is a good reference on SNES sprite formats:
  507. ; http://wiki.superfamicom.org/snes/show/SNES+Sprites
  508. ; It uses the same approach we're using, in which we keep a buffer of the
  509. ; sprite tables in RAM, and DMA the sprite tables to the system's OAM
  510. ; during VBlank.
  511. ; Sprite table 1 has 4 bytes per sprite, laid out as follows:
  512. ; Byte 1: xxxxxxxx x: X coordinate
  513. ; Byte 2: yyyyyyyy y: Y coordinate
  514. ; Byte 3: cccccccc c: Starting tile #
  515. ; Byte 4: vhoopppc v: vertical flip h: horizontal flip o: priority bits
  516. ; p: palette #
  517. ; Sprite table 2 has 2 bits per sprite, like so:
  518. ; bits 0,2,4,6 - High bit of the sprite's x-coordinate.
  519. ; bits 1,3,5,7 - Toggle Sprite size: 0 - small size 1 - large size
  520. ; Setting all the high bits keeps the sprites offscreen.
  521. ; Zero out the scratch space for the secondary sprite table.
  522. ldx #0
  523. -
  524. stz spriteTableScratchStart, X
  525. inx
  526. cpx #numSprites
  527. bne -
  528. ldx #0 ; Index into sprite table 1.
  529. ldy #0 ; Index into sprite table 2.
  530. ; Copy player coords into sprite table.
  531. lda playerX
  532. sta spriteTableStart, X
  533. lda playerY
  534. sta spriteTableStart + 1, X
  535. lda #0
  536. sta spriteTableStart + 2, X
  537. ; Set priority bits so that the sprite is drawn in front.
  538. lda #%00110000
  539. sta spriteTableStart + 3, X
  540. lda #%11000000 ; Enable large sprite.
  541. sta spriteTableScratchStart, Y
  542. .rept 4
  543. inx
  544. .endr
  545. iny
  546. ; Now add shots.
  547. sty $00 ; Save sprite table 2 index.
  548. ldy #0 ; Index into playerShotArray.
  549. -
  550. lda playerShotArray, Y
  551. cmp #0
  552. beq + ; If not enabled, skip to next shot.
  553. ; Update sprite table 1.
  554. sta spriteTableStart + 2, X ; sprite number
  555. lda playerShotArray + 1, Y
  556. sta spriteTableStart, X ; x
  557. lda playerShotArray + 2, Y
  558. sta spriteTableStart + 1, X ; y
  559. ; Update secondary sprite table.
  560. phy ; Save playerShotArray index.
  561. ldy $00
  562. lda #%11000000
  563. sta spriteTableScratchStart, Y
  564. iny
  565. sty $00
  566. ply ; Restore playerShotArrayIndex.
  567. .rept 4
  568. inx
  569. .endr
  570. +
  571. .rept shotSize
  572. iny
  573. .endr
  574. cpy #((playerShotArrayLength + enemyShotArrayLength) * shotSize)
  575. bne -
  576. ; Now clear out the unused entries in the sprite table.
  577. -
  578. cpx #spriteTable1Size
  579. beq +
  580. lda #1
  581. sta spriteTableStart, X
  582. .rept 4
  583. inx
  584. .endr
  585. +
  586. rts
  587. FillSecondarySpriteTable:
  588. ; The secondary sprite table wants 2 bits for each sprite: one to set the
  589. ; sprite's size, and one that's the high bit of the sprite's x-coordinate.
  590. ; It's annoying to deal with bitfields when thinking about business logic,
  591. ; so the spriteTableScratch array contains one byte for each sprite, in
  592. ; which the two most significant bits are the "size" and "upper x" bits.
  593. ; This function is meant to be called after UpdateWorld, and packs those
  594. ; bytes into the actual bitfield that the OAM wants for the secondary
  595. ; sprite table.
  596. ;
  597. ; The expected format of every byte in the scratch sprite table is:
  598. ; sx------ s = size (0 = small, 1 = large)
  599. ; x = flipped high x-coordinate (so 1 behaves like "enable").
  600. ldx #0 ; Index into input table.
  601. ldy #0 ; Index into output table.
  602. -
  603. stz $00 ; Current byte; filled out by a set of 4 input table entries.
  604. .rept 4
  605. ; For each byte, the lower-order bits correspond to the lower-numbered
  606. ; sprites; therefore we insert the current sprite's bits "at the top"
  607. ; and shift them right for each successive sprite.
  608. lsr $00
  609. lsr $00
  610. lda spriteTableScratchStart, X
  611. ora $00
  612. sta $00
  613. inx
  614. .endr
  615. lda $00
  616. eor #%01010101
  617. sta spriteTable2Start, Y
  618. iny
  619. cpx #numSprites
  620. bne -
  621. rts
  622. SetBackgroundColor:
  623. ; The background-color bytes are (R, G, B), each ranging from [0-31].
  624. ; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr]
  625. ; Set the background color.
  626. ; Entry 0 corresponds to the SNES background color.
  627. stz CGADDR
  628. ; Compute and the low-order byte and store it in CGDATA.
  629. lda backgroundGreen
  630. .rept 5
  631. asl
  632. .endr
  633. ora backgroundRed
  634. sta CGDATA
  635. ; Compute the high-order byte and store it in CGDATA.
  636. lda backgroundBlue
  637. .rept 2
  638. asl
  639. .endr
  640. sta $00
  641. lda backgroundGreen
  642. .rept 3
  643. lsr
  644. .endr
  645. ora $00
  646. sta CGDATA
  647. rts
  648. VBlankHandler:
  649. jsr VBlankCounter
  650. jsr DMASpriteTables
  651. rti
  652. VBlankCounter:
  653. ; Increment a counter of how many VBlanks we've done.
  654. ; This is a 24-bit counter. At 60 vblanks/second, this will take
  655. ; 77 hours to wrap around; that's good enough for me :)
  656. inc vBlankCounter
  657. bne +
  658. inc vBlankCounter + 1
  659. bne +
  660. inc vBlankCounter + 2
  661. +
  662. rts
  663. DMASpriteTables:
  664. ; Store at the base OAM address.
  665. ldx #$0000
  666. stx OAMADDR
  667. ; Default DMA control; destination $2104 (OAM data register).
  668. stz DMA0CTRL
  669. lda #$04
  670. sta DMA0DST
  671. ; Our sprites start at $0100 in bank 0 and are #$220 bytes long.
  672. ldx #spriteTableStart
  673. stx DMA0SRC
  674. stz DMA0SRCBANK
  675. ldx #spriteTableSize
  676. stx DMA0SIZE
  677. ; Kick off the DMA transfer.
  678. lda #%00000001
  679. sta DMAENABLE
  680. rts
  681. .ENDS
  682. ; Bank 1 is used for our graphics assets.
  683. .BANK 1 SLOT 0
  684. .ORG 0
  685. .SECTION "GraphicsData"
  686. SpriteData:
  687. .INCBIN "sprites32.pic"
  688. SpritePalette:
  689. .INCBIN "sprites32.clr"
  690. TileData:
  691. .INCBIN "tiles.pic"
  692. TilePalette:
  693. .INCBIN "tiles.clr"
  694. .ENDS
  695. ; Fill an entire bank with random numbers.
  696. .SEED 1
  697. .BANK 2 SLOT 0
  698. .ORG 0
  699. .SECTION "RandomBytes"
  700. .DBRND 32 * 1024, 0, 255
  701. .ENDS