diff options
author | Simon Howard | 2015-06-08 21:12:26 -0400 |
---|---|---|
committer | Simon Howard | 2015-06-08 21:12:26 -0400 |
commit | 25c67b716015e1a5cf9379ffcb7fd6e8a62766c6 (patch) | |
tree | 90eeea9b1d4b9de1ba37f122e30153febe11e96d | |
parent | e81997d7571cbe9372c4fe66b644d0d9a5059b6f (diff) | |
download | chocolate-doom-25c67b716015e1a5cf9379ffcb7fd6e8a62766c6.tar.gz chocolate-doom-25c67b716015e1a5cf9379ffcb7fd6e8a62766c6.tar.bz2 chocolate-doom-25c67b716015e1a5cf9379ffcb7fd6e8a62766c6.zip |
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.
-rw-r--r-- | opl/opl.c | 43 | ||||
-rw-r--r-- | opl/opl.h | 13 | ||||
-rw-r--r-- | src/i_oplmusic.c | 8 |
3 files changed, 40 insertions, 24 deletions
@@ -65,15 +65,16 @@ unsigned int opl_sample_rate = 22050; // 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 @@ static int InitDriver(opl_driver_t *_driver, unsigned int port_base) 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 @@ static int InitDriver(opl_driver_t *_driver, unsigned int port_base) // 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 @@ static int AutoSelectDriver(unsigned int port_base) 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,14 +151,14 @@ int OPL_Init(unsigned int port_base) { printf("OPL_Init: Failed to initialize " "driver: '%s'.\n", driver_name); - return 0; + return OPL_INIT_NONE; } } } printf("OPL_Init: unknown driver: '%s'.\n", driver_name); - return 0; + return OPL_INIT_NONE; } else { @@ -278,7 +279,7 @@ void OPL_WriteRegister(int reg, int value) // 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 @@ int OPL_Detect(void) result2 = OPL_ReadPort(OPL_REGISTER_PORT_OPL3); if (result1 == 0x00) { - return 2; + return OPL_INIT_OPL3; } - return 1; + else + { + return OPL_INIT_OPL2; + } + } + else + { + return OPL_INIT_NONE; } - return 0; } // Initialize registers on startup @@ -23,6 +23,15 @@ 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, @@ -66,7 +75,7 @@ typedef enum // 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 @@ void OPL_WriteRegister(int reg, int value); // 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. diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c index f98f2c91..239c9794 100644 --- a/src/i_oplmusic.c +++ b/src/i_oplmusic.c @@ -1651,12 +1651,12 @@ static void I_OPL_ShutdownMusic(void) 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 @@ static boolean I_OPL_InitMusic(void) 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; |