[pypy-svn] r55525 - in pypy/dist/pypy/lang/gameboy: . test
cami at codespeak.net
cami at codespeak.net
Tue Jun 3 19:40:18 CEST 2008
Author: cami
Date: Tue Jun 3 19:40:14 2008
New Revision: 55525
Added:
pypy/dist/pypy/lang/gameboy/test/test_gameboy_implementaton.py
Modified:
pypy/dist/pypy/lang/gameboy/gameboy_implementation.py
pypy/dist/pypy/lang/gameboy/joypad.py
Log:
added interactive test for the joypad implementation
fixed a possible bug in joypad.py
Modified: pypy/dist/pypy/lang/gameboy/gameboy_implementation.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/gameboy_implementation.py (original)
+++ pypy/dist/pypy/lang/gameboy/gameboy_implementation.py Tue Jun 3 19:40:14 2008
@@ -32,15 +32,9 @@
def mainLoop(self):
- #self.reset()
try:
isRunning = True
- while isRunning:
- while self.poll_event():
- if self.check_for_escape():
- isRunning = False
- break
- self.joypad_driver.update(self.event)
+ while isRunning and self.handle_events():
self.emulate(constants.GAMEBOY_CLOCK >> 2)
#RSDL.Delay(1)
finally:
@@ -48,6 +42,14 @@
RSDL.Quit()
return 0
+ def handle_events(self):
+ isRunning = True
+ while self.poll_event():
+ if self.check_for_escape():
+ isRunning = False
+ self.joypad_driver.update(self.event)
+ return isRunning
+
def poll_event(self):
ok = rffi.cast(lltype.Signed, RSDL.PollEvent(self.event))
@@ -129,11 +131,9 @@
self.last_key = rffi.getintfield(p.c_keysym, 'c_sym')
def on_key_down(self):
- print "press"
self.toggleButton(self.get_button_handler(self.last_key), True)
def on_key_up(self):
- print "release"
self.toggleButton(self.get_button_handler(self.last_key), False)
def toggleButton(self, pressButtonFunction, enabled):
@@ -142,28 +142,20 @@
def get_button_handler(self, key):
if key == RSDL.K_UP:
- print " up"
return JoypadDriver.button_up
elif key == RSDL.K_RIGHT:
- print " right"
return JoypadDriver.button_right
elif key == RSDL.K_DOWN:
- print " down"
return JoypadDriver.button_down
elif key == RSDL.K_LEFT:
- print " left"
return JoypadDriver.button_left
elif key == RSDL.K_RETURN:
- print " start"
return JoypadDriver.button_start
elif key == RSDL.K_SPACE:
- print " select"
return JoypadDriver.button_select
elif key == RSDL.K_a:
- print " A"
return JoypadDriver.button_a
elif key == RSDL.K_b:
- print " B"
return JoypadDriver.button_b
return None
Modified: pypy/dist/pypy/lang/gameboy/joypad.py
==============================================================================
--- pypy/dist/pypy/lang/gameboy/joypad.py (original)
+++ pypy/dist/pypy/lang/gameboy/joypad.py Tue Jun 3 19:40:14 2008
@@ -44,9 +44,9 @@
def update(self):
oldButtons = self.button_code
- if self.joyp == 0x1:
+ if self.joyp & 0xF0 == 0x10:
self.button_code = self.driver.get_button_code()
- elif self.joyp == 0x2:
+ elif self.joyp & 0xF0 == 0x20:
self.button_code = self.driver.get_direction_code()
else:
self.button_code = 0xF
Added: pypy/dist/pypy/lang/gameboy/test/test_gameboy_implementaton.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lang/gameboy/test/test_gameboy_implementaton.py Tue Jun 3 19:40:14 2008
@@ -0,0 +1,75 @@
+import py
+from pypy.lang.gameboy.gameboy_implementation import *
+from pypy.lang.gameboy import constants
+
+import py, sys
+from pypy import conftest
+
+#
+# This test file is skipped unless run with "py.test --view".
+# If it is run as "py.test --view -s", then it interactively asks
+# for confirmation that the window looks as expected.
+#
+
+if sys.platform == 'darwin':
+ from AppKit import NSApplication
+ NSApplication.sharedApplication()
+
+class TestGameBoyImplementation(object):
+
+ def setup_method(self, meth):
+ if not conftest.option.view:
+ py.test.skip("'--view' not specified, "
+ "skipping tests that open a window")
+ self.gameboy = GameBoyImplementation()
+ self.is_interactive = sys.stdout.isatty()
+
+ def check(self, msg):
+ if self.is_interactive:
+ print
+ answer = raw_input('Interactive test: %s - ok? [Y] ' % msg)
+ if answer and not answer.upper().startswith('Y'):
+ py.test.fail(msg)
+ else:
+ print msg
+
+ def test_buttons(self):
+ for i in [("A", constants.BUTTON_A),
+ ("B", constants.BUTTON_B),
+ ("START", constants.BUTTON_START),
+ ("SELECT", constants.BUTTON_SELECT),
+ ("A and B", constants.BUTTON_A | constants.BUTTON_B),]:
+ print "press ", i[0]
+ isRunning = True
+ while isRunning:
+ while self.gameboy.poll_event():
+ if self.gameboy.check_for_escape():
+ isRunning = False
+ break
+ self.gameboy.joypad_driver.update(self.gameboy.event)
+ if self.gameboy.joypad_driver.get_button_code() == i[1]:
+ isRunning = False
+
+ def test_directions(self):
+ for i in [("up", constants.BUTTON_UP),
+ ("left", constants.BUTTON_LEFT),
+ ("down", constants.BUTTON_DOWN),
+ ("right", constants.BUTTON_RIGHT),
+ ("down + right", constants.BUTTON_DOWN | constants.BUTTON_RIGHT)]:
+ print "press ", i[0]
+ isRunning = True
+ while isRunning:
+ while self.gameboy.poll_event():
+ if self.gameboy.check_for_escape():
+ isRunning = False
+ break
+ self.gameboy.joypad_driver.update(self.gameboy.event)
+ if self.gameboy.joypad_driver.get_direction_code() == i[1]:
+ isRunning = False
+
+
+
+
+ def teardown_method(self, meth):
+ RSDL.Quit()
+
More information about the Pypy-commit
mailing list