Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;== Include MemoryMap, HeaderInfo, and interrupt Vector table ==
- .INCLUDE "header.inc"
- ;== Include Library Routines ==
- .INCLUDE "InitSNES.asm"
- .INCLUDE "LoadGraphics.asm"
- ;RAM Usage:
- ; $0000 - BG1 (Map) Horizontal Scroll
- ; $0001 - BG1 (Map) Vertical Scroll
- ; $0002 - BG2 (Checkerboard) Horizontal Scroll
- ; $0003 - BG2 (Checkerboard) Vertical Scroll
- ; $0004 - Noise On Value
- ;==========================================
- ; Main Code
- ;==========================================
- .BANK 0 SLOT 0
- .ORG 0
- .SECTION "MainCode"
- Main:
- InitializeSNES ;Initialize the SNES
- rep #$10 ;Set X/Y to 16-bit
- sep #$20 ;Set A to 8-bit
- jsl UploadAndExecuteSoundEngine
- LoadPalette BGPalette, 0, 12 ;Load the background palette
- LoadPalette BGPalette, 8*16, 12 ;Load the background palette
- LoadBlockToVRAM TileData, $0000, TileDataEnd-TileData ;Load the background tiles
- LoadBlockToVRAM LevelData, $0800, $0800 ;Load the map to VRAM
- LoadBlockToVRAM CheckerData, $0C00, $0800 ;Load the checkerboard to VRAM (A Routine to generate the checkerboard will eventually be used)
- jsl PlaceHud ;Place the text on BG3
- jsr SetupVideo ;Setup video
- lda #$81
- sta $4200 ;Enable NMI and Joypad Auto-Read
- lda #$0F
- sta $2100 ; Turn on screen, full Brightness
- jsr MosaicEffect ; Do the mosaic effect
- lda #$00
- sta $0004
- sta $0005
- Infinity:
- sep #$20
- lda $4219
- and #$08
- bne @SkipUp
- lda $0001
- inc a
- sta $0001
- lda $0003
- dec a
- sta $0003
- @SkipUp:
- lda $4219
- and #$04
- bne @SkipDown
- lda $0001
- dec a
- sta $0001
- lda $0003
- inc a
- sta $0003
- @SkipDown:
- lda $4219
- and #$02
- bne @SkipLeft
- lda $0000
- inc a
- sta $0000
- lda $0002
- dec a
- sta $0002
- @SkipLeft:
- lda $4219
- and #$01
- bne @SkipRight
- lda $0000
- dec a
- sta $0000
- lda $0002
- inc a
- sta $0002
- @SkipRight:
- lda #$00
- sta $2141
- lda $4218
- and #$80
- beq @SkipA
- lda #$01
- sta $2141
- @SkipA:
- lda $0004
- inc a
- sta $0004
- sta $2140
- @WaitEcho:
- lda $2140
- cmp $0004
- bne @WaitEcho
- rep #$20
- wai ;Wait for interrupt
- jmp Infinity ;Jump to Infinity
- ;============================================================================
- VBlank:
- rep #$30 ; A/mem=16 bits, X/Y=16 bits (to push all 16 bits)
- phb
- pha
- phx
- phy
- phd
- sep #$20 ;Set A to 8-bit
- rep #$10 ;Set X/Y to 16-bit
- lda $4210 ; Clear NMI flag
- ;Sprite Code Start
- ldx #$0000
- stx $2102
- lda $0000
- sta $2104
- lda $0001
- sta $2104
- lda #$31
- sta $2104
- lda #$30
- sta $2104
- lda #$20
- sta $2104
- lda #$30
- sta $2104
- lda $0000
- sta $2104
- lda #$30
- sta $2104
- ldx #$0100
- stx $2102
- lda #$0A
- sta $2104
- ;Sprite Code End
- ldx #$0000
- lda $0000 ;Load $0002 into A
- sta $210D ;Store A into the low byte of $210D (BG1HOFS)
- stx $210D ;Store X into the high byte of $210D
- lda $0001
- sta $210E ;Store A into the low byte of $210E (BG1VOFS)
- stx $210E ;Store X into the high byte of $210E
- lda $0002
- sta $210F
- stx $210F
- lda $0003
- sta $2110
- stx $2110
- rep #$20 ;Set A to 16-bit
- ;sep #$10
- pld
- ply
- plx
- pla
- plb
- sep #$30
- rti
- ;============================================================================
- MosaicEffect:
- lda #$FF
- sta $2106
- Loop:
- sbc #$10
- sta $2106
- wai
- wai
- wai
- wai
- wai
- wai
- wai
- wai
- cmp #$0F
- bne Loop
- rts
- PlaceHud:
- rep #$10
- ldx #$1000
- ldy #$0000
- @PlaceHudLoop:
- stx $2116
- lda Text, y
- cmp #$FF
- beq @DonePlacingHud
- sta $2118
- lda #$20
- sta $2119
- inx
- iny
- jmp @PlaceHudLoop
- @DonePlacingHud:
- rtl
- Text: .db "USE D-PAD TO SCROLL HOLD A FOR NOISE", $FF
- UploadAndExecuteSoundEngine:
- sei ;Disable interrupts
- @WaitReady1:
- lda $2140
- cmp #$AA
- bne @WaitReady1
- @WaitReady2:
- lda $2141
- cmp #$BB
- bne @WaitReady2 ;"Is the SPC700 ready?"
- lda #$01
- sta $2141
- lda #$00
- sta $2142
- lda #$05
- sta $2143
- lda #$CC
- sta $2140 ;Send the transfer begin bytes
- @WaitEcho1:
- lda $2140
- cmp #$CC
- bne @WaitEcho1 ;Wait for PORT0 to echo
- ldx SoundEngineEnd-SoundEngine
- ldy #$0000
- @TransferFirst:
- lda SoundEngine, y
- sta $2141 ;Write the first byte to PORT1
- lda #$00
- sta $2140 ;Write 0 to PORT0
- @WaitEcho2:
- lda $2140
- cmp #$00
- bne @WaitEcho2 ;Wait for PORT0 to echo
- dex
- iny
- @TransferRest:
- lda SoundEngine, y
- sta $2141 ;Write the next byte to PORT1
- lda $2140
- inc a
- sta $2140 ;Increase the byte in PORT0 and send it back
- sta $0000
- @WaitEcho3:
- lda $2140
- cmp $0000
- bne @WaitEcho3
- dex
- iny
- txa
- cmp #$00
- bne @TransferRest
- lda #$00
- sta $2141 ;0 in PORT1
- lda #$00
- sta $2142
- lda #$05
- sta $2143 ;Execute address in PORT2 and PORT3
- lda $2140
- clc
- adc #$02
- sta $2140 ;Increase PORT0 by 2 and store it in PORT0
- stz $0000
- lda #$00
- ldx #$0000
- ldy #$0000
- cli ;Enable interrupts
- rtl
- SoundEngine: .incbin "soundEngine.bin"
- SoundEngineEnd:
- ;============================================================================
- ; SetupVideo -- Sets up the video mode and tile-related registers
- ;----------------------------------------------------------------------------
- ; In: None
- ;----------------------------------------------------------------------------
- ; Out: None
- ;----------------------------------------------------------------------------
- SetupVideo:
- lda #$09
- sta $2105 ; Set Video mode 1 and BG3 priority bit
- lda #$08
- sta $2107 ; Set BG1's Tile Map offset to $0800 (Word address)
- lda #$0C
- sta $2108 ; Set BG2's Tile Map offset to $0C00
- lda #$10
- sta $2109 ; Set BG3's Tile Map offset to $1000
- lda #$17 ; Enable BG1, BG2, BG3, and OBJ
- sta $212C
- rts
- .ENDS
- ;============================================================================
- .BANK 1 SLOT 0
- .ORG 0
- .SECTION "CharacterData"
- TileData:
- .incbin "tiles.chr"
- TileDataEnd:
- BGPalette:
- ; gggrrrrr ?bbbbbgg
- .db %00000000, %00000000
- .db %00010000, %01000010
- .db %00001000, %00100001
- .db %11111111, %01111111
- .db %00000000, %00000000
- .db %11111111, %01111111
- .db %00000000, %00000000
- .db %00011111, %00000000
- .db %00000000, %00000000
- .db %11010110, %01111110
- .db %00010000, %01111110
- .db %00001000, %01111101
- .ENDS
- .SECTION "MapData"
- LevelData: .incbin "level1.bin"
- CheckerData: .incbin "checker.bin"
- .ENDS
- ;.SECTION "SoundEngine"
- ;SoundEngine: .incbin "soundEngine.bin"
- ;SoundEngineEnd:
- ;.ENDS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement