diff options
author | Simon Howard | 2009-03-11 21:28:28 +0000 |
---|---|---|
committer | Simon Howard | 2009-03-11 21:28:28 +0000 |
commit | 99420c03a1cb10ea69207f2ed89f5fd1ec892bee (patch) | |
tree | af9112241116d823d71a2a3e55cd8a6fcabc47ba /src/i_oplmusic.c | |
parent | 962d6dcf12e740c26c3be035884b310e74947d97 (diff) | |
download | chocolate-doom-99420c03a1cb10ea69207f2ed89f5fd1ec892bee.tar.gz chocolate-doom-99420c03a1cb10ea69207f2ed89f5fd1ec892bee.tar.bz2 chocolate-doom-99420c03a1cb10ea69207f2ed89f5fd1ec892bee.zip |
More accurate initialisation; set registers to match what Doom does.
Subversion-branch: /branches/opl-branch
Subversion-revision: 1463
Diffstat (limited to 'src/i_oplmusic.c')
-rw-r--r-- | src/i_oplmusic.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/i_oplmusic.c b/src/i_oplmusic.c index 7ead7f02..baf17bd6 100644 --- a/src/i_oplmusic.c +++ b/src/i_oplmusic.c @@ -147,7 +147,7 @@ static void WriteRegister(int reg, int value) // Read the register port 25 times after writing the value to // cause the appropriate delay - for (i=0; i<25; ++i) + for (i=0; i<24; ++i) { GetStatus(); } @@ -158,6 +158,7 @@ static void WriteRegister(int reg, int value) static boolean DetectOPL(void) { int result1, result2; + int i; // Reset both timers: WriteRegister(OPL_REG_TIMER_CTRL, 0x60); @@ -175,7 +176,12 @@ static boolean DetectOPL(void) WriteRegister(OPL_REG_TIMER_CTRL, 0x21); // Wait for 80 microseconds - SDL_Delay(1); + // This is how Doom does it: + + for (i=0; i<200; ++i) + { + GetStatus(); + } // Read status result2 = GetStatus(); @@ -198,7 +204,7 @@ static void InitRegisters(void) // Initialise level registers - for (r=OPL_REGS_LEVEL; r < OPL_REGS_LEVEL + OPL_NUM_OPERATORS; ++r) + for (r=OPL_REGS_LEVEL; r <= OPL_REGS_LEVEL + OPL_NUM_OPERATORS; ++r) { WriteRegister(r, 0x3f); } @@ -206,15 +212,16 @@ static void InitRegisters(void) // Initialise other registers // These two loops write to registers that actually don't exist, // but this is what Doom does ... + // Similarly, the <= is also intenational. - for (r=OPL_REGS_ATTACK; r < OPL_REGS_WAVEFORM + OPL_NUM_OPERATORS; ++r) + for (r=OPL_REGS_ATTACK; r <= OPL_REGS_WAVEFORM + OPL_NUM_OPERATORS; ++r) { WriteRegister(r, 0x00); } // More registers ... - for (r=0; r < OPL_REGS_LEVEL; ++r) + for (r=1; r < OPL_REGS_LEVEL; ++r) { WriteRegister(r, 0x00); } @@ -364,6 +371,9 @@ static void I_OPL_ShutdownMusic(void) { if (music_initialised) { +#ifdef TEST + InitRegisters(); +#endif OPL_Shutdown(); // Release GENMIDI lump @@ -403,6 +413,22 @@ static boolean I_OPL_InitMusic(void) InitRegisters(); InitVoices(); +#ifdef TEST + { + opl_voice_t *voice; + + voice = GetFreeVoice(); + SetVoiceInstrument(voice, &main_instrs[34].opl2_voice); + + // Set level: + WriteRegister(OPL_REGS_LEVEL + voice->op2, 0x94); + + // Note on: + WriteRegister(OPL_REGS_FREQ_1 + voice->index, 0x65); + WriteRegister(OPL_REGS_FREQ_2 + voice->index, 0x2b); + } +#endif + music_initialised = true; return true; |