[pypy-svn] r62253 - in pypy/trunk/pypy/lang/gameboy: . debug
cami at codespeak.net
cami at codespeak.net
Fri Feb 27 21:45:44 CET 2009
Author: cami
Date: Fri Feb 27 21:45:43 2009
New Revision: 62253
Modified:
pypy/trunk/pypy/lang/gameboy/constants.py
pypy/trunk/pypy/lang/gameboy/cpu.py
pypy/trunk/pypy/lang/gameboy/debug/debug_comparator.py
pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_entry_point.py
pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_parts.py
pypy/trunk/pypy/lang/gameboy/video.py
pypy/trunk/pypy/lang/gameboy/video_mode.py
pypy/trunk/pypy/lang/gameboy/video_register.py
pypy/trunk/pypy/lang/gameboy/video_sprite.py
Log:
changing strange comment
some reformatting
Modified: pypy/trunk/pypy/lang/gameboy/constants.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/constants.py (original)
+++ pypy/trunk/pypy/lang/gameboy/constants.py Fri Feb 27 21:45:43 2009
@@ -148,11 +148,9 @@
# LCD Color Palette
#COLOR_MAP =[
# 0x9CB916, 0x8CAA14, 0x306430, 0x103F10
- # 0xE0F8D0, 0x88C070, 0x386850, 0x081820
- # 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000
-# ]
-
-
+# 0xE0F8D0, 0x88C070, 0x386850, 0x081820
+# 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000
+#]
# ___________________________________________________________________________
# JOYPAD
@@ -160,12 +158,10 @@
# Joypad Registers P+
JOYP = 0xFF00
-
# Joypad Poll Speed (64 Hz)
JOYPAD_CLOCK = GAMEBOY_CLOCK >> 6
-
BUTTON_DOWN = 0x08
BUTTON_UP = 0x04
BUTTON_LEFT = 0x02
@@ -176,8 +172,6 @@
BUTTON_B = 0x02
BUTTON_A = 0x01
-
-
# ___________________________________________________________________________
# SERIAL
# ___________________________________________________________________________
@@ -192,9 +186,6 @@
SERIAL_TRANSFER_DATA = 0xFF01
SERIAL_TRANSFER_CONTROL = 0xFF02
-
-
-
# ___________________________________________________________________________
# SOUND
# ___________________________________________________________________________
@@ -233,12 +224,10 @@
BUFFER_LOG_SIZE = 5;
-
# ___________________________________________________________________________
# TIMER
# ___________________________________________________________________________
-
# DIV Timer Speed (16384 Hz)
DIV_CLOCK = GAMEBOY_CLOCK >> 14
Modified: pypy/trunk/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/cpu.py (original)
+++ pypy/trunk/pypy/lang/gameboy/cpu.py Fri Feb 27 21:45:43 2009
@@ -297,7 +297,7 @@
def store_hl_in_pc(self):
# LD PC,HL, 1 cycle
self.load(DoubleRegisterCallWrapper(self.hl),
- DoubleRegisterCallWrapper(self.pc))
+ DoubleRegisterCallWrapper(self.pc))
def fetch_load(self, getCaller, setCaller):
self.load(CPUFetchCaller(self), setCaller)
@@ -732,7 +732,8 @@
self.cycles += 1
self.fetch()
-# ------------------------------------------------------------------------------
+# OP CODE META PROGRAMMING ===================================================
+# Call Wrappers --------------------------------------------------------------
class CallWrapper(object):
def get(self, use_cycles=True):
@@ -790,15 +791,13 @@
# op_code LOOKUP TABLE GENERATION -----------------------------------------------
-GROUPED_REGISTERS = [CPU.get_b, CPU.get_c, CPU.get_d, CPU.get_e,
- CPU.get_h, CPU.get_l, CPU.get_hli, CPU.get_a]
+GROUPED_REGISTERS = [ CPU.get_b, CPU.get_c, CPU.get_d, CPU.get_e,
+ CPU.get_h, CPU.get_l, CPU.get_hli, CPU.get_a ]
def create_group_op_codes(table):
- op_codes =[]
+ op_codes = []
for entry in table:
- op_code = entry[0]
- step = entry[1]
- function = entry[2]
+ op_code, step, function = entry[:3]
if len(entry) == 4:
for registerGetter in GROUPED_REGISTERS:
for n in entry[3]:
@@ -814,7 +813,7 @@
op_code+=step
else:
for registerGetter in GROUPED_REGISTERS:
- op_codes.append((op_code,group_lambda(function, registerGetter)))
+ op_codes.append((op_code, group_lambda(function, registerGetter)))
op_code += step
return op_codes
@@ -838,14 +837,12 @@
def load_group_lambda(store_register, load_register):
return lambda s: CPU.load(s, RegisterCallWrapper(load_register(s)),
- RegisterCallWrapper(store_register(s)))
+ RegisterCallWrapper(store_register(s)))
def create_register_op_codes(table):
op_codes = []
for entry in table:
- op_code = entry[0]
- step = entry[1]
- function = entry[2]
+ op_code, step, function = entry[:3]
for registerOrGetter in entry[3]:
op_codes.append((op_code, register_lambda(function, registerOrGetter)))
op_code += step
@@ -856,8 +853,7 @@
return lambda s: function(s, registerOrGetter(s))
else:
return lambda s: function(s, registerOrGetter)
-
-
+
def initialize_op_code_table(table):
result = [None] * (0xFF+1)
for entry in table:
Modified: pypy/trunk/pypy/lang/gameboy/debug/debug_comparator.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/debug/debug_comparator.py (original)
+++ pypy/trunk/pypy/lang/gameboy/debug/debug_comparator.py Fri Feb 27 21:45:43 2009
@@ -30,7 +30,7 @@
def __init__(self, debug_connection):
self.debug_connection = debug_connection
- self.memory_check_skip = 5
+ self.memory_check_skip = 1
def compare(self, data):
@@ -46,8 +46,6 @@
def print_compare(self, msg, python, java, printall=False):
if java != python:
self.compare_failed = True
- import pdb
- pdb.set_trace()
print "python: !!", msg, "java:", java, "python:", python, "!!"
if printall:
print "python: XX", msg, "java:", java, "python:", python, "!!"
@@ -281,31 +279,32 @@
("oam", self.video.oam, "oam"),
("line", self.video.line, "line"),
("objects", self.video.objects, "objects"),
- #("palette", self.video.palette, "palette")
+ ("palette", self.video.palette, "palette")
]
self.compare_memory_set(cmp, data, label="video");
@printframe("comparing registers")
def compare_registers(self, data):
cmp = [
- ("dirty", self.video.dirty, "dirty"),
- ("display", self.video.display, "display"),
- ("bgp", self.video.background_palette, "bgp"),
- ("dma", self.video.dma, "dma"),
- ("frames", self.video.frames, "frames"),
- ("frameSkip", self.video.frame_skip, "frameSkip"),
- ("lcdc", self.video.control.read(), "lcdc"),
- ("ly", self.video.line_y, "ly"),
- ("obp0", self.video.object_palette_0, "obp0"),
- ("obp1", self.video.object_palette_1, "obp1"),
- ("scx", self.video.background.scroll_x, "scx"),
- ("scy", self.video.background.scroll_y, "scy"),
- ("stat", self.video.status.read(), "stat"),
- ("transfer", self.video.transfer, "transfer"),
- ("vblank", self.video.v_blank, "vblank"),
- ("wly", self.video.window.line_y, "wly"),
- ("wx", self.video.window.x, "wx"),
- ("wy", self.video.window.y, "wy")
+ ("dirty", self.video.dirty, "dirty"),
+ ("display", self.video.display, "display"),
+ ("bgp", self.video.background_palette, "bgp"),
+ ("dma", self.video.dma, "dma"),
+ ("frames", self.video.frames, "frames"),
+ ("frameSkip", self.video.frame_skip, "frameSkip"),
+ ("lcdc", self.video.control.read(), "lcdc"),
+ ("ly", self.video.line_y, "ly"),
+ ("line_y_compare", self.video.line_y_compare, "lyc"),
+ ("obp0", self.video.object_palette_0, "obp0"),
+ ("obp1", self.video.object_palette_1, "obp1"),
+ ("scx", self.video.background.scroll_x, "scx"),
+ ("scy", self.video.background.scroll_y, "scy"),
+ ("stat", self.video.status.read(), "stat"),
+ ("transfer", self.video.transfer, "transfer"),
+ ("vblank", self.video.v_blank, "vblank"),
+ ("wly", self.video.window.line_y, "wly"),
+ ("wx", self.video.window.x, "wx"),
+ ("wy", self.video.window.y, "wy")
]
self.compare_set(cmp, data, label="video")
@@ -326,5 +325,7 @@
self.video.emulated_transfer, "emulated_transfer"),
("Check whether emulated VBLank",
self.video.emulated_vblank, "emulated_vblank"),
+ ("Check whether called draw Backgroundw",
+ self.video.drew_background, "drew_background"),
]
self.compare_set(cmp, data, label="video", printall=True)
Modified: pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_entry_point.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_entry_point.py (original)
+++ pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_entry_point.py Fri Feb 27 21:45:43 2009
@@ -5,20 +5,24 @@
# ------------------------------------------------------------------------------
-if sys.platform == 'darwin':
- from AppKit import NSApplication
- NSApplication.sharedApplication()
+#if sys.platform == 'darwin':
+ #from AppKit import NSApplication
+ #NSApplication.sharedApplication()
# ------------------------------------------------------------------------------
ROM_PATH = str(py.magic.autopath().dirpath().dirpath())+"/rom"
filename = ROM_PATH + "/rom9/rom9.gb"
SOCKET_PORT = 55682
-skip_count = 6150
-in_between_skip = 1000
-#skip_count = 22545
-#skip_count = 2700
-# skip_count = 0
+
+skip_count = 22545
+skip_count = 2700
+skip_count = 0
+
+if len(sys.argv) > 1:
+ skip_count = sys.argv[1]
+ first_skip = sys.argv[2]
+ in_between_skips = sys.argv[3]
# ------------------------------------------------------------------------------
@@ -31,6 +35,7 @@
def ask_for_skip_count():
global skip_count
+ if len(sys.argv) > 1: return
print ">> enter initial skip amount: ",
read = sys.stdin.readline()
try:
@@ -41,6 +46,7 @@
def ask_for_in_between_skip():
global in_between_skip
+ if len(sys.argv) > 1: return
print ">> enter initial in_between_skip amount: ",
read = sys.stdin.readline()
try:
Modified: pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_parts.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_parts.py (original)
+++ pypy/trunk/pypy/lang/gameboy/debug/gameboy_debug_parts.py Fri Feb 27 21:45:43 2009
@@ -34,6 +34,7 @@
self.emulated_vblank = False
self.emulated_oam = False
self.emulated_transfer = False
+ self.drew_background = False
def write(self, address, data):
Video.write(self, address, data)
Modified: pypy/trunk/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video.py (original)
+++ pypy/trunk/pypy/lang/gameboy/video.py Fri Feb 27 21:45:43 2009
@@ -446,8 +446,6 @@
def current_mode(self):
return self.status.current_mode
-
-
# graphics handling --------------------------------------------------------
def draw_frame(self):
@@ -465,17 +463,14 @@
if self.window.enabled:
self.window.draw_line(self.line_y)
if self.control.sprites_enabled:
- #self.draw_sprites_line_new()
self.draw_sprites_line()
self.draw_pixels_line()
def draw_sprites_line_new(self):
# XXX Not in use yet. Will replace the hacky version.
sprites_on_line = self.get_drawable_sprites_on_line(self.line_y)
-
- last_sprite = sprites_on_line[0]
+ last_sprite = sprites_on_line[0]
last_sprite.draw()
-
for sprite in sprites_on_line[1:]:
if sprite.overlaps_on_line(last_sprite, self.line_y):
sprite.draw_overlapped()
@@ -486,7 +481,7 @@
found = []
for i in range(len(self.sprites)):
if self.sprites[i].intersects_line(line_y) and \
- self.sprites[i].enabled:
+ self.sprites[i].enabled:
found.append(self.sprites[i])
return found
@@ -509,6 +504,51 @@
# -----------------------------------------------
+ def draw_sprites_line_new(self):
+ count = self.scan_sprites_new()
+ lastx = 176
+ for index in range(176, count):
+ paint_sprite = self.objects[index]
+ x = (data >> 24) & 0xFF
+ flags = (data >> 12) & 0xFF
+ address = data & 0xFFF
+ if (paint_sprite.x + SPRITE_SIZE <= lastx):
+ self.draw_object_tile_new(paint_sprite)
+ else:
+ self.draw_overlapped_object_tile_new(x, address, flags)
+ lastx = paint_sprite.x
+
+ def scan_sprites_new(self):
+ count = 0
+ # search active objects
+ for offset in range(0, 4*40, 4):
+ sprite = self.get_sprite(offset)
+ if sprite.hide_check(): continue
+ paint_sprite = PaintSprite(count, sprite, self)
+ self.objects[count] = paint_sprite
+ count += 1
+ if count >= constants.OBJECTS_PER_LINE: break
+ self.sort_scan_sprite_new(count)
+ return count
+
+ def sort_scan_sprite_new(self, count):
+ # sort objects from higher to lower priority
+ for index in range(count):
+ rightmost = index
+ for number in range(index+1, count):
+ if (self.objects[number].line_position) > \
+ (self.objects[rightmost].line_position):
+ rightmost = number
+ if rightmost != index:
+ self.swap_object_indices(rightmost, index)
+
+ def swap_object_indices(self, index_a, index_b):
+ data = self.objects[index_a]
+ self.objects[index_a] = self.objects[index_b]
+ self.objects[index_b] = data
+
+ # ---------------------------------------------------------------------
+
def draw_sprites_line(self):
count = self.scan_sprites()
lastx = SPRITE_SIZE + GAMEBOY_SCREEN_WIDTH + SPRITE_SIZE
@@ -522,33 +562,33 @@
else:
self.draw_overlapped_object_tile(x, address, flags)
lastx = x
-
+
def scan_sprites(self):
count = 0
# search active objects
for offset in range(0, 4*40, 4):
- y = self.oam[offset + 0]
- x = self.oam[offset + 1]
- if (y <= 0 or y >= SPRITE_SIZE + GAMEBOY_SCREEN_HEIGHT + SPRITE_SIZE
- or x <= 0 or x >= GAMEBOY_SCREEN_WIDTH + SPRITE_SIZE):
+ y = self.get_oam(offset + 0)
+ x = self.get_oam(offset + 1)
+ if y <= 0 \
+ or y >= (SPRITE_SIZE + GAMEBOY_SCREEN_HEIGHT + SPRITE_SIZE) \
+ or x <= 0 \
+ or x >= GAMEBOY_SCREEN_WIDTH + SPRITE_SIZE:
continue
- tile = self.oam[offset + 2]
- flags = self.oam[offset + 3]
- y = self.line_y - y + 16
+ tile = self.get_oam(offset + 2)
+ flags = self.get_oam(offset + 3)
+ y = self.line_y - y + 2 * SPRITE_SIZE
if self.control.big_sprite_size_selected:
# 8x16 tile size
- if (y < 0 or y > 15):
- continue
+ if y < 0 or y > 15: continue
# Y flip
- if ((flags & 0x40) != 0):
+ if (flags & 0x40) != 0:
y = 15 - y
tile &= 0xFE
else:
# 8x8 tile size
- if (y < 0 or y > 7):
- continue
+ if y < 0 or y > 7: continue
# Y flip
- if ((flags & 0x40) != 0):
+ if (flags & 0x40) != 0:
y = 7 - y
self.objects[count] = (x << 24) + (count << 20) + (flags << 12) + \
(tile << 4) + (y << 1)
Modified: pypy/trunk/pypy/lang/gameboy/video_mode.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_mode.py (original)
+++ pypy/trunk/pypy/lang/gameboy/video_mode.py Fri Feb 27 21:45:43 2009
@@ -194,7 +194,6 @@
"""
Mode 3: The LCD controller is reading from both OAM and VRAM,
The CPU <cannot> access OAM and VRAM during this period.
- CGB Mode: Cannot access Palette Data (FF69,FF6B) either.
"""
def reset(self):
pass
Modified: pypy/trunk/pypy/lang/gameboy/video_register.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_register.py (original)
+++ pypy/trunk/pypy/lang/gameboy/video_register.py Fri Feb 27 21:45:43 2009
@@ -51,14 +51,14 @@
return value
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))
- self.status = bool(value & (1 << 7))
self.mode0.h_blank_interrupt = bool(value & (1 << 3))
self.mode1.v_blank_interrupt = bool(value & (1 << 4))
self.mode2.oam_interrupt = bool(value & (1 << 5))
self.line_y_compare_interrupt = bool(value & (1 << 6))
+ if write_all:
+ self.current_mode = self.modes[value & 0x03]
+ self.line_y_compare_flag = bool(value & (1 << 2))
+ self.status = bool(value & (1 << 7))
def get_mode(self):
return self.current_mode.id()
Modified: pypy/trunk/pypy/lang/gameboy/video_sprite.py
==============================================================================
--- pypy/trunk/pypy/lang/gameboy/video_sprite.py (original)
+++ pypy/trunk/pypy/lang/gameboy/video_sprite.py Fri Feb 27 21:45:43 2009
@@ -104,6 +104,7 @@
self.hidden = True
else:
self.hidden = False
+ return self.hidden
def get_tile_number(self):
return self.tile.id
@@ -128,6 +129,31 @@
def draw_overlapped(self):
pass
+# -----------------------------------------------------------------------------
+
+class PaintSprite(Sprite):
+
+ def __init__(self, line_position, sprite, video):
+ Sprite.__init__(self)
+ self.line_position = line_position
+ self.extract_attributes(sprite, video)
+ self.update_position(sprite)
+
+ def extract_attributes(self, sprite, video):
+ self.x = sprite.x
+ self.y = video.line_y - sprite.y + 2 * SPRITE_SIZE
+ self.tile = sprite.tile
+ self.object_behind_background = sprite.object_behind_background
+ self.x_flipped = sprite.x_flipped
+ self.y_flipped = sprite.y_flipped
+ self.tile_number = sprite.tile_number
+ self.hidden = sprite.hidden
+ self.rest_attributes_and_flags = sprite.rest_attributes_and_flags
+
+ def update_position(sprite):
+ if sprite.y < 0 or sprite.y >= self.get_height(): return
+ if sprite.y_flipped:
+ self.y = self.get_height() - 1 - self.y
# -----------------------------------------------------------------------------
More information about the Pypy-commit
mailing list