2013-12-19 17:10:14 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "cfg/cfg.h"
|
|
|
|
|
|
|
|
#if HOST_OS==OS_LINUX
|
|
|
|
#include <poll.h>
|
|
|
|
#include <termios.h>
|
|
|
|
//#include <curses.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "hw/sh4/dyna/blockmanager.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-07-29 04:22:59 +00:00
|
|
|
#if defined(TARGET_EMSCRIPTEN)
|
2015-08-11 23:57:29 +00:00
|
|
|
#include <emscripten.h>
|
2015-07-29 04:22:59 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
#if defined(SUPPORT_X11)
|
2015-08-15 03:50:08 +00:00
|
|
|
#include "linux-dist/x11.h"
|
2013-12-19 17:10:14 +00:00
|
|
|
#endif
|
|
|
|
|
2015-08-15 03:07:37 +00:00
|
|
|
#if defined(USES_HOMEDIR)
|
2015-08-11 23:57:29 +00:00
|
|
|
#include <sys/stat.h>
|
2013-12-19 17:10:14 +00:00
|
|
|
#endif
|
|
|
|
|
2015-08-15 01:23:11 +00:00
|
|
|
#if defined(USE_EVDEV)
|
2015-08-15 03:07:37 +00:00
|
|
|
#include "linux-dist/evdev.h"
|
2015-08-15 01:23:11 +00:00
|
|
|
#endif
|
|
|
|
|
2015-08-12 01:03:01 +00:00
|
|
|
#if defined(USE_JOYSTICK)
|
2015-08-15 03:07:37 +00:00
|
|
|
#include "linux-dist/joystick.h"
|
2015-08-12 01:03:01 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-20 15:24:38 +00:00
|
|
|
#ifdef TARGET_PANDORA
|
2015-08-11 23:57:29 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <execinfo.h>
|
2015-08-15 03:50:08 +00:00
|
|
|
#include <sys/soundcard.h>
|
2013-12-20 15:24:38 +00:00
|
|
|
#endif
|
2015-08-11 23:57:29 +00:00
|
|
|
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
int msgboxf(const wchar* text, unsigned int type, ...)
|
2013-12-19 17:10:14 +00:00
|
|
|
{
|
2015-08-11 23:57:29 +00:00
|
|
|
va_list args;
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
wchar temp[2048];
|
|
|
|
va_start(args, type);
|
|
|
|
vsprintf(temp, text, args);
|
|
|
|
va_end(args);
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
//printf(NULL,temp,VER_SHORTNAME,type | MB_TASKMODAL);
|
|
|
|
puts(temp);
|
|
|
|
return MBX_OK;
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
2015-08-15 03:50:08 +00:00
|
|
|
void* x11_win = 0;
|
|
|
|
void* x11_disp = 0;
|
|
|
|
|
|
|
|
void* libPvr_GetRenderTarget()
|
|
|
|
{
|
|
|
|
return x11_win;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* libPvr_GetRenderSurface()
|
|
|
|
{
|
|
|
|
return x11_disp;
|
|
|
|
}
|
|
|
|
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
|
2015-08-12 10:16:23 +00:00
|
|
|
u16 kcode[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
|
|
|
|
u8 rt[4] = {0, 0, 0, 0};
|
|
|
|
u8 lt[4] = {0, 0, 0, 0};
|
2013-12-19 17:10:14 +00:00
|
|
|
u32 vks[4];
|
2015-08-12 10:29:41 +00:00
|
|
|
s8 joyx[4], joyy[4];
|
2013-12-19 17:10:14 +00:00
|
|
|
|
|
|
|
void emit_WriteCodeCache();
|
|
|
|
|
2015-08-12 01:40:09 +00:00
|
|
|
#if defined(USE_EVDEV)
|
2015-08-15 01:23:11 +00:00
|
|
|
/* evdev input */
|
|
|
|
static Controller controllers[4] = {
|
|
|
|
{ -1, NULL },
|
|
|
|
{ -1, NULL },
|
|
|
|
{ -1, NULL },
|
|
|
|
{ -1, NULL }
|
|
|
|
};
|
2015-08-12 01:40:09 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-12 01:40:09 +00:00
|
|
|
#if defined(USE_JOYSTICK)
|
2015-08-15 03:07:37 +00:00
|
|
|
/* legacy joystick input */
|
|
|
|
static int joystick_fd = -1; // Joystick file descriptor
|
2015-08-12 01:40:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void SetupInput()
|
|
|
|
{
|
|
|
|
#if defined(USE_EVDEV)
|
2015-08-14 18:57:32 +00:00
|
|
|
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++)
|
2015-08-14 10:06:06 +00:00
|
|
|
{
|
2015-08-14 18:57:32 +00:00
|
|
|
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]);
|
2015-08-15 01:23:11 +00:00
|
|
|
input_evdev_init(&controllers[port], evdev_device);
|
2015-08-14 18:57:32 +00:00
|
|
|
free(evdev_device);
|
|
|
|
}
|
2015-08-14 10:06:06 +00:00
|
|
|
}
|
2015-08-11 23:57:29 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-12 01:40:09 +00:00
|
|
|
#if defined(USE_JOYSTICK)
|
2015-08-14 10:06:06 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-08-12 01:40:09 +00:00
|
|
|
#endif
|
2015-08-15 03:50:08 +00:00
|
|
|
|
|
|
|
#if defined(SUPPORT_X11)
|
|
|
|
input_x11_init();
|
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateInputState(u32 port)
|
|
|
|
{
|
2015-08-11 23:57:29 +00:00
|
|
|
#if defined(TARGET_EMSCRIPTEN)
|
|
|
|
return;
|
|
|
|
#endif
|
2015-08-11 16:08:06 +00:00
|
|
|
|
2015-08-12 01:40:09 +00:00
|
|
|
#if defined(USE_JOYSTICK)
|
|
|
|
input_joystick_handle(joystick_fd, port);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_EVDEV)
|
2015-08-15 01:23:11 +00:00
|
|
|
input_evdev_handle(&controllers[port], port);
|
2015-08-11 23:57:29 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void os_DoEvents()
|
|
|
|
{
|
2015-08-11 23:57:29 +00:00
|
|
|
#if defined(SUPPORT_X11)
|
2015-08-15 03:50:08 +00:00
|
|
|
input_x11_handle();
|
2015-08-11 23:57:29 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void os_SetWindowText(const char * text)
|
|
|
|
{
|
2015-08-15 03:50:08 +00:00
|
|
|
printf("%s\n",text);
|
2015-08-11 23:57:29 +00:00
|
|
|
#if defined(SUPPORT_X11)
|
2015-08-15 03:50:08 +00:00
|
|
|
x11_window_set_text(text);
|
2015-08-11 23:57:29 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void os_CreateWindow()
|
|
|
|
{
|
2015-08-11 23:57:29 +00:00
|
|
|
#if defined(SUPPORT_X11)
|
2015-08-15 03:50:08 +00:00
|
|
|
x11_window_create();
|
2015-08-11 23:57:29 +00:00
|
|
|
#endif
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
termios tios, orig_tios;
|
|
|
|
|
|
|
|
int setup_curses()
|
|
|
|
{
|
2015-08-11 23:57:29 +00:00
|
|
|
//initscr();
|
|
|
|
//cbreak();
|
|
|
|
//noecho();
|
|
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
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 (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;
|
|
|
|
}
|
|
|
|
|
|
|
|
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
void common_linux_setup();
|
|
|
|
int dc_init(int argc,wchar* argv[]);
|
|
|
|
void dc_run();
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
#ifdef TARGET_PANDORA
|
|
|
|
void gl_term();
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
void clean_exit(int sig_num)
|
|
|
|
{
|
|
|
|
void* array[10];
|
|
|
|
size_t size;
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-12 00:37:12 +00:00
|
|
|
if (joystick_fd >= 0) { close(joystick_fd); }
|
2015-08-14 18:57:32 +00:00
|
|
|
for (int port = 0; port < 4 ; port++)
|
|
|
|
{
|
2015-08-15 03:56:17 +00:00
|
|
|
if (controllers[port]->fd >= 0)
|
2015-08-14 18:57:32 +00:00
|
|
|
{
|
2015-08-15 03:56:17 +00:00
|
|
|
close(controllers[port]->fd);
|
2015-08-14 18:57:32 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
// Close EGL context ???
|
|
|
|
if (sig_num!=0)
|
|
|
|
{
|
|
|
|
gl_term();
|
2013-12-19 17:10:14 +00:00
|
|
|
}
|
|
|
|
|
2015-08-15 03:50:08 +00:00
|
|
|
x11_window_destroy():
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
// finish cleaning
|
|
|
|
if (sig_num!=0)
|
|
|
|
{
|
|
|
|
write(2, "\nSignal received\n", sizeof("\nSignal received\n"));
|
2013-12-20 15:24:38 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
size = backtrace(array, 10);
|
|
|
|
backtrace_symbols_fd(array, size, STDERR_FILENO);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2013-12-20 15:24:38 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-19 17:10:14 +00:00
|
|
|
int main(int argc, wchar* argv[])
|
|
|
|
{
|
2015-08-11 23:57:29 +00:00
|
|
|
if (setup_curses() < 0)
|
|
|
|
{
|
|
|
|
printf("failed to setup curses!\n");
|
|
|
|
}
|
|
|
|
#ifdef TARGET_PANDORA
|
|
|
|
signal(SIGSEGV, clean_exit);
|
|
|
|
signal(SIGKILL, clean_exit);
|
|
|
|
#endif
|
2013-12-20 20:46:59 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
/* Set home dir */
|
2015-08-11 19:31:57 +00:00
|
|
|
string home = ".";
|
2015-08-11 19:36:14 +00:00
|
|
|
#if defined(USES_HOMEDIR)
|
2015-08-11 23:57:29 +00:00
|
|
|
if(getenv("HOME") != NULL)
|
|
|
|
{
|
|
|
|
home = (string)getenv("HOME") + "/.reicast";
|
|
|
|
mkdir(home.c_str(), 0755); // create the directory if missing
|
|
|
|
}
|
2015-08-11 19:31:57 +00:00
|
|
|
#endif
|
2015-08-11 23:57:29 +00:00
|
|
|
SetHomeDir(home);
|
|
|
|
printf("Home dir is: %s\n", GetPath("/").c_str());
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
common_linux_setup();
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
settings.profile.run_counts=0;
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
dc_init(argc,argv);
|
2013-12-19 17:10:14 +00:00
|
|
|
|
2015-08-14 10:06:06 +00:00
|
|
|
SetupInput();
|
|
|
|
|
2015-08-11 23:57:29 +00:00
|
|
|
#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;
|
|
|
|
}
|
2015-04-14 14:58:41 +00:00
|
|
|
#endif
|
2014-03-20 15:13:53 +00:00
|
|
|
|
|
|
|
int get_mic_data(u8* buffer) { return 0; }
|
|
|
|
int push_vmu_screen(u8* buffer) { return 0; }
|
2014-12-30 11:20:51 +00:00
|
|
|
|
|
|
|
void os_DebugBreak()
|
|
|
|
{
|
2015-08-11 23:57:29 +00:00
|
|
|
#if !defined(TARGET_EMSCRIPTEN)
|
2014-12-30 11:20:51 +00:00
|
|
|
raise(SIGTRAP);
|
2015-08-11 23:57:29 +00:00
|
|
|
#else
|
|
|
|
printf("DEBUGBREAK!\n");
|
|
|
|
exit(-1);
|
|
|
|
#endif
|
2014-12-30 11:20:51 +00:00
|
|
|
}
|