Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; NVMX DIZC
- ; |||| ||||
- ; |||| |||+- Carry
- ; |||| ||+-- Zero
- ; |||| |+--- Interrupt Disable
- ; |||| +---- Decimal Mode
- ; |||+------ Index Register Size (0 = 16 bit, 1 = 8-bit)
- ; ||+------- Accumulator Size (0 = 16 bit, 1 = 8-bit)
- ; |+-------- Overflow
- ; +--------- Negative
- .p816 ; Enable SNES instruction set
- .include "registers.inc"
- .segment "ZEROPAGE"
- temp_addr: .res 2
- joypad_press: .res 2
- joypad_hold: .res 2
- joypad_prev: .res 2
- inidisp: .res 1
- obj_sel: .res 1
- bg_mode: .res 1
- mosaic: .res 1
- bg1_sc: .res 1
- bg2_sc: .res 1
- bg3_sc: .res 1
- bg4_sc: .res 1
- cg_wsel: .res 1
- cg_adsub: .res 1
- tm: .res 1
- ts: .res 1
- memsel: .res 1
- nmitimen: .res 1
- bg1_scroll_x: .res 2
- bg2_scroll_x: .res 2
- bg3_scroll_x: .res 2
- bg4_scroll_x: .res 2
- bg1_scroll_y: .res 2
- bg2_scroll_y: .res 2
- bg3_scroll_y: .res 2
- bg4_scroll_y: .res 2
- wh0: .res 1
- wh1: .res 1
- wh2: .res 1
- wh3: .res 1
- mdma_en: .res 1
- hdma_en: .res 1
- main_loop_done: .res 1
- .segment "RAM"
- .include "lorom128.inc"
- .segment "BANK0"
- ;;================================================================================================================================;;
- ;;--------------------------------------------------------------------------------------------------------------------------------;;
- ;;================================================================================================================================;;
- RESET:
- CLC ; Set native mode
- XCE
- SEI
- CLD
- SEP #$30 ; Set A/X/Y to 8 bit
- .a8
- .i8
- LDA #$80 ; Enable FBlank
- STA INIDISP
- STZ MEMSEL
- STZ NMITIMEN ; Disable interrupts and auto-joypad
- STZ MDMAEN ; Stop DMAs
- STZ HDMAEN
- LDX #$00
- INX
- MemClear:
- STZ WMADDL ; Set WRAM address for DMA
- STZ WMADDM
- STX WMADDH
- LDA #%00001000 ; Set DMA with fixed Source
- STA DMAP0
- LDA #$80 ; Set DMA destination to $2180
- STA BBAD0
- LDA #$18 ; Set DMA source to $00:8018
- STA A1T0L ; This points to $00 in 'LDX #$00'
- LDA #$80
- STA A1T0H
- STZ A1B0
- LDA #$FF ; Set DMA transfer to $FFFF bytes
- STA DAS0L
- STA DAS0H
- LDA #%00000001
- STA MDMAEN ; Start DMA transfer
- DEX ; Decrement X and loop to clear the second page
- BPL MemClear
- LDA #$00
- TCD ; Set Direct Page
- PHA
- PLB ; Pull Data Bank
- TAX
- DEX
- TXS ; Set Stack Pointer
- JSR RegisterSetup
- LoadGraphics:
- .i16 ; Set for compiled, REP #$10 is in subroutine above
- LDX #$C000
- STX VMADDL ; Set VRAM address for DMA to $C000
- LDA #%00000001 ; Set DMA mode to write to two registers
- STA DMAP0
- LDA #$18 ; Set DMA destination to $2118
- STA BBAD0
- STZ A1T0L ; Set DMA source to $01:0000
- STZ A1T0H
- LDA #$01
- STA A1B0
- LDA #$FF ; Set DMA transfer to $FFFF bytes
- STA DAS0L
- STA DAS0H
- LDA #%00000001
- STA MDMAEN ; Start DMA transfer
- LDA #$80
- STA CGADD
- SEP #$10
- .i8
- REP #$20
- .a16
- LDX #$03
- PHX
- PLB
- LDX #$00
- : LDA PaletteZangetsu,X
- STA CGDATA
- INX
- INX
- CMP #$20
- BNE :-
- LDA #$81 ; Enable NMI and auto-joypad
- STA nmitimen
- STA NMITIMEN
- SEP #$30
- .a8
- .i8
- MainLoop:
- LDX #$01
- STX main_loop_done
- NMIWait:
- LDX main_loop_done
- BNE NMIWait
- JMP MainLoop
- ;;================================================================================================================================;;
- ;;--------------------------------------------------------------------------------------------------------------------------------;;
- ;;================================================================================================================================;;
- RegisterSetup:
- REP #$10
- .i16
- LDX #$0000
- LDA #$80 ; Enable FBlank
- STA inidisp
- STA INIDISP
- LDA #$03 ; Object Size 8x8 and 16x16, OAM 1 at $C000, OAM 2 at $E000
- STA obj_sel
- STA OBSEL
- STX OAMADDL ; Reset OAM address (OAMADDL/H)
- LDA #$09 ; BG Mode 1 with BG3 priority
- STA bg_mode
- STA BGMODE
- STZ MOSAIC
- LDA #%00000011 ; 2x2 tilemap starting from $0000
- STA bg1_sc
- STA BG1SC
- LDA #%00010011 ; 2x2 tilemap starting from $2000
- STA bg2_sc
- STA BG2SC
- LDA #%01011001 ; 2x1 tilemap starting from $B000
- STA bg3_sc
- STA BG3SC
- STZ BG4SC
- LDA #$22 ; Set BG 1 & 2 CHR address to $4000
- STA BG12NBA
- LDA #$05 ; Set BG 3 CHR address to $A000
- STA BG34NBA
- STZ BG1HOFS ; Reset scroll positions
- STZ BG1HOFS
- STZ BG1VOFS
- STZ BG1VOFS
- STZ BG2HOFS
- STZ BG2HOFS
- STZ BG2VOFS
- STZ BG2VOFS
- STZ BG3HOFS
- STZ BG3HOFS
- STZ BG3VOFS
- STZ BG3VOFS
- STZ BG4HOFS
- STZ BG4HOFS
- STZ BG4VOFS
- STZ BG4VOFS
- STZ VMAIN ; Reset video port controls
- STX VMADDL ; Reset VRAM address (VMADDL/H)
- STZ M7SEL ; Reset Mode 7 settings
- LDA #$01
- STA M7A ; Set $0001 to Mode 7 A & B parameters
- STZ M7A
- STA M7B
- STZ M7B
- STZ M7C ; Set Mode 7 parameters C, D, X & Y to $0000
- STZ M7C
- STZ M7D
- STZ M7D
- STZ M7X
- STZ M7X
- STZ M7Y
- STZ M7Y
- STZ CGADD ; Reset CGRAM address
- STZ W12SEL ; Reset Window Mask settings
- STZ W34SEL
- STZ WOBJSEL
- STZ WH0
- STZ WH1
- STZ WH2
- STZ WH3
- STZ WBGLOG
- STZ WOBJLOG
- STZ TM ; Reset main and sub-screen settings
- STZ TS
- STZ TMW
- STZ TSW
- STZ CGWSEL
- STZ CGADSUB
- LDA #$E0 ; Set fixed color data to black
- STA COLDATA
- STZ SETINI ; Reset screen mode
- STZ WMADDL
- STZ WMADDM
- STZ WMADDH
- STZ HTIMEL ; Clear H/VBlank counters
- STZ HTIMEH
- STZ VTIMEL
- STZ VTIMEH
- RTS
- ;;================================================================================================================================;;
- ;;--------------------------------------------------------------------------------------------------------------------------------;;
- ;;================================================================================================================================;;
- NMI:
- PHA
- PHX
- PHY
- LDA main_loop_done
- BEQ SkipNMI
- REP #$10
- .i16
- : LDA HVBJOY
- AND #$01
- BEQ :-
- LDX JOY1L
- STX joypad_hold
- ; Add press and release
- STZ main_loop_done
- SkipNMI:
- PLY
- PLX
- PLA
- RTI
- ;;================================================================================================================================;;
- ;;--------------------------------------------------------------------------------------------------------------------------------;;
- ;;================================================================================================================================;;
- IRQ:
- PHA
- PHX
- PHY
- PLY
- PLX
- PLA
- RTI
- ;;================================================================================================================================;;
- ;;--------------------------------------------------------------------------------------------------------------------------------;;
- ;;================================================================================================================================;;
- ABORT:
- COPROCESSOR:
- BREAK:
- RTI
- ;;================================================================================================================================;;
- ;;--------------------------------------------------------------------------------------------------------------------------------;;
- ;;================================================================================================================================;;
- .segment "BANK1"
- .incbin "graphics0.chr"
- .incbin "graphics1.chr"
- .segment "BANK2"
- .incbin "graphics2.chr"
- .incbin "graphics3.chr"
- .segment "BANK3"
- PaletteZangetsu:
- .word $0000,$577F,$31DF,$39CE,$0014,$7F95,$7E4B,$0000,$7E39,$7810,$7F3A,$7FFF,$7DFE,$4C08,$59DF,$6F1F
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement