[pypy-svn] r57730 - in pypy/dist/pypy/lang/gameboy: . test
tverwaes at codespeak.net
tverwaes at codespeak.net
Mon Sep 1 16:50:16 CEST 2008
Author: tverwaes
Date: Mon Sep 1 16:50:12 2008
New Revision: 57730
Modified:
pypy/dist/pypy/lang/gameboy/cartridge.py
pypy/dist/pypy/lang/gameboy/interrupt.py
pypy/dist/pypy/lang/gameboy/test/test_cpu.py
pypy/dist/pypy/lang/gameboy/test/test_interrupt.py
pypy/dist/pypy/lang/gameboy/test/test_video.py
pypy/dist/pypy/lang/gameboy/video.py
Log:
small refactorings + removed some print statements
Modified: pypy/dist/pypy/lang/gameboy/cartridge.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cartridge.py (original)
+++ pypy/dist/pypy/lang/gameboy/cartridge.py Mon Sep 1 16:50:12 2008
@@ -545,7 +545,7 @@
raise InvalidMemoryAccessException("MBC3.read_clock_data invalid address %i")
def write(self, address, data):
- print hex(address), hex(data)
+ #print hex(address), hex(data)
# 0000-1FFF
if address <= 0x1FFF:
self.write_ram_enable(address, data)
Modified: pypy/dist/pypy/lang/gameboy/interrupt.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/interrupt.py (original)
+++ pypy/dist/pypy/lang/gameboy/interrupt.py Mon Sep 1 16:50:12 2008
@@ -6,8 +6,8 @@
"""
An Interrupt Flag handles a single interrupt channel
"""
- def __init__(self, _reset, mask, call_code):
- self._reset = _reset
+ def __init__(self, reset, mask, call_code):
+ self._reset = reset
self.mask = mask
self.call_code = call_code
self.reset()
@@ -19,8 +19,8 @@
def is_pending(self):
return self._is_pending
- def set_pending(self, _is_pending=True):
- self._is_pending = _is_pending
+ def set_pending(self, is_pending=True):
+ self._is_pending = is_pending
def is_enabled(self):
return self.enabled
@@ -65,14 +65,14 @@
self.reset()
def create_interrupt_flags(self):
- self.vblank = InterruptFlag(True, constants.VBLANK, 0x40)
- self.lcd = InterruptFlag(False, constants.LCD, 0x48)
- self.timer = InterruptFlag(False, constants.TIMER, 0x50)
- self.serial = InterruptFlag(False, constants.SERIAL, 0x58)
- self.joypad = InterruptFlag(False, constants.JOYPAD, 0x60)
+ self.v_blank = InterruptFlag(True, constants.VBLANK, 0x40)
+ self.lcd = InterruptFlag(False, constants.LCD, 0x48)
+ self.timer = InterruptFlag(False, constants.TIMER, 0x50)
+ self.serial = InterruptFlag(False, constants.SERIAL, 0x58)
+ self.joypad = InterruptFlag(False, constants.JOYPAD, 0x60)
def create_flag_list(self):
- self.interrupt_flags = [ self.vblank, self.lcd, self.timer, self.serial,
+ self.interrupt_flags = [ self.v_blank, self.lcd, self.timer, self.serial,
self.joypad]
def create_flag_mask_mapping(self):
@@ -104,7 +104,7 @@
return (self.get_enable_mask() & self.get_interrupt_flag() & mask) != 0
def raise_interrupt(self, mask):
- self.mask_mapping[mask].set_pending(True)
+ self.mask_mapping[mask].set_pending()
def lower(self, mask):
self.mask_mapping[mask].set_pending(False)
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 Mon Sep 1 16:50:12 2008
@@ -1141,7 +1141,7 @@
cpu.halted = True
cpu.cycles = 4
cpu.interrupt.set_enable_mask(0xFF)
- cpu.interrupt.vblank.set_pending()
+ cpu.interrupt.v_blank.set_pending()
assert cpu.interrupt.is_pending() == True
assert cpu.halted == True
cpu.handle_pending_interrupts()
@@ -1156,14 +1156,14 @@
cpu.sp.set(0x02)
sp = cpu.sp.get()
cpu.interrupt.set_enable_mask(0xFF)
- cpu.interrupt.vblank.set_pending()
+ cpu.interrupt.v_blank.set_pending()
cpu.interrupt.lcd.set_pending()
assert cpu.interrupt.is_pending() == True
cpu.cycles = 0
cpu.handle_pending_interrupts()
assert cpu.cycles == 0
assert cpu.halted == False
- assert_default_registers(cpu, pc=cpu.interrupt.vblank.call_code, sp=sp-2)
+ assert_default_registers(cpu, pc=cpu.interrupt.v_blank.call_code, sp=sp-2)
assert cpu.pop() == 0x34
assert cpu.pop() == 0x12
@@ -1245,7 +1245,7 @@
cpu.ime = False
cpu.halted = False
prepare_for_fetch(cpu, 0x00) # nop 1 cycle
- print cpu.interrupt.get_enable_mask()
+ #print cpu.interrupt.get_enable_mask()
assert cpu.interrupt.is_pending() == False
cycle_test(cpu, 0xFB, 1+1)
assert cpu.interrupt.is_pending() == False
@@ -1257,7 +1257,7 @@
cpu.ime = True
cpu.halted = False
prepare_for_fetch(cpu, 0x00) # nop 1 cycle
- cpu.interrupt.vblank.set_pending()
+ cpu.interrupt.v_blank.set_pending()
cpu.interrupt.serial.set_pending()
cpu.interrupt.set_enable_mask(0x1F)
assert cpu.interrupt.is_pending() == True
@@ -1265,14 +1265,14 @@
assert cpu.ime == True
cycle_test(cpu, 0xFB, 1+1)
assert cpu.interrupt.is_pending() == True
- assert cpu.interrupt.vblank.is_pending() == False
+ assert cpu.interrupt.v_blank.is_pending() == False
assert cpu.interrupt.serial.is_pending() == True
- assert cpu.pc.get() == cpu.interrupt.vblank.call_code
+ assert cpu.pc.get() == cpu.interrupt.v_blank.call_code
assert cpu.ime == False
cpu.ime = True
cycle_test(cpu, 0xFB, 1+1)
- assert cpu.interrupt.vblank.is_pending() == False
+ assert cpu.interrupt.v_blank.is_pending() == False
assert cpu.interrupt.serial.is_pending() == False
assert cpu.interrupt.is_pending() == False
@@ -1551,8 +1551,8 @@
if register == cpu.hli:
cycles = 4
cpu.reset()
- if registerOpCode ==0xFF:
- print "6544444444444444"
+ #if registerOpCode ==0xFF:
+ # print "6544444444444444"
register.set(0)
fetch_execute_cycle_test_second_order(cpu, registerOpCode, cycles)
@@ -1580,8 +1580,8 @@
assert (register.get() & (1<<i)) == 0
register.set(0xFF)
fetch_execute_cycle_test_second_order(cpu, registerOpCode, cycles)
- print register.get(), (register.get() & (1<<i)), hex(registerOpCode) ,i
- print
+ #print register.get(), (register.get() & (1<<i)), hex(registerOpCode) ,i
+ #print
assert (register.get() & (1<<i)) == 0
registerOpCode += 0x08
@@ -1711,4 +1711,4 @@
-
\ No newline at end of file
+
Modified: pypy/dist/pypy/lang/gameboy/test/test_interrupt.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_interrupt.py (original)
+++ pypy/dist/pypy/lang/gameboy/test/test_interrupt.py Mon Sep 1 16:50:12 2008
@@ -25,17 +25,17 @@
assert interrupt.get_enable_mask() == 0x00
interrupt.set_enable_mask(0x01)
- assert interrupt.vblank.is_enabled()
+ assert interrupt.v_blank.is_enabled()
assert interrupt.get_enable_mask() == 0x01
# enable all interrupts 0x01 - 0x10
interrupt.set_enable_mask(0xFF)
- assert interrupt.vblank.is_enabled()
+ assert interrupt.v_blank.is_enabled()
assert interrupt.get_enable_mask() == 0xFF
def test_is_pending():
interrupt = get_interrupt()
- interrupt.vblank.set_pending()
+ interrupt.v_blank.set_pending()
assert interrupt.is_pending() == False
assert interrupt.is_pending(0x00) == False
@@ -50,7 +50,7 @@
for flag in interrupt.interrupt_flags:
interrupt.reset()
interrupt.set_enable_mask(0xFF)
- assert interrupt.vblank.is_pending()
+ assert interrupt.v_blank.is_pending()
flag.set_pending(True)
assert interrupt.is_pending(flag.mask)
@@ -59,7 +59,7 @@
masks= [constants.LCD, constants.TIMER,
constants.JOYPAD, constants.SERIAL]
interrupt.set_enable_mask(0xFF)
- interrupt.vblank.set_pending(True)
+ interrupt.v_blank.set_pending(True)
for mask in masks:
interrupt.raise_interrupt(mask)
assert interrupt.mask_mapping[mask].is_pending() == True
Modified: pypy/dist/pypy/lang/gameboy/test/test_video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_video.py (original)
+++ pypy/dist/pypy/lang/gameboy/test/test_video.py Mon Sep 1 16:50:12 2008
@@ -45,7 +45,7 @@
assert video.object_palette_1 == 0xFF
assert video.transfer == True
assert video.display == True
- assert video.vblank == True
+ assert video.v_blank == True
assert video.dirty == True
assert len(video.vram) == constants.VRAM_SIZE
assert len(video.oam) == constants.OAM_SIZE
@@ -98,7 +98,7 @@
video.control.write(0x80)
video.status.write(0x01, write_all=True)
video.write(0xFF41, 0x01)
- assert video.interrupt.lcd.is_pending()
+ assert video.lcd_interrupt_flag.is_pending()
def test_set_line_y_compare():
@@ -113,28 +113,28 @@
assert video.status.read(extend=True) == 0xFF
video.write(0xFF45, value)
assert video.status.read(extend=True) == 0xFB
- assert video.interrupt.lcd.is_pending() == False
+ assert video.lcd_interrupt_flag.is_pending() == False
video.control.write(0x80)
video.line_y = 0xF6
video.status.write(0x04, write_all=True)
video.write(0xFF45, value)
assert video.status.read(extend=True) == 0x04
- assert video.interrupt.lcd.is_pending() == False
+ assert video.lcd_interrupt_flag.is_pending() == False
video.control.write(0x80)
video.line_y = 0xF6
video.status.write(0x00, write_all=True)
video.write(0xFF45, value)
assert video.status.read(extend=True) == 0x04
- assert video.interrupt.lcd.is_pending() == False
+ assert video.lcd_interrupt_flag.is_pending() == False
video.control.write(0x80)
video.line_y = 0xF6
video.status.write(0x40, write_all=True)
video.write(0xFF45, value)
assert video.status.read(extend=True) == 0x44
- assert video.interrupt.lcd.is_pending() == True
+ assert video.lcd_interrupt_flag.is_pending() == True
@@ -241,16 +241,16 @@
video.emulate_transfer()
assert video.status.read(extend=True) == 0xF0
assert video.cycles == constants.MODE_0_TICKS
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
video.transfer = False
video.cycles = 0
video.status.write(0xF8, write_all=True)
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
video.emulate_transfer()
assert video.status.read(extend=True) == 0xF8
assert video.cycles == constants.MODE_0_TICKS
- assert video.interrupt.lcd.is_pending()
+ assert video.lcd_interrupt_flag.is_pending()
video.transfer = True
video.cycles = 0
@@ -269,7 +269,7 @@
video.status.line_y_compare_interrupt = False
video.emulate_hblank_line_y_compare()
assert not video.status.line_y_compare_flag
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
video.reset()
video.line_y = 0x12
@@ -278,7 +278,7 @@
video.status.line_y_compare_interrupt = False
video.emulate_hblank_line_y_compare()
assert video.status.line_y_compare_flag
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
video.reset()
video.line_y = 0x12
@@ -287,7 +287,7 @@
video.status.line_y_compare_interrupt = True
video.emulate_hblank_line_y_compare()
assert video.status.line_y_compare_flag
- assert video.interrupt.lcd.is_pending()
+ assert video.lcd_interrupt_flag.is_pending()
def test_emulate_hblank_line_y_compare_status_check():
video = get_video()
@@ -297,7 +297,7 @@
video.status.line_y_compare_interrupt = True
video.emulate_hblank_line_y_compare(stat_check=True)
assert video.status.line_y_compare_flag
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
video.reset()
video.line_y = 0x12
@@ -306,7 +306,7 @@
video.status.line_y_compare_interrupt = True
video.emulate_hblank_line_y_compare(stat_check=True)
assert video.status.line_y_compare_flag
- assert video.interrupt.lcd.is_pending()
+ assert video.lcd_interrupt_flag.is_pending()
def test_emulate_h_blank_part_1_1():
video = get_video()
@@ -315,10 +315,10 @@
video.status.write(0x20, write_all=True)
video.cycles = 0
video.frames = 0
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
video.emulate_hblank()
assert video.cycles == constants.MODE_2_TICKS
- assert video.interrupt.lcd.is_pending()
+ assert video.lcd_interrupt_flag.is_pending()
assert video.status.get_mode() == 2
assert video.status.read(extend=True) == 0x20 + 0x04 + 0x2
assert video.line_y == 1
@@ -335,7 +335,7 @@
video.emulate_hblank()
assert video.line_y == 2
assert video.cycles == constants.MODE_2_TICKS
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
assert video.status.read(extend=True) == 0x0B&0xFC + 0x2
assert video.frames == 0
@@ -347,16 +347,16 @@
video.cycles = 0
video.frames = 0
video.frame_skip = 20
- video.vblank = False
+ video.v_blank = False
video.display = False
video.emulate_hblank()
assert video.line_y == 145
assert video.cycles == constants.MODE_1_BEGIN_TICKS
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
assert video.status.read(extend=True) == 0xFB & 0xFC + 0x01
assert video.frames == 1
assert video.display == False
- assert video.vblank == True
+ assert video.v_blank == True
def test_emulate_h_blank_part_2_2_frame_skip():
@@ -367,62 +367,66 @@
video.cycles = 0
video.frames = 10
video.frame_skip = 10
- video.vblank = False
+ video.v_blank = False
video.display = False
video.emulate_hblank()
assert video.line_y == 145
assert video.cycles == constants.MODE_1_BEGIN_TICKS
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
assert video.status.read(extend=True) == 0xFB & 0xFC + 0x01
assert video.frames == 0
- assert video.vblank == True
+ assert video.v_blank == True
-def test_emulate_v_vblank_1():
+def test_emulate_v_v_blank_1():
video = get_video()
- video.interrupt.set_interrupt_flag(0)
+ video.lcd_interrupt_flag.set_pending(False)
+ video.v_blank_interrupt_flag.set_pending(False)
video.status.write(0xFE, write_all=True)
- video.vblank = True
+ video.v_blank = True
video.cycles = 0
- video.emulate_vblank()
- assert video.vblank == False
+ video.emulate_v_blank()
+ assert video.v_blank == False
assert video.status.get_mode() == 1
assert video.status.read(extend=True) == 0xFD
assert video.cycles == constants.MODE_1_TICKS - constants.MODE_1_BEGIN_TICKS
- assert video.interrupt.vblank.is_pending()
- assert video.interrupt.lcd.is_pending()
+ assert video.v_blank_interrupt_flag.is_pending()
+ assert video.lcd_interrupt_flag.is_pending()
- video.interrupt.set_interrupt_flag(0)
+ video.lcd_interrupt_flag.set_pending(False)
+ video.v_blank_interrupt_flag.set_pending(False)
video.status.write(0x00, write_all=True)
- video.vblank = True
- assert not video.interrupt.vblank.is_pending()
- assert not video.interrupt.lcd.is_pending()
- video.emulate_vblank()
+ video.v_blank = True
+ assert not video.v_blank_interrupt_flag.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
+ video.emulate_v_blank()
assert video.status.read(extend=True) == 0x01
- assert video.interrupt.vblank.is_pending()
- assert not video.interrupt.lcd.is_pending()
+ assert video.v_blank_interrupt_flag.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
-def test_emulate_v_vblank_2():
+def test_emulate_v_v_blank_2():
video = get_video()
- video.interrupt.set_interrupt_flag(0)
+ video.lcd_interrupt_flag.set_pending(False)
+ video.v_blank_interrupt_flag.set_pending(False)
video.status.write(0x2D, write_all=True)
- video.vblank = False
+ video.v_blank = False
video.cycles = 0
video.line_y = 0
- video.emulate_vblank()
- assert video.vblank == False
+ video.emulate_v_blank()
+ assert video.v_blank == False
assert video.status.read(extend=True) == 0x2E
assert video.cycles == constants.MODE_2_TICKS
- assert not video.interrupt.vblank.is_pending()
- assert video.interrupt.lcd.is_pending()
+ assert not video.v_blank_interrupt_flag.is_pending()
+ assert video.lcd_interrupt_flag.is_pending()
- video.interrupt.set_interrupt_flag(0)
+ video.lcd_interrupt_flag.set_pending(False)
+ video.v_blank_interrupt_flag.set_pending(False)
video.cycles = 0
video.status.write(0xFD, write_all=True)
- video.emulate_vblank()
- assert video.vblank == False
+ video.emulate_v_blank()
+ assert video.v_blank == False
assert video.status.read(extend=True) == 0xFE
assert video.cycles == constants.MODE_2_TICKS
- assert not video.interrupt.lcd.is_pending()
+ assert not video.lcd_interrupt_flag.is_pending()
Modified: pypy/dist/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/video.py (original)
+++ pypy/dist/pypy/lang/gameboy/video.py Mon Sep 1 16:50:12 2008
@@ -120,7 +120,7 @@
return value
- def write(self, value, write_all=False, \
+ def write(self, value, write_all=False,
keep_mode_0_h_blank_interrupt=False):
if write_all:
self._mode = value & 0x03
@@ -168,7 +168,7 @@
def get_height(self):
if self.big_size:
- return 16
+ return 2*8
else:
return 8
@@ -182,25 +182,25 @@
def __init__(self):
pass
-
-
+
def set_tile_data(self, rom, height):
self.height = height
-
- def get_tile_dta(self):
+
+ def get_tile_data(self):
pass
-
+
# -----------------------------------------------------------------------------
class Video(iMemory):
def __init__(self, video_driver, interrupt, memory):
assert isinstance(video_driver, VideoDriver)
- self.driver = video_driver
- self.interrupt = interrupt
- self.control = ControlRegister()
- self.status = StatusRegister()
- self.memory = memory
+ self.driver = video_driver
+ self.v_blank_interrupt_flag = interrupt.v_blank
+ self.lcd_interrupt_flag = interrupt.lcd
+ self.control = ControlRegister()
+ self.status = StatusRegister()
+ self.memory = memory
self.reset()
def get_frame_skip(self):
@@ -230,7 +230,7 @@
self.transfer = True
self.display = True
- self.vblank = True
+ self.v_blank = True
self.dirty = True
self.vram = [0] * constants.VRAM_SIZE
@@ -366,7 +366,7 @@
if self.control.lcd_enabled and \
self.status.get_mode() == 0x01 and \
self.status.line_y_compare_check():
- self.interrupt.raise_interrupt(constants.LCD)
+ self.lcd_interrupt_flag.set_pending()
def get_scroll_x(self):
""" see set_scroll_x """
@@ -522,21 +522,22 @@
def h_blank_interrupt_check(self):
if self.status.mode_0_h_blank_interrupt and \
self.status.line_y_compare_check():
- self.interrupt.raise_interrupt(constants.LCD)
+ self.lcd_interrupt_flag.set_pending()
def oam_interrupt_check(self):
if self.status.mode_2_oam_interrupt and \
self.status.line_y_compare_check():
- self.interrupt.raise_interrupt(constants.LCD)
+ self.lcd_interrupt_flag.set_pending()
def v_blank_interrupt_check(self):
if self.status.mode_1_v_blank_interrupt:
- self.interrupt.raise_interrupt(constants.LCD)
+ self.lcd_interrupt_flag.set_pending()
+ self.v_blank_interrupt_flag.set_pending()
def line_y_line_y_compare_interrupt_check(self):
self.status.line_y_compare_flag = True
if self.status.line_y_compare_interrupt:
- self.interrupt.raise_interrupt(constants.LCD)
+ self.lcd_interrupt_flag.set_pending()
# mode setting -----------------------------------------------------------
"""
@@ -607,7 +608,7 @@
if mode == 0:
self.emulate_hblank()
elif mode == 1:
- self.emulate_vblank()
+ self.emulate_v_blank()
elif mode == 2:
self.emulate_oam()
else:
@@ -649,32 +650,31 @@
else:
self.display = False
self.set_mode_1_begin()
- self.vblank = True
+ self.v_blank = True
- def emulate_vblank(self):
- if self.vblank:
- self.emulate_vblank_vblank()
+ def emulate_v_blank(self):
+ if self.v_blank:
+ self.emulate_v_blank_v_blank()
elif self.line_y == 0:
self.set_mode_2()
else:
- self.emulate_vblank_other()
+ self.emulate_v_blank_other()
- def emulate_vblank_vblank(self):
- self.vblank = False
+ def emulate_v_blank_v_blank(self):
+ self.v_blank = False
self.set_mode_1_between()
self.v_blank_interrupt_check()
- self.interrupt.raise_interrupt(constants.VBLANK)
- def emulate_vblank_other(self):
+ def emulate_v_blank_other(self):
if self.line_y < 153:
- self.emulate_vblank_mode_1()
+ self.emulate_v_blank_mode_1()
else:
self.line_y = 0
self.window_line_y = 0
self.set_mode_1_between()
self.emulate_hblank_line_y_compare()
- def emulate_vblank_mode_1(self):
+ def emulate_v_blank_mode_1(self):
self.line_y += 1
if self.line_y == 153:
self.set_mode_1_end()
More information about the Pypy-commit
mailing list