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

cami at codespeak.net cami at codespeak.net
Tue Apr 8 12:25:55 CEST 2008


Author: cami
Date: Tue Apr  8 12:25:54 2008
New Revision: 53570

Modified:
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_cpu.py
   pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_register.py
Log:
fixed cycle bug for call
added register test



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 12:25:54 2008
@@ -51,7 +51,7 @@
                 self.cpu.cycles += 1
         else:
             self.setHi(hi, useCycles)
-            self.setLo(lo, useCycles)   
+            self.setLo(lo, useCycles) 
     
     def reset(self):
         self.set(self.resetValue, None, useCycles=False)
@@ -94,14 +94,14 @@
             self.hl = hl
             
         def set(self, value, useCycles=True):
-            self.cpu.write(self.hl.get(useCycles), value)
+            self.cpu.write(self.hl.get(useCycles), value) # 2 + 0
             if not useCycles:
                 self.cpu.cycles += 2
         
         def get(self, useCycles=True):
             if not useCycles:
                 self.cpu.cycles += 1
-            return self.cpu.read(self.hl.get(useCycles))
+            return self.cpu.read(self.hl.get(useCycles)) # 1
     
 # ------------------------------------------------------------------------------
   
@@ -336,7 +336,8 @@
     def lowerPendingInterrupt(self):
         for flag in self.interrupt.interruptFlags:
             if flag.isPending():
-                self.call(flag.callCode, disableIME=True, useCycles=False)
+                self.ime = False
+                self.call(flag.callCode, useCycles=False)
                 flag.setPending(False)
                 return
 
@@ -406,14 +407,12 @@
         self.cycles += 1
         
     # 4 cycles
-    def call(self, address, disableIME=False, useCycles=True):
-        if disableIME:
-            self.ime = False
+    def call(self, address, useCycles=True):
         self.push(self.pc.getHi(useCycles), useCycles) # 2 cycles
         self.push(self.pc.getLo(useCycles), useCycles) # 2 cycles
-        self.pc.set(address, useCycles)       # 1 cycle
+        self.pc.set(address, None, useCycles)       # 1 cycle
         if useCycles:
-            self.cycles += 2
+            self.cycles += 1
         
      # 1 cycle
     def ld(self, getter, setter):
@@ -531,12 +530,13 @@
             self.f.hFlag = True
         setter(data) # 1 cycle
 
-    # 1 cycle
+    # RLC 1 cycle
     def rotateLeftCircular(self, getter, setter):
-        s = (getter()  << 1) + (getter() >> 7)
+        data = getter()
+        s = (data  << 1) + (data >> 7)
         self.flagsAndSetterFinish(s, setter, 0x80)
 
-    # rotateLeftCircularA 1 cycle
+    # RLCA rotateLeftCircularA 1 cycle
     def rotateLeftCircularA(self):
         self.rotateLeftCircular(self.a.get, self.a.set)
 
@@ -551,7 +551,7 @@
     def rotateLeftA(self):
         self.rotateLeft(self.a.get, self.a.set)
         
-    # 1 cycle
+    # RRC 1 cycle
     def rotateRightCircular(self, getter, setter):
         s = (getter() >> 1) + (getter() << 7)
         self.flagsAndSetterFinish(s, setter) # 1 cycle
@@ -822,7 +822,8 @@
      # RETI 4 cycles
     def returnFormInterrupt(self):
         self.ret() # 4 cycles
-        self.enableInterrupts() # 1 cycle
+        self.enableInterrupts() # 1 cycle + others
+        self.cycles += 1
 
      # RST nn 4 cycles
     def restart(self, nn):
@@ -834,7 +835,7 @@
         self.cycles -= 1; 
 
     # 1 cycle
-    def enableInterrupts(self): 
+    def enableInterrupts(self):
         self.ime = True
         self.execute(self.fetch()) #  1
         self.handlePendingInterrupt()

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 12:25:54 2008
@@ -1231,7 +1231,6 @@
 
 # reti
 def test_0xD9_returnFormInterrupt():
-    py.test.skip("cycle bug in cpu")
     cpu = get_cpu()
     value = 0x1234
     cpu.sp.set(0)
@@ -1241,8 +1240,10 @@
     cycle_test(cpu, 0xD9, 4+2) 
     assert_default_registers(cpu, pc=value+1, sp=2)
     
-def test_0xD9_handleInterrupt():
+def test_handleInterrupt():
     py.test.skip("figuring out how to do it")
+    cpu = get_cpu()
+    
 
 # ld_PC_HL 
 def test_0xE9():
@@ -1321,12 +1322,11 @@
 
 # ei
 def test_0xFB():
-    py.test.skip("cycle bug in cpu")
     cpu = get_cpu()
     cpu.sp.set(0)
     cpu.ime = False
     cpu.halted = False
-    prepare_for_fetch(cpu, 0x00)
+    prepare_for_fetch(cpu, 0x00) # nop 1 cycle
     cycle_test(cpu, 0xFB, 1+1)
     assert cpu.ime == True
     
@@ -1334,13 +1334,18 @@
     cpu.sp.set(0)
     cpu.ime = True
     cpu.halted = False
+    prepare_for_fetch(cpu, 0x00)  # nop 1 cycle
     cpu.interrupt.vBlank.setPending()
+    cpu.interrupt.serial.setPending()
     cpu.interrupt.setInterruptEnable(True)
     assert cpu.interrupt.isPending() == True
-    prepare_for_fetch(cpu, 0x00)
-    cycle_test(cpu, 0xFB, 1+1+4)
+    assert cpu.halted == False
+    assert cpu.ime == True  
+    cycle_test(cpu, 0xFB, 1+1)
     assert cpu.interrupt.isPending() == False
-    assert cpu.ime == True
+    assert cpu.interrupt.vBlank.isPending() == False
+    assert cpu.pc.get() == cpu.interrupt.vBlank.callCode
+    assert cpu.ime == False
 
 # call_NZ_nnnn
 def test_0xC4():
@@ -1408,7 +1413,6 @@
 
 # rst(0x00) to rst(0x38)
 def test_0xC7_to_0xFF():
-    py.test.skip("cycle bug in cpu")
     cpu = get_cpu()
     opCode = 0xC7
     rstValue = 0x00
@@ -1427,9 +1431,22 @@
 def test_0xCB():
     pass
 
+def test_rotateLeftCircular_flags():
+    cpu = get_cpu()
+    a = cpu.a
+    a.set(0x01)
+    cpu.rotateLeftA()
+    assert_default_flags(cpu, zFlag=False, cFlag=False)
+    assert_default_registers(cpu, a=0x02, f=None)
+    
+    cpu.reset()
+    a.set(0x40)
+    cpu.rotateLeftA()
+    assert_default_flags(cpu, zFlag=False, cFlag=True)
+    assert_default_registers(cpu, a=0x80, f=None)
+    
 # rlc_B to rlc_A
-def test_0x00_to_0x07():
-    py.test.skip("Bug in cpu")
+def test_0x00_to_0x07_rotateLeftCircular():
     cpu = get_cpu()
     registers = [cpu.b, cpu.c, cpu.d, cpu.e, cpu.h, cpu.l, cpu.hli, cpu.a]
     opCode = 0x00
@@ -1442,9 +1459,9 @@
             cycles = 4
         fetch_execute_cycle_test(cpu, opCode, cycles)
         rlc = ((value & 0x7F) << 1) + ((value & 0x80) >> 7)
-        assert register.get() ==  rcl
+        assert register.get() ==  rlc
         opCode += 0x01
-        vaue += 1
+        value += 1
 
 # rrc_B to rrc_F
 def test_0x08_to_0x0F():

Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_register.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_register.py	(original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/test/test_register.py	Tue Apr  8 12:25:54 2008
@@ -91,6 +91,8 @@
     value = 0xFFFF1234
     register.set(value)
     assert register.get() == 0x1234
+    register.set(0)
+    assert register.get() == 0
     
 def test_double_register_hilo():
     register = DoubleRegister(get_cpu())
@@ -120,7 +122,6 @@
     
     
 def test_double_register_methods():
-    print("test_double_register_methods")
     value = 0x1234
     register = DoubleRegister(get_cpu())
     register.set(value)



More information about the Pypy-commit mailing list