From 29f25bda7a03f4ac1c553930885f031b16d63eb4 Mon Sep 17 00:00:00 2001 From: n loewen Date: Sat, 26 Aug 2023 16:44:30 -0400 Subject: [PATCH] config / cpu - Add feature: Map the arrow keys to hex keypad, in addition to the larger Qwerty set --- cpu.js | 7 +++---- machine.config.js | 8 +++++++- readme.md | 13 +++++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cpu.js b/cpu.js index e5e5c2b..dbfa40c 100644 --- a/cpu.js +++ b/cpu.js @@ -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]; } }); } diff --git a/machine.config.js b/machine.config.js index e8e56e5..190ead1 100644 --- a/machine.config.js +++ b/machine.config.js @@ -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, } \ No newline at end of file diff --git a/readme.md b/readme.md index 62572e7..0dba40d 100644 --- a/readme.md +++ b/readme.md @@ -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