]> Shamusworld >> Repos - apple2/blobdiff - src/timing.cpp
Docs were missing GPLv3. Thanks to schampailler for the heads up. :-)
[apple2] / src / timing.cpp
old mode 100755 (executable)
new mode 100644 (file)
index eafaa21..2345a92
@@ -7,7 +7,7 @@
 // JLH = James L. Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
-// ---  ----------  ------------------------------------------------------------
+// ---  ----------  -----------------------------------------------------------
 // JLH  01/04/2006  Cosmetic changes (like this one ;-)
 //
 
 
 // NOTE ABOUT TIMING SYSTEM DATA STRUCTURES:
 
-// A queue won't work for this system because we can't guarantee that an event will go
-// in with a time that is later than the ones already queued up. So we just use a simple
-// list.
+// A queue won't work for this system because we can't guarantee that an event
+// will go in with a time that is later than the ones already queued up. So we
+// just use a simple list.
 
-// Although if we used an insertion sort we could, but it wouldn't work for adjusting
-// times...
+// Although if we used an insertion sort we could, but it wouldn't work for
+// adjusting times...
 
 struct Event
 {
@@ -38,19 +38,20 @@ struct Event
     void (* timerCallback)(void);
 };
 
+//let's try +1... nope.
 static Event eventList[EVENT_LIST_SIZE];
-static uint32 nextEvent;
+static uint32_t nextEvent;
 
 void InitializeEventList(void)
 {
-    for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+    for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
         eventList[i].valid = false;
 }
 
 //We just slap the next event into the list, no checking, no nada...
 void SetCallbackTime(void (* callback)(void), double time)
 {
-    for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+    for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
     {
         if (!eventList[i].valid)
         {
@@ -68,7 +69,7 @@ void SetCallbackTime(void (* callback)(void), double time)
 
 void RemoveCallback(void (* callback)(void))
 {
-    for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+    for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
     {
         if (eventList[i].valid && eventList[i].timerCallback == callback)
         {
@@ -81,7 +82,7 @@ void RemoveCallback(void (* callback)(void))
 
 void AdjustCallbackTime(void (* callback)(void), double time)
 {
-    for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+    for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
     {
         if (eventList[i].valid && eventList[i].timerCallback == callback)
         {
@@ -98,10 +99,11 @@ double GetTimeToNextEvent(void)
        // 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;
 
-    for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+    for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
     {
         if (eventList[i].valid)
         {
@@ -125,6 +127,9 @@ double GetTimeToNextEvent(void)
        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;
 }
 
@@ -133,7 +138,7 @@ void HandleNextEvent(void)
     double elapsedTime = eventList[nextEvent].eventTime;
     void (* event)(void) = eventList[nextEvent].timerCallback;
 
-    for(uint32 i=0; i<EVENT_LIST_SIZE; i++)
+    for(uint32_t i=0; i<EVENT_LIST_SIZE; i++)
         if (eventList[i].valid)
             eventList[i].eventTime -= elapsedTime;