diff --git a/src/VirtualKeyboard.c b/src/VirtualKeyboard.c index 45c8200..93ce6d8 100644 --- a/src/VirtualKeyboard.c +++ b/src/VirtualKeyboard.c @@ -175,13 +175,14 @@ struct virtkey *get_key_internal() int key_h = 64/RATIO; int border_x = VirtualKeyboard.sel_x/RATIO; int border_y = VirtualKeyboard.sel_y/RATIO; + int joy_n=0; draw_vk(); SDL_Flip(VirtualKeyboard.screen); SDL_ShowCursor(SDL_ENABLE); - k = menu_wait_key_press(); + k = menu_wait_key_press(&joy_n); SDL_ShowCursor(SDL_DISABLE); @@ -198,15 +199,15 @@ struct virtkey *get_key_internal() i = y/key_h*KEY_COLS + x/key_w; #ifdef HW_RVL - if (ordenador.vk_rumble) WPAD_Rumble(0, 1); + if (ordenador.vk_rumble) WPAD_Rumble(joy_n, 1); SDL_Delay(90); - if (ordenador.vk_rumble) WPAD_Rumble(0, 0); + if (ordenador.vk_rumble) WPAD_Rumble(joy_n, 0); #endif #ifdef HW_DOL - if (ordenador.vk_rumble) PAD_ControlMotor(0,PAD_MOTOR_RUMBLE); + if (ordenador.vk_rumble) PAD_ControlMotor(joy_n,PAD_MOTOR_RUMBLE); SDL_Delay(90); - if (ordenador.vk_rumble) PAD_ControlMotor(0,PAD_MOTOR_STOP); + if (ordenador.vk_rumble) PAD_ControlMotor(joy_n,PAD_MOTOR_STOP); #endif virtkey_t *key = &keys[i]; @@ -248,47 +249,52 @@ void virtkey_ir_run(void) int border_x = VirtualKeyboard.sel_x/RATIO; int border_y = VirtualKeyboard.sel_y/RATIO; int key_sel = 0; + int joy_n; SDL_Joystick *joy; - static int joy_bottons_last[5]; - static char countdown_rumble=0; + static int joy_bottons_last[2][5]; + static char countdown_rumble[2]; + + for(joy_n=0;joy_n 0) {countdown_rumble--; if ((countdown_rumble==0)&&(ordenador.vk_rumble)) WPAD_Rumble(0, 0);} + if (countdown_rumble[joy_n] > 0) {countdown_rumble[joy_n]--; if ((countdown_rumble[joy_n]==0)&&(ordenador.vk_rumble)) WPAD_Rumble(joy_n, 0);} #endif #ifdef HW_DOL - if (countdown_rumble > 0) {countdown_rumble--; if ((countdown_rumble==0)&&(ordenador.vk_rumble)) PAD_ControlMotor(0,PAD_MOTOR_STOP);} + if (countdown_rumble[joy_n] > 0) {countdown_rumble[joy_n]--; if ((countdown_rumble[joy_n]==0)&&(ordenador.vk_rumble)) PAD_ControlMotor(joy_n,PAD_MOTOR_STOP);} #endif - joy = ordenador.joystick_sdl[0]; + joy = ordenador.joystick_sdl[joy_n]; - if ((SDL_JoystickGetButton(joy, 0) && !joy_bottons_last[0]) || /* A */ - (SDL_JoystickGetButton(joy, 3) && !joy_bottons_last[1]) || /* 2 */ - (SDL_JoystickGetButton(joy, 9) && !joy_bottons_last[2]) || /* CA */ - (SDL_JoystickGetButton(joy, 10) && !joy_bottons_last[3]) /* CB */ + if ((SDL_JoystickGetButton(joy, 0) && !joy_bottons_last[joy_n][0]) || /* A */ + (SDL_JoystickGetButton(joy, 3) && !joy_bottons_last[joy_n][1]) || /* 2 */ + (SDL_JoystickGetButton(joy, 9) && !joy_bottons_last[joy_n][2]) || /* CA */ + (SDL_JoystickGetButton(joy, 10) && !joy_bottons_last[joy_n][3]) /* CB */ #ifndef GEKKO //Win - ||((SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))&& !joy_bottons_last[4])//mouse left button + ||(!joy_n && (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))&& !joy_bottons_last[0][4])//mouse left button #endif ) key_sel = KEY_SELECT; - if ((!SDL_JoystickGetButton(joy, 0) && joy_bottons_last[0]) || /* A */ - (!SDL_JoystickGetButton(joy, 3) && joy_bottons_last[1]) || /* 2 */ - (!SDL_JoystickGetButton(joy, 9) && joy_bottons_last[2]) || /* CA */ - (!SDL_JoystickGetButton(joy, 10) && joy_bottons_last[3]) /* CB */ + if ((!SDL_JoystickGetButton(joy, 0) && joy_bottons_last[joy_n][0]) || /* A */ + (!SDL_JoystickGetButton(joy, 3) && joy_bottons_last[joy_n][1]) || /* 2 */ + (!SDL_JoystickGetButton(joy, 9) && joy_bottons_last[joy_n][2]) || /* CA */ + (!SDL_JoystickGetButton(joy, 10) && joy_bottons_last[joy_n][3]) /* CB */ #ifndef GEKKO //Win - ||(!(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) && joy_bottons_last[4]) //mouse left button + ||(!joy_n && !(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)) && joy_bottons_last[0][4]) //mouse left button #endif ) key_sel = KEY_DESELECT; - joy_bottons_last[0]=SDL_JoystickGetButton(joy, 0) ; /* A */ - joy_bottons_last[1] =SDL_JoystickGetButton(joy, 3) ; /* 2 */ - joy_bottons_last[2] =SDL_JoystickGetButton(joy, 9) ; /* CA */ - joy_bottons_last[3] =SDL_JoystickGetButton(joy, 10) ; /* CB */ + joy_bottons_last[joy_n][0] =SDL_JoystickGetButton(joy, 0) ; /* A */ + joy_bottons_last[joy_n][1] =SDL_JoystickGetButton(joy, 3) ; /* 2 */ + joy_bottons_last[joy_n][2] =SDL_JoystickGetButton(joy, 9) ; /* CA */ + joy_bottons_last[joy_n][3] =SDL_JoystickGetButton(joy, 10) ; /* CB */ #ifndef GEKKO //Win - joy_bottons_last[4] =SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1); //mouse left button + if (!joy_n) joy_bottons_last[0][4] =SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1); //mouse left button #endif if (key_sel==KEY_SELECT) @@ -299,14 +305,14 @@ void virtkey_ir_run(void) if ((x>0)&&(x< KEY_COLS*key_w)&&(y>0)&&(y< KEY_ROWS*key_h)) { #ifdef HW_RVL - if (ordenador.vk_rumble) WPAD_Rumble(0, 1); + if (ordenador.vk_rumble) WPAD_Rumble(joy_n, 1); #endif #ifdef HW_DOL - if (ordenador.vk_rumble) PAD_ControlMotor(0,PAD_MOTOR_RUMBLE); + if (ordenador.vk_rumble) PAD_ControlMotor(joy_n,PAD_MOTOR_RUMBLE); #endif - countdown_rumble=5; + countdown_rumble[joy_n]=5; i = y/key_h*KEY_COLS + x/key_w; @@ -356,6 +362,7 @@ void virtkey_ir_run(void) key_code=0; } + } } void virtkey_ir_activate(void) diff --git a/src/computer.c b/src/computer.c index 4dc0011..869d19e 100644 --- a/src/computer.c +++ b/src/computer.c @@ -1184,7 +1184,8 @@ inline void paint_one_pixel(unsigned char *colour,unsigned char *address ) { inline void pause() { unsigned int temporal_io; SDL_Event evento,*pevento; - unsigned char minus_pressed=2; + unsigned char minus_pressed[2]={2,2}; + int joy_n; pevento=&evento; printf("Pause\n"); @@ -1193,19 +1194,21 @@ inline void pause() { { SDL_JoystickUpdate(); + for(joy_n=0;joy_n 16384) SDL_PrivateMouseMotion(0,1,4/RATIO,0); //C-stick Horizontal axix - if (SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 2) < -16384) SDL_PrivateMouseMotion(0,1,-4/RATIO,0); //C-stick Horizontal axix - if (SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 3) > 16384) SDL_PrivateMouseMotion(0,1,0,4/RATIO); //C-stick vertical axix - if (SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 3) < -16384) SDL_PrivateMouseMotion(0,1,0,-4/RATIO); //C-stick vertical axix + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[joy_n], 2) > 16384) SDL_PrivateMouseMotion(0,1,4/RATIO,0); //C-stick Horizontal axix + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[joy_n], 2) < -16384) SDL_PrivateMouseMotion(0,1,-4/RATIO,0); //C-stick Horizontal axix + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[joy_n], 3) > 16384) SDL_PrivateMouseMotion(0,1,0,4/RATIO); //C-stick vertical axix + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[joy_n], 3) < -16384) SDL_PrivateMouseMotion(0,1,0,-4/RATIO); //C-stick vertical axix } #endif - for(joy_n=0;joy_nir.valid)&&(!ordenador.vk_is_active)) virtkey_ir_activate(); - if ((!wd->ir.valid)&&(ordenador.vk_is_active)) virtkey_ir_deactivate(); - #else //WH_DOL - Win + WPADData *wd0, *wd1; + wd0 = WPAD_Data(0); //wiimote 0 + wd1 = WPAD_Data(1); //wiimote 1 + if (((wd0->ir.valid)||(wd1->ir.valid))&&(!ordenador.vk_is_active)) virtkey_ir_activate(); + if ((!wd0->ir.valid)&&(!wd1->ir.valid)&&(ordenador.vk_is_active)) virtkey_ir_deactivate(); + #else //Win int x=0,y=0 ; SDL_GetMouseState(&x,&y); if ((x>64/RATIO)&&(x<576/RATIO)&&(y>90/RATIO)&&(y<390/RATIO)) @@ -1807,7 +1817,6 @@ inline void read_keyboard () { } #endif } - old_plus_button = plus_button; if (ordenador.vk_is_active) virtkey_ir_run(); diff --git a/src/emulator.c b/src/emulator.c index 3334d03..4588133 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -559,6 +559,7 @@ if (sound_type==SOUND_SDL) if(SDL_NumJoysticks()>0){ // Open joystick ordenador.joystick_number = SDL_NumJoysticks(); + printf("Found %d joysticks \n", ordenador.joystick_number); if (ordenador.joystick_number>2) ordenador.joystick_number = 2; //Open max 2 joysticks printf("Try to open %d joysticks \n", ordenador.joystick_number); for (bucle=0;bucleformat, 0, 0, 0)); @@ -1709,7 +1709,7 @@ int parse_poke (const char *filename) k=0; while (!(k & KEY_ESCAPE)&&(ritorno==0)) - {k = menu_wait_key_press();} + {k = menu_wait_key_press(NULL);} play_click(2); fclose(fpoke); diff --git a/src/menu_sdl.c b/src/menu_sdl.c index bb7377c..0f88148 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -156,7 +156,7 @@ int msgInfo(char *text, int duration, SDL_Rect *irc) SDL_FillRect(real_screen, &brc, SDL_MapRGB(real_screen->format, 0x00, 0x80, 0x00)); menu_print_font(real_screen, 0,0,0, FULL_DISPLAY_X/2-w, Y+h*2, "OK",FONT_NORM,64); SDL_UpdateRect(real_screen, brc.x, brc.y, brc.w, brc.h); - while (!(KEY_SELECT & menu_wait_key_press())) {} + while (!(KEY_SELECT & menu_wait_key_press(NULL))) {} } @@ -232,7 +232,7 @@ int msgYesNo(char *text, int default_opt, int x, int y) SDL_UpdateRect(real_screen, brc.x, brc.y, brc.w,brc.h); //SDL_Flip(real_screen); - key = menu_wait_key_press(); + key = menu_wait_key_press(NULL); if (key & KEY_SELECT) { play_click(1); @@ -1145,7 +1145,7 @@ static void menu_fini(menu_t *p_menu) free(p_menu->p_submenus); } -uint32_t menu_wait_key_press() +uint32_t menu_wait_key_press(int *joy_n_p) { SDL_Event ev; uint32_t keys = 0; @@ -1157,18 +1157,8 @@ uint32_t menu_wait_key_press() static int joy_keys_changed; static int joy_keys_last; static int joy_bottons_last[2][8]; - SDL_JoystickUpdate(); - #if defined(HW_RVL) || defined(HW_DOL) - if (!ordenador.vk_auto) - { - int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y); - if (SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 2) > 16384) SDL_PrivateMouseMotion(0,1,4/RATIO,0); //C-stick Horizontal axix - if (SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 2) < -16384) SDL_PrivateMouseMotion(0,1,-4/RATIO,0); //C-stick Horizontal axix - if (SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 3) > 16384) SDL_PrivateMouseMotion(0,1,0,4/RATIO); //C-stick vertical axix - if (SDL_JoystickGetAxis(ordenador.joystick_sdl[0], 3) < -16384) SDL_PrivateMouseMotion(0,1,0,-4/RATIO); //C-stick vertical axix - } - #endif + SDL_JoystickUpdate(); /* Wii-specific, sorry */ for (nr = 0; nr < ordenador.joystick_number; nr++) { @@ -1176,6 +1166,16 @@ uint32_t menu_wait_key_press() if (!joy) continue; + #if defined(HW_RVL) || defined(HW_DOL) + if (!ordenador.vk_auto) + { + int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y); + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[nr], 2) > 16384) SDL_PrivateMouseMotion(0,1,4/RATIO,0); //C-stick Horizontal axix + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[nr], 2) < -16384) SDL_PrivateMouseMotion(0,1,-4/RATIO,0); //C-stick Horizontal axix + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[nr], 3) > 16384) SDL_PrivateMouseMotion(0,1,0,4/RATIO); //C-stick vertical axix + if (SDL_JoystickGetAxis(ordenador.joystick_sdl[nr], 3) < -16384) SDL_PrivateMouseMotion(0,1,0,-4/RATIO); //C-stick vertical axix + } + #endif hats = SDL_JoystickNumHats (joy); for (i = 0; i < hats; i++) { Uint8 v = SDL_JoystickGetHat (joy, i); @@ -1225,9 +1225,16 @@ uint32_t menu_wait_key_press() joy_bottons_last[nr][5] =SDL_JoystickGetButton(joy, 11) ; /* CX */ joy_bottons_last[nr][6] =SDL_JoystickGetButton(joy, 12) ; /* CY */ joy_bottons_last[nr][7] =SDL_JoystickGetButton(joy, 1) ; /* B */ - } joy_keys_changed = keys != joy_keys_last; + + if (joy_keys_changed&&keys) + { + if (joy_n_p) *joy_n_p = nr; + break; + } + } + joy_keys_last = keys; if (!joy_keys_changed) keys = 0; @@ -1333,7 +1340,7 @@ static int menu_select_internal(SDL_Surface *screen, menu_draw(screen, p_menu, 0, font_type, draw_scr); SDL_Flip(screen); - keys = menu_wait_key_press(); + keys = menu_wait_key_press(NULL); quit_thread = 1; diff --git a/src/menu_sdl.h b/src/menu_sdl.h index 5d74000..76a5b7c 100644 --- a/src/menu_sdl.h +++ b/src/menu_sdl.h @@ -58,7 +58,7 @@ const char *menu_select_file(char *dir_path,const char *selected_file, int draw_ const char *menu_select_browser(unsigned int tape_pos); const char *menu_select_browser_rzx(); -uint32_t menu_wait_key_press(); +uint32_t menu_wait_key_press(int *joy_n_p); void msgKill(SDL_Rect *rc); int msgInfo(char *text, int duration, SDL_Rect *rc);