apple2ix/src/timing.h
Aaron Culliney 41a1f3d598 Timing model back to nanosleep for sound fidelity
This is part 1 of 2

    * Proper emulator timing is critical for emulating the Apple2 speaker with a
      square wave on a modern soundcard.  The AppleWin sources provided
      reference, inspiration, and source for both timing and speaker emulation
      code.

    * cpu.S, cpu.h, timing.c : OK so I flip-flopped quite a bit here on how best
      to do proper emulator timing, but the previous spinloop implementation was
      not one of my more enlightened decisions :P ... cpu/power consumption
      nightmare ...

    * ds-shim.h, win-shim.h -- Shims for Windows-isms and DirectSound-isms.  I
      assume these will eventually be refactored away...

    * soundcore.[hc], speaker.[hc] -- Directly ported from a recent version of
      AppleWin.  Everything I've added should be braced with #ifdef APPLE2IX.

    * soundcore-alsa.[hc] -- An ALSA backend using mmap'ed soundcard access.
2013-10-05 23:33:18 -07:00

62 lines
1.2 KiB
C

/*
* 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
* Foundation.
*
* THERE ARE NO WARRANTIES WHATSOEVER.
*
*/
/*
* 65c02 CPU Timing Support.
*
* Copyleft 2013 Aaron Culliney
*
*/
#ifndef _TIMING_H_
#define _TIMING_H_
#include "common.h"
#define NANOSECONDS 1000000000
// timing values cribbed from AppleWin
// 14318181.81...
#define _M14 (157500000.0 / 11.0)
// 65 cycles per 912 14M clocks = 1020484.45...
#define CLK_6502 ((_M14 * 65.0) / 912.0)
#define CPU_SCALE_SLOWEST 0.25
#define CPU_SCALE_FASTEST 4.005
#define CPU_SCALE_STEP_DIV 0.01
#define CPU_SCALE_STEP 0.05
#define SPKR_SAMPLE_RATE 44100
extern double g_fCurrentCLK6502;
extern bool g_bFullSpeed;
extern uint64_t g_nCumulativeCycles;
extern int g_nCpuCyclesFeedback;
extern double cpu_scale_factor;
struct timespec timespec_diff(struct timespec start, struct timespec end, bool *negative);
bool timing_is_fullspeed();
void timing_enable_fullspeed();
void timing_enable_regular_speed();
void timing_initialize();
void cpu_thread();
void CpuCalcCycles(const unsigned long nExecutedCycles);
#endif // whole file