Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;=============================
- ;DEFINES
- ;=============================
- PPUCTRL = $2000
- PPUMASK = $2001
- PPUSTATUS = $2002
- OAMADDR = $2003
- OAMDATA = $2004
- PPUSCROLL = $2005
- PPUADDR = $2006
- PPUDATA = $2007
- OAMDMA = $4014
- ;=============================
- ;ZP RESERVATIONS
- ;=============================
- .segment "ZEROPAGE"
- ptr: .res 2 ;general purp pointer
- cbank: .res 1 ;keeps current bank in memory so NMI can restore it.
- ;=============================
- ;ROM START
- ;=============================
- .segment "HEADER"
- .byte "NES", $1A ;magic number
- .byte 8 ;8 banks, range 0-7
- .byte 0 ;CHR RAM instead of ROM
- .byte $20, $08 ;Mapper 2 - horz mirroring
- .byte $00 ;
- .byte $00 ;
- .byte $00 ;PRG RAM: no.
- .byte $07 ;8kB CHR RAM
- .byte $00 ;NTSC
- .byte $00 ;
- ;=============================
- ;ROM ADDR $8000
- ;=============================
- .segment "BANK0_TITLE"
- ;=============================
- ;ROM ADDR $C000
- ;=============================
- .segment "BANKTABLE"
- banktable: ;used for bus conflict avoidance. Bank $07 is fixed.
- .byte $00, $01, $02, $03, $04, $05, $06
- .segment "CODE_MAIN" ;all program code in fixed bank goes here.
- reset:
- ;makeshift without proper initialization
- ldy #0
- sty PPUCTRL
- sty PPUMASK
- jsr bankswitch ;expects a 0 at y for bank 0.
- jsr w_vblank
- ;set up sprite pattern
- lda #>title_spr
- ldy #<title_spr
- sta ptr+1
- sty ptr+0
- ldy #0
- lda #$00 ;0 is table 0, $10 is table 1
- jsr set_ppuaddr_ay
- ldx #16 ; + 16 pages' worth for spr chr.
- jsr st_ppudata_y_x_ptr
- ;set up background
- lda #>title_bg
- ldy #<title_bg
- sta ptr+1
- sty ptr+0
- ldy #0
- lda #$10 ;0 is table 0, $10 is table 1
- jsr set_ppuaddr_ay
- ldx #20 ; + 20 pages' worth - 16 for bg chr and 4 for nt
- jsr st_ppudata_y_x_ptr
- Load_palette:
- ;should be made a subroutine
- .scope
- lda PPUSTATUS
- lda #$3F
- sta PPUADDR
- lda #0
- sta PPUADDR
- ldx #0
- lda title_pal ;QUESTION: why do i have to load title_pal here to make colours load correctly?
- loop:
- lda title_pal, x
- sta PPUDATA
- inx
- cpx #32
- bne loop ; iterate
- .endscope
- ldx #0
- curtain_up:
- ;enable viewing. NMI is currently disabled.
- stx PPUSCROLL
- stx PPUSCROLL
- lda #%00010000
- sta PPUCTRL
- lda #%00011110
- sta PPUMASK
- clc ;set a known condition
- loop_forever:
- bcc loop_forever
- ;=============================
- ;SUBROUTINES
- ;=============================
- bankswitch:
- sty cbank ; save the current bank in RAM so the NMI handler can restore it
- lda banktable, y ; |
- sta banktable, y ; |<-- read and write to switch bank.
- rts
- w_vblank:
- .scope
- bit PPUSTATUS ;spinlock starts here
- spinlock:
- bit PPUSTATUS
- bpl spinlock
- rts
- .endscope
- set_ppuaddr_ay:
- sta PPUADDR
- sty PPUADDR
- rts
- st_ppudata_y_x_ptr:
- .scope
- loop:
- lda (ptr), y
- sta PPUDATA
- iny
- bne loop ; done a page yet? (y reg)
- inc ptr+1
- dex
- bne loop ; done all pages yet? (x reg)
- rts
- .endscope
- ;=============================
- ;INTERRUPTS
- ;=============================
- nmi:
- pha
- txa
- pha
- tya
- pha
- ;Place new stuff here and reenable NMI
- pla
- tay
- pla
- tax
- pla
- rti
- .segment "RODATA"
- ;place data here that should always be available regardless bank.
- ;QUESTION: Why does nametable etc break when i move this to the bank0 segment at line 41?
- title_spr: .incbin "dd_sprite.chr" ;4k
- title_bg: .incbin "dd.chr" ;4k
- title_nam: .incbin "dd.nam" ;1k
- title_pal:
- .incbin "dd.pal"
- .incbin "dd.pal"
- .segment "VECTORS"
- .word nmi
- .word reset
- .word reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement