Skip to content

Commit

Permalink
feat: initial commit for spcPauseMusic and spcResumeMusic function
Browse files Browse the repository at this point in the history
  • Loading branch information
alekmaul committed Feb 1, 2025
1 parent c356bd0 commit 8e818a4
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 0 deletions.
32 changes: 32 additions & 0 deletions snes-examples/audio/music2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ifeq ($(strip $(PVSNESLIB_HOME)),)
$(error "Please create an environment variable PVSNESLIB_HOME by following this guide: https://github.com/alekmaul/pvsneslib/wiki/Installation")
endif

# BEFORE including snes_rules :
# list in AUDIOFILES all your .it files in the right order. It will build to generate soundbank file
AUDIOFILES := res/pollen8.it
# then define the path to generate soundbank data. The name can be different but do not forget to update your include in .c file !
export SOUNDBANK := res/soundbank

include ${PVSNESLIB_HOME}/devkitsnes/snes_rules

.PHONY: bitmaps all

#---------------------------------------------------------------------------------
# ROMNAME is used in snes_rules file
export ROMNAME := music2

# to build musics, define SMCONVFLAGS with parameters you want
SMCONVFLAGS := -s -o $(SOUNDBANK) -V -b 5
musics: $(SOUNDBANK).obj

all: musics bitmaps $(ROMNAME).sfc

clean: cleanBuildRes cleanRom cleanGfx cleanAudio

#---------------------------------------------------------------------------------
pvsneslibfont.pic: pvsneslibfont.bmp
@echo convert font with no tile reduction ... $(notdir $@)
$(GFXCONV) -s 8 -o 2 -u 16 -p -e 1 -t bmp -i $<

bitmaps : pvsneslibfont.pic
13 changes: 13 additions & 0 deletions snes-examples/audio/music2/data.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.include "hdr.asm"

.section ".rodata1" superfree

snesfont:
.incbin "pvsneslibfont.pic"

snespal:
.incbin "pvsneslibfont.pal"

.ends


46 changes: 46 additions & 0 deletions snes-examples/audio/music2/hdr.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
;==LoRom== ; We'll get to HiRom some other time.

.MEMORYMAP ; Begin describing the system architecture.
SLOTSIZE $8000 ; The slot is $8000 bytes in size. More details on slots later.
DEFAULTSLOT 0 ; There's only 1 slot in SNES, there are more in other consoles.
SLOT 0 $8000 ; Defines Slot 0's starting address.
SLOT 1 $0 $2000
SLOT 2 $2000 $E000
SLOT 3 $0 $10000
.ENDME ; End MemoryMap definition

.ROMBANKSIZE $8000 ; Every ROM bank is 32 KBytes in size
.ROMBANKS 8 ; 2 Mbits - Tell WLA we want to use 8 ROM Banks

.SNESHEADER
ID "SNES" ; 1-4 letter string, just leave it as "SNES"

NAME "LIBSNES MUSIC DEMO " ; Program Title - can't be over 21 bytes,
; "123456789012345678901" ; use spaces for unused bytes of the name.

SLOWROM
LOROM

CARTRIDGETYPE $00 ; $00 = ROM only $02 = ROM+SRAM, see WLA documentation for others
ROMSIZE $08 ; $08 = 2 Mbits, see WLA doc for more..
SRAMSIZE $00 ; $00 = No Sram, $01 = 16 kbits, see WLA doc for more..
COUNTRY $01 ; $01 = U.S. $00 = Japan, that's all I know
LICENSEECODE $00 ; Just use $00
VERSION $00 ; $00 = 1.00, $01 = 1.01, etc.
.ENDSNES

.SNESNATIVEVECTOR ; Define Native Mode interrupt vector table
COP EmptyHandler
BRK EmptyHandler
ABORT EmptyHandler
NMI VBlank
IRQ EmptyHandler
.ENDNATIVEVECTOR

.SNESEMUVECTOR ; Define Emulation Mode interrupt vector table
COP EmptyHandler
ABORT EmptyHandler
NMI EmptyHandler
RESET tcc__start ; where execution starts
IRQBRK EmptyHandler
.ENDEMUVECTOR
93 changes: 93 additions & 0 deletions snes-examples/audio/music2/music2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*---------------------------------------------------------------------------------
Simple music demo with pause / resume function
-- alekmaul
---------------------------------------------------------------------------------*/
#include <snes.h>

#include "res/soundbank.h"

extern char snesfont, snespal;
extern char SOUNDBANK__;

unsigned short bgcolor = 0;

u8 keyapressed = 0,keybpressed = 0;

//---------------------------------------------------------------------------------
int main(void)
{
// Initialize sound engine (take some time)
spcBoot();

// Initialize text console with our font
consoleSetTextVramBGAdr(0x6800);
consoleSetTextVramAdr(0x3000);
consoleSetTextOffset(0x0100);
consoleInitText(0, 16 * 2, &snesfont, &snespal);

// Set give soundbank
spcSetBank(&SOUNDBANK__);

// Load music
spcLoad(MOD_POLLEN8);

// Init background
bgSetGfxPtr(0, 0x2000);
bgSetMapPtr(0, 0x6800, SC_32x32);

// Now Put in 16 color mode and disable Bgs except current
setMode(BG_MODE1, 0);
bgSetDisable(1);
bgSetDisable(2);

// Draw a wonderful text :P
consoleDrawText(5, 10, "Let's the music play !");
consoleDrawText(5, 12, " A to PAUSE ");
consoleDrawText(5, 13, " B to RESUME ");

// Wait for nothing :P
setScreenOn();

// Play file from the beginning
spcPlay(0);

// Wait for nothing :D !
while (1)
{
// Test key a (without repeating sound if still pressed)
if (padsCurrent(0) & KEY_A)
{
if (keyapressed == 0)
{
keyapressed = 1;
spcPauseMusic(); // Pause music and save position
}
}
else
keyapressed = 0;
if (padsCurrent(0) & KEY_B)
{
if (keybpressed == 0)
{
keybpressed = 1;
// stop current music and load music. We load 1st music just after effects, so number 1)
spcResumeMusic(); // Resume music at current position
}
}
else
keybpressed = 0;

// Update music / sfx stream and wait vbl
spcProcess();
WaitForVBlank();

// change background color
bgcolor++;
setPaletteColor(0x00, bgcolor);
}
return 0;
}
Binary file added snes-examples/audio/music2/pvsneslibfont.bmp
Binary file not shown.
Binary file added snes-examples/audio/music2/res/pollen8.it
Binary file not shown.

0 comments on commit 8e818a4

Please sign in to comment.