Advertisement
atm959

main.asm (SNES Homebrew Program)

Jul 17th, 2018
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. ;== Include MemoryMap, HeaderInfo, and interrupt Vector table ==
  2. .INCLUDE "header.inc"
  3.  
  4. ;== Include Library Routines ==
  5. .INCLUDE "InitSNES.asm"
  6. .INCLUDE "LoadGraphics.asm"
  7.  
  8. ;RAM Usage:
  9. ; $0000 - BG1 (Map) Horizontal Scroll
  10. ; $0001 - BG1 (Map) Vertical Scroll
  11. ; $0002 - BG2 (Checkerboard) Horizontal Scroll
  12. ; $0003 - BG2 (Checkerboard) Vertical Scroll
  13. ; $0004 - Noise On Value
  14.  
  15. ;==========================================
  16. ; Main Code
  17. ;==========================================
  18.  
  19. .BANK 0 SLOT 0
  20. .ORG 0
  21. .SECTION "MainCode"
  22.  
  23. Main:
  24. InitializeSNES ;Initialize the SNES
  25.  
  26. rep #$10 ;Set X/Y to 16-bit
  27. sep #$20 ;Set A to 8-bit
  28.  
  29. jsl UploadAndExecuteSoundEngine
  30.  
  31. LoadPalette BGPalette, 0, 12 ;Load the background palette
  32.  
  33. LoadPalette BGPalette, 8*16, 12 ;Load the background palette
  34.  
  35. LoadBlockToVRAM TileData, $0000, TileDataEnd-TileData ;Load the background tiles
  36. LoadBlockToVRAM LevelData, $0800, $0800 ;Load the map to VRAM
  37. LoadBlockToVRAM CheckerData, $0C00, $0800 ;Load the checkerboard to VRAM (A Routine to generate the checkerboard will eventually be used)
  38.  
  39. jsl PlaceHud ;Place the text on BG3
  40.  
  41. jsr SetupVideo ;Setup video
  42.  
  43. lda #$81
  44. sta $4200 ;Enable NMI and Joypad Auto-Read
  45.  
  46. lda #$0F
  47. sta $2100 ; Turn on screen, full Brightness
  48.  
  49. jsr MosaicEffect ; Do the mosaic effect
  50.  
  51. lda #$00
  52. sta $0004
  53. sta $0005
  54.  
  55. Infinity:
  56. sep #$20
  57.  
  58. lda $4219
  59. and #$08
  60. bne @SkipUp
  61. lda $0001
  62. inc a
  63. sta $0001
  64. lda $0003
  65. dec a
  66. sta $0003
  67. @SkipUp:
  68.  
  69. lda $4219
  70. and #$04
  71. bne @SkipDown
  72. lda $0001
  73. dec a
  74. sta $0001
  75. lda $0003
  76. inc a
  77. sta $0003
  78. @SkipDown:
  79.  
  80. lda $4219
  81. and #$02
  82. bne @SkipLeft
  83. lda $0000
  84. inc a
  85. sta $0000
  86. lda $0002
  87. dec a
  88. sta $0002
  89. @SkipLeft:
  90.  
  91. lda $4219
  92. and #$01
  93. bne @SkipRight
  94. lda $0000
  95. dec a
  96. sta $0000
  97. lda $0002
  98. inc a
  99. sta $0002
  100. @SkipRight:
  101.  
  102. lda #$00
  103. sta $2141
  104.  
  105. lda $4218
  106. and #$80
  107. beq @SkipA
  108.  
  109. lda #$01
  110. sta $2141
  111.  
  112. @SkipA:
  113.  
  114. lda $0004
  115. inc a
  116. sta $0004
  117. sta $2140
  118.  
  119. @WaitEcho:
  120. lda $2140
  121. cmp $0004
  122. bne @WaitEcho
  123.  
  124. rep #$20
  125.  
  126. wai ;Wait for interrupt
  127. jmp Infinity ;Jump to Infinity
  128.  
  129. ;============================================================================
  130. VBlank:
  131. rep #$30 ; A/mem=16 bits, X/Y=16 bits (to push all 16 bits)
  132. phb
  133. pha
  134. phx
  135. phy
  136. phd
  137.  
  138. sep #$20 ;Set A to 8-bit
  139. rep #$10 ;Set X/Y to 16-bit
  140.  
  141. lda $4210 ; Clear NMI flag
  142.  
  143. ;Sprite Code Start
  144. ldx #$0000
  145. stx $2102
  146.  
  147. lda $0000
  148. sta $2104
  149.  
  150. lda $0001
  151. sta $2104
  152.  
  153. lda #$31
  154. sta $2104
  155.  
  156. lda #$30
  157. sta $2104
  158.  
  159. lda #$20
  160. sta $2104
  161.  
  162. lda #$30
  163. sta $2104
  164.  
  165. lda $0000
  166. sta $2104
  167.  
  168. lda #$30
  169. sta $2104
  170.  
  171. ldx #$0100
  172. stx $2102
  173.  
  174. lda #$0A
  175. sta $2104
  176. ;Sprite Code End
  177.  
  178. ldx #$0000
  179.  
  180. lda $0000 ;Load $0002 into A
  181. sta $210D ;Store A into the low byte of $210D (BG1HOFS)
  182. stx $210D ;Store X into the high byte of $210D
  183.  
  184. lda $0001
  185. sta $210E ;Store A into the low byte of $210E (BG1VOFS)
  186. stx $210E ;Store X into the high byte of $210E
  187.  
  188. lda $0002
  189. sta $210F
  190. stx $210F
  191.  
  192. lda $0003
  193. sta $2110
  194. stx $2110
  195.  
  196. rep #$20 ;Set A to 16-bit
  197.  
  198. ;sep #$10
  199.  
  200. pld
  201. ply
  202. plx
  203. pla
  204. plb
  205.  
  206. sep #$30
  207. rti
  208. ;============================================================================
  209.  
  210. MosaicEffect:
  211. lda #$FF
  212. sta $2106
  213. Loop:
  214. sbc #$10
  215. sta $2106
  216. wai
  217. wai
  218. wai
  219. wai
  220. wai
  221. wai
  222. wai
  223. wai
  224. cmp #$0F
  225. bne Loop
  226. rts
  227.  
  228. PlaceHud:
  229. rep #$10
  230. ldx #$1000
  231. ldy #$0000
  232. @PlaceHudLoop:
  233. stx $2116
  234. lda Text, y
  235. cmp #$FF
  236. beq @DonePlacingHud
  237. sta $2118
  238. lda #$20
  239. sta $2119
  240. inx
  241. iny
  242. jmp @PlaceHudLoop
  243. @DonePlacingHud:
  244. rtl
  245.  
  246. Text: .db "USE D-PAD TO SCROLL HOLD A FOR NOISE", $FF
  247.  
  248. UploadAndExecuteSoundEngine:
  249. sei ;Disable interrupts
  250.  
  251. @WaitReady1:
  252. lda $2140
  253. cmp #$AA
  254. bne @WaitReady1
  255. @WaitReady2:
  256. lda $2141
  257. cmp #$BB
  258. bne @WaitReady2 ;"Is the SPC700 ready?"
  259.  
  260. lda #$01
  261. sta $2141
  262. lda #$00
  263. sta $2142
  264. lda #$05
  265. sta $2143
  266. lda #$CC
  267. sta $2140 ;Send the transfer begin bytes
  268.  
  269. @WaitEcho1:
  270. lda $2140
  271. cmp #$CC
  272. bne @WaitEcho1 ;Wait for PORT0 to echo
  273.  
  274. ldx SoundEngineEnd-SoundEngine
  275. ldy #$0000
  276. @TransferFirst:
  277. lda SoundEngine, y
  278. sta $2141 ;Write the first byte to PORT1
  279.  
  280. lda #$00
  281. sta $2140 ;Write 0 to PORT0
  282.  
  283. @WaitEcho2:
  284. lda $2140
  285. cmp #$00
  286. bne @WaitEcho2 ;Wait for PORT0 to echo
  287.  
  288. dex
  289. iny
  290.  
  291. @TransferRest:
  292. lda SoundEngine, y
  293. sta $2141 ;Write the next byte to PORT1
  294.  
  295. lda $2140
  296. inc a
  297. sta $2140 ;Increase the byte in PORT0 and send it back
  298. sta $0000
  299.  
  300. @WaitEcho3:
  301. lda $2140
  302. cmp $0000
  303. bne @WaitEcho3
  304.  
  305. dex
  306. iny
  307.  
  308. txa
  309. cmp #$00
  310. bne @TransferRest
  311.  
  312. lda #$00
  313. sta $2141 ;0 in PORT1
  314. lda #$00
  315. sta $2142
  316. lda #$05
  317. sta $2143 ;Execute address in PORT2 and PORT3
  318. lda $2140
  319. clc
  320. adc #$02
  321. sta $2140 ;Increase PORT0 by 2 and store it in PORT0
  322.  
  323. stz $0000
  324. lda #$00
  325. ldx #$0000
  326. ldy #$0000
  327.  
  328. cli ;Enable interrupts
  329. rtl
  330.  
  331. SoundEngine: .incbin "soundEngine.bin"
  332. SoundEngineEnd:
  333.  
  334. ;============================================================================
  335. ; SetupVideo -- Sets up the video mode and tile-related registers
  336. ;----------------------------------------------------------------------------
  337. ; In: None
  338. ;----------------------------------------------------------------------------
  339. ; Out: None
  340. ;----------------------------------------------------------------------------
  341. SetupVideo:
  342.  
  343. lda #$09
  344. sta $2105 ; Set Video mode 1 and BG3 priority bit
  345.  
  346. lda #$08
  347. sta $2107 ; Set BG1's Tile Map offset to $0800 (Word address)
  348. lda #$0C
  349. sta $2108 ; Set BG2's Tile Map offset to $0C00
  350. lda #$10
  351. sta $2109 ; Set BG3's Tile Map offset to $1000
  352.  
  353. lda #$17 ; Enable BG1, BG2, BG3, and OBJ
  354. sta $212C
  355.  
  356. rts
  357.  
  358. .ENDS
  359. ;============================================================================
  360.  
  361. .BANK 1 SLOT 0
  362. .ORG 0
  363. .SECTION "CharacterData"
  364. TileData:
  365. .incbin "tiles.chr"
  366. TileDataEnd:
  367.  
  368. BGPalette:
  369. ; gggrrrrr ?bbbbbgg
  370. .db %00000000, %00000000
  371. .db %00010000, %01000010
  372. .db %00001000, %00100001
  373. .db %11111111, %01111111
  374.  
  375. .db %00000000, %00000000
  376. .db %11111111, %01111111
  377. .db %00000000, %00000000
  378. .db %00011111, %00000000
  379.  
  380. .db %00000000, %00000000
  381. .db %11010110, %01111110
  382. .db %00010000, %01111110
  383. .db %00001000, %01111101
  384. .ENDS
  385.  
  386. .SECTION "MapData"
  387. LevelData: .incbin "level1.bin"
  388. CheckerData: .incbin "checker.bin"
  389. .ENDS
  390.  
  391. ;.SECTION "SoundEngine"
  392. ;SoundEngine: .incbin "soundEngine.bin"
  393. ;SoundEngineEnd:
  394. ;.ENDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement