Make CPU speed configurable when running program
This commit is contained in:
parent
66e530d225
commit
2089c1cf2c
24
sipsi-8.py
24
sipsi-8.py
|
@ -705,7 +705,7 @@ def initialize_keyboard():
|
||||||
waiting_for_keypress = False
|
waiting_for_keypress = False
|
||||||
keypress_arrived = False
|
keypress_arrived = False
|
||||||
|
|
||||||
def initialize_cpu():
|
def initialize_cpu(clockspeed):
|
||||||
global cpu_clock, data_registers, ip, stack, i_register
|
global cpu_clock, data_registers, ip, stack, i_register
|
||||||
data_registers = [0] * 16
|
data_registers = [0] * 16
|
||||||
|
|
||||||
|
@ -718,10 +718,7 @@ def initialize_cpu():
|
||||||
|
|
||||||
i_register = 0
|
i_register = 0
|
||||||
|
|
||||||
# TODO: Don't hardcode the update speed
|
cpu_clock = clockspeed
|
||||||
# Run the interpreter at 500Hz
|
|
||||||
# This was picked from https://github.com/AfBu/haxe-CHIP-8-emulator/wiki/(Super)CHIP-8-Secrets
|
|
||||||
cpu_clock = 500
|
|
||||||
|
|
||||||
def load_program(f):
|
def load_program(f):
|
||||||
global ram
|
global ram
|
||||||
|
@ -733,6 +730,19 @@ def load_program(f):
|
||||||
def main():
|
def main():
|
||||||
global window
|
global window
|
||||||
global cpu_cycles_to_go, frames_to_go
|
global cpu_cycles_to_go, frames_to_go
|
||||||
|
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
program_path = sys.argv[1]
|
||||||
|
# Run the interpreter at 500Hz by default
|
||||||
|
# This was picked from https://github.com/AfBu/haxe-CHIP-8-emulator/wiki/(Super)CHIP-8-Secrets
|
||||||
|
cpu_clock = 500
|
||||||
|
elif len(sys.argv) == 3:
|
||||||
|
program_path = sys.argv[1]
|
||||||
|
cpu_clock = int(sys.argv[2])
|
||||||
|
else:
|
||||||
|
print(f'Usage: {sys.argv[0]} program [cpu-speed]', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# TODO: Don't hardcode the size
|
# TODO: Don't hardcode the size
|
||||||
window = pyglet.window.Window(640, 320, resizable = True)
|
window = pyglet.window.Window(640, 320, resizable = True)
|
||||||
|
|
||||||
|
@ -760,10 +770,10 @@ def main():
|
||||||
initialize_screen()
|
initialize_screen()
|
||||||
initialize_timers()
|
initialize_timers()
|
||||||
initialize_keyboard()
|
initialize_keyboard()
|
||||||
initialize_cpu()
|
initialize_cpu(cpu_clock)
|
||||||
|
|
||||||
# TODO: Deal with missing file gracefully
|
# TODO: Deal with missing file gracefully
|
||||||
with open(sys.argv[1], 'rb') as f:
|
with open(program_path, 'rb') as f:
|
||||||
load_program(f)
|
load_program(f)
|
||||||
|
|
||||||
cpu_cycles_to_go = 0
|
cpu_cycles_to_go = 0
|
||||||
|
|
Loading…
Reference in New Issue