pgusinit: add option to init GUS/SB mode reosurces (base port, IRQ, DMA) from ULTRASND/BLASTER environment variable.

This commit is contained in:
wbcbz7 committed 2026-03-28 23:05:35 +07:00
1 parent 38d485ef01
commit 5e8dec0c89
2 files changed
+64 -29

No files matched your search

+2
View File
@@ -64,6 +64,7 @@ GUS emulation requires the ULTRASND variable to be set, in the format:
5 is the IRQ. pgusinit will check that the port set on the PicoGUS matches the
port specified in ULTRASND.
* `/gusenv` - sets the base I/O port from ULTRASND variable.
* `/gusport x` - sets the base I/O port of the GUS to x. Defaults to 240.
* `/gusbuf n` - sets the audio buffer size to n samples. Defaults to 4 with a
minimum of 1 and maximum of 256. Some programs require a different value to
@@ -91,6 +92,7 @@ Sound Blaster emulation requires the BLASTER variable to be set, in the format:
`set BLASTER=A220 I5 D1 H1 T6`, where 220 is the PicoGUS's SB emulation port,
5 is the IRQ, 1 is the DMA, 6 is the emulated SB type (see `/sbtype` option)
* `/sbenv` - sets SB base port, IRQ, DMA and type from BLASTER variable.
* `/sbport x` - sets the base port of the Sound Blaster. Defaults to 220.
* `/sbirq x` - sets the IRQ of the Sound Blaster. Must match jumper settings.
* `/sbdma x` - sets the DMA of the Sound Blaster. Must match jumper settings.
+62 -29
View File
@@ -34,6 +34,7 @@ static card_mode_t newMode = 0;
static board_type_t board_type;
static bool wifichg = false;
static bool permanent = false;
static bool resources_from_env = false;
static bool is_console;
static uint8_t page_lines;
@@ -95,6 +96,7 @@ static void usage(card_mode_t mode, bool print_all)
if (mode == GUS_MODE || print_all) {
// "...............................................................................\n"
pageprintf("GUS settings:\n");
pageprintf(" /gusenv - set the base port of the GUS from ULTRASND variable\n");
pageprintf(" /gusport x - set the base port of the GUS. Default: 240\n");
pageprintf(" /gusbuf n - set audio buffer to n samples. Default: 4, Min: 1, Max: 256\n");
pageprintf(" (tweaking can help programs that hang or have audio glitches)\n");
@@ -107,7 +109,8 @@ static void usage(card_mode_t mode, bool print_all)
if (mode == SB_MODE || print_all) {
// "...............................................................................\n"
pageprintf("Sound Blaster settings:\n");
pageprintf(" /sbport x - set the base port of the Sound Blaster. Default: 220\n");
pageprintf(" /sbenv - set the SB base port, IRQ, DMA and type from SET BLASTER=\n");
pageprintf(" /sbport x - set the SB base port. Default: 220\n");
pageprintf(" /sbirq x - set the SB IRQ (must match jumper settings!). Default: 5\n");
pageprintf(" /sbdma x - set the SB DMA (must match jumper settings!). Default: 1\n");
pageprintf(" /sbtype x - set the Sound Blaster type. Default: 6 (SB 16)\n");
@@ -229,11 +232,18 @@ static int init_gus(void)
return 2;
}
outp(CONTROL_PORT, CMD_GUSPORT); // Select port register
uint16_t tmp_port = inpw(DATA_PORT_LOW);
if (port != tmp_port) {
err_ultrasnd();
return 2;
if (resources_from_env) {
// init GUS base port from ULTRASND environment variable
outp(CONTROL_PORT, CMD_GUSPORT); // Select port register
outpw(DATA_PORT_LOW, port);
} else {
// verify ULTRASND against GUS mode settings
outp(CONTROL_PORT, CMD_GUSPORT); // Select port register
uint16_t tmp_port = inpw(DATA_PORT_LOW);
if (port != tmp_port) {
err_ultrasnd();
return 2;
}
}
// Detect if there's something GUS-like...
@@ -294,32 +304,48 @@ static int init_sb(void)
return 2;
}
outp(CONTROL_PORT, CMD_SBPORT); // Select port register
uint16_t tmp_port = inpw(DATA_PORT_LOW);
if (port != tmp_port) {
err_blaster();
return 2;
}
if (resources_from_env) {
// update resources from BLASTER environment variable
outp(CONTROL_PORT, CMD_SBPORT); // Select port register
outpw(DATA_PORT_LOW, port);
outp(CONTROL_PORT, CMD_SBIRQ); // Select IRQ register
uint8_t tmp_irq = inp(DATA_PORT_HIGH);
if (irq != tmp_irq) {
err_blaster();
return 2;
}
outp(CONTROL_PORT, CMD_SBIRQ); // Select IRQ register
outp(DATA_PORT_HIGH, irq);
outp(CONTROL_PORT, CMD_SBDMA); // Select DMA register
uint8_t tmp_dma = inp(DATA_PORT_HIGH);
if (dma8 != tmp_dma) {
err_blaster();
return 2;
}
outp(CONTROL_PORT, CMD_SBDMA); // Select DMA register
outp(DATA_PORT_HIGH, irq);
outp(CONTROL_PORT, CMD_SBTYPE); // Select SB type register
uint8_t tmp_type = inp(DATA_PORT_HIGH);
if (sbtype != tmp_type) {
err_blaster();
return 2;
outp(CONTROL_PORT, CMD_SBTYPE); // Select SB type register
outp(DATA_PORT_HIGH, sbtype);
} else {
// verify BLASTER variable against current SB mode settings
outp(CONTROL_PORT, CMD_SBPORT); // Select port register
uint16_t tmp_port = inpw(DATA_PORT_LOW);
if (port != tmp_port) {
err_blaster();
return 2;
}
outp(CONTROL_PORT, CMD_SBIRQ); // Select IRQ register
uint8_t tmp_irq = inp(DATA_PORT_HIGH);
if (irq != tmp_irq) {
err_blaster();
return 2;
}
outp(CONTROL_PORT, CMD_SBDMA); // Select DMA register
uint8_t tmp_dma = inp(DATA_PORT_HIGH);
if (dma8 != tmp_dma) {
err_blaster();
return 2;
}
outp(CONTROL_PORT, CMD_SBTYPE); // Select SB type register
uint8_t tmp_type = inp(DATA_PORT_HIGH);
if (sbtype != tmp_type) {
err_blaster();
return 2;
}
}
return 0;
@@ -684,6 +710,11 @@ static void send_string(const uint8_t cmd, const char* str, const int16_t max_le
outp(DATA_PORT_HIGH, 0);
}
static bool cmdSetResourcesFromEnv(const char* arg, const int cmd, const int cmd2, const int cmd3) {
resources_from_env = true;
return true;
}
static bool cmdDisplayUsage(const char* arg, const int print_all, const int cmd2, const int cmd3)
{
usage(gMode, print_all);
@@ -978,10 +1009,12 @@ ParseCommand parseCommands[] = {
{"/joy", cmdSendBool, CMD_JOYEN, ARG_REQUIRE},
{"/mode", cmdSetMode, 0, ARG_REQUIRE},
{"/wtvol", cmdSetVol, CMD_WTVOL, ARG_REQUIRE},
{"/gusenv", cmdSetResourcesFromEnv, 1, ARG_NONE},
{"/gus44k", cmdSendBool, CMD_GUS44K, ARG_REQUIRE, "false"},
{"/gusbuf", cmdGUSBuffer, CMD_GUSBUF, ARG_REQUIRE, "4"},
{"/gusdma", cmdSendUint8, CMD_GUSDMA, ARG_REQUIRE, "0"},
{"/gusport", cmdSendPort, CMD_GUSPORT, ARG_REQUIRE, "240"},
{"/sbenv", cmdSetResourcesFromEnv, 1, ARG_NONE},
{"/sbport", cmdSendPort, CMD_SBPORT, ARG_REQUIRE, "220"},
{"/sbirq", cmdSendUint8, CMD_SBIRQ, ARG_REQUIRE, "5"},
{"/sbdma", cmdSendUint8, CMD_SBDMA, ARG_REQUIRE, "1"},