;MSSPLAY.ASM -- Music Stream for SNES support library ;(C) 1999, 2000 Realtime Simulations and Roleplaying Games ;By BattleQueen and Grog ;Special thanks to ZSNES team for SPC debugger and Reset code ; ; See SPCPLAY.TXT for instructions on usage ; See MSS.TXT for details on the Music Stream for SNES file format ;MSSHalt -- Macro that sends MSS halt command to SPC700, causes reset MSSHalt .macro (Dummy) ;Assumes 8b mem lda #$01 sta $2140 lda $2143 inc A sta $2143 .endm ;MSSCallSong -- Macro that calls a song subroutine immediately ; Useful for sound effects MSSCallSong .macro (SongAddr) ;Assumes 16b index, 8b mem lda #$02 sta $2140 ldx #SongAddr stx $2141 lda $2143 inc A sta $2143 .endm ;MSSJumpToSong -- Macro that jumps to a song subroutine immediately ; Useful for starting a new song MSSJumpToSong .macro (SongAddr) ;Assumes 16b index, 8b mem lda #$03 sta $2140 ldx #SongAddr stx $2141 lda $2143 inc A sta $2143 .endm ;MSSSetSoundTable -- Set a sample directory table byte (four bytes per sample) ; First two bytes are Sample pointer, last two are for Loop MSSSetSoundTable .macro (TableIndex,TableByte) lda #$06 sta $2140 lda #TableIndex sta $2141 lda #TableByte sta $2142 lda $2143 inc A sta $2143 .endm ;MSSSetDSPRegister -- set a DSP register directly MSSSetDSPRegister .macro (DSPIndex,DSPByte) lda #$05 sta $2140 lda #DSPIndex sta $2141 lda #DSPByte sta $2142 lda $2143 inc A sta $2143 .endm ;MSSWait -- wait for last MSS command to finish MSSWait .macro (Dummy) inc A - cmp $2143 bne - .endm ;MSSLoadData -- Download sound sample or MSS data to SPC700 MSSLoadData .macro (SRCBANK,SRCOFF,DESTOFF,SIZE) lda #SRCBANK sta $02 ldx #SRCOFF stx $00 ldx #SIZE stx $04 ldy #DESTOFF JSR LoadMSSData - lda $2143 cmp #$DD bne - ;Wait for load to finish .endm ;InitMSSPlayer -- Download the MSS Player program to the SPC700 ;In: None ;Out: None ;Modifies: X,Y,A InitMSSPlayer: php rep #$30 sep #$20 .mem 8 .index 16 ldx #$0400 ;Target SPC address for program stx $2142 ldx #$0000 lda #$01 sta $2141 lda #$CC sta $2140 - cmp $2140 ;Wait for SPC to sync bne - SoundSendLoop: lda spcprog,X sta $2141 ;Set the address txa sta $2140 ;Set the data - cmp $2140 bne - ;Wait for SPC to sync inx cpx #spcend-spcprog ;Check for last data byte bne SoundSendLoop stz $2141 ;Mark end of data ldy #$0400 ;Set starting address of SPC code sty $2142 inx inx txa sta $2140 ;Tell SPC to begin executing its program plp rts ;LoadMSSData -- Download Sound Sample and/or Music data to the SPC700 ;In: $00:0002 -- Bank containing data ; $00:0000 -- Source offset into bank ; $00:0004 -- Size of data (up to 32768-5*256 bytes!) ; Y -- Target SPC address ;Modifies: X,Y,A, $00:0000 to $00:0002 ;Notes: Halts all sound output ; SPC RAM addresses from $0000 to $4FF are RESERVED! ; Once modified program/sound is loaded, you must use ; the MSS control command "Jump to SubSong" to begin music LoadMSSData: ; -- Assumes 8b mem, 16b index ;Send the MSS program the Reset command and wait for it to comply lda #$01 sta $2140 inc $2143 ldx #$BBAA - cpx $2140 bne - sty $2142 ;Store target address ldx $04 ;Get Size ldy #$0000 ;Clear offset counter lda #$01 sta $2141 lda #$CC ;Begin Transfer sta $2140 - cmp $2140 ;Wait for SPC to sync bne - SndDataLoop: lda [$00],Y ;Load next data byte sta $2141 ;Set the data tya ;Get address into A (lower 8-bits only) sta $2140 ;Set the address (note, only lower 8-bits) - cmp $2140 ; bne - ;Wait for SPC to sync iny ;Increment input offset dex ;decrement source size count bne SndDataLoop ;Loop while count != 0 stz $2141 ;Mark end of data ldx #$0400 ;Set starting address of MSS Program code stx $2142 iny iny tya sta $2140 ;Tell SPC to begin executing its program rts spcprog: .incbin "SPCPLAY.BIN" spcend: .dcb $FF