main.a65 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #include "memmap.i65"
  2. #include "dma.i65"
  3. GAME_MAIN:
  4. sep #$20 : .as
  5. jsr snes_init
  6. jsr setup_gfx
  7. jsr setup_hdma
  8. jsr tests
  9. jsr colortest
  10. sep #$20 : .as
  11. lda #$00
  12. sta @AVR_CMD
  13. rep #$20 : .al
  14. lda #$0000
  15. sta @AVR_PARAM
  16. sta @AVR_PARAM+2
  17. jsr menu_init
  18. sep #$20 : .as
  19. jsr menuloop
  20. cli
  21. stz $4200
  22. jmp @infloop ;infinite loop in WRAM
  23. colortest:
  24. sep #$20 : .as
  25. rep #$10 : .xl
  26. stz $2130
  27. rts
  28. setup_gfx:
  29. sep #$20 : .as
  30. rep #$10 : .xl
  31. stz $420b
  32. stz $420c
  33. ;clear tilemap buffers
  34. ldx #$0000
  35. stx $2181
  36. lda #$01
  37. sta $2183
  38. DMA0(#$08, #0, #^zero, #!zero, #$80)
  39. ;copy 2bpp font (can be used as 4-bit lores font!)
  40. ldx #$4000
  41. stx $2116
  42. DMA0(#$01, #$2000, #^font2, #!font2, #$18)
  43. ;copy 4bpp font
  44. ldx #$0000
  45. stx $2116
  46. DMA0(#$01, #$4000, #^font4, #!font4, #$18)
  47. ;clear BG1 tilemap
  48. ldx #BG1_TILE_BASE
  49. stx $2116
  50. DMA0(#$09, #$1000, #^zero, #!zero, #$18)
  51. ;clear BG2 tilemap
  52. ldx #BG2_TILE_BASE
  53. stx $2116
  54. DMA0(#$09, #$1000, #^zero, #!zero, #$18)
  55. ;copy logo tiles
  56. ldx #$2000
  57. stx $2116
  58. DMA0(#$01, #$3480, #^logo, #!logo, #$18)
  59. ;copy logo tilemap
  60. ldx #BG1_TILE_BASE
  61. stx $2116
  62. DMA0(#$01, #$280, #^logomap, #!logomap, #$18)
  63. ;set palette
  64. stz $2121
  65. DMA0(#$00, #$200, #^palette, #!palette, #$22)
  66. ;copy hdma tables so we can work "without" the cartridge
  67. ;palette
  68. lda #^hdma_pal
  69. ldx #!hdma_pal
  70. stx $2181
  71. sta $2183
  72. DMA0(#$00, #52, #^hdma_pal_src, #!hdma_pal_src, #$80)
  73. ;CG addr for palette
  74. lda #^hdma_cg_addr
  75. ldx #!hdma_cg_addr
  76. stx $2181
  77. sta $2183
  78. DMA0(#$00, #227, #^hdma_cg_addr_src, #!hdma_cg_addr_src, #$80)
  79. ;screen mode
  80. lda #^hdma_mode
  81. ldx #!hdma_mode
  82. stx $2181
  83. sta $2183
  84. DMA0(#$00, #5, #^hdma_mode_src, #!hdma_mode_src, #$80)
  85. ;bg scroll
  86. lda #^hdma_scroll
  87. ldx #!hdma_scroll
  88. stx $2181
  89. sta $2183
  90. DMA0(#$00, #11, #^hdma_scroll_src, #!hdma_scroll_src, #$80);
  91. ;color math
  92. lda #^hdma_math
  93. ldx #!hdma_math
  94. stx $2181
  95. sta $2183
  96. DMA0(#$00, #19, #^hdma_math_src, #!hdma_math_src, #$80);
  97. ;copy infinite loop to WRAM
  98. lda #$80
  99. sta infloop
  100. lda #$fe
  101. sta infloop+1
  102. rts
  103. tests:
  104. sep #$20 : .as ;8-bit accumulator
  105. rep #$10 : .xl ;16-bit index
  106. lda #$03 ;mode 3, mode 5 via HDMA :D
  107. sta $2105
  108. lda #$58 ;Tilemap addr 0xB000
  109. ora #$02 ;SC size 32x64
  110. sta $2107 ;for BG1
  111. lda #$50 ;Tilemap addr 0xA000
  112. ora #$02 ;SC size 32x64
  113. sta $2108 ;for BG2
  114. lda #$40 ;chr base addr:
  115. sta $210b ;BG1=0x0000, BG2=0x8000
  116. lda #$03 ;enable BG1+BG2
  117. sta $212c ;BG Main
  118. sta $212d ;BG Sub
  119. jsr setup_224
  120. lda #$00
  121. sta $2130
  122. stz $2121
  123. lda #$0f
  124. sta $2100 ;screen on, full brightness
  125. lda #9
  126. sta bar_yl
  127. rts
  128. snes_init:
  129. sep #$20 : .as ;8-bit accumulator
  130. rep #$10 : .xl ;16-bit index
  131. lda #$01
  132. sta $420d ; FAAAAAST
  133. lda #$8f
  134. sta $2100 ;INIDISP: force blank
  135. stz $2101 ;
  136. stz $2102 ;
  137. stz $2103 ;
  138. stz $2104 ; (OAM Data?!)
  139. stz $2104 ; (OAM Data?!)
  140. stz $2105 ;
  141. stz $2106 ;
  142. stz $2107 ;
  143. stz $2108 ;
  144. stz $2109 ;
  145. stz $210a ;
  146. stz $210b ;
  147. stz $210c ;
  148. stz $210d ;
  149. stz $210d ;
  150. stz $210e ;
  151. stz $210e ;
  152. stz $210f ;
  153. stz $210f ;
  154. lda #$05
  155. sta $2110 ;
  156. stz $2110 ;
  157. stz $2111 ;
  158. stz $2111 ;
  159. stz $2112 ;
  160. stz $2112 ;
  161. stz $2113 ;
  162. stz $2113 ;
  163. stz $2114 ;
  164. stz $2114 ;
  165. lda #$80
  166. sta $2115 ;
  167. stz $2116 ;
  168. stz $2117 ;
  169. stz $2118 ;(VRAM Data?!)
  170. stz $2119 ;(VRAM Data?!)
  171. stz $211a ;
  172. stz $211b ;
  173. lda #$01
  174. sta $211b ;
  175. stz $211c ;
  176. stz $211c ;
  177. stz $211d ;
  178. stz $211d ;
  179. stz $211e ;
  180. sta $211e ;
  181. stz $211f ;
  182. stz $211f ;
  183. stz $2120 ;
  184. stz $2120 ;
  185. stz $2121 ;
  186. stz $2122 ; (CG Data?!)
  187. stz $2122 ; (CG Data?!)
  188. stz $2123 ;
  189. stz $2124 ;
  190. stz $2125 ;
  191. stz $2126 ;
  192. stz $2127 ;
  193. stz $2128 ;
  194. stz $2129 ;
  195. stz $212a ;
  196. stz $212b ;
  197. stz $212c ;
  198. stz $212d ;
  199. stz $212e ;
  200. lda #$30
  201. sta $2130 ;
  202. stz $2131 ;
  203. lda #$e0
  204. sta $2132 ;
  205. stz $2133 ;
  206. stz $4200 ;
  207. lda #$ff
  208. sta $4201 ;
  209. stz $4202 ;
  210. stz $4203 ;
  211. stz $4204 ;
  212. stz $4205 ;
  213. stz $4206 ;
  214. stz $4207 ;
  215. stz $4208 ;
  216. stz $4209 ;
  217. stz $420a ;
  218. stz $420b ;
  219. stz $420c ;
  220. ;clear WRAM lower page
  221. ; ldx #$0200
  222. ; stx $2181
  223. ; lda #$00
  224. ; sta $2183
  225. ; DMA0(#$08, #$FF00, #^zero, #!zero, #$80)
  226. ; ldx #$0000
  227. ; stx $2181
  228. ; lda #$00
  229. ; sta $2183
  230. ; DMA0(#$08, #$1e0, #^zero, #!zero, #$80)
  231. rts