[pypy-svn] r55020 - pypy/dist/pypy/lang/gameboy
cami at codespeak.net
cami at codespeak.net
Tue May 20 17:45:28 CEST 2008
Author: cami
Date: Tue May 20 17:45:25 2008
New Revision: 55020
Modified:
pypy/dist/pypy/lang/gameboy/cartridge.py
pypy/dist/pypy/lang/gameboy/cpu.py
pypy/dist/pypy/lang/gameboy/gameboyImplementation.py
Log:
some bugfixes
made gameboyImplementation workable
gameboyImplementation with keyboard feedback working
Modified: pypy/dist/pypy/lang/gameboy/cartridge.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cartridge.py (original)
+++ pypy/dist/pypy/lang/gameboy/cartridge.py Tue May 20 17:45:25 2008
@@ -194,14 +194,12 @@
def create_battery_file_path(self, cartridge_file_path):
if cartridge_file_path.endswith(constants.CARTRIDGE_FILE_EXTENSION):
- return cartridge_file_path.replace(
- constants.CARTRIDGE_FILE_EXTENSION,
- constants.BATTERY_FILE_EXTENSION)
+ return cartridge_file_path[-len(constants.CARTRIDGE_FILE_EXTENSION)] \
+ +constants.BATTERY_FILE_EXTENSION
elif cartridge_file_path.endswith(
constants.CARTRIDGE_COLOR_FILE_EXTENSION):
- return cartridge_file_path.replace(
- constants.CARTRIDGE_COLOR_FILE_EXTENSION,
- constants.BATTERY_FILE_EXTENSION)
+ return cartridge_file_path[-len(constants.CARTRIDGE_COLOR_FILE_EXTENSION)] \
+ +constants.BATTERY_FILE_EXTENSION
else:
return cartridge_file_path + constants.BATTERY_FILE_EXTENSION
Modified: pypy/dist/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/cpu.py (original)
+++ pypy/dist/pypy/lang/gameboy/cpu.py Tue May 20 17:45:25 2008
@@ -198,7 +198,7 @@
self.halted = False
self.cycles = 0
self.ini_registers()
- self.rom = []
+ self.rom = [0]
self.reset()
def ini_registers(self):
Modified: pypy/dist/pypy/lang/gameboy/gameboyImplementation.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/gameboyImplementation.py (original)
+++ pypy/dist/pypy/lang/gameboy/gameboyImplementation.py Tue May 20 17:45:25 2008
@@ -5,7 +5,10 @@
from pypy.lang.gameboy.joypad import JoypadDriver
from pypy.lang.gameboy.video import VideoDriver
from pypy.lang.gameboy.sound import SoundDriver
+from pypy.lang.gameboy.timer import Clock
from pypy.rlib.rsdl import RSDL, RSDL_helper
+from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rlib.objectmodel import specialize
# GAMEBOY ----------------------------------------------------------------------
@@ -15,33 +18,46 @@
def __init__(self):
GameBoy.__init__(self)
self.init_sdl()
- #self.mainLoop()
+ self.mainLoop()
def init_sdl(self):
assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
self.event = lltype.malloc(RSDL.Event, flavor='raw')
- def create_window(self):
- self.win = None
- #self.win = window.Window()
- #self.win.set_caption("PyBoy a GameBoy (TM)")
- pass
-
def create_drivers(self):
self.clock = Clock()
self.joypad_driver = JoypadDriverImplementation()
self.video_driver = VideoDriverImplementation()
self.sound_driver = SoundDriverImplementation()
-
+
+
def mainLoop(self):
try:
- while not self.win.has_exit:
- self.joypad_driver.update( self.event)
- self.emulate(5)
- time.sleep(0.01)
+ while True:
+ if self.poll_event():
+ if self.check_for_escape():
+ break
+ self.joypad_driver.update(self.event)
+ #self.emulate(5)
+ #time.sleep(0.01)
finally:
- lltype.free(event, flavor='raw')
+ lltype.free(self.event, flavor='raw')
+ RSDL.Quit()
return 0
+
+
+ def poll_event(self):
+ ok = rffi.cast(lltype.Signed, RSDL.PollEvent(self.event))
+ return ok > 0
+
+ def check_for_escape(self):
+ c_type = rffi.getintfield(self.event, 'c_type')
+ if c_type == RSDL.KEYDOWN:
+ p = rffi.cast(RSDL.KeyboardEventPtr, self.event)
+ if rffi.getintfield(p.c_keysym, 'c_sym') == RSDL.K_ESCAPE:
+ return True
+ return False
+
# VIDEO DRIVER -----------------------------------------------------------------
@@ -49,21 +65,23 @@
def __init__(self):
VideoDriver.__init__(self)
+ self.create_screen()
self.map = []
- def set_window_size(self):
+ def create_screen(self):
self.screen = RSDL.SetVideoMode(self.width, self.height, 32, 0)
def update_display(self):
- RSDL.LockSurface(screen)
+ RSDL.LockSurface(self.screen)
self.draw_pixels()
- RSDL.UnlockSurface(screen)
- RSDL.Flip(screen)
-
+ RSDL.UnlockSurface(self.screen)
+ RSDL.Flip(self.screen)
+ pass
+
def draw_pixels(self):
for x in range(self.width):
for y in range(self.height):
- RSDL_helper.set_pixel(screen, x, y, self.get_pixel_color(x, y))
+ RSDL_helper.set_pixel(self.screen, x, y, self.get_pixel_color(x, y))
def get_pixel_color(self, x, y):
return self.pixels[x+self.width*y]
@@ -81,56 +99,52 @@
def __init__(self):
JoypadDriver.__init__(self)
- self.last_char = ""
+ self.last_key = 0
def update(self, event):
# fetch the event from sdl
- ok = RSDL.WaitEvent(event)
- assert rffi.cast(lltype.Signed, ok) == 1
type = rffi.getintfield(event, 'c_type')
+ print "JoypadDriver.update ", type
if type == RSDL.KEYDOWN:
- self.create_called_key()
+ self.create_called_key(event)
self.on_key_down()
elif type == RSDL.KEYUP:
- self.create_called_key()
+ self.create_called_key(event)
self.on_key_up()
+ pass
def create_called_key(self, event):
p = rffi.cast(RSDL.KeyboardEventPtr, event)
- char = rffi.getintfield(p.c_keysym, 'c_unicode')
- self.last_char = unichr(char).encode('utf-8')
-
-
-
- def create_button_key_codes(self):
- self.button_key_codes = {key.UP : (self.button_up),
- key.RIGHT : (self.button_right),
- key.DOWN : (self.button_down),
- key.LEFT : (self.button_left),
- key.ENTER : (self.button_start),
- key.SPACE : (self.button_select),
- key.A : (self.button_a),
- key.B : (self.button_b)}
-
- def create_listeners(self):
- self.win.on_key_press = self.on_key_press
- self.win.on_key_release = self.on_key_press
+ self.last_key = rffi.getintfield(p.c_keysym, 'c_sym')
- def on_key_press(self, symbol, modifiers):
- pressButtonFunction = self.get_button_handler(symbol, modifiers)
- if pressButtonFunction is not None:
- pressButtonFunction(True)
+ def on_key_down(self):
+ self.toggleButton(self.get_button_handler(self.last_key), True)
+
+ def on_key_up(self):
+ self.toggleButton(self.get_button_handler(self.last_key), False)
- def on_key_release(self, symbol, modifiers):
- pressButtonFunction = self.get_button_handler(symbol, modifiers)
+ def toggleButton(self, pressButtonFunction, enabled):
if pressButtonFunction is not None:
- pressButtonFunction(False)
-
- def get_button_handler(self, symbol, modifiers):
- if symbol in self.button_key_codes:
- if len(self.button_key_codes[symbol]) == 1 or\
- self.button_key_codes[symbol][1] == modifiers:
- return self.button_key_codes[symbol][0]
+ pressButtonFunction(self, enabled)
+
+ def get_button_handler(self, key):
+ print "get_button_handler: ", key
+ if key == RSDL.K_UP:
+ return JoypadDriver.button_up
+ elif key == RSDL.K_RIGHT:
+ return JoypadDriver.button_right
+ elif key == RSDL.K_DOWN:
+ return JoypadDriver.button_down
+ elif key == RSDL.K_LEFT:
+ return JoypadDriver.button_left
+ elif key == RSDL.K_RETURN:
+ return JoypadDriver.button_start
+ elif key == RSDL.K_SPACE:
+ return JoypadDriver.button_select
+ elif key == RSDL.K_a:
+ return JoypadDriver.button_a
+ elif key == RSDL.K_b:
+ return JoypadDriver.button_b
return None
@@ -163,6 +177,8 @@
def entry_point(args=None):
gameboy = GameBoyImplementation()
+ if args is None:
+ gameboy.load()
# add return statement...
return 0
More information about the Pypy-commit
mailing list