memset(mouse_status, 0, sizeof(mouse_status));
// initialize joysticks
-#if 0
- joy_num = joyGetNumDevs();
- for(int i = 0; i < joy_num && i < 2; i++) {
- JOYCAPS joycaps;
- if(joyGetDevCaps(i, &joycaps, sizeof(joycaps)) == JOYERR_NOERROR) {
- joy_mask[i] = (1 << joycaps.wNumButtons) - 1;
- } else {
- joy_mask[i] = 0x0f; // 4buttons
- }
- }
-#else
- joy_num = 0;
-#endif
// mouse emulation is disenabled
mouse_enabled = false;
+ joy_num = SDL_NumJoysticks();
+ for(int i = 0; i < joy_num && i < 2; i++) {
+ //SDL_Joystick *joycaps = SDL_JoystickOpen(i);
+ //if(joycaps != NULL) {
+ // joy_mask[i] = (1 << SDL_JoystickNumButtons(joycaps)) - 1;
+ // SDL_JoystickClose(joycaps);
+ //} else {
+ joy_mask[i] = 0x0f; // 4buttons
+ //}
+
+ }
+
// initialize keycode convert table
FILEIO* fio = new FILEIO();
#endif
}
+
void EMU::update_input()
{
}
}
lost_focus = false;
-#if 0
+#if 1
// update joystick status
- memset(joy_status, 0, sizeof(joy_status));
- for(int i = 0; i < joy_num && i < 2; i++) {
- JOYINFOEX joyinfo;
- joyinfo.dwSize = sizeof(JOYINFOEX);
- joyinfo.dwFlags = JOY_RETURNALL;
- if(joyGetPosEx(i, &joyinfo) == JOYERR_NOERROR) {
- if(joyinfo.dwYpos < 0x3fff) joy_status[i] |= 0x01; // up
- if(joyinfo.dwYpos > 0xbfff) joy_status[i] |= 0x02; // down
- if(joyinfo.dwXpos < 0x3fff) joy_status[i] |= 0x04; // left
- if(joyinfo.dwXpos > 0xbfff) joy_status[i] |= 0x08; // right
- joy_status[i] |= ((joyinfo.dwButtons & joy_mask[i]) << 4);
- }
- }
#ifdef USE_KEY_TO_JOY
// emulate joystick #1 with keyboard
if(key_status[0x26]) joy_status[0] |= 0x01; // up
#include "qt_main.h"\r
#include "agar_logger.h"\r
\r
-#include <SDL/SDL.h>\r
+//#include <SDL/SDL.h>\r
//#include <agar/dev.h>\r
\r
\r
\r
const int screen_mode_width[] = {320, 320, 640, 640, 800, 1024, 1280, 1280, 1440, 1440, 1600, 1600, 1920, 1920, 0};\r
const int screen_mode_height[] = {200, 240, 400, 480, 600, 768, 800, 960, 900, 1080, 1000, 1200, 1080, 1400, 0};\r
-bool bRunJoyThread = false;\r
\r
// timing control\r
#define MAX_SKIP_FRAMES 10\r
} while(1);\r
}\r
\r
-void JoyThreadClass::run()\r
+\r
+bool EventSDL(SDL_Event *eventQueue)\r
{\r
- bRunJoyThread = TRUE;\r
+// SDL_Surface *p;\r
+ Sint16 value;\r
+ uint32_t *joy_status;\r
+ uint8_t button;\r
+ int i;\r
+ if(eventQueue == NULL) return;\r
+ /*\r
+ * JoyStickなどはSDLが管理する\r
+ */\r
+// AG_SDL_GetNextEvent(void *obj, AG_DriverEvent *dev)\r
+ if(emu == NULL) return false;\r
+ if(SDL_WasInit(SDL_INIT_JOYSTICK) != 0) {\r
+// while (SDL_PollEvent(eventQueue))\r
+// {\r
+ switch (eventQueue->type){\r
+ case SDL_JOYAXISMOTION:\r
+ value = eventQueue->jaxis.value;\r
+ i = eventQueue->jaxis.which;\r
+ if((i < 0) || (i > 1)) break;\r
+\r
+ emu->LockVM();\r
+ joy_status = emu->getJoyStatPtr();\r
+ if(eventQueue->jaxis.axis == 0) { // X\r
+ if(value < -8192) {joy_status[i] |= 0x04; joy_status[i] &= 0xfffffff7;} // left\r
+ if(value > 8192) {joy_status[i] |= 0x08; joy_status[i] &= 0xfffffffb;} // right\r
+ } else if(eventQueue->jaxis.axis == 1) { // Y\r
+ if(value < -8192) {joy_status[i] |= 0x01; joy_status[i] &= 0xfffffffd;}// up\r
+ if(value > 8192) {joy_status[i] |= 0x02; joy_status[i] &= 0xfffffffe;}// down;\r
+ }\r
+ emu->UnlockVM();\r
+ break;\r
+ case SDL_JOYBUTTONDOWN:\r
+ button = eventQueue->jbutton.button;\r
+ i = eventQueue->jbutton.which;\r
+ if((i < 0) || (i > 1)) break;\r
+ emu->LockVM();\r
+ joy_status = emu->getJoyStatPtr();\r
+ joy_status[i] |= (1 << (button + 4));\r
+ emu->UnlockVM();\r
+ break;\r
+ case SDL_JOYBUTTONUP:\r
+ button = eventQueue->jbutton.button;\r
+ i = eventQueue->jbutton.which;\r
+ if((i < 0) || (i > 1)) break;\r
+ emu->LockVM();\r
+ joy_status = emu->getJoyStatPtr();\r
+ joy_status[i] &= ~(1 << (button + 4));\r
+ emu->UnlockVM();\r
+ break;\r
+ default: // Is right Ignoring?\r
+ break;\r
+ }\r
+ }\r
+// }\r
+ return TRUE;\r
+}\r
+\r
+\r
+\r
+//void JoyThreadClass::run()\r
+void JoyThread(void *p)\r
+{\r
+ int joy_num;\r
+ int i;\r
+ SDL_Joystick *joyhandle[2] = {NULL, NULL};\r
+ SDL_Event event;\r
+ for(i = 0; i < 2; i++) joyhandle[i] = SDL_JoystickOpen(i);\r
+ joy_num = SDL_NumJoysticks();\r
+ uint32 *joy_status = NULL;\r
do {\r
-// rMainWindow->getGraphicsView()->updateGL();\r
- // Event Handling for joystick\r
- SDL_Delay(10); // Right?\r
+ if(rMainWindow->GetJoyThreadEnabled() != true) {\r
+ for(i = 0; i < 2; i++) {\r
+ if(joyhandle[i] != NULL) SDL_JoystickClose(joyhandle[i]);\r
+ }\r
+ //exit(0);\r
+ return;\r
+ }\r
+ if(SDL_WaitEventTimeout(&event, 10) == 1) EventSDL(&event);\r
} while(1);\r
}\r
+ \r
\r
//EmuThreadClass *hEmuThread;\r
-JoyThreadClass *pJoyThread;\r
+//JoyThreadClass *pJoyThread;\r
//QThread *hEmuThread;\r
-QThread *hJoyThread;\r
+//QThread *hJoyThread;\r
\r
// Important Flags\r
AGAR_CPUID *pCpuID;\r
}\r
}\r
#endif\r
+ StopJoyThread();\r
StopEmuThread();\r
-\r
- bRunJoyThread = false;\r
- if(hJoyThread != NULL) {\r
- hJoyThread->terminate();\r
-// do {\r
- SDL_Delay(50);\r
-// if(hJoyThread->finished()) break;\r
-// } while(1);\r
- delete hJoyThread;\r
- hJoyThread = NULL;\r
- }\r
+ \r
// release emulation core\r
if(emu) {\r
SDL_Delay(50);\r
#endif\r
\r
\r
-BOOL EventSDL(void)\r
-{\r
-// SDL_Surface *p;\r
- SDL_Event eventQueue;\r
-\r
- /*\r
- * JoyStickなどはSDLが管理する\r
- */\r
-// AG_SDL_GetNextEvent(void *obj, AG_DriverEvent *dev)\r
\r
- if(SDL_WasInit(SDL_INIT_JOYSTICK) != 0) {\r
- while (SDL_PollEvent(&eventQueue))\r
- {\r
- switch (eventQueue.type)\r
- {\r
- case SDL_JOYAXISMOTION: /* JS */\r
- //OnMoveJoy(&eventQueue);\r
- break;\r
- case SDL_JOYBUTTONDOWN:\r
- //OnPressJoy(&eventQueue);\r
- break;\r
- case SDL_JOYBUTTONUP:\r
- //OnReleaseJoy(&eventQueue);\r
- break;\r
- default: // Is right Ignoring?\r
- // ConvertSDLEvent(drv, &eventQueue, &event);\r
- // if(!EventGuiSingle(drv, &event)) return FALSE;\r
- break;\r
- }\r
- }\r
- }\r
- return TRUE;\r
-}\r
\r
int MainLoop(int argc, char *argv[])\r
{\r
// Launch Emulator loop\r
#if 1\r
rMainWindow->LaunchEmuThread(EmuThread);\r
+ rMainWindow->LaunchJoyThread(JoyThread);\r
//hEmuThread = new QThread();\r
//pEmuThread->property("Emu Thread");\r
//pEmuThread->moveToThread(hEmuThread);\r
// rMainWindow->getGraphicsView(), rMainWindow->getGraphicsView()->update_screenChanged(int));\r
//hEmuThread->start();\r
// Launch JoystickClass\r
- bRunJoyThread = false;\r
+// bRunJoyThread = false;\r
//pJoyThread = new JoyThreadClass();\r
//hJoyThread = new QThread();\r
//hJoyThread->property("SDL Joy Thread");\r