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

cami at codespeak.net cami at codespeak.net
Tue Apr 8 14:03:05 CEST 2008


Author: cami
Date: Tue Apr  8 14:03:04 2008
New Revision: 53576

Modified:
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/interrupt.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/serial.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cpu.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_serial.py
Log:
added serial test
updated serial
added cpu test
fixed some bugs in cpu



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	Tue Apr  8 14:03:04 2008
@@ -325,7 +325,7 @@
      # Interrupts
     def handlePendingInterrupt(self):
         if self.halted:
-            if (self.interrupt.isPending()):
+            if self.interrupt.isPending():
                 self.halted = False
                 self.cycles -= 4
             elif (self.cycles > 0):

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/interrupt.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/interrupt.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/interrupt.py	Tue Apr  8 14:03:04 2008
@@ -88,8 +88,8 @@
     def getInterruptEnable(self):
         return int(self.enable)
 
-    def setInterruptEnable(self, data):
-        self.enable = bool(data)
+    def setInterruptEnable(self, isEnabled=True):
+        self.enable = bool(isEnabled)
         
     def getInterruptFlag(self):
         flag = 0x00

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	Tue Apr  8 14:03:04 2008
@@ -15,14 +15,14 @@
         self.sb = 0x00
         self.sc = 0x00
 
-    def cycles(self):
+    def getCycles(self):
         return self.cycles
 
     def emulate(self, ticks):
-        if ((self.sc & 0x81) != 0x81):
+        if (self.sc & 0x81) != 0x81:
             return
         self.cycles -= ticks
-        if (self.cycles <= 0):
+        if self.cycles <= 0:
             self.sb = 0xFF
             self.sc &= 0x7F
             self.cycles = constants.SERIAL_IDLE_CLOCK

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cpu.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cpu.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cpu.py	Tue Apr  8 14:03:04 2008
@@ -1241,9 +1241,39 @@
     assert_default_registers(cpu, pc=value+1, sp=2)
     
 def test_handleInterrupt():
-    py.test.skip("figuring out how to do it")
     cpu = get_cpu()
+    cpu.halted = True
+    cpu.cycles = 0xFF
+    cpu.handlePendingInterrupt()
+    assert cpu.cycles == 0
     
+    cpu.reset()
+    cpu.halted = True
+    cpu.interrupt.setInterruptEnable()
+    cpu.interrupt.vBlank.setPending()
+    assert cpu.interrupt.isPending() == True
+    cpu.cycles = 4
+    cpu.handlePendingInterrupt()
+    assert cpu.cycles == 0
+    assert cpu.halted == False
+    
+    cpu.reset()
+    cpu.halted = False
+    cpu.ime = True
+    cpu.pc.set(0x1234)
+    cpu.sp.set(0x02)
+    sp = cpu.sp.get()
+    cpu.interrupt.setInterruptEnable()
+    cpu.interrupt.vBlank.setPending()
+    cpu.interrupt.lcd.setPending()
+    assert cpu.interrupt.isPending() == True
+    cpu.cycles = 0
+    cpu.handlePendingInterrupt()
+    assert cpu.cycles == 0
+    assert cpu.halted == False 
+    assert_default_registers(cpu, pc=cpu.interrupt.vBlank.callCode, sp=sp-2)
+    assert cpu.pop() == 0x34
+    assert cpu.pop() == 0x12
 
 # ld_PC_HL 
 def test_0xE9():

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_serial.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_serial.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_serial.py	Tue Apr  8 14:03:04 2008
@@ -0,0 +1,55 @@
+
+from pypy.lang.gameboy import constants
+from pypy.lang.gameboy.interrupt import *
+from pypy.lang.gameboy.serial import *
+
+
+def get_serial():
+    return Serial(Interrupt())
+
+def test_reset():
+    serial = get_serial()
+    serial.cycles = 12
+    serial.sb = 12
+    serial.sc = 12
+    serial.reset()
+    assert serial.cycles == constants.SERIAL_CLOCK
+    assert serial.sb == 0
+    assert serial.sc == 0
+    
+    
+def test_setSerialControl():
+    serial = get_serial()
+    value = 0x12
+    serial.setSerialControl(value)
+    assert serial.getSerialControl() == value
+    assert serial.cycles == constants.SERIAL_IDLE_CLOCK + constants.SERIAL_CLOCK
+    
+    
+def test_emulate():
+    serial = get_serial()
+    serial.sc = 0x00
+    serial.emulate(20)
+    assert serial.cycles == constants.SERIAL_CLOCK
+    assert serial.sb == 0
+    assert serial.sc == 0
+    
+    serial.reset()
+    serial.sc = 0x81
+    serial.cycles = 10
+    cycles = serial.cycles
+    serial.emulate(2)
+    assert serial.cycles > 0
+    assert cycles-serial.cycles == 2
+    assert serial.sb == 0
+    assert serial.sc == 0x81
+    assert serial.interrupt.serial.isPending() == False
+    
+    serial.reset()
+    serial.sc = 0x81
+    serial.cycles = 0
+    serial.emulate(2)
+    assert serial.sb == 0xFF
+    assert serial.sc == 0x81 & 0x7F
+    assert serial.cycles == constants.SERIAL_IDLE_CLOCK
+    assert serial.interrupt.serial.isPending() == True
\ No newline at end of file



More information about the Pypy-commit mailing list