main.asm 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. .MEMORYMAP
  2. DEFAULTSLOT 0
  3. SLOTSIZE $10000
  4. SLOT 0 $0000
  5. .ENDME
  6. .ROMBANKSIZE $10000 ; Every ROM bank is 64 KBytes in size, also necessary.
  7. .HIROM
  8. .ROMBANKS 4
  9. .DEFINE HEADER_OFF $8000
  10. .COMPUTESNESCHECKSUM
  11. .EMPTYFILL $ff
  12. .include "routines/variables.asm"
  13. .include "routines/defines.asm"
  14. ;***********************************************************************************
  15. ; setup header
  16. ;***********************************************************************************
  17. .define BaseAdress $c00000
  18. ;includes with superfree sections go here:
  19. .include "routines/miscdata.asm"
  20. .include "routines/bgmodes.asm"
  21. ; .include "routines/battlefiles.asm"
  22. ; .include "routines/battlezscrolllists.asm"
  23. ; .include "routines/battlezscrolllut.asm"
  24. ; .include "routines/introscene3scrolltable.asm"
  25. .include "routines/oamvectoranglelut.asm"
  26. .include "routines/oamobjects.asm"
  27. .include "routines/oamanimationlists.asm"
  28. ; .include "routines/hdmatables.asm"
  29. .include "routines/menufiles.asm"
  30. .include "routines/textstrings.asm"
  31. .include "routines/spritedata.asm"
  32. .include "routines/songs.asm"
  33. .include "routines/samplepacks.asm"
  34. .include "routines/backgroundfiles.asm"
  35. ; .include "routines/videoframes.asm"
  36. ;includes with fixed sections go here:
  37. .include "routines/audiostreams.asm"
  38. ; .include "routines/levelfiles.asm"
  39. .BANK 0 SLOT 0 ; The SLOT 0 may be ommitted, as SLOT 0 is the DEFAULTSLOT
  40. ; === Cartridge Header - part 1 - =====================
  41. .ORG $7FC0 + HEADER_OFF
  42. .DB "OPTIXX TESTROM " ; Title (can't be more than 21 bytes, and should probably be a full 21 bytes)
  43. ; "123456789012345678901"
  44. .ORG $7FD5 + HEADER_OFF
  45. .DB $31 ; Memory Mode ( $20 = Slow LoRom, $21 = Slow HiRom )
  46. .BANK 0 SLOT 0
  47. ; === Cartridge Header - part 2 - =====================
  48. .ORG $7FD6 + HEADER_OFF
  49. .DB $00 ; Contents ( $00 = ROM only, $01 = ROM and RAM, $02 = ROM and Save RAM)
  50. .DB $08 ; ROM Size ( $08 = 2 Mbit, $09 = 4 Mbit, $0A = 8Mbit, $0B = 16Mbit c=32, d=64... etc )
  51. .DB $00 ; SRAM Size ( $00 = 0 bits, $01 = 16 kbits, $02 = 32 kbits, $03 = 64 kbits )
  52. .DB $01 ; Country ( $01 = USA )
  53. .DB $33 ; Licensee Code
  54. .DB $01 ; Version
  55. .dw $0 ;checksum
  56. .dw $ffff ;checksum xor. this must be filled out here, else wla dx thinks its free space, places something there and overwrites it with the checksum later.
  57. .BANK 0 SLOT 0
  58. ; === Interrupt Vector Table ====================
  59. .ORG $7FE4 + HEADER_OFF ; === Native Mode ===
  60. .DW EmptyHandler ; COP
  61. .DW EmptyHandler ; BRK
  62. .DW EmptyHandler ; ABORT
  63. .DW NmiHookUp ; NMI
  64. .DW $0000 ; (Unused)
  65. .DW IrqHookUp ; IRQ
  66. .ORG $7FF4 + HEADER_OFF ; === Emulation Mode ===
  67. .DW EmptyHandler ; COP
  68. .DW $0000 ; (Unused)
  69. .DW EmptyHandler ; ABORT
  70. .DW EmptyHandler ; NMI
  71. .DW Boot ; RESET
  72. .DW EmptyHandler ; IRQ/BRK
  73. ; ============================================
  74. .bank 0 slot 0
  75. .org $ffa0
  76. EmptyHandler:
  77. rti
  78. Boot:
  79. SEI
  80. CLC
  81. XCE
  82. PHK
  83. PLB
  84. REP #$30
  85. SEP #$20
  86. STZ $4200 ;reg $4200 - disable timers, NMI,and auto-joyread
  87. lda #%00000001
  88. sta $420d ;set memory mode to fastrom
  89. jml (HiromStart+BaseAdress) ;lorom
  90. NmiHookUp:
  91. rti
  92. IrqHookUp:
  93. jml (IrqLoader+BaseAdress)
  94. .bank 0 slot 0
  95. .org $0
  96. .Section "Main Code"
  97. ;functions to include go here:
  98. .include "routines/printstring.asm"
  99. .include "routines/menusystem.asm"
  100. .include "routines/gfxvrammisc.asm"
  101. .include "routines/vblanknmi.asm"
  102. ; .include "routines/levelloader.asm"
  103. ; .include "routines/bgscrolling.asm"
  104. .include "routines/dmafifo.asm"
  105. .include "routines/irq.asm"
  106. .include "routines/oammanager.asm"
  107. .include "routines/oamsubroutines.asm"
  108. ; .include "routines/collisiondetection.asm"
  109. .include "routines/randomnumbergen.asm"
  110. ; .include "routines/hdmahandler.asm"
  111. ; .include "routines/hdmasubroutines.asm"
  112. .include "routines/spcinterface.asm"
  113. .include "routines/menusubroutines.asm"
  114. ; .include "routines/videoplayer.asm"
  115. .include "routines/memoryclear.asm"
  116. .include "routines/eventroutines.asm"
  117. .include "routines/joypadread.asm"
  118. HiromStart:
  119. sep #$20
  120. LDA #$80
  121. STA $2100 ;turn screen off for now, zero brightness
  122. rep #$31
  123. lda.w #$0000
  124. tcd
  125. lda.w #$01ff
  126. tcs
  127. sep #$20
  128. lda.b #0 ;clear word: $0000
  129. ldy.w #$1f0
  130. ldx.w #0
  131. jsr ClearWRAM
  132. lda.b #0 ;clear word: $0000
  133. ldy.w #$6000
  134. ldx.w #$200
  135. jsr ClearWRAM
  136. LDX #$2101
  137. MemClearLoop1: ;regs $2101-$210C
  138. STZ $00,X ;set Sprite,Character,Tile sizes to lowest, and set addresses to $0000
  139. INX
  140. CPX #$210D
  141. BNE MemClearLoop1
  142. MemClearLoop2: ;regs $210D-$2114
  143. STZ $00,X ;Set all BG scroll values to $0000
  144. STZ $00,X
  145. INX
  146. CPX #$2115
  147. BNE MemClearLoop2
  148. LDA #$80 ;reg $2115
  149. STA $2115 ; Initialize VRAM transfer mode to word-access, increment by 1
  150. STZ $2116 ;regs $2117-$2117
  151. STZ $2117 ;VRAM address = $0000
  152. STZ $211A ;clear Mode7 setting
  153. LDX #$211B
  154. MemClearLoop3: ;regs $211B-$2120
  155. STZ $00,X ;clear out the Mode7 matrix values
  156. STZ $00,X
  157. INX
  158. CPX #$2121
  159. BNE MemClearLoop3
  160. LDX #$2123
  161. MemClearLoop4: ;regs $2123-$2133
  162. STZ $00,X ;turn off windows, main screens, sub screens, color addition,
  163. INX ;fixed color = $00, no super-impose (external synchronization),
  164. CPX #$2134 ;no interlaced mode, normal resolution
  165. BNE MemClearLoop4
  166. LDA #$FF
  167. STA $4201 ;reg $4201 - programmable I/O write port, initalize to allow reading at in-port
  168. nop
  169. nop
  170. LDA $4210 ;reg $4210 - NMI status, reading resets
  171. lda $4211 ;irq status reset
  172. ;clear all graphics buffers:
  173. jsr ClearPalette ;Reset colors
  174. jsr ClearPaletteBuffer
  175. jsr ClearBg1TilemapBuffer
  176. jsr ClearBg2TilemapBuffer
  177. jsr InitDmaFifo
  178. jsr InitOam
  179. jsr ClearColObjList
  180. jsr ClearZBuffer
  181. ;init variables:
  182. rep #$31
  183. lda.w #$1234 ;seed RNG
  184. sta.b R1
  185. lda.w #$55aa
  186. sta.b R2
  187. sep #$20
  188. lda #%00000001 ;enable screen, auto joypad
  189. sta.w InterruptEnableFlags
  190. sta.w $4200
  191. lda.w SetIni ;set display mode
  192. sta.w $2133 ;dont set this during nmi cause if the overscan flag is changed mid-nmi, it might result in screw ups with the nmi timing
  193. cli
  194. jsr ROMToWRAM
  195. jml (go+$7f0000)
  196. go:
  197. jsr EnableScreen
  198. jsr SpcPlaySong
  199. /*
  200. ;main loop starts here:
  201. CheckNextFrame:
  202. ldx.w FrameCounterLo ;load current frame counter
  203. cpx.w LastFrameLo ;load last frame processed
  204. beq CheckNextFrame ;check until one frame advances
  205. stx.w LastFrameLo
  206. */
  207. ;main loop starts here:
  208. CheckNextFrame:
  209. lda.w $4210 ;wait until out of nmi
  210. bmi CheckNextFrame
  211. CheckNextNMI:
  212. lda.w $4210 ;wait until in nmi
  213. bpl CheckNextNMI
  214. jsr NMI
  215. lda CurrentEvent ;load number of currently active scene
  216. asl ;multiply number by 2
  217. rep #$31 ;set accu to 16bit
  218. and.w #$00ff ;only use low byte
  219. tax ;transfer to x
  220. sep #$20 ;reset accu to 8bit
  221. lda.w SetIni ;set display mode
  222. sta.l $2133 ;dont set this during nmi cause if the overscan flag is changed mid-nmi, it might result in screw ups with the nmi timing
  223. php
  224. jsr (EventPtTable,x) ;and jump to the location found at pointertable where x is the pointernumber
  225. plp
  226. lda.b #$80
  227. sta.l $4201
  228. nop
  229. nop
  230. nop
  231. nop
  232. lda.l $2137
  233. lda.l $213f ;reset $213d to low byte
  234. lda.l $213d ;get current scanline
  235. sta.w CpuUsageScanline
  236. bra CheckNextFrame
  237. .ends