[pypy-svn] r62412 - in pypy/trunk/pypy/lang/gameboy: . test

cami at codespeak.net cami at codespeak.net
Mon Mar 2 17:29:04 CET 2009


Author: cami
Date: Mon Mar  2 17:29:04 2009
New Revision: 62412

Modified:
   pypy/trunk/pypy/lang/gameboy/test/test_video.py
   pypy/trunk/pypy/lang/gameboy/video.py
   pypy/trunk/pypy/lang/gameboy/video_sprite.py
Log:
compacting draw_pixels_line and conquerred the array bounds ;)


Modified: pypy/trunk/pypy/lang/gameboy/test/test_video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/test/test_video.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/test/test_video.py	Mon Mar  2 17:29:04 2009
@@ -116,9 +116,12 @@
     value = 0xF6
     video.control.lcd_enabled = False
     
+    import pdb
+    pdb.set_trace()
     video.write(0xFF45, value)
     
     assert video.line_y_compare == value
+    assert video.status.read() == 0x0
     
     video.control.write(0x80)
     

Modified: pypy/trunk/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video.py	Mon Mar  2 17:29:04 2009
@@ -53,12 +53,20 @@
         self.create_sprites()
         self.reset()
     
+    # -----------------------------------------------------------------------
+    
     def create_tile_maps(self):
         # create the maxumal possible sprites
-        self.tile_map_0 = [None] * 32 * 32
-        self.tile_map_1 = [None] * 32 * 32
+        self.tile_map_0 = self.create_tile_map(32 * 32)
+        self.tile_map_1 = self.create_tile_map(32 * 32)
         self.tile_maps = [self.tile_map_0, self.tile_map_1]
     
+    def create_tile_map(self, size):
+        tile_map = [None] * size
+        for i in range(size):
+            tile_map[i] = Tile(self)
+        return tile_map
+        
     def update_tile(self, address, data):
         # XXX to implement
         #self.get_tile(address).set_data();
@@ -75,6 +83,7 @@
         #    tile.reset()
         pass
     
+    # -----------------------------------------------------------------------
     def create_sprites(self):
         self.sprites = [None] * 40
         for i in range(40):
@@ -102,6 +111,8 @@
         #for sprite in self.sprites:
         #    sprite.reset()
         pass
+    
+    # -----------------------------------------------------------------------
          
     def reset(self):
         self.control.reset()
@@ -410,7 +421,7 @@
        self.update_tile(address, data)
     
     def get_vram(self, address):
-        #self.get_tile(address).get_data()[address % 4]
+        #return self.get_tile(address).get_data()[address % 4]
         return self.vram[address - constants.VRAM_ADDR]
     
     # emulation ----------------------------------------------------------------
@@ -457,15 +468,14 @@
             lastx = sprite.x
             
     def scan_sprites(self):
-        count = 0
         # search active objects
+        count = 0
         for sprite in self.sprites:
-            #if sprite.hidden: continue
-            if not sprite.intersects_current_line(self): continue
-            self.objects[count] = sprite
-            count += 1
-            if count >= constants.OBJECTS_PER_LINE:
-                break
+            if sprite.is_shown_on_current_line(self):
+                self.objects[count] = sprite
+                count += 1
+                if count >= constants.OBJECTS_PER_LINE:
+                    break
         self.sort_scan_sprite(count)
         return count
 
@@ -475,9 +485,7 @@
         for index in range(count):
             highest = index
             for right in range(index+1, count):
-                
-                if (self.objects[right].x) > \
-                   (self.objects[highest].x):
+                if self.objects[right].x > self.objects[highest].x:
                     highest = right
             self.objects[index], self.objects[highest] = \
                     self.objects[highest], self.objects[index]

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	Mon Mar  2 17:29:04 2009
@@ -130,9 +130,6 @@
         else:
             return SPRITE_SIZE
          
-    def overlaps_on_line(self, sprite, line):
-        return False
-    
     def get_tile_size(self, video):
          if video.control.big_sprite_size_selected:
             return 15
@@ -143,6 +140,9 @@
         y = self.current_line_y(video)
         return y >= 0 and y <= self.get_tile_size(video)
     
+    def is_shown_on_current_line(self, video):
+        return not self.hidden and self.intersects_current_line(video)
+         
     def current_line_y(self, video):
         return video.line_y - self.y + 2 * SPRITE_SIZE
     
@@ -198,7 +198,8 @@
     
 class Tile(object):
     
-    def __init__(self):
+    def __init__(self, video):
+        self.video = video
         self.reset()
         
     def reset(self):



More information about the Pypy-commit mailing list