Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. ;
  2. ; Example VRC6a (mapper 24) template for asm6f
  3. ; Author: Jeremy Chadwick <jdc@koitsu.org>
  4. ;
  5.  
  6. ;
  7. ; NES header
  8. ;
  9. .db $4E,$45,$53,$1A ; NES+$1A identifer
  10. .db 4 ; PRG-ROM bank count
  11. .db 0 ; CHR-ROM bank count (using CHR-RAM)
  12. .db %10000001 ; Bits 7-4: Mapper number 24 (lower nibble)
  13. ; Bit 3: Not 4-screen
  14. ; Bit 2: No trainer
  15. ; Bit 1: No battery-backed PRG-RAM (SRAM)
  16. ; Bit 0: Vertical mirroring
  17. .db %00010000 ; Bits 7-4: Mapper number 24 (upper nibble)
  18. ; Bit 3: Unused
  19. ; Bit 2: Unused
  20. ; Bit 1: Unused
  21. ; Bit 0: Unused
  22. .db $00,$00,$00,$00 ; Unused
  23. .db $00,$00,$00,$00 ; Unused
  24.  
  25. ;
  26. ; PRG bank #0 -- swappable in/out of $C000-DFFF
  27. ;
  28. .base $C000
  29. ;
  30. ; put your code here
  31. ;
  32. .pad $E000
  33.  
  34. ;
  35. ; PRG bank #1 -- swappable in/out of $C000-DFFF
  36. ;
  37. .base $C000
  38. ;
  39. ; put your code here
  40. ;
  41. .pad $E000
  42.  
  43. ;
  44. ; PRG bank #2 -- swappable in/out of $C000-DFFF
  45. ;
  46. .base $C000
  47. ;
  48. ; put your code here
  49. ;
  50. .pad $E000
  51.  
  52. ;
  53. ; PRG bank #3 -- swappable in/out of $C000-DFFF
  54. ;
  55. .base $C000
  56.  
  57. ;
  58. ; Just fooling around here with code...
  59. ;
  60. MAIN:
  61. lda #$DE
  62. sta $00
  63. lda #$AD
  64. sta $01
  65. lda #$BE
  66. sta $02
  67. lda #$EF
  68. sta $03
  69. jmp OTHER
  70.  
  71. .pad $E000
  72.  
  73.  
  74. ;
  75. ; PRG bank #4 and #5 (16KB) -- we choose put this at $8000-BFFF
  76. ;
  77. .base $8000
  78.  
  79. ;
  80. ; Just an infinite loop to ensure that assembled/calculated addresses
  81. ; and the like work correctly.
  82. ;
  83. OTHER:
  84. lda #$aa
  85. ldx #$bb
  86. ldy #$cc
  87. jmp OTHER
  88.  
  89. .pad $C000
  90.  
  91.  
  92. ;
  93. ; PRG bank #6 -- swappable in/out of $C000-DFFF
  94. ;
  95. .base $C000
  96. ;
  97. ; put your code here
  98. ;
  99. .pad $E000
  100.  
  101.  
  102. ;
  103. ; PRG bank #7 -- fixed to $E000-FFFF
  104. ;
  105. .base $E000
  106.  
  107. RESET: ; Code taken from https://wiki.nesdev.com/w/index.php/Init_code
  108. sei ; ignore IRQs
  109. cld ; disable decimal mode
  110. ldx #$40
  111. stx $4017 ; disable APU frame IRQ
  112. ldx #$FF
  113. txs ; Set up stack
  114. inx ; now X = 0
  115. stx $2000 ; disable NMI
  116. stx $2001 ; disable rendering
  117. stx $4010 ; disable DMC IRQs
  118.  
  119. ;
  120. ; VRC6a mapper setup
  121. ;
  122. lda #%00101000 ; Bit 7: PRG-RAM disabled
  123. ; Bit 6: unused
  124. ; Bit 5: CIRAM connected to CHR A10
  125. ; Bit 4: Nametables come from CIRAM
  126. ; Bits 3-0: Vertical mirroring
  127. ; NOTE: I sure hope I got these right... a wonderfully confusing mapper
  128. sta $B003 ; Set VRC6a PPU banking style
  129. lda #(4 >> 1) ; Select PRG banks 4+5 (16KB). The bitshift acts effectively /2, which
  130. ; is needed since "internally" the mapper considers PRG banks 8KB.
  131. ; This also means for 16KB selection, the bank number needs to be evenly
  132. ; divisible by 2 (i.e. you couldn't pick PRG banks 5+6).
  133. sta $8000 ; Set 16KB PRG-ROM @ $8000-BFFF
  134. lda #3 ; Select PRG bank 3
  135. sta $C000 ; Set 8KB PRG-ROM @ $C000
  136.  
  137. ; If the user presses Reset during vblank, the PPU may reset
  138. ; with the vblank flag still true. This has about a 1 in 13
  139. ; chance of happening on NTSC or 2 in 9 on PAL. Clear the
  140. ; flag now so the @vblankwait1 loop sees an actual vblank.
  141. bit $2002
  142.  
  143. ; First of two waits for vertical blank to make sure that the
  144. ; PPU has stabilized
  145. @vblankwait1:
  146. bit $2002
  147. bpl @vblankwait1
  148.  
  149. ; We now have about 30,000 cycles to burn before the PPU stabilizes.
  150. ; One thing we can do with this time is put RAM in a known state.
  151. ; Here we fill it with $00, which matches what (say) a C compiler
  152. ; expects for BSS. Conveniently, X is still 0.
  153. txa
  154. @clrmem:
  155. sta $000,x
  156. sta $100,x
  157. sta $300,x
  158. sta $400,x
  159. sta $500,x
  160. sta $600,x
  161. sta $700,x ; Remove this if you're storing reset-persistent data
  162.  
  163. ; We skipped $200,x on purpose. Usually, RAM page 2 is used for the
  164. ; display list to be copied to OAM. OAM needs to be initialized to
  165. ; $EF-$FF, not 0, or you'll get a bunch of garbage sprites at (0, 0).
  166.  
  167. inx
  168. bne @clrmem
  169.  
  170. ; Other things you can do between vblank waits are set up audio
  171. ; or set up other mapper registers.
  172.  
  173. @vblankwait2:
  174. bit $2002
  175. bpl @vblankwait2
  176.  
  177. jmp MAIN
  178.  
  179. NMI:
  180. rti
  181.  
  182. IRQ:
  183. rti
  184.  
  185. .pad $FFFA
  186. ;
  187. ; 6502 vectors
  188. ;
  189. .dw NMI
  190. .dw RESET
  191. .dw IRQ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement