mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-04-24 01:47:16 +00:00
Allow emulator shutdown state to be queried as needed
This commit is contained in:
parent
3ed159dd0b
commit
76f29d0865
@ -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) {
|
||||
LOG("...");
|
||||
_video_setRenderThread(pthread_self()); // by definition, this method is called on the render thread ...
|
||||
video_shutdown(false);
|
||||
video_shutdown();
|
||||
video_init();
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1216,7 @@ bool video_isRenderThread(void) {
|
||||
return (pthread_self() == render_thread_id);
|
||||
}
|
||||
|
||||
void video_shutdown(bool emulatorShuttingDown) {
|
||||
void video_shutdown(void) {
|
||||
|
||||
#if MOBILE_DEVICE
|
||||
// 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);
|
||||
#endif
|
||||
|
||||
video_backend->shutdown(emulatorShuttingDown);
|
||||
video_backend->shutdown();
|
||||
|
||||
if (pthread_self() == render_thread_id) {
|
||||
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
|
||||
* 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.
|
||||
|
@ -1308,7 +1308,7 @@ void c_interface_parameters()
|
||||
}
|
||||
|
||||
if (shutdown) {
|
||||
video_shutdown(/*emulatorShuttingDown:*/false); // soft quit video_main_loop()
|
||||
video_shutdown(); // soft quit video_main_loop()
|
||||
} else {
|
||||
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;
|
||||
|
||||
static module_ctor_node_s *head = NULL;
|
||||
static bool emulatorShuttingDown = false;
|
||||
|
||||
bool do_logging = true; // also controlled by NDEBUG
|
||||
FILE *error_log = NULL;
|
||||
@ -292,14 +293,19 @@ void emulator_start(void) {
|
||||
}
|
||||
|
||||
void emulator_shutdown(void) {
|
||||
emulatorShuttingDown = true;
|
||||
disk6_eject(0);
|
||||
disk6_eject(1);
|
||||
video_shutdown(/*emulatorShuttingDown:*/true);
|
||||
prefs_shutdown(/*emulatorShuttingDown:*/true);
|
||||
video_shutdown();
|
||||
prefs_shutdown();
|
||||
timing_stopCPU();
|
||||
_shutdown_threads();
|
||||
}
|
||||
|
||||
bool emulator_isShuttingDown(void) {
|
||||
return emulatorShuttingDown;
|
||||
}
|
||||
|
||||
#if !defined(__APPLE__) && !defined(ANDROID)
|
||||
int main(int _argc, char **_argv) {
|
||||
argc = _argc;
|
||||
|
11
src/misc.h
11
src/misc.h
@ -22,8 +22,6 @@ enum {
|
||||
CTOR_PRIORITY_LATE = 201,
|
||||
};
|
||||
|
||||
typedef void (*startup_callback_f)(void);
|
||||
|
||||
// top installation directory
|
||||
extern const char *data_dir;
|
||||
|
||||
@ -31,6 +29,12 @@ extern const char *data_dir;
|
||||
extern char **argv;
|
||||
extern int argc;
|
||||
|
||||
//
|
||||
// Emulator lifecycle
|
||||
//
|
||||
|
||||
typedef void (*startup_callback_f)(void);
|
||||
|
||||
// register a startup function
|
||||
void emulator_registerStartupCallback(long order, startup_callback_f callback);
|
||||
|
||||
@ -40,6 +44,9 @@ void emulator_start(void);
|
||||
// shutdown emulator in preparation for app exit
|
||||
void emulator_shutdown(void);
|
||||
|
||||
// is emulator shutting down?
|
||||
bool emulator_isShuttingDown(void);
|
||||
|
||||
//
|
||||
// Emulator state save/restore
|
||||
//
|
||||
|
@ -454,8 +454,8 @@ void prefs_sync(const char *domain) {
|
||||
FREE(alreadySynced);
|
||||
}
|
||||
|
||||
void prefs_shutdown(bool emulatorShuttingDown) {
|
||||
if (!emulatorShuttingDown) {
|
||||
void prefs_shutdown(void) {
|
||||
if (!emulator_isShuttingDown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -131,7 +131,7 @@ extern void prefs_registerListener(const char * _NONNULL domain, _NONNULL prefs_
|
||||
extern void prefs_sync(const char * _NULLABLE domain);
|
||||
|
||||
// cleans up and removes listener in preparation for app shutdown
|
||||
extern void prefs_shutdown(bool emulatorShuttingDown);
|
||||
extern void prefs_shutdown(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -161,12 +161,12 @@ static void glnode_setupNodes(void *ctx) {
|
||||
LOG("END glnode_setupNodes ...");
|
||||
}
|
||||
|
||||
static void glnode_shutdownNodes(bool emulatorShuttingDown) {
|
||||
static void glnode_shutdownNodes(void) {
|
||||
LOG("BEGIN glnode_shutdownNodes ...");
|
||||
|
||||
#if USE_GLUT
|
||||
if (glut_in_main_loop) {
|
||||
assert(!emulatorShuttingDown);
|
||||
assert(!emulator_isShuttingDown());
|
||||
glutLeaveMainLoop();
|
||||
return;
|
||||
}
|
||||
@ -178,7 +178,7 @@ static void glnode_shutdownNodes(bool emulatorShuttingDown) {
|
||||
p = p->last;
|
||||
}
|
||||
|
||||
if (emulatorShuttingDown) {
|
||||
if (emulator_isShuttingDown()) {
|
||||
// clean up to make Valgrind happy ...
|
||||
p = head;
|
||||
while (p) {
|
||||
|
@ -21,7 +21,7 @@ typedef struct video_backend_s {
|
||||
void (*main_loop)(void);
|
||||
void (*reshape)(int width, int height, bool landscape);
|
||||
void (*render)(void);
|
||||
void (*shutdown)(bool emulatorShuttingDown);
|
||||
void (*shutdown)(void);
|
||||
} video_backend_s;
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user