5

I'm currently writing a ZX Spectrum emulator (I know there are plenty, but it's a project).

I'm having an issue where it keeps repeating the last key press even though I know the port lines have been reset.

This is what it looks like: ZXE Keyboard Shenanigans (in this recording, I pressed C once).

It might be helpful if I could know the location in memory where the Speccy stores lines of BASIC being entered, so I could see what's updating that.

2

2 Answers 2

10

It's all in the original ZX Spectrum user manual.

Chapter 24 'The Memory' details the various memory areas maintained by ZX BASIC, including the memory format of a BASIC line and of the various types of variables.

Chapter 25 'System Variables' lists the various system variables, some of which are the start addresses of the various memory areas.

  • 16-bit start address of BASIC line being edited is stored in E_LINE at address 23641 (0x5C59).

  • 16-bit end address of BASIC line being edited is WORKSP-1.

  • 16-bit address WORKSP is stored at address 23649 (0x5C61).

You'll find the below diagram of memory allocation in chapter 24.

enter image description here

1
  • 1
    Ooh. That looks promising! Thanks... will investigate and accept the answer if it's correct.
    – Stevo
    Mar 2 at 23:24
3

The keyboard subroutines move the last key that has been pressed into the system variable LAST_K ($5C08).

The KSTATE array (the 8 bytes before LAST_K, $5C00-5C07) are an array of two sets of 4-byte entries that are used for keyboard de-bounce and key repeat triggering.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .