Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; Example VRC6a (mapper 24) template for asm6f
- ; Author: Jeremy Chadwick <jdc@koitsu.org>
- ;
- ;
- ; NES header
- ;
- .db $4E,$45,$53,$1A ; NES+$1A identifer
- .db 4 ; PRG-ROM bank count
- .db 0 ; CHR-ROM bank count (using CHR-RAM)
- .db %10000001 ; Bits 7-4: Mapper number 24 (lower nibble)
- ; Bit 3: Not 4-screen
- ; Bit 2: No trainer
- ; Bit 1: No battery-backed PRG-RAM (SRAM)
- ; Bit 0: Vertical mirroring
- .db %00010000 ; Bits 7-4: Mapper number 24 (upper nibble)
- ; Bit 3: Unused
- ; Bit 2: Unused
- ; Bit 1: Unused
- ; Bit 0: Unused
- .db $00,$00,$00,$00 ; Unused
- .db $00,$00,$00,$00 ; Unused
- ;
- ; PRG bank #0 -- swappable in/out of $C000-DFFF
- ;
- .base $C000
- ;
- ; put your code here
- ;
- .pad $E000
- ;
- ; PRG bank #1 -- swappable in/out of $C000-DFFF
- ;
- .base $C000
- ;
- ; put your code here
- ;
- .pad $E000
- ;
- ; PRG bank #2 -- swappable in/out of $C000-DFFF
- ;
- .base $C000
- ;
- ; put your code here
- ;
- .pad $E000
- ;
- ; PRG bank #3 -- swappable in/out of $C000-DFFF
- ;
- .base $C000
- ;
- ; Just fooling around here with code...
- ;
- MAIN:
- lda #$DE
- sta $00
- lda #$AD
- sta $01
- lda #$BE
- sta $02
- lda #$EF
- sta $03
- jmp OTHER
- .pad $E000
- ;
- ; PRG bank #4 and #5 (16KB) -- we choose put this at $8000-BFFF
- ;
- .base $8000
- ;
- ; Just an infinite loop to ensure that assembled/calculated addresses
- ; and the like work correctly.
- ;
- OTHER:
- lda #$aa
- ldx #$bb
- ldy #$cc
- jmp OTHER
- .pad $C000
- ;
- ; PRG bank #6 -- swappable in/out of $C000-DFFF
- ;
- .base $C000
- ;
- ; put your code here
- ;
- .pad $E000
- ;
- ; PRG bank #7 -- fixed to $E000-FFFF
- ;
- .base $E000
- RESET: ; Code taken from https://wiki.nesdev.com/w/index.php/Init_code
- sei ; ignore IRQs
- cld ; disable decimal mode
- ldx #$40
- stx $4017 ; disable APU frame IRQ
- ldx #$FF
- txs ; Set up stack
- inx ; now X = 0
- stx $2000 ; disable NMI
- stx $2001 ; disable rendering
- stx $4010 ; disable DMC IRQs
- ;
- ; VRC6a mapper setup
- ;
- lda #%00101000 ; Bit 7: PRG-RAM disabled
- ; Bit 6: unused
- ; Bit 5: CIRAM connected to CHR A10
- ; Bit 4: Nametables come from CIRAM
- ; Bits 3-0: Vertical mirroring
- ; NOTE: I sure hope I got these right... a wonderfully confusing mapper
- sta $B003 ; Set VRC6a PPU banking style
- lda #(4 >> 1) ; Select PRG banks 4+5 (16KB). The bitshift acts effectively /2, which
- ; is needed since "internally" the mapper considers PRG banks 8KB.
- ; This also means for 16KB selection, the bank number needs to be evenly
- ; divisible by 2 (i.e. you couldn't pick PRG banks 5+6).
- sta $8000 ; Set 16KB PRG-ROM @ $8000-BFFF
- lda #3 ; Select PRG bank 3
- sta $C000 ; Set 8KB PRG-ROM @ $C000
- ; If the user presses Reset during vblank, the PPU may reset
- ; with the vblank flag still true. This has about a 1 in 13
- ; chance of happening on NTSC or 2 in 9 on PAL. Clear the
- ; flag now so the @vblankwait1 loop sees an actual vblank.
- bit $2002
- ; First of two waits for vertical blank to make sure that the
- ; PPU has stabilized
- @vblankwait1:
- bit $2002
- bpl @vblankwait1
- ; We now have about 30,000 cycles to burn before the PPU stabilizes.
- ; One thing we can do with this time is put RAM in a known state.
- ; Here we fill it with $00, which matches what (say) a C compiler
- ; expects for BSS. Conveniently, X is still 0.
- txa
- @clrmem:
- sta $000,x
- sta $100,x
- sta $300,x
- sta $400,x
- sta $500,x
- sta $600,x
- sta $700,x ; Remove this if you're storing reset-persistent data
- ; We skipped $200,x on purpose. Usually, RAM page 2 is used for the
- ; display list to be copied to OAM. OAM needs to be initialized to
- ; $EF-$FF, not 0, or you'll get a bunch of garbage sprites at (0, 0).
- inx
- bne @clrmem
- ; Other things you can do between vblank waits are set up audio
- ; or set up other mapper registers.
- @vblankwait2:
- bit $2002
- bpl @vblankwait2
- jmp MAIN
- NMI:
- rti
- IRQ:
- rti
- .pad $FFFA
- ;
- ; 6502 vectors
- ;
- .dw NMI
- .dw RESET
- .dw IRQ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement