diff --git a/pgusinit/pgusinit.c b/pgusinit/pgusinit.c index a702ad6..fdeb503 100755 --- a/pgusinit/pgusinit.c +++ b/pgusinit/pgusinit.c @@ -27,6 +27,7 @@ typedef enum { MPU_MODE = 2, TANDY_MODE = 3, CMS_MODE = 4, + SB_MODE = 5, JOYSTICK_ONLY_MODE = 0x0f } card_mode_t; @@ -40,7 +41,8 @@ const char* usage_by_card[] = { "[/p x] [/v x] [/s] [/n]", // MPU_MODE "[/p x]", // TANDY_MODE "[/p x]", // CMS_MODE - "", "", "", "", "", "", "", "", "", "", // future expansion + "[/p x] [/o x]", // SB_MODE + "", "", "", "", "", "", "", "", "", // future expansion "", // JOYSTICK_ONLY_MODE }; @@ -57,9 +59,13 @@ void usage(char *argv0, card_mode_t mode) { fprintf(stderr, " /f fw.uf2 - program the PicoGUS with the firmware file fw.uf2\n"); fprintf(stderr, " /j - enable USB joystick support\n"); if (mode > GUS_MODE && mode < JOYSTICK_ONLY_MODE) { - fprintf(stderr, "AdLib, MPU-401, Tandy, CMS modes only:\n"); + fprintf(stderr, "Sound Blaster, MPU-401, Tandy, CMS modes only:\n"); fprintf(stderr, " /p x - set the (hex) base port address of the emulated card. Defaults:\n"); - fprintf(stderr, " AdLib: 388; MPU-401: 330; Tandy: 2C0; CMS: 220\n"); + fprintf(stderr, " Sound Blaster: 220; MPU-401: 330; Tandy: 2C0; CMS: 220\n"); + // "................................................................................\n" + } + if (mode == SB_MODE) { + fprintf(stderr, " /o x - set the base address of the OPL2/AdLib on the SB. Default: 388\n"); // "................................................................................\n" } if (mode == MPU_MODE) { @@ -276,6 +282,7 @@ int main(int argc, char* argv[]) { unsigned short buffer_size = 0; unsigned short dma_interval = 0; uint16_t port_override = 0; + uint16_t opl_port_override = 0; uint8_t wt_volume = 100; char fw_filename[256] = {0}; card_mode_t mode; @@ -334,6 +341,16 @@ int main(int argc, char* argv[]) { usage(argv[0], mode); return 4; } + } else if (stricmp(argv[i], "/o") == 0) { + if (i + 1 >= argc) { + usage(argv[0], mode); + return 255; + } + e = sscanf(argv[++i], "%hx", &opl_port_override); + if (e != 1 || opl_port_override > 0x3ffu) { + usage(argv[0], mode); + return 4; + } } else if (stricmp(argv[i], "/v") == 0) { if (i + 1 >= argc) { usage(argv[0], mode); @@ -389,6 +406,7 @@ int main(int argc, char* argv[]) { printf("\n"); uint16_t port; + uint16_t opl_port; if (mode != GUS_MODE) { if (port_override) { outp(CONTROL_PORT, 0x04); // Select port register @@ -397,11 +415,19 @@ int main(int argc, char* argv[]) { outp(CONTROL_PORT, 0x04); // Select port register port = inpw(DATA_PORT_LOW); // Get port + if (mode == SB_MODE) { + if (opl_port_override) { + outp(CONTROL_PORT, 0x05); // Select OPL port register + outpw(DATA_PORT_LOW, opl_port_override); // Write port + } + outp(CONTROL_PORT, 0x05); // Select OPL port register + opl_port = inpw(DATA_PORT_LOW); // Get port + } } outp(CONTROL_PORT, 0x0f); // Select joystick enable register outp(DATA_PORT_HIGH, enable_joystick); - printf("USB joystick support %s\n", enable_joystick ? "enabled" : "disabled"); + printf("USB joystick support %s\n", enable_joystick ? "enabled" : "disabled (use /j to enable)"); switch(mode) { case GUS_MODE: @@ -444,6 +470,9 @@ int main(int argc, char* argv[]) { case CMS_MODE: printf("Running in CMS/Game Blaster mode on port %x\n", port); break; + case SB_MODE: + printf("Running in Sound Blaster 2.0 mode on port %x (AdLib port %x)\n", port, opl_port); + break; case JOYSTICK_ONLY_MODE: printf("Running in Joystick exclusive mode on port 201\n"); default: diff --git a/sw/picogus.cpp b/sw/picogus.cpp index 9272265..22c9a29 100644 --- a/sw/picogus.cpp +++ b/sw/picogus.cpp @@ -137,6 +137,7 @@ __force_inline void select_picogus(uint8_t value) { case 0x03: // Mode (GUS, OPL, MPU, etc...) break; case 0x04: // Base port + case 0x05: // Adlib Base port basePort_tmp = 0; break; case 0x0f: // enable joystick @@ -165,6 +166,7 @@ __force_inline void select_picogus(uint8_t value) { __force_inline void write_picogus_low(uint8_t value) { switch (sel_reg) { case 0x04: // Base port + case 0x05: // Adlib Base port basePort_tmp = value; break; } @@ -184,6 +186,8 @@ __force_inline void write_picogus_high(uint8_t value) { sb_port_test = basePort >> 4; #endif break; + case 0x05: // Adlib Base port + adlib_basePort = (value << 8) | basePort_tmp; case 0x0f: // enable joystick #ifdef USB_JOYSTICK joyPort = value ? 0x201u : 0xffff; @@ -222,6 +226,12 @@ __force_inline uint8_t read_picogus_low(void) { return 0xff; #endif break; + case 0x05: // Adlib Base port +#if defined(SOUND_SB) + return adlib_basePort & 0xff; +#else + return 0xff; +#endif default: return 0x0; } @@ -265,6 +275,13 @@ __force_inline uint8_t read_picogus_high(void) { return basePort >> 8; #else return 0xff; +#endif + break; + case 0x05: // Adlib Base port +#if defined(SOUND_SB) + return adlib_basePort >> 8; +#else + return 0xff; #endif break; case 0x0f: // enable joystick