[pypy-svn] r58395 - in pypy/dist/pypy/lang/gameboy: . test
cami at codespeak.net
cami at codespeak.net
Tue Sep 23 22:26:24 CEST 2008
Author: cami
Date: Tue Sep 23 22:26:22 2008
New Revision: 58395
Modified:
pypy/dist/pypy/lang/gameboy/cpu.py
pypy/dist/pypy/lang/gameboy/test/test_cpu_2.py
pypy/dist/pypy/lang/gameboy/video.py
Log:
small changes
Modified: pypy/dist/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cpu.py (original)
+++ pypy/dist/pypy/lang/gameboy/cpu.py Tue Sep 23 22:26:22 2008
@@ -6,12 +6,13 @@
# ---------------------------------------------------------------------------
-def process_2_complement(value):
+def process_2s_complement(value):
# check if the left most bit is set
- if (value >> 7) == 1:
- return -((~value) & 0xFF) - 1
- else :
- return value
+ #if (value >> 7) == 1:
+ # return -((~value) & 0xFF) - 1
+ #else :
+ # return value
+ return (value ^ 0x80) - 128
# ---------------------------------------------------------------------------
class AbstractRegister(object):
@@ -829,7 +830,7 @@
def get_fetchadded_sp(self):
# 1 cycle
- offset = process_2_complement(self.fetch()) # 1 cycle
+ offset = process_2s_complement(self.fetch()) # 1 cycle
s = (self.sp.get() + offset) & 0xFFFF
self.flag.reset()
if (offset >= 0):
@@ -869,7 +870,7 @@
def relative_jump(self):
# JR +nn, 3 cycles
- self.pc.add(process_2_complement(self.fetch())) # 3 + 1 cycles
+ self.pc.add(process_2s_complement(self.fetch())) # 3 + 1 cycles
self.cycles += 1
def relative_conditional_jump(self, cc):
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 Tue Sep 23 22:26:22 2008
@@ -662,15 +662,15 @@
assert cpu.flag.get() == 0xFF
assert cpu.pc.get() == 0x1234+2
-def test_process_2_complement():
- assert process_2_complement(0x00) == 0
- assert process_2_complement(0xFF) == -1
+def test_process_2s_complement():
+ assert process_2s_complement(0x00) == 0
+ assert process_2s_complement(0xFF) == -1
for i in range(0x7E):
- assert process_2_complement(i) == i
+ assert process_2s_complement(i) == i
for i in range(1, 0x7E):
- assert process_2_complement(0xFF - i+1) == -i
+ assert process_2s_complement(0xFF - i+1) == -i
def test_relative_jump():
cpu = get_cpu()
Modified: pypy/dist/pypy/lang/gameboy/video.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/video.py (original)
+++ pypy/dist/pypy/lang/gameboy/video.py Tue Sep 23 22:26:22 2008
@@ -3,9 +3,10 @@
constants.LCD Video Display Processor
"""
import math
+import operator
from pypy.lang.gameboy import constants
from pypy.lang.gameboy.ram import iMemory
-from pypy.lang.gameboy.cpu import process_2_complement
+from pypy.lang.gameboy.cpu import process_2s_complement
# -----------------------------------------------------------------------------
class VideoCallWraper(object):
@@ -486,9 +487,6 @@
def get_tile_number(self):
return self.tile.id
- def set_tile_number(self, tile_number):
- self.tile = self.video.tiles[tile_number]
-
def get_width(self):
return 8
@@ -521,6 +519,9 @@
def set_tile_data(self, data):
pass
+ def get_pixel_data(self):
+ return self.pixel_data
+
def get_selected_tile_map_space(self):
pass
# -----------------------------------------------------------------------------
@@ -963,7 +964,8 @@
"""
sets one byte of the object attribute memory.
The object attribute memory stores the position and seme other
- attributes of the sprites
+ attributes of the sprites, this works only during the v-blank and
+ the h-blank period.
"""
self.oam[address - constants.OAM_ADDR] = data & 0xFF
#self.update_sprites(address)
@@ -975,7 +977,7 @@
def set_vram(self, address, data):
"""
sets one byte of the video memory.
- The video memroy contains the tiles used to display.
+ The video memory contains the tiles used to display.
"""
self.vram[address - constants.VRAM_ADDR] = data & 0xFF
self.update_tile(address, data)
@@ -1017,7 +1019,7 @@
self.draw_pixels_line()
def draw_sprites_line_new(self):
- sprites_on_line = self.get_active_sprites_on_line(self.line_y)
+ sprites_on_line = self.get_drawable_sprites_on_line(self.line_y)
last_sprite = sprites_on_line[0]
last_sprite.draw()
@@ -1036,6 +1038,21 @@
found.append(self.sprites[i])
return found
+ def get_drawable_sprites_on_line(self, line_y):
+ sprites_on_line = self.get_active_sprites_on_line(self.line_y)
+ sprites_on_line = self.sort_drawable_sprites(sprites_on_line)
+ # only 10 sprites per line
+ return sprites_on_line[:constants.OBJECTS_PER_LINE]
+
+ def sort_drawable_sprites(self, sprites):
+ """
+ returns an ordered list of selected sprites.
+ The order rules are as following:
+ 1. order by x -coordinates, lower first
+ 2. order by id, lower first
+ """
+ return sprites.sort(key=operator.itemgetter("x"))
+
def draw_sprites_line(self):
count = self.scan_sprites()
lastx = 176
More information about the Pypy-commit
mailing list