Ejemplo n.º 1
0
void UPD7759StartWrite(UINT8 Data)
{
	UINT8 Oldstart = Chip->start;
	Chip->start = (Data != 0);

	if (Chip->state == STATE_IDLE && !Oldstart && Chip->start && Chip->reset) {
		Chip->state = STATE_START;
		
		if (SlaveMode) UPD7759SlaveModeUpdate();
	}
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
void UPD7759StartWrite(INT32 chip, UINT8 Data)
{
#if defined FBA_DEBUG
    if (!DebugSnd_UPD7759Initted) bprintf(PRINT_ERROR, _T("UPD7759StartWrite called without init\n"));
    if (chip > nNumChips) bprintf(PRINT_ERROR, _T("UPD7759StartWrite called with invalid chip %x\n"), chip);
#endif

    Chip = Chips[chip];
    UINT8 Oldstart = Chip->start;
    Chip->start = (Data != 0);

    if (Chip->state == STATE_IDLE && !Oldstart && Chip->start && Chip->reset) {
        Chip->state = STATE_START;

        if (SlaveMode) UPD7759SlaveModeUpdate();
    }
}
Ejemplo n.º 4
0
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 */
            INT32 nLeftSample = 0;
            INT32 nRightSample = 0;

            if ((Chip->output_dir & BURN_SND_ROUTE_LEFT) == BURN_SND_ROUTE_LEFT) {
                nLeftSample += (INT32)((Sample << 7) * Chip->volume);
            }
            if ((Chip->output_dir & BURN_SND_ROUTE_RIGHT) == BURN_SND_ROUTE_RIGHT) {
                nRightSample += (INT32)((Sample << 7) * Chip->volume);
            }

            nLeftSample = BURN_SND_CLIP(nLeftSample);
            nRightSample = BURN_SND_CLIP(nRightSample);

            pSoundBuf[0] += nLeftSample;
            pSoundBuf[1] += nRightSample;
            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;
}