diff options
| author | Polesznyák Márk <contact@pml68.dev> | 2026-02-23 19:44:57 +0100 |
|---|---|---|
| committer | Polesznyák Márk <contact@pml68.dev> | 2026-02-23 19:44:57 +0100 |
| commit | 7c6c9af0261bd72ca42fe273591be40b2661bb10 (patch) | |
| tree | 9ea3e1fd74bcb3d8cf7f1ddd4cc46a34b3890917 | |
| parent | fix: incorrectly implemented instructions (8XY6, 8XYE) (diff) | |
| download | hare-chip8-7c6c9af0261bd72ca42fe273591be40b2661bb10.tar.gz | |
fix: broken FX0A instruction implementation
| -rw-r--r-- | main.ha | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -50,6 +50,7 @@ type state = struct { mem: [MEM_SIZE]u8, display: [SCREEN_WIDTH * SCREEN_HEIGHT]bool, draw: bool, + current_key_pressed: u8, keys: [16]bool, stack: [16]u16, SP: u16, @@ -63,6 +64,7 @@ type state = struct { fn chip8() state = { let state = state { PC = START_ADDR, + current_key_pressed = 0xFF, ... }; @@ -301,24 +303,19 @@ fn execute_instruction(state: *state, inst: inst, random: *random::random) void case 0x07 => state.V[inst.X] = state.DT; case 0x0A => - let any_pressed = false; - let key: u8 = 0xFF; - - for (let i = 0z; key == 0xFF && i < len(state.keys); i += 1) + for (let i = 0z; state.current_key_pressed == 0xFF && i < len(state.keys); i += 1) if (state.keys[i]) { - any_pressed = true; - key = i: u8; + state.current_key_pressed = i: u8; break; }; - if (!any_pressed) state.PC -= 2 + if (state.current_key_pressed == 0xFF) state.PC -= 2 else { - if (state.keys[key]) + if (state.keys[state.current_key_pressed]) state.PC -= 2 else { - state.V[inst.X] = key; - key = 0xFF; - any_pressed = false; + state.V[inst.X] = state.current_key_pressed; + state.current_key_pressed = 0xFF; }; }; case 0x15 => |
