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.

256 lines
6.7 KiB

  1. ;------------------------------------------------------------------------
  2. ;- Standard SNES initialization routine, originally by Neviksti
  3. ;------------------------------------------------------------------------
  4. .MACRO InitSNES
  5. sei ;disable interrupts
  6. clc ;switch to native mode
  7. xce
  8. REP #$38 ; mem/A = 16 bit, X/Y = 16 bit
  9. ;decimal mode off
  10. LDX #$1FFF ;Setup the stack
  11. TXS ;Transfer Index X to Stack Pointer Register
  12. ;do the rest of the initialization in a routine
  13. JSL $008000
  14. SEP #$20 ; mem/A = 8 bit
  15. .ENDM
  16. ;----------------------------------------------------------------------------
  17. .BANK 0 SLOT 0
  18. .ORG 0
  19. .SECTION "InitializeSNESCode" FORCE
  20. InitializeSNES:
  21. PHK ;set Data Bank = Program Bank
  22. PLB
  23. LDA #$0000 ;set Direct Page = $0000
  24. TCD ;Transfer Accumulator to Direct Register
  25. LDX $1FFD ;we clear all the mem at one point ...
  26. STX $4372 ;so save the return address in a place that won't get overwritten
  27. LDX $1FFF
  28. STX $4374
  29. SEP #$20 ; mem/A = 8 bit
  30. REP #$10
  31. LDA #$8F
  32. STA $2100 ;turn screen off for now, set brightness to normal
  33. LDX #$2101
  34. _Loop00: ;regs $2101-$210C
  35. STZ $00,X ;set Sprite,Character,Tile sizes to lowest, and set addresses to $0000
  36. INX
  37. CPX #$210D
  38. BNE _Loop00
  39. _Loop01: ;regs $210D-$2114
  40. STZ $00,X ;Set all BG scroll values to $0000
  41. STZ $00,X
  42. INX
  43. CPX #$2115
  44. BNE _Loop01
  45. LDA #$80 ;reg $2115
  46. STA $2115 ; Initialize VRAM transfer mode to word-access, increment by 1
  47. STZ $2116 ;regs $2117-$2117
  48. STZ $2117 ;VRAM address = $0000
  49. ;reg $2118-$2119
  50. ;VRAM write register... don't need to initialize
  51. STZ $211A ;clear Mode7 setting
  52. LDX #$211B
  53. _Loop02: ;regs $211B-$2120
  54. STZ $00,X ;clear out the Mode7 matrix values
  55. STZ $00,X
  56. INX
  57. CPX #$2121
  58. BNE _Loop02
  59. ;reg $2121 - Color address, doesn't need initilaizing
  60. ;reg $2122 - Color data, is initialized later
  61. LDX #$2123
  62. _Loop03: ;regs $2123-$2133
  63. STZ $00,X ;turn off windows, main screens, sub screens, color addition,
  64. INX ;fixed color = $00, no super-impose (external synchronization),
  65. CPX #$2134 ;no interlaced mode, normal resolution
  66. BNE _Loop03
  67. ;regs $2134-$2136 - multiplication result, no initialization needed
  68. ;reg $2137 - software H/V latch, no initialization needed
  69. ;reg $2138 - Sprite data read, no initialization needed
  70. ;regs $2139-$213A - VRAM data read, no initialization needed
  71. ;reg $213B - Color RAM data read, no initialization needed
  72. ;regs $213C-$213D - H/V latched data read, no initialization needed
  73. STZ $213E ;reg $213E - might not be necesary, but selects PPU master/slave mode
  74. ;reg $213F - PPU status flag, no initialization needed
  75. ;reg $2140-$2143 - APU communication regs, no initialization required
  76. ;reg $2180 - read/write WRAM register, no initialization required
  77. ;reg $2181-$2183 - WRAM address, no initialization required
  78. ;reg $4016-$4017 - serial JoyPad read registers, no need to initialize
  79. STZ $4200 ;reg $4200 - disable timers, NMI,and auto-joyread
  80. LDA #$FF
  81. STA $4201 ;reg $4201 - programmable I/O write port, initalize to allow reading at in-port
  82. ;regs $4202-$4203 - multiplication registers, no initialization required
  83. ;regs $4204-$4206 - division registers, no initialization required
  84. ;regs $4207-$4208 - Horizontal-IRQ timer setting, since we disabled this, it is OK to not init
  85. ;regs $4209-$420A - Vertical-IRQ timer setting, since we disabled this, it is OK to not init
  86. STZ $420B ;reg $420B - turn off all general DMA channels
  87. STZ $420C ;reg $420C - turn off all H-MA channels
  88. STZ $420D ;reg $420D - ROM access time to slow (2.68Mhz)
  89. LDA $4210 ;reg $4210 - NMI status, reading resets
  90. ;reg $4211 - IRQ status, no need to initialize
  91. ;reg $4212 - H/V blank and JoyRead status, no need to initialize
  92. ;reg $4213 - programmable I/O inport, no need to initialize
  93. ;reg $4214-$4215 - divide results, no need to initialize
  94. ;reg $4216-$4217 - multiplication or remainder results, no need to initialize
  95. ;regs $4218-$421f - JoyPad read registers, no need to initialize
  96. ;regs $4300-$437F
  97. ;no need to intialize because DMA was disabled above
  98. ;also, we're not sure what all of the registers do, so it is better to leave them at
  99. ;their reset state value
  100. JSR ClearVRAM ;Reset VRAM
  101. JSR ClearPalette ;Reset colors
  102. ;**** clear Sprite tables ********
  103. STZ $2102 ;sprites initialized to be off the screen, palette 0, character 0
  104. STZ $2103
  105. LDX #$0080
  106. LDA #$F0
  107. _Loop08:
  108. STA $2104 ;set X = 240
  109. STA $2104 ;set Y = 240
  110. STZ $2104 ;set character = $00
  111. STZ $2104 ;set priority=0, no flips
  112. DEX
  113. BNE _Loop08
  114. LDX #$0020
  115. _Loop09:
  116. STZ $2104 ;set size bit=0, x MSB = 0
  117. DEX
  118. BNE _Loop09
  119. ;**** clear WRAM ********
  120. STZ $2181 ;set WRAM address to $000000
  121. STZ $2182
  122. STZ $2183
  123. LDX #$8008
  124. STX $4300 ;Set DMA mode to fixed source, BYTE to $2180
  125. LDX #wram_fill_byte
  126. STX $4302 ;Set source offset
  127. LDA #:wram_fill_byte
  128. STA $4304 ;Set source bank
  129. LDX #$0000
  130. STX $4305 ;Set transfer size to 64k bytes
  131. LDA #$01
  132. STA $420B ;Initiate transfer
  133. LDA #$01 ;now set the next 64k bytes
  134. STA $420B ;Initiate transfer
  135. PHK ;make sure Data Bank = Program Bank
  136. PLB
  137. CLI ;enable interrupts again
  138. LDX $4372 ;get our return address...
  139. STX $1FFD
  140. LDA $4374
  141. STA $1FFF
  142. RTL
  143. wram_fill_byte:
  144. .db $00
  145. ;----------------------------------------------------------------------------
  146. ; ClearVRAM -- Sets every byte of VRAM to zero
  147. ; In: None
  148. ; Out: None
  149. ; Modifies: flags
  150. ;----------------------------------------------------------------------------
  151. ClearVRAM:
  152. pha
  153. phx
  154. php
  155. REP #$30 ; mem/A = 8 bit, X/Y = 16 bit
  156. SEP #$20
  157. LDA #$80
  158. STA $2115 ;Set VRAM port to word access
  159. LDX #$1809
  160. STX $4300 ;Set DMA mode to fixed source, WORD to $2118/9
  161. LDX #$0000
  162. STX $2116 ;Set VRAM port address to $0000
  163. STX $0000 ;Set $00:0000 to $0000 (assumes scratchpad ram)
  164. STX $4302 ;Set source address to $xx:0000
  165. LDA #$00
  166. STA $4304 ;Set source bank to $00
  167. LDX #$FFFF
  168. STX $4305 ;Set transfer size to 64k-1 bytes
  169. LDA #$01
  170. STA $420B ;Initiate transfer
  171. STZ $2119 ;clear the last byte of the VRAM
  172. plp
  173. plx
  174. pla
  175. RTS
  176. ;----------------------------------------------------------------------------
  177. ; ClearPalette -- Reset all palette colors to zero
  178. ; In: None
  179. ; Out: None
  180. ; Modifies: flags
  181. ;----------------------------------------------------------------------------
  182. ClearPalette:
  183. PHX
  184. PHP
  185. REP #$30 ; mem/A = 8 bit, X/Y = 16 bit
  186. SEP #$20
  187. STZ $2121
  188. LDX #$0100
  189. ClearPaletteLoop:
  190. STZ $2122
  191. STZ $2122
  192. DEX
  193. BNE ClearPaletteLoop
  194. PLP
  195. PLX
  196. RTS
  197. .ENDS