From 489370b026c0f61c1aa6573ce902171919c23bcc Mon Sep 17 00:00:00 2001 From: Ian Scott Date: Tue, 30 Jul 2024 00:05:05 -0600 Subject: [PATCH] Fix disabling ports --- pgusinit/pgusinit.c | 12 ++++++++---- sw/picogus.cpp | 46 ++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/pgusinit/pgusinit.c b/pgusinit/pgusinit.c index 0c01bd1..c54a21a 100755 --- a/pgusinit/pgusinit.c +++ b/pgusinit/pgusinit.c @@ -724,10 +724,14 @@ int main(int argc, char* argv[]) { printf("Running in Sound Blaster 2.0 mode on port %x ", tmp_uint16); outp(CONTROL_PORT, MODE_OPLPORT); // Select port register tmp_uint16 = inpw(DATA_PORT_LOW); // Get port - printf("(AdLib port %x", tmp_uint16); - outp(CONTROL_PORT, MODE_OPLWAIT); // Select Adlib wait register - tmp_uint8 = inp(DATA_PORT_HIGH); - printf("%s)\n", tmp_uint8 ? ", wait on" : ""); + if (tmp_uint16) { + printf("(AdLib port %x", tmp_uint16); + outp(CONTROL_PORT, MODE_OPLWAIT); // Select Adlib wait register + tmp_uint8 = inp(DATA_PORT_HIGH); + printf("%s)\n", tmp_uint8 ? ", wait on" : ""); + } else { + printf("(AdLib port disabled)\n"); + } break; default: printf("Running in unknown mode (maybe upgrade pgusinit?)\n"); diff --git a/sw/picogus.cpp b/sw/picogus.cpp index 3860447..65b16a3 100644 --- a/sw/picogus.cpp +++ b/sw/picogus.cpp @@ -345,17 +345,17 @@ __force_inline uint8_t read_picogus_high(void) { case MODE_BOOTMODE: // Mode (GUS, OPL, MPU, etc...) return settings.startupMode; case MODE_GUSPORT: // GUS Base port - return settings.GUS.basePort >> 8; + return settings.GUS.basePort == 0xFFFF ? 0 : (settings.GUS.basePort >> 8); case MODE_OPLPORT: // Adlib Base port - return settings.SB.oplBasePort >> 8; + return settings.SB.oplBasePort == 0xFFFF ? 0 : (settings.SB.oplBasePort >> 8); case MODE_SBPORT: // SB Base port - return settings.SB.basePort >> 8; + return settings.SB.basePort == 0xFFFF ? 0 : (settings.SB.basePort >> 8); case MODE_MPUPORT: // MPU Base port - return settings.MPU.basePort >> 8; + return settings.MPU.basePort == 0xFFFF ? 0 : (settings.MPU.basePort >> 8); case MODE_TANDYPORT: // Tandy Base port - return settings.Tandy.basePort >> 8; + return settings.Tandy.basePort == 0xFFFF ? 0 : (settings.Tandy.basePort >> 8); case MODE_CMSPORT: // CMS Base port - return settings.CMS.basePort >> 8; + return settings.CMS.basePort == 0xFFFF ? 0 : (settings.CMS.basePort >> 8); case MODE_JOYEN: // enable joystick return settings.Joy.basePort == 0x201u; case MODE_GUSBUF: // GUS audio buffer size @@ -392,6 +392,23 @@ __force_inline uint8_t read_picogus_high(void) { void processSettings(void) { +#if defined(SOUND_GUS) + settings.startupMode = GUS_MODE; +#elif defined(SOUND_TANDY) + settings.startupMode = TANDY_MODE; +#elif defined(SOUND_CMS) + settings.startupMode = CMS_MODE; +#elif defined(SOUND_SB) + settings.startupMode = SB_MODE; +#elif defined(SOUND_OPL) + settings.startupMode = ADLIB_MODE; +#elif defined(MPU_ONLY) + settings.startupMode = MPU_MODE; +#elif defined(USB_ONLY) + settings.startupMode = USB_MODE; +#else + settings.startupMode = INVALID_MODE; +#endif #ifdef SOUND_SB sb_port_test = settings.SB.basePort >> 4; #endif @@ -774,23 +791,6 @@ int main() // Load settings from flash loadSettings(&settings); -#if defined(SOUND_GUS) - settings.startupMode = GUS_MODE; -#elif defined(SOUND_TANDY) - settings.startupMode = TANDY_MODE; -#elif defined(SOUND_CMS) - settings.startupMode = CMS_MODE; -#elif defined(SOUND_SB) - settings.startupMode = SB_MODE; -#elif defined(SOUND_OPL) - settings.startupMode = ADLIB_MODE; -#elif defined(MPU_ONLY) - settings.startupMode = MPU_MODE; -#elif defined(USB_ONLY) - settings.startupMode = USB_MODE; -#else - settings.startupMode = INVALID_MODE; -#endif hw_clear_bits(&xip_ctrl_hw->ctrl, XIP_CTRL_EN_BITS); // Determine board type. GPIO 29 is grounded on PicoGUS v2.0, and on a Pico, it's VSYS/3 (~1.666V)