void UpdateFifoFlag() { if (gUcode == UNDEFINED_UCODE) return; if (gUcode == 1) { *AudioInfo.AI_STATUS_REG |= AI_STATUS_FIFO_FULL; if (remainingBytes <= MAXBUFFER-LOCK_SIZE) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); } } else { if (*AudioInfo.AI_LEN_REG <= MAXBUFFER-LOCK_SIZE) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); } else *AudioInfo.AI_STATUS_REG |= AI_STATUS_FIFO_FULL; } }
EXPORT void CALL AiLenChanged (void) { int count, offset=0, temp; DWORD dwStatus; if (!lpdsbuf) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); return;} else if (gUcode == UNDEFINED_UCODE) { gUcode = 88; ucodeDetected = TRUE; } // if (gUcode == UNDEFINED_UCODE) {DetectMicrocode(); } if ((gUcode != 4) /*&& (gUcode != UNDEFINED_UCODE)*/)//Hack for MusyX *AudioInfo.AI_STATUS_REG |= AI_STATUS_FIFO_FULL; //if (*AudioInfo.AI_LEN_REG == 0) { return; } //this breaks sound in Zelda load states!! Snd1Len = (*AudioInfo.AI_LEN_REG & 0x3FFF8); temp = Snd1Len; Snd1ReadPos = AudioInfo.RDRAM + (*AudioInfo.AI_DRAM_ADDR_REG & 0x00FFFFF8); if (Playing) { for (count = 0; count < 3; count ++) { if (SndBuffer[count] == Buffer_Playing) { offset = (count + 1) & 3; } } } else { offset = 0; } for (count = 0; count < 3; count ++) { if (SndBuffer[(count + offset) & 3] == Buffer_HalfFull) { FillBuffer((count + offset) & 3); count = 3; } } for (count = 0; count < 3; count ++) { if (SndBuffer[(count + offset) & 3] == Buffer_Full) { FillBuffer((count + offset + 1) & 3); FillBuffer((count + offset + 2) & 3); count = 20; } } if (count < 10) { FillBuffer((0 + offset) & 3); FillBuffer((1 + offset) & 3); FillBuffer((2 + offset) & 3); } }
EXPORT void CALL Update (BOOL Wait) { DWORD dwEvt; if (!lpdsbuf) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); return; } else if (gUcode == UNDEFINED_UCODE) { gUcode = 88; ucodeDetected = TRUE; } if (Wait) { dwEvt = MsgWaitForMultipleObjects(NUMCAPTUREEVENTS,rghEvent,FALSE, INFINITE,QS_ALLINPUT); } else { dwEvt = MsgWaitForMultipleObjects(NUMCAPTUREEVENTS,rghEvent,FALSE, 0,QS_ALLINPUT); } dwEvt -= WAIT_OBJECT_0; if (dwEvt == NUMCAPTUREEVENTS) { return; } switch (dwEvt) { case 0: SndBuffer[0] = Buffer_Empty; FillSectionWithSilence(0); SndBuffer[1] = Buffer_Playing; FillBuffer(2); FillBuffer(0); break; case 1: SndBuffer[1] = Buffer_Empty; FillSectionWithSilence(1); SndBuffer[2] = Buffer_Playing; FillBuffer(0); FillBuffer(1); break; case 2: SndBuffer[2] = Buffer_Empty; FillSectionWithSilence(2); SndBuffer[0] = Buffer_Playing; FillBuffer(1); FillBuffer(2); break; } }
void FillBuffer ( int buffer ) { //void AddToBuffer (void *sndptr, DWORD sndlen); DWORD dwBytesLocked; VOID *lpvData; if (!audioIsPlaying) StartAudio(); if (gUcode != 4) if (Snd1Len == 0) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); return; } if (SndBuffer[buffer] == Buffer_Empty) { if (Snd1Len >= BufferSize) { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, BufferSize * buffer,BufferSize, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_Full; Snd1ReadPos += dwBytesLocked; Snd1Len -= dwBytesLocked; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } else { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, BufferSize * buffer,Snd1Len, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_HalfFull; Snd1ReadPos += dwBytesLocked; SpaceLeft = BufferSize - Snd1Len; Snd1Len = 0; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } } else if (SndBuffer[buffer] == Buffer_HalfFull) { if (Snd1Len >= SpaceLeft) { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, (BufferSize * (buffer + 1)) - SpaceLeft ,SpaceLeft, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_Full; Snd1ReadPos += dwBytesLocked; Snd1Len -= dwBytesLocked; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } else { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, (BufferSize * (buffer + 1)) - SpaceLeft,Snd1Len, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_HalfFull; Snd1ReadPos += dwBytesLocked; SpaceLeft = SpaceLeft - Snd1Len; Snd1Len = 0; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } } if (gUcode != 4) if ((Snd1Len == 0) /*&& (gUcode != UNDEFINED_UCODE)*/) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); } }