mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-08-05 16:25:12 +00:00
Avoid resetting joystick buttons too soon (to allow for ClosedApple-Reset to trigger)
This commit is contained in:
@@ -272,6 +272,7 @@ void Java_org_deadc0de_apple2ix_Apple2View_nativeRender(JNIEnv *env, jclass cls)
|
||||
void Java_org_deadc0de_apple2ix_Apple2Activity_nativeReboot(JNIEnv *env, jclass cls, jint resetState) {
|
||||
LOG("...");
|
||||
if (resetState) {
|
||||
// joystick button settings should be balanced by c_joystick_reset() triggered on CPU thread
|
||||
if (resetState == 1) {
|
||||
joy_button0 = 0xff;
|
||||
joy_button1 = 0x0;
|
||||
|
@@ -648,7 +648,7 @@ void cpu65_uninterrupt(int reason)
|
||||
}
|
||||
|
||||
void cpu65_reboot(void) {
|
||||
joy_button0 = 0xff; // OpenApple
|
||||
joy_button0 = 0xff; // OpenApple -- should be balanced by c_joystick_reset() triggers on CPU thread
|
||||
cpu65_interrupt(ResetSig);
|
||||
}
|
||||
|
||||
|
@@ -264,14 +264,29 @@ void c_calibrate_joystick()
|
||||
}
|
||||
#endif // INTERFACE_CLASSIC
|
||||
|
||||
// HACK : avoid resetting joystick button values too quickly. This should allow for ClosedApple-Reset. (This is still a
|
||||
// race, but hopefully much less likely to trigger).
|
||||
static void *_joystick_resetDelayed(void *ctx) {
|
||||
(void)ctx;
|
||||
|
||||
// delay
|
||||
sleep(1);
|
||||
|
||||
joy_button0 = 0x0;
|
||||
joy_button1 = 0x0;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void c_joystick_reset(void)
|
||||
{
|
||||
if (joydriver_resetJoystick) {
|
||||
joydriver_resetJoystick();
|
||||
}
|
||||
|
||||
joy_button0 = 0x0;
|
||||
joy_button1 = 0x0;
|
||||
pthread_t pid;
|
||||
pthread_create(&pid, NULL, (void *)&_joystick_resetDelayed, (void *)NULL);
|
||||
pthread_detach(pid);
|
||||
|
||||
joy_x = HALF_JOY_RANGE;
|
||||
joy_y = HALF_JOY_RANGE;
|
||||
|
@@ -40,7 +40,7 @@ static struct {
|
||||
touchjoy_button_type_t touchDownChar;
|
||||
touchjoy_button_type_t northChar;
|
||||
touchjoy_button_type_t southChar;
|
||||
} joys;
|
||||
} joys = { 0 };
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -60,7 +60,7 @@ static inline void _reset_buttons_state(void) {
|
||||
|
||||
static void touchjoy_resetState(void) {
|
||||
_reset_axis_state();
|
||||
_reset_buttons_state();
|
||||
//_reset_buttons_state(); -- do not reset button state here, it may interfere with other code performing reboot/reset
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -87,7 +87,7 @@ static void *_button_tap_delayed_thread(void *dummyptr) {
|
||||
|
||||
int timedOut = ETIMEDOUT;
|
||||
for (;;) {
|
||||
if (UNLIKELY(!joyglobals.isAvailable)) {
|
||||
if (UNLIKELY(emulator_isShuttingDown())) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ static void *_button_tap_delayed_thread(void *dummyptr) {
|
||||
_reset_buttons_state();
|
||||
}
|
||||
|
||||
if (UNLIKELY(!joyglobals.isAvailable)) {
|
||||
if (UNLIKELY(emulator_isShuttingDown())) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ static void *_button_tap_delayed_thread(void *dummyptr) {
|
||||
timedOut = pthread_cond_timedwait(&joys.tapDelayCond, &joys.tapDelayMutex, _tap_wait());
|
||||
assert((!timedOut || timedOut == ETIMEDOUT) && "should not fail any other way");
|
||||
|
||||
if (UNLIKELY(!joyglobals.isAvailable)) {
|
||||
if (UNLIKELY(emulator_isShuttingDown())) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -186,24 +186,20 @@ static void *_button_tap_delayed_thread(void *dummyptr) {
|
||||
}
|
||||
|
||||
static void touchjoy_setup(void (*buttonDrawCallback)(char newChar)) {
|
||||
assert((joys.tapDelayThreadId == 0) && "setup called multiple times!");
|
||||
|
||||
long lVal = 0;
|
||||
const interface_device_t screenOwner = prefs_parseLongValue(PREF_DOMAIN_TOUCHSCREEN, PREF_SCREEN_OWNER, &lVal, /*base:*/10) ? lVal : TOUCH_DEVICE_NONE;
|
||||
if (screenOwner == TOUCH_DEVICE_JOYSTICK) {
|
||||
joys.buttonDrawCallback = buttonDrawCallback;
|
||||
joys.buttonDrawCallback = buttonDrawCallback;
|
||||
if (joys.tapDelayThreadId == 0) {
|
||||
pthread_create(&joys.tapDelayThreadId, NULL, (void *)&_button_tap_delayed_thread, (void *)NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void touchjoy_shutdown(void) {
|
||||
pthread_mutex_lock(&joys.tapDelayMutex);
|
||||
pthread_cond_signal(&joys.tapDelayCond);
|
||||
pthread_mutex_unlock(&joys.tapDelayMutex);
|
||||
if (joys.tapDelayThreadId && pthread_join(joys.tapDelayThreadId, NULL)) {
|
||||
ERRLOG("OOPS: pthread_join tap delay thread ...");
|
||||
if (joys.tapDelayThreadId && emulator_isShuttingDown()) {
|
||||
pthread_mutex_lock(&joys.tapDelayMutex);
|
||||
pthread_cond_signal(&joys.tapDelayCond);
|
||||
pthread_mutex_unlock(&joys.tapDelayMutex);
|
||||
pthread_join(joys.tapDelayThreadId, NULL);
|
||||
joys.tapDelayThreadId = 0;
|
||||
}
|
||||
joys.tapDelayThreadId = 0;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user