]> Shamusworld >> Repos - virtualjaguar/commitdiff
Preliminary key handling using Qt key types.
authorShamus Hammons <jlhamm@acm.org>
Thu, 23 Jun 2011 00:38:01 +0000 (00:38 +0000)
committerShamus Hammons <jlhamm@acm.org>
Thu, 23 Jun 2011 00:38:01 +0000 (00:38 +0000)
src/gui/mainwin.cpp
src/gui/mainwin.h
src/joystick.cpp
src/joystick.h

index c0f215ee865dde2e77a85284c233851ccace9b73..30c3b2a37c1a18b44ad7604eebfdf2576999b48e 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "mainwin.h"
 
+#include "SDL.h"
 //#include <QtGui>
 //#include <QtOpenGL>
 #include "glwidget.h"
@@ -37,6 +38,7 @@
 #include "tom.h"
 #include "log.h"
 #include "file.h"
+#include "joystick.h"
 
 // Uncomment this to use built-in BIOS/CD-ROM BIOS
 // You'll need a copy of jagboot.h & jagcd.h for this to work...!
@@ -247,6 +249,66 @@ void MainWin::closeEvent(QCloseEvent * event)
        event->accept(); // ignore() if can't close for some reason
 }
 
+void MainWin::keyPressEvent(QKeyEvent * e)
+{
+       // NOTE: Keys are hardwired...
+/*
+       vjs.p1KeyBindings[0] = settings.value("p1k_up", SDLK_UP).toInt();
+       vjs.p1KeyBindings[1] = settings.value("p1k_down", SDLK_DOWN).toInt();
+       vjs.p1KeyBindings[2] = settings.value("p1k_left", SDLK_LEFT).toInt();
+       vjs.p1KeyBindings[3] = settings.value("p1k_right", SDLK_RIGHT).toInt();
+       vjs.p1KeyBindings[4] = settings.value("p1k_c", SDLK_z).toInt();
+       vjs.p1KeyBindings[5] = settings.value("p1k_b", SDLK_x).toInt();
+       vjs.p1KeyBindings[6] = settings.value("p1k_a", SDLK_c).toInt();
+       vjs.p1KeyBindings[7] = settings.value("p1k_option", SDLK_QUOTE).toInt();
+       vjs.p1KeyBindings[8] = settings.value("p1k_pause", SDLK_RETURN).toInt();
+       vjs.p1KeyBindings[9] = settings.value("p1k_0", SDLK_KP0).toInt();
+       vjs.p1KeyBindings[10] = settings.value("p1k_1", SDLK_KP1).toInt();
+       vjs.p1KeyBindings[11] = settings.value("p1k_2", SDLK_KP2).toInt();
+       vjs.p1KeyBindings[12] = settings.value("p1k_3", SDLK_KP3).toInt();
+       vjs.p1KeyBindings[13] = settings.value("p1k_4", SDLK_KP4).toInt();
+       vjs.p1KeyBindings[14] = settings.value("p1k_5", SDLK_KP5).toInt();
+       vjs.p1KeyBindings[15] = settings.value("p1k_6", SDLK_KP6).toInt();
+       vjs.p1KeyBindings[16] = settings.value("p1k_7", SDLK_KP7).toInt();
+       vjs.p1KeyBindings[17] = settings.value("p1k_8", SDLK_KP8).toInt();
+       vjs.p1KeyBindings[18] = settings.value("p1k_9", SDLK_KP9).toInt();
+       vjs.p1KeyBindings[19] = settings.value("p1k_pound", SDLK_KP_DIVIDE).toInt();
+       vjs.p1KeyBindings[20] = settings.value("p1k_star", SDLK_KP_MULTIPLY).toInt();
+*/
+       if (e->key() == Qt::Key_Up)
+               keyBuffer[0] = true;
+       else if (e->key() == Qt::Key_Down)
+               keyBuffer[1] = true;
+       else if (e->key() == Qt::Key_Left)
+               keyBuffer[2] = true;
+       else if (e->key() == Qt::Key_Right)
+               keyBuffer[3] = true;
+       else if (e->key() == Qt::Key_Z)
+               keyBuffer[4] = true;
+       else if (e->key() == Qt::Key_X)
+               keyBuffer[5] = true;
+       else if (e->key() == Qt::Key_C)
+               keyBuffer[6] = true;
+}
+
+void MainWin::keyReleaseEvent(QKeyEvent * e)
+{
+       if (e->key() == Qt::Key_Up)
+               keyBuffer[0] = false;
+       else if (e->key() == Qt::Key_Down)
+               keyBuffer[1] = false;
+       else if (e->key() == Qt::Key_Left)
+               keyBuffer[2] = false;
+       else if (e->key() == Qt::Key_Right)
+               keyBuffer[3] = false;
+       else if (e->key() == Qt::Key_Z)
+               keyBuffer[4] = false;
+       else if (e->key() == Qt::Key_X)
+               keyBuffer[5] = false;
+       else if (e->key() == Qt::Key_C)
+               keyBuffer[6] = false;
+}
+
 void MainWin::Open(void)
 {
 }
@@ -561,6 +623,51 @@ WriteLog("    jagBootPath = \"%s\"\n", vjs.jagBootPath);
 WriteLog("    CDBootPath  = \"%s\"\n", vjs.CDBootPath);
 WriteLog("    EEPROMPath  = \"%s\"\n", vjs.EEPROMPath);
 WriteLog("    ROMPath     = \"%s\"\n", vjs.ROMPath);
+
+       // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
+       vjs.p1KeyBindings[0] = settings.value("p1k_up", SDLK_UP).toInt();
+       vjs.p1KeyBindings[1] = settings.value("p1k_down", SDLK_DOWN).toInt();
+       vjs.p1KeyBindings[2] = settings.value("p1k_left", SDLK_LEFT).toInt();
+       vjs.p1KeyBindings[3] = settings.value("p1k_right", SDLK_RIGHT).toInt();
+       vjs.p1KeyBindings[4] = settings.value("p1k_c", SDLK_z).toInt();
+       vjs.p1KeyBindings[5] = settings.value("p1k_b", SDLK_x).toInt();
+       vjs.p1KeyBindings[6] = settings.value("p1k_a", SDLK_c).toInt();
+       vjs.p1KeyBindings[7] = settings.value("p1k_option", SDLK_QUOTE).toInt();
+       vjs.p1KeyBindings[8] = settings.value("p1k_pause", SDLK_RETURN).toInt();
+       vjs.p1KeyBindings[9] = settings.value("p1k_0", SDLK_KP0).toInt();
+       vjs.p1KeyBindings[10] = settings.value("p1k_1", SDLK_KP1).toInt();
+       vjs.p1KeyBindings[11] = settings.value("p1k_2", SDLK_KP2).toInt();
+       vjs.p1KeyBindings[12] = settings.value("p1k_3", SDLK_KP3).toInt();
+       vjs.p1KeyBindings[13] = settings.value("p1k_4", SDLK_KP4).toInt();
+       vjs.p1KeyBindings[14] = settings.value("p1k_5", SDLK_KP5).toInt();
+       vjs.p1KeyBindings[15] = settings.value("p1k_6", SDLK_KP6).toInt();
+       vjs.p1KeyBindings[16] = settings.value("p1k_7", SDLK_KP7).toInt();
+       vjs.p1KeyBindings[17] = settings.value("p1k_8", SDLK_KP8).toInt();
+       vjs.p1KeyBindings[18] = settings.value("p1k_9", SDLK_KP9).toInt();
+       vjs.p1KeyBindings[19] = settings.value("p1k_pound", SDLK_KP_DIVIDE).toInt();
+       vjs.p1KeyBindings[20] = settings.value("p1k_star", SDLK_KP_MULTIPLY).toInt();
+
+       vjs.p2KeyBindings[0] = settings.value("p2k_up", SDLK_UP).toInt();
+       vjs.p2KeyBindings[1] = settings.value("p2k_down", SDLK_DOWN).toInt();
+       vjs.p2KeyBindings[2] = settings.value("p2k_left", SDLK_LEFT).toInt();
+       vjs.p2KeyBindings[3] = settings.value("p2k_right", SDLK_RIGHT).toInt();
+       vjs.p2KeyBindings[4] = settings.value("p2k_c", SDLK_z).toInt();
+       vjs.p2KeyBindings[5] = settings.value("p2k_b", SDLK_x).toInt();
+       vjs.p2KeyBindings[6] = settings.value("p2k_a", SDLK_c).toInt();
+       vjs.p2KeyBindings[7] = settings.value("p2k_option", SDLK_QUOTE).toInt();
+       vjs.p2KeyBindings[8] = settings.value("p2k_pause", SDLK_RETURN).toInt();
+       vjs.p2KeyBindings[9] = settings.value("p2k_0", SDLK_KP0).toInt();
+       vjs.p2KeyBindings[10] = settings.value("p2k_1", SDLK_KP1).toInt();
+       vjs.p2KeyBindings[11] = settings.value("p2k_2", SDLK_KP2).toInt();
+       vjs.p2KeyBindings[12] = settings.value("p2k_3", SDLK_KP3).toInt();
+       vjs.p2KeyBindings[13] = settings.value("p2k_4", SDLK_KP4).toInt();
+       vjs.p2KeyBindings[14] = settings.value("p2k_5", SDLK_KP5).toInt();
+       vjs.p2KeyBindings[15] = settings.value("p2k_6", SDLK_KP6).toInt();
+       vjs.p2KeyBindings[16] = settings.value("p2k_7", SDLK_KP7).toInt();
+       vjs.p2KeyBindings[17] = settings.value("p2k_8", SDLK_KP8).toInt();
+       vjs.p2KeyBindings[18] = settings.value("p2k_9", SDLK_KP9).toInt();
+       vjs.p2KeyBindings[19] = settings.value("p2k_pound", SDLK_KP_DIVIDE).toInt();
+       vjs.p2KeyBindings[20] = settings.value("p2k_star", SDLK_KP_MULTIPLY).toInt();
 }
 
 void MainWin::WriteSettings(void)
@@ -586,6 +693,50 @@ void MainWin::WriteSettings(void)
        settings.setValue("CDBootROM", vjs.CDBootPath);
        settings.setValue("EEPROMs", vjs.EEPROMPath);
        settings.setValue("ROMs", vjs.ROMPath);
+
+       settings.setValue("p1k_up", vjs.p1KeyBindings[0]);
+       settings.setValue("p1k_down", vjs.p1KeyBindings[1]);
+       settings.setValue("p1k_left", vjs.p1KeyBindings[2]);
+       settings.setValue("p1k_right", vjs.p1KeyBindings[3]);
+       settings.setValue("p1k_c", vjs.p1KeyBindings[4]);
+       settings.setValue("p1k_b", vjs.p1KeyBindings[5]);
+       settings.setValue("p1k_a", vjs.p1KeyBindings[6]);
+       settings.setValue("p1k_option", vjs.p1KeyBindings[7]);
+       settings.setValue("p1k_pause", vjs.p1KeyBindings[8]);
+       settings.setValue("p1k_0", vjs.p1KeyBindings[9]);
+       settings.setValue("p1k_1", vjs.p1KeyBindings[10]);
+       settings.setValue("p1k_2", vjs.p1KeyBindings[11]);
+       settings.setValue("p1k_3", vjs.p1KeyBindings[12]);
+       settings.setValue("p1k_4", vjs.p1KeyBindings[13]);
+       settings.setValue("p1k_5", vjs.p1KeyBindings[14]);
+       settings.setValue("p1k_6", vjs.p1KeyBindings[15]);
+       settings.setValue("p1k_7", vjs.p1KeyBindings[16]);
+       settings.setValue("p1k_8", vjs.p1KeyBindings[17]);
+       settings.setValue("p1k_9", vjs.p1KeyBindings[18]);
+       settings.setValue("p1k_pound", vjs.p1KeyBindings[19]);
+       settings.setValue("p1k_star", vjs.p1KeyBindings[20]);
+
+       settings.setValue("p2k_up", vjs.p2KeyBindings[0]);
+       settings.setValue("p2k_down", vjs.p2KeyBindings[1]);
+       settings.setValue("p2k_left", vjs.p2KeyBindings[2]);
+       settings.setValue("p2k_right", vjs.p2KeyBindings[3]);
+       settings.setValue("p2k_c", vjs.p2KeyBindings[4]);
+       settings.setValue("p2k_b", vjs.p2KeyBindings[5]);
+       settings.setValue("p2k_a", vjs.p2KeyBindings[6]);
+       settings.setValue("p2k_option", vjs.p2KeyBindings[7]);
+       settings.setValue("p2k_pause", vjs.p2KeyBindings[8]);
+       settings.setValue("p2k_0", vjs.p2KeyBindings[9]);
+       settings.setValue("p2k_1", vjs.p2KeyBindings[10]);
+       settings.setValue("p2k_2", vjs.p2KeyBindings[11]);
+       settings.setValue("p2k_3", vjs.p2KeyBindings[12]);
+       settings.setValue("p2k_4", vjs.p2KeyBindings[13]);
+       settings.setValue("p2k_5", vjs.p2KeyBindings[14]);
+       settings.setValue("p2k_6", vjs.p2KeyBindings[15]);
+       settings.setValue("p2k_7", vjs.p2KeyBindings[16]);
+       settings.setValue("p2k_8", vjs.p2KeyBindings[17]);
+       settings.setValue("p2k_9", vjs.p2KeyBindings[18]);
+       settings.setValue("p2k_pound", vjs.p2KeyBindings[19]);
+       settings.setValue("p2k_star", vjs.p2KeyBindings[20]);
 }
 
 // Here's how Byuu does it...
index 78a37b9699cd356142c9f7abe71dfe0e94e623b7..e6dfef1c56c07406c9b8fd4250c3b34098ce77bc 100644 (file)
@@ -25,7 +25,9 @@ class MainWin: public QMainWindow
                MainWin();
 
        protected:
-               void closeEvent(QCloseEvent * event);
+               void closeEvent(QCloseEvent *);
+               void keyPressEvent(QKeyEvent *);
+               void keyReleaseEvent(QKeyEvent *);
 
        private slots:
                void Open(void);
index 057d059bf7ef756aa09dd20f68373a4837d99442..2de43cecfabd054952d95b013381141a014acf98 100644 (file)
@@ -52,6 +52,9 @@
 static uint8 joystick_ram[4];
 static uint8 joypad_0_buttons[21];
 static uint8 joypad_1_buttons[21];
+
+bool keyBuffer[21];
+
 //extern bool finished;
 ////extern bool showGUI;
 bool GUIKeyHeld = false;
@@ -95,6 +98,7 @@ void JoystickExec(void)
        // Keybindings in order of U, D, L, R, C, B, A, Op, Pa, 0-9, #, *
 //     vjs.p1KeyBindings[0] = sdlemu_getval_int("p1k_up", SDLK_UP);
 
+#if 0
        if (keystate[vjs.p1KeyBindings[0]])
                joypad_0_buttons[BUTTON_U] = 0x01;
        if (keystate[vjs.p1KeyBindings[1]])
@@ -110,6 +114,23 @@ void JoystickExec(void)
                joypad_0_buttons[BUTTON_B] = 0x01;
        if (keystate[vjs.p1KeyBindings[6]])
                joypad_0_buttons[BUTTON_A] = 0x01;
+#else
+       if (keyBuffer[0])
+               joypad_0_buttons[BUTTON_U] = 0x01;
+       if (keyBuffer[1])
+               joypad_0_buttons[BUTTON_D] = 0x01;
+       if (keyBuffer[2])
+               joypad_0_buttons[BUTTON_L] = 0x01;
+       if (keyBuffer[3])
+               joypad_0_buttons[BUTTON_R] = 0x01;
+       // The buttons are labelled C,B,A on the controller (going from left to right)
+       if (keyBuffer[4])
+               joypad_0_buttons[BUTTON_C] = 0x01;
+       if (keyBuffer[5])
+               joypad_0_buttons[BUTTON_B] = 0x01;
+       if (keyBuffer[6])
+               joypad_0_buttons[BUTTON_A] = 0x01;
+#endif
 //I may yet move these to O and P...
        if (keystate[vjs.p1KeyBindings[7]])
                joypad_0_buttons[BUTTON_OPTION] = 0x01;
index d56c080387668fcdabba62743fd3a85ee0b04b65..e98dcdbc795b6f5af08d2c06a17ab664269529b7 100644 (file)
@@ -16,4 +16,6 @@ uint8 JoystickReadByte(uint32);
 uint16 JoystickReadWord(uint32);
 void JoystickExec(void);
 
+extern bool keyBuffer[];
+
 #endif