redquark-amiberry-rb/src/osdep/amiberry.cpp

957 lines
21 KiB
C++
Raw Normal View History

2015-05-13 18:47:23 +00:00
/*
* UAE - The Un*x Amiga Emulator
*
2017-02-27 14:29:54 +01:00
* Amiberry interface
2015-05-13 18:47:23 +00:00
*
*/
#include <algorithm>
#include <vector>
#include <stdio.h>
2015-05-13 18:47:23 +00:00
#include <stdlib.h>
#include <stdarg.h>
#include <asm/sigcontext.h>
#include <signal.h>
#include "sysconfig.h"
#include "sysdeps.h"
#include "config.h"
#include "autoconf.h"
#include "uae.h"
#include "options.h"
#include "threaddep/thread.h"
2015-05-13 18:47:23 +00:00
#include "gui.h"
#include "include/memory.h"
#include "newcpu.h"
2015-05-13 18:47:23 +00:00
#include "custom.h"
#include "xwin.h"
#include "drawing.h"
#include "inputdevice.h"
#include "keybuf.h"
#include "keyboard.h"
#include "disk.h"
#include "savestate.h"
2015-10-11 14:23:51 +02:00
#include "traps.h"
#include "bsdsocket.h"
#include "blkdev.h"
2015-10-11 14:23:51 +02:00
#include "native2amiga.h"
#include "rtgmodes.h"
#include "uaeresource.h"
#include "rommgr.h"
#include "akiko.h"
2017-01-21 14:54:08 +01:00
#include "SDL.h"
2017-02-27 14:29:54 +01:00
#include "amiberry_rp9.h"
#include <map>
2017-02-28 13:21:37 +01:00
#include "scsidev.h"
2015-05-13 18:47:23 +00:00
extern void signal_segv(int signum, siginfo_t* info, void* ptr);
extern void gui_force_rtarea_hdchange();
2015-05-13 18:47:23 +00:00
extern int loadconfig_old(struct uae_prefs* p, const char* orgpath);
extern void SetLastActiveConfig(const char* filename);
2015-05-13 18:47:23 +00:00
/* Keyboard */
map<int, int> customControlMap; // No SDLK_LAST. SDL2 migration guide suggests std::map
2015-05-13 18:47:23 +00:00
char start_path_data[MAX_DPATH];
char currentDir[MAX_DPATH];
#include <linux/kd.h>
#include <sys/ioctl.h>
2016-11-30 22:30:52 +01:00
unsigned char kbd_led_status;
char kbd_flags;
2015-05-13 18:47:23 +00:00
static char config_path[MAX_DPATH];
static char rom_path[MAX_DPATH];
static char rp9_path[MAX_DPATH];
char last_loaded_config[MAX_DPATH] = {'\0'};
2015-05-13 18:47:23 +00:00
2016-11-30 22:25:43 +01:00
int max_uae_width;
int max_uae_height;
extern "C" int main(int argc, char* argv[]);
2015-05-13 18:47:23 +00:00
void reinit_amiga()
2015-10-11 14:23:51 +02:00
{
write_log("reinit_amiga() called\n");
DISK_free();
#ifdef CD32
akiko_free();
#endif
2015-10-11 14:23:51 +02:00
#ifdef FILESYS
filesys_cleanup();
hardfile_reset();
2015-10-11 14:23:51 +02:00
#endif
#ifdef AUTOCONFIG
#if defined (BSDSOCKET)
bsdlib_reset();
#endif
expansion_cleanup();
2015-10-11 14:23:51 +02:00
#endif
device_func_reset();
memory_cleanup();
currprefs = changed_prefs;
/* force sound settings change */
currprefs.produce_sound = 0;
2015-10-11 14:23:51 +02:00
framecnt = 1;
2015-10-11 14:23:51 +02:00
#ifdef AUTOCONFIG
rtarea_setup();
2015-10-11 14:23:51 +02:00
#endif
#ifdef FILESYS
rtarea_init();
uaeres_install();
hardfile_install();
2015-10-11 14:23:51 +02:00
#endif
keybuf_init();
2015-10-11 14:23:51 +02:00
#ifdef AUTOCONFIG
expansion_init();
2015-10-11 14:23:51 +02:00
#endif
#ifdef FILESYS
filesys_install();
2015-10-11 14:23:51 +02:00
#endif
memory_init();
memory_reset();
2015-10-11 14:23:51 +02:00
#ifdef AUTOCONFIG
#if defined (BSDSOCKET)
bsdlib_install();
#endif
emulib_install();
native2amiga_install();
2015-10-11 14:23:51 +02:00
#endif
custom_init(); /* Must come after memory_init */
DISK_init();
reset_frame_rate_hack();
init_m68k();
2015-10-11 14:23:51 +02:00
}
void sleep_millis_main(int ms)
2015-05-13 18:47:23 +00:00
{
usleep(ms * 1000);
2015-05-13 18:47:23 +00:00
}
void sleep_millis(int ms)
2015-05-13 18:47:23 +00:00
{
usleep(ms * 1000);
2015-05-13 18:47:23 +00:00
}
void logging_init()
2015-05-13 18:47:23 +00:00
{
#ifdef WITH_LOGGING
static int started;
static int first;
char debugfilename[MAX_DPATH];
2015-05-13 18:47:23 +00:00
if (first > 1)
{
write_log ("***** RESTART *****\n");
return;
}
if (first == 1)
{
if (debugfile)
fclose (debugfile);
debugfile = 0;
}
2015-05-13 18:47:23 +00:00
sprintf(debugfilename, "%s/amiberry_log.txt", start_path_data);
if(!debugfile)
debugfile = fopen(debugfilename, "wt");
2015-05-13 18:47:23 +00:00
first++;
write_log ( "Amiberry Logfile\n\n");
2015-05-13 18:47:23 +00:00
#endif
}
void logging_cleanup()
2015-05-13 18:47:23 +00:00
{
#ifdef WITH_LOGGING
if(debugfile)
fclose(debugfile);
debugfile = 0;
2015-05-13 18:47:23 +00:00
#endif
}
void stripslashes(TCHAR* p)
{
while (_tcslen (p) > 0 && (p[_tcslen (p) - 1] == '\\' || p[_tcslen (p) - 1] == '/'))
p[_tcslen (p) - 1] = 0;
}
void fixtrailing(TCHAR* p)
{
if (_tcslen(p) == 0)
return;
if (p[_tcslen(p) - 1] == '/' || p[_tcslen(p) - 1] == '\\')
return;
_tcscat(p, "/");
}
void getpathpart(TCHAR* outpath, int size, const TCHAR* inpath)
{
_tcscpy (outpath, inpath);
TCHAR* p = _tcsrchr (outpath, '/');
if (p)
p[0] = 0;
fixtrailing(outpath);
}
void getfilepart(TCHAR* out, int size, const TCHAR* path)
{
out[0] = 0;
const TCHAR* p = _tcsrchr (path, '/');
if (p)
_tcscpy (out, p + 1);
else
_tcscpy (out, path);
}
uae_u8* target_load_keyfile(struct uae_prefs* p, const char* path, int* sizep, char* name)
2015-10-11 14:23:51 +02:00
{
return nullptr;
2015-10-11 14:23:51 +02:00
}
void target_run()
{
}
void target_quit()
2015-09-09 21:49:41 +02:00
{
}
void target_fixup_options(struct uae_prefs* p)
2015-09-09 21:49:41 +02:00
{
p->rtgmem_type = 1;
if (p->z3fastmem_start != z3_start_adr)
p->z3fastmem_start = z3_start_adr;
p->picasso96_modeflags = RGBFF_CLUT | RGBFF_R5G6B5 | RGBFF_R8G8B8A8;
if (p->gfx_size.width == 0)
p->gfx_size.width = 640;
if (p->gfx_size.height == 0)
p->gfx_size.height == 256;
p->gfx_resolution = p->gfx_size.width > 600 ? 1 : 0;
2015-09-09 21:49:41 +02:00
}
void target_default_options(struct uae_prefs* p, int type)
2015-05-13 18:47:23 +00:00
{
2017-02-27 14:29:54 +01:00
p->amiberry_customControls = 0;
p->picasso96_modeflags = RGBFF_CLUT | RGBFF_R5G6B5 | RGBFF_R8G8B8A8;
2017-02-28 13:21:37 +01:00
p->kbd_led_num = -1; // No status on numlock
p->kbd_led_scr = -1; // No status on scrollock
p->scaling_method = -1; //Default is Auto
p->key_for_menu = SDLK_F12;
p->key_for_quit = 0;
p->button_for_menu = -1;
p->button_for_quit = -1;
2015-05-13 18:47:23 +00:00
}
void target_save_options(struct zfile* f, struct uae_prefs* p)
2015-05-13 18:47:23 +00:00
{
2017-02-28 13:21:37 +01:00
cfgfile_write(f, _T("gfx_correct_aspect"), _T("%d"), p->gfx_correct_aspect);
cfgfile_write(f, _T("kbd_led_num"), _T("%d"), p->kbd_led_num);
cfgfile_write(f, _T("kbd_led_scr"), _T("%d"), p->kbd_led_scr);
cfgfile_write(f, _T("scaling_method"), _T("%d"), p->scaling_method);
cfgfile_write(f, _T("key_for_menu"), _T("%d"), p->key_for_menu);
cfgfile_write(f, _T("key_for_quit"), _T("%d"), p->key_for_quit);
cfgfile_write(f, _T("button_for_menu"), _T("%d"), p->button_for_menu);
cfgfile_write(f, _T("button_for_quit"), _T("%d"), p->button_for_quit);
2017-02-27 14:29:54 +01:00
cfgfile_write(f, "amiberry.custom_controls", "%d", p->amiberry_customControls);
cfgfile_write(f, "amiberry.custom_up", "%d", customControlMap[VK_UP]);
cfgfile_write(f, "amiberry.custom_down", "%d", customControlMap[VK_DOWN]);
cfgfile_write(f, "amiberry.custom_left", "%d", customControlMap[VK_LEFT]);
cfgfile_write(f, "amiberry.custom_right", "%d", customControlMap[VK_RIGHT]);
2017-02-28 13:21:37 +01:00
cfgfile_write(f, "amiberry.custom_a", "%d", customControlMap[VK_Green]);
cfgfile_write(f, "amiberry.custom_b", "%d", customControlMap[VK_Blue]);
cfgfile_write(f, "amiberry.custom_x", "%d", customControlMap[VK_Red]);
cfgfile_write(f, "amiberry.custom_y", "%d", customControlMap[VK_Yellow]);
cfgfile_write(f, "amiberry.custom_l", "%d", customControlMap[VK_LShoulder]);
cfgfile_write(f, "amiberry.custom_r", "%d", customControlMap[VK_RShoulder]);
2017-03-01 00:49:56 +01:00
cfgfile_write(f, "amiberry.custom_play", "%d", customControlMap[VK_Play]);
}
void target_restart()
{
}
TCHAR* target_expand_environment(const TCHAR* path)
{
2017-02-28 13:21:37 +01:00
if (!path)
return nullptr;
return strdup(path);
}
int target_parse_option(struct uae_prefs* p, const char* option, const char* value)
2015-05-13 18:47:23 +00:00
{
2017-02-28 13:21:37 +01:00
if (cfgfile_intval(option, value, "gfx_correct_aspect", &p->gfx_correct_aspect, 1))
return 1;
if (cfgfile_intval(option, value, "kbd_led_num", &p->kbd_led_num, 1))
return 1;
if (cfgfile_intval(option, value, "kbd_led_scr", &p->kbd_led_scr, 1))
return 1;
if (cfgfile_intval(option, value, "scaling_method", &p->scaling_method, 1))
return 1;
if (cfgfile_intval(option, value, "key_for_menu", &p->key_for_menu, 1))
return 1;
if (cfgfile_intval(option, value, "key_for_quit", &p->key_for_quit, 1))
return 1;
if (cfgfile_intval(option, value, "button_for_menu", &p->button_for_menu, 1))
return 1;
if (cfgfile_intval(option, value, "button_for_quit", &p->button_for_quit, 1))
return 1;
int result = cfgfile_intval(option, value, "custom_controls", &p->amiberry_customControls, 1)
|| cfgfile_intval(option, value, "custom_up", &customControlMap[VK_UP], 1)
|| cfgfile_intval(option, value, "custom_down", &customControlMap[VK_DOWN], 1)
|| cfgfile_intval(option, value, "custom_left", &customControlMap[VK_LEFT], 1)
|| cfgfile_intval(option, value, "custom_right", &customControlMap[VK_RIGHT], 1)
|| cfgfile_intval(option, value, "custom_a", &customControlMap[VK_Green], 1)
|| cfgfile_intval(option, value, "custom_b", &customControlMap[VK_Blue], 1)
|| cfgfile_intval(option, value, "custom_x", &customControlMap[VK_Red], 1)
|| cfgfile_intval(option, value, "custom_y", &customControlMap[VK_Yellow], 1)
|| cfgfile_intval(option, value, "custom_l", &customControlMap[VK_LShoulder], 1)
|| cfgfile_intval(option, value, "custom_r", &customControlMap[VK_RShoulder], 1)
2017-03-01 00:49:56 +01:00
|| cfgfile_intval(option, value, "custom_play", &customControlMap[VK_Play], 1);
return result;
2015-05-13 18:47:23 +00:00
}
void fetch_datapath(char* out, int size)
{
strncpy(out, start_path_data, size);
strncat(out, "/", size);
}
void fetch_saveimagepath(char* out, int size, int dir)
2015-10-11 14:23:51 +02:00
{
strncpy(out, start_path_data, size);
strncat(out, "/savestates/", size);
2015-10-11 14:23:51 +02:00
}
void fetch_configurationpath(char* out, int size)
2015-05-13 18:47:23 +00:00
{
strncpy(out, config_path, size);
2015-05-13 18:47:23 +00:00
}
void set_configurationpath(char* newpath)
2015-05-13 18:47:23 +00:00
{
strncpy(config_path, newpath, MAX_DPATH);
2015-05-13 18:47:23 +00:00
}
void fetch_rompath(char* out, int size)
2015-05-13 18:47:23 +00:00
{
strncpy(out, rom_path, size);
2015-05-13 18:47:23 +00:00
}
void set_rompath(char* newpath)
2015-05-13 18:47:23 +00:00
{
strncpy(rom_path, newpath, MAX_DPATH);
2015-05-13 18:47:23 +00:00
}
void fetch_rp9path(char* out, int size)
{
strncpy(out, rp9_path, size);
}
void fetch_statefilepath(char* out, int size)
2015-05-13 18:47:23 +00:00
{
strncpy(out, start_path_data, size);
strncat(out, "/savestates/", size);
2015-05-13 18:47:23 +00:00
}
void fetch_screenshotpath(char* out, int size)
2015-05-13 18:47:23 +00:00
{
strncpy(out, start_path_data, size);
strncat(out, "/screenshots/", size);
2015-05-13 18:47:23 +00:00
}
int target_cfgfile_load(struct uae_prefs* p, const char* filename, int type, int isdefault)
2015-05-13 18:47:23 +00:00
{
int i;
int result = 0;
if (emulating && changed_prefs.cdslots[0].inuse)
gui_force_rtarea_hdchange();
discard_prefs(p, type);
default_prefs(p, 0);
const char* ptr = strstr(filename, ".rp9");
if (ptr > nullptr)
{
// Load rp9 config
result = rp9_parse_file(p, filename);
if (result)
extractFileName(filename, last_loaded_config);
}
else
{
ptr = strstr(filename, ".uae");
if (ptr > nullptr)
{
int type = CONFIG_TYPE_HARDWARE | CONFIG_TYPE_HOST;
result = cfgfile_load(p, filename, &type, 0, 1);
}
if (result)
extractFileName(filename, last_loaded_config);
else
result = loadconfig_old(p, filename);
}
if (result)
{
for (i = 0; i < p->nr_floppies; ++i)
{
2017-01-29 13:24:39 +01:00
if (!DISK_validate_filename(p, p->floppyslots[i].df, 0, nullptr, nullptr, nullptr))
p->floppyslots[i].df[0] = 0;
disk_insert(i, p->floppyslots[i].df);
if (strlen(p->floppyslots[i].df) > 0)
AddFileToDiskList(p->floppyslots[i].df, 1);
}
if (!isdefault)
2017-01-29 13:24:39 +01:00
inputdevice_updateconfig(nullptr, p);
SetLastActiveConfig(filename);
if (count_HDs(p) > 0) // When loading a config with HDs, always do a hardreset
gui_force_rtarea_hdchange();
}
return result;
2015-05-13 18:47:23 +00:00
}
int check_configfile(char* file)
2015-05-13 18:47:23 +00:00
{
char tmp[MAX_PATH];
2017-01-29 13:24:39 +01:00
FILE* f = fopen(file, "rt");
if (f)
{
fclose(f);
return 1;
}
strcpy(tmp, file);
char* ptr = strstr(tmp, ".uae");
if (ptr > nullptr)
{
*(ptr + 1) = '\0';
strcat(tmp, "conf");
f = fopen(tmp, "rt");
if (f)
{
fclose(f);
return 2;
}
}
return 0;
2015-05-13 18:47:23 +00:00
}
void extractFileName(const char* str, char* buffer)
2015-05-13 18:47:23 +00:00
{
const char* p = str + strlen(str) - 1;
while (*p != '/' && p > str)
p--;
p++;
strcpy(buffer, p);
2015-05-13 18:47:23 +00:00
}
void extractPath(char* str, char* buffer)
2015-05-13 18:47:23 +00:00
{
strcpy(buffer, str);
char* p = buffer + strlen(buffer) - 1;
while (*p != '/' && p > buffer)
p--;
p[1] = '\0';
2015-05-13 18:47:23 +00:00
}
void removeFileExtension(char* filename)
2015-05-13 18:47:23 +00:00
{
char* p = filename + strlen(filename) - 1;
while (p > filename && *p != '.')
{
*p = '\0';
--p;
}
*p = '\0';
2015-05-13 18:47:23 +00:00
}
2017-01-29 13:24:39 +01:00
void ReadDirectory(const char* path, vector<string>* dirs, vector<string>* files)
2015-05-13 18:47:23 +00:00
{
DIR* dir;
struct dirent* dent;
2017-01-29 13:24:39 +01:00
if (dirs != nullptr)
dirs->clear();
2017-01-29 13:24:39 +01:00
if (files != nullptr)
files->clear();
dir = opendir(path);
2017-01-29 13:24:39 +01:00
if (dir != nullptr)
{
2017-01-29 13:24:39 +01:00
while ((dent = readdir(dir)) != nullptr)
{
if (dent->d_type == DT_DIR)
{
2017-01-29 13:24:39 +01:00
if (dirs != nullptr)
dirs->push_back(dent->d_name);
}
2017-01-29 13:24:39 +01:00
else if (files != nullptr)
files->push_back(dent->d_name);
}
2017-01-29 13:24:39 +01:00
if (dirs != nullptr && dirs->size() > 0 && (*dirs)[0] == ".")
dirs->erase(dirs->begin());
closedir(dir);
}
2017-01-29 13:24:39 +01:00
if (dirs != nullptr)
std::sort(dirs->begin(), dirs->end());
2017-01-29 13:24:39 +01:00
if (files != nullptr)
std::sort(files->begin(), files->end());
2015-05-13 18:47:23 +00:00
}
2017-01-29 13:24:39 +01:00
void saveAdfDir()
2015-05-13 18:47:23 +00:00
{
char path[MAX_DPATH];
int i;
snprintf(path, MAX_DPATH, "%s/conf/adfdir.conf", start_path_data);
2017-01-29 13:24:39 +01:00
FILE* f = fopen(path, "w");
if (!f)
return;
char buffer[MAX_DPATH];
snprintf(buffer, MAX_DPATH, "path=%s\n", currentDir);
fputs(buffer, f);
snprintf(buffer, MAX_DPATH, "config_path=%s\n", config_path);
fputs(buffer, f);
snprintf(buffer, MAX_DPATH, "rom_path=%s\n", rom_path);
fputs(buffer, f);
snprintf(buffer, MAX_DPATH, "ROMs=%d\n", lstAvailableROMs.size());
fputs(buffer, f);
for (i = 0; i < lstAvailableROMs.size(); ++i)
{
snprintf(buffer, MAX_DPATH, "ROMName=%s\n", lstAvailableROMs[i]->Name);
fputs(buffer, f);
snprintf(buffer, MAX_DPATH, "ROMPath=%s\n", lstAvailableROMs[i]->Path);
fputs(buffer, f);
snprintf(buffer, MAX_DPATH, "ROMType=%d\n", lstAvailableROMs[i]->ROMType);
fputs(buffer, f);
}
snprintf(buffer, MAX_DPATH, "MRUDiskList=%d\n", lstMRUDiskList.size());
fputs(buffer, f);
for (i = 0; i < lstMRUDiskList.size(); ++i)
{
snprintf(buffer, MAX_DPATH, "Diskfile=%s\n", lstMRUDiskList[i].c_str());
fputs(buffer, f);
}
snprintf(buffer, MAX_DPATH, "MRUCDList=%d\n", lstMRUCDList.size());
fputs(buffer, f);
for (i = 0; i < lstMRUCDList.size(); ++i)
{
snprintf(buffer, MAX_DPATH, "CDfile=%s\n", lstMRUCDList[i].c_str());
fputs(buffer, f);
}
fclose(f);
2015-05-13 18:47:23 +00:00
}
void get_string(FILE* f, char* dst, int size)
2015-05-13 18:47:23 +00:00
{
char buffer[MAX_PATH];
fgets(buffer, MAX_PATH, f);
int i = strlen(buffer);
while (i > 0 && (buffer[i - 1] == '\t' || buffer[i - 1] == ' '
|| buffer[i - 1] == '\r' || buffer[i - 1] == '\n'))
buffer[--i] = '\0';
strncpy(dst, buffer, size);
2015-05-13 18:47:23 +00:00
}
2017-01-29 13:24:39 +01:00
void loadAdfDir()
2015-05-13 18:47:23 +00:00
{
char path[MAX_DPATH];
int i;
2015-05-13 18:47:23 +00:00
strcpy(currentDir, start_path_data);
snprintf(config_path, MAX_DPATH, "%s/conf/", start_path_data);
snprintf(rom_path, MAX_DPATH, "%s/kickstarts/", start_path_data);
snprintf(rp9_path, MAX_DPATH, "%s/rp9/", start_path_data);
snprintf(path, MAX_DPATH, "%s/conf/adfdir.conf", start_path_data);
2017-01-29 13:24:39 +01:00
FILE* f1 = fopen(path, "rt");
if (f1)
{
fscanf(f1, "path=");
get_string(f1, currentDir, sizeof(currentDir));
if (!feof(f1))
{
fscanf(f1, "config_path=");
get_string(f1, config_path, sizeof(config_path));
fscanf(f1, "rom_path=");
get_string(f1, rom_path, sizeof(rom_path));
int numROMs;
fscanf(f1, "ROMs=%d\n", &numROMs);
for (i = 0; i < numROMs; ++i)
{
AvailableROM* tmp;
tmp = new AvailableROM();
fscanf(f1, "ROMName=");
get_string(f1, tmp->Name, sizeof(tmp->Name));
fscanf(f1, "ROMPath=");
get_string(f1, tmp->Path, sizeof(tmp->Path));
fscanf(f1, "ROMType=%d\n", &(tmp->ROMType));
lstAvailableROMs.push_back(tmp);
}
lstMRUDiskList.clear();
int numDisks = 0;
char disk[MAX_PATH];
fscanf(f1, "MRUDiskList=%d\n", &numDisks);
for (i = 0; i < numDisks; ++i)
{
fscanf(f1, "Diskfile=");
get_string(f1, disk, sizeof(disk));
FILE * f = fopen(disk, "rb");
if (f != NULL)
{
fclose(f);
lstMRUDiskList.push_back(disk);
}
}
2015-05-13 18:47:23 +00:00
lstMRUCDList.clear();
int numCD = 0;
char cd[MAX_PATH];
fscanf(f1, "MRUCDList=%d\n", &numCD);
for (i = 0; i < numCD; ++i)
{
fscanf(f1, "CDfile=");
get_string(f1, cd, sizeof(cd));
FILE * f = fopen(cd, "rb");
if (f != NULL)
{
fclose(f);
lstMRUCDList.push_back(cd);
}
}
}
fclose(f1);
}
}
2015-05-13 18:47:23 +00:00
void target_reset()
{
}
uae_u32 emulib_target_getcpurate(uae_u32 v, uae_u32* low)
{
*low = 0;
if (v == 1)
{
*low = 1e+9; /* We have nano seconds */
return 0;
}
2017-01-29 13:24:39 +01:00
if (v == 2)
{
int64_t time;
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
time = (int64_t(ts.tv_sec) * 1000000000) + ts.tv_nsec;
*low = uae_u32(time & 0xffffffff);
return uae_u32(time >> 32);
}
return 0;
}
int main(int argc, char* argv[])
2015-05-13 18:47:23 +00:00
{
struct sigaction action;
max_uae_width = 1920;
max_uae_height = 1080;
// Get startup path
getcwd(start_path_data, MAX_DPATH);
loadAdfDir();
rp9_init();
snprintf(savestate_fname, MAX_PATH, "%s/saves/default.ads", start_path_data);
logging_init();
memset(&action, 0, sizeof(action));
action.sa_sigaction = signal_segv;
action.sa_flags = SA_SIGINFO;
2017-01-29 13:24:39 +01:00
if (sigaction(SIGSEGV, &action, nullptr) < 0)
{
printf("Failed to set signal handler (SIGSEGV).\n");
abort();
}
2017-01-29 13:24:39 +01:00
if (sigaction(SIGILL, &action, nullptr) < 0)
{
printf("Failed to set signal handler (SIGILL).\n");
abort();
}
alloc_AmigaMem();
RescanROMs();
keyboard_settrans();
2016-08-29 20:08:05 +02:00
#ifdef CAPSLOCK_DEBIAN_WORKAROUND
// set capslock state based upon current "real" state
ioctl(0, KDGKBLED, &kbd_flags);
ioctl(0, KDGETLED, &kbd_led_status);
2017-03-01 13:23:32 +01:00
if (kbd_flags & 07 & LED_CAP)
{
// record capslock pressed
kbd_led_status |= LED_CAP;
inputdevice_do_keyboard(AK_CAPSLOCK, 1);
}
else
{
// record capslock as not pressed
kbd_led_status &= ~LED_CAP;
inputdevice_do_keyboard(AK_CAPSLOCK, 0);
}
ioctl(0, KDSETLED, kbd_led_status);
2016-08-29 20:08:05 +02:00
#endif
real_main(argc, argv);
2016-11-30 22:25:43 +01:00
#ifdef CAPSLOCK_DEBIAN_WORKAROUND
// restore keyboard LEDs to normal state
ioctl(0, KDSETLED, 0xFF);
2016-11-30 22:25:43 +01:00
#endif
ClearAvailableROMList();
romlist_clear();
free_keyring();
free_AmigaMem();
lstMRUDiskList.clear();
lstMRUCDList.clear();
rp9_cleanup();
2015-05-13 18:47:23 +00:00
logging_cleanup();
return 0;
}
2015-05-13 18:47:23 +00:00
int handle_msgpump()
2015-05-13 18:47:23 +00:00
{
int got = 0;
SDL_Event rEvent;
int keycode;
while (SDL_PollEvent(&rEvent))
{
got = 1;
2017-01-29 13:24:39 +01:00
const Uint8* keystate = SDL_GetKeyboardState(nullptr);
switch (rEvent.type)
{
case SDL_QUIT:
uae_quit();
break;
case SDL_JOYBUTTONDOWN:
if (currprefs.button_for_menu != -1 && rEvent.jbutton.button == currprefs.button_for_menu)
inputdevice_add_inputcode(AKS_ENTERGUI, 1);
if (currprefs.button_for_quit != -1 && rEvent.jbutton.button == currprefs.button_for_quit)
inputdevice_add_inputcode(AKS_QUIT, 1);
break;
case SDL_KEYDOWN:
if (keystate[SDL_SCANCODE_LCTRL] && keystate[SDL_SCANCODE_LGUI] && (keystate[SDL_SCANCODE_RGUI] || keystate[SDL_SCANCODE_APPLICATION]))
{
uae_reset(0, 1);
break;
}
2017-02-28 13:21:37 +01:00
switch (rEvent.key.keysym.sym)
{
2017-02-28 13:21:37 +01:00
case SDLK_NUMLOCKCLEAR:
if (currprefs.keyboard_leds[KBLED_NUMLOCKB] > 0)
{
//oldleds ^= KBLED_NUMLOCKM;
//ch = true;
}
break;
2017-02-28 13:21:37 +01:00
case SDLK_CAPSLOCK: // capslock
if (currprefs.keyboard_leds[KBLED_CAPSLOCKB] > 0)
{
//oldleds ^= KBLED_CAPSLOCKM;
//ch = true;
}
// Treat CAPSLOCK as a toggle. If on, set off and vice/versa
ioctl(0, KDGKBLED, &kbd_flags);
ioctl(0, KDGETLED, &kbd_led_status);
if ((kbd_flags & 07) & LED_CAP)
{
// On, so turn off
kbd_led_status &= ~LED_CAP;
kbd_flags &= ~LED_CAP;
inputdevice_do_keyboard(AK_CAPSLOCK, 0);
}
else
{
// Off, so turn on
kbd_led_status |= LED_CAP;
kbd_flags |= LED_CAP;
inputdevice_do_keyboard(AK_CAPSLOCK, 1);
}
ioctl(0, KDSETLED, kbd_led_status);
ioctl(0, KDSKBLED, kbd_flags);
break;
2017-02-28 13:21:37 +01:00
case SDLK_SCROLLLOCK:
if (currprefs.keyboard_leds[KBLED_SCROLLLOCKB] > 0)
{
//oldleds ^= KBLED_SCROLLLOCKM;
//ch = true;
}
break;
default:
if (currprefs.amiberry_customControls)
{
keycode = customControlMap[rEvent.key.keysym.sym];
if (keycode < 0)
{
// Simulate mouse or joystick
SimulateMouseOrJoy(keycode, 1);
break;
}
2017-02-28 13:21:37 +01:00
if (keycode > 0)
{
// Send mapped key press
inputdevice_do_keyboard(keycode, 1);
break;
}
}
translate_amiberry_keys(rEvent.key.keysym.sym, 1);
break;
}
break;
case SDL_KEYUP:
if (currprefs.amiberry_customControls)
{
keycode = customControlMap[rEvent.key.keysym.sym];
if (keycode < 0)
{
// Simulate mouse or joystick
SimulateMouseOrJoy(keycode, 0);
break;
}
2017-02-28 13:21:37 +01:00
if (keycode > 0)
{
// Send mapped key release
inputdevice_do_keyboard(keycode, 0);
break;
}
}
translate_amiberry_keys(rEvent.key.keysym.sym, 0);
break;
case SDL_MOUSEBUTTONDOWN:
if (currprefs.jports[0].id == JSEM_MICE || currprefs.jports[1].id == JSEM_MICE)
{
if (rEvent.button.button == SDL_BUTTON_LEFT)
2017-02-28 23:05:10 +01:00
setmousebuttonstate(0, 0, 1);
if (rEvent.button.button == SDL_BUTTON_RIGHT)
setmousebuttonstate(0, 1, 1);
2017-02-28 23:05:10 +01:00
if (rEvent.button.button == SDL_BUTTON_MIDDLE)
2017-02-28 16:05:32 +01:00
setmousebuttonstate(0, 2, 1);
}
break;
case SDL_MOUSEBUTTONUP:
if (currprefs.jports[0].id == JSEM_MICE || currprefs.jports[1].id == JSEM_MICE)
{
if (rEvent.button.button == SDL_BUTTON_LEFT)
2017-02-28 23:05:10 +01:00
setmousebuttonstate(0, 0, 0);
if (rEvent.button.button == SDL_BUTTON_RIGHT)
setmousebuttonstate(0, 1, 0);
2017-02-28 23:05:10 +01:00
if (rEvent.button.button == SDL_BUTTON_MIDDLE)
2017-02-28 16:05:32 +01:00
setmousebuttonstate(0, 2, 0);
}
break;
case SDL_MOUSEMOTION:
if (currprefs.input_tablet == TABLET_OFF)
{
if (currprefs.jports[0].id == JSEM_MICE || currprefs.jports[1].id == JSEM_MICE)
{
int x, y;
int mouseScale = currprefs.input_joymouse_multiplier / 2;
x = rEvent.motion.xrel;
y = rEvent.motion.yrel;
2017-01-29 13:24:39 +01:00
setmousestate(0, 0, x * mouseScale, 0);
setmousestate(0, 1, y * mouseScale, 0);
}
}
break;
case SDL_MOUSEWHEEL:
if (currprefs.jports[0].id == JSEM_MICE || currprefs.jports[1].id == JSEM_MICE)
{
int valY = rEvent.wheel.y;
int valX = rEvent.wheel.x;
setmousestate(0, 2, valY, 0);
setmousestate(0, 3, valX, 0);
}
break;
}
}
return got;
}
static uaecptr clipboard_data;
void amiga_clipboard_die()
{
}
void amiga_clipboard_init()
{
}
void amiga_clipboard_task_start(uaecptr data)
{
clipboard_data = data;
}
uae_u32 amiga_clipboard_proc_start()
{
return clipboard_data;
}
void amiga_clipboard_got_data(uaecptr data, uae_u32 size, uae_u32 actual)
{
}
int amiga_clipboard_want_data()
{
return 0;
}
void clipboard_vsync()
2015-05-13 18:47:23 +00:00
{
}