void UPD7759Update(INT32 chip, INT16 *pSoundBuf, INT32 nLength) { #if defined FBA_DEBUG if (!DebugSnd_UPD7759Initted) bprintf(PRINT_ERROR, _T("UPD7759Update called without init\n")); if (chip > nNumChips) bprintf(PRINT_ERROR, _T("UPD7759Update called with invalid chip %x\n"), chip); #endif Chip = Chips[chip]; INT32 ClocksLeft = Chip->clocks_left; INT16 Sample = Chip->sample; UINT32 Step = Chip->step; UINT32 Pos = Chip->pos; /* loop until done */ if (Chip->state != STATE_IDLE) while (nLength != 0) { /* store the current sample */ pSoundBuf[0] += Sample << 7; pSoundBuf[1] += Sample << 7; pSoundBuf += 2; nLength--; /* advance by the number of clocks/output sample */ Pos += Step; /* handle clocks, but only in standalone mode */ while (Chip->rom && Pos >= FRAC_ONE) { INT32 ClocksThisTime = Pos >> FRAC_BITS; if (ClocksThisTime > ClocksLeft) ClocksThisTime = ClocksLeft; /* clock once */ Pos -= ClocksThisTime * FRAC_ONE; ClocksLeft -= ClocksThisTime; /* if we're out of clocks, time to handle the next state */ if (ClocksLeft == 0) { /* advance one state; if we hit idle, bail */ UPD7759AdvanceState(); if (Chip->state == STATE_IDLE) break; /* reimport the variables that we cached */ ClocksLeft = Chip->clocks_left; Sample = Chip->sample; } } } if (SlaveMode && ClocksLeft > 0) UPD7759SlaveModeUpdate(); Chip->clocks_left = ClocksLeft; Chip->pos = Pos; }
static void UPD7759SlaveModeUpdate() { UINT8 OldDrq = Chip->drq; UPD7759AdvanceState(); if (OldDrq != Chip->drq && Chip->drqcallback) { (*Chip->drqcallback)(Chip->drq); } }
void UPD7759Update(int chip, short *pSoundBuf, int nLength) { Chip = Chips[chip]; INT32 ClocksLeft = Chip->clocks_left; INT16 Sample = Chip->sample; UINT32 Step = Chip->step; UINT32 Pos = Chip->pos; /* loop until done */ if (Chip->state != STATE_IDLE) while (nLength != 0) { /* store the current sample */ pSoundBuf[0] += Sample << 7; pSoundBuf[1] += Sample << 7; pSoundBuf += 2; nLength--; /* advance by the number of clocks/output sample */ Pos += Step; /* handle clocks, but only in standalone mode */ while (Chip->rom && Pos >= FRAC_ONE) { int ClocksThisTime = Pos >> FRAC_BITS; if (ClocksThisTime > ClocksLeft) ClocksThisTime = ClocksLeft; /* clock once */ Pos -= ClocksThisTime * FRAC_ONE; ClocksLeft -= ClocksThisTime; /* if we're out of clocks, time to handle the next state */ if (ClocksLeft == 0) { /* advance one state; if we hit idle, bail */ UPD7759AdvanceState(); if (Chip->state == STATE_IDLE) break; /* reimport the variables that we cached */ ClocksLeft = Chip->clocks_left; Sample = Chip->sample; } } } if (SlaveMode && ClocksLeft > 0) UPD7759SlaveModeUpdate(); Chip->clocks_left = ClocksLeft; Chip->pos = Pos; }