summaryrefslogtreecommitdiff
path: root/callbacks.c
diff options
context:
space:
mode:
authorPeter Fors <peter.fors@mindkiller.com>2025-04-06 12:27:12 +0200
committerPeter Fors <peter.fors@mindkiller.com>2025-04-06 12:27:12 +0200
commit39715ca6bf65d2e2dd889cdef4b39d584464d9e7 (patch)
tree39390f6fadd0ddbe913ae66e11847b8b3e7b16bb /callbacks.c
parentdabd7a5848e6aa55e91cf4c804f6236b4f7fe30e (diff)
added more mappers (buggy)
Diffstat (limited to 'callbacks.c')
-rw-r--r--callbacks.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/callbacks.c b/callbacks.c
index 806fe86..a610a43 100644
--- a/callbacks.c
+++ b/callbacks.c
@@ -43,6 +43,7 @@ static void toggle_fullscreen(bool enable) {
}
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
+ struct nes_state *nes_state = (struct nes_state*)glfwGetWindowUserPointer(window);
if(key == GLFW_KEY_ESCAPE) {
if(action == GLFW_PRESS) {
@@ -50,6 +51,30 @@ static void key_callback(GLFWwindow *window, int key, int scancode, int action,
}
}
+ if(action == GLFW_PRESS) {
+ switch(key) {
+ case GLFW_KEY_X: nes_state->input[0] |= (1 << 0); break; // A
+ case GLFW_KEY_Z: nes_state->input[0] |= (1 << 1); break; // B
+ case GLFW_KEY_SPACE: nes_state->input[0] |= (1 << 2); break; // Select
+ case GLFW_KEY_ENTER: nes_state->input[0] |= (1 << 3); break; // Start
+ case GLFW_KEY_UP: nes_state->input[0] |= (1 << 4); break;
+ case GLFW_KEY_DOWN: nes_state->input[0] |= (1 << 5); break;
+ case GLFW_KEY_LEFT: nes_state->input[0] |= (1 << 6); break;
+ case GLFW_KEY_RIGHT: nes_state->input[0] |= (1 << 7); break;
+ }
+ } else if(action == GLFW_RELEASE) {
+ switch(key) {
+ case GLFW_KEY_X: nes_state->input[0] &= ~(1 << 0); break;
+ case GLFW_KEY_Z: nes_state->input[0] &= ~(1 << 1); break;
+ case GLFW_KEY_SPACE: nes_state->input[0] &= ~(1 << 2); break;
+ case GLFW_KEY_ENTER: nes_state->input[0] &= ~(1 << 3); break;
+ case GLFW_KEY_UP: nes_state->input[0] &= ~(1 << 4); break;
+ case GLFW_KEY_DOWN: nes_state->input[0] &= ~(1 << 5); break;
+ case GLFW_KEY_LEFT: nes_state->input[0] &= ~(1 << 6); break;
+ case GLFW_KEY_RIGHT: nes_state->input[0] &= ~(1 << 7); break;
+ }
+ }
+
if(action == GLFW_RELEASE) {
switch(key) {
case GLFW_KEY_F12: {