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

tverwaes at codespeak.net tverwaes at codespeak.net
Thu Mar 5 02:19:02 CET 2009


Author: tverwaes
Date: Thu Mar  5 02:19:00 2009
New Revision: 62552

Modified:
   pypy/trunk/pypy/lang/gameboy/gameboy_implementation.py
   pypy/trunk/pypy/lang/gameboy/video.py
   pypy/trunk/pypy/lang/gameboy/video_register.py
   pypy/trunk/pypy/lang/gameboy/video_sprite.py
Log:
moving around some code and cleaning up. tiles don't need pointers to video if
they get the line as an argument 


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	Thu Mar  5 02:19:00 2009
@@ -10,6 +10,8 @@
 
 use_rsdl = True
 # use_rsdl = False
+use_tile_screen = True
+
 if use_rsdl:
     from pypy.rlib.rsdl import RSDL, RSDL_helper
     from pypy.rpython.lltypesystem import lltype, rffi
@@ -109,14 +111,24 @@
     def __init__(self):
         VideoDriver.__init__(self)
         self.create_screen()
+        #self.create_tile_screen()
         self.map = []
-    
+
+    #def create_tile_screen(self):
+    #     if use_rsdl and use_tile_screen:
+    #        self.tile_screen = RSDL.SetVideoMode(128, 128, 32, 0)    
+
     def create_screen(self):
         if use_rsdl:
             self.screen = RSDL.SetVideoMode(self.width, self.height, 32, 0)
         
     def update_display(self):
         if use_rsdl:
+            # if use_tile_screen:
+            #    RSDL.LockSurface(self.tile_screen)
+            #    self.draw_tile_pixels()
+            #    RSDL.UnlockSurface(self.tile_screen)
+            #    RSDL.Flip(self.tile_screen)
             RSDL.LockSurface(self.screen)
             self.draw_pixels()
             RSDL.UnlockSurface(self.screen)
@@ -130,6 +142,13 @@
             for x in range(self.width):
                 color = VideoDriverImplementation.COLOR_MAP[self.get_pixel_color(x, y)]
                 RSDL_helper.set_pixel(self.screen, x, y, color)
+
+    def draw_tile_pixels(self):
+        for y in range(128):
+            for x in range(128):
+                #color = VideoDriverImplementation.COLOR_MAP[self.get_pixel_color(x, y)]
+                #RSDL_helper.set_pixel(self.screen, x, y, color)
+                pass
         
     def draw_ascii_pixels(self):
             str = []

Modified: pypy/trunk/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video.py	Thu Mar  5 02:19:00 2009
@@ -52,7 +52,7 @@
         self.tile_data = [self.tile_data_0, self.tile_data_1]
 
     def create_tile_data(self):
-        return [Tile(i, self) for i in range(TILE_DATA_SIZE / 2)]
+        return [Tile() for i in range(TILE_DATA_SIZE / 2)]
         
     def update_tile(self, address, data):
         self.get_tile(address).set_data_at(address, data);
@@ -77,6 +77,12 @@
         tile_group = map[tile_map_index >> 5]
         return tile_group, tile_map_index & 0x1F
 
+    def get_selected_tile_data_space(self):
+        if self.control.background_and_window_lower_tile_data_selected:
+            return self.tile_data_0
+        else:
+            return self.tile_data_1
+
     def get_tile_map(self, address):
         tile_group, group_index = self.select_tile_group_for(address)
         return tile_group[group_index]

Modified: pypy/trunk/pypy/lang/gameboy/video_register.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_register.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video_register.py	Thu Mar  5 02:19:00 2009
@@ -145,9 +145,3 @@
 
         if previous_big_sprites != self.big_sprites:
             self.video.update_sprite_size()
-        
-    def get_selected_tile_data_space(self):
-        if self.background_and_window_lower_tile_data_selected:
-            return self.video.tile_data_0
-        else:
-            return self.video.tile_data_1

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	Thu Mar  5 02:19:00 2009
@@ -118,16 +118,15 @@
         return value
         
     def hide_check(self):
-        if self.y <= 0  or self.y >= GAMEBOY_SCREEN_WIDTH:
+        if self.y <= 0 or self.y >= GAMEBOY_SCREEN_WIDTH:
             self.hidden = True
-        elif self.x <= 0  or self.x >= GAMEBOY_SCREEN_WIDTH+SPRITE_SIZE:
+        elif self.x <= 0 or self.x >= GAMEBOY_SCREEN_WIDTH+SPRITE_SIZE:
             self.hidden = True
         else:
             self.hidden = False
         return self.hidden
         
     def get_tile_number(self):
-        #return self.tile.id
         return self.tile_number
     
     def get_width(self):
@@ -175,22 +174,20 @@
             return self.get_lower_tile()
 
     def draw(self, lastx):
-        self.get_tile_for_current_line().draw_for_sprite(self, lastx)
+        self.get_tile_for_current_line().draw_for_sprite(self, self.video.line, lastx)
 
 # -----------------------------------------------------------------------------
 
 class Tile(object):
     
-    def __init__(self, number, video):
-        self.video = video
-        self.number = number
+    def __init__(self):
         self.data = [0x00 for i in range(2*SPRITE_SIZE)]
 
-    def draw(self, x, y):
+    def draw(self, line, x, y):
         pattern = self.get_pattern_at(y << 1)
         for i in range(SPRITE_SIZE):
             value = (pattern >> (SPRITE_SIZE - 1 - i)) & 0x0101
-            self.video.line[x + i] = value
+            line[x + i] = value
         
     def set_tile_data(self, data):
         self.data = data
@@ -208,7 +205,7 @@
         return self.get_data_at(address) +\
                (self.get_data_at(address + 1) << 8)
 
-    def draw_for_sprite(self, sprite, lastx):
+    def draw_for_sprite(self, sprite, line, lastx):
         if sprite.x_flipped:
             convert, offset =  1, 0           # 0-7
         else:
@@ -225,8 +222,8 @@
             if bool(color):
                 if sprite.x + SPRITE_SIZE > lastx:
                     # Overlapped.
-                    self.video.line[x] &= 0x0101
-                self.video.line[x] |= color | mask
+                    line[x] &= 0x0101
+                line[x] |= color | mask
 
 # -----------------------------------------------------------------------------
 
@@ -246,13 +243,13 @@
 
     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()
+        tile_data = self.video.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)
+            tile.draw(self.video.line, x, y)
             group_index += 1
             x += SPRITE_SIZE
 



More information about the Pypy-commit mailing list