keyboard
This commit is contained in:
26
chip8.c
26
chip8.c
@@ -1,5 +1,4 @@
|
|||||||
// http://devernay.free.fr/hacks/chip8/C8TECH10.HTM
|
// http://devernay.free.fr/hacks/chip8/C8TECH10.HTM
|
||||||
// TODO: keyboard
|
|
||||||
// TODO: buzzer
|
// TODO: buzzer
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -21,6 +20,11 @@
|
|||||||
fprintf(stderr, "unrecognized instruction\n"); \
|
fprintf(stderr, "unrecognized instruction\n"); \
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
static const uint8_t keyboard_map[] = {KEY_ONE, KEY_TWO, KEY_THREE, KEY_FOUR,
|
||||||
|
KEY_FIVE, KEY_SIX, KEY_SEVEN, KEY_EIGHT,
|
||||||
|
KEY_NINE, KEY_Q, KEY_W, KEY_E,
|
||||||
|
KEY_R, KEY_T, KEY_Y, KEY_U};
|
||||||
|
|
||||||
typedef struct CHIP8 {
|
typedef struct CHIP8 {
|
||||||
uint8_t *memory;
|
uint8_t *memory;
|
||||||
uint16_t pc;
|
uint16_t pc;
|
||||||
@@ -330,10 +334,14 @@ void chip8_step(CHIP8 *c) {
|
|||||||
case 0xE: {
|
case 0xE: {
|
||||||
switch (kk) {
|
switch (kk) {
|
||||||
case 0x9E:
|
case 0x9E:
|
||||||
printf("TODO: SKP V%x\n", x);
|
if (IsKeyDown(keyboard_map[c->reg[x]])) {
|
||||||
|
c->pc += 2;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 0xA1:
|
case 0xA1:
|
||||||
printf("TODO: SKNP V%x\n", x);
|
if (!IsKeyDown(keyboard_map[c->reg[x]])) {
|
||||||
|
c->pc += 2;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BAD_INS();
|
BAD_INS();
|
||||||
@@ -344,9 +352,17 @@ void chip8_step(CHIP8 *c) {
|
|||||||
case 0x07:
|
case 0x07:
|
||||||
c->reg[x] = c->delay_timer;
|
c->reg[x] = c->delay_timer;
|
||||||
break;
|
break;
|
||||||
case 0x0A:
|
case 0x0A: {
|
||||||
printf("TODO: LD V%x, K\n", x);
|
bool key_pressed = false;
|
||||||
|
while (!key_pressed && WindowShouldClose()) {
|
||||||
|
for (size_t i = 0; i < 16; i++) {
|
||||||
|
if (IsKeyDown(keyboard_map[i])) {
|
||||||
|
key_pressed = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case 0x15:
|
case 0x15:
|
||||||
c->delay_timer = c->reg[x];
|
c->delay_timer = c->reg[x];
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user