[pypy-svn] r55774 - in pypy/dist/pypy/lang/gameboy: . test

cami at codespeak.net cami at codespeak.net
Thu Jun 12 09:53:05 CEST 2008


Author: cami
Date: Thu Jun 12 09:53:03 2008
New Revision: 55774

Modified:
   pypy/dist/pypy/lang/gameboy/cpu.py
   pypy/dist/pypy/lang/gameboy/test/test_cpu.py
   pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py
Log:
bug tracking, minor test cleanup


Modified: pypy/dist/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cpu.py	(original)
+++ pypy/dist/pypy/lang/gameboy/cpu.py	Thu Jun 12 09:53:03 2008
@@ -791,8 +791,8 @@
             delta |= 0x60
         if (self.a.get() & 0x0F) > 0x09:
             delta |= 0x06
-            if (self.a.get() & 0xF0) > 0x80:
-                delta |= 0x60
+        if (self.a.get() & 0xF0) > 0x80:
+            delta |= 0x60
         if (self.a.get() & 0xF0) > 0x90:
             delta |= 0x60
         if not self.is_n():

Modified: pypy/dist/pypy/lang/gameboy/test/test_cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_cpu.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_cpu.py	Thu Jun 12 09:53:03 2008
@@ -355,7 +355,7 @@
         cpu.f.set(~flags[i])
         cycle_test(cpu, opCode, 2)
         assert cpu.pc.get() == pc+1
-        value += 3
+        value  += 3
         opCode += 0x08
         
 # ld_BC_nnnn to ld_SP_nnnn
@@ -369,11 +369,11 @@
         cycle_test(cpu, opCode, 3)
         assert registers[index].get_lo() == value+1
         assert registers[index].get_hi() == value
-        value += 3
+        value  += 3
         opCode += 0x10
         
 # add_HL_BC to add_HL_SP
-def test_0x09_0x19_0x29_0x39():
+def test_0x09_0x19_0x29_0x39_add_HL():
     cpu       = get_cpu()
     registers = [cpu.bc, cpu.de, cpu.hl, cpu.sp]
     value     = 0x1234
@@ -384,7 +384,7 @@
         assert  registers[i].get() == value
         cycle_test(cpu, opCode, 2)
         assert cpu.hl.get()        == value+value
-        value += 3
+        value  += 3
         opCode += 0x10
         
 # ld_BCi_A
@@ -480,7 +480,7 @@
         assert  registers[i].get() == value + 1
         cpu.reset()
         opCode += 0x10
-        value += 3
+        value  += 3
  
 # dec_BC
 def test_0x0B_to_0c38_dec_double_registers():
@@ -496,7 +496,7 @@
         cpu.reset()
         cpu.reset()
         opCode += 0x10
-        value += 3
+        value  += 3
         
 def test_inc():
     cpu = get_cpu()
@@ -531,7 +531,7 @@
         assert register.get() == value+1
         cpu.reset()
         opCode += 0x08
-        value += 3
+        value  += 3
         
 # inc_HLi
 def test_0x34():
@@ -585,7 +585,7 @@
         cycle_test(cpu, opCode, 1)
         assert register.get() == value-1
         opCode += 0x08
-        value += 3
+        value  += 3
 
 # dec_HLi
 def test_0x35():
@@ -766,7 +766,7 @@
 
     
 # add_A_B to add_A_A
-def test_0x80_to_0x87():
+def test_0x80_to_0x87_add_A():
     cpu    = get_cpu()
     opCode = 0x80
     valueA = 0x11
@@ -776,9 +776,10 @@
         cpu.reset()
         cpu.a.set(valueA)
         register.set(value)
-        numCycles= 1
         if register == cpu.hli:
             numCycles = 2
+        else:
+            numCycles= 1
         cycle_test(cpu, opCode, numCycles)
         if register == cpu.a:
             assert cpu.a.get() == 2*value
@@ -815,8 +816,7 @@
             assert cpu.a.get() == 2*value+1
         else:
             assert cpu.a.get() == 2*value
-        
-        value += 3
+        value  += 3
         opCode += 0x01
 
 # sub_A_B to sub_A_A
@@ -834,7 +834,7 @@
             numCycles = 2
         cycle_test(cpu, opCode, numCycles)
         assert cpu.a.get() == 0
-        value += 3
+        value  += 3
         opCode += 0x01
     
 # sbc_A_B to sbc_A_A
@@ -866,7 +866,7 @@
         else:
             assert cpu.a.get() == 0
         
-        value += 3
+        value  += 3
         opCode += 0x01
     
 # and_A_B to and_A_A
@@ -888,7 +888,7 @@
             assert cpu.a.get() == (value & value)
         else:
             assert cpu.a.get() == (valueA & value)
-        value += 1
+        value  += 1
         opCode += 0x01
     
 # xor_A_B to xor_A_A
@@ -910,7 +910,7 @@
             assert cpu.a.get() == (value ^ value)
         else:
             assert cpu.a.get() == (valueA ^ value)
-        value += 1
+        value  += 1
         opCode += 0x01
 
     
@@ -933,7 +933,7 @@
             assert cpu.a.get() == (value | value)
         else:
             assert cpu.a.get() == (valueA | value)
-        value += 1
+        value  += 1
         opCode += 0x01
 
 # cp_A_B to cp_A_A
@@ -953,7 +953,7 @@
         cycle_test(cpu, opCode, numCycles)
         if register == cpu.a:
             valueA = value
-        value += 1
+        value  += 1
         opCode += 0x01
 
 # ret_NZ to ret_C
@@ -974,7 +974,7 @@
         cpu.f.set(~flags[i])
         cycle_test(cpu, opCode, 2)
         assert_default_registers(cpu, f=cpu.f.get())
-        value += 3
+        value  += 3
         opCode += 0x08
 
 # ldh_mem_A
@@ -1055,7 +1055,7 @@
         prepare_for_pop(cpu, value >> 8, value & 0xFF)
         cycle_test(cpu, opCode, 3)
         assert register.get() == value
-        value += 3
+        value  += 3
         opCode += 0x10
 
 # ret
@@ -1116,8 +1116,8 @@
     assert cpu.cycles == 0
     assert cpu.halted == False 
     assert_default_registers(cpu, pc=cpu.interrupt.vblank.call_code, sp=sp-2)
-    assert cpu.pop() == 0x34
-    assert cpu.pop() == 0x12
+    assert cpu.pop()  == 0x34
+    assert cpu.pop()  == 0x12
 
 # ld_PC_HL 
 def test_0xE9_store_hl_in_pc():
@@ -1157,7 +1157,7 @@
         pc = cpu.pc.get()
         cycle_test(cpu, opCode, 3)
         assert_default_registers(cpu, f=~flags[i] & 0xFF, pc=pc+2)
-        value += 3
+        value  += 3
         opCode += 0x08
 
 # ldh_Ci_A
@@ -1296,7 +1296,7 @@
         assert cpu.memory.read(cpu.sp.get()+1) == value >> 8
         assert cpu.memory.read(cpu.sp.get()) == value & 0xFF
         opCode += 0x10
-        value += 0x0101
+        value  += 0x0101
             
 
 # call_nnnn
@@ -1403,7 +1403,7 @@
         fetch_execute_cycle_test_second_order(cpu, opCode, cycles)
         assert register.get() ==  createFunction(value)
         opCode += 0x01
-        value += 1
+        value  += 1
 
 # rlc_B to rlc_A
 def test_0x00_to_0x07_rotateLeftCircular():

Modified: pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py	Thu Jun 12 09:53:03 2008
@@ -164,6 +164,7 @@
     method_value_call(cpu, CPU.add_a, 0x00)
     assert cpu.a.get() == 0x00
     assert_flags(cpu, z=True, n=False, h=False, c=False)
+    
     add_flag_test(cpu, CPU.add_a)
     
     
@@ -222,9 +223,70 @@
         assert cpu.sp.get() == 0xFF - i
         assert_flags(cpu, z=False, n=False, h=False, c=False)
         
-def test_add_sp_cary_flags():
+def test_add_sp_carry():
     cpu = get_cpu()
-    py.test.skip("test not yet implemented")
+    cpu.f.set(0xFF)
+    cpu.sp.set(0xFF)
+    prepare_for_fetch(cpu, 0xFF)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0xFE
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+
+    cpu.f.set(0x00)
+    cpu.sp.set(0xFF)
+    prepare_for_fetch(cpu, 0xFF)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0xFE
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.sp.set(0x00)
+    prepare_for_fetch(cpu, 0x01)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0x01
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0xFF)
+    cpu.sp.set(0x00)
+    prepare_for_fetch(cpu, 0x01)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0x01
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0xFF)
+    cpu.sp.set(0x02)
+    prepare_for_fetch(cpu, 0xFE)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0x00
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+
+def test_add_sp_carry_flags():
+    cpu = get_cpu()   
+    cpu.f.set(0xFF)
+    cpu.sp.set(0x0FFF)
+    prepare_for_fetch(cpu, 0x01)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0x1000
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    cpu.sp.set(0x1000)
+    prepare_for_fetch(cpu, 0xFF)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0x0FFF
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    cpu.sp.set(0xFFFF)
+    prepare_for_fetch(cpu, 0x01)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0x0000
+    assert_flags(cpu, z=False, n=False, h=True, c=True)
+    
+    cpu.sp.set(0x0000)
+    prepare_for_fetch(cpu, 0xFF)
+    cpu.increment_sp_by_fetch()
+    assert cpu.sp.get() == 0xFFFF
+    assert_flags(cpu, z=False, n=False, h=True, c=True)
+    
     
 def test_and_a():
     cpu = get_cpu()
@@ -457,10 +519,12 @@
     py.test.skip("not yet implemented")
     cpu = get_cpu()
     cpu.f.set(0xFF)
+    cpu.a.set(0)
     cpu.decimal_adjust_a()
     assert_flags(cpu, z=False, n=True, h=False, c=False)
     
     cpu.f.set(0x00)
+    cpu.a.set(0)
     cpu.decimal_adjust_a()
     assert_flags(cpu, z=False, n=False, h=False, c=False)
     
@@ -576,7 +640,7 @@
     cpu.f.set(0xFF)
     prepare_for_double_fetch(cpu, 0x1234)
     cpu.jump()
-    assert cpu.f.get() == 0xFF
+    assert cpu.f.get()  == 0xFF
     assert cpu.pc.get() == 0x1234
 
 def test_conditional_jump():
@@ -584,13 +648,13 @@
     cpu.f.set(0xFF)
     prepare_for_double_fetch(cpu, 0x1234)
     cpu.conditional_jump(True)
-    assert cpu.f.get() == 0xFF
+    assert cpu.f.get()  == 0xFF
     assert cpu.pc.get() == 0x1234  
     
     cpu.pc.set(0x1234)
     prepare_for_double_fetch(cpu, 0x1234)
     cpu.conditional_jump(False)
-    assert cpu.f.get() == 0xFF
+    assert cpu.f.get()  == 0xFF
     assert cpu.pc.get() == 0x1234+2
     
 def test_process_2_complement():
@@ -610,16 +674,16 @@
         cpu.pc.set(0x1234)
         prepare_for_fetch(cpu, i)
         cpu.relative_jump()
-        assert cpu.f.get() == 0xFF
-        #+1 fpr a single fetch
+        assert cpu.f.get()  == 0xFF
+        #+1 for a single fetch
         assert cpu.pc.get() == 0x1234+1 + i
         
     for i in range(1, 0x7F):
         cpu.pc.set(0x1234)
         prepare_for_fetch(cpu, 0xFF - i+1)
         cpu.relative_jump()
-        assert cpu.f.get() == 0xFF
-        #+1 fpr a single fetch
+        assert cpu.f.get()  == 0xFF
+        #+1 for a single fetch
         assert cpu.pc.get() == 0x1234+1 - i
 
 def test_conditional_relative_jump():
@@ -630,7 +694,7 @@
         prepare_for_fetch(cpu, i)
         cpu.relative_conditional_jump(True)
         assert cpu.f.get() == 0xFF
-        #+1 fpr a single fetch
+        #+1 for a single fetch
         assert cpu.pc.get() == 0x1234+1 + i
     
     cpu.pc.set(0x1234)
@@ -803,7 +867,6 @@
     assert cpu.a.get() == 0x01
     assert_flags(cpu, z=False, n=False, h=False, c=False)
     
-
 def test_subtract_with_carry_a():
     cpu = get_cpu()
     cpu.f.set(0xFF)
@@ -830,7 +893,7 @@
     assert cpu.a.get() == 0xFF
     assert_flags(cpu, z=False, n=True, h=True, c=True)
     
-    # FIXME add separated Test for each flag
+    subtract_flag_test(cpu, CPU.subtract_with_carry_a)
     
 def test_subtract_a():
     cpu = get_cpu()
@@ -840,31 +903,39 @@
     assert cpu.a.get() == 0xFE
     assert_flags(cpu, z=False, n=True, h=False, c=False)
     
+    cpu.f.set(0xFF)
+    cpu.a.set(0x01)
+    method_value_call(cpu, CPU.subtract_a, 0x01)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=True, h=False, c=False)
+    
+    subtract_flag_test(cpu, CPU.subtract_a)
+    
+def subtract_flag_test(cpu, method):
     cpu.f.set(0x00)
     cpu.a.set(0xFF)
     method_value_call(cpu, CPU.subtract_a, 0x01)
     assert cpu.a.get() == 0xFE
     assert_flags(cpu, z=False, n=True, h=False, c=False)
     
-    cpu.f.set(0xFF)
+    cpu.f.set(0x00)
     cpu.a.set(0x01)
     method_value_call(cpu, CPU.subtract_a, 0x01)
     assert cpu.a.get() == 0x00
     assert_flags(cpu, z=True, n=True, h=False, c=False)
     
-    cpu.f.set(0xFF)
+    cpu.f.set(0x00)
     cpu.a.set(0x10)
     method_value_call(cpu, CPU.subtract_a, 0x01)
     assert cpu.a.get() == 0x0F
     assert_flags(cpu, z=False, n=True, h=True, c=False)
     
-    cpu.f.set(0xFF)
+    cpu.f.set(0x00)
     cpu.a.set(0x00)
     method_value_call(cpu, CPU.subtract_a, 0x01)
     assert cpu.a.get() == 0xFF
     assert_flags(cpu, z=False, n=True, h=True, c=True)
-    
-    
+     
 def test_swap():
     cpu = get_cpu()
     cpu.f.set(0xFF)



More information about the Pypy-commit mailing list