Skip to content

Keyboard, memory and registers ​

Hold and release keys ​

python
from mrkwatkins.oakemu.zxspectrum import Keys, ZXSpectrum

spectrum = ZXSpectrum()
spectrum.keyboard.press(Keys.SHIFT | Keys.A)
spectrum.execute_frames(2)
spectrum.keyboard.depress(Keys.A)
spectrum.keyboard.depress_all()

press holds down keys without releasing others. depress releases the supplied keys, and depress_all releases every key.

Assign pressed to replace the whole set of held keys:

python
spectrum.keyboard.pressed = Keys.SPACE | Keys.D1
print(spectrum.keyboard.pressed)
spectrum.keyboard.pressed = Keys.NONE

D0 to D9 are the digit keys. SHIFT is Caps Shift and SYMBOL_SHIFT is Symbol Shift.

Read and write memory ​

python
spectrum.memory[30000] = 0xAB
value = spectrum.memory[30000]

Addresses are integers from 0 to 65535. Values written to memory must be integers from 0 to 255. An invalid address raises IndexError; a value outside the byte range raises OverflowError.

Access CPU registers ​

python
spectrum.cpu.registers.pc = 30000
spectrum.cpu.registers.de = 0x1234
print(spectrum.cpu.registers.a)

Register names are lowercase. Individual registers such as a are bytes; pairs such as de and address registers such as pc are words.