[pypy-svn] r57676 - in pypy/dist/pypy/lang/gameboy: . test
cami at codespeak.net
cami at codespeak.net
Fri Aug 29 12:54:39 CEST 2008
Author: cami
Date: Fri Aug 29 12:54:35 2008
New Revision: 57676
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/timer.py
pypy/dist/pypy/lang/gameboy/video.py
Log:
renamed flag register for better code understanding
added doc text for flag register
Modified: pypy/dist/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cpu.py (original)
+++ pypy/dist/pypy/lang/gameboy/cpu.py Fri Aug 29 12:54:35 2008
@@ -124,7 +124,41 @@
# ------------------------------------------------------------------------------
class FlagRegister(Register):
-
+ """
+ The Flag Register (lower 8bit of AF register)
+ Bit Name Set Clr Expl.
+ 7 zf Z NZ Zero Flag
+ 6 n - - Add/Sub-Flag (BCD)
+ 5 h - - Half Carry Flag (BCD)
+ 4 cy C NC Carry Flag
+ 3-0 - - - Not used (always zero)
+ Conatins the result from the recent instruction which has affected flags.
+
+ The Zero Flag (Z)
+ This bit becomes set (1) if the result of an operation has been zero (0).
+ Used for conditional jumps.
+
+ The Carry Flag (C, or Cy)
+ Becomes set when the result of an addition became bigger than FFh (8bit) or
+ FFFFh (16bit). Or when the result of a subtraction or comparision became
+ less than zero (much as for Z80 and 80x86 CPUs, but unlike as for 65XX and
+ ARM CPUs). Also the flag becomes set when a rotate/shift operation has
+ shifted-out a "1"-bit.
+ Used for conditional jumps, and for instructions such like ADC, SBC, RL,
+ RLA, etc.
+
+ The BCD Flags (N, H)
+ These flags are (rarely) used for the DAA instruction only, N Indicates
+ whether the previous instruction has been an addition or subtraction, and H
+ indicates carry for lower 4bits of the result, also for DAA, the C flag must
+ indicate carry for upper 8bits.
+ After adding/subtracting two BCD numbers, DAA is intended to convert the
+ result into BCD format; BCD numbers are ranged from 00h to 99h rather than
+ 00h to FFh.
+ Because C and H flags must contain carry-outs for each digit, DAA cannot be
+ used for 16bit operations (which have 4 digits), or for INC/DEC operations
+ (which do not affect C-flag).
+ """
def __init__(self, cpu, reset_value):
assert isinstance(cpu, CPU)
self.cpu = cpu
@@ -134,16 +168,17 @@
def reset(self):
self.partial_reset()
- def partial_reset(self, keep_z=False, keep_n=False, keep_h=False, keep_c=False,\
+ def partial_reset(self, keep_is_zero=False, keep_is_subtraction=False,
+ keep_is_half_carry=False, keep_is_carry=False,\
keep_p=False, keep_s=False):
- if not keep_z:
- self.z_flag = False
- if not keep_n:
- self.n_flag = False
- if not keep_h:
- self.h_flag = False
- if not keep_c:
- self.c_flag = False
+ if not keep_is_zero:
+ self.is_zero = False
+ if not keep_is_subtraction:
+ self.is_subtraction = False
+ if not keep_is_half_carry:
+ self.is_half_carry = False
+ if not keep_is_carry:
+ self.is_carry = False
if not keep_p:
self.p_flag = False
if not keep_s:
@@ -152,41 +187,41 @@
def get(self, use_cycles=True):
value = 0
- value += (int(self.c_flag) << 4)
- value += (int(self.h_flag) << 5)
- value += (int(self.n_flag) << 6)
- value += (int(self.z_flag) << 7)
+ value += (int(self.is_carry) << 4)
+ value += (int(self.is_half_carry) << 5)
+ value += (int(self.is_subtraction) << 6)
+ value += (int(self.is_zero) << 7)
return value + self.lower
def set(self, value, use_cycles=True):
- self.c_flag = bool(value & (1 << 4))
- self.h_flag = bool(value & (1 << 5))
- self.n_flag = bool(value & (1 << 6))
- self.z_flag = bool(value & (1 << 7))
- self.lower = value & 0x0F
+ self.is_carry = bool(value & (1 << 4))
+ self.is_half_carry = bool(value & (1 << 5))
+ self.is_subtraction = bool(value & (1 << 6))
+ self.is_zero = bool(value & (1 << 7))
+ self.lower = value & 0x0F
if use_cycles:
self.cpu.cycles -= 1
- def z_flag_compare(self, a, reset=False):
+ def is_zero_check(self, a, reset=False):
if reset:
self.reset()
if isinstance(a, (Register)):
a = a.get()
- self.z_flag = ((a & 0xFF) == 0)
+ self.is_zero = ((a & 0xFF) == 0)
- def c_flag_compare(self, value, compare_and=0x01, reset=False):
+ def is_carry_compare(self, value, compare_and=0x01, reset=False):
if reset:
self.reset()
- self.c_flag = ((value & compare_and) != 0)
+ self.is_carry = ((value & compare_and) != 0)
- def h_flag_compare(self, value, a, inverted=False):
+ def is_half_carry_compare(self, value, a, inverted=False):
if inverted:
- self.h_flag = ((value & 0x0F) < (a & 0x0F))
+ self.is_half_carry = ((value & 0x0F) < (a & 0x0F))
else:
- self.h_flag = ((value & 0x0F) > (a & 0x0F))
+ self.is_half_carry = ((value & 0x0F) > (a & 0x0F))
- #def c_flag_compare(self, a, b):
- # self.c_flag = (a < b)
+ #def is_carry_compare(self, a, b):
+ # self.is_carry = (a < b)
# # ------------------------------------------------------------------------------
@@ -211,41 +246,41 @@
self.reset()
def ini_registers(self):
- self.b = Register(self)
- self.c = Register(self)
- self.bc = DoubleRegister(self, self.b, self.c, constants.RESET_BC)
-
- self.d = Register(self)
- self.e = Register(self)
- self.de = DoubleRegister(self, self.d, self.e, constants.RESET_DE)
-
- self.h = Register(self)
- self.l = Register(self)
- self.hl = DoubleRegister(self, self.h, self.l, constants.RESET_HL)
-
- self.hli = ImmediatePseudoRegister(self, self.hl)
- self.pc = DoubleRegister(self, Register(self), Register(self), reset_value=constants.RESET_PC)
- self.sp = DoubleRegister(self, Register(self), Register(self), reset_value=constants.RESET_SP)
-
- self.a = Register(self, constants.RESET_A)
- self.f = FlagRegister(self, constants.RESET_F)
- self.af = DoubleRegister(self, self.a, self.f)
+ self.b = Register(self)
+ self.c = Register(self)
+ self.bc = DoubleRegister(self, self.b, self.c, constants.RESET_BC)
+
+ self.d = Register(self)
+ self.e = Register(self)
+ self.de = DoubleRegister(self, self.d, self.e, constants.RESET_DE)
+
+ self.h = Register(self)
+ self.l = Register(self)
+ self.hl = DoubleRegister(self, self.h, self.l, constants.RESET_HL)
+
+ self.hli = ImmediatePseudoRegister(self, self.hl)
+ self.pc = DoubleRegister(self, Register(self), Register(self), reset_value=constants.RESET_PC)
+ self.sp = DoubleRegister(self, Register(self), Register(self), reset_value=constants.RESET_SP)
+
+ self.a = Register(self, constants.RESET_A)
+ self.flag = FlagRegister(self, constants.RESET_F)
+ self.af = DoubleRegister(self, self.a, self.flag)
def reset(self):
self.reset_registers()
- self.f.reset()
- self.f.z_flag = True
- self.ime = False
- self.halted = False
- self.cycles = 0
+ self.flag.reset()
+ self.flag.is_zero = True
+ self.ime = False
+ self.halted = False
+ self.cycles = 0
self.instruction_counter = 0
self.last_op_code = -1
self.last_fetch_execute_op_code = -1
def reset_registers(self):
self.a.reset()
- self.f.reset()
+ self.flag.reset()
self.bc.reset()
self.de.reset()
self.hl.reset()
@@ -306,25 +341,25 @@
def is_z(self):
""" zero flag"""
- return self.f.z_flag
+ return self.flag.is_zero
def is_c(self):
""" carry flag, true if the result did not fit in the register"""
- return self.f.c_flag
+ return self.flag.is_carry
def is_h(self):
""" half carry, carry from bit 3 to 4"""
- return self.f.h_flag
+ return self.flag.is_half_carry
def is_n(self):
""" subtract flag, true if the last operation was a subtraction"""
- return self.f.n_flag
+ return self.flag.is_subtraction
def isS(self):
- return self.f.s_flag
+ return self.flag.s_flag
def is_p(self):
- return self.f.p_flag
+ return self.flag.p_flag
def is_not_z(self):
return not self.is_z()
@@ -483,31 +518,31 @@
# 2 cycles
data = register.get()
added = (self.hl.get() + data) # 1 cycle
- self.f.partial_reset(keep_z=True)
- self.f.h_flag = (((added ^ self.hl.get() ^ data) & 0x1000) != 0)
- self.f.c_flag = (added >= 0x10000 or added < 0)
+ self.flag.partial_reset(keep_is_zero=True)
+ self.flag.is_half_carry = (((added ^ self.hl.get() ^ data) & 0x1000) != 0)
+ self.flag.is_carry = (added >= 0x10000 or added < 0)
self.hl.set(added & 0xFFFF)
self.cycles -= 1
def add_a_with_carry(self, getCaller, setCaller=None):
# 1 cycle
data = getCaller.get()
- s = self.a.get() + data + int(self.f.c_flag)
+ s = self.a.get() + data + int(self.flag.is_carry)
self.add_sub_flag_finish(s,data)
def subtract_with_carry_a(self, getCaller, setCaller=None):
# 1 cycle
data = getCaller.get()
- s = self.a.get() - data - int(self.f.c_flag)
+ s = self.a.get() - data - int(self.flag.is_carry)
self.add_sub_flag_finish(s, data)
- self.f.n_flag = True
+ self.flag.is_subtraction = True
def add_sub_flag_finish(self, s, data):
- self.f.reset()
+ self.flag.reset()
# set the h flag if the 0x10 bit was affected
- 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.flag.is_half_carry = (((s ^ self.a.get() ^ data) & 0x10) != 0)
+ self.flag.is_carry = (s >= 0x100 or s < 0)
+ self.flag.is_zero_check(s)
self.a.set(s & 0xFF) # 1 cycle
def subtract_a(self, getCaller, setCaller=None):
@@ -528,32 +563,32 @@
def compare_a_simple(self, s):
s = (self.a.get() - s) & 0xFF
- self.f.reset()
- self.f.n_flag = True
- self.f.z_flag_compare(s)
- self.subtract_hc_flag_finish(s)
+ self.flag.reset()
+ self.flag.is_subtraction = True
+ self.flag.is_zero_check(s)
+ self.subtract_his_carry_finish(s)
self.cycles -= 1
- 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 subtract_his_carry_finish(self, data):
+ self.flag.is_carry = (data > self.a.get())
+ self.flag.is_half_carry_compare(data, self.a.get())
def and_a(self, getCaller, setCaller=None):
# 1 cycle
self.a.set(self.a.get() & getCaller.get()) # 1 cycle
- self.f.reset()
- self.f.z_flag_compare(self.a.get())
- self.f.h_flag = True
+ self.flag.reset()
+ self.flag.is_zero_check(self.a.get())
+ self.flag.is_half_carry = True
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)
+ self.flag.is_zero_check(self.a.get(), reset=True)
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)
+ self.flag.is_zero_check(self.a.get(), reset=True)
def inc_double_register(self, register):
# INC rr
@@ -566,18 +601,18 @@
def inc(self, getCaller, setCaller):
# 1 cycle
data = (getCaller.get() + 1) & 0xFF
- self.dec_inc_flag_finish(data, setCaller, 0x00)
+ self.dec_inis_carry_finish(data, setCaller, 0x00)
def dec(self, getCaller, setCaller):
# 1 cycle
data = (getCaller.get() - 1) & 0xFF
- self.dec_inc_flag_finish(data, setCaller, 0x0F)
- self.f.n_flag = True
+ self.dec_inis_carry_finish(data, setCaller, 0x0F)
+ self.flag.is_subtraction = True
- def dec_inc_flag_finish(self, data, setCaller, compare):
- self.f.partial_reset(keep_c=True)
- self.f.z_flag_compare(data)
- self.f.h_flag = ((data & 0x0F) == compare)
+ def dec_inis_carry_finish(self, data, setCaller, compare):
+ self.flag.partial_reset(keep_is_carry=True)
+ self.flag.is_zero_check(data)
+ self.flag.is_half_carry = ((data & 0x0F) == compare)
setCaller.set(data) # 1 cycle
def rotate_left_circular(self, getCaller, setCaller):
@@ -595,7 +630,7 @@
def rotate_left(self, getCaller, setCaller):
# 1 cycle
data = getCaller.get()
- s = ((data & 0x7F) << 1) + int(self.f.c_flag)
+ s = ((data & 0x7F) << 1) + int(self.flag.is_carry)
self.flags_and_setter_finish(s, data, setCaller, 0x80) # 1 cycle
def rotate_left_a(self):
@@ -618,7 +653,7 @@
# 1 cycle
data = getCaller.get()
s = (data >> 1)
- if self.f.c_flag:
+ if self.flag.is_carry:
s += 0x80
self.flags_and_setter_finish(s, data, setCaller) # 1 cycle
@@ -648,25 +683,24 @@
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(data, compare_and)
+ self.flag.reset()
+ self.flag.is_zero_check(s)
+ self.flag.is_carry_compare(data, compare_and)
setCaller.set(s) # 1 cycle
def swap(self, getCaller, setCaller):
data = getCaller.get()
# 1 cycle
s = ((data << 4) + (data >> 4)) & 0xFF
- self.f.z_flag_compare(s, reset=True)
+ self.flag.is_zero_check(s, reset=True)
setCaller.set(s)
def test_bit(self, getCaller, setCaller, n):
# 2 cycles
- self.f.partial_reset(keep_c=True)
- self.f.h_flag = True
- self.f.z_flag = False
- self.f.z_flag = ((getCaller.get() & (1 << n)) == 0)
+ self.flag.partial_reset(keep_is_carry=True)
+ self.flag.is_half_carry = True
+ self.flag.is_zero = ((getCaller.get() & (1 << n)) == 0)
self.cycles -= 1
def set_bit(self, getCaller, setCaller, n):
@@ -733,7 +767,7 @@
# LDH (nn),A 3 cycles
self.write(0xFF00 + self.fetch(), self.a.get()) # 2 + 1 cycles
- def write_a_at_expaded_c_address(self):
+ def write_a_at_expanded_c_address(self):
# LDH (C),A 2 cycles
self.write(0xFF00 + self.c.get(), self.a.get()) # 2 cycles
@@ -757,8 +791,8 @@
def complement_a(self):
# CPA
self.a.set(self.a.get() ^ 0xFF)
- self.f.n_flag = True
- self.f.h_flag = True
+ self.flag.is_subtraction = True
+ self.flag.is_half_carry = True
def decimal_adjust_a(self):
# DAA 1 cycle
@@ -777,10 +811,10 @@
self.a.set((self.a.get() + delta) & 0xFF) # 1 cycle
else:
self.a.set((self.a.get() - delta) & 0xFF) # 1 cycle
- self.f.partial_reset(keep_n=True)
+ self.flag.partial_reset(keep_is_subtraction=True)
if delta >= 0x60:
- self.f.c_flag = True
- self.f.z_flag_compare(self.a.get())
+ self.flag.is_carry = True
+ self.flag.is_zero_check(self.a.get())
def increment_sp_by_fetch(self):
# ADD SP,nn 4 cycles
@@ -796,25 +830,25 @@
# 1 cycle
offset = process_2_complement(self.fetch()) # 1 cycle
s = (self.sp.get() + offset) & 0xFFFF
- self.f.reset()
+ self.flag.reset()
if (offset >= 0):
- self.f.c_flag = (s < self.sp.get())
+ self.flag.is_carry = (s < self.sp.get())
if (s & 0x0F00) < (self.sp.get() & 0x0F00):
- self.f.h_flag = True
+ self.flag.is_half_carry = True
else:
- self.f.c_flag = (s > self.sp.get())
+ self.flag.is_carry = (s > self.sp.get())
if (s & 0x0F00) > (self.sp.get() & 0x0F00):
- self.f.h_flag = True
+ self.flag.is_half_carry = True
return s
def complement_carry_flag(self):
# CCF/SCF
- self.f.partial_reset(keep_z=True, keep_c=True)
- self.f.c_flag = not self.f.c_flag
+ self.flag.partial_reset(keep_is_zero=True, keep_is_carry=True)
+ self.flag.is_carry = not self.flag.is_carry
def set_carry_flag(self):
- self.f.partial_reset(keep_z=True)
- self.f.c_flag = True
+ self.flag.partial_reset(keep_is_zero=True)
+ self.flag.is_carry = True
def nop(self):
# NOP 1 cycle
@@ -880,7 +914,7 @@
# RST nn 4 cycles
self.call(nn) # 4 cycles
- def disable_interrups(self):
+ def disable_interrupts(self):
# DI/EI 1 cycle
self.ime = False
self.cycles -= 1
@@ -1072,9 +1106,9 @@
(0x37, CPU.set_carry_flag),
(0x3F, CPU.complement_carry_flag),
(0x76, CPU.halt),
- (0xF3, CPU.disable_interrups),
+ (0xF3, CPU.disable_interrupts),
(0xFB, CPU.enable_interrupts),
- (0xE2, CPU.write_a_at_expaded_c_address),
+ (0xE2, CPU.write_a_at_expanded_c_address),
(0xEA, CPU.store_a_at_fetched_address),
(0xF2, CPU.store_expanded_c_in_a),
(0xFA, CPU.store_fetched_memory_in_a),
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 Fri Aug 29 12:54:35 2008
@@ -34,7 +34,7 @@
def test_reset():
cpu = get_cpu()
assert cpu.a.get() == 0x01
- #assert cpu.f.get() == 0xB0
+ #assert cpu.flag.get() == 0xB0
assert cpu.b.get() == 0x00
assert cpu.c.get() == 0x13
assert cpu.de.get() == 0x00D8
@@ -46,7 +46,7 @@
assert_default_registers(cpu)
assert cpu.af.cpu == cpu
assert cpu.a.cpu == cpu
- assert cpu.f.cpu == cpu
+ assert cpu.flag.cpu == cpu
assert cpu.bc.cpu == cpu
assert cpu.b.cpu == cpu
@@ -120,23 +120,23 @@
def test_flags():
cpu = get_cpu()
- cpu.f.set(constants.Z_FLAG)
+ cpu.flag.set(constants.Z_FLAG)
assert cpu.is_z() == True
assert cpu.is_not_z() == False
- cpu.f.set(~constants.Z_FLAG)
+ cpu.flag.set(~constants.Z_FLAG)
assert cpu.is_z() == False
assert cpu.is_not_z() == True
- cpu.f.set(constants.C_FLAG)
+ cpu.flag.set(constants.C_FLAG)
assert cpu.is_c() == True
assert cpu.is_not_c() == False
- cpu.f.set(~constants.C_FLAG)
+ cpu.flag.set(~constants.C_FLAG)
assert cpu.is_c() == False
assert cpu.is_not_c() == True
def test_flags_memory_access():
cpu = get_cpu()
- cpu.f.set(constants.Z_FLAG)
+ cpu.flag.set(constants.Z_FLAG)
assert cpu.is_z() == True
prepare_for_fetch(cpu, 0x12, 0x12)
cpu.memory.write(0x1234, 0x12)
@@ -220,7 +220,7 @@
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))
+ assert cpu.flag.get() == f, "Register f is %s but should be %s" % (hex(cpu.flag.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:
@@ -234,17 +234,17 @@
def assert_flags(cpu, z_flag=None, n_flag=None, h_flag=None, c_flag=None, p_flag=None, s_flag=None):
if z_flag is not None:
- assert cpu.f.z_flag == z_flag, "Z-Flag is %s but should be %s" % (cpu.f.z_flag, z_flag)
+ assert cpu.flag.is_zero == z_flag, "Z-Flag is %s but should be %s" % (cpu.flag.is_zero, z_flag)
if n_flag is not None:
- assert cpu.f.n_flag == n_flag, "N-Flag is %s but should be %s" % (cpu.f.n_flag, n_flag)
+ assert cpu.flag.is_subtraction == n_flag, "N-Flag is %s but should be %s" % (cpu.flag.is_subtraction, n_flag)
if h_flag is not None:
- assert cpu.f.h_flag == h_flag, "H-Flag is %s but should be %s" % (cpu.f.h_flag, h_flag)
+ assert cpu.flag.is_half_carry == h_flag, "H-Flag is %s but should be %s" % (cpu.flag.is_half_carry, h_flag)
if c_flag is not None:
- assert cpu.f.c_flag == c_flag, "C-Flag is %s but should be %s" % (cpu.f.c_flag, c_flag)
+ assert cpu.flag.is_carry == c_flag, "C-Flag is %s but should be %s" % (cpu.flag.is_carry, c_flag)
if p_flag is not None:
- assert cpu.f.p_flag == p_flag, "P-Flag is %s but should be %s" % (cpu.f.p_flag, p_flag)
+ assert cpu.flag.p_flag == p_flag, "P-Flag is %s but should be %s" % (cpu.flag.p_flag, p_flag)
if s_flag is not None:
- assert cpu.f.s_flag == s_flag, "S-Flag is %s but should be %s" % (cpu.f.s_flag, s_flag)
+ assert cpu.flag.s_flag == s_flag, "S-Flag is %s but should be %s" % (cpu.flag.s_flag, s_flag)
def prepare_for_fetch(cpu, value, valueLo=None):
pc = cpu.pc.get()
@@ -373,7 +373,7 @@
cycle_test(cpu, 0x18, 3)
# relative offset + one fetch
assert cpu.pc.get() == 0x1234 + jump + 1
- assert_default_registers(cpu, f=cpu.f.get(), pc=0x1234+jump+1)
+ assert_default_registers(cpu, f=cpu.flag.get(), pc=0x1234+jump+1)
# jr_NZ_nn see test_jr_cc_nn
def test_0x20_to_0x38_relative_conditional_jump():
@@ -385,17 +385,17 @@
for jump in range(-128,128):
cpu.pc.set(0x1234)
prepare_for_fetch(cpu, jump & 0xFF)
- cpu.f.set(flags[i])
+ cpu.flag.set(flags[i])
cycle_test(cpu, opCode, 3)
# relative offset + one fetch
assert cpu.pc.get() == 0x1234 + jump + 1
- assert_default_registers(cpu, f=cpu.f.get(), pc=0x1234+jump+1)
+ assert_default_registers(cpu, f=cpu.flag.get(), pc=0x1234+jump+1)
pc = cpu.pc.get()
- cpu.f.set(~flags[i])
+ cpu.flag.set(~flags[i])
cycle_test(cpu, opCode, 2)
assert cpu.pc.get() == pc+1
- assert_default_registers(cpu, f=cpu.f.get(), pc=pc+1)
+ assert_default_registers(cpu, f=cpu.flag.get(), pc=pc+1)
value += 3
opCode += 0x08
@@ -544,7 +544,7 @@
# cycle testing is done in the other tests
a = cpu.a
a.set(0xFF)
- cpu.f.c_flag = True
+ cpu.flag.is_carry = True
cpu.inc(RegisterCallWrapper(a), RegisterCallWrapper(a))
assert_default_flags(cpu, z_flag=True, h_flag=True, c_flag=True)
@@ -589,22 +589,22 @@
# cycle testing is done in the other tests
a = cpu.a
a.set(1)
- cpu.f.c_flag = True
+ cpu.flag.is_carry = True
cpu.dec(RegisterCallWrapper(a), RegisterCallWrapper(a))
assert_default_flags(cpu, z_flag=True, h_flag=False, n_flag=True, c_flag=True)
a.set(1)
- cpu.f.c_flag = False
+ cpu.flag.is_carry = False
cpu.dec(RegisterCallWrapper(a), RegisterCallWrapper(a))
assert_default_flags(cpu, z_flag=True, h_flag=False, n_flag=True, c_flag=False)
a.set(0x0F+1)
- cpu.f.c_flag = True
+ cpu.flag.is_carry = True
cpu.dec(RegisterCallWrapper(a), RegisterCallWrapper(a))
assert_default_flags(cpu, z_flag=False, h_flag=True, n_flag=True, c_flag=True)
a.set(0x0F+1)
- cpu.f.c_flag = False
+ cpu.flag.is_carry = False
cpu.dec(RegisterCallWrapper(a), RegisterCallWrapper(a))
assert_default_flags(cpu, z_flag=False, h_flag=True, n_flag=True, c_flag=False)
@@ -701,7 +701,7 @@
def test_0x17():
cpu = get_cpu()
value = 0x01
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
cpu.a.set(value)
cycle_test(cpu, 0x17, 1)
assert_default_registers(cpu, a=(value << 1) & 0xFF, f=None);
@@ -710,20 +710,20 @@
def test_0x1F():
cpu = get_cpu()
value = 0x40
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
cpu.a.set(value)
cycle_test(cpu, 0x1F, 1)
assert_default_registers(cpu, a=(value >> 1) & 0xFF, f=None);
cpu.reset()
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
value = 0x40
cpu.a.set(value)
cycle_test(cpu, 0x1F, 1)
assert_default_registers(cpu, a=(value >> 1) & 0xFF, f=None);
cpu.reset()
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
value = 0x02
cpu.a.set(value)
cycle_test(cpu, 0x1F, 1)
@@ -738,9 +738,9 @@
def test_0x2F_complement_a():
cpu = get_cpu()
value = 0x12
- fValue = cpu.f.get()
- cpu.f.n_flag = False
- cpu.f.h_flag = False
+ fValue = cpu.flag.get()
+ cpu.flag.is_subtraction = False
+ cpu.flag.is_half_carry = False
cpu.a.set(value)
cycle_test(cpu, 0x2F, 1)
assert_default_registers(cpu, a=value^0xFF, f=None)
@@ -748,12 +748,12 @@
# scf
def test_0x37():
cpu = get_cpu()
- cpu.f.c_flag = False
+ cpu.flag.is_carry = False
cycle_test(cpu, 0x37, 0)
assert_default_registers(cpu, f=None)
assert_default_flags(cpu, c_flag=True)
- cpu.f.c_flag = True
+ cpu.flag.is_carry = True
cycle_test(cpu, 0x37, 0)
assert_default_registers(cpu, f=None)
assert_default_flags(cpu, c_flag=True)
@@ -761,12 +761,12 @@
# ccf
def test_0x3F():
cpu = get_cpu()
- cpu.f.c_flag = True
+ cpu.flag.is_carry = True
cycle_test(cpu, 0x3F, 0)
assert_default_registers(cpu, f=None)
assert_default_flags(cpu, c_flag=False)
- cpu.f.c_flag = False
+ cpu.flag.is_carry = False
cycle_test(cpu, 0x3F, 0)
assert_default_registers(cpu, f=None)
assert_default_flags(cpu, c_flag=True)
@@ -844,7 +844,7 @@
assert cpu.a.get() == 2*value
cpu.reset()
- cpu.f.c_flag = True
+ cpu.flag.is_carry = True
cpu.a.set(value-1)
register.set(value)
numCycles= 1
@@ -893,7 +893,7 @@
assert cpu.a.get() == 0
cpu.reset()
- cpu.f.c_flag = True
+ cpu.flag.is_carry = True
cpu.a.set(value+1)
register.set(value)
numCycles= 1
@@ -989,9 +989,9 @@
numCycles = 2
cycle_test(cpu, opCode, numCycles)
if register == cpu.a:
- assert cpu.f.z_flag == True
+ assert cpu.flag.is_zero == True
else:
- assert cpu.f.z_flag == False
+ assert cpu.flag.is_zero == False
cpu.a.set(0x12)
register.set(0x12)
@@ -999,7 +999,7 @@
if register == cpu.hli:
numCycles = 2
cycle_test(cpu, opCode, numCycles)
- assert cpu.f.z_flag == True
+ assert cpu.flag.is_zero == True
opCode += 0x01
@@ -1012,15 +1012,15 @@
for i in range(0, 4):
cpu.reset()
prepare_for_pop(cpu, value >> 8, value & 0xFF)
- cpu.f.set(flags[i])
+ cpu.flag.set(flags[i])
cycle_test(cpu, opCode, 5)
assert cpu.pc.get() == value
cpu.reset()
prepare_for_pop(cpu, value >> 8, value & 0xFF)
- cpu.f.set(~flags[i])
+ cpu.flag.set(~flags[i])
cycle_test(cpu, opCode, 2)
- assert_default_registers(cpu, f=cpu.f.get())
+ assert_default_registers(cpu, f=cpu.flag.get())
value += 3
opCode += 0x08
@@ -1088,7 +1088,7 @@
cpu.sp.set(valueSp)
pc = cpu.pc.get()
cycle_test(cpu, 0xF8, 3)
- f = cpu.f.get();
+ f = cpu.flag.get();
assert_default_registers(cpu, hl=valueSp+value, f=f, sp=valueSp, pc=pc+1)
# pop_BC to pop_AF
@@ -1195,13 +1195,13 @@
cpu.reset()
prepare_for_fetch(cpu, value >> 8, value & 0xFF)
pc = cpu.pc.get()
- cpu.f.set(flags[i])
+ cpu.flag.set(flags[i])
cycle_test(cpu, opCode, 4)
assert_default_registers(cpu, f=flags[i] & 0xFF, pc=value)
cpu.reset()
prepare_for_fetch(cpu, value >> 8, value & 0xFF)
- cpu.f.set(~flags[i])
+ cpu.flag.set(~flags[i])
pc = cpu.pc.get()
cycle_test(cpu, opCode, 3)
assert_default_registers(cpu, f=~flags[i] & 0xFF, pc=pc+2)
@@ -1289,7 +1289,7 @@
# set the condition to false and dont call
flagSetter(cpu, False)
cpu.pc.set(0)
- f = cpu.f.get()
+ f = cpu.flag.get()
cycle_test(cpu, opCode, 3)
assert_default_registers(cpu, pc=2, f=f)
# set the condition to true: unconditional_call
@@ -1300,7 +1300,7 @@
cpu.sp.set(0x03)
prepare_for_fetch(cpu, fetchValue >> 8, fetchValue & 0xFF)
assert cpu.sp.get() == 0x03
- f = cpu.f.get()
+ f = cpu.flag.get()
cycle_test(cpu, opCode, 6)
assert_default_registers(cpu, pc=fetchValue, sp=1, f=f)
# 2 fetches happen before the pc is pushed on the stack
@@ -1313,7 +1313,7 @@
conditional_call_test(cpu, 0xC4, set_flag_0xC4)
def set_flag_0xC4(cpu, value):
- cpu.f.z_flag = not value
+ cpu.flag.is_zero = not value
# call_Z_nnnn
def test_0xCC_call_z_nnn():
@@ -1321,7 +1321,7 @@
conditional_call_test(cpu, 0xCC, set_flag_0xCC)
def set_flag_0xCC(cpu, value):
- cpu.f.z_flag = value
+ cpu.flag.is_zero = value
# call_NC_nnnn
def test_0xD4_call_nc_nnn():
@@ -1329,7 +1329,7 @@
conditional_call_test(cpu, 0xD4, set_flag_0xD4)
def set_flag_0xD4(cpu, value):
- cpu.f.c_flag = not value
+ cpu.flag.is_carry = not value
# call_C_nnnn
def test_0xDC_call_C_nnnn():
@@ -1337,7 +1337,7 @@
conditional_call_test(cpu, 0xDC, set_flag_0xDC)
def set_flag_0xDC(cpu, value):
- cpu.f.c_flag = value
+ cpu.flag.is_carry = value
# call_nnnn
def test_unconditional_call():
@@ -1394,7 +1394,7 @@
pc = cpu.pc.get()
cycle_test(cpu, opCode, cycles)
- assert_default_registers(cpu, a=opCaller(value,valueAdd, cpu), pc=pc+1, f=cpu.f.get())
+ assert_default_registers(cpu, a=opCaller(value,valueAdd, cpu), pc=pc+1, f=cpu.flag.get())
return cpu
# add_A_nn
@@ -1436,8 +1436,8 @@
cycle_test(cpu, 0xFE, 2)
- assert_default_registers(cpu, a=valueA, pc=pc+1, f=cpu.f.get())
- assert cpu.f.z_flag == True
+ assert_default_registers(cpu, a=valueA, pc=pc+1, f=cpu.flag.get())
+ assert cpu.flag.is_zero == True
# rst(0x00) to rst(0x38)
def test_0xC7_to_0xFF_reset():
@@ -1528,12 +1528,12 @@
cpu.reset()
register.set(0)
fetch_execute_cycle_test_second_order(cpu, registerOpCode, cycles)
- assert cpu.f.z_flag == True
+ assert cpu.flag.is_zero == True
cpu.reset()
register.set((1<<i))
fetch_execute_cycle_test_second_order(cpu, registerOpCode, cycles)
- assert cpu.f.z_flag == False
+ assert cpu.flag.is_zero == False
registerOpCode += 0x08
opCode += 0x01
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 Fri Aug 29 12:54:35 2008
@@ -44,7 +44,7 @@
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))
+ assert cpu.flag.get() == f, "Register f is %s but should be %s" % (hex(cpu.flag.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:
@@ -58,17 +58,17 @@
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)
+ assert cpu.flag.is_zero == z, "Z-Flag is %s but should be %s" % (cpu.flag.is_zero, 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)
+ assert cpu.flag.is_subtraction == n, "N-Flag is %s but should be %s" % (cpu.flag.is_subtraction, 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)
+ assert cpu.flag.is_half_carry == h, "H-Flag is %s but should be %s" % (cpu.flag.is_half_carry, 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)
+ assert cpu.flag.is_carry == c, "C-Flag is %s but should be %s" % (cpu.flag.is_carry, 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)
+ assert cpu.flag.p_flag == p, "P-Flag is %s but should be %s" % (cpu.flag.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)
+ assert cpu.flag.s_flag == s, "S-Flag is %s but should be %s" % (cpu.flag.s_flag, s)
def prepare_for_double_fetch(cpu, value):
prepare_for_fetch(cpu, (value & 0xFF00) >> 8, value & 0x00FF)
@@ -125,7 +125,7 @@
def test_add_with_carry():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.a.set(0x00)
method_value_call(cpu, CPU.add_a_with_carry, 0x00)
assert cpu.a.get() == 0x01
@@ -135,7 +135,7 @@
def test_add_a():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.a.set(0x00)
method_value_call(cpu, CPU.add_a, 0x00)
assert cpu.a.get() == 0x00
@@ -144,25 +144,25 @@
add_flag_test(cpu, CPU.add_a)
def add_flag_test(cpu, method):
- cpu.f.set(0x00)
+ cpu.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0xFF)
method_value_call(cpu, CPU.add_a_with_carry, 0x01)
assert cpu.a.get() == 0x00
@@ -170,37 +170,37 @@
def test_add_hl():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.hl.set(0xFF00)
method_value_call(cpu, CPU.add_hl, 0x0100)
assert cpu.hl.get() == 0x0000
@@ -208,7 +208,7 @@
def test_add_sp():
cpu = get_cpu()
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
for i in range(0, 0x7F):
cpu.sp.set(0x00)
prepare_for_fetch(cpu, i);
@@ -225,35 +225,35 @@
def test_add_sp_carry():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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.flag.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.flag.set(0xFF)
cpu.sp.set(0x02)
prepare_for_fetch(cpu, 0xFE)
cpu.increment_sp_by_fetch()
@@ -262,7 +262,7 @@
def test_add_sp_carry_flags():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.sp.set(0x0FFF)
prepare_for_fetch(cpu, 0x01)
cpu.increment_sp_by_fetch()
@@ -291,12 +291,12 @@
def test_and_a():
cpu = get_cpu()
cpu.sp.set(0xFF)
- cpu.f.set(0xFF)
+ cpu.flag.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.f.set(0x00)
+ cpu.flag.set(0x00)
method_value_call(cpu, CPU.and_a, 0x00)
assert cpu.a.get() == 0x00
assert_flags(cpu, z=True, n=False, h=True, c=False)
@@ -306,7 +306,7 @@
assert cpu.a.get() == 0x12
assert_flags(cpu, z=False, n=False, h=True, c=False)
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
cpu.a.set(0xFF)
method_value_call(cpu, CPU.and_a, 0x12)
assert cpu.a.get() == 0x12
@@ -314,31 +314,31 @@
def test_or_a():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0x01)
method_value_call(cpu, CPU.or_a, 0xFF)
assert cpu.a.get() == 0xFF
@@ -346,31 +346,31 @@
def test_xor_a():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0x00)
method_value_call(cpu, CPU.xor_a, 0x00)
assert cpu.a.get() == 0x00
@@ -378,19 +378,19 @@
def test_bit():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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)
@@ -404,118 +404,118 @@
def test_set_bit():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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
+ assert cpu.flag.get() == 0xFF
for i in range(8):
cpu = get_cpu()
- cpu.f.set(0x00)
+ cpu.flag.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
+ assert cpu.flag.get() == 0x00
def test_reset_bit():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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
+ assert cpu.flag.get() == 0xFF
for i in range(8):
cpu = get_cpu()
- cpu.f.set(0x00)
+ cpu.flag.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
+ assert cpu.flag.get() == 0x00
def test_unconditional_call():
cpu = get_cpu()
- cpu.f.set(0x12)
+ cpu.flag.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.flag.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.flag.set(0x12)
cpu.pc.set(0x1234)
cpu.conditional_call(False)
assert cpu.pc.get() == 0x1234+2
- assert cpu.f.get() == 0x12
+ assert cpu.flag.get() == 0x12
cpu.reset()
- cpu.f.set(0x12)
+ cpu.flag.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.flag.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.flag.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.flag.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.flag.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.flag.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.flag.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.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.complement_a()
assert cpu.a.get() == 0xF0
assert_flags(cpu, z=False, n=True, h=True, c=False)
@@ -523,36 +523,36 @@
def test_decimal_adjust_a():
py.test.skip("not yet implemented")
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.set(0x00)
cpu.a.set(0)
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.flag.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)
+ cpu.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0x10)
method_register_call(cpu, CPU.dec, cpu.a)
assert cpu.a.get() == 0x0F
@@ -560,24 +560,24 @@
def test_increment_register():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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)
+ cpu.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0xFF)
method_register_call(cpu, CPU.inc, cpu.a)
assert cpu.a.get() == 0x00
@@ -585,81 +585,81 @@
def test_decrement_double_register():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.bc.set(0xFFFF)
cpu.dec_double_register(cpu.bc)
assert cpu.bc.get() == 0xFFFE
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.dec_double_register(cpu.bc)
assert cpu.bc.get() == 0xFFFD
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.bc.set(0x0000)
cpu.dec_double_register(cpu.bc)
assert cpu.bc.get() == 0xFFFF
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
def test_increment_double_register():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.bc.set(0xFFFD)
cpu.inc_double_register(cpu.bc)
assert cpu.bc.get() == 0xFFFE
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.inc_double_register(cpu.bc)
assert cpu.bc.get() == 0xFFFF
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.inc_double_register(cpu.bc)
assert cpu.bc.get() == 0x0000
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.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
+ cpu.flag.set(0xFF)
+ cpu.disable_interrupts()
+ assert cpu.flag.get() == 0xFF
+
+ cpu.flag.set(0x00)
+ cpu.disable_interrupts()
+ assert cpu.flag.get() == 0x00
def test_enable_interrupts():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.enable_interrupts()
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
cpu.enable_interrupts()
- assert cpu.f.get() == 0x00
+ assert cpu.flag.get() == 0x00
def test_jump():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
prepare_for_double_fetch(cpu, 0x1234)
cpu.jump()
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
assert cpu.pc.get() == 0x1234
def test_conditional_jump():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
prepare_for_double_fetch(cpu, 0x1234)
cpu.conditional_jump(True)
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.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.flag.get() == 0xFF
assert cpu.pc.get() == 0x1234+2
def test_process_2_complement():
@@ -674,12 +674,12 @@
def test_relative_jump():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
for i in range(0x7F):
cpu.pc.set(0x1234)
prepare_for_fetch(cpu, i)
cpu.relative_jump()
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
#+1 for a single fetch
assert cpu.pc.get() == 0x1234+1 + i
@@ -687,30 +687,30 @@
cpu.pc.set(0x1234)
prepare_for_fetch(cpu, 0xFF - i+1)
cpu.relative_jump()
- assert cpu.f.get() == 0xFF
+ assert cpu.flag.get() == 0xFF
#+1 for a single fetch
assert cpu.pc.get() == 0x1234+1 - i
def test_conditional_relative_jump():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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
+ assert cpu.flag.get() == 0xFF
#+1 for 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.flag.get() == 0xFF
assert cpu.pc.get() == 0x1234+1
def store_fetch_added_sp_in_hl():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.sp.set(0x1234)
prepare_for_fetch(0x02)
cpu.store_fetch_added_sp_in_hl()
@@ -718,7 +718,7 @@
assert_flags(cpu, z=False, n=False, h=False, c=False)
- cpu.f.set(0x00)
+ cpu.flag.set(0x00)
cpu.sp.set(0x1234)
prepare_for_fetch(0x02)
cpu.store_fetch_added_sp_in_hl()
@@ -726,7 +726,7 @@
assert_flags(cpu, z=False, n=False, h=False, c=False)
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
cpu.sp.set(0x1234)
prepare_for_fetch(0xFF)
cpu.store_fetch_added_sp_in_hl()
@@ -735,44 +735,44 @@
def test_rotate_left():
cpu = get_cpu()
- cpu.f.set(0x00)
+ cpu.flag.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.flag.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.flag.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.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0x7F)
method_register_call(cpu, CPU.rotate_left, cpu.a)
assert cpu.a.get() == 0xFE
@@ -780,39 +780,39 @@
def test_rotate_right():
cpu = get_cpu()
- cpu.f.set(0x00)
+ cpu.flag.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.flag.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.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0x80 >> i)
method_register_call(cpu, CPU.rotate_right, cpu.a)
assert cpu.a.get() == 0x80 >> (i+1)
@@ -820,26 +820,26 @@
def test_rotate_left_circular():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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.flag.set(0xFF)
cpu.a.set(0x01)
method_register_call(cpu, CPU.rotate_left_circular, cpu.a)
assert cpu.a.get() == 0x02
@@ -847,26 +847,26 @@
def test_rotate_right_circular():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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.flag.set(0xFF)
cpu.a.set(0x02)
method_register_call(cpu, CPU.rotate_right_circular, cpu.a)
assert cpu.a.get() == 0x01
@@ -874,25 +874,25 @@
def test_subtract_with_carry_a():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0x00)
method_value_call(cpu, CPU.subtract_with_carry_a, 0x01)
assert cpu.a.get() == 0xFF
@@ -902,13 +902,13 @@
def test_subtract_a():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.set(0xFF)
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.flag.set(0xFF)
cpu.a.set(0x01)
method_value_call(cpu, CPU.subtract_a, 0x01)
assert cpu.a.get() == 0x00
@@ -917,25 +917,25 @@
subtract_flag_test(cpu, CPU.subtract_a)
def subtract_flag_test(cpu, method):
- cpu.f.set(0x00)
+ cpu.flag.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(0x00)
+ cpu.flag.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(0x00)
+ cpu.flag.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(0x00)
+ cpu.flag.set(0x00)
cpu.a.set(0x00)
method_value_call(cpu, CPU.subtract_a, 0x01)
assert cpu.a.get() == 0xFF
@@ -943,19 +943,19 @@
def test_swap():
cpu = get_cpu()
- cpu.f.set(0xFF)
+ cpu.flag.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.flag.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.flag.set(0x00)
cpu.a.set(0x34)
method_register_call(cpu, CPU.swap, cpu.a)
assert cpu.a.get() == 0x43
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 Fri Aug 29 12:54:35 2008
@@ -114,29 +114,29 @@
emulate_step_op_codes_test(gameboy, [0xDD, 0xAF, 0xC6])
pc = cpu.pc.get()
assert cpu.a.get() == 1
- assert cpu.f.c_flag == False
+ assert cpu.flag.c_flag == False
# check jr in .loop2
emulate_step_op_codes_test(gameboy, [0x30])
assert cpu.pc.get() == pc-2
# looping in .loop2
emulate_step_op_codes_test(gameboy, [0xC6, 0x30]*0xFF)
assert cpu.a.get() == 0
- assert cpu.f.c_flag == True
+ assert cpu.flag.c_flag == True
# debugg call reseting
emulate_step_op_codes_test(gameboy, [0xDD, 0xAF])
assert cpu.a.get() == 0
- assert cpu.f.c_flag == False
+ assert cpu.flag.c_flag == False
pc = cpu.pc.get()
# enter .loop3
- c_flag = cpu.f.c_flag
+ c_flag = cpu.flag.c_flag
emulate_step_op_codes_test(gameboy, [0x3C, 0xD2])
- assert cpu.f.c_flag == c_flag
+ assert cpu.flag.c_flag == c_flag
assert cpu.a.get() == 1
assert cpu.pc.get() == pc
# looping in .loop3
emulate_step_op_codes_test(gameboy, [0x3C, 0xD2]*255)
assert cpu.a.get() == 0
- assert cpu.f.c_flag == False
+ assert cpu.flag.c_flag == False
emulate_step_op_codes_test(gameboy, [0xDD, 0x76, 0x76])
@@ -192,7 +192,7 @@
emulate_step_op_codes_test(gameboy, [0x0D, 0x20])
assert cpu.c.get() == c-1
- while not cpu.f.z_flag:
+ while not cpu.flag.is_zero:
hl = cpu.hl.get()
emulate_step_op_codes_test(gameboy, [0x22])
assert cpu.hl.get() == hl+1
Modified: pypy/dist/pypy/lang/gameboy/timer.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/timer.py (original)
+++ pypy/dist/pypy/lang/gameboy/timer.py Fri Aug 29 12:54:35 2008
@@ -60,13 +60,23 @@
return self.divider
def set_divider(self, data):
- """ DIV register resets on write """
+ """
+ This register is incremented at rate of 16384Hz (~16779Hz on SGB).
+ Writing any value to this register resets it to 00h.
+ """
self.divider = 0
def get_timer_counter(self):
return self.timer_counter
def set_timer_counter(self, data):
+ """
+ TIMA
+ This timer is incremented by a clock frequency specified by the TAC
+ register ($FF07). When the value overflows (gets bigger than FFh) then
+ it will be reset to the value specified in TMA (FF06), and an interrupt
+ will be requested, as described below.
+ """
self.timer_counter = data
@@ -74,6 +84,9 @@
return self.timer_modulo
def set_timer_modulo(self, data):
+ """
+ When the TIMA overflows, this data will be loaded.
+ """
self.timer_modulo = data
@@ -81,6 +94,14 @@
return 0xF8 | self.timer_control
def set_timer_control(self, data):
+ """
+ Bit 2 - Timer Stop (0=Stop, 1=Start)
+ Bits 1-0 - Input Clock Select
+ 00: 4096 Hz
+ 01: 262144 Hz
+ 10: 65536 Hz
+ 11: 16384 Hz
+ """
if (self.timer_control & 0x03) != (data & 0x03):
self.timer_clock = constants.TIMER_CLOCK[data & 0x03]
self.timer_cycles = constants.TIMER_CLOCK[data & 0x03]
@@ -113,9 +134,18 @@
while self.timer_cycles <= 0:
self.timer_counter = (self.timer_counter + 1) & 0xFF
self.timer_cycles += self.timer_clock
- if self.timer_counter == 0x00:
- self.timer_counter = self.timer_modulo
- self.interrupt.raise_interrupt(constants.TIMER)
+ self.timer_interrupt_check()
+
+ def timer_interrupt_check(self):
+ """
+ Each time when the timer overflows (ie. when TIMA gets bigger than FFh),
+ then an interrupt is requested by setting Bit 2 in the IF Register
+ (FF0F). When that interrupt is enabled, then the CPU will execute it by
+ calling the timer interrupt vector at 0050h.
+ """
+ if self.timer_counter == 0x00:
+ self.timer_counter = self.timer_modulo
+ self.interrupt.raise_interrupt(constants.TIMER)
#def emulate_timer(self, ticks):
# if (self.timer_control & 0x04) == 0:
Modified: pypy/dist/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/video.py (original)
+++ pypy/dist/pypy/lang/gameboy/video.py Fri Aug 29 12:54:35 2008
@@ -142,6 +142,56 @@
# -----------------------------------------------------------------------------
+class Sprite(object):
+
+ def __init__(self):
+ self.big_size = False
+ self.reset()
+
+ def reset(self):
+ self.x = 0
+ self.y = 0
+ self._tile_number = 0
+ self.object_behind_background = False
+ self.x_flipped = False
+ self.y_flipped = False
+ self.use_object_pallette_1 = False
+
+ def get_tile_number(self):
+ return self._tile_number
+
+ def set_tile_number(self, patter_number):
+ self._tile_number = patter_number & 0xFF
+
+ def get_width(self):
+ return 8
+
+ def get_height(self):
+ if self.big_size:
+ return 16
+ else:
+ return 8
+
+ def overlaps(self, sprite):
+ return False
+
+# -----------------------------------------------------------------------------
+
+
+class Tile(object):
+
+ def __init__(self):
+ pass
+
+
+ def set_tile_data(self, rom, height):
+ self.height = height
+
+ def get_tile_dta(self):
+ pass
+
+# -----------------------------------------------------------------------------
+
class Video(iMemory):
def __init__(self, video_driver, interrupt, memory):
More information about the Pypy-commit
mailing list