From e81d269fbe6db0034f57be08252708d6b87251c2 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Sat, 24 Jun 2017 09:12:08 -0400 Subject: [PATCH] pizza: support pocahontas custom musacks. this game is an abomination --- waterbox/pizza/Makefile | 2 +- waterbox/pizza/lib/sgb.c | 25 ++++++++++++++++++++++++- waterbox/pizza/lib/snes_spc/SNES_SPC.h | 4 ++++ waterbox/pizza/lib/snes_spc/spc.cpp | 1 + waterbox/pizza/lib/snes_spc/spc.h | 2 ++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/waterbox/pizza/Makefile b/waterbox/pizza/Makefile index efb16ef84d..91f7224824 100644 --- a/waterbox/pizza/Makefile +++ b/waterbox/pizza/Makefile @@ -10,7 +10,7 @@ CCFLAGS:=$(FLAGS) -Ilib \ -std=c99 \ -DLSB_FIRST -D_GNU_SOURCE -CPPFLAGS:=$(FLAGS) +CPPFLAGS:=$(FLAGS) -DSPC_NO_COPY_STATE_FUNCS TARGET = pizza.wbx diff --git a/waterbox/pizza/lib/sgb.c b/waterbox/pizza/lib/sgb.c index 0e35d8989c..8ecfd9aa9c 100644 --- a/waterbox/pizza/lib/sgb.c +++ b/waterbox/pizza/lib/sgb.c @@ -454,7 +454,8 @@ static void cmd_sound(void) { sgb.sound_control[1] = sgb.command[1]; sgb.sound_control[2] = sgb.command[2]; - sgb.sound_control[3] = sgb.command[3]; + sgb.sound_control[3] = sgb.command[3]; + sgb.sound_control[0] = sgb.command[4]; } else { @@ -732,6 +733,26 @@ void sgb_set_controller_data(const uint8_t *buttons) memcpy(sgb.joypad_data, buttons, sizeof(sgb.joypad_data)); } +static void trn_sound(const uint8_t* data) +{ + int len = data[0] | data[1] << 8; + int addr = data[2] | data[3] << 8; + utils_log("TRN_SOUND %04x %04x", addr, len); + uint8_t* dst = spc_get_ram(sgb.spc); + + if (len > 0xffc) + { + utils_log("TRN_SOUND src overflow"); + return; + } + if (len + addr >= 0x10000) + { + utils_log("TRN_SOUND dst overflow"); + return; + } + memcpy(dst + addr, data + 4, len); +} + static void trn_pal(const uint8_t *data) { const uint16_t *src = (const uint16_t *)data; @@ -826,6 +847,7 @@ static void do_vram_transfer(void) switch (sgb.waiting_transfer) { case TRN_SOUND: + trn_sound(vram); break; case TRN_PAL: trn_pal(vram); @@ -962,6 +984,7 @@ void sgb_render_audio(uint64_t time, void (*callback)(int16_t l, int16_t r, uint } if (p == 4) // recived { + sgb.sound_control[0] = 0; sgb.sound_control[1] = 0; sgb.sound_control[2] = 0; } diff --git a/waterbox/pizza/lib/snes_spc/SNES_SPC.h b/waterbox/pizza/lib/snes_spc/SNES_SPC.h index 8ea0392fd2..662b160928 100644 --- a/waterbox/pizza/lib/snes_spc/SNES_SPC.h +++ b/waterbox/pizza/lib/snes_spc/SNES_SPC.h @@ -51,6 +51,8 @@ public: // Runs SPC to end_time and starts a new time frame at 0 void end_frame( time_t end_time ); + + uint8_t* get_ram(); // Sound control @@ -254,6 +256,8 @@ private: #include +inline uint8_t* SNES_SPC::get_ram() { return m.ram.ram; } + inline int SNES_SPC::sample_count() const { return (m.extra_clocks >> 5) * 2; } inline int SNES_SPC::read_port( time_t t, int port ) diff --git a/waterbox/pizza/lib/snes_spc/spc.cpp b/waterbox/pizza/lib/snes_spc/spc.cpp index 85deaefc0e..4e5a77ef15 100644 --- a/waterbox/pizza/lib/snes_spc/spc.cpp +++ b/waterbox/pizza/lib/snes_spc/spc.cpp @@ -54,6 +54,7 @@ void spc_end_frame ( SNES_SPC* s, spc_time_t t ) { s->end void spc_mute_voices ( SNES_SPC* s, int mask ) { s->mute_voices( mask ); } void spc_disable_surround( SNES_SPC* s, int disable ) { s->disable_surround( disable ); } void spc_set_tempo ( SNES_SPC* s, int tempo ) { s->set_tempo( tempo ); } +uint8_t* spc_get_ram(SNES_SPC* s) { return s->get_ram(); } spc_err_t spc_load_spc ( SNES_SPC* s, void const* p, long n ) { return s->load_spc( p, n ); } void spc_clear_echo ( SNES_SPC* s ) { s->clear_echo(); } spc_err_t spc_play ( SNES_SPC* s, int count, short* out ) { return s->play( count, out ); } diff --git a/waterbox/pizza/lib/snes_spc/spc.h b/waterbox/pizza/lib/snes_spc/spc.h index 9ffdedce16..cf23f3c945 100644 --- a/waterbox/pizza/lib/snes_spc/spc.h +++ b/waterbox/pizza/lib/snes_spc/spc.h @@ -5,6 +5,7 @@ #define SPC_H #include +#include #ifdef __cplusplus extern "C" { @@ -60,6 +61,7 @@ void spc_write_port( SNES_SPC*, spc_time_t, int port, int data ); /* Runs SPC to end_time and starts a new time frame at 0 */ void spc_end_frame( SNES_SPC*, spc_time_t end_time ); +uint8_t* spc_get_ram(SNES_SPC*); /**** Sound control ****/