config / cpu - Add feature: Map the arrow keys to hex keypad, in addition to the larger Qwerty set

This commit is contained in:
n loewen 2023-08-26 16:44:30 -04:00
parent 872489c18d
commit 29f25bda7a
3 changed files with 21 additions and 7 deletions

7
cpu.js
View File

@ -307,10 +307,9 @@ function startCPU(code) {
}
process.stdin.on('keypress', (str, key) => { // TODO: is it possible to turn this off again?
if (key.sequence === '\x03') process.exit();
str = str.toUpperCase();
if (str in KEY_MAP) {
CPU.memory[KEYPAD_ADDR] = KEY_MAP[str];
let name = key.name.toUpperCase();
if (name in KEY_MAP) {
CPU.memory[KEYPAD_ADDR] = KEY_MAP[name];
}
});
}

View File

@ -16,10 +16,16 @@ module.exports = {
'Q':'4', 'W':'5', 'E':'6', 'R':'D',
'A':'7', 'S':'8', 'D':'9', 'F':'E',
'Z':'A', 'X':'0', 'C':'B', 'V':'F',
// Include conventional arrow keys
'UP': '5',
'LEFT': '7',
'DOWN': '8',
'RIGHT': '9',
},
// max number of times to step the CPU,
// to stop endless loops
// 0 = infinite
"CYCLE_LIMIT": 256,
"DEFAULT_CYCLE_LIMIT": 2048,
}

View File

@ -125,7 +125,7 @@ Put differently: it starts executing instructions at the address contained in `$
The value of the latest keypress on a hex keypad is stored at `$1B`.
The keypad uses the same layout as the COSMAC VIP (and CHIP-8). The CPU simulator maps those keys onto a Qwerty set.
The keypad uses the same layout as the COSMAC VIP (and CHIP-8). The CPU simulator maps those keys onto a Qwerty set:
```
1 2 3 C 1 2 3 4
@ -133,7 +133,16 @@ The keypad uses the same layout as the COSMAC VIP (and CHIP-8). The CPU simulato
7 8 9 E A S D F
A 0 B F Z X C V
VIP simulator
hex pad simulator
```
The arrow keys are also mapped onto the hex keypad:
```
5 ↑
7 8 9 ← ↓ →
hex pad simulator
```
## Assembly language