diff --git a/Android/jni/jnihooks.c b/Android/jni/jnihooks.c index df4a486c..90dc08a4 100644 --- a/Android/jni/jnihooks.c +++ b/Android/jni/jnihooks.c @@ -130,8 +130,7 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnCreate(JNIEnv *env, jobje #if TESTING _run_tests(); #else - c_initialize_firsttime(); - pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL); + timing_startCPU(); #endif } diff --git a/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorGLView.m b/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorGLView.m index 48ceda86..dab97019 100644 --- a/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorGLView.m +++ b/Apple2Mac/Apple2Mac/Classes/OSX/EmulatorGLView.m @@ -186,8 +186,7 @@ static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt // to [self openGLContext]) [[self openGLContext] makeCurrentContext]; - c_initialize_firsttime(); - pthread_create(&cpu_thread_id, NULL, (void *)&cpu_thread, (void *)NULL); + timing_startCPU(); // Synchronize buffer swaps with vertical refresh rate GLint swapInt = 1; diff --git a/src/display.c b/src/display.c index 7409840b..a4589f29 100644 --- a/src/display.c +++ b/src/display.c @@ -1068,13 +1068,11 @@ void video_init(void) { memset(video__fb2,0,SCANWIDTH*SCANHEIGHT); #if !HEADLESS -#if !defined(__APPLE__) -#if !defined(ANDROID) +# if !defined(__APPLE__) && !defined(ANDROID) if (!is_headless) { video_backend->init((void*)0); } -#endif -#endif +# endif #endif } diff --git a/src/misc.c b/src/misc.c index 35774564..d5bd2450 100644 --- a/src/misc.c +++ b/src/misc.c @@ -566,43 +566,6 @@ void c_initialize_vm() { c_joystick_reset(); /* reset joystick */ } -/* ------------------------------------------------------------------------- - void c_initialize_firsttime() - ------------------------------------------------------------------------- */ - -void reinitialize(void) { -#if !TESTING - assert(pthread_self() == cpu_thread_id); -#endif - - cycles_count_total = 0; - - c_initialize_vm(); - - softswitches = SS_TEXT | SS_IOUDIS | SS_C3ROM | SS_LCWRT | SS_LCSEC; - - video_setpage( 0 ); - - video_redraw(); - - cpu65_init(); - - timing_initialize(); - -#ifdef AUDIO_ENABLED - MB_Reset(); -#endif -} - -void c_initialize_firsttime(void) { - - video_init(); - -#ifdef DEBUGGER - c_debugger_init(); -#endif -} - #if !TESTING && !defined(__APPLE__) && !defined(ANDROID) extern void *cpu_thread(void *dummyptr); @@ -652,11 +615,8 @@ int main(int _argc, char **_argv) { #ifdef INTERFACE_CLASSIC c_keys_set_key(kF8); // show credits before emulation start #endif - c_initialize_firsttime(); // one-time initializations - - // spin off cpu thread - pthread_create(&cpu_thread_id, NULL, (void *)&cpu_thread, (void *)NULL); + timing_startCPU(); video_main_loop(); assert(emulator_shutting_down && "emulator is properly shutting down"); diff --git a/src/misc.h b/src/misc.h index fdc70aef..b96d247b 100644 --- a/src/misc.h +++ b/src/misc.h @@ -100,14 +100,12 @@ extern uint32_t softswitches; extern bool emulator_shutting_down; -void c_initialize_firsttime(); void c_initialize_sound_hooks(); void c_disable_sound_hooks(); void c_set_primary_char(); void c_set_altchar(); void c_initialize_font(); void c_initialize_vm(); -void reinitialize(); /* vm hooks */ diff --git a/src/timing.c b/src/timing.c index 4780bdd6..f913c3ff 100644 --- a/src/timing.c +++ b/src/timing.c @@ -1,5 +1,5 @@ /* - * Apple // emulator for *nix + * Apple // emulator for *nix * * This software package is subject to the GNU General Public License * version 2 or later (your choice) as published by the Free Software @@ -16,7 +16,7 @@ * * ..{...+....[....|..................|.........]....^....|....^....^....}...... * ti MBB CHK CHK MBE CHX SPK MBX tj ZZZ - * + * * - ti : timing sample begin (lock out interface thread) * - tj : timing sample end (unlock interface thread) * - [ : cpu65_run() @@ -160,6 +160,33 @@ static void _timing_initialize(double scale) { #endif } +#if !TESTING +static +#endif +void reinitialize(void) { +#if !TESTING + assert(pthread_self() == cpu_thread_id); +#endif + + cycles_count_total = 0; + + c_initialize_vm(); + + softswitches = SS_TEXT | SS_IOUDIS | SS_C3ROM | SS_LCWRT | SS_LCSEC; + + video_setpage( 0 ); + + video_redraw(); + + cpu65_init(); + + timing_initialize(); + +#ifdef AUDIO_ENABLED + MB_Reset(); +#endif +} + void timing_initialize(void) { assert(cpu_isPaused() || (pthread_self() == cpu_thread_id)); _timing_initialize(alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor); @@ -234,7 +261,7 @@ bool timing_shouldAutoAdjustSpeed(void) { } #endif -void *cpu_thread(void *dummyptr) { +static void *cpu_thread(void *dummyptr) { assert(pthread_self() == cpu_thread_id); @@ -525,6 +552,11 @@ void *cpu_thread(void *dummyptr) { return NULL; } +void timing_startCPU(void) { + video_init(); + pthread_create(&cpu_thread_id, NULL, (void *)&cpu_thread, (void *)NULL); +} + unsigned int CpuGetCyclesThisVideoFrame(void) { timing_checkpoint_cycles(); return g_dwCyclesThisFrame + cycles_checkpoint_count; diff --git a/src/timing.h b/src/timing.h index 0964aa48..b37a147a 100644 --- a/src/timing.h +++ b/src/timing.h @@ -69,6 +69,11 @@ extern READONLY pthread_t cpu_thread_id; */ struct timespec timespec_diff(struct timespec start, struct timespec end, bool *negative); +/* + * Start CPU thread + */ +void timing_startCPU(void); + /* * toggles CPU speed between configured values */ @@ -91,11 +96,6 @@ void timing_initialize(void); */ void timing_reinitializeAudio(void); -/* - * timing/CPU thread entry point - */ -void *cpu_thread(void *ignored); - /* * Pause timing/CPU thread. *