[pypy-svn] r54517 - pypy/branch/gameboy-emulator/pypy/lang/gameboy
cami at codespeak.net
cami at codespeak.net
Wed May 7 11:27:47 CEST 2008
Author: cami
Date: Wed May 7 11:27:46 2008
New Revision: 54517
Added:
pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboyImplementation.py
Modified:
pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py
pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py
Log:
create gameboy pyglet test implementation
if it would run, should create a new window
Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py (original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/cpu.py Wed May 7 11:27:46 2008
@@ -2,6 +2,7 @@
class Register(object):
+
def __init__(self, cpu, value=0):
self.resetValue = self.value = value
self.cpu = cpu
@@ -31,11 +32,11 @@
def __init__(self, cpu, hi=None, lo=None, resetValue=0):
self.cpu = cpu
- if isinstance(hi, (Register)) :
- self.hi = hi
- else:
+ if hi == None :
self.hi = Register(self.cpu)
- if lo==None:
+ else:
+ self.hi = hi
+ if lo == None:
self.lo = Register(self.cpu)
else:
self.lo = lo
@@ -87,6 +88,7 @@
# ------------------------------------------------------------------------------
class ImmediatePseudoRegister(object):
+
def __init__(self, cpu, hl):
self.cpu = cpu
self.hl = hl
@@ -182,24 +184,24 @@
self.reset()
def iniRegisters(self):
- self.b = Register(self)
- self.c = Register(self)
+ self.b = Register(self)
+ self.c = Register(self)
self.bc = DoubleRegister(self, self.b, self.c, constants.RESET_BC)
- self.d = Register(self)
- self.e = Register(self)
+ self.d = Register(self)
+ self.e = Register(self)
self.de = DoubleRegister(self, self.d, self.e, constants.RESET_DE)
- self.h = Register(self)
- self.l = Register(self)
+ self.h = Register(self)
+ self.l = Register(self)
self.hl = DoubleRegister(self, self.h, self.l, constants.RESET_HL)
self.hli = ImmediatePseudoRegister(self, self.hl)
- self.pc = DoubleRegister(self, resetValue=constants.RESET_PC)
- self.sp = DoubleRegister(self, resetValue=constants.RESET_SP)
+ self.pc = DoubleRegister(self, resetValue=constants.RESET_PC)
+ self.sp = DoubleRegister(self, resetValue=constants.RESET_SP)
- self.a = Register(self, constants.RESET_A)
- self.f = FlagRegister(self)
+ self.a = Register(self, constants.RESET_A)
+ self.f = FlagRegister(self)
self.af = DoubleRegister(self, self.a, self.f)
@@ -207,9 +209,9 @@
self.resetRegisters()
self.f.reset()
self.f.zFlag = True
- self.ime = False
- self.halted = False
- self.cycles = 0
+ self.ime = False
+ self.halted = False
+ self.cycles = 0
def resetRegisters(self):
self.a.reset()
Modified: pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py
==============================================================================
--- pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py (original)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboy.py Wed May 7 11:27:46 2008
@@ -4,16 +4,16 @@
GameBoy Scheduler and Memory Mapper
"""
-from pypy.lang.gameboy import constants
-from pypy.lang.gameboy.cpu import *
+from pypy.lang.gameboy import constants
+from pypy.lang.gameboy.cpu import *
from pypy.lang.gameboy.cartridge import *
from pypy.lang.gameboy.interrupt import *
-from pypy.lang.gameboy.joypad import *
-from pypy.lang.gameboy.ram import *
-from pypy.lang.gameboy.serial import *
-from pypy.lang.gameboy.sound import *
-from pypy.lang.gameboy.timer import *
-from pypy.lang.gameboy.video import *
+from pypy.lang.gameboy.joypad import *
+from pypy.lang.gameboy.ram import *
+from pypy.lang.gameboy.serial import *
+from pypy.lang.gameboy.sound import *
+from pypy.lang.gameboy.timer import *
+from pypy.lang.gameboy.video import *
from pypy.lang.gameboy.cartridge import *
Added: pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboyImplementation.py
==============================================================================
--- (empty file)
+++ pypy/branch/gameboy-emulator/pypy/lang/gameboy/gameboyImplementation.py Wed May 7 11:27:46 2008
@@ -0,0 +1,127 @@
+
+import pyglet
+pyglet.options['audio'] = ('openal', 'silent')
+
+from pyglet import window
+from pyglet.window import key
+from pyglet import media
+
+from pypy.lang.gameboy.joypad import JoypadDriver
+from pypy.lang.gameboy.video import VideoDriver
+from pypy.lang.gameboy.sound import SoundDriver
+
+
+# GAMEBOY ----------------------------------------------------------------------
+
+class GameBoyImplementation(GameBoy):
+
+ def __init__(self):
+ self.iniWindow()
+ GameBoy.__init__(self)
+
+ def iniWindow(self):
+ self.win = window.Window()
+
+ def createDrivers(self):
+ self.clock = Clock()
+ self.joypadDriver = JoypadDriverImplementation(self.win)
+ self.videoDriver = VideoDriverImplementation(self.win)
+ self.soundDriver = SoundDriverImplementation(self.win)
+
+
+# JOYPAD DRIVER ----------------------------------------------------------------
+
+class JoypadDriverImplementation(object):
+
+ def __ini__(self, win):
+ JoypadDriver.__ini__(self)
+ self.crateButtonKeyCodes()
+ self.win = win
+ self.createListeners()
+
+ def crateButtonKeyCodes(self):
+ self.buttonKeyCodes = {key.UP : (self.buttonUp),
+ key.RIGHT : (self.buttonRight),
+ key.DOWN : (self.buttonDown),
+ key.LEFT : (self.buttonLeft),
+ key.ENTER : (self.buttonStart),
+ key.SPACE : (self.buttonSelect),
+ key.A : (self.buttonA),
+ key.B : (self.ButtonB)}
+
+ def createListeners(self):
+ self.win.on_key_press = self.on_key_press
+ self.win.on_key_release = self.on_key_press
+
+ def on_key_press(symbol, modifiers):
+ pressButtonFunction = self.getButton(symbol, modifiers)
+ if pressButtonFunction != None:
+ pressButtonFunction(True)
+
+ def on_key_release(symbol, modifiers):
+ pressButtonFunction = self.getButton(symbol, modifiers)
+ if pressButtonFunction != None:
+ pressButtonFunction(False)
+
+ def getButton(self, symbol, modifiers):
+ if symbol in self.buttonKeyCodes:
+ if len(self.buttonKeyCodes[symbol]) == 1 or\
+ self.buttonKeyCodes[symbol][1] == modifiers:
+ return self.buttonKeyCodes[symbol][0]
+ return None
+
+
+# SOUND DRIVER -----------------------------------------------------------------
+
+class SoundDriverImplementation(SoundDriver):
+
+ def __init__(self):
+ SoundDriver.__init__(self)
+ self.createSoundDriver()
+ self.enabled = True
+ self.sampleRate = 44100
+ self.channelCount = 2
+ self.bitsPerSample = 8
+
+ def createSoundDriver(self):
+
+ def start(self):
+ pass
+
+ def stop(self):
+ pass
+
+ def write(self, buffer, length):
+ pass
+
+
+# VIDEO DRIVER -----------------------------------------------------------------
+
+class VideoDriverImplementation(VideoDriver):
+
+ def __init__(self, win):
+ VideoDriver.__init__(self)
+ self.win = win
+ self.win.on_resize = self.on_resize
+ self.setWindowSize()
+ self.createImageBuffer()
+
+ def createImageBuffer(self):
+ self.buffers = image.get_buffer_manager()
+ self.imageBuffer = self.buffers.get_color_buffer()
+
+ def on_resize(self, width, height):
+ pass
+
+ def setWindowSize(self):
+ self.win.setSize(self.width, self.height)
+
+ def updateDisplay(self):
+ self.clearPixels()
+
+
+# ==============================================================================
+
+if __name__ == '__main__':
+ print "starting gameboy"
+ gameboy = GameBoyImplementation()
More information about the pypy-svn
mailing list