[pypy-svn] r57989 - in pypy/dist/pypy/lang/gameboy: . profiling test
cami at codespeak.net
cami at codespeak.net
Mon Sep 8 21:30:51 CEST 2008
Author: cami
Date: Mon Sep 8 21:30:47 2008
New Revision: 57989
Modified:
pypy/dist/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py
pypy/dist/pypy/lang/gameboy/test/test_video.py
pypy/dist/pypy/lang/gameboy/video.py
Log:
refactored video, introduced separated mode objects
adapted tests according to the refactoring
Modified: pypy/dist/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py (original)
+++ pypy/dist/pypy/lang/gameboy/profiling/gameboy_profiling_implementation.py Mon Sep 8 21:30:47 2008
@@ -1,11 +1,13 @@
#!/usr/bin/env python
from __future__ import generators
+from pypy.lang.gameboy.ram import iMemory
from pypy.lang.gameboy.gameboy_implementation import *
from pypy.lang.gameboy.profiling.profiling_cpu import ProfilingCPU
from pypy.lang.gameboy.debug import debug
from pypy.lang.gameboy.debug.debug_socket_memory import *
+
# GAMEBOY ----------------------------------------------------------------------
class GameBoyProfilingImplementation(GameBoyImplementation):
@@ -21,9 +23,10 @@
self.is_running = False
debug.print_results()
-
+
# CUSTOM DRIVER IMPLEMENTATIONS currently not used =============================
+
# VIDEO DRIVER -----------------------------------------------------------------
class VideoDriverDebugImplementation(VideoDriverImplementation):
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 8 21:30:47 2008
@@ -227,7 +227,7 @@
video.transfer = False
video.status.write(0xFE, write_all=True)
video.cycles = 0
- video.emulate_oam()
+ video.status.mode2.emulate_oam()
assert video.status.read(extend=True) == 0xFF
assert video.cycles == constants.MODE_3_BEGIN_TICKS
assert video.transfer == True
@@ -238,7 +238,7 @@
video.transfer = False
video.cycles = 0
video.status.write(0xF0, write_all=True)
- video.emulate_transfer()
+ video.status.mode3.emulate_transfer()
assert video.status.read(extend=True) == 0xF0
assert video.cycles == constants.MODE_0_TICKS
assert not video.lcd_interrupt_flag.is_pending()
@@ -247,7 +247,7 @@
video.cycles = 0
video.status.write(0xF8, write_all=True)
assert not video.lcd_interrupt_flag.is_pending()
- video.emulate_transfer()
+ video.status.mode3.emulate_transfer()
assert video.status.read(extend=True) == 0xF8
assert video.cycles == constants.MODE_0_TICKS
assert video.lcd_interrupt_flag.is_pending()
@@ -255,7 +255,7 @@
video.transfer = True
video.cycles = 0
video.status.write(0xFC, write_all=True)
- video.emulate_transfer()
+ video.status.mode3.emulate_transfer()
assert video.cycles == constants.MODE_3_END_TICKS
assert video.transfer == False
assert video.status.read(extend=True) == 0xFF
@@ -267,7 +267,7 @@
video.line_y_compare = 0x13
video.status.line_y_compare_flag = True
video.status.line_y_compare_interrupt = False
- video.emulate_hblank_line_y_compare()
+ video.status.mode0.emulate_hblank_line_y_compare()
assert not video.status.line_y_compare_flag
assert not video.lcd_interrupt_flag.is_pending()
@@ -276,7 +276,7 @@
video.line_y_compare = 0x12
video.status.line_y_compare_flag = False
video.status.line_y_compare_interrupt = False
- video.emulate_hblank_line_y_compare()
+ video.status.mode0.emulate_hblank_line_y_compare()
assert video.status.line_y_compare_flag
assert not video.lcd_interrupt_flag.is_pending()
@@ -285,7 +285,7 @@
video.line_y_compare = 0x12
video.status.line_y_compare_flag = False
video.status.line_y_compare_interrupt = True
- video.emulate_hblank_line_y_compare()
+ video.status.mode0.emulate_hblank_line_y_compare()
assert video.status.line_y_compare_flag
assert video.lcd_interrupt_flag.is_pending()
@@ -295,7 +295,7 @@
video.line_y_compare = 0x12
video.status.line_y_compare_flag = True
video.status.line_y_compare_interrupt = True
- video.emulate_hblank_line_y_compare(stat_check=True)
+ video.status.mode0.emulate_hblank_line_y_compare(stat_check=True)
assert video.status.line_y_compare_flag
assert not video.lcd_interrupt_flag.is_pending()
@@ -304,7 +304,7 @@
video.line_y_compare = 0x12
video.status.line_y_compare_flag = False
video.status.line_y_compare_interrupt = True
- video.emulate_hblank_line_y_compare(stat_check=True)
+ video.status.mode0.emulate_hblank_line_y_compare(stat_check=True)
assert video.status.line_y_compare_flag
assert video.lcd_interrupt_flag.is_pending()
@@ -316,7 +316,7 @@
video.cycles = 0
video.frames = 0
assert not video.lcd_interrupt_flag.is_pending()
- video.emulate_hblank()
+ video.status.mode0.emulate_hblank()
assert video.cycles == constants.MODE_2_TICKS
assert video.lcd_interrupt_flag.is_pending()
assert video.status.get_mode() == 2
@@ -332,7 +332,7 @@
video.status.write(0x0F, write_all=True)
video.cycles = 0
video.frames = 0
- video.emulate_hblank()
+ video.status.mode0.emulate_hblank()
assert video.line_y == 2
assert video.cycles == constants.MODE_2_TICKS
assert not video.lcd_interrupt_flag.is_pending()
@@ -349,7 +349,7 @@
video.frame_skip = 20
video.v_blank = False
video.display = False
- video.emulate_hblank()
+ video.status.mode0.emulate_hblank()
assert video.line_y == 145
assert video.cycles == constants.MODE_1_BEGIN_TICKS
assert not video.lcd_interrupt_flag.is_pending()
@@ -369,7 +369,7 @@
video.frame_skip = 10
video.v_blank = False
video.display = False
- video.emulate_hblank()
+ video.status.mode0.emulate_hblank()
assert video.line_y == 145
assert video.cycles == constants.MODE_1_BEGIN_TICKS
assert not video.lcd_interrupt_flag.is_pending()
@@ -385,7 +385,7 @@
video.status.write(0xFE, write_all=True)
video.v_blank = True
video.cycles = 0
- video.emulate_v_blank()
+ video.status.mode1.emulate_v_blank()
assert video.v_blank == False
assert video.status.get_mode() == 1
assert video.status.read(extend=True) == 0xFD
@@ -399,7 +399,7 @@
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()
+ video.status.mode1.emulate_v_blank()
assert video.status.read(extend=True) == 0x01
assert video.v_blank_interrupt_flag.is_pending()
assert not video.lcd_interrupt_flag.is_pending()
@@ -414,7 +414,7 @@
video.v_blank = False
video.cycles = 0
video.line_y = 0
- video.emulate_v_blank()
+ video.status.mode1.emulate_v_blank()
assert video.v_blank == False
assert video.status.read(extend=True) == 0x2E
assert video.cycles == constants.MODE_2_TICKS
@@ -425,7 +425,7 @@
video.v_blank_interrupt_flag.set_pending(False)
video.cycles = 0
video.status.write(0xFD, write_all=True)
- video.emulate_v_blank()
+ video.status.mode1.emulate_v_blank()
assert video.v_blank == False
assert video.status.read(extend=True) == 0xFE
assert video.cycles == constants.MODE_2_TICKS
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 8 21:30:47 2008
@@ -85,32 +85,109 @@
class Mode(object):
def id(self):
raise Exception()
+
def __init__(self, video):
self.video = video
+ def emulate_hblank_line_y_compare(self, stat_check=False):
+ if self.video.line_y == self.video.line_y_compare:
+ if not (stat_check and self.video.status.line_y_compare_flag):
+ self.video.line_y_line_y_compare_interrupt_check()
+ else:
+ self.video.status.line_y_compare_flag = False
+
class Mode0(Mode):
def id(self):
return 0
+
def emulate(self):
- self.video.emulate_hblank()
-
+ #self.video.emulate_hblank()
+ self.emulate_hblank()
+
+ def emulate_hblank(self):
+ self.video.line_y += 1
+ self.emulate_hblank_line_y_compare()
+ if self.video.line_y < 144:
+ self.video.set_mode_2()
+ else:
+ self.emulate_hblank_part_2()
+
+ def emulate_hblank_part_2(self):
+ if self.video.display:
+ self.video.draw_frame()
+ self.video.frames += 1
+ if self.video.frames >= self.video.frame_skip:
+ self.video.display = True
+ self.video.frames = 0
+ else:
+ self.video.display = False
+ self.video.set_mode_1_begin()
+ self.video.v_blank = True
+
+
class Mode1(Mode):
def id(self):
return 1
+
def emulate(self):
- self.video.emulate_v_blank()
-
+ self.emulate_v_blank()
+
+ def emulate_v_blank(self):
+ if self.video.v_blank:
+ self.emulate_v_blank_v_blank()
+ elif self.video.line_y == 0:
+ self.video.set_mode_2()
+ else:
+ self.emulate_v_blank_other()
+
+ def emulate_v_blank_v_blank(self):
+ self.video.v_blank = False
+ self.video.set_mode_1_between()
+ self.video.v_blank_interrupt_check()
+
+ def emulate_v_blank_other(self):
+ if self.video.line_y < 153:
+ self.emulate_v_blank_mode_1()
+ else:
+ self.video.line_y = 0
+ self.video.window_line_y = 0
+ self.video.set_mode_1_between()
+ self.emulate_hblank_line_y_compare()
+
+ def emulate_v_blank_mode_1(self):
+ self.video.line_y += 1
+ if self.video.line_y == 153:
+ self.video.set_mode_1_end()
+ else:
+ self.video.set_mode_1()
+
class Mode2(Mode):
def id(self):
return 2
+
def emulate(self):
- self.video.emulate_oam()
+ self.emulate_oam()
+
+ def emulate_oam(self):
+ self.video.set_mode_3_begin()
class Mode3(Mode):
+
def id(self):
return 3
+
def emulate(self):
- self.video.emulate_transfer()
+ self.emulate_transfer()
+
+ def emulate_transfer(self):
+ if self.video.transfer:
+ if self.video.display:
+ self.video.draw_line()
+ self.video.set_mode_3_end()
+ else:
+ self.video.set_mode_0()
+
+# -----------------------------------------------------------------------------
class StatusRegister(object):
"""
@@ -126,12 +203,16 @@
3: During Transfering Data to LCD Driver
"""
def __init__(self, video):
- self.modes = [Mode0(video),
- Mode1(video),
- Mode2(video),
- Mode3(video)]
+ self.create_modes(video)
self.reset()
+ def create_modes(self, video):
+ self.mode0 = Mode0(video)
+ self.mode1 = Mode1(video)
+ self.mode2 = Mode2(video)
+ self.mode3 = Mode3(video)
+ self.modes = [self.mode0, self.mode1, self.mode2, self.mode3]
+
def reset(self):
self.set_mode(0x02)
self.line_y_compare_flag = False
@@ -433,7 +514,7 @@
"""
self.line_y_compare = data
if self.control.lcd_enabled:
- self.emulate_hblank_line_y_compare(stat_check=True)
+ self.status.mode0.emulate_hblank_line_y_compare(stat_check=True)
def get_dma(self):
return self.dma
@@ -623,73 +704,8 @@
def current_mode(self):
return self.status.current_mode
-
- def emulate_oam(self):
- self.set_mode_3_begin()
- def emulate_transfer(self):
- if self.transfer:
- if self.display:
- self.draw_line()
- self.set_mode_3_end()
- else:
- self.set_mode_0()
- def emulate_hblank(self):
- self.line_y+=1
- self.emulate_hblank_line_y_compare()
- if self.line_y < 144:
- self.set_mode_2()
- else:
- self.emulate_hblank_part_2()
-
- def emulate_hblank_line_y_compare(self, stat_check=False):
- if self.line_y == self.line_y_compare:
- if not (stat_check and self.status.line_y_compare_flag):
- self.line_y_line_y_compare_interrupt_check()
- else:
- self.status.line_y_compare_flag = False
-
- def emulate_hblank_part_2(self):
- if self.display:
- self.draw_frame()
- self.frames += 1
- if self.frames >= self.frame_skip:
- self.display = True
- self.frames = 0
- else:
- self.display = False
- self.set_mode_1_begin()
- self.v_blank = True
-
- 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_v_blank_other()
-
- def emulate_v_blank_v_blank(self):
- self.v_blank = False
- self.set_mode_1_between()
- self.v_blank_interrupt_check()
-
- def emulate_v_blank_other(self):
- if self.line_y < 153:
- 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_v_blank_mode_1(self):
- self.line_y += 1
- if self.line_y == 153:
- self.set_mode_1_end()
- else:
- self.set_mode_1()
# graphics handling --------------------------------------------------------
More information about the Pypy-commit
mailing list