[pypy-svn] r62532 - pypy/trunk/pypy/lang/gameboy

tverwaes at codespeak.net tverwaes at codespeak.net
Wed Mar 4 16:39:02 CET 2009


Author: tverwaes
Date: Wed Mar  4 16:39:00 2009
New Revision: 62532

Modified:
   pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
   pypy/trunk/pypy/lang/gameboy/timer.py
Log:
hardwiring the clock in the gameboy_implementation


Modified: pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py	Wed Mar  4 16:39:00 2009
@@ -6,6 +6,7 @@
 from pypy.lang.gameboy.sound import SoundDriver
 from pypy.lang.gameboy.timer import Clock
 from pypy.lang.gameboy import constants
+import time
 
 use_rsdl = True
 if use_rsdl:
@@ -49,10 +50,20 @@
     
     def emulate_cycle(self):
         # self.joypad_driver.button_up(True)
+        X = 1<<5
+        start_time = time.time()
         self.handle_events()
-        self.emulate(constants.GAMEBOY_CLOCK >> 2)
+        # Come back to this cycle every 1/X seconds
+        self.emulate(constants.GAMEBOY_CLOCK / X)
         if use_rsdl:
             RSDL.Delay(1)
+        spent = time.time() - start_time
+        left = (1.0/X) - spent
+        if left >= 0:
+            time.sleep(left)
+        else:
+            print "WARNING: Going to slow: ", spent, " ", left
+        
     
     def handle_execution_error(self, error): 
         if use_rsdl:

Modified: pypy/trunk/pypy/lang/gameboy/timer.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/timer.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/timer.py	Wed Mar  4 16:39:00 2009
@@ -156,5 +156,4 @@
         pass
     
     def get_time(self):
-        return int(time.time()*1000)
-        
+        return int(time.time())



More information about the Pypy-commit mailing list