summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2020-08-21 22:43:23 +0930
committerDaniel Jones <admin@danieljon.es>2020-08-21 22:43:23 +0930
commit96aee8e563cbe395881c86d39e46ae4649426eec (patch)
tree56c726dcbc692a89ad099e0db87cc7842b44aed0
parente3e8912dae70da1fff03607e68610d21adf21002 (diff)
downloadchip8-96aee8e563cbe395881c86d39e46ae4649426eec.tar.gz
chip8-96aee8e563cbe395881c86d39e46ae4649426eec.zip
fixed wait until key press opcode
-rw-r--r--chip8.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/chip8.c b/chip8.c
index 7c966ed..97d67ff 100644
--- a/chip8.c
+++ b/chip8.c
@@ -129,7 +129,7 @@ chip8_beep()
void
unknown_opcode(uint16_t bad_opcode)
{
- fprintf(stderr, "unknown opcode: 0x%02X at 0x%02X\n", bad_opcode, PC-2); // minus 2 because we increment PC by 2 at the start of decoding
+ fprintf(stderr, "unknown opcode: 0x%04X at 0x%02X\n", bad_opcode, PC-2); // minus 2 because we increment PC by 2 at the start of decoding
}
void
chip8_cycle()
@@ -306,14 +306,16 @@ chip8_cycle()
case 0x0A: /* LD Vx, K (all execution stops until a key is pressed, then that key is put into Vx) */
{
// TODO: not tested
- int found_key = 0;
- for (int i = 0; i < 15; i++)
+ int found = 0;
+ for (int i = 0; i <= KEY_SIZE; i++)
{
- V[x] = key[i];
- if (V[x] == 1)
- found_key = 1;
+ if (key[i])
+ {
+ V[x] = i;
+ found = 1;
+ }
}
- PC -= (found_key == 0) ? 2 : 0;
+ PC -= (found == 0) ? 2 : 0;
break;
}
case 0x15: /* LD DT, Vx (delay timer is set to the value of Vx */