From d975c16ed7ad39a3caf32452c54cee57f7ffb5b2 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn Date: Sat, 18 Jul 2026 15:15:55 -0500 Subject: [PATCH] fix(cpu): add key register and font address bounds checks --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 6b66b59..059ce78 100644 --- a/main.c +++ b/main.c @@ -389,11 +389,11 @@ int main(int argc, char *argv[]) { break; case 57344: // E000 if (nn == 158) { - if (chip->keys[chip->V[x]] == 1) { + if (chip->keys[chip->V[x] & 0x0F] == 1) { chip->pc += 2; } } else if (nn == 161) { - if (chip->keys[chip->V[x]] != 1) { + if (chip->keys[chip->V[x] & 0x0F] != 1) { chip->pc += 2; } } @@ -411,7 +411,7 @@ int main(int argc, char *argv[]) { } else if (nn == 30) { chip->I += chip->V[x]; } else if (nn == 41) { - chip->I = FONT_START + (chip->V[x] * 5); + chip->I = FONT_START + ((chip->V[x] & 0x0F) * 5); } else if (nn == 51) { chip->memory[chip->I] = chip->V[x] / 100; chip->memory[chip->I + 1] = (chip->V[x] / 10) % 10;