예제 #1
0
int main(void)
{
	// Setup any needed hardware
	SetupUART(8);
	SetupTimer();
	SetupAccelerometer(TWOG, EIGHTBITS);
	InitADC();
	
	// Enable global interrupts
	sei();
	
	PORTB &= ~(_BV(PORTB5));	// Clear PB5, so it drives low by default (need to do this before switching it to an output)
	DDRB |= _BV(PORTB5);		// Set PB5 as an output
	
	// Test data
	struct SensorData data;
	
	while(1)
	{
		if(ready_to_send)
		{
			SetupPulseSensor();
			while(ADCSRA & _BV(ADSC));	//wait for conversion to finish DISCARD RESULT
			ADCSRA |= _BV(ADSC); //Start real conversion
			
			while(ADCSRA & _BV(ADSC));	//wait for conversion to finish USE RESULT
			
			data.pulse_val = ADCH;	//save result of pulse sensor
			_delay_us(9);
			
			SetupGSR();
			while(ADCSRA & _BV(ADSC));	//wait for conversion to finish DISCARD RESULT
			ADCSRA |= _BV(ADSC); //Start real conversion
			
			while(ADCSRA & _BV(ADSC));	//wait for conversion to finish USE RESULT
			
			data.gsr_val = ADCH;	//save result of GSR sensor
			_delay_us(9);
			
			// Grab the accelerometer data
			AccelGetData(&data);
			
			// Send some bytes so RealTerm can sync to it
			UARTTransmit(0xAA);
			UARTTransmit(24);
			// Send the data
			UARTTransmit(data.pulse_val);
			UARTTransmit(data.gsr_val + 15);
			UARTTransmit(data.accel_x + 128);
			UARTTransmit(data.accel_y + 128);
			UARTTransmit(data.accel_z + 128);
			
			UARTTransmit(0); 
			UARTTransmit(0); //to fill the UART receive fifo buffer in the tiva board for interrupt 
			
			
			ready_to_send = false;
		}
	}
}
예제 #2
0
int HAL_TIMER_TTC_TimerSetup(unsigned int nHz)
{
	int Status;
	TmrCntrSetup *TimerSetup;
	XTtcPs *TtcPsTick;

	SettingsTable.OutputHz = nHz;

	TimerSetup = &SettingsTable;

	/*
	 * Set up appropriate options for Ticker: interval mode without
	 * waveform output.
	 */
	TimerSetup->Options |= (XTTCPS_OPTION_INTERVAL_MODE |
					      XTTCPS_OPTION_WAVE_DISABLE);

	/*
	 * Calling the timer setup routine
	 *  . initialize device
	 *  . set options
	 */
	Status = SetupTimer(TTC_TICK_DEVICE_ID);
	if(Status != XST_SUCCESS) {
		return Status;
	}

	TtcPsTick = &TtcPsInst;

	/*
	 * Connect to the interrupt controller
	 */
	Status = HAL_GIC_ConnectIntRoutine(TTC_TICK_INTR_ID,
		(Xil_ExceptionHandler)TickHandler, (void *)TtcPsTick);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable the interrupt for the Timer counter
	 */
	HAL_GIC_EnableIntForDevice(TTC_TICK_INTR_ID);

	/*
	 * Enable the interrupts for the tick timer/counter
	 * We only care about the interval timeout.
	 */
	XTtcPs_EnableInterrupts(TtcPsTick, XTTCPS_IXR_INTERVAL_MASK);

	/*
	 * Start the tick timer/counter
	 */
	XTtcPs_Start(TtcPsTick);

	return Status;
}
/**
*
* This function sets up the waveform output timer counter (PWM).
*
* @param	None
*
* @return	XST_SUCCESS if everything sets up well, XST_FAILURE otherwise.
*
* @note		None
*
*****************************************************************************/
int SetupPWM(void)
{
	int Status;
	TmrCntrSetup *TimerSetup;
	XTtcPs *TtcPsPWM;

	TimerSetup = &(SettingsTable[TTC_PWM_DEVICE_ID]);

	/*
	 * Set up appropriate options for PWM: interval mode  and
	 * match mode for waveform output.
	 */
	TimerSetup->Options |= (XTTCPS_OPTION_INTERVAL_MODE |
					      XTTCPS_OPTION_MATCH_MODE);

	/*
	 * Calling the timer setup routine
	 * 	initialize device
	 * 	set options
	 */
	Status = SetupTimer(TTC_PWM_DEVICE_ID);
	if(Status != XST_SUCCESS) {
		return Status;
	}

	TtcPsPWM = &(TtcPsInst[TTC_PWM_DEVICE_ID]);

	/*
	 * Connect to the interrupt controller
	 */
	Status = XScuGic_Connect(&InterruptController, TTC_PWM_INTR_ID,
		(Xil_ExceptionHandler)PWMHandler, (void *)&MatchValue);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable the interrupt for the Timer counter
	 */
	XScuGic_Enable(&InterruptController, TTC_PWM_INTR_ID);

	/*
	 * Enable the interrupts for the tick timer/counter
	 * We only care about the interval timeout.
	 */
	XTtcPs_EnableInterrupts(TtcPsPWM, XTTCPS_IXR_INTERVAL_MASK);

	/*
	 * Start the tick timer/counter
	 */
	XTtcPs_Start(TtcPsPWM);

	return Status;
}
예제 #4
0
파일: main.c 프로젝트: z9u2k/remote
/**
 * prepare system on boot
 */
static void InitializeSystem(void) {
    #if defined(__18CXX)
        SetupTimer();
        INTCONbits.GIEH = 1;
    #endif
    
    InitLED();
    LED_Off();

    InitReceiver();
    ReceiverOff();
    
    USBDeviceInit();
}
예제 #5
0
int main(void) {

    init();

    Serial.begin(9600);

    SetupPort();
    SetupTimer();

    /* repeat forever */
    while (1) {

        for (int thisNote = 0; thisNote < size; thisNote++)
            PlayNote(melody[thisNote],duration[thisNote],FULL_NOTE);

        delay(2000);
    }
    return 0;
}
예제 #6
0
int main(void)
{
	SystemInit ( );

	SetupTimer ( );

	xTaskCreate( DispatcherTask, ( signed char * ) "Dispatcher", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
	xTaskCreate( PixelTask, ( signed char * ) "Pixel", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
	xTaskCreate( LCDTask, ( signed char * ) "Display", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
	xTaskCreate( USBTask, ( signed char * ) "USB", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
	xTaskCreate( MMCTask, ( signed char * ) "SD-Card", 512, NULL, 1, NULL );
	xTaskCreate( AudioTask, ( signed char * ) "USB", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
	vTaskStartScheduler ( );

	while ( 1 )
	{
	};

	return ( 0 );
};
예제 #7
0
파일: main.c 프로젝트: VajdaBela/LedProject
int main()
{
	
	//setup
	DDRB = 0xFF;
	DDRC |= (1 << SRCK);
	SetupTimer();
	Clear();
	
	while(1)
	{
		SetBufer();
			for(uint8_t br = 0; br < 7; ++br)
			{
				for(uint8_t br1 = 0; br1 < PLATE_NUM; ++br1)
				{
					PutData(bufer[br1][br]);
				}
				TurnOnRow(br);
			}
	}
}
예제 #8
0
long CALLBACK SPUfreeze(unsigned long ulFreezeMode,SPUFreeze_t * pF)
{
	int i;SPUOSSFreeze_t * pFO;
	
	if(!pF) return 0;                                     // first check
	
	if(!bSpuInit) return 0;                               // -> no init, no call
	
	if(ulFreezeMode)                                      // info or save?
  {//--------------------------------------------------//
		if(ulFreezeMode==1)                                 
			memset(pF,0,sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t));
		
		strcpy(pF->szSPUName,"PBOSS");
		pF->ulFreezeVersion=100;
		pF->ulFreezeSize=sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t);
		
		if(ulFreezeMode==2) return 1;                       // info mode? ok, bye
		// save mode:
		RemoveTimer();                                      // stop timer

		memcpy(pF->cSPURam,spuMem,0x80000);                 // copy common infos
		memcpy(pF->cSPUPort,regArea,0x200);
		
		if(xapGlobal && XAPlay!=XAFeed)                     // some xa
    {
			pF->xaS=*xapGlobal;     
    }
		else 
			memset(&pF->xaS,0,sizeof(xa_decode_t));           // or clean xa


		pFO=(SPUOSSFreeze_t *)(pF+1);                       // store special stuff
		
		pFO->spuIrq=spuIrq;
		if(pSpuIrq)
			pFO->pSpuIrq = (unsigned long)pSpuIrq-(unsigned long)spuMemC;
		else
			pFO->pSpuIrq = 0;

		// extra crash data
		pFO->dwNewChannel = dwNewChannel;
		pFO->dwNoiseVal = dwNoiseVal;
		pFO->spuAddr = spuAddr;
		pFO->spuCtrl = spuCtrl;
		pFO->spuStat = spuStat;

		for(i=0;i<MAXCHAN;i++)
    {
			memcpy((void *)&pFO->s_chan[i],(void *)&s_chan[i],sizeof(SPUCHAN));
			
			if(pFO->s_chan[i].pStart)
				pFO->s_chan[i].pStart-=(unsigned long)spuMemC;

			if(pFO->s_chan[i].pCurr)
				pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;
			
			if(pFO->s_chan[i].pLoop)
				pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;
		}
		
		SetupTimer();                                       // sound processing on again
		
		return 1;
		//--------------------------------------------------//
  }
	
	if(ulFreezeMode!=0) return 0;                         // bad mode? bye
	
#ifdef _WINDOWS
	//if(iDebugMode && IsWindow(hWDebug))                   // clean debug mute infos
  //SendMessage(hWDebug,WM_MUTE,0,0);
	if(IsBadReadPtr(pF,sizeof(SPUFreeze_t)))              // check bad emu stuff
		return 0;
#endif
	
	RemoveTimer();                                        // we stop processing while doing the save!
	
	memcpy(spuMem,pF->cSPURam,0x80000);                   // get ram
	memcpy(regArea,pF->cSPUPort,0x200);

	if(pF->xaS.nsamples<=4032)                            // start xa again
		SPUplayADPCMchannel(&pF->xaS);

	xapGlobal=0;
	
	if(!strcmp(pF->szSPUName,"PBOSS") &&                  
    pF->ulFreezeVersion==100)
		LoadStateV100(pF);
	else
		LoadStateUnknown(pF);
	
	// repair some globals
	for(i=0;i<=62;i+=2)
		SPUwriteRegister(H_Reverb+i,regArea[(H_Reverb+i-0xc00)>>1]);
	SPUwriteRegister(H_SPUReverbAddr,regArea[(H_SPUReverbAddr-0xc00)>>1]);
	SPUwriteRegister(H_SPUrvolL,regArea[(H_SPUrvolL-0xc00)>>1]);
	SPUwriteRegister(H_SPUrvolR,regArea[(H_SPUrvolR-0xc00)>>1]);
	
	SPUwriteRegister(H_SPUctrl,(unsigned short)(regArea[(H_SPUctrl-0xc00)>>1]|0x4000));
	SPUwriteRegister(H_SPUstat,regArea[(H_SPUstat-0xc00)>>1]);
	SPUwriteRegister(H_CDLeft,regArea[(H_CDLeft-0xc00)>>1]);
	SPUwriteRegister(H_CDRight,regArea[(H_CDRight-0xc00)>>1]);
	
	SPUwriteRegister(H_SPUmvolL,regArea[(H_SPUmvolL-0xc00)>>1]);
	SPUwriteRegister(H_SPUmvolR,regArea[(H_SPUmvolR-0xc00)>>1]);

	// fix to prevent new interpolations from crashing
	for(i=0;i<MAXCHAN;i++) s_chan[i].SB[28]=0;
	
	// repair LDChen's ADSR changes
	for(i=0;i<24;i++)
  {
		SPUwriteRegister(0x1f801c08+(i<<4),regArea[ ((i<<4)+0x08)>>1 ] );
		SPUwriteRegister(0x1f801c0a+(i<<4),regArea[ ((i<<4)+0x0a)>>1 ] );
  }
	
	SetupTimer();                                         // start sound processing again
	
	
	// stop load crackling
	total_cpu_cycles = 0;
	total_apu_cycles = 0;
	cpu_cycles = 0;
	iCycle = 0;


	// fix movie lag
	CDDAPlay  = CDDAStart;
	CDDAFeed  = CDDAStart;
	CDDARepeat = 0;
	
	XAPlay  = XAStart;
	XAFeed  = XAStart;
	XARepeat = 0;
	
	lastxa_lc = 0; lastxa_rc = 0;
	lastcd_lc = 0, lastcd_rc = 0;

	
	// win32
	ResetSound();


	// clear out gaussian registers
	memset( out_gauss_window, 0, 8*4 );
	memset( xa_gauss_window, 0, 8*4 );

	
	return 1;
}
예제 #9
0
파일: freeze.c 프로젝트: IWhisper/libpsx
long CALLBACK SPU_freeze(uint32_t ulFreezeMode,SPUFreeze_t * pF)
{
 int i;SPUOSSFreeze_t * pFO;

 if(!pF) return 0;                                     // first check

 if(ulFreezeMode)                                      // info or save?
  {//--------------------------------------------------//
   if(ulFreezeMode==1)                                 
    memset(pF,0,sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t));

   strcpy(pF->szSPUName,"PBOSS");
   pF->ulFreezeVersion=5;
   pF->ulFreezeSize=sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t);

   if(ulFreezeMode==2) return 1;                       // info mode? ok, bye
                                                       // save mode:
   RemoveTimer();                                      // stop timer

   memcpy(pF->cSPURam,spuMem,0x80000);                 // copy common infos
   memcpy(pF->cSPUPort,regArea,0x200);

   if(xapGlobal && XAPlay!=XAFeed)                     // some xa
    {
     pF->xaS=*xapGlobal;     
    }
   else 
   memset(&pF->xaS,0,sizeof(xa_decode_t));             // or clean xa

   pFO=(SPUOSSFreeze_t *)(pF+1);                       // store special stuff

   pFO->spuIrq=spuIrq;
   if(pSpuIrq)  pFO->pSpuIrq  = (unsigned long)pSpuIrq-(unsigned long)spuMemC;

   pFO->spuAddr=spuAddr;
   if(pFO->spuAddr==0) pFO->spuAddr=0xbaadf00d;

   for(i=0;i<MAXCHAN;i++)
    {
     save_channel(&pFO->s_chan[i],&s_chan[i],i);
     if(pFO->s_chan[i].pStart)
      pFO->s_chan[i].pStart-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pCurr)
      pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pLoop)
      pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;
    }

   SetupTimer();                                       // sound processing on again

   return 1;
   //--------------------------------------------------//
  }
                                                       
 if(ulFreezeMode!=0) return 0;                         // bad mode? bye

 RemoveTimer();                                        // we stop processing while doing the save!

 memcpy(spuMem,pF->cSPURam,0x80000);                   // get ram
 memcpy(regArea,pF->cSPUPort,0x200);

 if(pF->xaS.nsamples<=4032)                            // start xa again
  SPU_playADPCMchannel(&pF->xaS);

 xapGlobal=0;

 if(!strcmp(pF->szSPUName,"PBOSS") && pF->ulFreezeVersion==5)
   LoadStateV5(pF);
 else LoadStateUnknown(pF);

 lastch = -1;

 // repair some globals
 for(i=0;i<=62;i+=2)
  SPU_writeRegister(H_Reverb+i,regArea[(H_Reverb+i-0xc00)>>1]);
 SPU_writeRegister(H_SPUReverbAddr,regArea[(H_SPUReverbAddr-0xc00)>>1]);
 SPU_writeRegister(H_SPUrvolL,regArea[(H_SPUrvolL-0xc00)>>1]);
 SPU_writeRegister(H_SPUrvolR,regArea[(H_SPUrvolR-0xc00)>>1]);

 SPU_writeRegister(H_SPUctrl,(unsigned short)(regArea[(H_SPUctrl-0xc00)>>1]|0x4000));
 SPU_writeRegister(H_SPUstat,regArea[(H_SPUstat-0xc00)>>1]);
 SPU_writeRegister(H_CDLeft,regArea[(H_CDLeft-0xc00)>>1]);
 SPU_writeRegister(H_CDRight,regArea[(H_CDRight-0xc00)>>1]);

 // fix to prevent new interpolations from crashing
 for(i=0;i<MAXCHAN;i++) s_chan[i].SB[28]=0;

 SetupTimer();                                         // start sound processing again

 return 1;
}
예제 #10
0
파일: freeze.c 프로젝트: emukidid/pcsxgc
////////////////////////////////////////////////////////////////////////
// SPUFREEZE: called by main emu on savestate load/save
////////////////////////////////////////////////////////////////////////
//TODO: ENDIAN FIX ME!!
long CALLBACK PEOPS_SPUfreeze(unsigned long ulFreezeMode,SPUFreeze_t * pF)
{
 int i;SPUOSSFreeze_t * pFO;

 if(!pF) return 0;                                     // first check

 if(ulFreezeMode)                                      // info or save?
  {//--------------------------------------------------//
   if(ulFreezeMode==1)                                 
    memset(pF,0,sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t));

   strcpy(pF->szSPUName,"PBOSS");
   pF->ulFreezeVersion=5;
   pF->ulFreezeSize=sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t);

   if(ulFreezeMode==2) return 1;                       // info mode? ok, bye
                                                       // save mode:
   RemoveTimer();                                      // stop timer

   //memcpy(pF->cSPURam,spuMem,0x80000);                 // done in Misc.c
   memcpy(pF->cSPUPort,regArea,0x200);

   if(xapGlobal && XAPlay!=XAFeed)                     // some xa
    {
     pF->xaS=*xapGlobal;     
    }
   else 
   memset(&pF->xaS,0,sizeof(xa_decode_t));             // or clean xa

   pFO=(SPUOSSFreeze_t *)(pF+1);                       // store special stuff

   pFO->spuIrq=spuIrq;
   if(pSpuIrq)  pFO->pSpuIrq  = (unsigned long)pSpuIrq-(unsigned long)spuMemC;

   for(i=0;i<MAXCHAN;i++)
    {
     memcpy((void *)&pFO->s_chan[i],(void *)&s_chan[i],sizeof(SPUCHAN));
     if(pFO->s_chan[i].pStart)
      pFO->s_chan[i].pStart-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pCurr)
      pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pLoop)
      pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;
    }

   SetupTimer();                                       // sound processing on again

   return 1;
   //--------------------------------------------------//
  }
                                                       
 if(ulFreezeMode!=0) return 0;                         // bad mode? bye

#ifdef _WINDOWS
 if(iSPUDebugMode && IsWindow(hWDebug))                   // clean debug mute infos
  SendMessage(hWDebug,WM_MUTE,0,0);
 if(IsBadReadPtr(pF,sizeof(SPUFreeze_t)))              // check bad emu stuff
  return 0;
#endif

 RemoveTimer();                                        // we stop processing while doing the save!

 //memcpy(spuMem,pF->cSPURam,0x80000);                   // get ram (done in Misc.c)
 memcpy(regArea,pF->cSPUPort,0x200);

 if(pF->xaS.nsamples<=4032)                            // start xa again
  PEOPS_SPUplayADPCMchannel(&pF->xaS);

 xapGlobal=0;

 if(!strcmp(pF->szSPUName,"PBOSS") &&                  
    pF->ulFreezeVersion==5)
      LoadStateV5(pF);
 else LoadStateUnknown(pF);

 // repair some globals
 for(i=0;i<=62;i+=2)
  PEOPS_SPUwriteRegister(H_Reverb+i,regArea[(H_Reverb+i-0xc00)>>1]);
 PEOPS_SPUwriteRegister(H_SPUReverbAddr,regArea[(H_SPUReverbAddr-0xc00)>>1]);
 PEOPS_SPUwriteRegister(H_SPUrvolL,regArea[(H_SPUrvolL-0xc00)>>1]);
 PEOPS_SPUwriteRegister(H_SPUrvolR,regArea[(H_SPUrvolR-0xc00)>>1]);

 PEOPS_SPUwriteRegister(H_SPUctrl,(unsigned short)(regArea[(H_SPUctrl-0xc00)>>1]|0x4000));
 PEOPS_SPUwriteRegister(H_SPUstat,regArea[(H_SPUstat-0xc00)>>1]);
 PEOPS_SPUwriteRegister(H_CDLeft,regArea[(H_CDLeft-0xc00)>>1]);
 PEOPS_SPUwriteRegister(H_CDRight,regArea[(H_CDRight-0xc00)>>1]);

 // fix to prevent new interpolations from crashing
 for(i=0;i<MAXCHAN;i++) s_chan[i].SB[28]=0;

 // repair LDChen's ADSR changes
 for(i=0;i<24;i++)
  {
   PEOPS_SPUwriteRegister(0x1f801c00+(i<<4)+0xc8,regArea[(i<<3)+0x64]);
   PEOPS_SPUwriteRegister(0x1f801c00+(i<<4)+0xca,regArea[(i<<3)+0x65]);
  }

 SetupTimer();                                         // start sound processing again

 return 1;
}
예제 #11
0
EXPORT_GCC long CALLBACK SPU2freeze(unsigned long ulFreezeMode,SPUFreeze_t * pFt)
{
 int i;SPUOSSFreeze_t * pFO;SPUFreeze_Ex_t * pF;

 if(!pFt) return 0;                                    // first check

 if(ulFreezeMode)                                      // save?
  {//--------------------------------------------------//
   pFt->size=sizeof(SPUFreeze_Ex_t)+sizeof(SPUOSSFreeze_t);

   if(ulFreezeMode==2) return 0;                       // emu just asking for size? bye

   if(!pFt->data) return 0;

   pF=(SPUFreeze_Ex_t *)pFt->data;

   memset(pF,0,pFt->size);

   strcpy(pF->szSPUName,"PBOSS2");
   pF->ulFreezeVersion=1;
   pF->ulFreezeSize=pFt->size;
                                                       // save mode:
   RemoveTimer();                                      // stop timer

   memcpy(pF->cSPURam,spuMem,2*1024*1024);             // copy common infos
   memcpy(pF->cSPUPort,regArea,64*1024);

   pFO=(SPUOSSFreeze_t *)(pF+1);                       // store special stuff

   pFO->spuIrq0=spuIrq2[0];
   if(pSpuIrq[0])  pFO->pSpuIrq0 = (unsigned long)pSpuIrq[0]-(unsigned long)spuMemC;
   pFO->spuIrq1=spuIrq2[1];
   if(pSpuIrq[1])  pFO->pSpuIrq1 = (unsigned long)pSpuIrq[1]-(unsigned long)spuMemC;

   for(i=0;i<MAXCHAN;i++)
    {
     memcpy((void *)&pFO->s_chan[i],(void *)&s_chan[i],sizeof(SPUCHAN));
     if(pFO->s_chan[i].pStart)
      pFO->s_chan[i].pStart-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pCurr)
      pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pLoop)
      pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;
    }

   SetupTimer();                                       // sound processing on again

   return 1;
   //--------------------------------------------------//
  }

                                                       // load state:
#ifdef _WINDOWS
 if(iDebugMode==1 && IsWindow(hWDebug))                // we have to disbale the debug window, if active
  DestroyWindow(hWDebug);
 hWDebug=0;

 if(IsBadReadPtr(pFt,sizeof(SPUFreeze_t)))             // check bad emu stuff
  return 0;
#endif

 if(pFt->size!=sizeof(SPUFreeze_Ex_t)+                 // not our stuff? bye
               sizeof(SPUOSSFreeze_t)) return 0;
 if(!pFt->data) return 0;

 pF=(SPUFreeze_Ex_t *)pFt->data;

 RemoveTimer();                                        // we stop processing while doing the save!

 memcpy(spuMem,pF->cSPURam,2*1024*1024);               // get ram
 memcpy(regArea,pF->cSPUPort,64*1024);

 if(!strcmp(pF->szSPUName,"PBOSS2") &&
    pF->ulFreezeVersion==1)
      LoadStateV1(pF);
 else LoadStateUnknown(pF);

 // repair some globals
 for(i=0x7FFE;i>=0x0000;i-=2)
  {
   SPU2write(i,regArea[i]);
  }

 // fix to prevent new interpolations from crashing
 for(i=0;i<MAXCHAN;i++) s_chan[i].SB[28]=0;

 SetupTimer();                                         // start sound processing again

#ifdef _WINDOWS
 if(iDebugMode)                                        // re-activate windows debug dialog
  {
   hWDebug=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DEBUG),
                        NULL,(DLGPROC)DebugDlgProc);
   SetWindowPos(hWDebug,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
   UpdateWindow(hWDebug);
   SetFocus(hWMain);
  }
#endif

 return 1;
}
예제 #12
0
파일: freeze.c 프로젝트: bsv798/pcsxr
long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF)
{
 int i;SPUOSSFreeze_t * pFO;

 if(!pF) return 0;                                     // first check

 if(!bSpuInit) return 0;

 if(ulFreezeMode)                                      // info or save?
  {//--------------------------------------------------//
   if(ulFreezeMode==1)                                 
    memset(pF,0,sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t));

   strcpy(pF->szSPUName,"PBOSS");
   pF->ulFreezeVersion=5;
   pF->ulFreezeSize=sizeof(SPUFreeze_t)+sizeof(SPUOSSFreeze_t);

   if(ulFreezeMode==2) return 1;                       // info mode? ok, bye
                                                       // save mode:
   RemoveTimer();                                      // stop timer

   memcpy(pF->cSPURam,spuMem,0x80000);                 // copy common infos
   memcpy(pF->cSPUPort,regArea,0x200);

   if(xapGlobal && XAPlay!=XAFeed)                     // some xa
    {
     pF->xaS=*xapGlobal;     
    }
   else 
   memset(&pF->xaS,0,sizeof(xa_decode_t));             // or clean xa

   pFO=(SPUOSSFreeze_t *)(pF+1);                       // store special stuff

   pFO->spuIrq=spuIrq;
   if(pSpuIrq)  pFO->pSpuIrq  = (unsigned long)pSpuIrq-(unsigned long)spuMemC;

   pFO->spuAddr=spuAddr;
   if(pFO->spuAddr==0) pFO->spuAddr=0xbaadf00d;

   for(i=0;i<MAXCHAN;i++)
    {
     memcpy((void *)&pFO->s_chan[i],(void *)&s_chan[i],sizeof(SPUCHAN));
     if(pFO->s_chan[i].pStart)
      pFO->s_chan[i].pStart-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pCurr)
      pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;
     if(pFO->s_chan[i].pLoop)
      pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;
    }

   SetupTimer();                                       // sound processing on again

   return 1;
   //--------------------------------------------------//
  }
                                                       
 if(ulFreezeMode!=0) return 0;                         // bad mode? bye

#ifdef _WINDOWS
 if(iDebugMode && IsWindow(hWDebug))                   // clean debug mute infos
  SendMessage(hWDebug,WM_MUTE,0,0);
 if(IsBadReadPtr(pF,sizeof(SPUFreeze_t)))              // check bad emu stuff
  return 0;
#endif

 RemoveTimer();                                        // we stop processing while doing the save!

 memcpy(spuMem,pF->cSPURam,0x80000);                   // get ram
 memcpy(regArea,pF->cSPUPort,0x200);

 if(pF->xaS.nsamples<=4032)                            // start xa again
  SPUplayADPCMchannel(&pF->xaS);

 xapGlobal=0;

 if(!strcmp(pF->szSPUName,"PBOSS") && pF->ulFreezeVersion==5)
   LoadStateV5(pF);
 else LoadStateUnknown(pF);

 lastch = -1;

 // repair some globals
 for(i=0;i<=62;i+=2)
  SPUwriteRegister(H_Reverb+i,regArea[(H_Reverb+i-0xc00)>>1]);
 SPUwriteRegister(H_SPUReverbAddr,regArea[(H_SPUReverbAddr-0xc00)>>1]);
 SPUwriteRegister(H_SPUrvolL,regArea[(H_SPUrvolL-0xc00)>>1]);
 SPUwriteRegister(H_SPUrvolR,regArea[(H_SPUrvolR-0xc00)>>1]);

 SPUwriteRegister(H_SPUctrl,(unsigned short)(regArea[(H_SPUctrl-0xc00)>>1]|0x4000));
 SPUwriteRegister(H_SPUstat,regArea[(H_SPUstat-0xc00)>>1]);
 SPUwriteRegister(H_CDLeft,regArea[(H_CDLeft-0xc00)>>1]);
 SPUwriteRegister(H_CDRight,regArea[(H_CDRight-0xc00)>>1]);

 // fix to prevent new interpolations from crashing
 for(i=0;i<MAXCHAN;i++) s_chan[i].SB[28]=0;

 SetupTimer();                                         // start sound processing again

 // stop load crackling
 //cpu_cycles = 0;
 //iCycle = 0;

 // fix movie lag
 CDDAEnd   = CDDAStart + 44100;
 CDDAPlay  = CDDAStart;
 CDDAFeed  = CDDAStart;

 XAPlay  = XAStart;
 XAFeed  = XAStart;
 XAEnd   = XAStart + 44100;

 return 1;
}