Skip to content

Commit

Permalink
Fix keyboard wait for key instruction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscodelahoz committed Apr 6, 2024
1 parent 0e70cbe commit 0c7b92d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/scripts/emulator/cpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class CPU {

private waitingForKeyPressed: boolean = false;

private waitingKeyRegister: number = -1;

public halted: boolean = true;

private cyclesPerFrame: number = defaultCyclesPerFrame;
Expand Down Expand Up @@ -94,6 +96,8 @@ export class CPU {
this.flags.fill(0);

this.waitingForKeyPressed = false;
this.waitingKeyRegister = -1;

this.playing = false;
this.drawingFlag = true;
this.hiresMode = false;
Expand Down Expand Up @@ -824,13 +828,13 @@ export class CPU {
*/
case 0x0A: {
this.waitingForKeyPressed = true;
this.waitingKeyRegister = x;

this.keyboardInterface.onNextKeyPressed = (key) => {
this.registers[x] = key;
};
this.keyboardInterface.onNextKeyPressed = () => {};

this.keyboardInterface.onNextKeyReleased = () => {
this.keyboardInterface.onNextKeyReleased = (key) => {
this.waitingForKeyPressed = false;
this.registers[this.waitingKeyRegister] = key;
};

break;
Expand Down

0 comments on commit 0c7b92d

Please sign in to comment.