From the FAQ: The 128K machine's keypad extra editing facilities are also available via the normal keyboard: FUNCTION KEYS ----------------------------------------- Beginning of next word [E] [S] J Beginning of previous word [E] I Up ten lines [E] P Down ten lines [S] I Start of line [E] [S] 2 End of line [E] M First line [E] N Last line [E] T Screen [E] [S] 8 Delete this character [E] [S] K Delete word left [E] E Delete word right [E] W Delete to start of line [E] K Delete to end of line [E] J [E] = Extended Mode [S] = Symbol Shift From Warajevo documentation: 2.3. THE KEYBOARD AND KEYPAD ======================= The keyboard is mostly mapped as the standard Spectrum's keyboard (F1 displays the keyboard layout on the original keyboard). For CAPS SHIFT you can use keys 'Shift' or 'Ctrl', and for SYMBOL SHIFT you can use 'Alt'. Some keys on the PC keyboard have a special meaning: CapsLock: CAPS SHIFT + 2 (CAPS LOCK) Tab: CAPS SHIFT + SYMBOL SHIFT (EXTENDED MODE) Esc: CAPS SHIFT + SPACE (BREAK) Backspace: CAPS SHIFT + 0 (DELETE) The cursor keys on the numerical keyboard, like the grey cursor keys, normally generate CAPS SHIFT + 5, 6, 7 and 8, but this can be changed using the previously described option /J. The key '+' on the numerical keyboard and the key '~' (depending on the option /J) behave like a fire button on the joystick. We can not say anything more about the keyboard in the 48 version of the emulator. However, the 128 version of the emulator also emulates the KEYPAD. This is the addition to the keyboard delivered with the first versions of the Spectrum 128K, and later it was bought as an optional. The KEYPAD emulation activates or deactivates by pressing the key 'NumLock', and the corresponding LED diode determines whether the emulation is active. When emulating the KEYPAD, the keys on the numerical keyboard and some grey keys receive special meaning. Because most of the users had no opportunity to see a real KEYPAD, we will describe it in more detail. The KEYPAD has 18 keys (one key more than is on most PC numeric keyboards). Its keys have the same labels as the PC, except that 'NumLock' doesn't exist, and left and right brackets are present. The keyboard layout is almost identical, with small differences. The keys '*' and '/' are above the keys '7' and '8'. The keys '(' and ')' are above '9' and '+'. Instead of a big '+' key, on the KEYPAD there are the keys '-' (up) and '+' (down), one key above another. The layout of the other keys is the same. But on the KEYPAD keys there are also the labels showing different enhanced editor functions. The ROM routine which reads from the KEYPAD interprets the pressing of these keys differently depending on whether the computer is in '128 Basic' or in 'Calculator' mode. In 'Calculator' mode the KEYPAD works as a numerical keyboard. This is implemented in the emulator too, and the keys are mapped on the PC keyboard as normal (only the brackets are missing), and there is nothing more to say. However, in '128 Basic' mode, the KEYPAD keys have additional functions. Unfortunately, the way they are mapped must be remembered because these labels are not written on the PC's numerical keyboard. The keys are mapped in this way: 7 - Cursor left for one character (LEFT) 9 - Cursor right for one character (RIGHT) * - Cursor up for one character (UP) 8 - Cursor down for one character (DOWN) 4 - Cursor left for one word (WORD LEFT) 5 - Cursor right for one word (WORD RIGHT) 6 - Cursor up for 10 rows (PAGE UP) + - Cursor down for 10 rows (PAGE DOWN) 1 - Cursor to the start of BASIC line (HOME) 2 - Cursor to the end of BASIC line (END) 3 - Cursor to the top of the program (TOP) . - Cursor to the end of program (BOTTOM) / - Delete characters left from cursor (DELETE LEFT) - - Open command menu (CMND) 0 - SHIFT for destructive functions (DEL SHIFT) Some destructive functions are activated if you simultaneously press '0' on the numerical keyboard, and one of the following keys on the numerical keyboard too: 1 - Delete from cursor to start of line (DELETE FROM START) 2 - Delete from cursor to end of line (DELETE TO END) 4 - Delete word left from the cursor (DELETE WORD LEFT) 5 - Delete word right from the cursor (DELETE WORD RIGHT) There are two functions on the keypad (on the brackets) which delete the character at the cursor position (DELETE RIGHT) and switch the editor's window to the bottom part of the screen (TOGGLE). These are mapped to the keys 'Delete' (grey) and 'Scroll lock'. This key mapping is a bit unusual, at first sight. Of course the keys could be mapped to be like some labels on the PC's numerical keyboard, but because the KEYPAD is emulated on an I/O level, and the routine in ROM interprets the keys differently depending on '128 Basic' or 'Calculator' mode (more precisely, depending on bit 0 of the system variable FLAGS3 (23398) ) any other keyboard mapping (without ROM changing) will ruin the correct behaviour of the KEYPAD keys in the 'Calculator' mode. To simplify the use of some extended editor's functions when KEYPAD emulation is active the grey keys have the following meanings: Page Up: Cursor up for 10 rows (PAGE UP) Page Down: Cursor down for 10 rows (PAGE DOWN) Home: Cursor to the start of the BASIC line (HOME) End: Cursor to the end of the BASIC line (END) The side effect is that pressing of these keys in the 'Calculator' mode generates the signs '6', '+', '1' and '2' respectively. The key 'Insert' also works like SHIFT for destructive operations (in the calculator it generates a sign '0'). The keys 'Delete' (grey) and 'Scroll lock' in '128 BASIC' mode work as already described. In our calculator mode they generate missing brackets. To reduce confusion, while the KEYPAD is active, the grey cursor keys always generate the moving of the cursor (CAPS SHIFT + 5, 6, 7 and 8), no matter what option /J is active. We should mention that, because the scanning of the KEYPAD in ROM executes quite an ugly routine program execution, especially on slower machines, is slower when KEYPAD emulation is active. 7.7. THE EMULATION OF THE KEYBOARD AND THE KEYPAD ============================================ Keyboard emulation is simple: the emulator installs a new handler for keyboard interrupt, which keeps keyboard state in similar way as on real Spectrum. Later, when the program reads keyboard ports, emulator reads this state, so keyboard reading is smooth and extremely fast. However, 'matrix' effect is not emulated, so CAPS SHIFT + SYMBOL SHIFT + Z will not generate BREAK. We think that this is really not very important, although some emulators include this effect too. KEYPAD (at Spectrum 128) is a quite complex device, but it is not obvious at a first look (this is a reason why it was so expensive). KEYPAD controller is a (hardware) finite automate with time-outs, which changes state on every transient of a KEYPAD clock pulse. It is implemented on the emulator as a software finite automate. KEYPAD controller communicate with Spectrum 128 using very unusual serial protocol. When we first time connect KEYPAD on the Spectrum, KEYPAD controller goes through following sequence of states (this is initial test sequence, states is grouped in groups of four states for more readability): 1011 0111 0111 0111 0111 After this, KEYPAD controller enters a working loop. It scans rows of KEYPAD. If we numerate rows from 1 to 5 (1 is a top row), the controller scans rows in following order: 5, 4, 1, 2, 3. If controller detects that keys positions (non-press or press) in current row is not changed since last scanning, controller goes through following sequence of states: 0011 Otherwise (if some key in current row changes its position), controller goes through following sequence of states: 0111 0A11 0B11 0C11 0D11 Letters A, B, C, D have meaning 'state of first, second etc. key in current row' (1 = pressed, 0 = released). After first row, KEYPAD controller scans a next row, and so on. If clock pulse is set for a long time, KEYPAD controller will go out of working loop, e.g. it will reset, and next time, responds with initial test sequence. As you see, KEYPAD protocol is very complex, and ROM routine which reads KEYPAD is long (and slow, that is reason why KEYPAD emulation slows down BASIC programs). The system variables ROW01, ROW23 and ROW45 (addresses 23432, 23433 and 23434) keeps bit images of KEYPAD keys, and ROM routine decode this bits differently, depending of active mode ('128 Basic' or 'Calculator'), more precisely, depending of bit 0 in system variable FLAGS3 (address 23398). INKEY$ function in BASIC will read KEYPAD too and for KEYPAD keys it will return codes as with ordinary number keys (except if you give command like POKE 23398,0 within BASIC program). Variable ROW01 contains some flags for KEYPAD reading too: D7=0 & D6=0 => ROM routine waits for reset of KEYPAD controller and responding with initial sequence (during this, bit D0=1 means waiting for reset, and then ROW23 acts as waiting counter); D7=1 & D6=0 => ROM routine detects that something is wrong with KEYPAD and stops any following scanning; D7=1 & D6=1 => KEYPAD controller is into working loop. So, if you execute POKE 23432,128 from BASIC, ROM routine will not scan the KEYPAD, and this will speed up BASIC program (even when KEYPAD emulation is active). On a real Spectrum 128, when KEYPAD is not connect, bit D5 in register R14 will be always 1. However, in the emulator, this bit is 0 when the KEYPAD emulation is not active. This is done because with this bit as zero ROM routine which scans the KEYPAD will fail (and exit with NOTDONE status) earlier, and this trick slightly speeds up interrupt routine when KEYPAD emulation is not active). 7.3.5. 'ZX SPECTRUM 128' PORTS ======================= Every port with A1=0 acts to the Spectrum 128 peripherals (AY sound chip, memory management, RS232, KEYPAD and MIDI ports). True meaning of this ports depend of other address bits. Every port with A1=0 and A15=0 (usually 32765) acts to the memory management unit. This port is write only: Output: bits D0-D2: select RAM bank at addresses above 49152 bit D3: select active video page (0 = normal, 1 = alternative) bit D4: select active ROM (0 = Derby, 1 = Standard) bit D5: 48K lock bit (1 = MMU is locked) Due to hardware bug, reading this port is same as writing 255 at this port, so IN 32765 will cause crash, as on real Spectrum 128. This effect is implemented only at Warajevo emulator (that's why program Insane, which on most emulators may be loaded either in 48 or 128 Basic, on Warajevo emulator must be loaded into 48 Basic, like on real Spectrum). Every port with A1=0 and A15=1 acts to AY sound chip (and RS232, KEYPAD and MIDI which work through register R14 of sound chip). When A14=1 (usually port 65533) writing to this port selects active sound chip register, and reading from this port returns value of active sound chip register. When A14=0 (usually 49149) writing to this port stores value in active AY sound chip register, and reading from this port will always return 255. Some of the sound chip registers have length smaller than 8 bits (extra bits is always zero). This is brief table of sound chip registers: Register Length Description R0 8 Fine control of channel A frequency R1 4 Coarse control of channel A frequency R2 8 Fine control of channel B frequency R3 4 Coarse control of channel B frequency R4 8 Fine control of channel B frequency R5 4 Coarse control of channel B frequency R6 6 Noise pseudofrequency (implemented only with options /SX and /SB) R7 7 Mixer control: D0 - if D0=0, channel A produce tone D1 - if D1=0, channel B produce tone D2 - if D2=0, channel C produce tone D3 - if D3=0, channel A produce noise (not implemented with options /S0-7) D4 - if D4=0, channel B produce noise (not implemented with options /S0-7) D5 - if D5=0, channel C produce noise (not implemented with options /S0-7) D6 - if D6=0, register R14 is input port, else it is output port R8 5 Channel A volume, if D4=1 envelope generator is used R9 5 Channel B volume, if D4=1 envelope generator is used R10 5 Channel C volume, if D4=1 envelope generator is used R11 8 Fine control of envelope period R12 8 Coarse control of envelope period R13 4 Envelope control register D0 - HOLD bit D1 - ALTERNATE bit D2 - ATTACK bit D3 - CONTINUE bit R14 8 Controls RS232, KEYPAD and MIDI (see text below) R15 8 Exists, but not in use (game OutRun tests presence of this register) Detailed description of exact behaviour of sound chip may be found in the documentation given with Lunter's Z80 emulator release 3.5. When you try to select register above R15, it seems that most significant 4 bits will be ignored (can anybody confirm this to us)? When register R14 acts as output port (bit D6=1 in register R7), bits in register R14 have following meanings: Output: bit D0: KEYPAD clock (see KEYPAD emulation) bit D1,D4: have no meaning bit D2: CTS and MIDI output signal (CTS is not implemented, MIDI output is implemented using analogous method like RS232 output on ZX Interface 1, except that collected byte will be sent to Sound Blaster MIDI output register) bit D3: RS232 output bit (implemented as on ZX Interface 1) bits D5-D7: masks for reading bits D5-D7 (see text below) Input: bits D0-D4: last values sent to these bits bit D5: KEYPAD response bit bit D6: DTR bit (i.e. printer is ready) bit D7: RS232 input bit (not implemented, always one) The bits D5-D7 when reading return valid values only if they are not masked, i.e. if corresponding mask bits is one, else they will return zeroes. When register R14 acts as input port (bit D6=0 in register R7, Spectrum 128 software never make this setting), bits in register R14 have following meaning: Output: Ignored! Input: bits D0-D4: always one bit D5: KEYPAD response bit bit D6: DTR bit (i.e. printer is ready) bit D7: RS232 input bit (not implemented, always one) In this case, bits D5-D7 could not be masked.