Refactor : move reinitialize() to timing module and make static (mostly)

This commit is contained in:
Aaron Culliney 2015-09-06 14:03:02 -07:00
parent f95a00df7b
commit 7d4b63e12d
7 changed files with 45 additions and 59 deletions

View File

@ -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
}

View File

@ -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;

View File

@ -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
}

View File

@ -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");

View File

@ -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 */

View File

@ -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;

View File

@ -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.
*