diff options
Diffstat (limited to 'main.ha')
| -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 => |
