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.

208 lines
3.7 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. .INCLUDE "header.asm"
  2. .INCLUDE "InitSNES.asm"
  3. .INCLUDE "registers.asm"
  4. .BANK 0 SLOT 0
  5. .ORG 0
  6. .SECTION "MainCode"
  7. ; Memory layout:
  8. ; 00-0F: scratch space for functions.
  9. ; 10-13: controller state.
  10. ; 14-17: 32-bit counter of vblanks.
  11. ; 20-22: RGB color values to use for background color, from [0-31].
  12. Start:
  13. InitSNES ; Initialize SNES.
  14. ; Turn on the screen.
  15. ; Format: x000bbbb
  16. ; x: 0 = screen on, 1 = screen off, bbbb: Brightness ($0-$F)
  17. lda #%00001111
  18. sta INIDISP
  19. ; Enable NMI interrupt & joypad.
  20. ; n-vh---j n: NMI interrupt enable v: vertical counter enable
  21. ; h: horizontal counter enable j: joypad enable
  22. lda #$81
  23. sta NMITIMEN
  24. ; Store zeroes to the controller status registers.
  25. ; TODO(mcmillen): is this needed? I think the system will overwrite these
  26. ; automatically.
  27. stz JOY1H
  28. stz JOY1L
  29. ; Write something recognizable into our scratch space.
  30. jsr FillScratch
  31. MainLoop:
  32. wai ; Wait for interrupt.
  33. jmp MainLoop
  34. VBlankHandler:
  35. jsr VBlankCounter ; DEBUG
  36. jsr JoypadHandler
  37. jsr SetBackgroundColor
  38. ; jsr FillScratch ; DEBUG
  39. rti
  40. VBlankCounter:
  41. ; Increment a counter of how many VBlanks we've done.
  42. inc $14
  43. lda $14
  44. cmp #$00
  45. bne VBlankCounterDone
  46. inc $15
  47. lda $15
  48. cmp #$00
  49. bne VBlankCounterDone
  50. inc $16
  51. lda $16
  52. cmp #$00
  53. bne VBlankCounterDone
  54. inc $17
  55. VBlankCounterDone:
  56. rts
  57. JoypadHandler:
  58. ; $4218: Joypad #1 status [JOY1L]
  59. ; Format: AXLR0000
  60. ; $4219: Joypad #1 status [JOY1H]
  61. ; Format: BYsSudlr (s=select, S=start, udlr = joypad)
  62. jsr JoypadDebug ; DEBUG
  63. ; TODO(mcmillen): read joypad from local memory instead of registers?
  64. JoypadUp:
  65. lda JOY1H
  66. and #$08 ; Up
  67. cmp #$08
  68. bne JoypadDown ; Button not pressed.
  69. lda $20
  70. cmp #31
  71. beq JoypadDown ; Value saturated.
  72. inc $20
  73. JoypadDown:
  74. lda JOY1H
  75. and #$04
  76. cmp #$04
  77. bne JoypadLeft ; Button not pressed.
  78. lda $20
  79. cmp #0
  80. beq JoypadLeft ; Value saturated.
  81. dec $20
  82. JoypadLeft:
  83. lda JOY1H
  84. and #$02 ; Left
  85. cmp #$02
  86. bne JoypadRight ; Button not pressed.
  87. lda $22
  88. cmp #0
  89. beq JoypadRight ; Value saturated.
  90. dec $22
  91. JoypadRight:
  92. lda JOY1H
  93. and #$01
  94. cmp #$01 ; Right
  95. bne JoypadB ; Button not pressed.
  96. lda $22
  97. cmp #31
  98. beq JoypadB ; Value saturated.
  99. inc $22
  100. JoypadB:
  101. lda JOY1H
  102. and #$80 ; B
  103. cmp #$80
  104. bne JoypadY ; Button not pressed.
  105. lda $21
  106. cmp #31
  107. beq JoypadY ; Value saturated.
  108. inc $21
  109. JoypadY:
  110. lda JOY1H
  111. and #$40 ; Y
  112. cmp #$40
  113. bne JoypadDone ; Button not pressed.
  114. lda $21
  115. cmp #0
  116. beq JoypadDone ; Value saturated.
  117. dec $21
  118. JoypadDone:
  119. rts
  120. JoypadDebug:
  121. ; Load joypad registers into RAM for easier inspection.
  122. lda JOY1L
  123. sta $10
  124. lda JOY1H
  125. sta $11
  126. lda JOY2L
  127. sta $12
  128. lda JOY2H
  129. sta $13
  130. rts
  131. SetBackgroundColor:
  132. ; $20 $21 $22 are (R, G, B), each ranging from [0-31].
  133. ; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr]
  134. ; Compute and the low-order byte and store it in CGDATA.
  135. lda $21 ; Green.
  136. .rept 5
  137. asl
  138. .endr
  139. ora $20 ; Red.
  140. sta CGDATA
  141. ; Compute the high-order byte and store it in CGDATA.
  142. lda $22 ; Blue.
  143. .rept 2
  144. asl
  145. .endr
  146. sta $00
  147. lda $21 ; Green.
  148. .rept 3
  149. lsr
  150. .endr
  151. ora $00
  152. sta CGDATA
  153. ; Set the background color.
  154. ; $2121 is the color palette selection register [CGADD].
  155. ; Entry 0 corresponds to the SNES background color.
  156. stz CGADD
  157. rts
  158. FillScratch:
  159. lda #$42 ; B
  160. ldx #0
  161. FillScratchLoop:
  162. sta $00,X
  163. inx
  164. cpx #$10
  165. bne FillScratchLoop
  166. rts
  167. .ENDS