mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-08-20 07:28:02 +00:00
Refactor classic interface to run within its own thread
* previously this classic interface acted as an oldschool modal dialog (which worked fine with the X11 renderer where we actively pumped the event loop)
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
bool in_interface = false;
|
||||||
|
|
||||||
static struct stat statbuf;
|
static struct stat statbuf;
|
||||||
static int altdrive;
|
static int altdrive;
|
||||||
|
|
||||||
@@ -1539,3 +1541,74 @@ void c_interface_keyboard_layout()
|
|||||||
c_interface_exit(ch);
|
c_interface_exit(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------
|
||||||
|
c_interface_begin()
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void *interface_thread(void *current_key)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&interface_mutex);
|
||||||
|
#ifdef AUDIO_ENABLED
|
||||||
|
SoundSystemPause();
|
||||||
|
#endif
|
||||||
|
in_interface = true;
|
||||||
|
|
||||||
|
switch ((int)current_key) {
|
||||||
|
#ifdef INTERFACE_CLASSIC
|
||||||
|
case kF1:
|
||||||
|
c_interface_select_diskette( 0 );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kF2:
|
||||||
|
c_interface_select_diskette( 1 );
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case kPAUSE:
|
||||||
|
while (c_mygetch(1) == -1)
|
||||||
|
{
|
||||||
|
struct timespec ts = { .tv_sec=0, .tv_nsec=1 };
|
||||||
|
nanosleep(&ts, NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifdef INTERFACE_CLASSIC
|
||||||
|
case kF5:
|
||||||
|
c_interface_keyboard_layout();
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifdef DEBUGGER
|
||||||
|
case kF7:
|
||||||
|
c_interface_debugging();
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case kF8:
|
||||||
|
c_interface_credits();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kF10:
|
||||||
|
c_interface_parameters();
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef AUDIO_ENABLED
|
||||||
|
SoundSystemUnpause();
|
||||||
|
#endif
|
||||||
|
c_joystick_reset();
|
||||||
|
pthread_mutex_unlock(&interface_mutex);
|
||||||
|
in_interface = false;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void c_interface_begin(int current_key)
|
||||||
|
{
|
||||||
|
pthread_t t = 0;
|
||||||
|
pthread_create(&t, NULL, (void *) &interface_thread, (void *)current_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
#define MOUSETEXT_BEGIN 0x90
|
#define MOUSETEXT_BEGIN 0x90
|
||||||
|
|
||||||
|
extern bool in_interface;
|
||||||
|
|
||||||
|
void c_interface_begin(int current_key);
|
||||||
void c_interface_print(int x, int y, const int cs, const char *s);
|
void c_interface_print(int x, int y, const int cs, const char *s);
|
||||||
void c_interface_print_submenu_centered(char *submenu, const int xlen, const int ylen);
|
void c_interface_print_submenu_centered(char *submenu, const int xlen, const int ylen);
|
||||||
void c_load_interface_font();
|
void c_load_interface_font();
|
||||||
|
69
src/keys.c
69
src/keys.c
@@ -33,7 +33,6 @@ extern int raw_js_y;
|
|||||||
static int next_key = -1;
|
static int next_key = -1;
|
||||||
static int last_scancode = -1;
|
static int last_scancode = -1;
|
||||||
bool caps_lock = false; /* is enabled */
|
bool caps_lock = false; /* is enabled */
|
||||||
static bool in_interface = false;
|
|
||||||
|
|
||||||
/* ----------------------------------------------------
|
/* ----------------------------------------------------
|
||||||
//e Keymap. Mapping scancodes to Apple //e US Keyboard
|
//e Keymap. Mapping scancodes to Apple //e US Keyboard
|
||||||
@@ -234,8 +233,11 @@ void c_keys_handle_input(int scancode, int pressed)
|
|||||||
|
|
||||||
// key input consumption
|
// key input consumption
|
||||||
|
|
||||||
if ((next_key >= 0) && !in_interface)
|
if ((next_key >= 0)
|
||||||
{
|
#ifdef INTERFACE_CLASSIC
|
||||||
|
&& !in_interface
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
do {
|
do {
|
||||||
int current_key = next_key;
|
int current_key = next_key;
|
||||||
next_key = -1;
|
next_key = -1;
|
||||||
@@ -262,67 +264,12 @@ void c_keys_handle_input(int scancode, int pressed)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !(c_keys_is_interface_key(current_key) || (current_key == kPAUSE)) )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_lock(&interface_mutex);
|
|
||||||
#ifdef AUDIO_ENABLED
|
|
||||||
SoundSystemPause();
|
|
||||||
#endif
|
|
||||||
in_interface = true;
|
|
||||||
|
|
||||||
switch (current_key)
|
|
||||||
{
|
|
||||||
#ifdef INTERFACE_CLASSIC
|
#ifdef INTERFACE_CLASSIC
|
||||||
case kF1:
|
if ( c_keys_is_interface_key(current_key) || (current_key == kPAUSE) )
|
||||||
c_interface_select_diskette( 0 );
|
{
|
||||||
break;
|
c_interface_begin(current_key);
|
||||||
|
|
||||||
case kF2:
|
|
||||||
c_interface_select_diskette( 1 );
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case kPAUSE:
|
|
||||||
while (c_mygetch(1) == -1)
|
|
||||||
{
|
|
||||||
struct timespec ts = { .tv_sec=0, .tv_nsec=1 };
|
|
||||||
nanosleep(&ts, NULL);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
#ifdef INTERFACE_CLASSIC
|
|
||||||
case kF5:
|
|
||||||
c_interface_keyboard_layout();
|
|
||||||
break;
|
|
||||||
|
|
||||||
#ifdef DEBUGGER
|
|
||||||
case kF7:
|
|
||||||
c_interface_debugging();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case kF8:
|
|
||||||
c_interface_credits();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case kF10:
|
|
||||||
c_interface_parameters();
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef AUDIO_ENABLED
|
|
||||||
SoundSystemUnpause();
|
|
||||||
#endif
|
#endif
|
||||||
c_joystick_reset();
|
|
||||||
pthread_mutex_unlock(&interface_mutex);
|
|
||||||
in_interface = false;
|
|
||||||
|
|
||||||
} while(0);
|
} while(0);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user