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

tverwaes at codespeak.net tverwaes at codespeak.net
Fri Mar 6 17:20:34 CET 2009


Author: tverwaes
Date: Fri Mar  6 17:20:34 2009
New Revision: 62654

Modified:
   pypy/trunk/pypy/lang/gameboy/video.py
   pypy/trunk/pypy/lang/gameboy/video_meta.py
   pypy/trunk/pypy/lang/gameboy/video_mode.py
   pypy/trunk/pypy/lang/gameboy/video_register.py
   pypy/trunk/pypy/lang/gameboy/video_sprite.py
Log:
lots of refactorings which now allow the window to be draw separately as
well... what was that jmario coder thinking? :)


Modified: pypy/trunk/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video.py	Fri Mar  6 17:20:34 2009
@@ -78,7 +78,7 @@
         return tile_group, tile_map_index & 0x1F
 
     def get_selected_tile_data_space(self):
-        if self.control.background_and_window_lower_tile_data_selected:
+        if self.control.lower_tile_data_selected:
             return self.tile_data_0
         else:
             return self.tile_data_1
@@ -457,10 +457,10 @@
         self.driver.update_gb_display()
 
     def tile_index_flip(self):
-        if self.control.background_and_window_lower_tile_data_selected:
-            return 0x00
+        if self.control.lower_tile_data_selected:
+            return 0
         else:
-            return 0x80
+            return 1 << 7 # First and last 128 tiles are swapped.
 
     def draw_window(self, window, line_y, line):
         if window.enabled:

Modified: pypy/trunk/pypy/lang/gameboy/video_meta.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_meta.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video_meta.py	Fri Mar  6 17:20:34 2009
@@ -68,8 +68,20 @@
     def update_screen(self):
         for y in range(self.height):
             line = self.screen[y]
+            for i in range(len(line)):
+                line[i] = 0x00
             self.gameboy.video.draw_window(self.get_window(), y, line)
 
+class WindowPreview(PreviewWindow):
+    def get_window(self):
+        # XXX Broken for now
+        return self.gameboy.video.window
+
+class BackgroundPreview(PreviewWindow):
+    def get_window(self):
+        return self.gameboy.video.background
+
+
 class MapViewer(VideoMetaWindow):
     def __init__(self, gameboy):
         self.map_x = 32
@@ -104,15 +116,6 @@
     def get_map(self):
         return self.gameboy.video.tile_map_1
 
-class WindowPreview(PreviewWindow):
-    def get_window(self):
-        # XXX Broken for now
-        return self.gameboy.video.window
-
-class BackgroundPreview(PreviewWindow):
-    def get_window(self):
-        return self.gameboy.video.background
-
 class SpriteWindow(VideoMetaWindow):
     def __init__(self, gameboy):
         self.sprites_y = 8

Modified: pypy/trunk/pypy/lang/gameboy/video_mode.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_mode.py	(original)
+++ pypy/trunk/pypy/lang/gameboy/video_mode.py	Fri Mar  6 17:20:34 2009
@@ -144,11 +144,10 @@
         self.video.v_blank_interrupt_flag.set_pending()
         
     def emulate_v_blank_other(self):
-        if self.video.line_y < 153:
+        if self.video.line_y <= GAMEBOY_SCREEN_HEIGHT + SPRITE_SIZE:
             self.emulate_v_blank_mode_1()
         else:
             self.video.line_y        = 0
-            self.video.window.line_y = 0
             self.set_between_end()
         self.emulate_hblank_line_y_compare() 
                 

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	Fri Mar  6 17:20:34 2009
@@ -91,21 +91,21 @@
         self.reset()
         
     def reset(self):
-        self.lcd_enabled                              = True
-        self.window.upper_tile_map_selected           = False
-        self.window.enabled                           = False
-        self.background_and_window_lower_tile_data_selected  = True
-        self.background.upper_tile_map_selected       = False
-        self.big_sprites                              = False
-        self.sprites_enabled                          = False
-        self.background.enabled                       = True
+        self.lcd_enabled                        = True
+        self.window.upper_tile_map_selected     = False
+        self.window.enabled                     = False
+        self.lower_tile_data_selected           = True
+        self.background.upper_tile_map_selected = False
+        self.background.enabled                 = True
+        self.big_sprites                        = False
+        self.sprites_enabled                    = False
         
     def read(self):
         value = 0
         value += int(self.lcd_enabled)                        << 7 
         value += int(self.window.upper_tile_map_selected)     << 6 
         value += int(self.window.enabled)                     << 5
-        value += int(self.background_and_window_lower_tile_data_selected)  << 4
+        value += int(self.lower_tile_data_selected)           << 4
         value += int(self.background.upper_tile_map_selected) << 3
         value += int(self.big_sprites)                        << 2
         value += int(self.sprites_enabled)                    << 1
@@ -132,16 +132,12 @@
             
         was_enabled         = self.window.enabled
         self.window.enabled = bool(value & (1 << 5))
-        if not was_enabled and self.window.enabled:
-            self.window.switch_on()
-
-        self.window.upper_tile_map_selected          = bool(value & (1 << 6))
-        self.background_and_window_lower_tile_data_selected = \
-                                                       bool(value & (1 << 4))
-        self.background.upper_tile_map_selected      = bool(value & (1 << 3))
-        self.big_sprites                             = bool(value & (1 << 2))
-        self.sprites_enabled                         = bool(value & (1 << 1))
-        self.background.enabled                      = bool(value & (1 << 0))
+        self.window.upper_tile_map_selected     = bool(value & (1 << 6))
+        self.lower_tile_data_selected           = bool(value & (1 << 4))
+        self.background.upper_tile_map_selected = bool(value & (1 << 3))
+        self.big_sprites                        = bool(value & (1 << 2))
+        self.sprites_enabled                    = bool(value & (1 << 1))
+        self.background.enabled                 = bool(value & (1 << 0))
 
         if previous_big_sprites != self.big_sprites:
             self.video.update_sprite_size()

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	Fri Mar  6 17:20:34 2009
@@ -249,7 +249,9 @@
 
 class Drawable(object):
     def __init__(self, video):
-        self.video = video
+        self.video                   = video
+        self.enabled                 = False
+        self.upper_tile_map_selected = False
         self.reset()
 
     def get_tile_map_space(self):
@@ -282,28 +284,20 @@
     def reset(self):
         self.x       = 0
         self.y       = 0
-        self.line_y  = 0
-        self.enabled = False
-        self.upper_tile_map_selected  = False
-        
-    def switch_on(self):
-        if self.line_y == 0 and self.video.line_y > self.y:
-            self.line_y = GAMEBOY_SCREEN_HEIGHT
 
     def draw_clean_line(self, line):
         pass
        
     def draw_line(self, line_y, tile_data, tile_index_flip, line):
-        if line_y >= self.y and self.x < GAMEBOY_SCREEN_WIDTH+SPRITE_SIZE-1 and \
-           self.line_y < GAMEBOY_SCREEN_HEIGHT:
+        relative_y = line_y - self.y
+        if relative_y >= 0 and relative_y < GAMEBOY_SCREEN_HEIGHT:
 
             tile_map   = self.get_tile_map_space()
-            tile_group = tile_map[self.line_y >> 3]
+            tile_group = tile_map[relative_y >> 3]
 
             self.draw_tiles(self.x + 1, tile_group,
-                            self.line_y, tile_data,
+                            relative_y, tile_data,
                             tile_index_flip, line)
-            self.line_y += 1
 
 # -----------------------------------------------------------------------------
 
@@ -314,8 +308,6 @@
         # be displayed in the left upper corner of the screen.
         self.scroll_x   = 0
         self.scroll_y   = 0
-        self.enabled    = True
-        self.upper_tile_map_selected = False
       
     def draw_clean_line(self, line):
         for x in range(len(line)):



More information about the Pypy-commit mailing list