Code cleanup, simplification and modernization
This commit is contained in:
parent
66a2956a76
commit
342d2e4c2c
6 changed files with 73 additions and 113 deletions
|
@ -43,13 +43,13 @@
|
|||
#define _vsnprintf vsnprintf
|
||||
#define _vsntprintf vsnprintf
|
||||
|
||||
static inline size_t uae_tcslcpy(char *dst, const TCHAR *src, size_t size)
|
||||
static size_t uae_tcslcpy(char *dst, const TCHAR *src, size_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
size_t src_len = _tcslen(src);
|
||||
size_t cpy_len = src_len;
|
||||
const auto src_len = _tcslen(src);
|
||||
auto cpy_len = src_len;
|
||||
if (cpy_len >= size) {
|
||||
cpy_len = size - 1;
|
||||
}
|
||||
|
@ -58,13 +58,13 @@ static inline size_t uae_tcslcpy(char *dst, const TCHAR *src, size_t size)
|
|||
return src_len;
|
||||
}
|
||||
|
||||
static inline size_t uae_strlcpy(char *dst, const char *src, size_t size)
|
||||
static size_t uae_strlcpy(char *dst, const char *src, size_t size)
|
||||
{
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
size_t src_len = strlen(src);
|
||||
size_t cpy_len = src_len;
|
||||
const auto src_len = strlen(src);
|
||||
auto cpy_len = src_len;
|
||||
if (cpy_len >= size) {
|
||||
cpy_len = size - 1;
|
||||
}
|
||||
|
|
|
@ -14,26 +14,24 @@ typedef unsigned long frame_time_t;
|
|||
extern int64_t g_uae_epoch;
|
||||
|
||||
/* Returns elapsed time in microseconds since start of emulator. */
|
||||
static __inline__ frame_time_t read_processor_time (void)
|
||||
static frame_time_t read_processor_time()
|
||||
{
|
||||
int64_t time;
|
||||
struct timespec ts;
|
||||
struct timespec ts {};
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &ts);
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
time = (((int64_t) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
|
||||
const int64_t time = int64_t(ts.tv_sec) * 1000000 + ts.tv_nsec / 1000;
|
||||
return time - g_uae_epoch;
|
||||
}
|
||||
|
||||
|
||||
static __inline__ int64_t read_processor_time_ns (void)
|
||||
static int64_t read_processor_time_ns()
|
||||
{
|
||||
int64_t time;
|
||||
struct timespec ts;
|
||||
struct timespec ts{};
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, &ts);
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
|
||||
time = (((int64_t) ts.tv_sec) * 1000000 * 1000) + (ts.tv_nsec);
|
||||
const int64_t time = int64_t(ts.tv_sec) * 1000000 * 1000 + ts.tv_nsec;
|
||||
return time;
|
||||
}
|
||||
|
||||
|
|
|
@ -391,9 +391,8 @@ void target_restart(void)
|
|||
TCHAR *target_expand_environment(const TCHAR *path, TCHAR *out, int maxlen)
|
||||
{
|
||||
if (out == nullptr)
|
||||
{
|
||||
return strdup(path);
|
||||
}
|
||||
|
||||
_tcscpy(out, path);
|
||||
return out;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
#endif
|
||||
|
||||
int emulating = 0;
|
||||
|
||||
extern int screen_is_picasso;
|
||||
struct uae_prefs workprefs;
|
||||
|
||||
struct gui_msg
|
||||
|
|
|
@ -298,6 +298,7 @@ static int acquire_mouse(const int num, int flags)
|
|||
{
|
||||
if (num >= 0 && num < numMice)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -314,6 +315,7 @@ static const TCHAR* get_mouse_friendlyname(const int mouse)
|
|||
{
|
||||
if (numMice > 0 && mouse == 0)
|
||||
return "Mouse";
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -321,15 +323,15 @@ static const TCHAR* get_mouse_uniquename(const int mouse)
|
|||
{
|
||||
if (numMice > 0 && mouse == 0)
|
||||
return "MOUSE0";
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
static int get_mouse_widget_num(const int mouse)
|
||||
{
|
||||
if (numMice > 0 && mouse == 0)
|
||||
{
|
||||
return MAX_MOUSE_AXES + MAX_MOUSE_BUTTONS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -360,6 +362,7 @@ static int get_mouse_widget_type(const int mouse, const int num, TCHAR* name, ua
|
|||
{
|
||||
if (name)
|
||||
sprintf(name, "Button %d", num + 1 - MAX_MOUSE_AXES);
|
||||
|
||||
return IDEV_WIDGET_BUTTON;
|
||||
}
|
||||
if (num < MAX_MOUSE_AXES)
|
||||
|
@ -506,9 +509,8 @@ struct inputdevice_functions inputdevicefunc_keyboard = {
|
|||
int input_get_default_keyboard(int num)
|
||||
{
|
||||
if (num == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -544,21 +546,16 @@ int find_retroarch(const TCHAR* find_setting, char* retroarch_file, host_input_b
|
|||
|
||||
// remove leading "
|
||||
if (param.at(0) == '"')
|
||||
{
|
||||
param.erase(0, 1);
|
||||
}
|
||||
|
||||
// remove trailing "
|
||||
if (param.at(param.length() - 1) == '"')
|
||||
{
|
||||
param.erase(param.length() - 1, 1);
|
||||
}
|
||||
|
||||
// time to get the output number
|
||||
if (param.at(0) != 'h') // check it isnt some kind of hat starting 'h' (so if D-pad uses buttons)
|
||||
{
|
||||
tempbutton = abs(atol(param.c_str()));
|
||||
} // gets the parameter
|
||||
// gets the parameter
|
||||
|
||||
// this will need something separate to pull out the number of hats
|
||||
// use SET_BIT on hX numbers
|
||||
|
@ -573,15 +570,12 @@ int find_retroarch(const TCHAR* find_setting, char* retroarch_file, host_input_b
|
|||
|
||||
// ok, this is the 'normal' storing of values
|
||||
if (option == find_setting)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (strncmp(find_setting, "count_hats", 11) != 0)
|
||||
{
|
||||
tempbutton = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
readFile.close();
|
||||
|
||||
return tempbutton;
|
||||
|
@ -605,27 +599,22 @@ const TCHAR* find_retroarch_key(const TCHAR* find_setting, char* retroarch_file)
|
|||
if (option != line) // exit if we got no result from splitting the string
|
||||
{
|
||||
// using the " = " to work out whis is the option, and which is the parameter.
|
||||
string param = line.substr(line.find(delimiter) + delimiter.length(), line.length());
|
||||
auto param = line.substr(line.find(delimiter) + delimiter.length(), line.length());
|
||||
|
||||
// remove leading "
|
||||
if (param.at(0) == '"')
|
||||
{
|
||||
param.erase(0, 1);
|
||||
}
|
||||
|
||||
// remove trailing "
|
||||
if (param.at(param.length() - 1) == '"')
|
||||
{
|
||||
param.erase(param.length() - 1, 1);
|
||||
}
|
||||
|
||||
output = ¶m[0u];
|
||||
|
||||
// ok, this is the 'normal' storing of values
|
||||
if (option == find_setting)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
output = "nul";
|
||||
}
|
||||
}
|
||||
|
@ -673,42 +662,55 @@ static int init_joystick(void)
|
|||
auto tempkey = find_retroarch_key("input_player1_y", retroarch_file);
|
||||
auto x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.north_button = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_a", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.east_button = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_b", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.south_button = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_x", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.west_button = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_left", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.dpad_left = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_right", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.dpad_right = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_up", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.dpad_up = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_down", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.dpad_down = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_l", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.left_shoulder = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_r", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.right_shoulder = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_select", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.select_button = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_start", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.start_button = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_l3", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.lstick_button = RemapKeyMapList[x];
|
||||
|
||||
tempkey = find_retroarch_key("input_player1_r3", retroarch_file);
|
||||
x = find_string_in_array(RemapKeyMapListStrings, RemapKeyMapListSize, tempkey);
|
||||
temp_keyboard_buttons.rstick_button = RemapKeyMapList[x];
|
||||
|
@ -803,16 +805,12 @@ static int init_joystick(void)
|
|||
host_input_buttons[cpt].lstick_axis_x = find_retroarch("input_l_x_plus_axis", ControlConfig,
|
||||
host_input_buttons[cpt]);
|
||||
if (host_input_buttons[cpt].lstick_axis_x == -1)
|
||||
{
|
||||
host_input_buttons[cpt].lstick_axis_x = find_retroarch("input_right_axis", ControlConfig, host_input_buttons[cpt]);
|
||||
}
|
||||
|
||||
host_input_buttons[cpt].lstick_axis_y = find_retroarch("input_l_y_plus_axis", ControlConfig,
|
||||
host_input_buttons[cpt]);
|
||||
if (host_input_buttons[cpt].lstick_axis_y == -1)
|
||||
{
|
||||
host_input_buttons[cpt].lstick_axis_y = find_retroarch("input_down_axis", ControlConfig, host_input_buttons[cpt]);
|
||||
}
|
||||
|
||||
host_input_buttons[cpt].rstick_axis_x = find_retroarch("input_r_x_plus_axis", ControlConfig,
|
||||
host_input_buttons[cpt]);
|
||||
|
@ -1037,70 +1035,37 @@ static void read_joystick(void)
|
|||
current_controller_map = host_input_buttons[hostjoyid];
|
||||
|
||||
if (current_controller_map.east_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.east_button = -1;
|
||||
}
|
||||
if (current_controller_map.south_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.south_button = -1;
|
||||
}
|
||||
if (current_controller_map.north_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.north_button = -1;
|
||||
}
|
||||
if (current_controller_map.west_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.west_button = -1;
|
||||
}
|
||||
if (current_controller_map.dpad_left == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.dpad_left = -1;
|
||||
}
|
||||
if (current_controller_map.dpad_right == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.dpad_right = -1;
|
||||
}
|
||||
if (current_controller_map.dpad_up == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.dpad_up = -1;
|
||||
}
|
||||
if (current_controller_map.dpad_down == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.dpad_down = -1;
|
||||
}
|
||||
if (current_controller_map.select_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.select_button = -1;
|
||||
}
|
||||
if (current_controller_map.start_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.start_button = -1;
|
||||
}
|
||||
if (current_controller_map.left_trigger == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.left_trigger = -1;
|
||||
}
|
||||
if (current_controller_map.right_trigger == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.right_trigger = -1;
|
||||
}
|
||||
if (current_controller_map.lstick_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.lstick_button = -1;
|
||||
}
|
||||
if (current_controller_map.rstick_button == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.rstick_button = -1;
|
||||
}
|
||||
|
||||
if (current_controller_map.left_shoulder == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.left_shoulder = -1;
|
||||
}
|
||||
if (current_controller_map.right_shoulder == current_controller_map.hotkey_button)
|
||||
{
|
||||
current_controller_map.right_shoulder = -1;
|
||||
}
|
||||
|
||||
|
||||
// left stick
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
* UAE - The Un*x Amiga Emulator
|
||||
*
|
||||
* Threading support, using SDL
|
||||
*
|
||||
* Copyright 1997, 2001 Bernd Schmidt
|
||||
*/
|
||||
/*
|
||||
* UAE - The Un*x Amiga Emulator
|
||||
*
|
||||
* Threading support, using SDL
|
||||
*
|
||||
* Copyright 1997, 2001 Bernd Schmidt
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <SDL.h>
|
||||
#include <SDL_thread.h>
|
||||
|
||||
/* Sempahores. We use POSIX semaphores; if you are porting this to a machine
|
||||
* with different ones, make them look like POSIX semaphores. */
|
||||
* with different ones, make them look like POSIX semaphores. */
|
||||
typedef SDL_sem *uae_sem_t;
|
||||
|
||||
STATIC_INLINE int uae_sem_init(uae_sem_t *sem, int dummy, int init)
|
||||
{
|
||||
*sem = SDL_CreateSemaphore (init);
|
||||
*sem = SDL_CreateSemaphore(init);
|
||||
return (*sem == nullptr);
|
||||
}
|
||||
|
||||
|
@ -31,51 +31,51 @@ STATIC_INLINE int uae_sem_init(uae_sem_t *sem, int dummy, int init)
|
|||
typedef SDL_Thread *uae_thread_id;
|
||||
#define BAD_THREAD 0
|
||||
|
||||
STATIC_INLINE void uae_set_thread_priority (uae_thread_id *id, int pri)
|
||||
STATIC_INLINE void uae_set_thread_priority(uae_thread_id *id, int pri)
|
||||
{
|
||||
}
|
||||
|
||||
STATIC_INLINE void uae_end_thread (uae_thread_id *tid)
|
||||
STATIC_INLINE void uae_end_thread(uae_thread_id *tid)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef USE_SDL1
|
||||
STATIC_INLINE int uae_start_thread (const TCHAR *name, void *(*f) (void *), void *arg, uae_thread_id *foo)
|
||||
STATIC_INLINE int uae_start_thread(const TCHAR *name, void *(*f) (void *), void *arg, uae_thread_id *foo)
|
||||
{
|
||||
uae_thread_id id = SDL_CreateThread ((int (*)(void *))f, arg);
|
||||
if(foo != NULL)
|
||||
auto id = SDL_CreateThread(reinterpret_cast<int(*)(void*)>(f), arg);
|
||||
if (foo != nullptr)
|
||||
*foo = id;
|
||||
return (int)id;
|
||||
return int(id);
|
||||
}
|
||||
|
||||
STATIC_INLINE int uae_start_thread_fast (void *(*f) (void *), void *arg, uae_thread_id *foo)
|
||||
STATIC_INLINE int uae_start_thread_fast(void *(*f) (void *), void *arg, uae_thread_id *foo)
|
||||
{
|
||||
uae_thread_id id = SDL_CreateThread ((int (*)(void *))f, arg);
|
||||
if(foo != NULL)
|
||||
auto id = SDL_CreateThread(reinterpret_cast<int(*)(void*)>(f), arg);
|
||||
if (foo != nullptr)
|
||||
*foo = id;
|
||||
return (int)id;
|
||||
return int(id);
|
||||
}
|
||||
#elif USE_SDL2
|
||||
STATIC_INLINE uae_thread_id uae_start_thread(const TCHAR* name, void*(*f)(void*), void* arg, uae_thread_id* foo)
|
||||
{
|
||||
uae_thread_id id = SDL_CreateThread (reinterpret_cast<int (*)(void*)>(f), "StartThread", arg);
|
||||
if(foo != NULL)
|
||||
uae_thread_id id = SDL_CreateThread(reinterpret_cast<int(*)(void*)>(f), "StartThread", arg);
|
||||
if (foo != NULL)
|
||||
*foo = id;
|
||||
return id;
|
||||
}
|
||||
|
||||
STATIC_INLINE uae_thread_id uae_start_thread_fast(void*(*f)(void*), void* arg, uae_thread_id* foo)
|
||||
{
|
||||
uae_thread_id id = SDL_CreateThread (reinterpret_cast<int (*)(void*)>(f), "StartThreadFast", arg);
|
||||
if(foo != NULL)
|
||||
uae_thread_id id = SDL_CreateThread(reinterpret_cast<int(*)(void*)>(f), "StartThreadFast", arg);
|
||||
if (foo != NULL)
|
||||
*foo = id;
|
||||
return id;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC_INLINE void uae_wait_thread (uae_thread_id thread)
|
||||
STATIC_INLINE void uae_wait_thread(uae_thread_id thread)
|
||||
{
|
||||
SDL_WaitThread (thread, static_cast<int*>(0));
|
||||
SDL_WaitThread(thread, static_cast<int*>(nullptr));
|
||||
}
|
||||
|
||||
/* Do nothing; thread exits if thread function returns. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue