diff --git a/core/linux-dist/evdev.cpp b/core/linux-dist/evdev.cpp index e11868959..5a1526ccd 100644 --- a/core/linux-dist/evdev.cpp +++ b/core/linux-dist/evdev.cpp @@ -6,201 +6,216 @@ #if defined(USE_EVDEV) - int input_evdev_init(Controller* controller, const char* device) - { - char name[256] = "Unknown"; + int input_evdev_init(Controller* controller, const char* device) + { + char name[256] = "Unknown"; - printf("evdev: Trying to open device at '%s'\n", device); + printf("evdev: Trying to open device at '%s'\n", device); - int fd = open(device, O_RDONLY); + int fd = open(device, O_RDONLY); - if (fd >= 0) - { - fcntl(fd, F_SETFL, O_NONBLOCK); - if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) - { - perror("evdev: ioctl"); - return -2; - } - else - { - printf("evdev: Found '%s' at '%s'\n", name, device); + if (fd >= 0) + { + fcntl(fd, F_SETFL, O_NONBLOCK); + if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) + { + perror("evdev: ioctl"); + return -2; + } + else + { + printf("evdev: Found '%s' at '%s'\n", name, device); - controller->fd = fd; + controller->fd = fd; - #if defined(TARGET_PANDORA) - *controller.mapping = &controller_mapping_pandora; - #elif defined(TARGET_GCW0) - *controller.mapping = &controller_mapping_gcwz; - #else - if (strcmp(name, "Microsoft X-Box 360 pad") == 0 || - strcmp(name, "Xbox 360 Wireless Receiver") == 0 || - strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0) - { - controller->mapping = &controller_mapping_xpad; - } - else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL) - { - controller->mapping = &controller_mapping_xboxdrv; - } - else if (strstr(name, "keyboard") != NULL || - strstr(name, "Keyboard") != NULL) - { - controller->mapping = &controller_mapping_keyboard; - } - else - { - controller->mapping = &controller_mapping_generic; - } - #endif - printf("evdev: Using '%s' mapping\n", controller->mapping->name); + #if defined(TARGET_PANDORA) + *controller.mapping = &controller_mapping_pandora; + #elif defined(TARGET_GCW0) + *controller.mapping = &controller_mapping_gcwz; + #else + if (strcmp(name, "Microsoft X-Box 360 pad") == 0 || + strcmp(name, "Xbox 360 Wireless Receiver") == 0 || + strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0) + { + controller->mapping = &controller_mapping_xpad; + } + else if (strstr(name, "Xbox Gamepad (userspace driver)") != NULL) + { + controller->mapping = &controller_mapping_xboxdrv; + } + else if (strstr(name, "keyboard") != NULL || + strstr(name, "Keyboard") != NULL) + { + controller->mapping = &controller_mapping_keyboard; + } + else + { + controller->mapping = &controller_mapping_generic; + } + #endif + printf("evdev: Using '%s' mapping\n", controller->mapping->name); - return 0; - } - } - else - { - perror("evdev: open"); - return -1; - } - } + return 0; + } + } + else + { + perror("evdev: open"); + return -1; + } + } - bool input_evdev_handle(Controller* controller, u32 port) - { - #define SET_FLAG(field, mask, expr) field =((expr) ? (field & ~mask) : (field | mask)) - if (controller->fd < 0 || controller->mapping == NULL) - { - return false; - } + bool input_evdev_handle(Controller* controller, u32 port) + { + #define SET_FLAG(field, mask, expr) field =((expr) ? (field & ~mask) : (field | mask)) + if (controller->fd < 0 || controller->mapping == NULL) + { + return false; + } - input_event ie; + input_event ie; - while(read(controller->fd, &ie, sizeof(ie)) == sizeof(ie)) - { - if(ie.type != EV_SYN && ie.type != EV_MSC) - { - printf("type %i key %i state %i\n", ie.type, ie.code, ie.value); - } - switch(ie.type) - { - case EV_KEY: - if (ie.code == controller->mapping->Btn_A) { - SET_FLAG(kcode[port], DC_BTN_A, ie.value); - } else if (ie.code == controller->mapping->Btn_B) { - SET_FLAG(kcode[port], DC_BTN_B, ie.value); - } else if (ie.code == controller->mapping->Btn_C) { - SET_FLAG(kcode[port], DC_BTN_C, ie.value); - } else if (ie.code == controller->mapping->Btn_D) { - SET_FLAG(kcode[port], DC_BTN_D, ie.value); - } else if (ie.code == controller->mapping->Btn_X) { - SET_FLAG(kcode[port], DC_BTN_X, ie.value); - } else if (ie.code == controller->mapping->Btn_Y) { - SET_FLAG(kcode[port], DC_BTN_Y, ie.value); - } else if (ie.code == controller->mapping->Btn_Z) { - SET_FLAG(kcode[port], DC_BTN_Z, ie.value); - } else if (ie.code == controller->mapping->Btn_Start) { - SET_FLAG(kcode[port], DC_BTN_START, ie.value); - } else if (ie.code == controller->mapping->Btn_Escape) { - die("death by escape key"); - } else if (ie.code == controller->mapping->Btn_DPad_Left) { - SET_FLAG(kcode[port], DC_DPAD_LEFT, ie.value); - } else if (ie.code == controller->mapping->Btn_DPad_Right) { - SET_FLAG(kcode[port], DC_DPAD_RIGHT, ie.value); - } else if (ie.code == controller->mapping->Btn_DPad_Up) { - SET_FLAG(kcode[port], DC_DPAD_UP, ie.value); - } else if (ie.code == controller->mapping->Btn_DPad_Down) { - SET_FLAG(kcode[port], DC_DPAD_DOWN, ie.value); - } else if (ie.code == controller->mapping->Btn_DPad2_Left) { - SET_FLAG(kcode[port], DC_DPAD2_LEFT, ie.value); - } else if (ie.code == controller->mapping->Btn_DPad2_Right) { - SET_FLAG(kcode[port], DC_DPAD2_RIGHT, ie.value); - } else if (ie.code == controller->mapping->Btn_DPad2_Up) { - SET_FLAG(kcode[port], DC_DPAD2_UP, ie.value); - } else if (ie.code == controller->mapping->Btn_DPad2_Down) { - SET_FLAG(kcode[port], DC_DPAD2_DOWN, ie.value); - } else if (ie.code == controller->mapping->Btn_Trigger_Left) { - lt[port] = (ie.value ? 255 : 0); - } else if (ie.code == controller->mapping->Btn_Trigger_Right) { - rt[port] = (ie.value ? 255 : 0); - } - break; - case EV_ABS: - if (ie.code == controller->mapping->Axis_DPad_X) { - switch(ie.value) - { - case -1: - SET_FLAG(kcode[port], DC_DPAD_LEFT, 1); - SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0); - break; - case 0: - SET_FLAG(kcode[port], DC_DPAD_LEFT, 0); - SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0); - break; - case 1: - SET_FLAG(kcode[port], DC_DPAD_LEFT, 0); - SET_FLAG(kcode[port], DC_DPAD_RIGHT, 1); - break; - } - } else if (ie.code == controller->mapping->Axis_DPad_Y) { - switch(ie.value) - { - case -1: - SET_FLAG(kcode[port], DC_DPAD_UP, 1); - SET_FLAG(kcode[port], DC_DPAD_DOWN, 0); - break; - case 0: - SET_FLAG(kcode[port], DC_DPAD_UP, 0); - SET_FLAG(kcode[port], DC_DPAD_DOWN, 0); - break; - case 1: - SET_FLAG(kcode[port], DC_DPAD_UP, 0); - SET_FLAG(kcode[port], DC_DPAD_DOWN, 1); - break; - } - } else if (ie.code == controller->mapping->Axis_DPad2_X) { - switch(ie.value) - { - case -1: - SET_FLAG(kcode[port], DC_DPAD2_LEFT, 1); - SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0); - break; - case 0: - SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0); - SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0); - break; - case 1: - SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0); - SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 1); - break; - } - } else if (ie.code == controller->mapping->Axis_DPad2_X) { - switch(ie.value) - { - case -1: - SET_FLAG(kcode[port], DC_DPAD2_UP, 1); - SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0); - break; - case 0: - SET_FLAG(kcode[port], DC_DPAD2_UP, 0); - SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0); - break; - case 1: - SET_FLAG(kcode[port], DC_DPAD2_UP, 0); - SET_FLAG(kcode[port], DC_DPAD2_DOWN, 1); - break; - } - } else if (ie.code == controller->mapping->Axis_Analog_X) { - printf("%d", ie.value); - joyx[port] = (s8)(ie.value/256); - } else if (ie.code == controller->mapping->Axis_Analog_Y) { - joyy[port] = (s8)(ie.value/256); - } else if (ie.code == controller->mapping->Axis_Trigger_Left) { - lt[port] = (s8)ie.value; - } else if (ie.code == controller->mapping->Axis_Trigger_Right) { - rt[port] = (s8)ie.value; - } - break; - } - } - } -#endif \ No newline at end of file + while(read(controller->fd, &ie, sizeof(ie)) == sizeof(ie)) + { + if(ie.type != EV_SYN && ie.type != EV_MSC) + { + printf("type %i key %i state %i\n", ie.type, ie.code, ie.value); + } + switch(ie.type) + { + case EV_KEY: + if (ie.code == controller->mapping->Btn_A) { + SET_FLAG(kcode[port], DC_BTN_A, ie.value); + } else if (ie.code == controller->mapping->Btn_B) { + SET_FLAG(kcode[port], DC_BTN_B, ie.value); + } else if (ie.code == controller->mapping->Btn_C) { + SET_FLAG(kcode[port], DC_BTN_C, ie.value); + } else if (ie.code == controller->mapping->Btn_D) { + SET_FLAG(kcode[port], DC_BTN_D, ie.value); + } else if (ie.code == controller->mapping->Btn_X) { + SET_FLAG(kcode[port], DC_BTN_X, ie.value); + } else if (ie.code == controller->mapping->Btn_Y) { + SET_FLAG(kcode[port], DC_BTN_Y, ie.value); + } else if (ie.code == controller->mapping->Btn_Z) { + SET_FLAG(kcode[port], DC_BTN_Z, ie.value); + } else if (ie.code == controller->mapping->Btn_Start) { + SET_FLAG(kcode[port], DC_BTN_START, ie.value); + } else if (ie.code == controller->mapping->Btn_Escape) { + die("death by escape key"); + } else if (ie.code == controller->mapping->Btn_DPad_Left) { + SET_FLAG(kcode[port], DC_DPAD_LEFT, ie.value); + } else if (ie.code == controller->mapping->Btn_DPad_Right) { + SET_FLAG(kcode[port], DC_DPAD_RIGHT, ie.value); + } else if (ie.code == controller->mapping->Btn_DPad_Up) { + SET_FLAG(kcode[port], DC_DPAD_UP, ie.value); + } else if (ie.code == controller->mapping->Btn_DPad_Down) { + SET_FLAG(kcode[port], DC_DPAD_DOWN, ie.value); + } else if (ie.code == controller->mapping->Btn_DPad2_Left) { + SET_FLAG(kcode[port], DC_DPAD2_LEFT, ie.value); + } else if (ie.code == controller->mapping->Btn_DPad2_Right) { + SET_FLAG(kcode[port], DC_DPAD2_RIGHT, ie.value); + } else if (ie.code == controller->mapping->Btn_DPad2_Up) { + SET_FLAG(kcode[port], DC_DPAD2_UP, ie.value); + } else if (ie.code == controller->mapping->Btn_DPad2_Down) { + SET_FLAG(kcode[port], DC_DPAD2_DOWN, ie.value); + } else if (ie.code == controller->mapping->Btn_Trigger_Left) { + lt[port] = (ie.value ? 255 : 0); + } else if (ie.code == controller->mapping->Btn_Trigger_Right) { + rt[port] = (ie.value ? 255 : 0); + } + break; + case EV_ABS: + if (ie.code == controller->mapping->Axis_DPad_X) + { + switch(ie.value) + { + case -1: + SET_FLAG(kcode[port], DC_DPAD_LEFT, 1); + SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0); + break; + case 0: + SET_FLAG(kcode[port], DC_DPAD_LEFT, 0); + SET_FLAG(kcode[port], DC_DPAD_RIGHT, 0); + break; + case 1: + SET_FLAG(kcode[port], DC_DPAD_LEFT, 0); + SET_FLAG(kcode[port], DC_DPAD_RIGHT, 1); + break; + } + } + else if (ie.code == controller->mapping->Axis_DPad_Y) + { + switch(ie.value) + { + case -1: + SET_FLAG(kcode[port], DC_DPAD_UP, 1); + SET_FLAG(kcode[port], DC_DPAD_DOWN, 0); + break; + case 0: + SET_FLAG(kcode[port], DC_DPAD_UP, 0); + SET_FLAG(kcode[port], DC_DPAD_DOWN, 0); + break; + case 1: + SET_FLAG(kcode[port], DC_DPAD_UP, 0); + SET_FLAG(kcode[port], DC_DPAD_DOWN, 1); + break; + } + } + else if (ie.code == controller->mapping->Axis_DPad2_X) + { + switch(ie.value) + { + case -1: + SET_FLAG(kcode[port], DC_DPAD2_LEFT, 1); + SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0); + break; + case 0: + SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0); + SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 0); + break; + case 1: + SET_FLAG(kcode[port], DC_DPAD2_LEFT, 0); + SET_FLAG(kcode[port], DC_DPAD2_RIGHT, 1); + break; + } + } + else if (ie.code == controller->mapping->Axis_DPad2_X) + { + switch(ie.value) + { + case -1: + SET_FLAG(kcode[port], DC_DPAD2_UP, 1); + SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0); + break; + case 0: + SET_FLAG(kcode[port], DC_DPAD2_UP, 0); + SET_FLAG(kcode[port], DC_DPAD2_DOWN, 0); + break; + case 1: + SET_FLAG(kcode[port], DC_DPAD2_UP, 0); + SET_FLAG(kcode[port], DC_DPAD2_DOWN, 1); + break; + } + } + else if (ie.code == controller->mapping->Axis_Analog_X) + { + printf("%d", ie.value); + joyx[port] = (s8)(ie.value/256); + } + else if (ie.code == controller->mapping->Axis_Analog_Y) + { + joyy[port] = (s8)(ie.value/256); + } + else if (ie.code == controller->mapping->Axis_Trigger_Left) + { + lt[port] = (s8)ie.value; + } + else if (ie.code == controller->mapping->Axis_Trigger_Right) + { + rt[port] = (s8)ie.value; + } + break; + } + } + } +#endif diff --git a/core/linux-dist/evdev.h b/core/linux-dist/evdev.h index 44a34253f..a3fff381d 100644 --- a/core/linux-dist/evdev.h +++ b/core/linux-dist/evdev.h @@ -5,8 +5,8 @@ struct s_controller { - int fd; - ControllerMapping* mapping; + int fd; + ControllerMapping* mapping; }; typedef struct s_controller Controller; @@ -14,12 +14,12 @@ typedef struct s_controller Controller; #define EVDEV_DEVICE_STRING "/dev/input/event%d" #ifdef TARGET_PANDORA - #define EVDEV_DEFAULT_DEVICE_ID_1 4 + #define EVDEV_DEFAULT_DEVICE_ID_1 4 #else - #define EVDEV_DEFAULT_DEVICE_ID_1 0 + #define EVDEV_DEFAULT_DEVICE_ID_1 0 #endif #define EVDEV_DEFAULT_DEVICE_ID(port) (port == 1 ? EVDEV_DEFAULT_DEVICE_ID_1 : -1) extern int input_evdev_init(Controller* controller, const char* device); -extern bool input_evdev_handle(Controller* controller, u32 port); \ No newline at end of file +extern bool input_evdev_handle(Controller* controller, u32 port); diff --git a/core/linux-dist/evdev_mappings.cpp b/core/linux-dist/evdev_mappings.cpp index 74f0e9f28..e09af1557 100644 --- a/core/linux-dist/evdev_mappings.cpp +++ b/core/linux-dist/evdev_mappings.cpp @@ -2,190 +2,190 @@ #if defined(USE_EVDEV) - ControllerMapping controller_mapping_generic = { - "Generic Controller", - BTN_A, - BTN_B, - BTN_C, - BTN_THUMBL, - BTN_X, - BTN_Y, - BTN_Z, - BTN_START, - BTN_SELECT, - BTN_DPAD_LEFT, - BTN_DPAD_RIGHT, - BTN_DPAD_UP, - BTN_DPAD_DOWN, - -1, - -1, - -1, - -1, - BTN_TL, - BTN_TR, - ABS_HAT0X, - ABS_HAT0Y, - ABS_HAT1X, - ABS_HAT1Y, - ABS_X, - ABS_Y, - ABS_Z, - ABS_RZ, - }; + ControllerMapping controller_mapping_generic = { + "Generic Controller", + BTN_A, + BTN_B, + BTN_C, + BTN_THUMBL, + BTN_X, + BTN_Y, + BTN_Z, + BTN_START, + BTN_SELECT, + BTN_DPAD_LEFT, + BTN_DPAD_RIGHT, + BTN_DPAD_UP, + BTN_DPAD_DOWN, + -1, + -1, + -1, + -1, + BTN_TL, + BTN_TR, + ABS_HAT0X, + ABS_HAT0Y, + ABS_HAT1X, + ABS_HAT1Y, + ABS_X, + ABS_Y, + ABS_Z, + ABS_RZ, + }; - ControllerMapping controller_mapping_keyboard = { - "Generic Keyboard", - KEY_A, - KEY_B, - KEY_C, - KEY_D, - KEY_X, - KEY_Y, - KEY_Z, - KEY_ENTER, - KEY_ESC, - KEY_LEFT, - KEY_RIGHT, - KEY_UP, - KEY_DOWN, - -1, - -1, - -1, - -1, - KEY_LEFTCTRL, - KEY_RIGHTCTRL, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1 - }; + ControllerMapping controller_mapping_keyboard = { + "Generic Keyboard", + KEY_A, + KEY_B, + KEY_C, + KEY_D, + KEY_X, + KEY_Y, + KEY_Z, + KEY_ENTER, + KEY_ESC, + KEY_LEFT, + KEY_RIGHT, + KEY_UP, + KEY_DOWN, + -1, + -1, + -1, + -1, + KEY_LEFTCTRL, + KEY_RIGHTCTRL, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + }; - ControllerMapping controller_mapping_xpad = { - "Xbox 360 Controller (xpad driver)", - BTN_A, - BTN_B, - BTN_TL, - BTN_TR, - BTN_X, - BTN_Y, - BTN_THUMBL, - BTN_START, - BTN_SELECT, - BTN_TRIGGER_HAPPY1, - BTN_TRIGGER_HAPPY2, - BTN_TRIGGER_HAPPY3, - BTN_TRIGGER_HAPPY4, - -1, - -1, - -1, - -1, - -1, - -1, - ABS_HAT0X, - ABS_HAT0Y, - ABS_HAT1X, - ABS_HAT1Y, - ABS_X, - ABS_Y, - ABS_Z, - ABS_RZ - }; + ControllerMapping controller_mapping_xpad = { + "Xbox 360 Controller (xpad driver)", + BTN_A, + BTN_B, + BTN_TL, + BTN_TR, + BTN_X, + BTN_Y, + BTN_THUMBL, + BTN_START, + BTN_SELECT, + BTN_TRIGGER_HAPPY1, + BTN_TRIGGER_HAPPY2, + BTN_TRIGGER_HAPPY3, + BTN_TRIGGER_HAPPY4, + -1, + -1, + -1, + -1, + -1, + -1, + ABS_HAT0X, + ABS_HAT0Y, + ABS_HAT1X, + ABS_HAT1Y, + ABS_X, + ABS_Y, + ABS_Z, + ABS_RZ + }; - ControllerMapping controller_mapping_xboxdrv = { - "Xbox 360 Controller (xboxdrv userspace driver)", - BTN_A, - BTN_B, - BTN_TL, - BTN_TR, - BTN_X, - BTN_Y, - BTN_THUMBL, - BTN_START, - BTN_SELECT, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - ABS_HAT0X, - ABS_HAT0Y, - ABS_HAT1X, - ABS_HAT1Y, - ABS_X, - ABS_Y, - ABS_BRAKE, - ABS_GAS - }; + ControllerMapping controller_mapping_xboxdrv = { + "Xbox 360 Controller (xboxdrv userspace driver)", + BTN_A, + BTN_B, + BTN_TL, + BTN_TR, + BTN_X, + BTN_Y, + BTN_THUMBL, + BTN_START, + BTN_SELECT, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + ABS_HAT0X, + ABS_HAT0Y, + ABS_HAT1X, + ABS_HAT1Y, + ABS_X, + ABS_Y, + ABS_BRAKE, + ABS_GAS + }; - ControllerMapping controller_mapping_gcwz = { - "GCW Zero", - 0x1D, // GCWZ_BTN_A - 0x38, // GCWZ_BTN_B - 0x0F, // GCWZ_BTN_L - 0x0E, // GCWZ_BTN_R - 0x2A, // GCWZ_BTN_X - 0x39, // GCWZ_BTN_Y - -1, - 0x1C, // GCWZ_BTN_START - 0x01, // GCWZ_BTN_SELECT - 0x69, // GCWZ_BTN_LEFT - 0x6A, // GCWZ_BTN_RIGHT - 0x67, // GCWZ_BTN_UP - 0x6C, // GCWZ_BTN_DOWN - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1 - }; + ControllerMapping controller_mapping_gcwz = { + "GCW Zero", + 0x1D, // GCWZ_BTN_A + 0x38, // GCWZ_BTN_B + 0x0F, // GCWZ_BTN_L + 0x0E, // GCWZ_BTN_R + 0x2A, // GCWZ_BTN_X + 0x39, // GCWZ_BTN_Y + -1, + 0x1C, // GCWZ_BTN_START + 0x01, // GCWZ_BTN_SELECT + 0x69, // GCWZ_BTN_LEFT + 0x6A, // GCWZ_BTN_RIGHT + 0x67, // GCWZ_BTN_UP + 0x6C, // GCWZ_BTN_DOWN + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + }; - ControllerMapping controller_mapping_pandora = { - "Pandora", - KEY_PAGEDOWN, - KEY_END, - KEY_SPACE, - -1, - KEY_HOME, - KEY_PAGEUP, - -1, - KEY_LEFTALT, - KEY_MENU, - KEY_LEFT, - KEY_RIGHT, - KEY_UP, - KEY_DOWN, - -1, - -1, - -1, - -1, - KEY_RIGHTSHIFT, - KEY_RIGHTCTRL, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - -1 - }; + ControllerMapping controller_mapping_pandora = { + "Pandora", + KEY_PAGEDOWN, + KEY_END, + KEY_SPACE, + -1, + KEY_HOME, + KEY_PAGEUP, + -1, + KEY_LEFTALT, + KEY_MENU, + KEY_LEFT, + KEY_RIGHT, + KEY_UP, + KEY_DOWN, + -1, + -1, + -1, + -1, + KEY_RIGHTSHIFT, + KEY_RIGHTCTRL, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + }; -#endif \ No newline at end of file +#endif diff --git a/core/linux-dist/evdev_mappings.h b/core/linux-dist/evdev_mappings.h index 3e2ee2523..f9dd4814c 100644 --- a/core/linux-dist/evdev_mappings.h +++ b/core/linux-dist/evdev_mappings.h @@ -3,34 +3,34 @@ struct s_evdev_controller_mapping { - const char* name; - const int Btn_A; - const int Btn_B; - const int Btn_C; - const int Btn_D; - const int Btn_X; - const int Btn_Y; - const int Btn_Z; - const int Btn_Start; - const int Btn_Escape; - const int Btn_DPad_Left; - const int Btn_DPad_Right; - const int Btn_DPad_Up; - const int Btn_DPad_Down; - const int Btn_DPad2_Left; - const int Btn_DPad2_Right; - const int Btn_DPad2_Up; - const int Btn_DPad2_Down; - const int Btn_Trigger_Left; - const int Btn_Trigger_Right; - const int Axis_DPad_X; - const int Axis_DPad_Y; - const int Axis_DPad2_X; - const int Axis_DPad2_Y; - const int Axis_Analog_X; - const int Axis_Analog_Y; - const int Axis_Trigger_Left; - const int Axis_Trigger_Right; + const char* name; + const int Btn_A; + const int Btn_B; + const int Btn_C; + const int Btn_D; + const int Btn_X; + const int Btn_Y; + const int Btn_Z; + const int Btn_Start; + const int Btn_Escape; + const int Btn_DPad_Left; + const int Btn_DPad_Right; + const int Btn_DPad_Up; + const int Btn_DPad_Down; + const int Btn_DPad2_Left; + const int Btn_DPad2_Right; + const int Btn_DPad2_Up; + const int Btn_DPad2_Down; + const int Btn_Trigger_Left; + const int Btn_Trigger_Right; + const int Axis_DPad_X; + const int Axis_DPad_Y; + const int Axis_DPad2_X; + const int Axis_DPad2_Y; + const int Axis_Analog_X; + const int Axis_Analog_Y; + const int Axis_Trigger_Left; + const int Axis_Trigger_Right; }; typedef struct s_evdev_controller_mapping ControllerMapping; @@ -39,4 +39,4 @@ extern ControllerMapping controller_mapping_keyboard; extern ControllerMapping controller_mapping_xpad; extern ControllerMapping controller_mapping_xboxdrv; extern ControllerMapping controller_mapping_gcwz; -extern ControllerMapping controller_mapping_pandora; \ No newline at end of file +extern ControllerMapping controller_mapping_pandora; diff --git a/core/linux-dist/joystick.cpp b/core/linux-dist/joystick.cpp index c32350e5b..e4023f37b 100644 --- a/core/linux-dist/joystick.cpp +++ b/core/linux-dist/joystick.cpp @@ -5,154 +5,154 @@ #include "linux-dist/joystick.h" #if defined(USE_JOYSTICK) - const u32 joystick_map_btn_usb[JOYSTICK_MAP_SIZE] = { DC_BTN_Y, DC_BTN_B, DC_BTN_A, DC_BTN_X, 0, 0, 0, 0, 0, DC_BTN_START }; - const u32 joystick_map_axis_usb[JOYSTICK_MAP_SIZE] = { DC_AXIS_X, DC_AXIS_Y, 0, 0, 0, 0, 0, 0, 0, 0 }; + const u32 joystick_map_btn_usb[JOYSTICK_MAP_SIZE] = { DC_BTN_Y, DC_BTN_B, DC_BTN_A, DC_BTN_X, 0, 0, 0, 0, 0, DC_BTN_START }; + const u32 joystick_map_axis_usb[JOYSTICK_MAP_SIZE] = { DC_AXIS_X, DC_AXIS_Y, 0, 0, 0, 0, 0, 0, 0, 0 }; - const u32 joystick_map_btn_xbox360[JOYSTICK_MAP_SIZE] = { DC_BTN_A, DC_BTN_B, DC_BTN_X, DC_BTN_Y, 0, 0, 0, DC_BTN_START, 0, 0 }; - const u32 joystick_map_axis_xbox360[JOYSTICK_MAP_SIZE] = { DC_AXIS_X, DC_AXIS_Y, DC_AXIS_LT, 0, 0, DC_AXIS_RT, DC_DPAD_LEFT, DC_DPAD_UP, 0, 0 }; + const u32 joystick_map_btn_xbox360[JOYSTICK_MAP_SIZE] = { DC_BTN_A, DC_BTN_B, DC_BTN_X, DC_BTN_Y, 0, 0, 0, DC_BTN_START, 0, 0 }; + const u32 joystick_map_axis_xbox360[JOYSTICK_MAP_SIZE] = { DC_AXIS_X, DC_AXIS_Y, DC_AXIS_LT, 0, 0, DC_AXIS_RT, DC_DPAD_LEFT, DC_DPAD_UP, 0, 0 }; - const u32* joystick_map_btn = joystick_map_btn_usb; - const u32* joystick_map_axis = joystick_map_axis_usb; + const u32* joystick_map_btn = joystick_map_btn_usb; + const u32* joystick_map_axis = joystick_map_axis_usb; - int input_joystick_init(const char* device) - { - int axis_count = 0; - int button_count = 0; - char name[128] = "Unknown"; + int input_joystick_init(const char* device) + { + int axis_count = 0; + int button_count = 0; + char name[128] = "Unknown"; - printf("joystick: Trying to open device at '%s'\n", device); + printf("joystick: Trying to open device at '%s'\n", device); - int fd = open(device, O_RDONLY); + int fd = open(device, O_RDONLY); - if(fd >= 0) - { - fcntl(fd, F_SETFL, O_NONBLOCK); - ioctl(fd, JSIOCGAXES, &axis_count); - ioctl(fd, JSIOCGBUTTONS, &button_count); - ioctl(fd, JSIOCGNAME(sizeof(name)), &name); + if(fd >= 0) + { + fcntl(fd, F_SETFL, O_NONBLOCK); + ioctl(fd, JSIOCGAXES, &axis_count); + ioctl(fd, JSIOCGBUTTONS, &button_count); + ioctl(fd, JSIOCGNAME(sizeof(name)), &name); - printf("joystick: Found '%s' with %d axis and %d buttons at '%s'.\n", name, axis_count, button_count, device); + printf("joystick: Found '%s' with %d axis and %d buttons at '%s'.\n", name, axis_count, button_count, device); - if (strcmp(name, "Microsoft X-Box 360 pad") == 0 || - strcmp(name, "Xbox Gamepad (userspace driver)") == 0 || - strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0) - { - joystick_map_btn = joystick_map_btn_xbox360; - joystick_map_axis = joystick_map_axis_xbox360; - printf("joystick: Using Xbox 360 map\n"); - } - } - else - { - perror("joystick open"); - } + if (strcmp(name, "Microsoft X-Box 360 pad") == 0 || + strcmp(name, "Xbox Gamepad (userspace driver)") == 0 || + strcmp(name, "Xbox 360 Wireless Receiver (XBOX)") == 0) + { + joystick_map_btn = joystick_map_btn_xbox360; + joystick_map_axis = joystick_map_axis_xbox360; + printf("joystick: Using Xbox 360 map\n"); + } + } + else + { + perror("joystick open"); + } - return fd; - } + return fd; + } - bool input_joystick_handle(int fd, u32 port) - { - // Joystick must be connected - if(fd < 0) { - return false; - } + bool input_joystick_handle(int fd, u32 port) + { + // Joystick must be connected + if(fd < 0) { + return false; + } - struct js_event JE; - while(read(fd, &JE, sizeof(JE)) == sizeof(JE)) - if (JE.number < JOYSTICK_MAP_SIZE) - { - switch(JE.type & ~JS_EVENT_INIT) - { - case JS_EVENT_AXIS: - { - u32 mt = joystick_map_axis[JE.number] >> 16; - u32 mo = joystick_map_axis[JE.number] & 0xFFFF; + struct js_event JE; + while(read(fd, &JE, sizeof(JE)) == sizeof(JE)) + if (JE.number < JOYSTICK_MAP_SIZE) + { + switch(JE.type & ~JS_EVENT_INIT) + { + case JS_EVENT_AXIS: + { + u32 mt = joystick_map_axis[JE.number] >> 16; + u32 mo = joystick_map_axis[JE.number] & 0xFFFF; - //printf("AXIS %d,%d\n",JE.number,JE.value); - s8 v=(s8)(JE.value/256); //-127 ... + 127 range + //printf("AXIS %d,%d\n",JE.number,JE.value); + s8 v=(s8)(JE.value/256); //-127 ... + 127 range - if (mt == 0) - { - kcode[port] |= mo; - kcode[port] |= mo*2; - if (v<-64) - { - kcode[port] &= ~mo; - } - else if (v>64) - { - kcode[port] &= ~(mo*2); - } + if (mt == 0) + { + kcode[port] |= mo; + kcode[port] |= mo*2; + if (v<-64) + { + kcode[port] &= ~mo; + } + else if (v>64) + { + kcode[port] &= ~(mo*2); + } - //printf("Mapped to %d %d %d\n",mo,kcode[port]&mo,kcode[port]&(mo*2)); - } - else if (mt == 1) - { - if (v >= 0) - { - v++; //up to 255 - } - //printf("AXIS %d,%d Mapped to %d %d %d\n",JE.number,JE.value,mo,v,v+127); - if (mo == 0) - { - lt[port] = (v + 127); - } - else if (mo == 1) - { - rt[port] = (v + 127); - } - } - else if (mt == 2) - { - // printf("AXIS %d,%d Mapped to %d %d [%d]",JE.number,JE.value,mo,v); - if (mo == 0) - { - joyx[port] = v; - } - else if (mo == 1) - { - joyy[port] = v; - } - } - } - break; + //printf("Mapped to %d %d %d\n",mo,kcode[port]&mo,kcode[port]&(mo*2)); + } + else if (mt == 1) + { + if (v >= 0) + { + v++; //up to 255 + } + //printf("AXIS %d,%d Mapped to %d %d %d\n",JE.number,JE.value,mo,v,v+127); + if (mo == 0) + { + lt[port] = (v + 127); + } + else if (mo == 1) + { + rt[port] = (v + 127); + } + } + else if (mt == 2) + { + // printf("AXIS %d,%d Mapped to %d %d [%d]",JE.number,JE.value,mo,v); + if (mo == 0) + { + joyx[port] = v; + } + else if (mo == 1) + { + joyy[port] = v; + } + } + } + break; - case JS_EVENT_BUTTON: - { - u32 mt = joystick_map_btn[JE.number] >> 16; - u32 mo = joystick_map_btn[JE.number] & 0xFFFF; + case JS_EVENT_BUTTON: + { + u32 mt = joystick_map_btn[JE.number] >> 16; + u32 mo = joystick_map_btn[JE.number] & 0xFFFF; - // printf("BUTTON %d,%d\n",JE.number,JE.value); + // printf("BUTTON %d,%d\n",JE.number,JE.value); - if (mt == 0) - { - // printf("Mapped to %d\n",mo); - if (JE.value) - { - kcode[port] &= ~mo; - } - else - { - kcode[port] |= mo; - } - } - else if (mt == 1) - { - // printf("Mapped to %d %d\n",mo,JE.value?255:0); - if (mo==0) - { - lt[port] = JE.value ? 255 : 0; - } - else if (mo==1) - { - rt[port] = JE.value ? 255 : 0; - } - } - } - break; - } - } + if (mt == 0) + { + // printf("Mapped to %d\n",mo); + if (JE.value) + { + kcode[port] &= ~mo; + } + else + { + kcode[port] |= mo; + } + } + else if (mt == 1) + { + // printf("Mapped to %d %d\n",mo,JE.value?255:0); + if (mo==0) + { + lt[port] = JE.value ? 255 : 0; + } + else if (mo==1) + { + rt[port] = JE.value ? 255 : 0; + } + } + } + break; + } + } - return true; - } -#endif \ No newline at end of file + return true; + } +#endif diff --git a/core/linux-dist/joystick.h b/core/linux-dist/joystick.h index 3644e53fc..ca88f8233 100644 --- a/core/linux-dist/joystick.h +++ b/core/linux-dist/joystick.h @@ -7,4 +7,4 @@ #define JOYSTICK_MAP_SIZE 32 extern int input_joystick_init(const char* device); -extern bool input_joystick_handle(int fd, u32 port); \ No newline at end of file +extern bool input_joystick_handle(int fd, u32 port); diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index 2680884eb..08ae38eff 100755 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -16,44 +16,44 @@ #include #if defined(TARGET_EMSCRIPTEN) - #include + #include #endif #if defined(SUPPORT_X11) - #include "linux-dist/x11.h" + #include "linux-dist/x11.h" #endif #if defined(USES_HOMEDIR) - #include + #include #endif #if defined(USE_EVDEV) - #include "linux-dist/evdev.h" + #include "linux-dist/evdev.h" #endif #if defined(USE_JOYSTICK) - #include "linux-dist/joystick.h" + #include "linux-dist/joystick.h" #endif #ifdef TARGET_PANDORA - #include - #include - #include + #include + #include + #include #endif int msgboxf(const wchar* text, unsigned int type, ...) { - va_list args; + va_list args; - wchar temp[2048]; - va_start(args, type); - vsprintf(temp, text, args); - va_end(args); + wchar temp[2048]; + va_start(args, type); + vsprintf(temp, text, args); + va_end(args); - //printf(NULL,temp,VER_SHORTNAME,type | MB_TASKMODAL); - puts(temp); - return MBX_OK; + //printf(NULL,temp,VER_SHORTNAME,type | MB_TASKMODAL); + puts(temp); + return MBX_OK; } void* x11_win = 0; @@ -61,16 +61,14 @@ void* x11_disp = 0; void* libPvr_GetRenderTarget() { - return x11_win; + return x11_win; } void* libPvr_GetRenderSurface() { - return x11_disp; + return x11_disp; } - - u16 kcode[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; u8 rt[4] = {0, 0, 0, 0}; u8 lt[4] = {0, 0, 0, 0}; @@ -80,155 +78,155 @@ s8 joyx[4], joyy[4]; void emit_WriteCodeCache(); #if defined(USE_EVDEV) - /* evdev input */ - static Controller controllers[4] = { - { -1, NULL }, - { -1, NULL }, - { -1, NULL }, - { -1, NULL } - }; + /* evdev input */ + static Controller controllers[4] = { + { -1, NULL }, + { -1, NULL }, + { -1, NULL }, + { -1, NULL } + }; #endif #if defined(USE_JOYSTICK) - /* legacy joystick input */ - static int joystick_fd = -1; // Joystick file descriptor + /* legacy joystick input */ + static int joystick_fd = -1; // Joystick file descriptor #endif void SetupInput() { - #if defined(USE_EVDEV) - char evdev_config_key[17]; - int evdev_device_id[4] = { -1, -1, -1, -1 }; - - int evdev_device_length, port, i; - char* evdev_device; - - for (port = 0; port < 4; port++) - { - sprintf(evdev_config_key, "evdev_device_id_%d", port+1); - evdev_device_id[port] = cfgLoadInt("input", evdev_config_key, EVDEV_DEFAULT_DEVICE_ID(port+1)); - - // Check if the same device is already in use on another port - if (evdev_device_id[port] < 0) - { - printf("evdev: Controller %d disabled by config.\n", port + 1); - } - else - { - for (i = 0; i < port; i++) - { - if (evdev_device_id[port] == evdev_device_id[i]) - { - die("You can't assign the same device to multiple ports!\n"); - } - } + #if defined(USE_EVDEV) + char evdev_config_key[17]; + int evdev_device_id[4] = { -1, -1, -1, -1 }; + + int evdev_device_length, port, i; + char* evdev_device; + + for (port = 0; port < 4; port++) + { + sprintf(evdev_config_key, "evdev_device_id_%d", port+1); + evdev_device_id[port] = cfgLoadInt("input", evdev_config_key, EVDEV_DEFAULT_DEVICE_ID(port+1)); + + // Check if the same device is already in use on another port + if (evdev_device_id[port] < 0) + { + printf("evdev: Controller %d disabled by config.\n", port + 1); + } + else + { + for (i = 0; i < port; i++) + { + if (evdev_device_id[port] == evdev_device_id[i]) + { + die("You can't assign the same device to multiple ports!\n"); + } + } - evdev_device_length = snprintf(NULL, 0, EVDEV_DEVICE_STRING, evdev_device_id[port]); - evdev_device = (char*)malloc(evdev_device_length + 1); - sprintf(evdev_device, EVDEV_DEVICE_STRING, evdev_device_id[port]); - input_evdev_init(&controllers[port], evdev_device); - free(evdev_device); - } - } - #endif + evdev_device_length = snprintf(NULL, 0, EVDEV_DEVICE_STRING, evdev_device_id[port]); + evdev_device = (char*)malloc(evdev_device_length + 1); + sprintf(evdev_device, EVDEV_DEVICE_STRING, evdev_device_id[port]); + input_evdev_init(&controllers[port], evdev_device); + free(evdev_device); + } + } + #endif - #if defined(USE_JOYSTICK) - int joystick_device_id = cfgLoadInt("input", "joystick_device_id", JOYSTICK_DEFAULT_DEVICE_ID); - if (joystick_device_id < 0) { - puts("joystick input disabled by config.\n"); - } - else - { - int joystick_device_length = snprintf(NULL, 0, JOYSTICK_DEVICE_STRING, joystick_device_id); - char* joystick_device = (char*)malloc(joystick_device_length + 1); - sprintf(joystick_device, JOYSTICK_DEVICE_STRING, joystick_device_id); - joystick_fd = input_joystick_init(joystick_device); - free(joystick_device); - } - #endif + #if defined(USE_JOYSTICK) + int joystick_device_id = cfgLoadInt("input", "joystick_device_id", JOYSTICK_DEFAULT_DEVICE_ID); + if (joystick_device_id < 0) { + puts("joystick input disabled by config.\n"); + } + else + { + int joystick_device_length = snprintf(NULL, 0, JOYSTICK_DEVICE_STRING, joystick_device_id); + char* joystick_device = (char*)malloc(joystick_device_length + 1); + sprintf(joystick_device, JOYSTICK_DEVICE_STRING, joystick_device_id); + joystick_fd = input_joystick_init(joystick_device); + free(joystick_device); + } + #endif - #if defined(SUPPORT_X11) - input_x11_init(); - #endif + #if defined(SUPPORT_X11) + input_x11_init(); + #endif } void UpdateInputState(u32 port) { - #if defined(TARGET_EMSCRIPTEN) - return; - #endif + #if defined(TARGET_EMSCRIPTEN) + return; + #endif - #if defined(USE_JOYSTICK) - input_joystick_handle(joystick_fd, port); - #endif + #if defined(USE_JOYSTICK) + input_joystick_handle(joystick_fd, port); + #endif - #if defined(USE_EVDEV) - input_evdev_handle(&controllers[port], port); - #endif + #if defined(USE_EVDEV) + input_evdev_handle(&controllers[port], port); + #endif } void os_DoEvents() { - #if defined(SUPPORT_X11) - input_x11_handle(); - #endif + #if defined(SUPPORT_X11) + input_x11_handle(); + #endif } void os_SetWindowText(const char * text) { - printf("%s\n",text); - #if defined(SUPPORT_X11) - x11_window_set_text(text); - #endif + printf("%s\n",text); + #if defined(SUPPORT_X11) + x11_window_set_text(text); + #endif } void os_CreateWindow() { - #if defined(SUPPORT_X11) - x11_window_create(); - #endif + #if defined(SUPPORT_X11) + x11_window_create(); + #endif } termios tios, orig_tios; int setup_curses() { - //initscr(); - //cbreak(); - //noecho(); + //initscr(); + //cbreak(); + //noecho(); - /* Get current terminal settings */ - if (tcgetattr(STDIN_FILENO, &orig_tios)) { - printf("Error getting current terminal settings\n"); - return -1; - } + /* Get current terminal settings */ + if (tcgetattr(STDIN_FILENO, &orig_tios)) { + printf("Error getting current terminal settings\n"); + return -1; + } - memcpy(&tios, &orig_tios, sizeof(struct termios)); - tios.c_lflag &= ~ICANON; //(ECHO|ICANON);&= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL); + memcpy(&tios, &orig_tios, sizeof(struct termios)); + tios.c_lflag &= ~ICANON; //(ECHO|ICANON);&= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL); - tios.c_cc[VTIME] = 0; - tios.c_cc[VMIN] = 0; + tios.c_cc[VTIME] = 0; + tios.c_cc[VMIN] = 0; - if (tcsetattr(STDIN_FILENO, TCSANOW, &tios)) { - printf("Error applying terminal settings\n"); - return -2; - } + if (tcsetattr(STDIN_FILENO, TCSANOW, &tios)) { + printf("Error applying terminal settings\n"); + return -2; + } - if (tcgetattr(STDIN_FILENO, &tios)) { - tcsetattr(0, TCSANOW, &orig_tios); - printf("Error while asserting terminal settings\n"); - return -3; - } + if (tcgetattr(STDIN_FILENO, &tios)) { + tcsetattr(0, TCSANOW, &orig_tios); + printf("Error while asserting terminal settings\n"); + return -3; + } - if ((tios.c_lflag & ICANON) || !(tios.c_lflag & ECHO)) { - tcsetattr(STDIN_FILENO, TCSANOW, &orig_tios); - printf("Could not apply all terminal settings\n"); - return -4; - } + if ((tios.c_lflag & ICANON) || !(tios.c_lflag & ECHO)) { + tcsetattr(STDIN_FILENO, TCSANOW, &orig_tios); + printf("Could not apply all terminal settings\n"); + return -4; + } - fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); - return 1; + fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); + return 1; } void common_linux_setup(); @@ -236,85 +234,85 @@ int dc_init(int argc,wchar* argv[]); void dc_run(); #ifdef TARGET_PANDORA - void gl_term(); + void gl_term(); - void clean_exit(int sig_num) - { - void* array[10]; - size_t size; + void clean_exit(int sig_num) + { + void* array[10]; + size_t size; - if (joystick_fd >= 0) { close(joystick_fd); } - for (int port = 0; port < 4 ; port++) - { - if (controllers[port]->fd >= 0) - { - close(controllers[port]->fd); - } - } + if (joystick_fd >= 0) { close(joystick_fd); } + for (int port = 0; port < 4 ; port++) + { + if (controllers[port]->fd >= 0) + { + close(controllers[port]->fd); + } + } - // Close EGL context ??? - if (sig_num!=0) - { - gl_term(); - } + // Close EGL context ??? + if (sig_num!=0) + { + gl_term(); + } - x11_window_destroy(): + x11_window_destroy(): - // finish cleaning - if (sig_num!=0) - { - write(2, "\nSignal received\n", sizeof("\nSignal received\n")); + // finish cleaning + if (sig_num!=0) + { + write(2, "\nSignal received\n", sizeof("\nSignal received\n")); - size = backtrace(array, 10); - backtrace_symbols_fd(array, size, STDERR_FILENO); - exit(1); - } - } + size = backtrace(array, 10); + backtrace_symbols_fd(array, size, STDERR_FILENO); + exit(1); + } + } #endif int main(int argc, wchar* argv[]) { - if (setup_curses() < 0) - { - printf("failed to setup curses!\n"); - } - #ifdef TARGET_PANDORA - signal(SIGSEGV, clean_exit); - signal(SIGKILL, clean_exit); - #endif + if (setup_curses() < 0) + { + printf("failed to setup curses!\n"); + } + #ifdef TARGET_PANDORA + signal(SIGSEGV, clean_exit); + signal(SIGKILL, clean_exit); + #endif - /* Set home dir */ - string home = "."; - #if defined(USES_HOMEDIR) - if(getenv("HOME") != NULL) - { - home = (string)getenv("HOME") + "/.reicast"; - mkdir(home.c_str(), 0755); // create the directory if missing - } - #endif - SetHomeDir(home); - printf("Home dir is: %s\n", GetPath("/").c_str()); + /* Set home dir */ + string home = "."; + #if defined(USES_HOMEDIR) + if(getenv("HOME") != NULL) + { + home = (string)getenv("HOME") + "/.reicast"; + mkdir(home.c_str(), 0755); // create the directory if missing + } + #endif + SetHomeDir(home); + printf("Home dir is: %s\n", GetPath("/").c_str()); - common_linux_setup(); + common_linux_setup(); - settings.profile.run_counts=0; + settings.profile.run_counts=0; - dc_init(argc,argv); + dc_init(argc,argv); - SetupInput(); + SetupInput(); - #if !defined(TARGET_EMSCRIPTEN) - dc_run(); - #else - emscripten_set_main_loop(&dc_run, 100, false); - #endif + #if !defined(TARGET_EMSCRIPTEN) + dc_run(); + #else + emscripten_set_main_loop(&dc_run, 100, false); + #endif - #ifdef TARGET_PANDORA - clean_exit(0); - #endif + #ifdef TARGET_PANDORA + clean_exit(0); + #endif - return 0; + return 0; } #endif @@ -323,10 +321,10 @@ int push_vmu_screen(u8* buffer) { return 0; } void os_DebugBreak() { - #if !defined(TARGET_EMSCRIPTEN) - raise(SIGTRAP); - #else - printf("DEBUGBREAK!\n"); - exit(-1); - #endif + #if !defined(TARGET_EMSCRIPTEN) + raise(SIGTRAP); + #else + printf("DEBUGBREAK!\n"); + exit(-1); + #endif } diff --git a/core/linux-dist/main.h b/core/linux-dist/main.h index f9e9c3db8..a4d72aa8b 100644 --- a/core/linux-dist/main.h +++ b/core/linux-dist/main.h @@ -11,25 +11,25 @@ extern void* x11_disp; enum DreamcastController { - DC_BTN_C = 1, - DC_BTN_B = 1<<1, - DC_BTN_A = 1<<2, - DC_BTN_START = 1<<3, - DC_DPAD_UP = 1<<4, - DC_DPAD_DOWN = 1<<5, - DC_DPAD_LEFT = 1<<6, - DC_DPAD_RIGHT = 1<<7, - DC_BTN_Z = 1<<8, - DC_BTN_Y = 1<<9, - DC_BTN_X = 1<<10, - DC_BTN_D = 1<<11, - DC_DPAD2_UP = 1<<12, - DC_DPAD2_DOWN = 1<<13, - DC_DPAD2_LEFT = 1<<14, - DC_DPAD2_RIGHT = 1<<15, + DC_BTN_C = 1, + DC_BTN_B = 1<<1, + DC_BTN_A = 1<<2, + DC_BTN_START = 1<<3, + DC_DPAD_UP = 1<<4, + DC_DPAD_DOWN = 1<<5, + DC_DPAD_LEFT = 1<<6, + DC_DPAD_RIGHT = 1<<7, + DC_BTN_Z = 1<<8, + DC_BTN_Y = 1<<9, + DC_BTN_X = 1<<10, + DC_BTN_D = 1<<11, + DC_DPAD2_UP = 1<<12, + DC_DPAD2_DOWN = 1<<13, + DC_DPAD2_LEFT = 1<<14, + DC_DPAD2_RIGHT = 1<<15, - DC_AXIS_LT = 0X10000, - DC_AXIS_RT = 0X10001, - DC_AXIS_X = 0X20000, - DC_AXIS_Y = 0X20001, -}; \ No newline at end of file + DC_AXIS_LT = 0X10000, + DC_AXIS_RT = 0X10001, + DC_AXIS_X = 0X20000, + DC_AXIS_Y = 0X20001, +}; diff --git a/core/linux-dist/x11.cpp b/core/linux-dist/x11.cpp index 994859a50..381f29303 100644 --- a/core/linux-dist/x11.cpp +++ b/core/linux-dist/x11.cpp @@ -5,8 +5,8 @@ #include #if !defined(GLES) - #include - #include + #include + #include #endif #include "types.h" @@ -15,9 +15,9 @@ #include "linux-dist/main.h" #if defined(TARGET_PANDORA) - #define WINDOW_WIDTH 800 + #define WINDOW_WIDTH 800 #else - #define WINDOW_WIDTH 640 + #define WINDOW_WIDTH 640 #endif #define WINDOW_HEIGHT 480 @@ -29,283 +29,284 @@ int ndcid = 0; void* x11_glc; #ifdef TARGET_PANDORA - static Cursor CreateNullCursor(Display *display, Window root) - { - Pixmap cursormask; - XGCValues xgc; - GC gc; - XColor dummycolour; - Cursor cursor; + static Cursor CreateNullCursor(Display *display, Window root) + { + Pixmap cursormask; + XGCValues xgc; + GC gc; + XColor dummycolour; + Cursor cursor; - cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/); - xgc.function = GXclear; - gc = XCreateGC(display, cursormask, GCFunction, &xgc); - XFillRectangle(display, cursormask, gc, 0, 0, 1, 1); - dummycolour.pixel = 0; - dummycolour.red = 0; - dummycolour.flags = 04; - cursor = XCreatePixmapCursor(display, cursormask, cursormask, &dummycolour,&dummycolour, 0,0); - XFreePixmap(display,cursormask); - XFreeGC(display,gc); - return cursor; - } + cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/); + xgc.function = GXclear; + gc = XCreateGC(display, cursormask, GCFunction, &xgc); + XFillRectangle(display, cursormask, gc, 0, 0, 1, 1); + dummycolour.pixel = 0; + dummycolour.red = 0; + dummycolour.flags = 04; + cursor = XCreatePixmapCursor(display, cursormask, cursormask, &dummycolour,&dummycolour, 0,0); + XFreePixmap(display,cursormask); + XFreeGC(display,gc); + return cursor; + } #endif -void input_x11_handle() { - if (x11_win && x11_keyboard_input) - { - //Handle X11 - XEvent e; +void input_x11_handle() +{ + if (x11_win && x11_keyboard_input) + { + //Handle X11 + XEvent e; - if(XCheckWindowEvent((Display*)x11_disp, (Window)x11_win, KeyPressMask | KeyReleaseMask, &e)) - { - switch(e.type) - { - case KeyPress: - case KeyRelease: - { - int dc_key = x11_keymap[e.xkey.keycode]; + if(XCheckWindowEvent((Display*)x11_disp, (Window)x11_win, KeyPressMask | KeyReleaseMask, &e)) + { + switch(e.type) + { + case KeyPress: + case KeyRelease: + { + int dc_key = x11_keymap[e.xkey.keycode]; - if (e.type == KeyPress) - { - kcode[0] &= ~dc_key; - } - else - { - kcode[0] |= dc_key; - } + if (e.type == KeyPress) + { + kcode[0] &= ~dc_key; + } + else + { + kcode[0] |= dc_key; + } - //printf("KEY: %d -> %d: %d\n",e.xkey.keycode, dc_key, x11_dc_buttons ); - } - break; + //printf("KEY: %d -> %d: %d\n",e.xkey.keycode, dc_key, x11_dc_buttons ); + } + break; - { - printf("KEYRELEASE\n"); - } - break; + { + printf("KEYRELEASE\n"); + } + break; - } - } - } + } + } + } } void input_x11_init() { - x11_keymap[113] = DC_DPAD_LEFT; - x11_keymap[114] = DC_DPAD_RIGHT; + x11_keymap[113] = DC_DPAD_LEFT; + x11_keymap[114] = DC_DPAD_RIGHT; - x11_keymap[111] = DC_DPAD_UP; - x11_keymap[116] = DC_DPAD_DOWN; + x11_keymap[111] = DC_DPAD_UP; + x11_keymap[116] = DC_DPAD_DOWN; - x11_keymap[53] = DC_BTN_X; - x11_keymap[54] = DC_BTN_B; - x11_keymap[55] = DC_BTN_A; + x11_keymap[53] = DC_BTN_X; + x11_keymap[54] = DC_BTN_B; + x11_keymap[55] = DC_BTN_A; - /* - //TODO: Fix sliders - x11_keymap[38] = DPad_Down; - x11_keymap[39] = DPad_Down; - */ + /* + //TODO: Fix sliders + x11_keymap[38] = DPad_Down; + x11_keymap[39] = DPad_Down; + */ - x11_keymap[36] = DC_BTN_START; + x11_keymap[36] = DC_BTN_START; - x11_keyboard_input = cfgLoadInt("input", "enable_x11_keyboard", 1); + x11_keyboard_input = cfgLoadInt("input", "enable_x11_keyboard", 1); } void x11_window_create() { - if (cfgLoadInt("pvr", "nox11", 0) == 0) - { - XInitThreads(); - // X11 variables - Window x11Window = 0; - Display* x11Display = 0; - long x11Screen = 0; - XVisualInfo* x11Visual = 0; - Colormap x11Colormap = 0; + if (cfgLoadInt("pvr", "nox11", 0) == 0) + { + XInitThreads(); + // X11 variables + Window x11Window = 0; + Display* x11Display = 0; + long x11Screen = 0; + XVisualInfo* x11Visual = 0; + Colormap x11Colormap = 0; - /* - Step 0 - Create a NativeWindowType that we can use it for OpenGL ES output - */ - Window sRootWindow; - XSetWindowAttributes sWA; - unsigned int ui32Mask; - int i32Depth; + /* + Step 0 - Create a NativeWindowType that we can use it for OpenGL ES output + */ + Window sRootWindow; + XSetWindowAttributes sWA; + unsigned int ui32Mask; + int i32Depth; - // Initializes the display and screen - x11Display = XOpenDisplay(0); - if (!x11Display && !(x11Display = XOpenDisplay(":0"))) - { - printf("Error: Unable to open X display\n"); - return; - } - x11Screen = XDefaultScreen(x11Display); + // Initializes the display and screen + x11Display = XOpenDisplay(0); + if (!x11Display && !(x11Display = XOpenDisplay(":0"))) + { + printf("Error: Unable to open X display\n"); + return; + } + x11Screen = XDefaultScreen(x11Display); - // Gets the window parameters - sRootWindow = RootWindow(x11Display, x11Screen); + // Gets the window parameters + sRootWindow = RootWindow(x11Display, x11Screen); - int depth = CopyFromParent; + int depth = CopyFromParent; - #if !defined(GLES) - // Get a matching FB config - static int visual_attribs[] = - { - GLX_X_RENDERABLE , True, - GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, - GLX_RENDER_TYPE , GLX_RGBA_BIT, - GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, - GLX_RED_SIZE , 8, - GLX_GREEN_SIZE , 8, - GLX_BLUE_SIZE , 8, - GLX_ALPHA_SIZE , 8, - GLX_DEPTH_SIZE , 24, - GLX_STENCIL_SIZE , 8, - GLX_DOUBLEBUFFER , True, - //GLX_SAMPLE_BUFFERS , 1, - //GLX_SAMPLES , 4, - None - }; + #if !defined(GLES) + // Get a matching FB config + static int visual_attribs[] = + { + GLX_X_RENDERABLE , True, + GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, + GLX_RENDER_TYPE , GLX_RGBA_BIT, + GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, + GLX_RED_SIZE , 8, + GLX_GREEN_SIZE , 8, + GLX_BLUE_SIZE , 8, + GLX_ALPHA_SIZE , 8, + GLX_DEPTH_SIZE , 24, + GLX_STENCIL_SIZE , 8, + GLX_DOUBLEBUFFER , True, + //GLX_SAMPLE_BUFFERS , 1, + //GLX_SAMPLES , 4, + None + }; - int glx_major, glx_minor; + int glx_major, glx_minor; - // FBConfigs were added in GLX version 1.3. - if (!glXQueryVersion(x11Display, &glx_major, &glx_minor) || - ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) - { - printf("Invalid GLX version"); - exit(1); - } + // FBConfigs were added in GLX version 1.3. + if (!glXQueryVersion(x11Display, &glx_major, &glx_minor) || + ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) + { + printf("Invalid GLX version"); + exit(1); + } - int fbcount; - GLXFBConfig* fbc = glXChooseFBConfig(x11Display, x11Screen, visual_attribs, &fbcount); - if (!fbc) - { - printf("Failed to retrieve a framebuffer config\n"); - exit(1); - } - printf("Found %d matching FB configs.\n", fbcount); + int fbcount; + GLXFBConfig* fbc = glXChooseFBConfig(x11Display, x11Screen, visual_attribs, &fbcount); + if (!fbc) + { + printf("Failed to retrieve a framebuffer config\n"); + exit(1); + } + printf("Found %d matching FB configs.\n", fbcount); - GLXFBConfig bestFbc = fbc[0]; - XFree(fbc); + GLXFBConfig bestFbc = fbc[0]; + XFree(fbc); - // Get a visual - XVisualInfo *vi = glXGetVisualFromFBConfig(x11Display, bestFbc); - printf("Chosen visual ID = 0x%x\n", vi->visualid); + // Get a visual + XVisualInfo *vi = glXGetVisualFromFBConfig(x11Display, bestFbc); + printf("Chosen visual ID = 0x%x\n", vi->visualid); - depth = vi->depth; - x11Visual = vi; + depth = vi->depth; + x11Visual = vi; - x11Colormap = XCreateColormap(x11Display, RootWindow(x11Display, x11Screen), vi->visual, AllocNone); - #else - i32Depth = DefaultDepth(x11Display, x11Screen); - x11Visual = new XVisualInfo; - XMatchVisualInfo(x11Display, x11Screen, i32Depth, TrueColor, x11Visual); - if (!x11Visual) - { - printf("Error: Unable to acquire visual\n"); - return; - } - x11Colormap = XCreateColormap(x11Display, sRootWindow, x11Visual->visual, AllocNone); - #endif + x11Colormap = XCreateColormap(x11Display, RootWindow(x11Display, x11Screen), vi->visual, AllocNone); + #else + i32Depth = DefaultDepth(x11Display, x11Screen); + x11Visual = new XVisualInfo; + XMatchVisualInfo(x11Display, x11Screen, i32Depth, TrueColor, x11Visual); + if (!x11Visual) + { + printf("Error: Unable to acquire visual\n"); + return; + } + x11Colormap = XCreateColormap(x11Display, sRootWindow, x11Visual->visual, AllocNone); + #endif - sWA.colormap = x11Colormap; + sWA.colormap = x11Colormap; - // Add to these for handling other events - sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; - ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; + // Add to these for handling other events + sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask; + ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; - #ifdef TARGET_PANDORA - int width = 800; - int height = 480; - #else - int width = cfgLoadInt("x11", "width", WINDOW_WIDTH); - int height = cfgLoadInt("x11", "height", WINDOW_HEIGHT); - #endif + #ifdef TARGET_PANDORA + int width = 800; + int height = 480; + #else + int width = cfgLoadInt("x11", "width", WINDOW_WIDTH); + int height = cfgLoadInt("x11", "height", WINDOW_HEIGHT); + #endif - if (width == -1) - { - width = XDisplayWidth(x11Display, x11Screen); - height = XDisplayHeight(x11Display, x11Screen); - } + if (width == -1) + { + width = XDisplayWidth(x11Display, x11Screen); + height = XDisplayHeight(x11Display, x11Screen); + } - // Creates the X11 window - x11Window = XCreateWindow(x11Display, RootWindow(x11Display, x11Screen), (ndcid%3)*640, (ndcid/3)*480, width, height, - 0, depth, InputOutput, x11Visual->visual, ui32Mask, &sWA); + // Creates the X11 window + x11Window = XCreateWindow(x11Display, RootWindow(x11Display, x11Screen), (ndcid%3)*640, (ndcid/3)*480, width, height, + 0, depth, InputOutput, x11Visual->visual, ui32Mask, &sWA); - #ifdef TARGET_PANDORA - // fullscreen - Atom wmState = XInternAtom(x11Display, "_NET_WM_STATE", False); - Atom wmFullscreen = XInternAtom(x11Display, "_NET_WM_STATE_FULLSCREEN", False); - XChangeProperty(x11Display, x11Window, wmState, XA_ATOM, 32, PropModeReplace, (unsigned char *)&wmFullscreen, 1); + #ifdef TARGET_PANDORA + // fullscreen + Atom wmState = XInternAtom(x11Display, "_NET_WM_STATE", False); + Atom wmFullscreen = XInternAtom(x11Display, "_NET_WM_STATE_FULLSCREEN", False); + XChangeProperty(x11Display, x11Window, wmState, XA_ATOM, 32, PropModeReplace, (unsigned char *)&wmFullscreen, 1); - XMapRaised(x11Display, x11Window); - #else - XMapWindow(x11Display, x11Window); + XMapRaised(x11Display, x11Window); + #else + XMapWindow(x11Display, x11Window); - #if !defined(GLES) - #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 - #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 - typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); + #if !defined(GLES) + #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 + #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 + typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); - glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; - glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); - verify(glXCreateContextAttribsARB != 0); - int context_attribs[] = - { - GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX_CONTEXT_MINOR_VERSION_ARB, 1, - GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, - None - }; + glXCreateContextAttribsARBProc glXCreateContextAttribsARB = 0; + glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB"); + verify(glXCreateContextAttribsARB != 0); + int context_attribs[] = + { + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 1, + GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + None + }; - x11_glc = glXCreateContextAttribsARB(x11Display, bestFbc, 0, True, context_attribs); - XSync(x11Display, False); + x11_glc = glXCreateContextAttribsARB(x11Display, bestFbc, 0, True, context_attribs); + XSync(x11Display, False); - if (!x11_glc) - { - die("Failed to create GL3.1 context\n"); - } - #endif - #endif + if (!x11_glc) + { + die("Failed to create GL3.1 context\n"); + } + #endif + #endif - XFlush(x11Display); + XFlush(x11Display); - //(EGLNativeDisplayType)x11Display; - x11_disp = (void*)x11Display; - x11_win = (void*)x11Window; - } - else - { - printf("Not creating X11 window ..\n"); - } + //(EGLNativeDisplayType)x11Display; + x11_disp = (void*)x11Display; + x11_win = (void*)x11Window; + } + else + { + printf("Not creating X11 window ..\n"); + } } void x11_window_set_text(const char* text) { - if (x11_win) - { - XChangeProperty((Display*)x11_disp, (Window)x11_win, - XInternAtom((Display*)x11_disp, "WM_NAME", False), //WM_NAME, - XInternAtom((Display*)x11_disp, "UTF8_STRING", False), //UTF8_STRING, - 8, PropModeReplace, (const unsigned char *)text, strlen(text)); - } + if (x11_win) + { + XChangeProperty((Display*)x11_disp, (Window)x11_win, + XInternAtom((Display*)x11_disp, "WM_NAME", False), //WM_NAME, + XInternAtom((Display*)x11_disp, "UTF8_STRING", False), //UTF8_STRING, + 8, PropModeReplace, (const unsigned char *)text, strlen(text)); + } } void x11_window_destroy() { - // close XWindow - if (x11_win) - { - XDestroyWindow(x11_disp, x11_win); - x11_win = 0; - } - if (x11_disp) - { - XCloseDisplay(x11_disp); - x11_disp = 0; - } + // close XWindow + if (x11_win) + { + XDestroyWindow(x11_disp, x11_win); + x11_win = 0; + } + if (x11_disp) + { + XCloseDisplay(x11_disp); + x11_disp = 0; + } } -#endif \ No newline at end of file +#endif diff --git a/core/linux-dist/x11.h b/core/linux-dist/x11.h index d4b60da70..dcb056870 100644 --- a/core/linux-dist/x11.h +++ b/core/linux-dist/x11.h @@ -4,4 +4,4 @@ extern void* x11_glc; extern void input_x11_init(); extern void input_x11_handle(); extern void x11_window_create(); -extern void x11_window_set_text(const char* text); \ No newline at end of file +extern void x11_window_set_text(const char* text);