ref: 25c67b716015e1a5cf9379ffcb7fd6e8a62766c6
parent: e81997d7571cbe9372c4fe66b644d0d9a5059b6f
author: Simon Howard <fraggle@soulsphere.org>
date: Mon Jun 8 17:12:26 EDT 2015
opl: Change result from OPL_Init() to an enum. This no longer returns a boolean value, but actually returns an integer indicating the type of OPL chip that was detected. Change the return value to have a more meaningful value.
--- a/opl/opl.c
+++ b/opl/opl.c
@@ -65,15 +65,16 @@
// Initialize the specified driver and detect an OPL chip. Returns
// true if an OPL is detected.
-static int InitDriver(opl_driver_t *_driver, unsigned int port_base)
+static opl_init_result_t InitDriver(opl_driver_t *_driver,
+ unsigned int port_base)
{
- int result1, result2;
+ opl_init_result_t result1, result2;
// Initialize the driver.
if (!_driver->init_func(port_base))
{
- return 0;
+ return OPL_INIT_NONE;
}
// The driver was initialized okay, so we now have somewhere
@@ -86,12 +87,12 @@
result1 = OPL_Detect();
result2 = OPL_Detect();
- if (!result1 || !result2)
+ if (result1 == OPL_INIT_NONE || result2 == OPL_INIT_NONE)
{
printf("OPL_Init: No OPL detected using '%s' driver.\n", _driver->name);
_driver->shutdown_func();
driver = NULL;
- return 0;
+ return OPL_INIT_NONE;
}
init_stage_reg_writes = 0;
@@ -103,15 +104,15 @@
// Find a driver automatically by trying each in the list.
-static int AutoSelectDriver(unsigned int port_base)
+static opl_init_result_t AutoSelectDriver(unsigned int port_base)
{
int i;
- int result;
+ opl_init_result_t result;
for (i=0; drivers[i] != NULL; ++i)
{
result = InitDriver(drivers[i], port_base);
- if (result)
+ if (result != OPL_INIT_NONE)
{
return result;
}
@@ -119,13 +120,13 @@
printf("OPL_Init: Failed to find a working driver.\n");
- return 0;
+ return OPL_INIT_NONE;
}
-// Initialize the OPL library. Returns true if initialized
-// successfully.
+// Initialize the OPL library. Return value indicates type of OPL chip
+// detected, if any.
-int OPL_Init(unsigned int port_base)
+opl_init_result_t OPL_Init(unsigned int port_base)
{
char *driver_name;
int i;
@@ -150,7 +151,7 @@
{
printf("OPL_Init: Failed to initialize "
"driver: '%s'.\n", driver_name);
- return 0;
+ return OPL_INIT_NONE;
}
}
}
@@ -157,7 +158,7 @@
printf("OPL_Init: unknown driver: '%s'.\n", driver_name);
- return 0;
+ return OPL_INIT_NONE;
}
else
{
@@ -278,7 +279,7 @@
// Detect the presence of an OPL chip
-int OPL_Detect(void)
+opl_init_result_t OPL_Detect(void)
{
int result1, result2;
int i;
@@ -323,11 +324,17 @@
result2 = OPL_ReadPort(OPL_REGISTER_PORT_OPL3);
if (result1 == 0x00)
{
- return 2;
+ return OPL_INIT_OPL3;
}
- return 1;
+ else
+ {
+ return OPL_INIT_OPL2;
+ }
}
- return 0;
+ else
+ {
+ return OPL_INIT_NONE;
+ }
}
// Initialize registers on startup
--- a/opl/opl.h
+++ b/opl/opl.h
@@ -23,8 +23,17 @@
typedef void (*opl_callback_t)(void *data);
+// Result from OPL_Init(), indicating what type of OPL chip was detected,
+// if any.
typedef enum
{
+ OPL_INIT_NONE,
+ OPL_INIT_OPL2,
+ OPL_INIT_OPL3,
+} opl_init_result_t;
+
+typedef enum
+{
OPL_REGISTER_PORT = 0,
OPL_DATA_PORT = 1,
OPL_REGISTER_PORT_OPL3 = 2
@@ -66,7 +75,7 @@
// Initialize the OPL subsystem.
-int OPL_Init(unsigned int port_base);
+opl_init_result_t OPL_Init(unsigned int port_base);
// Shut down the OPL subsystem.
@@ -99,7 +108,7 @@
// Perform a detection sequence to determine that an
// OPL chip is present.
-int OPL_Detect(void);
+opl_init_result_t OPL_Detect(void);
// Initialize all registers, performed on startup.
--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -1651,12 +1651,12 @@
static boolean I_OPL_InitMusic(void)
{
char *dmxoption;
- int opl_chip_type;
+ opl_init_result_t chip_type;
OPL_SetSampleRate(snd_samplerate);
- opl_chip_type = OPL_Init(opl_io_port);
- if (!opl_chip_type)
+ chip_type = OPL_Init(opl_io_port);
+ if (chip_type == OPL_INIT_NONE)
{
printf("Dude. The Adlib isn't responding.\n");
return false;
@@ -1670,7 +1670,7 @@
dmxoption = snd_dmxoption != NULL ? snd_dmxoption : "";
}
- if (opl_chip_type == 2 && strstr(dmxoption, "-opl3") != NULL)
+ if (chip_type == OPL_INIT_OPL3 && strstr(dmxoption, "-opl3") != NULL)
{
opl_opl3mode = 1;
num_opl_voices = OPL_NUM_VOICES * 2;