manejando teclado
This commit is contained in:
@@ -512,7 +512,7 @@ void Interpreter::drw_vx_vy_nibble(const Instruction& instruction) const
|
||||
|
||||
void Interpreter::skp_vx(const Instruction& instruction) const
|
||||
{
|
||||
if (this->machine_state->keyboard & 1 << instruction.x)
|
||||
if (this->machine_state->keyboard & 1 << this->machine_state->v[instruction.x])
|
||||
{
|
||||
this->machine_state->pc += 2;
|
||||
}
|
||||
@@ -520,7 +520,7 @@ void Interpreter::skp_vx(const Instruction& instruction) const
|
||||
|
||||
void Interpreter::sknp_vx(const Instruction& instruction) const
|
||||
{
|
||||
if (!(this->machine_state->keyboard & 1 << instruction.x))
|
||||
if (!(this->machine_state->keyboard & 1 << this->machine_state->v[instruction.x]))
|
||||
{
|
||||
this->machine_state->pc += 2;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,94 @@ bool Machine::on_event(const SDL_Event* event) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (event->type == SDL_EVENT_KEY_DOWN || event->type == SDL_EVENT_KEY_UP)
|
||||
{
|
||||
const bool pressed = event->type == SDL_EVENT_KEY_DOWN;
|
||||
switch (event->key.scancode)
|
||||
{
|
||||
case SDL_SCANCODE_1:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x1)
|
||||
: machine_state->keyboard & ~(1 << 0x1);
|
||||
break;
|
||||
case SDL_SCANCODE_2:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x2)
|
||||
: machine_state->keyboard & ~(1 << 0x2);
|
||||
break;
|
||||
case SDL_SCANCODE_3:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x3)
|
||||
: machine_state->keyboard & ~(1 << 0x3);
|
||||
break;
|
||||
case SDL_SCANCODE_4:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0xC)
|
||||
: machine_state->keyboard & ~(1 << 0xC);
|
||||
break;
|
||||
case SDL_SCANCODE_Q:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x4)
|
||||
: machine_state->keyboard & ~(1 << 0x4);
|
||||
break;
|
||||
case SDL_SCANCODE_W:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x5)
|
||||
: machine_state->keyboard & ~(1 << 0x5);
|
||||
break;
|
||||
case SDL_SCANCODE_E:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x6)
|
||||
: machine_state->keyboard & ~(1 << 0x6);
|
||||
break;
|
||||
case SDL_SCANCODE_R:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0xD)
|
||||
: machine_state->keyboard & ~(1 << 0xD);
|
||||
break;
|
||||
case SDL_SCANCODE_A:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x7)
|
||||
: machine_state->keyboard & ~(1 << 0x7);
|
||||
break;
|
||||
case SDL_SCANCODE_S:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x8)
|
||||
: machine_state->keyboard & ~(1 << 0x8);
|
||||
break;
|
||||
case SDL_SCANCODE_D:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x9)
|
||||
: machine_state->keyboard & ~(1 << 0x9);
|
||||
break;
|
||||
case SDL_SCANCODE_F:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0xE)
|
||||
: machine_state->keyboard & ~(1 << 0xE);
|
||||
break;
|
||||
case SDL_SCANCODE_Z:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0xA)
|
||||
: machine_state->keyboard & ~(1 << 0xA);
|
||||
break;
|
||||
case SDL_SCANCODE_X:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0x0)
|
||||
: machine_state->keyboard & ~(1 << 0x0);
|
||||
break;
|
||||
case SDL_SCANCODE_C:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0xB)
|
||||
: machine_state->keyboard & ~(1 << 0xB);
|
||||
break;
|
||||
case SDL_SCANCODE_V:
|
||||
machine_state->keyboard = pressed
|
||||
? machine_state->keyboard | (1 << 0xF)
|
||||
: machine_state->keyboard & ~(1 << 0xF);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ void RegisterView::render()
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
|
||||
ImGui::Text("Keyboard: 0b%016B", this->machine_state->keyboard);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user