main.a65 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. #include "memmap.i65"
  2. #include "dma.i65"
  3. GAME_MAIN:
  4. sep #$20 : .as
  5. lda #$00
  6. sta @AVR_CMD
  7. rep #$20 : .al
  8. lda #$0000
  9. sta @AVR_PARAM
  10. sta @AVR_PARAM+2
  11. sep #$20 : .as
  12. stz $4200 ; inhibit VBlank NMI
  13. jsr killdma
  14. jsr waitblank
  15. jsr snes_init
  16. lda #$01
  17. sta $420d ; fast cpu
  18. jsr setup_gfx
  19. jsr colortest
  20. jsr setup_hdma
  21. jsr menu_init
  22. jsr tests
  23. sep #$20 : .as
  24. lda @RTC_STATUS
  25. beq +
  26. jsl time_init
  27. +
  28. jsr menuloop
  29. cli
  30. stz $4200
  31. jmp @infloop ;infinite loop in WRAM
  32. killdma:
  33. stz $420b
  34. stz $420c
  35. stz $4310
  36. stz $4311
  37. stz $4312
  38. stz $4313
  39. stz $4314
  40. stz $4320
  41. stz $4321
  42. stz $4322
  43. stz $4323
  44. stz $4324
  45. stz $4330
  46. stz $4331
  47. stz $4332
  48. stz $4333
  49. stz $4334
  50. stz $4340
  51. stz $4341
  52. stz $4342
  53. stz $4343
  54. stz $4344
  55. stz $4350
  56. stz $4351
  57. stz $4352
  58. stz $4353
  59. stz $4354
  60. stz $4360
  61. stz $4361
  62. stz $4362
  63. stz $4363
  64. stz $4364
  65. rts
  66. waitblank:
  67. - lda $4212
  68. and #$80
  69. bne -
  70. - lda $4212
  71. and #$80
  72. beq -
  73. rts
  74. colortest:
  75. sep #$20 : .as
  76. rep #$10 : .xl
  77. stz $2130
  78. rts
  79. setup_gfx:
  80. sep #$20 : .as
  81. rep #$10 : .xl
  82. stz $4200
  83. stz $420b
  84. stz $420c
  85. ;clear tilemap buffers
  86. ldx #$0000
  87. stx $2181
  88. lda #$01
  89. sta $2183
  90. DMA0(#$08, #0, #^zero, #!zero, #$80)
  91. ;copy 2bpp font (can be used as 4-bit lores font!)
  92. ldx #$4000
  93. stx $2116
  94. DMA0(#$01, #$2000, #^font2, #!font2, #$18)
  95. ;copy 4bpp font
  96. ldx #$0000
  97. stx $2116
  98. DMA0(#$01, #$4000, #^font4, #!font4, #$18)
  99. ;clear BG1 tilemap
  100. ldx #BG1_TILE_BASE
  101. stx $2116
  102. DMA0(#$09, #$1000, #^zero, #!zero, #$18)
  103. ;clear BG2 tilemap
  104. ldx #BG2_TILE_BASE
  105. stx $2116
  106. DMA0(#$09, #$1000, #^zero, #!zero, #$18)
  107. ;clear OAM tables
  108. ldx #$0000
  109. stx $2102
  110. DMA0(#$08, #$544, #^zero, #!zero, #$04)
  111. ;copy logo tiles
  112. ldx #$2000
  113. stx $2116
  114. DMA0(#$01, #$4000, #^logo, #!logo, #$18)
  115. ;copy logo tilemap
  116. ldx #BG1_TILE_BASE
  117. stx $2116
  118. DMA0(#$01, #$280, #^logomap, #!logomap, #$18)
  119. ;copy sprites tiles
  120. ldx #OAM_TILE_BASE
  121. stx $2116
  122. DMA0(#$01, #$400, #^logospr, #!logospr, #$18)
  123. ;set OAM tables
  124. ldx #$0000
  125. stx $2102
  126. DMA0(#$00, #$5C, #^oam_data_l, #!oam_data_l, #$04)
  127. ldx #$0100
  128. stx $2102
  129. DMA0(#$00, #$08, #^oam_data_h, #!oam_data_h, #$04)
  130. ;set palette
  131. stz $2121
  132. DMA0(#$00, #$200, #^palette, #!palette, #$22)
  133. ;copy hdma tables so we can work "without" the cartridge
  134. ;palette
  135. lda #^hdma_pal
  136. ldx #!hdma_pal
  137. stx $2181
  138. sta $2183
  139. DMA0(#$00, #52, #^hdma_pal_src, #!hdma_pal_src, #$80)
  140. ;CG addr for palette
  141. lda #^hdma_cg_addr
  142. ldx #!hdma_cg_addr
  143. stx $2181
  144. sta $2183
  145. DMA0(#$00, #227, #^hdma_cg_addr_src, #!hdma_cg_addr_src, #$80)
  146. ;screen mode
  147. lda #^hdma_mode
  148. ldx #!hdma_mode
  149. stx $2181
  150. sta $2183
  151. DMA0(#$00, #5, #^hdma_mode_src, #!hdma_mode_src, #$80)
  152. ;bg scroll
  153. lda #^hdma_scroll
  154. ldx #!hdma_scroll
  155. stx $2181
  156. sta $2183
  157. DMA0(#$00, #11, #^hdma_scroll_src, #!hdma_scroll_src, #$80);
  158. ;color math
  159. lda #^hdma_math
  160. ldx #!hdma_math
  161. stx $2181
  162. sta $2183
  163. DMA0(#$00, #19, #^hdma_math_src, #!hdma_math_src, #$80);
  164. ;copy infinite loop to WRAM
  165. lda #$80
  166. sta infloop
  167. lda #$fe
  168. sta infloop+1
  169. lda #^wram_fadeloop
  170. ldx #!wram_fadeloop
  171. stx $2181
  172. sta $2183
  173. DMA0(#$00, #$6C, #^fadeloop, #!fadeloop, #$80);
  174. rts
  175. tests:
  176. sep #$20 : .as ;8-bit accumulator
  177. rep #$10 : .xl ;16-bit index
  178. lda #$03 ;mode 3, mode 5 via HDMA :D
  179. sta $2105
  180. lda #$58 ;Tilemap addr 0xB000
  181. ora #$02 ;SC size 32x64
  182. sta $2107 ;for BG1
  183. lda #$50 ;Tilemap addr 0xA000
  184. ora #$02 ;SC size 32x64
  185. sta $2108 ;for BG2
  186. lda #$40 ;chr base addr:
  187. sta $210b ;BG1=0x0000, BG2=0x8000
  188. lda #$13 ;enable BG1+BG2+OBJ
  189. sta $212c ;BG Main
  190. lda #$13 ;enable BG1+BG2+OBJ
  191. sta $212d ;BG Sub
  192. lda #$20 ;Window 1 for color
  193. sta $2125 ;Color window
  194. lda #$01 ;cut off leftmost subscreen pixel garbage
  195. sta $2126
  196. lda #$fe
  197. sta $2127
  198. jsr setup_224
  199. lda #$10
  200. sta $2130
  201. lda #$1f
  202. sta $212e
  203. sta $212f
  204. stz $2121
  205. lda #$0f
  206. sta $2100 ;screen on, full brightness
  207. lda #9
  208. sta bar_yl
  209. rts
  210. snes_init:
  211. sep #$20 : .as ;8-bit accumulator
  212. rep #$10 : .xl ;16-bit index
  213. stz $4200 ;
  214. lda #$ff
  215. sta $4201 ;
  216. stz $4202 ;
  217. stz $4203 ;
  218. stz $4204 ;
  219. stz $4205 ;
  220. stz $4206 ;
  221. stz $4207 ;
  222. stz $4208 ;
  223. stz $4209 ;
  224. stz $420a ;
  225. stz $420b ;
  226. stz $420c ;
  227. lda #$01
  228. sta $420d ; FAAAAAST
  229. lda #$8f
  230. sta $2100 ;INIDISP: force blank
  231. lda #$03 ; 8x8+16x16; name=0; base=3
  232. sta $2101 ;
  233. stz $2102 ;
  234. stz $2103 ;
  235. ; stz $2104 ; (OAM Data?!)
  236. ; stz $2104 ; (OAM Data?!)
  237. stz $2105 ;
  238. stz $2106 ;
  239. stz $2107 ;
  240. stz $2108 ;
  241. stz $2109 ;
  242. stz $210a ;
  243. stz $210b ;
  244. stz $210c ;
  245. stz $210d ;
  246. stz $210d ;
  247. stz $210e ;
  248. stz $210e ;
  249. stz $210f ;
  250. stz $210f ;
  251. lda #$05
  252. sta $2110 ;
  253. stz $2110 ;
  254. stz $2111 ;
  255. stz $2111 ;
  256. stz $2112 ;
  257. stz $2112 ;
  258. stz $2113 ;
  259. stz $2113 ;
  260. stz $2114 ;
  261. stz $2114 ;
  262. lda #$80
  263. sta $2115 ;
  264. stz $2116 ;
  265. stz $2117 ;
  266. ; stz $2118 ;(VRAM Data?!)
  267. ; stz $2119 ;(VRAM Data?!)
  268. stz $211a ;
  269. stz $211b ;
  270. lda #$01
  271. sta $211b ;
  272. stz $211c ;
  273. stz $211c ;
  274. stz $211d ;
  275. stz $211d ;
  276. stz $211e ;
  277. sta $211e ;
  278. stz $211f ;
  279. stz $211f ;
  280. stz $2120 ;
  281. stz $2120 ;
  282. stz $2121 ;
  283. ; stz $2122 ; (CG Data?!)
  284. ; stz $2122 ; (CG Data?!)
  285. stz $2123 ;
  286. stz $2124 ;
  287. stz $2125 ;
  288. stz $2126 ;
  289. stz $2127 ;
  290. stz $2128 ;
  291. stz $2129 ;
  292. stz $212a ;
  293. stz $212b ;
  294. stz $212c ;
  295. stz $212d ;
  296. stz $212e ;
  297. stz $212f ;
  298. lda #$30
  299. sta $2130 ;
  300. stz $2131 ;
  301. lda #$e0
  302. sta $2132 ;
  303. stz $2133 ;
  304. ;clear WRAM lower page
  305. ; ldx #$0200
  306. ; stx $2181
  307. ; lda #$00
  308. ; sta $2183
  309. ; DMA0(#$08, #$FF00, #^zero, #!zero, #$80)
  310. ; ldx #$0000
  311. ; stx $2181
  312. ; lda #$00
  313. ; sta $2183
  314. ; DMA0(#$08, #$1e0, #^zero, #!zero, #$80)
  315. rts
  316. fadeloop:
  317. sep #$30 : .as : .xs
  318. ldx #$0f
  319. and #$00
  320. pha
  321. plb
  322. lda #$7f
  323. sta hdma_math_selection+2
  324. lda #$30
  325. sta hdma_math_selection+1
  326. lda #$bf
  327. sta hdma_math+1
  328. sta hdma_math+4
  329. sta hdma_math+16
  330. lda #$e0
  331. sta hdma_math+2
  332. sta hdma_math+5
  333. sta hdma_math+17
  334. fadeloop_start
  335. lda $4212
  336. and #$80
  337. bne fadeloop_start
  338. - lda $4212
  339. and #$80
  340. bne +
  341. bra -
  342. + lda hdma_math+2
  343. inc
  344. inc
  345. sta hdma_math+2
  346. sta hdma_math+5
  347. sta hdma_math+17
  348. txa
  349. dec
  350. sta $2100
  351. tax
  352. bne fadeloop_start
  353. stz $2126
  354. stz $212e
  355. stz $2131
  356. stz $2130
  357. lda #$00
  358. sta @hdma_math
  359. stz $2100
  360. - bra -
  361. fadeloop_end:
  362. .byt $ff