[pypy-svn] r58456 - in pypy/dist/pypy/lang/gameboy: . test
cami at codespeak.net
cami at codespeak.net
Sun Sep 28 01:12:29 CEST 2008
Author: cami
Date: Sun Sep 28 01:12:27 2008
New Revision: 58456
Added:
pypy/dist/pypy/lang/gameboy/test/test_video_mode.py
Modified:
pypy/dist/pypy/lang/gameboy/test/test_video_registers.py
pypy/dist/pypy/lang/gameboy/video_mode.py
pypy/dist/pypy/lang/gameboy/video_register.py
Log:
added test for video mode
extended video register tests
Added: pypy/dist/pypy/lang/gameboy/test/test_video_mode.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/gameboy/test/test_video_mode.py Sun Sep 28 01:12:27 2008
@@ -0,0 +1,22 @@
+from pypy.lang.gameboy import constants
+from pypy.lang.gameboy.video_sprite import Sprite
+from pypy.lang.gameboy.video import Video
+from pypy.lang.gameboy.test.test_video import get_video
+import py
+
+# ------------------------------------------------------------------------------
+
+def get_mode0():
+ return Mode0(get_video())
+
+def get_mode1():
+ return Mode1(get_video())
+
+def get_mode2():
+ return Mode2(get_video())
+
+def get_mode3():
+ return Mode3(get_video())
+
+
+# ------------------------------------------------------------------------------
\ No newline at end of file
Modified: pypy/dist/pypy/lang/gameboy/test/test_video_registers.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/test/test_video_registers.py (original)
+++ pypy/dist/pypy/lang/gameboy/test/test_video_registers.py Sun Sep 28 01:12:27 2008
@@ -22,17 +22,24 @@
control.write(0xFF)
assert control.read() == 0xFF
control.reset()
- assert control.read() == 0x91
+ assert control.read() == 0x91
def test_video_control_read_write_properties():
control = get_control_register()
-
for i in range(0xFF):
control.write(i)
assert control.read() == i
-
+def test_video_control_get_selected_tile_data_space():
+ control = get_control_register()
+
+ control.window.upper_tile_map_selected = True
+ assert control.get_selected_tile_data_space() == constants.VRAM_DATA_A
+
+ control.window.upper_tile_map_selected = False
+ assert control.get_selected_tile_data_space() == constants.VRAM_DATA_B
+
# StatusRegister ---------------------------------------------------------------
def test_video_status_reset():
@@ -52,9 +59,61 @@
def test_video_status_mode():
status = get_status_register()
assert status.get_mode() == 2
-
for i in range(3):
status.set_mode(i)
assert status.get_mode() == i
+
status.set_mode(4)
assert status.get_mode() == 0
+
+def test_video_status_mode_properties():
+ status = get_status_register()
+ status.write(0x00, write_all=True)
+
+ assert status.read(extend=True) == 0x00
+
+ status.mode0.h_blank_interrupt = True
+ assert status.read(extend=True) == (1 << 3)
+ status.mode0.h_blank_interrupt = False
+
+ status.mode1.v_blank_interrupt = True
+ assert status.read(extend=True) == (1 << 4)
+ status.mode1.v_blank_interrupt = False
+
+ status.mode2.oam_interrupt = True
+ assert status.read(extend=True) == (1 << 5)
+ status.mode2.oam_interrupt = False
+
+def test_video_status_get_mode():
+ status = get_status_register()
+ status.current_mode = status.mode0
+ assert status.get_mode() == 0
+
+ for i in range(0,4):
+ status.current_mode = status.modes[i]
+ assert status.get_mode() == status.modes[i].id()
+
+def test_video_status_set_mode():
+ status = get_status_register()
+ for i in range(0,4):
+ status.set_mode(i)
+ assert status.current_mode == status.modes[i]
+
+def test_video_status_line_y_compare_check():
+ status = get_status_register()
+
+ status.line_y_compare_flag = False
+ status.line_y_compare_interrupt = False
+ assert status.line_y_compare_check()
+
+ status.line_y_compare_flag = True
+ status.line_y_compare_interrupt = False
+ assert status.line_y_compare_check()
+
+ status.line_y_compare_flag = False
+ status.line_y_compare_interrupt = True
+ assert status.line_y_compare_check()
+
+ status.line_y_compare_flag = True
+ status.line_y_compare_interrupt = True
+ assert not status.line_y_compare_check()
\ No newline at end of file
Modified: pypy/dist/pypy/lang/gameboy/video_mode.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/video_mode.py (original)
+++ pypy/dist/pypy/lang/gameboy/video_mode.py Sun Sep 28 01:12:27 2008
@@ -48,6 +48,8 @@
if self.video.status.line_y_compare_interrupt:
self.video.lcd_interrupt_flag.set_pending()
+# -----------------------------------------------------------------------------
+
class Mode0(Mode):
"""
Mode 0: The LCD controller is in the H-Blank period and
@@ -61,14 +63,9 @@
def id(self):
return 0
- def activate(self, previous_mode):
- #if previous_mode.id() == 3:
- self.video.cycles += constants.MODE_0_TICKS
- self.h_blank_interrupt_check()
- #else:
- # video.reset_control() can be called in any position
- # pass
- #raise InvalidModeOrderException(self, previous_mode)
+ def activate(self):
+ self.video.cycles += constants.MODE_0_TICKS
+ self.h_blank_interrupt_check()
def h_blank_interrupt_check(self):
if self.h_blank_interrupt and \
@@ -98,7 +95,9 @@
self.video.display = False
self.video.status.set_mode(1)
self.video.v_blank = True
-
+
+# -----------------------------------------------------------------------------
+
class Mode1(Mode):
"""
Mode 1: The LCD contoller is in the V-Blank period (or the
@@ -112,12 +111,8 @@
def id(self):
return 1
- def activate(self, previous_mode):
- #if previous_mode.id() == 0:
- self.set_begin()
- #else:
- # pass
- #raise InvalidModeOrderException(self, previous_mode)
+ def activate(self):
+ self.set_begin()
def set_begin(self):
self.video.cycles += constants.MODE_1_BEGIN_TICKS
@@ -164,7 +159,9 @@
self.video.cycles += constants.MODE_1_TICKS
else:
self.set_end()
-
+
+# -----------------------------------------------------------------------------
+
class Mode2(Mode):
"""
Mode 2: The LCD controller is reading from OAM memory.
@@ -178,13 +175,9 @@
def id(self):
return 2
- def activate(self, previous_mode):
- #if previous_mode.id() == 0 or previous_mode.id() == 1:
- self.video.cycles += constants.MODE_2_TICKS
- self.oam_interrupt_check()
- #else:
- # pass
- #raise InvalidModeOrderException(self, previous_mode)
+ def activate(self):
+ self.video.cycles += constants.MODE_2_TICKS
+ self.oam_interrupt_check()
def oam_interrupt_check(self):
if self.oam_interrupt and \
@@ -197,6 +190,8 @@
def emulate_oam(self):
self.video.status.set_mode(3)
+# -----------------------------------------------------------------------------
+
class Mode3(Mode):
"""
Mode 3: The LCD controller is reading from both OAM and VRAM,
@@ -210,12 +205,8 @@
def id(self):
return 3
- def activate(self, previous_mode):
- #if previous_mode.id() == 2:
- self.set_begin()
- #else:
- # pass
- # #raise InvalidModeOrderException(self, previous_mode)
+ def activate(self):
+ self.set_begin()
def set_begin(self):
self.video.cycles += constants.MODE_3_BEGIN_TICKS
Modified: pypy/dist/pypy/lang/gameboy/video_register.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/video_register.py (original)
+++ pypy/dist/pypy/lang/gameboy/video_register.py Sun Sep 28 01:12:27 2008
@@ -1,7 +1,9 @@
from pypy.lang.gameboy import constants
from pypy.lang.gameboy.video_mode import Mode0, Mode1, Mode2, Mode3
+
# -----------------------------------------------------------------------------
+
class StatusRegister(object):
"""
Bit 6 - LYC=LY Coincidence Interrupt (1=Enable) (Read/Write)
@@ -26,8 +28,6 @@
self.mode3 = Mode3(video)
self.modes = [self.mode0, self.mode1, self.mode2, self.mode3]
-
-
def reset(self):
self.current_mode = self.mode2
self.line_y_compare_flag = False
@@ -39,7 +39,6 @@
#self.mode_2_oam_interrupt = False
self.status = True
-
def read(self, extend=False):
value = self.get_mode()
value += self.line_y_compare_flag << 2
@@ -51,9 +50,7 @@
value += int(self.status) << 7
return value
-
- def write(self, value, write_all=False,
- keep_mode_0_h_blank_interrupt=False):
+ def write(self, value, write_all=False):
if write_all:
self.current_mode = self.modes[value & 0x03]
self.line_y_compare_flag = bool(value & (1 << 2))
@@ -67,12 +64,11 @@
return self.current_mode.id()
def set_mode(self, mode):
- old_mode = self.current_mode
self.current_mode = self.modes[mode & 0x03]
- self.current_mode.activate(old_mode)
+ self.current_mode.activate()
def line_y_compare_check(self):
- return not self.line_y_compare_flag or not self.line_y_compare_interrupt
+ return not (self.line_y_compare_flag and self.line_y_compare_interrupt)
# -----------------------------------------------------------------------------
More information about the Pypy-commit
mailing list