+void JERRYResetPIT1(void);
+void JERRYResetPIT2(void);
+void JERRYResetI2S(void);
+
+void JERRYPIT1Callback(void);
+void JERRYPIT2Callback(void);
+void JERRYI2SCallback(void);
+
+//This approach is probably wrong, since the timer is continuously counting down, though
+//it might only be a problem if the # of interrupts generated is greater than 1--the M68K's
+//timeslice should be running during that phase... (The DSP needs to be aware of this!)
+
+//This is only used by the old system, so once the new timer system is working this
+//should be safe to nuke.
+void JERRYI2SExec(uint32 cycles)
+{
+#ifndef NEW_TIMER_SYSTEM
+ extern uint16 serialMode; // From DAC.CPP
+ if (serialMode & 0x01) // INTERNAL flag (JERRY is master)
+ {
+
+ // Why is it called this? Instead of SCLK? Shouldn't this be read from DAC.CPP???
+//Yes, it should. !!! FIX !!!
+ jerry_i2s_interrupt_divide &= 0xFF;
+
+ if (jerry_i2s_interrupt_timer == -1)
+ {
+ // We don't have to divide the RISC clock rate by this--the reason is a bit
+ // convoluted. Will put explanation here later...
+// What's needed here is to find the ratio of the frequency to the number of clock cycles
+// in one second. For example, if the sample rate is 44100, we divide the clock rate by
+// this: 26590906 / 44100 = 602 cycles.
+// Which means, every 602 cycles that go by we have to generate an interrupt.
+ jerryI2SCycles = 32 * (2 * (jerry_i2s_interrupt_divide + 1));
+ }
+
+ jerry_i2s_interrupt_timer -= cycles;
+ if (jerry_i2s_interrupt_timer <= 0)
+ {
+//This is probably wrong as well (i.e., need to check enable lines)... !!! FIX !!!
+ DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE);
+ jerry_i2s_interrupt_timer += jerryI2SCycles;
+#ifdef JERRY_DEBUG
+ if (jerry_i2s_interrupt_timer < 0)
+ WriteLog("JERRY: Missed generating an interrupt (missed %u)!\n", (-jerry_i2s_interrupt_timer / jerryI2SCycles) + 1);
+#endif
+ }
+ }
+ else // JERRY is slave to external word clock
+ {
+ // This is just a temporary kludge to see if the CD bus mastering works
+ // I.e., this is totally faked...!
+// The whole interrupt system is pretty much borked and is need of an overhaul.
+// What we need is a way of handling these interrupts when they happen instead of
+// scanline boundaries the way it is now.
+ jerry_i2s_interrupt_timer -= cycles;
+ if (jerry_i2s_interrupt_timer <= 0)
+ {
+//This is probably wrong as well (i.e., need to check enable lines)... !!! FIX !!! [DONE]
+ if (ButchIsReadyToSend())//Not sure this is right spot to check...
+ {
+// return GetWordFromButchSSI(offset, who);
+ SetSSIWordsXmittedFromButch();
+ DSPSetIRQLine(DSPIRQ_SSI, ASSERT_LINE);
+ }
+ jerry_i2s_interrupt_timer += 602;
+ }
+ }
+#else
+ RemoveCallback(JERRYI2SCallback);
+ JERRYI2SCallback();
+#endif
+}