#include "types.h" #include "cfg/cfg.h" #if HOST_OS==OS_LINUX #include #include //#include #include #include #include #include #include #include #include #include "hw/sh4/dyna/blockmanager.h" #include #if defined(TARGET_EMSCRIPTEN) #include #endif #if defined(SUPPORT_X11) #include "linux-dist/x11.h" #endif #if defined(USES_HOMEDIR) #include #endif #if defined(USE_EVDEV) #include "linux-dist/evdev.h" #endif #if defined(USE_JOYSTICK) #include "linux-dist/joystick.h" #endif #ifdef TARGET_PANDORA #include #include #include #endif int msgboxf(const wchar* text, unsigned int type, ...) { va_list 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; } void* x11_win = 0; void* x11_disp = 0; void* libPvr_GetRenderTarget() { return x11_win; } void* libPvr_GetRenderSurface() { return x11_disp; } u16 kcode[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; u8 rt[4] = {0, 0, 0, 0}; u8 lt[4] = {0, 0, 0, 0}; u32 vks[4]; 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 } }; #endif #if defined(USE_JOYSTICK) /* legacy joystick input */ static int joystick_fd = -1; // Joystick file descriptor #endif void SetupInput() { #if defined(USE_EVDEV) int evdev_device_id[4] = { -1, -1, -1, -1 }; size_t size_needed; int port, i; char* evdev_device; for (port = 0; port < 4; port++) { size_needed = snprintf(NULL, 0, EVDEV_DEVICE_CONFIG_KEY, port+1) + 1; char* evdev_config_key = (char*)malloc(size_needed); sprintf(evdev_config_key, EVDEV_DEVICE_CONFIG_KEY, port+1); evdev_device_id[port] = cfgLoadInt("input", evdev_config_key, EVDEV_DEFAULT_DEVICE_ID(port+1)); free(evdev_config_key); // 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"); } } size_needed = snprintf(NULL, 0, EVDEV_DEVICE_STRING, evdev_device_id[port]) + 1; evdev_device = (char*)malloc(size_needed); sprintf(evdev_device, EVDEV_DEVICE_STRING, evdev_device_id[port]); size_needed = snprintf(NULL, 0, EVDEV_MAPPING_CONFIG_KEY, port+1) + 1; evdev_config_key = (char*)malloc(size_needed); sprintf(evdev_config_key, EVDEV_MAPPING_CONFIG_KEY, port+1); const char* mapping = (cfgExists("input", evdev_config_key) == 2 ? cfgLoadStr("input", evdev_config_key, "").c_str() : NULL); free(evdev_config_key); input_evdev_init(&controllers[port], evdev_device, mapping); 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(SUPPORT_X11) input_x11_init(); #endif } void UpdateInputState(u32 port) { #if defined(TARGET_EMSCRIPTEN) return; #endif #if defined(USE_JOYSTICK) input_joystick_handle(joystick_fd, port); #endif #if defined(USE_EVDEV) input_evdev_handle(&controllers[port], port); #endif } void os_DoEvents() { #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 } void os_CreateWindow() { #if defined(SUPPORT_X11) x11_window_create(); #endif } void common_linux_setup(); int dc_init(int argc,wchar* argv[]); void dc_run(); #ifdef TARGET_PANDORA void gl_term(); 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); } } // Close EGL context ??? if (sig_num!=0) { gl_term(); } x11_window_destroy(): // 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); } } #endif int main(int argc, wchar* argv[]) { #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()); common_linux_setup(); settings.profile.run_counts=0; dc_init(argc,argv); SetupInput(); #if !defined(TARGET_EMSCRIPTEN) dc_run(); #else emscripten_set_main_loop(&dc_run, 100, false); #endif #ifdef TARGET_PANDORA clean_exit(0); #endif return 0; } #endif int get_mic_data(u8* buffer) { return 0; } int push_vmu_screen(u8* buffer) { return 0; } void os_DebugBreak() { #if !defined(TARGET_EMSCRIPTEN) raise(SIGTRAP); #else printf("DEBUGBREAK!\n"); exit(-1); #endif }