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

tverwaes at codespeak.net tverwaes at codespeak.net
Wed Mar 4 23:54:49 CET 2009


Author: tverwaes
Date: Wed Mar  4 23:54:48 2009
New Revision: 62550

Modified:
   pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
   pypy/trunk/pypy/lang/gameboy/video.py
   pypy/trunk/pypy/lang/gameboy/video_sprite.py
Log:
propagating penalties


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 23:54:48 2009
@@ -23,6 +23,7 @@
     def __init__(self):
         GameBoy.__init__(self)
         self.is_running = False
+        self.penalty = 0.0
         if use_rsdl:
             self.init_sdl()
         
@@ -60,11 +61,13 @@
         # if use_rsdl:
          #    RSDL.Delay(100)
         spent = time.time() - start_time
-        left = (1.0/X) - spent
+        left = (1.0/X) + self.penalty - spent
         if left > 0:
             time.sleep(left)
+            self.penalty = 0.0
         else:
-            print "WARNING: Going too slow: ", spent, " ", left
+            self.penalty = left
+            # print "WARNING: Going too slow: ", spent, " ", left
         
     
     def handle_execution_error(self, error): 

Modified: pypy/trunk/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video.py	Wed Mar  4 23:54:48 2009
@@ -444,7 +444,7 @@
         self.driver.update_display()
 
     def clear_frame(self):
-        self.clear_pixels()
+        self.driver.clear_pixels()
         self.driver.update_display()
 
     def draw_line(self):
@@ -490,18 +490,6 @@
             self.shown_sprites[index], self.shown_sprites[highest] = \
                     self.shown_sprites[highest], self.shown_sprites[index]
 
-    def draw_tiles(self, x_start, tile_group, y, group_index=0):
-        x = x_start
-        tile_data = self.control.get_selected_tile_data_space()
-        while x < GAMEBOY_SCREEN_WIDTH+SPRITE_SIZE:
-            tile_index = tile_group[group_index % TILE_GROUP_SIZE]
-            if not self.control.background_and_window_lower_tile_data_selected:
-                tile_index ^= 0x80
-            tile = tile_data[tile_index]
-            tile.draw(x, y)
-            group_index += 1
-            x += SPRITE_SIZE
-     
     def draw_pixels_line(self):
         self.update_palette()
         pixels = self.driver.get_pixels()
@@ -509,9 +497,6 @@
         for x in range(SPRITE_SIZE, GAMEBOY_SCREEN_WIDTH+SPRITE_SIZE):
             pixels[offset + x] = self.palette[self.line[x]]
 
-    def clear_pixels(self):
-        self.driver.clear_pixels()
-
     def update_palette(self):
         if not self.dirty: return
         # bit 4/0 = BG color, 

Modified: pypy/trunk/pypy/lang/gameboy/video_sprite.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_sprite.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video_sprite.py	Wed Mar  4 23:54:48 2009
@@ -1,7 +1,5 @@
 
-from pypy.lang.gameboy import constants
-from pypy.lang.gameboy.constants import SPRITE_SIZE, GAMEBOY_SCREEN_WIDTH, \
-                                        GAMEBOY_SCREEN_HEIGHT
+from pypy.lang.gameboy.constants import *
 
 # -----------------------------------------------------------------------------
 
@@ -51,14 +49,14 @@
         """
         extracts the sprite data from an oam entry
         """
-        position = address % 4
-        if position == 0:
+        address %= 4
+        if address == 0:
             self.extract_y_position(data)
-        if position == 1:
+        if address == 1:
             self.extract_x_position(data)
-        if position == 2:
+        if address == 2:
             self.extract_tile_number(data)
-        if position == 3:
+        if address == 3:
             self.extract_attributes_and_flags(data)
         
     def extract_y_position(self, data):
@@ -161,7 +159,7 @@
         return self.video.get_tile_at(self.get_tile_address())
 
     def get_lower_tile(self):
-        return self.video.get_tile_at(self.get_tile_address()+1)
+        return self.video.get_tile_at(self.get_tile_address() + 1)
         
     def get_draw_y(self):
         y = self.current_line_y()
@@ -245,7 +243,18 @@
 
     def reset(self):
         raise Exception("Not implemented")
- 
+
+    def draw_tiles(self, x_start, tile_group, y, group_index=0):
+        x = x_start
+        tile_data = self.video.control.get_selected_tile_data_space()
+        while x < GAMEBOY_SCREEN_WIDTH+SPRITE_SIZE:
+            tile_index = tile_group[group_index % TILE_GROUP_SIZE]
+            if not self.video.control.background_and_window_lower_tile_data_selected:
+                tile_index ^= 0x80
+            tile = tile_data[tile_index]
+            tile.draw(x, y)
+            group_index += 1
+            x += SPRITE_SIZE
 
 class Window(Drawable):
     
@@ -267,7 +276,7 @@
             tile_map   = self.get_tile_map_space()
             tile_group = tile_map[self.line_y >> 5]
 
-            self.video.draw_tiles(self.x + 1, tile_group, self.line_y)
+            self.draw_tiles(self.x + 1, tile_group, self.line_y)
             self.line_y += 1
 
 # -----------------------------------------------------------------------------
@@ -292,4 +301,4 @@
 
         tile_map = self.get_tile_map_space()
         tile_group = tile_map[y >> 3]
-        self.video.draw_tiles(8 - (x % 8), tile_group, y, x >> 3)
+        self.draw_tiles(8 - (x % 8), tile_group, y, x >> 3)



More information about the Pypy-commit mailing list