[pypy-svn] r54744 - in pypy/branch/gameboy-emulator/pypy: lang/gameboy lang/gameboy/test translator/goal

cami at codespeak.net cami at codespeak.net
Thu May 15 10:52:40 CEST 2008


Author: cami
Date: Thu May 15 10:52:38 2008
New Revision: 54744

Modified:
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboyImplementation.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/serial.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cartridge.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py
   pypy/branch/gameboy-emulator/pypy/translator/goal/targetgbrom4.py
Log:
traintravel office resluts commited


Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py	Thu May 15 10:52:38 2008
@@ -50,6 +50,7 @@
         self.mbc.write(address, data)
     
     def load(self, cartridge):
+        assert isinstance(cartridge, Cartridge)
         self.cartridge = cartridge
         self.rom  = self.cartridge.read()
         self.check_rom()
@@ -147,7 +148,7 @@
             self.load(file)
         
     def reset(self):
-        self.cartridge_name = None
+        #self.cartridge_name = None
         self.cartridge_file_path = None
         self.cartridge_file = None    
         self.battery_name = None
@@ -155,21 +156,21 @@
         self.battery_file = None
         
         
-    def load(self, cartridge_file_path):
-        cartridge_file_path = str(cartridge_file_path)
-        self.cartridge_file_path = cartridge_file_path
-        self.cartridge_name = os.path.basename(self.cartridge_file_path)
-        self.cartridge_file = open(cartridge_file_path)
-        self._load_battery(cartridge_file_path)
-        
-        
-    def _load_battery(self, cartridge_file_path):
-        self.battery_file_path = self._create_battery_file_path(cartridge_file_path)
+    def load(self, cartridge_path):
+        cartridge_path = str(cartridge_path)
+        self.cartridge_file_path = cartridge_path
+        #self.cartridge_name = os.path.basename(self.cartridge_file_path)
+        self.cartridge_file = file(cartridge_path, "r")
+        self.load_battery(cartridge_path)
+        
+        cartridge_path
+    def load_battery(self, cartridge_file_path):
+        self.battery_file_path = self.create_battery_file_path(cartridge_path)
         self.battery_name = os.path.basename(self.battery_file_path)
         if self.has_battery():
             self.battery_file = open(self.battery_file_path)
     
-    def _create_battery_file_path(self, cartridge_file_path):
+    def create_battery_file_path(self, cartridge_file_path):
         if cartridge_file_path.endswith(constants.CARTRIDGE_FILE_EXTENSION):
             return cartridge_file_path.replace(constants.CARTRIDGE_FILE_EXTENSION,
                     constants.BATTERY_FILE_EXTENSION)

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboyImplementation.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboyImplementation.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboyImplementation.py	Thu May 15 10:52:38 2008
@@ -1,17 +1,17 @@
 #!/usr/bin/env python 
-
+import time
 import pyglet
 pyglet.options['audio'] = ('openal', 'silent')
         
-from pyglet        import window
-from pyglet        import media
-from pyglet        import image
+from pyglet import window
+from pyglet import media
+from pyglet import image
 from pyglet.window import key
 
 from pypy.lang.gameboy.gameboy import *
 from pypy.lang.gameboy.joypad import JoypadDriver
-from pypy.lang.gameboy.video  import VideoDriver
-from pypy.lang.gameboy.sound  import SoundDriver
+from pypy.lang.gameboy.video import VideoDriver
+from pypy.lang.gameboy.sound import SoundDriver
 
 
 # GAMEBOY ----------------------------------------------------------------------
@@ -35,7 +35,9 @@
         
     def mainLoop(self):
         while not self.win.has_exit: 
-           pass
+            print "i"
+            self.emulate(5)
+            time.sleep(0.01)
         
 # VIDEO DRIVER -----------------------------------------------------------------
 
@@ -51,6 +53,9 @@
     def create_image_buffer(self):
         self.buffers = image.get_buffer_manager()
         self.image_buffer = self.buffers.get_color_buffer()
+        self.buffer_image_data = self.image_buffer.image_data
+        self.buffer_image_data.format = "RGB"
+        self.pixel_buffer = self.buffer_image_data.data
         
     def on_resize(self, width, height):
         pass
@@ -59,9 +64,15 @@
         self.win.set_size(self.width, self.height)
         
     def update_display(self):
+        self.buffer_image_data.data = map(self.pixel_to_byte, self.pixel_buffer)
         self.image_buffer.blit(0, 0)
         self.win.flip()
         
+    def pixel_to_byte(self, int_number):
+        return struct.pack("B", (int_number) & 0xFF, 
+                                (int_number >> 8) & 0xFF, 
+                                (int_number >> 16) & 0xFF)
+        
         
 # JOYPAD DRIVER ----------------------------------------------------------------
 
@@ -87,12 +98,12 @@
         self.win.on_key_press = self.on_key_press
         self.win.on_key_release = self.on_key_press
         
-    def on_key_press(symbol, modifiers): 
+    def on_key_press(self, symbol, modifiers): 
         pressButtonFunction = self.get_button_handler(symbol, modifiers)
         if pressButtonFunction != None:
             pressButtonFunction(True)
     
-    def on_key_release(symbol, modifiers): 
+    def on_key_release(self, symbol, modifiers): 
         pressButtonFunction = self.get_button_handler(symbol, modifiers)
         if pressButtonFunction != None:
             pressButtonFunction(False)
@@ -132,12 +143,7 @@
     
 # ==============================================================================
 
-if __name__ == '__main__':
-    entry_point()
-
-
-
-def entry_point(args):
+def entry_point(args=None):
     gameboy = GameBoyImplementation()
 
 
@@ -145,3 +151,6 @@
 
 def target(*args):
     return entry_point, None
+
+if __name__ == '__main__':
+    entry_point()
\ No newline at end of file

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/serial.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/serial.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/serial.py	Thu May 15 10:52:38 2008
@@ -14,7 +14,7 @@
         self.reset()
 
     def reset(self):
-        self.cycles = constants.SERIAL_CLOCK
+        self.cycles = int(constants.SERIAL_CLOCK)
         self.sb = 0x00
         self.sc = 0x00
 

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cartridge.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cartridge.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cartridge.py	Thu May 15 10:52:38 2008
@@ -43,7 +43,7 @@
 def test_cartridge_init(): 
     cartridge = get_cartridge()
     
-    assert cartridge.cartridge_name is None
+    #assert cartridge.cartridge_name is None
     assert cartridge.cartridge_file_path is None
     assert cartridge.cartridge_file is None
     
@@ -58,7 +58,7 @@
     romFilePath = ROM_PATH+"/rom1/"+romName
     
     cartridge.load(romFilePath)
-    assert cartridge.cartridge_name == romName
+    #assert cartridge.cartridge_name == romName
     assert cartridge.cartridge_file_path == romFilePath
     assert cartridge.cartridge_file is not None
     

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/video.py	Thu May 15 10:52:38 2008
@@ -478,7 +478,7 @@
                 self.objects[rightmost] = data
 
     def draw_tiles(self, x, tileMap, tileData):
-        while (x < 168):
+        while x < 168:
             if (self.control & 0x10) != 0:
                 tile = self.vram[tileMap] & 0xFF
             else:
@@ -489,7 +489,7 @@
             
     def get_pattern(self, address):
         pattern = self.vram[address]      & 0xFF
-        pattern +=(self.vram[address + 1] & 0xFF) << 8
+        pattern += (self.vram[address + 1] & 0xFF) << 8
         return pattern
 
     def draw_object(self, setter):
@@ -585,8 +585,8 @@
 class VideoDriver(object):
     
     def __init__(self):
-        self.width = constants.GAMEBOY_SCREEN_WIDTH
-        self.height = constants.GAMEBOY_SCREEN_HEIGHT
+        self.width = int(constants.GAMEBOY_SCREEN_WIDTH)
+        self.height = int(constants.GAMEBOY_SCREEN_HEIGHT)
         self.clear_pixels()
         
     def clear_pixels(self):

Modified: pypy/branch/gameboy-emulator/pypy/translator/goal/targetgbrom4.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/translator/goal/targetgbrom4.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/translator/goal/targetgbrom4.py	Thu May 15 10:52:38 2008
@@ -23,13 +23,13 @@
 
 
 def entry_point(argv):
-    #if len(argv) > 1:
-    #    filename = argv[1]
-    #else:
-    #    print "usage:", argv[0], "<image name>"
-    #    return -1
+    if len(argv) > 1:
+        filename = argv[1]
+    else:
+        filename = ROM_PATH+"/rom4/rom4.gb"
     gameBoy = GameBoy()
-    gameBoy.load_cartridge_file(ROM_PATH+"/rom4/rom4.gb")#filename)
+    #gameBoy.load_cartridge_file(ROM_PATH+"/rom4/rom4.gb")#filename)
+    gameBoy.load_cartridge_file(str(filename))
     gameBoy.emulate(EMULATION_CYCLES)
 
 # _____ Define and setup target ___



More information about the Pypy-commit mailing list