2013-07-06 04:37:13 +00:00
|
|
|
/*
|
2013-10-06 06:22:08 +00:00
|
|
|
* Apple // emulator for *nix
|
2013-06-28 06:36:25 +00:00
|
|
|
*
|
2013-10-06 06:22:08 +00:00
|
|
|
* This software package is subject to the GNU General Public License
|
|
|
|
* version 2 or later (your choice) as published by the Free Software
|
|
|
|
* Foundation.
|
2013-06-28 06:36:25 +00:00
|
|
|
*
|
2013-10-06 06:22:08 +00:00
|
|
|
* THERE ARE NO WARRANTIES WHATSOEVER.
|
2013-06-28 06:36:25 +00:00
|
|
|
*
|
2013-10-06 06:22:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 65c02 CPU Timing Support.
|
|
|
|
*
|
|
|
|
* Copyleft 2013 Aaron Culliney
|
2013-07-06 04:37:13 +00:00
|
|
|
*
|
2013-06-28 06:36:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _TIMING_H_
|
|
|
|
#define _TIMING_H_
|
|
|
|
|
2013-10-06 06:22:08 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
#if !defined(NANOSECONDS_PER_SECOND)
|
2015-07-02 05:54:09 +00:00
|
|
|
#define NANOSECONDS_PER_SECOND 1000000000UL
|
2015-01-31 21:57:10 +00:00
|
|
|
#endif
|
2013-06-28 06:36:25 +00:00
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
// timing values cribbed from AppleWin ... reference: Sather's _Understanding the Apple IIe_
|
|
|
|
// TODO: revisit this if/when attempting to actually sync up VBL/VSYNC to actual device vsync
|
2013-10-06 06:22:08 +00:00
|
|
|
|
|
|
|
// 14318181.81...
|
2015-01-31 21:57:10 +00:00
|
|
|
#define _M14 (157500000.0 / 11.0)
|
|
|
|
#define _M14_INT (157500000 / 11)
|
2013-10-06 06:22:08 +00:00
|
|
|
|
|
|
|
// 65 cycles per 912 14M clocks = 1020484.45...
|
2015-01-31 21:57:10 +00:00
|
|
|
#define CLK_6502 ((_M14 * 65.0) / 912.0)
|
|
|
|
#define CLK_6502_INT ((_M14_INT * 65) / 912)
|
2013-10-06 06:22:08 +00:00
|
|
|
|
|
|
|
#define CPU_SCALE_SLOWEST 0.25
|
2015-03-23 01:53:13 +00:00
|
|
|
#define CPU_SCALE_FASTEST0 4.0
|
2013-10-06 08:31:58 +00:00
|
|
|
#define CPU_SCALE_FASTEST 4.05
|
2015-01-31 21:57:10 +00:00
|
|
|
#ifdef INTERFACE_CLASSIC
|
|
|
|
# define CPU_SCALE_STEP_DIV 0.01
|
|
|
|
# define CPU_SCALE_STEP 0.05
|
|
|
|
#endif
|
2013-10-06 06:22:08 +00:00
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
extern unsigned long long cycles_count_total;// cumulative cycles count from machine reset
|
|
|
|
extern double cycles_persec_target; // CLK_6502 * current CPU scale
|
|
|
|
extern int cycles_speaker_feedback; // current -/+ speaker requested feedback
|
2013-10-06 06:22:08 +00:00
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
extern double cpu_scale_factor; // scale factor #1
|
|
|
|
extern double cpu_altscale_factor; // scale factor #2
|
|
|
|
extern bool is_fullspeed; // emulation in full native speed?
|
2015-03-23 01:53:13 +00:00
|
|
|
extern bool alt_speed_enabled;
|
2013-10-06 06:22:08 +00:00
|
|
|
|
2014-03-30 17:57:56 +00:00
|
|
|
extern pthread_t cpu_thread_id;
|
2015-02-16 16:46:29 +00:00
|
|
|
extern pthread_mutex_t interface_mutex;
|
|
|
|
extern pthread_cond_t cpu_thread_cond;
|
|
|
|
extern pthread_cond_t dbg_thread_cond;
|
2014-03-30 17:57:56 +00:00
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
/*
|
|
|
|
* calculate the difference between two timespec structures
|
|
|
|
*/
|
2013-10-06 06:22:08 +00:00
|
|
|
struct timespec timespec_diff(struct timespec start, struct timespec end, bool *negative);
|
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
/*
|
|
|
|
* toggles CPU speed between configured values
|
|
|
|
*/
|
2015-01-11 20:12:51 +00:00
|
|
|
void timing_toggle_cpu_speed(void);
|
2013-06-28 06:36:25 +00:00
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
/*
|
|
|
|
* (dis)allow automatic adjusting of CPU speed between presently configured and max (when loading disk images).
|
|
|
|
*/
|
|
|
|
void timing_set_auto_adjust_speed(bool auto_adjust);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check whether automatic adjusting of CPU speed is configured.
|
|
|
|
*/
|
|
|
|
bool timing_should_auto_adjust_speed(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize timing
|
|
|
|
*/
|
2015-01-11 20:12:51 +00:00
|
|
|
void timing_initialize(void);
|
2013-06-28 06:36:25 +00:00
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
/*
|
|
|
|
* timing/CPU thread entry point
|
|
|
|
*/
|
2014-09-17 03:39:08 +00:00
|
|
|
void *cpu_thread(void *ignored);
|
2013-10-06 06:22:08 +00:00
|
|
|
|
2015-07-05 01:17:04 +00:00
|
|
|
/*
|
|
|
|
* Pause timing/CPU thread
|
|
|
|
*/
|
|
|
|
void cpu_pause(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resume timing/CPU thread
|
|
|
|
*/
|
|
|
|
void cpu_resume(void);
|
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
/*
|
|
|
|
* checkpoints current cycle count and updates total (for timing-dependent I/O)
|
|
|
|
*/
|
|
|
|
void timing_checkpoint_cycles(void);
|
2013-06-28 06:36:25 +00:00
|
|
|
|
|
|
|
#endif // whole file
|