// --- ---------- ------------------------------------------------------------
// JLH 06/15/2006 Added changelog ;-)
// JLH 06/15/2006 Scrubbed all BYTE, WORD & DWORD references from the code
+// JLH 02/10/2009 Fixed sound IRQ callback so that CPU samples are taken at
+// cycle exact boundaries
//
// Notes:
// The sound CPU (6808) runs at 894,750 (3,579,000 / 4) Hz.
extern uint8 sram[];
int cnt = 0;
+#define CYCLE_EXACT_SOUND
+#ifdef CYCLE_EXACT_SOUND
+ static float overflow = 0.0;
+ static uint32 time = 20;
+#endif
+
while (cnt != length)
{
// This is close, but not cycle exact (exact would be 20.289115646...)
-//Need to figure out how to get that fraction to execute... !!! FIX !!!
+//Need to figure out how to get that fraction to execute... !!! FIX !!! [DONE]
+/*
+One way would be to use a fractional accumulator, then subtract 1 every
+time it overflows. Like so:
+
+double overflow = 0;
+uint32 time = 20;
+while (!done)
+{
+ Execute6808(&soundCPU, time);
+ overflow += 0.289115646;
+ if (overflow > 1.0)
+ {
+ overflow -= 1.0;
+ time = 21;
+ }
+ else
+ time = 20;
+}
+*/
+#ifdef CYCLE_EXACT_SOUND
+ Execute6808(&soundCPU, time);
+ soundCPU.clock -= time;
+#else
Execute6808(&soundCPU, 20);
soundCPU.clock -= 20;
+#endif
buffer[cnt++] = sram[0x0400]; // Fill the buffer with the PIA output value
+#ifdef CYCLE_EXACT_SOUND
+ overflow += 0.289115646; // Fractional part of CPU cycles...
+
+ if (overflow > 1.0)
+ {
+ overflow -= 1.0;
+ time = 21;
+ }
+ else
+ time = 20;
+#endif
}
}