mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-08-09 12:24:57 +00:00
Allow emulator shutdown state to be queried as needed
This commit is contained in:
@@ -200,7 +200,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jclas
|
|||||||
void Java_org_deadc0de_apple2ix_Apple2View_nativeGraphicsInitialized(JNIEnv *env, jclass cls) {
|
void Java_org_deadc0de_apple2ix_Apple2View_nativeGraphicsInitialized(JNIEnv *env, jclass cls) {
|
||||||
LOG("...");
|
LOG("...");
|
||||||
_video_setRenderThread(pthread_self()); // by definition, this method is called on the render thread ...
|
_video_setRenderThread(pthread_self()); // by definition, this method is called on the render thread ...
|
||||||
video_shutdown(false);
|
video_shutdown();
|
||||||
video_init();
|
video_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1216,7 +1216,7 @@ bool video_isRenderThread(void) {
|
|||||||
return (pthread_self() == render_thread_id);
|
return (pthread_self() == render_thread_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_shutdown(bool emulatorShuttingDown) {
|
void video_shutdown(void) {
|
||||||
|
|
||||||
#if MOBILE_DEVICE
|
#if MOBILE_DEVICE
|
||||||
// WARNING : shutdown should occur on the render thread. Platform code (iOS, Android) should ensure this is called
|
// WARNING : shutdown should occur on the render thread. Platform code (iOS, Android) should ensure this is called
|
||||||
@@ -1224,7 +1224,7 @@ void video_shutdown(bool emulatorShuttingDown) {
|
|||||||
assert(!render_thread_id || pthread_self() == render_thread_id);
|
assert(!render_thread_id || pthread_self() == render_thread_id);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
video_backend->shutdown(emulatorShuttingDown);
|
video_backend->shutdown();
|
||||||
|
|
||||||
if (pthread_self() == render_thread_id) {
|
if (pthread_self() == render_thread_id) {
|
||||||
FREE(video__fb);
|
FREE(video__fb);
|
||||||
|
@@ -64,7 +64,7 @@ void video_main_loop(void);
|
|||||||
* Shutdown video system. Should only be called on the render thread (unless render thread is in emulator-managed main
|
* Shutdown video system. Should only be called on the render thread (unless render thread is in emulator-managed main
|
||||||
* video loop).
|
* video loop).
|
||||||
*/
|
*/
|
||||||
void video_shutdown(bool emulatorShuttingDown);
|
void video_shutdown(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Begin a render pass (only for non-emulator-managed main video). This should only be called on the render thread.
|
* Begin a render pass (only for non-emulator-managed main video). This should only be called on the render thread.
|
||||||
|
@@ -1308,7 +1308,7 @@ void c_interface_parameters()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shutdown) {
|
if (shutdown) {
|
||||||
video_shutdown(/*emulatorShuttingDown:*/false); // soft quit video_main_loop()
|
video_shutdown(); // soft quit video_main_loop()
|
||||||
} else {
|
} else {
|
||||||
prefs_sync(NULL);
|
prefs_sync(NULL);
|
||||||
}
|
}
|
||||||
|
10
src/misc.c
10
src/misc.c
@@ -25,6 +25,7 @@ typedef struct module_ctor_node_s {
|
|||||||
} module_ctor_node_s;
|
} module_ctor_node_s;
|
||||||
|
|
||||||
static module_ctor_node_s *head = NULL;
|
static module_ctor_node_s *head = NULL;
|
||||||
|
static bool emulatorShuttingDown = false;
|
||||||
|
|
||||||
bool do_logging = true; // also controlled by NDEBUG
|
bool do_logging = true; // also controlled by NDEBUG
|
||||||
FILE *error_log = NULL;
|
FILE *error_log = NULL;
|
||||||
@@ -292,14 +293,19 @@ void emulator_start(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void emulator_shutdown(void) {
|
void emulator_shutdown(void) {
|
||||||
|
emulatorShuttingDown = true;
|
||||||
disk6_eject(0);
|
disk6_eject(0);
|
||||||
disk6_eject(1);
|
disk6_eject(1);
|
||||||
video_shutdown(/*emulatorShuttingDown:*/true);
|
video_shutdown();
|
||||||
prefs_shutdown(/*emulatorShuttingDown:*/true);
|
prefs_shutdown();
|
||||||
timing_stopCPU();
|
timing_stopCPU();
|
||||||
_shutdown_threads();
|
_shutdown_threads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool emulator_isShuttingDown(void) {
|
||||||
|
return emulatorShuttingDown;
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(__APPLE__) && !defined(ANDROID)
|
#if !defined(__APPLE__) && !defined(ANDROID)
|
||||||
int main(int _argc, char **_argv) {
|
int main(int _argc, char **_argv) {
|
||||||
argc = _argc;
|
argc = _argc;
|
||||||
|
11
src/misc.h
11
src/misc.h
@@ -22,8 +22,6 @@ enum {
|
|||||||
CTOR_PRIORITY_LATE = 201,
|
CTOR_PRIORITY_LATE = 201,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*startup_callback_f)(void);
|
|
||||||
|
|
||||||
// top installation directory
|
// top installation directory
|
||||||
extern const char *data_dir;
|
extern const char *data_dir;
|
||||||
|
|
||||||
@@ -31,6 +29,12 @@ extern const char *data_dir;
|
|||||||
extern char **argv;
|
extern char **argv;
|
||||||
extern int argc;
|
extern int argc;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Emulator lifecycle
|
||||||
|
//
|
||||||
|
|
||||||
|
typedef void (*startup_callback_f)(void);
|
||||||
|
|
||||||
// register a startup function
|
// register a startup function
|
||||||
void emulator_registerStartupCallback(long order, startup_callback_f callback);
|
void emulator_registerStartupCallback(long order, startup_callback_f callback);
|
||||||
|
|
||||||
@@ -40,6 +44,9 @@ void emulator_start(void);
|
|||||||
// shutdown emulator in preparation for app exit
|
// shutdown emulator in preparation for app exit
|
||||||
void emulator_shutdown(void);
|
void emulator_shutdown(void);
|
||||||
|
|
||||||
|
// is emulator shutting down?
|
||||||
|
bool emulator_isShuttingDown(void);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Emulator state save/restore
|
// Emulator state save/restore
|
||||||
//
|
//
|
||||||
|
@@ -454,8 +454,8 @@ void prefs_sync(const char *domain) {
|
|||||||
FREE(alreadySynced);
|
FREE(alreadySynced);
|
||||||
}
|
}
|
||||||
|
|
||||||
void prefs_shutdown(bool emulatorShuttingDown) {
|
void prefs_shutdown(void) {
|
||||||
if (!emulatorShuttingDown) {
|
if (!emulator_isShuttingDown()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -131,7 +131,7 @@ extern void prefs_registerListener(const char * _NONNULL domain, _NONNULL prefs_
|
|||||||
extern void prefs_sync(const char * _NULLABLE domain);
|
extern void prefs_sync(const char * _NULLABLE domain);
|
||||||
|
|
||||||
// cleans up and removes listener in preparation for app shutdown
|
// cleans up and removes listener in preparation for app shutdown
|
||||||
extern void prefs_shutdown(bool emulatorShuttingDown);
|
extern void prefs_shutdown(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -161,12 +161,12 @@ static void glnode_setupNodes(void *ctx) {
|
|||||||
LOG("END glnode_setupNodes ...");
|
LOG("END glnode_setupNodes ...");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glnode_shutdownNodes(bool emulatorShuttingDown) {
|
static void glnode_shutdownNodes(void) {
|
||||||
LOG("BEGIN glnode_shutdownNodes ...");
|
LOG("BEGIN glnode_shutdownNodes ...");
|
||||||
|
|
||||||
#if USE_GLUT
|
#if USE_GLUT
|
||||||
if (glut_in_main_loop) {
|
if (glut_in_main_loop) {
|
||||||
assert(!emulatorShuttingDown);
|
assert(!emulator_isShuttingDown());
|
||||||
glutLeaveMainLoop();
|
glutLeaveMainLoop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ static void glnode_shutdownNodes(bool emulatorShuttingDown) {
|
|||||||
p = p->last;
|
p = p->last;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emulatorShuttingDown) {
|
if (emulator_isShuttingDown()) {
|
||||||
// clean up to make Valgrind happy ...
|
// clean up to make Valgrind happy ...
|
||||||
p = head;
|
p = head;
|
||||||
while (p) {
|
while (p) {
|
||||||
|
@@ -21,7 +21,7 @@ typedef struct video_backend_s {
|
|||||||
void (*main_loop)(void);
|
void (*main_loop)(void);
|
||||||
void (*reshape)(int width, int height, bool landscape);
|
void (*reshape)(int width, int height, bool landscape);
|
||||||
void (*render)(void);
|
void (*render)(void);
|
||||||
void (*shutdown)(bool emulatorShuttingDown);
|
void (*shutdown)(void);
|
||||||
} video_backend_s;
|
} video_backend_s;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user