]> Shamusworld >> Repos - apple2/blobdiff - src/timing.cpp
Changes to sound system relating to the new threaded CPU core. It works,
[apple2] / src / timing.cpp
index 2bf07091173a20fcd3c391d02328e8f330d6a751..e93ee1a7e77565474ef634c7306f083141b1f358 100755 (executable)
@@ -38,6 +38,7 @@ struct Event
     void (* timerCallback)(void);
 };
 
+//let's try +1... nope.
 static Event eventList[EVENT_LIST_SIZE];
 static uint32 nextEvent;
 
@@ -63,7 +64,7 @@ void SetCallbackTime(void (* callback)(void), double time)
         }
     }
 
-    WriteLog("SetCallbackTime() failed to find an empty slot in the list!\n");
+    WriteLog("TIMING: SetCallbackTime() failed to find an empty slot in the list!\n");
 }
 
 void RemoveCallback(void (* callback)(void))
@@ -94,6 +95,11 @@ void AdjustCallbackTime(void (* callback)(void), double time)
 
 double GetTimeToNextEvent(void)
 {
+       // Find the next event. Since the events are not necessarily in order of
+       // increasing time, we have to search through the list for the lowest one.
+
+//ALSO: There's a bug here--nextEvent is getting a bogus value/getting clobbered...
+//      Seems like it's getting clobbered somewhere other than here...
     double time = 0;
     bool firstTime = true;
 
@@ -102,15 +108,28 @@ double GetTimeToNextEvent(void)
         if (eventList[i].valid)
         {
             if (firstTime)
-                time = eventList[i].eventTime, nextEvent = i, firstTime = false;
+                       {
+                time = eventList[i].eventTime;
+                               nextEvent = i;
+                               firstTime = false;
+                       }
             else
             {
                 if (eventList[i].eventTime < time)
-                    time = eventList[i].eventTime, nextEvent = i;
+                               {
+                    time = eventList[i].eventTime;
+                                       nextEvent = i;
+                               }
             }
         }
     }
 
+       if (time == 0)
+               WriteLog("TIMING: GetTimeToNextEvent() failed to find next event!\n");
+
+       if (nextEvent >= EVENT_LIST_SIZE)
+               WriteLog("TIMING: GetTimeToNextEvent() has bad nextEvent (=%u)!\n", nextEvent);
+
     return time;
 }