소스 검색

Timers: convert reads and writes for increasing values

Streetwalrus Einstein 10 년 전
부모
커밋
7478f14dec
2개의 변경된 파일8개의 추가작업 그리고 9개의 파일을 삭제
  1. 2 2
      src/drivers/Timers.cpp
  2. 6 7
      src/engine/StateMachine.cpp

+ 2 - 2
src/drivers/Timers.cpp

@@ -57,10 +57,10 @@ void TIMERS::mode(uint32_t timer, bool free_run, bool oneshot, bool interrupt,
 
 void TIMERS::load(uint32_t timer, uint32_t value)
 {
-    timer_load[8 * timer] = value;
+    timer_load[8 * timer] = 0xFFFFFFFF - value;
 }
 
 uint32_t TIMERS::read(uint32_t timer)
 {
-    return timer_value[8 * timer];
+    return 0xFFFFFFFF - timer_value[8 * timer];
 }

+ 6 - 7
src/engine/StateMachine.cpp

@@ -36,21 +36,21 @@ void STATEMACHINE::run()
     Timers::mode(0, true, false, false, 1, true);
     Timers::load(0, 0);
     const unsigned loop_time = TIMER_FREQ / 60;
-    unsigned loop_next = -loop_time;
+    unsigned loop_next = loop_time;
     unsigned last_update = 0, update_stamp, update_time;
     unsigned last_frame = 0, frame_stamp, frame_time;
 
     while (!stack.empty())
     {
         update_stamp = Timers::read(0);
-        update_time = last_update - update_stamp;
+        update_time = update_stamp - last_update;
         stack.back()->update(update_time);
         last_update = update_stamp;
 
-        if (Timers::read(0) > loop_next)
+        if (Timers::read(0) < loop_next)
         {
             frame_stamp = Timers::read(0);
-            frame_time = last_frame - frame_stamp;
+            frame_time = frame_stamp - last_frame;
             stack.back()->render(frame_time);
             last_frame = frame_stamp;
 
@@ -63,8 +63,7 @@ void STATEMACHINE::run()
         if (isKeyPressed(KEY_NSPIRE_ESC))
             this->pop();
 
-        while (Timers::read(0) > loop_next)
-            ;
-        loop_next -= loop_time;
+        while (Timers::read(0) < loop_next);
+        loop_next += loop_time;
     }
 }