[pypy-svn] r54376 - in pypy/branch/gameboy-emulator/pypy/lang/gameboy: . test

cami at codespeak.net cami at codespeak.net
Sat May 3 17:19:39 CEST 2008


Author: cami
Date: Sat May  3 17:19:38 2008
New Revision: 54376

Modified:
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/cartridge.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py
Log:
started to complete rom test
bug in cpu/ram read returns None
bug fixes



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	Sat May  3 17:19:38 2008
@@ -80,7 +80,10 @@
     def getMemoryBankType(self):
         return self.rom[constants.CARTRIDGE_TYPE_ADDRESS] & 0xFF
     
-    def getRom(self):
+    def getMemoryBank(self):
+        return self.mbc
+
+    def getROM(self):
         return self.rom
         
     def getROMSize(self):
@@ -130,6 +133,8 @@
         return MEMORY_BANK_MAPPING[type](rom, ram, clockDriver)
 
 
+# ------------------------------------------------------------------------------
+
     
 class Cartridge(object):
     """

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py	Sat May  3 17:19:38 2008
@@ -207,7 +207,8 @@
         self.a = Register(self, constants.RESET_A)
         self.f = FlagRegister(self)
         self.af = DoubleRegister(self, self.a, self.f)
-
+        
+        self.rom = []
         self.reset()
 
     def reset(self):
@@ -319,8 +320,8 @@
     def emulate(self, ticks):
         self.cycles += ticks
         self.handlePendingInterrupt()
-        while (self.cycles > 0):
-            self.execute()
+        while self.cycles > 0:
+            self.execute(self.fetch())
 
      # Interrupts
     def handlePendingInterrupt(self):

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py	Sat May  3 17:19:38 2008
@@ -1,7 +1,7 @@
 """
 PyBoy GameBoy (TM) Emulator
  
-Gameboy Scheduler and Memory Mapper
+GameBoy Scheduler and Memory Mapper
 
 """
 from pypy.lang.gameboy import constants
@@ -26,25 +26,26 @@
     def createDrivers(self):
         self.clock = Clock()
         self.joypadDriver = JoypadDriver()
-        self.videoDriver = VideoDriver()
-        self.soundDriver = SoundDriver()
+        self.videoDriver  = VideoDriver()
+        self.soundDriver  = SoundDriver()
         
     def createGamboyElements(self): 
-        self.ram = RAM()
+        self.ram    = RAM()
         self.cartridgeManager = CartridgeManager(self.clock)
         self.interrupt = Interrupt()
-        self.cpu = CPU(self.interrupt, self)
+        self.cpu    = CPU(self.interrupt, self)
         self.serial = Serial(self.interrupt)
-        self.timer = Timer(self.interrupt)
+        self.timer  = Timer(self.interrupt)
         self.joypad = Joypad(self.joypadDriver, self.interrupt)
-        self.video = Video(self.videoDriver, self.interrupt, self)
-        self.sound = Sound(self.soundDriver)  
+        self.video  = Video(self.videoDriver, self.interrupt, self)
+        self.sound  = Sound(self.soundDriver)  
 
     def getCartridgeManager(self):
         return self.cartridgeManager
     
     def loadCartridge(self, cartridge):
         self.cartridgeManager.load(cartridge)
+        self.cpu.setROM(self.cartridgeManager.getROM())
         
     def loadCartridgeFile(self, path):
         self.loadCartridge(Cartridge(path))
@@ -55,7 +56,6 @@
     def setFrameSkip(self, frameSkip):
         self.video.setFrameSkip(frameSkip)
 
-
     def save(self, cartridgeName):
         self.cartridge.save(cartridgeName)
 
@@ -75,16 +75,16 @@
         self.joypad.reset()
         self.video.reset()
         self.sound.reset()
-        self.cpu.setROM(self.cartridge.getROM())
+        self.cpu.setROM(self.cartridgeManager.getROM())
         self.drawLogo()
 
     def cycles(self):
-        return min( self.video.cycles(), self.serial.cycles(),
-                    self.timer.cycles(), self.sound.cycles(),
-                    self.joypad.cycles())
+        return min( self.video.getCycles(), self.serial.getCycles(),
+                    self.timer.getCycles(), self.sound.getCycles(),
+                    self.joypad.getCycles())
 
     def emulate(self, ticks):
-        while (ticks > 0):
+        while ticks > 0:
             count = self.cycles()
             self.cpu.emulate(count)
             self.serial.emulate(count)
@@ -95,38 +95,38 @@
             ticks -= count
 
     def write(self, address, data):
-        self.getreceiver(address).write(address, data)
+        self.getReceiver(address).write(address, data)
 
     def read(self, address):
-        self.getreceiver(address).read(address)
+        self.getReceiver(address).read(address)
 
-    def getreceiver(self, address):
+    def getReceiver(self, address):
         if 0x0000 <= address <= 0x7FFF:
-            return Gameboy.cartridge
+            return self.cartridgeManager.getMemoryBank()
         elif 0x8000 <= address <= 0x9FFF:
-            return Gameboy.video
+            return self.video
         elif 0xA000 <= address <= 0xBFFF:
-            return Gameboy.cartridge
+            return self.cartridgeManager.getMemoryBank()
         elif 0xC000 <= address <= 0xFDFF:
-            return Gameboy.ram
+            return self.ram
         elif 0xFE00 <= address <= 0xFEFF:
-            return Gameboy.video
+            return self.video
         elif 0xFF00 <= address <= 0xFF00:
-            return Gameboy.joypad
+            return self.joypad
         elif 0xFF01 <= address <= 0xFF02:
-            return Gameboy.serial
+            return self.serial
         elif 0xFF04 <= address <= 0xFF07:
-            return Gameboy.timer
+            return self.timer
         elif 0xFF0F <= address <= 0xFF0F:
-            return Gameboy.interrupt
+            return self.interrupt
         elif 0xFF10 <= address <= 0xFF3F:
-            return Gameboy.sound
+            return self.sound
         elif 0xFF40 <= address <= 0xFF4B:
-            return Gameboy.video
+            return self.video
         elif 0xFF80 <= address <= 0xFFFE:
-            return Gameboy.ram
+            return self.ram
         elif 0xFFFF <= address <= 0xFFFF:
-            return Gameboy.interrupt
+            return self.interrupt
 
     def drawLogo(self):
         for index in range(0, 48):

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/joypad.py	Sat May  3 17:19:38 2008
@@ -18,7 +18,7 @@
         self.buttonCode = 0xF
         self.cycles = constants.JOYPAD_CLOCK
 
-    def cycles(self):
+    def getCycles(self):
         return self.cycles
 
     def emulate(self, ticks):

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/sound.py	Sat May  3 17:19:38 2008
@@ -551,7 +551,7 @@
     def stop(self):
         self.driver.stop()
 
-    def cycles(self):
+    def getCycles(self):
         return self.cycles
 
     def emulate(self, ticks):

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_rom.py	Sat May  3 17:19:38 2008
@@ -7,7 +7,9 @@
 
 
 ROM_PATH = str(py.magic.autopath().dirpath().dirpath())+"/rom"
+EMULATION_CYCLES = 64
 
+# ------------------------------------------------------------------------------
 
 
 def test_rom1():
@@ -29,35 +31,47 @@
     
 
 def test_rom3():
+    """ some NOP and an endless loop at the end '"""
     gameBoy = GameBoy()
     gameBoy.loadCartridgeFile(ROM_PATH+"/rom3/rom3.gb")
+    gameBoy.emulate(EMULATION_CYCLES)
     
     
 def test_rom4():
     gameBoy = GameBoy()
     gameBoy.loadCartridgeFile(ROM_PATH+"/rom4/rom4.gb")
+    gameBoy.emulate(EMULATION_CYCLES)
     
     
 def test_rom5():
     gameBoy = GameBoy()
     gameBoy.loadCartridgeFile(ROM_PATH+"/rom5/rom5.gb")
+    gameBoy.emulate(EMULATION_CYCLES)
     
     
 def test_rom6():
     gameBoy = GameBoy()
     gameBoy.loadCartridgeFile(ROM_PATH+"/rom6/rom6.gb")
+    gameBoy.emulate(EMULATION_CYCLES)
     
     
 def test_rom7():
+    py.test.skip("cpu bug in storeMemoryAtExpandedFetchAddressInA")
     gameBoy = GameBoy()
     gameBoy.loadCartridgeFile(ROM_PATH+"/rom7/rom7.gb")
+    gameBoy.emulate(EMULATION_CYCLES)
     
     
 def test_rom8():
+    py.test.skip("cpu bug in storeMemoryAtExpandedFetchAddressInA")
     gameBoy = GameBoy()
     gameBoy.loadCartridgeFile(ROM_PATH+"/rom8/rom8.gb")
+    gameBoy.emulate(EMULATION_CYCLES)
     
     
 def test_rom9():
+    py.test.skip("cpu bug in storeMemoryAtExpandedFetchAddressInA")
     gameBoy = GameBoy()
-    gameBoy.loadCartridgeFile(ROM_PATH+"/rom9/rom9.gb")
\ No newline at end of file
+    gameBoy.loadCartridgeFile(ROM_PATH+"/rom9/rom9.gb")
+    gameBoy.emulate(EMULATION_CYCLES)
+    

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/timer.py	Sat May  3 17:19:38 2008
@@ -65,8 +65,8 @@
             self.timerClock =  self.timerCycles = constants.TIMER_CLOCK[data & 0x03]
         self.tac = data
 
-    def cycles(self):
-        if ((self.tac & 0x04) != 0 and self.timerCycles < self.dividerCycles):
+    def getCycles(self):
+        if (self.tac & 0x04) != 0 and self.timerCycles < self.dividerCycles:
                 return self.timerCycles
         return self.dividerCycles
 



More information about the Pypy-commit mailing list