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

cami at codespeak.net cami at codespeak.net
Thu Jun 12 16:21:57 CEST 2008


Author: cami
Date: Thu Jun 12 16:21:56 2008
New Revision: 55785

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
   pypy/dist/pypy/lang/gameboy/test/test_rom.py
   pypy/dist/pypy/lang/gameboy/test/test_video.py
Log:
small test improvements
still annoying bucktracking


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 16:21:56 2008
@@ -502,8 +502,7 @@
         data = register.get()
         added = (self.hl.get() + data) # 1 cycle
         self.f.partial_reset(keep_z=True)
-        if ((added ^ self.hl.get() ^ data) & 0x1000) != 0:
-            self.f.h_flag = True
+        self.f.h_flag = (((added ^ self.hl.get() ^ data) & 0x1000) != 0) 
         self.f.c_flag = (added >= 0x10000 or added < 0)
         self.hl.set(added & 0xFFFF)
         self.cycles -= 1
@@ -524,8 +523,7 @@
     def add_sub_flag_finish(self, s, data):
         self.f.reset()
         # set the h flag if the 0x10 bit was affected
-        if ((s ^ self.a.get() ^ data) & 0x10) != 0:
-            self.f.h_flag = True
+        self.f.h_flag = (((s ^ self.a.get() ^ data) & 0x10) != 0)
         self.f.c_flag = (s >= 0x100 or s < 0)
         self.f.z_flag_compare(s)
         self.a.set(s & 0xFF)  # 1 cycle
@@ -551,12 +549,11 @@
         self.f.reset()
         self.f.n_flag = True
         self.f.z_flag_compare(s)
-        self.hc_flag_finish(s)
+        self.subtract_hc_flag_finish(s)
         self.cycles -= 1
             
-    def hc_flag_finish(self, data):
-        if data > self.a.get():
-            self.f.c_flag = True
+    def subtract_hc_flag_finish(self, data):
+        self.f.c_flag = (data > self.a.get())
         self.f.h_flag_compare(data, self.a.get())
         
     def and_a(self, getCaller, setCaller=None):
@@ -687,8 +684,7 @@
         self.f.partial_reset(keep_c=True)
         self.f.h_flag = True
         self.f.z_flag = False
-        if (getCaller.get() & (1 << n)) == 0:
-            self.f.z_flag = True
+        self.f.z_flag = ((getCaller.get() & (1 << n)) == 0)
         self.cycles -= 1
 
     def set_bit(self, getCaller, setCaller, 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 16:21:56 2008
@@ -534,14 +534,13 @@
         value  += 3
         
 # inc_HLi
-def test_0x34():
+def test_0x34_increment_hli():
     cpu   = get_cpu()
-    value = 0x12
     cpu.hl.set(0xCDEF)
-    cpu.write(cpu.hl.get(), value)
-    assert cpu.read(cpu.hl.get()) == value
+    cpu.write(cpu.hl.get(), 0x12)
+    assert cpu.read(cpu.hl.get()) == 0x12
     cycle_test(cpu, 0x34, 3)
-    assert cpu.read(cpu.hl.get()) == value +1
+    assert cpu.read(cpu.hl.get()) == 0x12 +1
     
 
 def test_dec():
@@ -588,14 +587,13 @@
         value  += 3
 
 # dec_HLi
-def test_0x35():
+def test_0x35_decrement_hli():
     cpu   = get_cpu()
-    value = 0x12
     cpu.hl.set(0xCDEF)
-    cpu.write(cpu.hl.get(), value)
-    assert cpu.read(cpu.hl.get()) == value
+    cpu.write(cpu.hl.get(), 0x12)
+    assert cpu.read(cpu.hl.get()) == 0x12
     cycle_test(cpu, 0x35, 3)
-    assert cpu.read(cpu.hl.get()) == value -1
+    assert cpu.read(cpu.hl.get()) == 0x12 -1
     
 # ld_B_nn C D E H L A )
 def test_0x06_to_0x3A():
@@ -788,8 +786,8 @@
         value  += 3
         opCode += 0x01
 
-# adc_A_B to adx_A_A
-def test_0x88_to_0x8F():
+# adc_A_B to adc_A_A
+def test_0x88_to_0x8F_add_with_carry_a():
     cpu    = get_cpu()
     opCode = 0x88
     value  = 0x12
@@ -820,7 +818,7 @@
         opCode += 0x01
 
 # sub_A_B to sub_A_A
-def test_0x90_to_0x98():
+def test_0x90_to_0x98_subtract_a():
     cpu       = get_cpu()
     opCode    = 0x90
     value     = 0x12
@@ -838,7 +836,7 @@
         opCode += 0x01
     
 # sbc_A_B to sbc_A_A
-def test_0x98_0x9F():
+def test_0x98_0x9F_subtract_with_carry_a():
     cpu       = get_cpu()
     opCode    = 0x98
     value     = 0x12
@@ -940,20 +938,28 @@
 def test_0xB8_to_0xBF_compare_a():
     cpu       = get_cpu()
     opCode    = 0xB8
-    value     = 0x12
-    valueA    = 0x11
     registers = [cpu.b, cpu.c, cpu.d, cpu.e, cpu.h, cpu.l, cpu.hli, cpu.a]
     for register in registers:
         cpu.reset()
-        cpu.a.set(valueA)
-        register.set(value)
+        cpu.a.set(0x12)
+        register.set(0x22)
         numCycles= 1
         if register == cpu.hli:
             numCycles = 2
         cycle_test(cpu, opCode, numCycles)
         if register == cpu.a:
-            valueA = value
-        value  += 1
+            assert cpu.f.z_flag == True
+        else:
+            assert cpu.f.z_flag == False
+        
+        cpu.a.set(0x12)
+        register.set(0x12)
+        numCycles= 1
+        if register == cpu.hli:
+            numCycles = 2
+        cycle_test(cpu, opCode, numCycles)
+        assert cpu.f.z_flag == True
+            
         opCode += 0x01
 
 # ret_NZ to ret_C
@@ -1138,7 +1144,7 @@
     assert_default_registers(cpu, sp=value, hl=value)
 
 # jp_NZ_nnnn to jp_C_nnnn
-def test_0xC2_to_0xDA():
+def test_0xC2_to_0xDA_conditional_jump():
     cpu    = get_cpu()
     flags  = [~constants.Z_FLAG, constants.Z_FLAG, ~constants.C_FLAG, constants.C_FLAG]
     opCode = 0xC2
@@ -1326,19 +1332,19 @@
     a_nn_test(0xC6, 2, lambda a, b, cpu: a+b)
 
 # adc_A_nn
-def test_0xCE():
+def test_0xCE_add_a_with_carry_fetch():
     a_nn_test(0xCE, 2, lambda a, b, cpu: a+b)
 
 # sub_A_nn
-def test_0xD6():
+def test_0xD6_subtract_a_fetch():
     a_nn_test(0xD6, 2, lambda a, b, cpu: a-b)
 
 # sbc_A_nn
-def test_0xDE():
+def test_0xDE_subtract_with_carry_fetch():
     a_nn_test(0xDE, 2, lambda a, b, cpu: a-b)
 
 # and_A_nn
-def test_0xE6():
+def test_0xE6_and_a_fetch():
     a_nn_test(0xE6, 2, lambda a, b, cpu: a&b)
 
 # xor_A_nn

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 16:21:56 2008
@@ -123,15 +123,26 @@
 # Tests -----------------------------------------------------------------------
 
 
-def test_pa_with_carry():
+def test_add_with_carry():
     cpu = get_cpu()
     cpu.f.set(0xFF)
     cpu.a.set(0x00)
     method_value_call(cpu, CPU.add_a_with_carry, 0x00)
     assert cpu.a.get() == 0x01
     assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
     add_flag_test(cpu, CPU.add_a_with_carry)
+     
+def test_add_a():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0x00)
+    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)
+       
 def add_flag_test(cpu, method):
     cpu.f.set(0x00)
     cpu.a.set(0x00)
@@ -157,17 +168,6 @@
     assert cpu.a.get() == 0x00
     assert_flags(cpu, z=True, n=False, h=True, c=True)
     
-def test_add_a():
-    cpu = get_cpu()
-    cpu.f.set(0xFF)
-    cpu.a.set(0x00)
-    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)
-    
-    
 def test_add_hl():
     cpu = get_cpu()
     cpu.f.set(0xFF)

Modified: pypy/dist/pypy/lang/gameboy/test/test_rom.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_rom.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_rom.py	Thu Jun 12 16:21:56 2008
@@ -31,7 +31,7 @@
         pass
     
 def test_rom1_step():
-    py.test.skip()
+    py.test.skip("rom has incorrect header")
     gameboy = GameBoy()
     gameboy.load_cartridge_file(ROM_PATH+"/rom1/rom1.raw", verify=False)
     cpu = gameboy.cpu
@@ -58,12 +58,11 @@
     
 
 def test_rom3_step():
-    py.test.skip()
     gameboy = GameBoy()
     gameboy.load_cartridge_file(ROM_PATH+"/rom3/rom3.gb")
     cpu = gameboy.cpu
     # jp nop
-    emulate_step_op_codes_test(gameboy, [0xC3])
+    emulate_step_op_codes_test(gameboy, [0, 0xC3])
     emulate_step_op_codes_test(gameboy, [0]*12)
     emulate_step_op_codes_test(gameboy, [0xC3]*100)
     
@@ -100,7 +99,7 @@
     
 
 def test_rom5_step():
-    py.test.skip("dec and inc dont work as excepted")
+    py.test.skip("wrong usage of inc and its c flag")
     gameboy = GameBoy()
     gameboy.load_cartridge_file(ROM_PATH+"/rom5/rom5.gb")
     cpu = gameboy.cpu
@@ -120,7 +119,7 @@
     emulate_step_op_codes_test(gameboy, [0x30])
     assert cpu.pc.get()  == pc-2
     # looping in .loop2
-    emulate_step_op_codes_test(gameboy, [0xC6, 0x30]*255)
+    emulate_step_op_codes_test(gameboy, [0xC6, 0x30]*0xFF)
     assert cpu.a.get() == 0
     assert cpu.f.c_flag == True
     # debugg call reseting 
@@ -235,18 +234,18 @@
                                 
     
 # ------------------------------------------------------------------------------
-    
-def test_rom7_load():
-    py.test.skip("Current Default ROM Implemenation doesnt allow write")
-    gameboy = GameBoy()
-    gameboy.load_cartridge_file(ROM_PATH+"/rom7/rom7.gb")
-    gameboy.emulate(EMULATION_CYCLES)
-    cpu = gameboy.cpu
-    
-    
-def test_rom7_step():
-    py.test.skip("Current Default ROM Implemenation doesnt allow write")
-    
+#    
+#def test_rom7_load():
+#    py.test.skip("Current Default ROM Implemenation doesnt allow write")
+#    gameboy = GameBoy()
+#    gameboy.load_cartridge_file(ROM_PATH+"/rom7/rom7.gb")
+#    gameboy.emulate(EMULATION_CYCLES)
+#    cpu = gameboy.cpu
+#    
+#    
+#def test_rom7_step():
+#    py.test.skip("Current Default ROM Implemenation doesnt allow write")
+#    
 # ------------------------------------------------------------------------------
     
 def test_rom8_load():

Modified: pypy/dist/pypy/lang/gameboy/test/test_video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_video.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_video.py	Thu Jun 12 16:21:56 2008
@@ -351,9 +351,3 @@
     assert video.stat == 0xFE
     assert video.cycles == constants.MODE_2_TICKS 
     assert not video.interrupt.lcd.is_pending()
-    
-
-def test_emulate_v_vblank_3():
-    py.test.skip("not yet implemented")
-    
-    
\ No newline at end of file



More information about the Pypy-commit mailing list