shithub: choc

Download patch

ref: 90fd85b32dd85884fb9a9cf0a7063c4509147d40
parent: 99420c03a1cb10ea69207f2ed89f5fd1ec892bee
author: Simon Howard <fraggle@gmail.com>
date: Thu Mar 12 14:50:15 EDT 2009

Read from register port when doing register writes during startup phase;
afterwards, read from the data port.

Subversion-branch: /branches/opl-branch
Subversion-revision: 1464

--- a/src/i_oplmusic.c
+++ b/src/i_oplmusic.c
@@ -116,6 +116,13 @@
 static opl_voice_t voices[OPL_NUM_VOICES];
 static opl_voice_t *voice_free_list;
 
+// In the initialisation stage, register writes are spaced by reading
+// from the register port (0).  After initialisation, spacing is
+// peformed by reading from the data port instead.  I have no idea
+// why.
+
+static boolean init_stage_reg_writes = false;
+
 // Configuration file variable, containing the port number for the
 // adlib chip.
 
@@ -139,7 +146,18 @@
 
     for (i=0; i<6; ++i)
     {
-        GetStatus();
+        // An oddity of the Doom OPL code: at startup initialisation,
+        // the spacing here is performed by reading from the register
+        // port; after initialisation, the data port is read, instead.
+
+        if (init_stage_reg_writes)
+        {
+            OPL_ReadPort(OPL_REGISTER_PORT);
+        }
+        else
+        {
+            OPL_ReadPort(OPL_DATA_PORT);
+        }
     }
 
     OPL_WritePort(OPL_DATA_PORT, value);
@@ -393,6 +411,8 @@
         return false;
     }
 
+    init_stage_reg_writes = true;
+
     // Doom does the detection sequence twice, for some reason:
 
     if (!DetectOPL() || !DetectOPL())
@@ -412,6 +432,11 @@
 
     InitRegisters();
     InitVoices();
+
+    // Now that initialisation has finished, switch the
+    // register writing mode:
+
+    init_stage_reg_writes = false;
 
 #ifdef TEST
     {