-#if 0
- frameDone = false;
-
- do
- {
- double timeToNextEvent = GetTimeToNextEvent();
-//WriteLog("JEN: Time to next event (%u) is %f usec (%u RISC cycles)...\n", nextEvent, timeToNextEvent, USEC_TO_RISC_CYCLES(timeToNextEvent));
-
- m68k_execute(USEC_TO_M68K_CYCLES(timeToNextEvent));
-
- if (vjs.GPUEnabled)
- GPUExec(USEC_TO_RISC_CYCLES(timeToNextEvent));
-
-#ifndef NEW_DAC_CODE
- if (vjs.DSPEnabled)
- {
- if (vjs.usePipelinedDSP)
- DSPExecP2(USEC_TO_RISC_CYCLES(timeToNextEvent)); // Pipelined DSP execution (3 stage)...
- else
- DSPExec(USEC_TO_RISC_CYCLES(timeToNextEvent)); // Ordinary non-pipelined DSP
- }
-#endif
-
- HandleNextEvent();
- }
- while (!frameDone);
-#endif
-
-
-//
-// SDL callback routine to fill audio buffer
-//
-// Note: The samples are packed in the buffer in 16 bit left/16 bit right pairs.
-// Also, length is the length of the buffer in BYTES
-//
-void SDLSoundCallback(void * userdata, Uint8 * buffer, int length)
-{
- // Clear the buffer to silence, in case the DAC buffer is empty (or short)
-//This causes choppy sound... Ick.
- memset(buffer, desired.silence, length);
-//WriteLog("DAC: Inside callback...\n");
- if (LeftFIFOHeadPtr != LeftFIFOTailPtr)
- {
-//WriteLog("DAC: About to write some data!\n");
- int numLeftSamplesReady
- = (LeftFIFOTailPtr + (LeftFIFOTailPtr < LeftFIFOHeadPtr ? BUFFER_SIZE : 0))
- - LeftFIFOHeadPtr;
- int numRightSamplesReady
- = (RightFIFOTailPtr + (RightFIFOTailPtr < RightFIFOHeadPtr ? BUFFER_SIZE : 0))
- - RightFIFOHeadPtr;
-//This waits for the slower side to catch up. If writing only one side, then this
-//causes the buffer not to drain...
- int numSamplesReady
- = (numLeftSamplesReady < numRightSamplesReady
- ? numLeftSamplesReady : numRightSamplesReady);//Hmm. * 2;
-
-//Kludge, until I can figure out WTF is going on WRT Super Burnout.
-if (numLeftSamplesReady == 0 || numRightSamplesReady == 0)
- numSamplesReady = numLeftSamplesReady + numRightSamplesReady;
-
-//The numbers look good--it's just that the DSP can't get enough samples in the DAC buffer!
-//WriteLog("DAC: Left/RightFIFOHeadPtr: %u/%u, Left/RightFIFOTailPtr: %u/%u\n", LeftFIFOHeadPtr, RightFIFOHeadPtr, LeftFIFOTailPtr, RightFIFOTailPtr);
-//WriteLog(" numLeft/RightSamplesReady: %i/%i, numSamplesReady: %i, length of buffer: %i\n", numLeftSamplesReady, numRightSamplesReady, numSamplesReady, length);
-
-/* if (numSamplesReady > length)
- numSamplesReady = length;//*/
- if (numSamplesReady > length / 2) // length / 2 because we're comparing 16-bit lengths
- numSamplesReady = length / 2;
-//else
-// WriteLog(" Not enough samples to fill the buffer (short by %u L/R samples)...\n", (length / 2) - numSamplesReady);
-//WriteLog("DAC: %u samples ready.\n", numSamplesReady);
-
- // Actually, it's a bit more involved than this, but this is the general idea:
-// memcpy(buffer, DACBuffer, length);
- for(int i=0; i<numSamplesReady; i++)
- ((uint16 *)buffer)[i] = DACBuffer[(LeftFIFOHeadPtr + i) % BUFFER_SIZE];
- // Could also use (as long as BUFFER_SIZE is a multiple of 2):
-// buffer[i] = DACBuffer[(LeftFIFOHeadPtr + i) & (BUFFER_SIZE - 1)];
-
- LeftFIFOHeadPtr = (LeftFIFOHeadPtr + numSamplesReady) % BUFFER_SIZE;
- RightFIFOHeadPtr = (RightFIFOHeadPtr + numSamplesReady) % BUFFER_SIZE;
- // Could also use (as long as BUFFER_SIZE is a multiple of 2):
-// LeftFIFOHeadPtr = (LeftFIFOHeadPtr + numSamplesReady) & (BUFFER_SIZE - 1);
-// RightFIFOHeadPtr = (RightFIFOHeadPtr + numSamplesReady) & (BUFFER_SIZE - 1);
-//WriteLog(" -> Left/RightFIFOHeadPtr: %04X/%04X, Left/RightFIFOTailPtr: %04X/%04X\n", LeftFIFOHeadPtr, RightFIFOHeadPtr, LeftFIFOTailPtr, RightFIFOTailPtr);
- }
-//Hmm. Seems that the SDL buffer isn't being starved by the DAC buffer...
-// else
-// WriteLog("DAC: Silence...!\n");
-}