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

cami at codespeak.net cami at codespeak.net
Sat May 31 09:52:45 CEST 2008


Author: cami
Date: Sat May 31 09:52:43 2008
New Revision: 55440

Added:
   pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py
Modified:
   pypy/dist/pypy/lang/gameboy/cpu.py
   pypy/dist/pypy/lang/gameboy/test/test_joypad.py
Log:
added more flag tests


Modified: pypy/dist/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cpu.py	(original)
+++ pypy/dist/pypy/lang/gameboy/cpu.py	Sat May 31 09:52:43 2008
@@ -188,7 +188,7 @@
     """
     PyGIRL GameBoy (TM) Emulator
     
-    Central Unit ProcessOR (Sharp LR35902 CPU)
+    Central Unit Processor_a (Sharp LR35902 CPU)
     """
     def __init__(self, interrupt, memory):
         assert isinstance(interrupt, Interrupt)
@@ -365,7 +365,7 @@
 
     def fetch_execute(self):
         opCode = self.fetch()
-        print "    fetch exe:", hex(opCode), "  "
+        #print "    fetch exe:", hex(opCode), "  "
         #, FETCH_EXECUTE_OP_CODES[opCode].__name__
         self.last_fetch_execute_op_code = opCode
         FETCH_EXECUTE_OP_CODES[opCode](self)
@@ -456,8 +456,9 @@
         
     def call(self, address, use_cycles=True):
         # 4 cycles
-        self.push(self.pc.get_hi(use_cycles), use_cycles) # 2 cycles
-        self.push(self.pc.get_lo(use_cycles), use_cycles) # 2 cycles
+        self.push_double_register(self.pc, use_cycles)
+        #self.push(self.pc.get_hi(use_cycles), use_cycles) # 2 cycles
+        #self.push(self.pc.get_lo(use_cycles), use_cycles) # 2 cycles
         self.pc.set(address, use_cycles=use_cycles)       # 1 cycle
         if use_cycles:
             self.cycles += 1
@@ -480,7 +481,6 @@
     def add_a(self, getCaller, setCaller=None):
         # ALU, 1 cycle
         added = (self.a.get() + getCaller.get()) & 0xFF
-        self.f.reset()
         self.f.z_flag_compare(added)
         self.f.h_flag_compare(added, self.a.get(), inverted=True)
         self.f.c_flag = (added < self.a.get())
@@ -496,20 +496,16 @@
         self.hl.set(added)
         self.cycles -= 1
         
-    def add_with_carry(self, getCaller, setCaller=None):
+    def add_a_with_carry(self, getCaller, setCaller=None):
         # 1 cycle
         data = getCaller.get()
-        s = self.a.get() + data
-        if self.f.c_flag:
-            s +=1
+        s = self.a.get() + data + int(self.f.c_flag)
         self.carry_flag_finish(s,data)
 
-    def subtract_with_carry(self, getCaller, setCaller=None):
+    def subtract_with_carry_a(self, getCaller, setCaller=None):
         # 1 cycle
         data = getCaller.get()
-        s = self.a.get() - data
-        if self.f.c_flag:
-            s -= 1
+        s = self.a.get() - data - int(self.f.c_flag)
         self.carry_flag_finish(s, data)
         self.f.n_flag = True
         
@@ -518,16 +514,15 @@
         # set the hflag if the 0x10 bit was affected
         if ((s ^ self.a.get() ^ data) & 0x10) != 0:
             self.f.h_flag = True
-        if s >= 0x100:
-            self.f.c_flag= True
+        self.f.c_flag = (s >= 0x100 or s < 0)
         self.f.z_flag_compare(s)
-        self.a.set(s)  # 1 cycle
+        self.a.set(s & 0xFF)  # 1 cycle
         
     def subtract_a(self, getCaller, setCaller=None):
         # 1 cycle
         self.compare_a(getCaller) # 1 cycle
         self.a.sub(getCaller.get(use_cycles=False), False)
-
+ 
     def fetch_subtract_a(self):
         data = self.fetch()
         # 1 cycle
@@ -552,27 +547,37 @@
         #self.f.c_flag_compare(data, self.a.get())
         self.f.h_flag_compare(data, self.a.get())
         
-    def AND(self, getCaller, setCaller=None):
+    def and_a(self, getCaller, setCaller=None):
         # 1 cycle
         self.a.set(self.a.get() & getCaller.get())  # 1 cycle
-        self.f.z_flag_compare(self.a.get(), reset=True)
+        self.f.reset()
+        self.f.z_flag_compare(self.a.get())
+        self.f.h_flag = True
 
-    def XOR(self, getCaller, setCaller=None):
+    def xor_a(self, getCaller, setCaller=None):
         # 1 cycle
         self.a.set( self.a.get() ^ getCaller.get())  # 1 cycle
         self.f.z_flag_compare(self.a.get(), reset=True)
 
-    def OR(self, getCaller, setCaller=None):
+    def or_a(self, getCaller, setCaller=None):
         # 1 cycle
         self.a.set(self.a.get() | getCaller.get())  # 1 cycle
         self.f.z_flag_compare(self.a.get(), reset=True)
 
-    def inc_double_register(self, doubleRegister):
-        doubleRegister.set((doubleRegister.get() + 1) & 0xFF)
-        
-    def dec_double_register(self, doubleRegister):
-        doubleRegister.set((doubleRegister.get() - 1) & 0xFF)
-        
+    def inc_double_register(self, register):
+        # INC rr
+        register.inc()
+
+    def dec_double_register(self, register):
+        # DEC rr
+        register.dec()
+
+#    def inc_double_register(self, doubleRegister):
+#        doubleRegister.set((doubleRegister.get() + 1) & 0xFF)
+#        
+#    def dec_double_register(self, doubleRegister):        
+#        doubleRegister.set((doubleRegister.get() - 1) & 0xFF)
+   
     def inc(self, getCaller, setCaller):
         # 1 cycle
         data = (getCaller.get() + 1) & 0xFF
@@ -593,8 +598,8 @@
     def rotate_left_circular(self, getCaller, setCaller):
         # RLC 1 cycle
         data = getCaller.get()
-        s = (data  << 1) + (data >> 7)
-        self.flags_and_setter_finish(s, setCaller, 0x80)
+        s = ((data << 1) & 0xFF) + ((data & 0x80) >> 7)
+        self.flags_and_setter_finish(s, data, setCaller, 0x80)
         #self.cycles -= 1
 
     def rotate_left_circular_a(self):
@@ -604,10 +609,9 @@
 
     def rotate_left(self, getCaller, setCaller):
         # 1 cycle
-        s = (getCaller.get() << 1) & 0xFF
-        if self.f.c_flag:
-            s += 0x01
-        self.flags_and_setter_finish(s, setCaller, 0x80) # 1 cycle
+        data = getCaller.get()
+        s = ((data & 0x7F) << 1) + int(self.f.c_flag)
+        self.flags_and_setter_finish(s, data, setCaller, 0x80) # 1 cycle
 
     def rotate_left_a(self):
         # RLA  1 cycle
@@ -618,7 +622,7 @@
         data = getCaller.get()
         # RRC 1 cycle
         s = (data >> 1) + ((data & 0x01) << 7)
-        self.flags_and_setter_finish(s, setCaller) # 1 cycle
+        self.flags_and_setter_finish(s, data, setCaller) # 1 cycle
    
     def rotate_right_circular_a(self):
         # RRCA 1 cycle
@@ -627,38 +631,41 @@
 
     def rotate_right(self, getCaller, setCaller):
         # 1 cycle
-        s = (getCaller.get() >> 1)
+        data = getCaller.get()
+        s = (data >> 1)
         if self.f.c_flag:
-            s +=  0x08
-        self.flags_and_setter_finish(s, setCaller) # 1 cycle
+            s +=  0x80
+        self.flags_and_setter_finish(s, data, setCaller) # 1 cycle
 
     def rotate_right_a(self):
         # RRA 1 cycle
         self.rotate_right(RegisterCallWrapper(self.a), 
                           RegisterCallWrapper(self.a))
-
+   
     def shift_left_arithmetic(self, getCaller, setCaller):
         # 2 cycles
-        s = (getCaller.get() << 1) & 0xFF
-        self.flags_and_setter_finish(s, setCaller, 0x80) # 1 cycle
+        data = getCaller.get()
+        s = (data << 1) & 0xFF
+        self.flags_and_setter_finish(s, data, setCaller, 0x80) # 1 cycle
 
     def shift_right_arithmetic(self, getCaller, setCaller):
         data = getCaller.get()
         # 1 cycle
         s = (data >> 1) + (data & 0x80)
-        self.flags_and_setter_finish(s, setCaller) # 1 cycle
+        self.flags_and_setter_finish(s, data, setCaller) # 1 cycle
 
     def shift_word_right_logical(self, getCaller, setCaller):
         # 2 cycles
-        s = (getCaller.get() >> 1)
-        self.flags_and_setter_finish(s, setCaller) # 2 cycles
-        
-    def flags_and_setter_finish(self, s, setCaller, compare_and=0x01):
+        data = getCaller.get()
+        s = (data >> 1)
+        self.flags_and_setter_finish(s, data, setCaller) # 2 cycles
+         
+    def flags_and_setter_finish(self, s, data, setCaller, compare_and=0x01):
         # 2 cycles
         s &= 0xFF
         self.f.reset()
         self.f.z_flag_compare(s)
-        self.f.c_flag_compare(s, compare_and)
+        self.f.c_flag_compare(data, compare_and)
         setCaller.set(s) # 1 cycle
 
     def swap(self, getCaller, setCaller):
@@ -668,6 +675,7 @@
         self.f.z_flag_compare(s, reset=True)
         setCaller.set(s)
 
+
     def test_bit(self, getCaller, setCaller, n):
         # 2 cycles
         self.f.partial_reset(keep_c=True)
@@ -768,7 +776,7 @@
         self.f.n_flag = True
         self.f.h_flag = True
 
-    def decimal_adjust_accumulator(self):
+    def decimal_adjust_a(self):
         # DAA 1 cycle
         delta = 0
         if self.is_h(): 
@@ -790,14 +798,6 @@
             self.f.c_flag = True
         self.f.z_flag_compare(self.a.get())
 
-    def inc_double_register(self, register):
-        # INC rr
-        register.inc()
-
-    def dec_double_register(self, register):
-        # DEC rr
-        register.dec()
-
     def increment_sp_by_fetch(self):
         # ADD SP,nn 4 cycles
         self.sp.set(self.get_fetchadded_sp()) # 1+1 cycle
@@ -828,7 +828,7 @@
     def process_2_complement(self, value):
         # check if the left most bit is set
         if (value >> 7) == 1:
-            return -((~value) & 0xFF)-1
+            return -((~value) & 0xFF) - 1
         else :
             return value
         
@@ -845,7 +845,7 @@
         # NOP 1 cycle
         self.cycles -= 1
 
-    def unconditional_jump(self):
+    def jump(self):
         # JP nnnn, 4 cycles
         self.pc.set(self.fetch_double_address()) # 1+2 cycles
         self.cycles -= 1
@@ -853,11 +853,11 @@
     def conditional_jump(self, cc):
         # JP cc,nnnn 3,4 cycles
         if cc:
-            self.unconditional_jump() # 4 cycles
+            self.jump() # 4 cycles
         else:
             self.pc.add(2) # 3 cycles
 
-    def relative_unconditional_jump(self):
+    def relative_jump(self):
         # JR +nn, 3 cycles
         #pc = pc & 0xFF00 + ((pc & 0x00FF) + add) & 0xFF
         self.pc.add(self.process_2_complement(self.fetch())) # 3 + 1 cycles
@@ -866,7 +866,7 @@
     def relative_conditional_jump(self, cc):
         # JR cc,+nn, 2,3 cycles
         if cc:
-            self.relative_unconditional_jump() # 3 cycles
+            self.relative_jump() # 3 cycles
         else:
             self.pc.inc() # 2 cycles
     
@@ -1076,11 +1076,11 @@
 
 # OPCODE TABLES ---------------------------------------------------------------
 # Table with one to one mapping of simple OP Codes                
-FIRST_ORDER_OP_CODES = [
+FIRST_or_aDER_OP_CODES = [
     (0x00, CPU.nop),
     (0x08, CPU.load_mem_sp),
     (0x10, CPU.stop),
-    (0x18, CPU.relative_unconditional_jump),
+    (0x18, CPU.relative_jump),
     (0x02, CPU.write_a_at_bc_address),
     (0x12, CPU.write_a_at_de_address),
     (0x22, CPU.load_and_increment_hli_a),
@@ -1093,7 +1093,7 @@
     (0x0F, CPU.rotate_right_circular_a),
     (0x17, CPU.rotate_left_a),
     (0x1F, CPU.rotate_right_a),
-    (0x27, CPU.decimal_adjust_accumulator),
+    (0x27, CPU.decimal_adjust_a),
     (0x2F, CPU.complement_a),
     (0x37, CPU.set_carry_flag),
     (0x3F, CPU.complement_carry_flag),
@@ -1104,7 +1104,7 @@
     (0xEA, CPU.store_a_at_fetched_address),
     (0xF2, CPU.store_expanded_c_in_a),
     (0xFA, CPU.store_fetched_memory_in_a),
-    (0xC3, CPU.unconditional_jump),
+    (0xC3, CPU.jump),
     (0xC9, CPU.ret),
     (0xD9, CPU.return_form_interrupt),
     (0xDD, CPU.debug),
@@ -1117,12 +1117,12 @@
     (0xCB, CPU.fetch_execute),
     (0xCD, CPU.unconditional_call),
     (0xC6, lambda s: CPU.add_a(s,               CPUFetchCaller(s))),
-    (0xCE, lambda s: CPU.add_with_carry(s,      CPUFetchCaller(s))),
+    (0xCE, lambda s: CPU.add_a_with_carry(s,      CPUFetchCaller(s))),
     (0xD6, CPU.fetch_subtract_a),
-    (0xDE, lambda s: CPU.subtract_with_carry(s, CPUFetchCaller(s))),
-    (0xE6, lambda s: CPU.AND(s,                 CPUFetchCaller(s))),
-    (0xEE, lambda s: CPU.XOR(s,                 CPUFetchCaller(s))),
-    (0xF6, lambda s: CPU.OR(s,                  CPUFetchCaller(s))),
+    (0xDE, lambda s: CPU.subtract_with_carry_a(s, CPUFetchCaller(s))),
+    (0xE6, lambda s: CPU.and_a(s,                 CPUFetchCaller(s))),
+    (0xEE, lambda s: CPU.xor_a(s,                 CPUFetchCaller(s))),
+    (0xF6, lambda s: CPU.or_a(s,                  CPUFetchCaller(s))),
     (0xFE, lambda s: CPU.compare_a(s,           CPUFetchCaller(s))),
     (0xC7, lambda s: CPU.restart(s, 0x00)),
     (0xCF, lambda s: CPU.restart(s, 0x08)),
@@ -1140,12 +1140,12 @@
     (0x05, 0x08, CPU.dec),    
     (0x06, 0x08, CPU.load_fetch_register),
     (0x80, 0x01, CPU.add_a),    
-    (0x88, 0x01, CPU.add_with_carry),    
+    (0x88, 0x01, CPU.add_a_with_carry),    
     (0x90, 0x01, CPU.subtract_a),    
-    (0x98, 0x01, CPU.subtract_with_carry),    
-    (0xA0, 0x01, CPU.AND),    
-    (0xA8, 0x01, CPU.XOR),    
-    (0xB0, 0x01, CPU.OR),
+    (0x98, 0x01, CPU.subtract_with_carry_a),    
+    (0xA0, 0x01, CPU.and_a),    
+    (0xA8, 0x01, CPU.xor_a),    
+    (0xB0, 0x01, CPU.or_a),
     (0xB8, 0x01, CPU.compare_a),
     (0x06, 0x08, CPU.fetch_load)
 ]    
@@ -1169,7 +1169,7 @@
     (0xC5, 0x10, CPU.push_double_register,      REGISTER_SET_B)
 ]
 # Table for Second Order OPCodes: (startAddress, delta, method, [args])
-SECOND_ORDER_REGISTER_GROUP_OP_CODES = [
+SECOND_or_aDER_REGISTER_GROUP_OP_CODES = [
     (0x00, 0x01, CPU.rotate_left_circular),    
     (0x08, 0x01, CPU.rotate_right_circular),    
     (0x10, 0x01, CPU.rotate_left),    
@@ -1185,11 +1185,11 @@
 
 # RAW OPCODE TABLE INITIALIZATION ----------------------------------------------
 
-FIRST_ORDER_OP_CODES += create_register_op_codes(REGISTER_OP_CODES)
-FIRST_ORDER_OP_CODES += create_group_op_codes(REGISTER_GROUP_OP_CODES)
-FIRST_ORDER_OP_CODES += create_load_group_op_codes()
-SECOND_ORDER_OP_CODES = create_group_op_codes(SECOND_ORDER_REGISTER_GROUP_OP_CODES)
+FIRST_or_aDER_OP_CODES += create_register_op_codes(REGISTER_OP_CODES)
+FIRST_or_aDER_OP_CODES += create_group_op_codes(REGISTER_GROUP_OP_CODES)
+FIRST_or_aDER_OP_CODES += create_load_group_op_codes()
+SECOND_or_aDER_OP_CODES = create_group_op_codes(SECOND_or_aDER_REGISTER_GROUP_OP_CODES)
 
 
-OP_CODES = initialize_op_code_table(FIRST_ORDER_OP_CODES)
-FETCH_EXECUTE_OP_CODES = initialize_op_code_table(SECOND_ORDER_OP_CODES)
+OP_CODES = initialize_op_code_table(FIRST_or_aDER_OP_CODES)
+FETCH_EXECUTE_OP_CODES = initialize_op_code_table(SECOND_or_aDER_OP_CODES)

Added: pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py	Sat May 31 09:52:43 2008
@@ -0,0 +1,842 @@
+import py
+from pypy.lang.gameboy.cpu import *
+from pypy.lang.gameboy.ram import *
+from pypy.lang.gameboy import *
+from pypy.lang.gameboy.interrupt import * 
+
+# Helpers ---------------------------------------------------------------------
+
+class Memory(object):
+    def __init__(self):
+        self.memory = [0xFF]*0xFFFFF
+        
+    def write(self, address, data):
+        self.memory[address] = data
+        
+    def read(self, address):
+        return self.memory[address]
+    
+global TEST_CPU
+
+TEST_CPU = None
+def get_cpu(new=False):
+    if new:
+        cpu = CPU(Interrupt(), Memory())
+        cpu.set_rom([0]*0xFFFF);
+        return cpu
+    global TEST_CPU
+    if TEST_CPU == None:
+        TEST_CPU = get_cpu(True)
+    TEST_CPU.reset()
+    return TEST_CPU
+
+def assert_default_registers(cpu, a=constants.RESET_A, bc=constants.RESET_BC,\
+                             de=constants.RESET_DE, f=constants.RESET_F,\
+                             hl=constants.RESET_HL, sp=constants.RESET_SP,\
+                             pc=constants.RESET_PC):
+    return assert_registers(cpu, a, bc, de, f, hl, sp, pc)
+
+def assert_registers(cpu, a=None, bc=None, de=None, f=None, hl=None, sp=None, pc=None):
+    if a is not None:
+        assert cpu.a.get() == a, "Register a  is %s but should be %s" % (hex(cpu.a.get()), hex(a))
+    if bc is not None:
+        assert cpu.bc.get() == bc, "Register bc  is %s but should be %s" % (hex(cpu.bc.get()), hex(bc))
+    if de is not None:
+        assert cpu.de.get() == de, "Register de is %s but should be %s" % (hex(cpu.de.get()),hex(de))
+    if f is not None:
+        assert cpu.f.get() == f, "Register f is %s but should be %s" % (hex(cpu.f.get()),hex(f))
+    if hl is not None:
+        assert cpu.hl.get() == hl, "Register hl is %s but should be %s" % (hex(cpu.hl.get()), hex(hl))
+    if sp is not None:
+        assert cpu.sp.get() == sp, "Register sp is %s but should be %s" % (hex(cpu.sp.get()), hex(sp))
+    if pc is not None:
+        assert cpu.pc.get() == pc, "Register pc is %s but should be %s" % (hex(cpu.pc.get()), hex(pc))
+        
+
+def assert_defaults(cpu, z=True, n=False, h=False, c=False, p=False, s=False):        
+    assert_flags(cpu, z, n, h, c, p, s)
+
+def assert_flags(cpu, z=None, n=None, h=None, c=None, p=None, s=None):
+    if z is not None:
+        assert cpu.f.z_flag == z, "Z-Flag is %s but should be %s" % (cpu.f.z_flag, z)
+    if n is not None:
+        assert cpu.f.n_flag == n, "N-Flag is %s but should be %s" % (cpu.f.n_flag, n)
+    if h is not None:
+        assert cpu.f.h_flag == h,  "H-Flag is %s but should be %s" % (cpu.f.h_flag, h)
+    if c is not None:
+        assert cpu.f.c_flag == c,  "C-Flag is %s but should be %s" % (cpu.f.c_flag, c)
+    if p is not None:
+        assert cpu.f.p_flag == p,  "P-Flag is %s but should be %s" % (cpu.f.p_flag, p)
+    if s is not None:
+        assert cpu.f.s_flag == s,  "S-Flag is %s but should be %s" % (cpu.f.s_flag, s)
+
+def prepare_for_double_fetch(cpu, value):
+    prepare_for_fetch(cpu, (value & 0xFF00) >> 8, value & 0x00FF)
+    
+def prepare_for_fetch(cpu, value, valueLo=None):
+    pc = cpu.pc.get()
+    if valueLo is not None:
+        cpu.rom[pc] = valueLo & 0xFF
+        cpu.memory.write(pc, valueLo & 0xFF)
+        pc += 1
+    cpu.rom[pc] = value & 0xFF
+    cpu.memory.write(pc, value & 0xFF)
+    
+def test_prepare_for_fetch():
+    cpu = get_cpu()
+    value = 0x12
+    prepare_for_fetch(cpu, value+1, value)
+    assert cpu.fetch() == value
+    assert cpu.fetch() == value+1
+        
+def prepare_for_pop(cpu, value, valueLo=None):
+    sp = cpu.sp.get()
+    if valueLo is not None:
+        cpu.memory.write(sp, valueLo & 0xFF)
+        sp += 1
+    cpu.memory.write(sp, value & 0xFF)
+    
+def test_prepare_for_pop():
+    cpu = get_cpu()
+    value = 0x12
+    prepare_for_pop(cpu, value+1, value)
+    assert cpu.pop() == value
+    assert cpu.pop() == value+1
+        
+def set_registers(registers, value):
+    #if registers is not list:
+      #  registers = [registers]
+    for register in registers:
+        register.set(value);
+        
+        
+def method_value_call(cpu, method, number):
+    method(cpu, NumberCallWrapper(number))
+    
+def method_register_call(cpu, method, register):
+    method(cpu, RegisterCallWrapper(register), RegisterCallWrapper(register))
+    
+def method_register_value_call(cpu, method, register, number):
+    method(cpu, RegisterCallWrapper(register), RegisterCallWrapper(register),
+           number)
+    
+# Tests -----------------------------------------------------------------------
+
+
+def test_add_a_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 add_flag_test(cpu, method):
+    cpu.f.set(0x00)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.add_a_with_carry, 0x00)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x0F)
+    method_value_call(cpu, CPU.add_a_with_carry, 0x01)
+    assert cpu.a.get() == 0x10
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_value_call(cpu, CPU.add_a_with_carry, 0xF0)
+    assert cpu.a.get() == 0xEF
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_value_call(cpu, CPU.add_a_with_carry, 0x01)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=True, c=True)
+    
+def test_add_a():
+    py.test.skip("Flag check broken")
+    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():
+    py.test.skip("Carry flag check broken")
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.hl.set(0x0000)
+    method_value_call(cpu, CPU.add_hl, 0x0000)
+    assert cpu.hl.get() == 0x0000
+    assert_flags(cpu, z=True, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.hl.set(0x0000)
+    method_value_call(cpu, CPU.add_hl, 0x0000)
+    assert cpu.hl.get() == 0x0000
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.hl.set(0x0000)
+    method_value_call(cpu, CPU.add_hl, 0x00)
+    assert cpu.hl.get() == 0x0000
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.hl.set(0x0F00)
+    method_value_call(cpu, CPU.add_hl, 0x0100)
+    assert cpu.hl.get() == 0x1000
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.hl.set(0xFF00)
+    method_value_call(cpu, CPU.add_hl, 0xF000)
+    assert cpu.hl.get() == 0xEF00
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.hl.set(0xFF00)
+    method_value_call(cpu, CPU.add_hl, 0x0100)
+    assert cpu.hl.get() == 0x0000
+    assert_flags(cpu, z=False, n=False, h=True, c=True)
+    
+def test_add_sp():
+    py.test.skip("not yet implemented")
+    cpu = get_cpu()
+    
+def test_and_a():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_value_call(cpu, CPU.and_a, 0x00)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=True, c=False)
+    
+    cpu.a.set(0xFF)
+    method_value_call(cpu, CPU.and_a, 0x12)
+    assert cpu.a.get() == 0x12
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    
+def test_or_a():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.or_a, 0xFF)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.or_a, 0x00)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_value_call(cpu, CPU.or_a, 0x00)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_value_call(cpu, CPU.or_a, 0x00)
+    assert cpu.a.get() == 0x01
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_value_call(cpu, CPU.or_a, 0xFF)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+
+    
+def test_xor_a():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.xor_a, 0xFF)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_value_call(cpu, CPU.xor_a, 0xFF)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_value_call(cpu, CPU.xor_a, 0x00)
+    assert cpu.a.get() == 0x01
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_value_call(cpu, CPU.xor_a, 0xFF)
+    assert cpu.a.get() == 0xFF - 0x01
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.xor_a, 0x00)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=False, c=False)
+      
+def test_bit():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_register_value_call(cpu, CPU.test_bit, cpu.a, 0x00)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=True, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_register_value_call(cpu, CPU.test_bit, cpu.a, 0x00)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x40)
+    method_register_value_call(cpu, CPU.test_bit, cpu.a, 0x05)
+    assert_flags(cpu, z=True, n=False, h=True, c=False)
+    
+    method_register_value_call(cpu, CPU.test_bit, cpu.a, 0x06)
+    assert cpu.a.get() == 0x40
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    method_register_value_call(cpu, CPU.test_bit, cpu.a, 0x07)
+    assert_flags(cpu, z=True, n=False, h=True, c=False)
+    
+def test_set_bit():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0x00)
+    method_register_value_call(cpu, CPU.set_bit, cpu.a, 0x00)
+    assert cpu.a.get() == 0x01
+    assert cpu.f.get() == 0xFF
+    
+    for i in range(8):
+        cpu = get_cpu()
+        cpu.f.set(0x00)
+        cpu.a.set(0x00)
+        method_register_value_call(cpu, CPU.set_bit, cpu.a, i)
+        assert cpu.a.get() == 0x01 << i
+        assert cpu.f.get() == 0x00
+        
+def test_reset_bit():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0x01)
+    method_register_value_call(cpu, CPU.reset_bit, cpu.a, 0x00)
+    assert cpu.a.get() == 0x00
+    assert cpu.f.get() == 0xFF
+    
+    for i in range(8):
+        cpu = get_cpu()
+        cpu.f.set(0x00)
+        cpu.a.set(0xFF)
+        method_register_value_call(cpu, CPU.reset_bit, cpu.a, i)
+        assert cpu.a.get() == 0xFF - (0x01 << i)
+        assert cpu.f.get() == 0x00
+
+    
+def test_unconditional_call():
+    cpu = get_cpu()
+    cpu.f.set(0x12)
+    cpu.pc.set(0x1234)
+    assert cpu.pc.get_hi() == 0x12
+    assert cpu.pc.get_lo() == 0x34
+    prepare_for_double_fetch(cpu, 0x5678)
+    cpu.unconditional_call()
+    assert cpu.f.get() == 0x12  
+    assert cpu.pop() == 0x34+2
+    assert cpu.pop() == 0x12
+    assert cpu.pc.get() == 0x5678
+    
+
+def test_conditional_call():
+    cpu = get_cpu()
+    cpu.f.set(0x12)
+    cpu.pc.set(0x1234)
+    cpu.conditional_call(False)
+    assert cpu.pc.get() == 0x1234+2
+    assert cpu.f.get() == 0x12 
+    
+    cpu.reset()
+    cpu.f.set(0x12)
+    cpu.pc.set(0x1234)
+    assert cpu.pc.get_hi() == 0x12
+    assert cpu.pc.get_lo() == 0x34
+    prepare_for_double_fetch(cpu, 0x5678)
+    cpu.conditional_call(True)
+    assert cpu.f.get() == 0x12
+    assert cpu.pop() == 0x34+2
+    assert cpu.pop() == 0x12
+    assert cpu.pc.get() == 0x5678
+    
+def test_complement_carry_flag():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.complement_carry_flag()
+    assert_flags(cpu, z=True, n=False, h=False, c=False)
+    
+    cpu.complement_carry_flag()
+    assert_flags(cpu, z=True, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.complement_carry_flag()
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+def test_compare_a():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.compare_a, 0x00)
+    assert_flags(cpu, z=True, n=True, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.compare_a, 0x00)
+    assert_flags(cpu, z=True, n=True, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x11)
+    method_value_call(cpu, CPU.compare_a, 0x02)
+    assert_flags(cpu, z=False, n=True, h=True, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x0F)
+    method_value_call(cpu, CPU.compare_a, 0xFF)
+    assert_flags(cpu, z=False, n=True, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.compare_a, 0x01)
+    assert_flags(cpu, z=False, n=True, h=True, c=True)
+    
+def test_complement_a():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xF0)
+    cpu.complement_a()
+    assert cpu.a.get() == 0x0F
+    assert_flags(cpu, z=True, n=True, h=True, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.complement_a()
+    assert cpu.a.get() == 0xF0
+    assert_flags(cpu, z=False, n=True, h=True, c=False)
+    
+def test_decimal_adjust_a():
+    py.test.skip("not yet implemented")
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.decimal_adjust_a()
+    assert_flags(cpu, z=False, n=True, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.decimal_adjust_a()
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+def test_decrement_register():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.dec, cpu.a)
+    assert cpu.a.get() == 0xFE
+    assert_flags(cpu, z=False, n=True, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    method_register_call(cpu, CPU.dec, cpu.a)
+    assert cpu.a.get() == 0xFD
+    assert_flags(cpu, z=False, n=True, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_register_call(cpu, CPU.dec, cpu.a)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=True, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x10)
+    method_register_call(cpu, CPU.dec, cpu.a)
+    assert cpu.a.get() == 0x0F
+    assert_flags(cpu, z=False, n=True, h=True, c=False)
+
+def test_increment_register():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xF1)
+    method_register_call(cpu, CPU.inc, cpu.a)
+    assert cpu.a.get() == 0xF2
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    method_register_call(cpu, CPU.inc, cpu.a)
+    assert cpu.a.get() == 0xF3
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x0F)
+    method_register_call(cpu, CPU.inc, cpu.a)
+    assert cpu.a.get() == 0x10
+    assert_flags(cpu, z=False, n=False, h=True, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.inc, cpu.a)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=True, c=False)
+  
+def test_decrement_double_register():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.bc.set(0xFFFF)
+    cpu.dec_double_register(cpu.bc)
+    assert cpu.bc.get() == 0xFFFE
+    assert cpu.f.get() == 0xFF
+    
+    cpu.f.set(0xFF)
+    cpu.dec_double_register(cpu.bc)
+    assert cpu.bc.get() == 0xFFFD
+    assert cpu.f.get() == 0xFF
+    
+    cpu.f.set(0xFF)
+    cpu.bc.set(0x0000)
+    cpu.dec_double_register(cpu.bc)
+    assert cpu.bc.get() == 0xFFFF
+    assert cpu.f.get() == 0xFF
+    
+def test_increment_double_register():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.bc.set(0xFFFD)
+    cpu.inc_double_register(cpu.bc)
+    assert cpu.bc.get() == 0xFFFE
+    assert cpu.f.get() == 0xFF
+    
+    cpu.f.set(0xFF)
+    cpu.inc_double_register(cpu.bc)
+    assert cpu.bc.get() == 0xFFFF
+    assert cpu.f.get() == 0xFF
+    
+    cpu.f.set(0xFF)
+    cpu.inc_double_register(cpu.bc)
+    assert cpu.bc.get() == 0x0000
+    assert cpu.f.get() == 0xFF
+    
+def test_disable_interrupts():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.disable_interrups()
+    assert cpu.f.get() == 0xFF
+    
+    cpu.f.set(0x00)
+    cpu.disable_interrups()
+    assert cpu.f.get() == 0x00
+  
+def test_enable_interrupts():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.enable_interrupts()
+    assert cpu.f.get() == 0xFF
+    
+    cpu.f.set(0x00)
+    cpu.enable_interrupts()
+    assert cpu.f.get() == 0x00
+  
+def test_jump():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    prepare_for_double_fetch(cpu, 0x1234)
+    cpu.jump()
+    assert cpu.f.get() == 0xFF
+    assert cpu.pc.get() == 0x1234
+
+def test_conditional_jump():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    prepare_for_double_fetch(cpu, 0x1234)
+    cpu.conditional_jump(True)
+    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.pc.get() == 0x1234+2
+    
+def test_process_2_complement():
+    cpu = get_cpu()
+    
+    assert cpu.process_2_complement(0x00) == 0
+    assert cpu.process_2_complement(0xFF) == -1
+    
+    for i in range(0x7E):
+        assert cpu.process_2_complement(i) == i
+        
+    for i in range(1, 0x7E):
+        assert cpu.process_2_complement(0xFF - i+1) == -i
+    
+def test_relative_jump():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    for i in range(0x7F):
+        cpu.pc.set(0x1234)
+        prepare_for_fetch(cpu, i)
+        cpu.relative_jump()
+        assert cpu.f.get() == 0xFF
+        #+1 fpr 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.pc.get() == 0x1234+1 - i
+
+def test_conditional_relative_jump():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    for i in range(0x7F):
+        cpu.pc.set(0x1234)
+        prepare_for_fetch(cpu, i)
+        cpu.relative_conditional_jump(True)
+        assert cpu.f.get() == 0xFF
+        #+1 fpr a single fetch
+        assert cpu.pc.get() == 0x1234+1 + i
+    
+    cpu.pc.set(0x1234)
+    prepare_for_fetch(cpu, 0x12)
+    cpu.relative_conditional_jump(False)
+    assert cpu.f.get() == 0xFF
+    assert cpu.pc.get() == 0x1234+1
+    
+def store_fetch_added_sp_in_hl():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.sp.set(0x1234)
+    prepare_for_fetch(0x02)
+    cpu.store_fetch_added_sp_in_hl()
+    assert cpu.hl.get() == 0x1234 + 0x02
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    
+    cpu.f.set(0x00)
+    cpu.sp.set(0x1234)
+    prepare_for_fetch(0x02)
+    cpu.store_fetch_added_sp_in_hl()
+    assert cpu.hl.get() == 0x1234 + 0x02
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    
+    cpu.f.set(0xFF)
+    cpu.sp.set(0x1234)
+    prepare_for_fetch(0xFF)
+    cpu.store_fetch_added_sp_in_hl()
+    assert cpu.hl.get() == 0x1234 - 1
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+def test_rotate_left():
+    cpu = get_cpu()
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_left, cpu.a)
+    assert cpu.a.get() == 0xFE
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_left, cpu.a)
+    assert cpu.a.get() == 0xFE+1
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_register_call(cpu, CPU.rotate_left, cpu.a)
+    assert cpu.a.get() == 0x02
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x80)
+    method_register_call(cpu, CPU.rotate_left, cpu.a)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=False, c=True)
+    
+    cpu.f.set(0xFF)
+    cpu.a.set(0x80)
+    method_register_call(cpu, CPU.rotate_left, cpu.a)
+    assert cpu.a.get() == 0x01
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x40)
+    method_register_call(cpu, CPU.rotate_left, cpu.a)
+    assert cpu.a.get() == 0x80
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x7F)
+    method_register_call(cpu, CPU.rotate_left, cpu.a)
+    assert cpu.a.get() == 0xFE
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+def test_rotate_right():
+    cpu = get_cpu()
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_right, cpu.a)
+    assert cpu.a.get() == 0x7F
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_right, cpu.a)
+    assert cpu.a.get() == 0x7F + 0x80
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_register_call(cpu, CPU.rotate_right, cpu.a)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=False, c=True)
+    
+    cpu.f.set(0xFF)
+    cpu.a.set(0x01)
+    method_register_call(cpu, CPU.rotate_right, cpu.a)
+    assert cpu.a.get() == 0x80
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x08)
+    method_register_call(cpu, CPU.rotate_right, cpu.a)
+    assert cpu.a.get() == 0x04
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+   
+    for i in range(0, 7):
+        cpu.f.set(0x00)
+        cpu.a.set(0x80 >> i)
+        method_register_call(cpu, CPU.rotate_right, cpu.a)
+        assert cpu.a.get() == 0x80 >> (i+1)
+        assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+def test_rotate_left_circular():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_left_circular, cpu.a)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu = get_cpu()
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_left_circular, cpu.a)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x80)
+    method_register_call(cpu, CPU.rotate_left_circular, cpu.a)
+    assert cpu.a.get() == 0x01
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0xFF)
+    cpu.a.set(0x01)
+    method_register_call(cpu, CPU.rotate_left_circular, cpu.a)
+    assert cpu.a.get() == 0x02
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+def test_rotate_right_circular():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_right_circular, cpu.a)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu = get_cpu()
+    cpu.f.set(0x00)
+    cpu.a.set(0xFF)
+    method_register_call(cpu, CPU.rotate_right_circular, cpu.a)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_register_call(cpu, CPU.rotate_right_circular, cpu.a)
+    assert cpu.a.get() == 0x80
+    assert_flags(cpu, z=False, n=False, h=False, c=True)
+    
+    cpu.f.set(0xFF)
+    cpu.a.set(0x02)
+    method_register_call(cpu, CPU.rotate_right_circular, cpu.a)
+    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)
+    cpu.a.set(0x01)
+    method_value_call(cpu, CPU.subtract_with_carry_a, 0x00)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=True, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x01)
+    method_value_call(cpu, CPU.subtract_with_carry_a, 0x00)
+    assert cpu.a.get() == 0x01
+    assert_flags(cpu, z=False, n=True, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x10)
+    method_value_call(cpu, CPU.subtract_with_carry_a, 0x01)
+    assert cpu.a.get() == 0x0F
+    assert_flags(cpu, z=False, n=True, h=True, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x00)
+    method_value_call(cpu, CPU.subtract_with_carry_a, 0x01)
+    assert cpu.a.get() == 0xFF
+    assert_flags(cpu, z=False, n=True, h=True, c=True)
+    
+    # FIXME add separated Test for each flag
+    
+
+def test_swap():
+    cpu = get_cpu()
+    cpu.f.set(0xFF)
+    cpu.a.set(0x12)
+    method_register_call(cpu, CPU.swap, cpu.a)
+    assert cpu.a.get() == 0x21
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+    
+    cpu.f.set(0xFF)
+    cpu.a.set(0x00)
+    method_register_call(cpu, CPU.swap, cpu.a)
+    assert cpu.a.get() == 0x00
+    assert_flags(cpu, z=True, n=False, h=False, c=False)
+    
+    cpu.f.set(0x00)
+    cpu.a.set(0x34)
+    method_register_call(cpu, CPU.swap, cpu.a)
+    assert cpu.a.get() == 0x43
+    assert_flags(cpu, z=False, n=False, h=False, c=False)
+
+    
\ No newline at end of file

Modified: pypy/dist/pypy/lang/gameboy/test/test_joypad.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_joypad.py	(original)
+++ pypy/dist/pypy/lang/gameboy/test/test_joypad.py	Sat May 31 09:52:43 2008
@@ -44,11 +44,11 @@
 # TEST BUTTON ------------------------------------------------------------------
 
 def test_ini():
-    value = 0xf
+    value  = 0xf
     button = Button(value)
     assert button.opposite_button is None
-    assert button.code_value == value
-    assert button.is_pressed() == False
+    assert button.code_value      == value
+    assert button.is_pressed()    == False
     
     button2 = Button(value, button)
     assert button2.opposite_button == button
@@ -67,74 +67,74 @@
     button2.press()
     assert button2.is_pressed() == True
     button.press()
-    assert button.is_pressed() == True
+    assert button.is_pressed()  == True
     assert button2.is_pressed() == False
     button.release()
-    assert button.is_pressed() == False
+    assert button.is_pressed()  == False
     assert button2.is_pressed() == False
 
 # TEST JOYPAD DRIVER -----------------------------------------------------------
 
 def test_ini():
     driver = get_driver()
-    assert driver.raised == False
-    assert driver.get_button_code() == 0
+    assert driver.raised               == False
+    assert driver.get_button_code()    == 0
     assert driver.get_direction_code() == 0
     
 def test_isRaised():
-    driver = get_driver()
+    driver        = get_driver()
     driver.raised = True
-    assert driver.raised == True
+    assert driver.raised      == True
     assert driver.is_raised() == True
-    assert driver.raised == False
+    assert driver.raised      == False
     
 def test_button_code_values():
     driver = get_driver()
-    assert driver.up.code_value == constants.BUTTON_UP 
-    assert driver.right.code_value == constants.BUTTON_RIGHT   
-    assert driver.down.code_value == constants.BUTTON_DOWN
-    assert driver.left.code_value == constants.BUTTON_LEFT
+    assert driver.up.code_value     == constants.BUTTON_UP 
+    assert driver.right.code_value  == constants.BUTTON_RIGHT   
+    assert driver.down.code_value   == constants.BUTTON_DOWN
+    assert driver.left.code_value   == constants.BUTTON_LEFT
     assert driver.select.code_value == constants.BUTTON_SELECT
-    assert driver.start.code_value == constants.BUTTON_START
-    assert driver.a.code_value == constants.BUTTON_A
-    assert driver.b.code_value == constants.BUTTON_B
+    assert driver.start.code_value  == constants.BUTTON_START
+    assert driver.a.code_value      == constants.BUTTON_A
+    assert driver.b.code_value      == constants.BUTTON_B
     
     
 def test_toggle_opposite_directions():
     driver = get_driver()
-    directions = [(driver.button_up, driver.up, driver.down),
-                 (driver.button_down, driver.down, driver.up),
-                 (driver.button_left, driver.left, driver.right),
-                 (driver.button_right, driver.right, driver.left)]
+    directions = [(driver.button_up,    driver.up,    driver.down),
+                  (driver.button_down,  driver.down,  driver.up),
+                  (driver.button_left,  driver.left,  driver.right),
+                  (driver.button_right, driver.right, driver.left)]
     for dir in directions:
-        toggleFunction = dir[0]
-        button = dir[1]
+        toggleFunction  = dir[0]
+        button          = dir[1]
         opposite_button = dir[2]
         driver.reset()
         
         opposite_button.press()
-        assert driver.raised == False
-        assert button.is_pressed() == False
+        assert driver.raised                == False
+        assert button.is_pressed()          == False
         assert opposite_button.is_pressed() == True
-        assert driver.get_direction_code() == opposite_button.code_value
-        assert driver.get_button_code() == 0
+        assert driver.get_direction_code()  == opposite_button.code_value
+        assert driver.get_button_code()     == 0
         
         toggleFunction()
-        assert driver.raised == True
-        assert button.is_pressed() == True
+        assert driver.raised                == True
+        assert button.is_pressed()          == True
         assert opposite_button.is_pressed() == False
-        assert driver.get_direction_code() == button.code_value
-        assert driver.get_button_code() == 0
+        assert driver.get_direction_code()  == button.code_value
+        assert driver.get_button_code()     == 0
         
         toggleFunction(False)
-        assert button.is_pressed() == False
+        assert button.is_pressed()          == False
         assert opposite_button.is_pressed() == False
-        assert driver.get_direction_code() == 0
-        assert driver.get_button_code() == 0
+        assert driver.get_direction_code()  == 0
+        assert driver.get_button_code()     == 0
     
     
 def test_toggle_buttons():
-    driver = get_driver()
+    driver  = get_driver()
     buttons = [(driver.button_select, driver.select),
                  (driver.button_start, driver.start),
                  (driver.button_a, driver.a),
@@ -144,24 +144,24 @@
         button = button[1]
         driver.reset()
         
-        assert button.is_pressed() == False
-        assert driver.get_button_code() == 0
+        assert button.is_pressed()         == False
+        assert driver.get_button_code()    == 0
         assert driver.get_direction_code() == 0
         
         toggleFunction()
-        assert driver.raised == True
-        assert button.is_pressed() == True
-        assert driver.get_button_code() == button.code_value
+        assert driver.raised               == True
+        assert button.is_pressed()         == True
+        assert driver.get_button_code()    == button.code_value
         assert driver.get_direction_code() == 0
         
         toggleFunction(False)
-        assert button.is_pressed() == False
-        assert driver.get_button_code() == 0
+        assert button.is_pressed()         == False
+        assert driver.get_button_code()    == 0
         assert driver.get_direction_code() == 0
         
         
 def test_toggle_multiple_buttons():
-    driver = get_driver()
+    driver  = get_driver()
     buttons = [(driver.button_select, driver.select),
                  (driver.button_start, driver.start),
                  (driver.button_a, driver.a),
@@ -205,15 +205,15 @@
         
 def test_emulate():
     joypad = get_joypad()
-    ticks = 2
+    ticks  = 2
     cycles = joypad.cycles
     joypad.emulate(ticks)
     assert cycles - joypad.cycles == ticks
 
 def test_emulate_zero_ticks():
-    joypad = get_joypad()
+    joypad        = get_joypad()
     joypad.cycles = 2
-    ticks = 2
+    ticks         = 2
     joypad.emulate(ticks)
     assert joypad.cycles == constants.JOYPAD_CLOCK
     
@@ -226,15 +226,15 @@
     joypad.cycles = 2
     ticks = 2
     joypad.emulate(ticks)
-    assert joypad.cycles == constants.JOYPAD_CLOCK
-    assert joypad.joyp == value
+    assert joypad.cycles      == constants.JOYPAD_CLOCK
+    assert joypad.joyp        == value
     assert joypad.button_code == 0
     
 def test_read_write():
     joypad = get_joypad()
-    value = 0x2
+    value  = 0x2
     joypad.write(constants.JOYP, value)
-    joyp = 0xC + (value & 0x3)
+    joyp   = 0xC + (value & 0x3)
     assert joypad.joyp == joyp
     joyp = (joyp << 4) + 0xF
     assert joypad.read(constants.JOYP) == joyp



More information about the Pypy-commit mailing list