diff --git a/base/src/vn_engine.c b/base/src/vn_engine.c index 5184753..5456df8 100644 --- a/base/src/vn_engine.c +++ b/base/src/vn_engine.c @@ -209,7 +209,7 @@ void VN_init() { XGM_setForceDelayDMA(TRUE); VDP_setTextPalette(TEXT_PAL); - VDP_drawText("choice4genesis v0.11.2", 17, 27); + VDP_drawText("choice4genesis v0.12.0", 17, 27); } @@ -245,14 +245,22 @@ void VN_font(const Image *image) { } -void VN_music(const u8 *music) { - XGM_startPlay(music); +void VN_music(const u8 *music, const u32 length, const u8 driverFlags) { + if (driverFlags == SOUND_ADPCM) { + SND_startPlay_2ADPCM(music, length, SOUND_PCM_CH1, TRUE); + } else { + XGM_startPlay(music); + } } -void VN_sound(const u8 *sound, const u16 length) { - XGM_stopPlayPCM (SOUND_PCM_CH2); - XGM_setPCM(PCM_CHANNEL, sound, length); - XGM_startPlayPCM(PCM_CHANNEL, 1, SOUND_PCM_CH2); +void VN_sound(const u8 *sound, const u32 length, const u8 driverFlags) { + if (driverFlags == SOUND_ADPCM) { + SND_startPlay_2ADPCM(sound, length, SOUND_PCM_CH2, FALSE); + } else { + XGM_stopPlayPCM (SOUND_PCM_CH2); + XGM_setPCM(PCM_CHANNEL, sound, length); + XGM_startPlayPCM(PCM_CHANNEL, 1, SOUND_PCM_CH2); + } } void VN_stop(const u8 flags) { diff --git a/base/src/vn_engine.h b/base/src/vn_engine.h index f0d1415..4b9b252 100644 --- a/base/src/vn_engine.h +++ b/base/src/vn_engine.h @@ -15,6 +15,9 @@ #define LAYER_BACKGROUND (2) #define LAYER_WINDOW (4) +#define SOUND_XGM (1) +#define SOUND_ADPCM (2) + extern void VN_init(); extern void VN_background(const Image *image); @@ -22,8 +25,8 @@ extern void VN_image(const Image *image, const u8 flags); extern void VN_imageAt(u16 x, u16 y); extern void VN_font(const Image *image); -extern void VN_music(const u8 *music); -extern void VN_sound(const u8 *sound, const u16 length); +extern void VN_music(const u8 *music, const u32 length, const u8 driverFlags); +extern void VN_sound(const u8 *sound, const u32 length, const u8 driverFlags); extern void VN_stop(const u8 flags); extern void VN_textStart(); diff --git a/examples/test/project/greeting_3_karen.wav b/examples/test/project/greeting_3_karen.wav new file mode 100644 index 0000000..a66abdb Binary files /dev/null and b/examples/test/project/greeting_3_karen.wav differ diff --git a/examples/test/project/illurock.wav b/examples/test/project/illurock.wav new file mode 100644 index 0000000..07f1635 Binary files /dev/null and b/examples/test/project/illurock.wav differ diff --git a/examples/test/project/startup.choice b/examples/test/project/startup.choice index d9a87ec..1a04aa5 100644 --- a/examples/test/project/startup.choice +++ b/examples/test/project/startup.choice @@ -104,5 +104,11 @@ * flush * background "Red echidna.jpg" Showing a red echidna - # Go to another scene - * goto_scene test + # More options... + * choice + # Play ADPCM music + * music "illurock.wav", adpcm + # Play ADPCM sound + * sound "greeting_3_karen.wav", adpcm + # Go to another scene + * goto_scene test diff --git a/generator/generator.js b/generator/generator.js index 9e0ade7..f290abd 100644 --- a/generator/generator.js +++ b/generator/generator.js @@ -152,18 +152,31 @@ const COMMAND_GENERATORS = { 'music': (entity, context) => { const musicFileName = getFileNameConstant(entity, entity.params.positional.fileName, context, 'Music filename'); + const flags = entity.params.flags || {}; + const isAdpcm = Object.entries(flags).filter(([k, v]) => v).find(([name, v]) => name.toUpperCase() === 'ADPCM'); + + const resType = isAdpcm ? 'WAV' : 'XGM'; + const driver = isAdpcm ? '2ADPCM' : 'APLIB'; + const driverFlag = isAdpcm ? 'SOUND_ADPCM' : 'SOUND_XGM'; + const musicVariable = addResource(context.res.music, musicFileName, musicVariable => - `XGM ${musicVariable} "../project/${musicFileName}" APLIB`); + `${resType} ${musicVariable} "../project/${musicFileName}" ${driver}`); - return `VN_music(${musicVariable});`; + return `VN_music(${musicVariable}, sizeof(${musicVariable}), ${driverFlag});`; }, 'sound': (entity, context) => { const soundFileName = getFileNameConstant(entity, entity.params.positional.fileName, context, 'Sound filename'); + const flags = entity.params.flags || {}; + const isAdpcm = Object.entries(flags).filter(([k, v]) => v).find(([name, v]) => name.toUpperCase() === 'ADPCM'); + + const driver = isAdpcm ? '2ADPCM' : 'XGM'; + const driverFlag = isAdpcm ? 'SOUND_ADPCM' : 'SOUND_XGM'; + const soundVariable = addResource(context.res.music, soundFileName, soundVariable => - `WAV ${soundVariable} "../project/${soundFileName}" XGM`); + `WAV ${soundVariable} "../project/${soundFileName}" ${driver}`); - return `VN_sound(${soundVariable}, sizeof(${soundVariable}));`; + return `VN_sound(${soundVariable}, sizeof(${soundVariable}), ${driverFlag});`; }, 'stop': (entity, context) => { diff --git a/package.json b/package.json index 2b3b591..3a5018b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "choice4genesis", - "version": "0.11.2", + "version": "0.12.0", "description": "A ChoiceScript clone that generates SGDK-compatible C source for the Sega Genesis ", "main": "index.js", "scripts": { diff --git a/parser/syntax-full.js b/parser/syntax-full.js index c97de2b..f0c02f6 100644 --- a/parser/syntax-full.js +++ b/parser/syntax-full.js @@ -27,8 +27,8 @@ const COMMANDS = { 'image': { positional: ['fileName'], named: { 'at': ['x', 'y'] }, flags: ['foreground', 'background'] }, 'font': { positional: ['fileName'] }, - 'music': { positional: ['fileName'] }, - 'sound': { positional: ['fileName'] }, + 'music': { positional: ['fileName'], flags: ['adpcm'] }, + 'sound': { positional: ['fileName'], flags: ['adpcm'] }, 'stop': { flags: ['music', 'sound'] }, 'window': { named: { 'from': ['x', 'y'], 'to': ['x', 'y'], 'size': ['w', 'h'] }, flags: ['borderless', 'withborder', 'default'] },