Esempio n. 1
0
		void Cartridge::ReadUnif(std::istream& stream,FavoredSystem favoredSystem,Profile& profile)
		{
			Log::Suppressor logSupressor;
			Ram prg, chr;
			ProfileEx profileEx;
			Unif::Load( stream, NULL, false, NULL, prg, chr, favoredSystem, profile, profileEx, NULL );
			SetupBoard( prg, chr, NULL, NULL, profile, profileEx, NULL );
		}
Esempio n. 2
0
		void Cartridge::ReadRomset(std::istream& stream,FavoredSystem favoredSystem,bool askSystem,Profile& profile)
		{
			Log::Suppressor logSupressor;
			Ram prg, chr;
			ProfileEx profileEx;
			Romset::Load( stream, NULL, false, NULL, prg, chr, favoredSystem, askSystem, profile, true );
			SetupBoard( prg, chr, NULL, NULL, profile, profileEx, NULL, true );
		}
Esempio n. 3
0
main()
{
	Dudes *Board[8][8];
	CreateBoard(Board);
	SetupBoard(Board);
	while (1)
	{
		TakeTurn(Board);
	}
}
Esempio n. 4
0
void RunSpeedSimulation
(
__global int* intStream,
  int* pCharPos,
  int cSimulations,
  int seed
)
{
  //These are needed for FastRandom function calls
  unsigned long mt[N];
  int mti=N+1;

  SimulationResults results;
  Board board;
      
  double averageResult = 0.0;

  double blackWinPercentage = 0;
  int x;

  SetupBoard(&board);

  init_genrand(seed, mt, &mti);

  results.blackPlays = 0;
  results.whitePlays = 0;

  for(x = 0; x < cSimulations; x++)
  {
    MonteCarloSimulate(&board, genrand_int32(mt, &mti), &results, mt, &mti);
    averageResult += results.scoreInFavourOfBlack;

    if(results.scoreInFavourOfBlack > 0)
      blackWinPercentage++;
  }
  

  WriteStringToIntStream(intStream, pCharPos, "(");
  WriteFloatToIntStream(intStream, pCharPos, (float)averageResult / cSimulations, 5);
  WriteStringToIntStream(intStream, pCharPos, ") <average result> with ");

  WriteStringToIntStream(intStream, pCharPos, "(");
  WriteFloatToIntStream(intStream, pCharPos, (float)blackWinPercentage / cSimulations, 5);
  WriteStringToIntStream(intStream, pCharPos, ") <average black win percentage>\n");

  WriteStringToIntStream(intStream, pCharPos, "(");
  WriteFloatToIntStream(intStream, pCharPos, (float)results.blackPlays / cSimulations, 5);
  WriteStringToIntStream(intStream, pCharPos, ") <average black plays>\n");

  WriteStringToIntStream(intStream, pCharPos, "(");
  WriteFloatToIntStream(intStream, pCharPos, (float)results.whitePlays / cSimulations, 5);
  WriteStringToIntStream(intStream, pCharPos, ") <average white plays>\n");

}
Esempio n. 5
0
int main()
{
    Setup();
    SetupBoard();
    while (!(key[KEY_ESC]) && RedLeft > 0 && BlackLeft > 0)
    {
		DrawBackGround();
		Clicks();
		CheckPlay();
        Flip();
    }
    destroy_bitmap(buffer2);
    destroy_bitmap(buffer);
    unload_datafile(data);
}
Esempio n. 6
0
void RunBasicSimulations
(
__global int* intStream,
  int* pCharPos
)
{
  int streamPos = 0;

  //These are needed for FastRandom function calls
  unsigned long mt[N];
  int mti=N+1;
 
  Board board;
 
 
  SetupBoard(&board);
  Board_ToString(&board, intStream, pCharPos);
  WriteCharToIntStream(intStream, pCharPos, '\n');  
  
  Board_MetaToString(&board, intStream, pCharPos);
  WriteCharToIntStream(intStream, pCharPos, '\n');

  Board_LibsToString(&board, intStream, pCharPos);
  WriteCharToIntStream(intStream, pCharPos, '\n');    
   
  {
    SimulationResults results;
            
    MonteCarloSimulate(&board, 20452, &results, mt, &mti);    
    WriteStringToIntStream(intStream, pCharPos, "(");
    WriteFloatToIntStream(intStream, pCharPos, (float)results.scoreInFavourOfBlack, 0);
    WriteStringToIntStream(intStream, pCharPos, ") <1st black score>\n");
     
    MonteCarloSimulate(&board, 3452, &results, mt, &mti);
    WriteStringToIntStream(intStream, pCharPos, "(");
    WriteFloatToIntStream(intStream, pCharPos, (float)results.scoreInFavourOfBlack, 0);
    WriteStringToIntStream(intStream, pCharPos, ") <2nd black score>\n");
  
    MonteCarloSimulate(&board, 3422, &results, mt, &mti);
    WriteStringToIntStream(intStream, pCharPos, "(");
    WriteFloatToIntStream(intStream, pCharPos, (float)results.scoreInFavourOfBlack, 0);
    WriteStringToIntStream(intStream, pCharPos, ") <3rd black score>\n");    
  }
}
int main(void)
#endif
{
    BYTE RecvdByte;

    initCDC(); // setup the CDC state machine
    SetupBoard(); //setup the hardware, customize for your hardware
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // initialize USB. TODO: Remove magic with macro
    usb_start(); //start the USB peripheral

// PIC18 INTERRUPTS
// It is the users resposibility to set up high, low or legacy mode
// interrupt operation. The following macros for high and low interrupt
// setup have been removed:

//#define EnableUsbHighPriInterrupt()             do { RCONbits.IPEN = 1; IPR2bits.USBIP = 1; INTCONbits.GIEH = 1;} while(0) // JTR new
//#define EnableUsbLowPriInterrupt()              do { RCONbits.IPEN = 1; IPR2bits.USBIP = 0; INTCONbits.GIEL = 1;} while(0)  // JTR new

// By default, the interrupt mode will be LEGACY (ISR Vector 0x08)
// (Same as high priority vector wise but the operation (latency) is
// not the same. Consult the data sheet for details.)

// If a priority mode is enabled then this affects ALL other interrupt
// sources therefore it does not belong to the usb stack to be
// doing this. It is a global, user application choice.

#if defined USB_INTERRUPTS // See the prj_usb_config.h file.
    EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST);
#if defined __18CXX //turn on interrupts for PIC18
    INTCONbits.PEIE = 1;
    INTCONbits.GIE = 1;
#endif
    EnableUsbGlobalInterrupt(); // Only enables global USB interrupt. Chip interrupts must be enabled by the user (PIC18)
#endif


// Wait for USB to connect
    do {
#ifndef USB_INTERRUPTS
        usb_handler();
#endif
    } while (usb_device_state < CONFIGURED_STATE);

    usb_register_sof_handler(CDCFlushOnTimeout); // Register our CDC timeout handler after device configured

// Main echo loop
    do {

// If USB_INTERRUPT is not defined each loop should have at least one additional call to the usb handler to allow for control transfers.
#ifndef USB_INTERRUPTS
        usb_handler();
#endif

// Receive and send method 1
// The CDC module will call usb_handler each time a BULK CDC packet is sent or received.
// If there is a byte ready will return with the number of bytes available and received byte in RecvdByte
        if (poll_getc_cdc(&RecvdByte)) 
            putc_cdc(RecvdByte+1); //

// Receive and send method 2
// Same as poll_getc_cdc except that byte is NOT removed from queue.
// This function will wait for a byte and return and remove it from the queue when it arrives.
        if (peek_getc_cdc(&RecvdByte)) { 
            RecvdByte = getc_cdc(); 
            putc_cdc(RecvdByte+1);
        }

// Receive and send method 3
// If there is a byte ready will return with the number of bytes available and received byte in RecvdByte
// use CDC_Flush_In_Now(); when it has to be sent immediately and not wait for a timeout condition.
        if (poll_getc_cdc(&RecvdByte)) { 
            putc_cdc(RecvdByte+1); //
            CDC_Flush_In_Now(); 
        }
    } while (1);

} //end main
Esempio n. 8
0
int main ( void )
{
    /** pin buttons locals */
    volatile bool regPinButton1;
    volatile bool regPinButton2;
    
    /** speed local */
    short iRefSpeed;
    
    // Configure Oscillator to operate the device at 40Mhz
    // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
    // Fosc= 8*40/(2*2)= 80Mhz for 8M input clock
    PLLFBD = 38;                // M=40
    CLKDIVbits.PLLPOST = 0;     // N1=2
    CLKDIVbits.PLLPRE = 0;      // N2=2
    
//    while(OSCCONbits.LOCK != 1) {};     // Wait for PLL to loc
    
    /** setup dsPIC ports */
    SetupPorts();
    
    /** init user parameters */
    InitUserParms();
    
    /** init user specified parms and stop on error */
    if( SetupPeripherals() )
    {
        /* Error */
        return 0;
    }
    
    uGF.Word = 0;                   // clear flags
    
    while(1)
    {
        // init Mode
        eStateControl = CNTRL_STOP;
        iLockLoopCnt = 0;
        
        /** clear the variables other than STOP command */
        uGF.bit.TLock = 0;
        uGF.bit.Btn1Pressed = 0;
        uGF.bit.Btn2Pressed = 0;
        uGF.bit.DoSnap = 0;
        uGF.bit.SnapDone = 0;
        
        /** ============= Open Loop ======================*/
        OpenLoopParm.qVelMech = dqOL_VelMech;    
        CtrlParm.qVelRef = OpenLoopParm.qVelMech;
        iRefSpeed = CtrlParm.qVelRef;
        
        InitOpenLoop();
        
        /** Inital offsets for currents */
        InitMeasCompCurr( 450, 730 );  
        
        // init board
        SetupBoard();
        
        // Enable ADC interrupt and begin main loop timing
        IFS0bits.AD1IF = 0; 
        IEC0bits.AD1IE = 1;
        
        /** Initialize private variables used by CalcVelIrp. */
        InitCalcVel();
        
        /** Initialize private variables used by CurrModel */
        InitCurModel();
        
        // zero out i sums 
        PIParmD.qdSum = 0;
        PIParmQ.qdSum = 0;
        PIParmQref.qdSum = 0;
        
        // zero out i out 
        PIParmD.qOut = 0;
        PIParmQ.qOut = 0;
        PIParmQref.qOut = 0;
        
        /** if state is stop */
        if(eStateControl == CNTRL_STOP)
        {
            //wait here until button 1 is pressed or stop time elapsed
            while(uGF.bit.TStop){};
            while(!pinButton1)                   
            {
                /** make sure that the STOP do not occur due to this loop */
                iStopLoopCnt = 0;
                
                // Start offset accumulation    
                //and accumulate current offset while waiting
                MeasCompCurr();
                
            }
            while(pinButton1);                  //when button 1 is released 
            eStateControl = CNTRL_OPEN_LOOP;    //then start motor in open loop
        }
        
        // Run the motor
        uGF.bit.ChangeMode = 1;
        // Enable the driver IC on the motor control PCB
        pinPWMOutputEnable_ = 0;
        
        //Run Motor loop
        while(1)
        {
            
            /** algorithm was stopped before*/
            if(uGF.bit.TStop)
            {
                /* break the while */
                break;
            }
            
            /* for logic of this application 2 buttons are used
               S3 and S6. If both buttons are pressed the state of
               the application is commuted between OPEN_LOOP,
               CLOSED_LOOP and CLOSED_LOOP_DOUBLE_SPEED. The touch
               of only one button will increase the speed in one
               of the states enumerated above */
            /* read the buttons state */
            
            /* while no buttons are pushed */
            do{
                regPinButton1 = pinButton1;     /* pin button 1 */
                /* retain if pressed */
                if(regPinButton1 == 1)
                {
                    uGF.bit.Btn1Pressed=1;
                }
                regPinButton2 = pinButton2;     /* pin button 2 */
                /* retain if pressed */
                if(regPinButton2 == 1)
                {
                    uGF.bit.Btn2Pressed=1;
                }
                
                /** make sure that the STOP do not occur due to this loop */
                iStopLoopCnt = 0;
            
            }while((!regPinButton1)&&(!regPinButton2));
            
            /* while buttons are released */
            do{
                regPinButton1 = pinButton1;     /* pin button 1 */
                /* retain if pressed */
                if(regPinButton1 == 1)
                {
                    uGF.bit.Btn1Pressed=1;
                }
                regPinButton2 = pinButton2;     /* pin button 2 */
                /* retain if pressed */
                if(regPinButton2 == 1)
                {
                    uGF.bit.Btn2Pressed=1;
                }
            }while(pinButton1||pinButton2);
            
            /** the counter for STOP is cleared - if buttons released */
            iStopLoopCnt = 0;
            
            /* check if one of the buttons is pressed */
            
            /* check if both buttons are pressed */
            if ((uGF.bit.Btn1Pressed)&&(uGF.bit.Btn2Pressed))
            {
                /* if yes */
                /* clear both flags indicating the buttons were pressed */
                uGF.bit.Btn1Pressed = 0;
                uGF.bit.Btn2Pressed = 0;
                /* and command not locked */
                /* check if command not locked */
                if(!uGF.bit.TLock)
                {
                    /* lock command for Tlock_multiple */
                    uGF.bit.TLock = 1;      /* command locked */
                    iLockLoopCnt = 0;       /* reset counter */
                    /* state machine for control algorithm */
                    switch(eStateControl)
                    {
                        /* the previous state was STOP */
                        case CNTRL_OPEN_LOOP:
                        {
                            /* swich the state machine */
                            eStateControl = CNTRL_CLOSED_LOOP;
                            /* first switch the global flag */
                            uGF.bit.ChangeMode = 1;
                            break;
                        }
                        case CNTRL_CLOSED_LOOP:
                        {
                            /* double the speed of the motor */
                            /* and swich the state machine */
                            eStateControl = CNTRL_CLOSED_LOOP_DBL_SPEED;
                            /* double the speed */
                            iRefSpeed += iRefSpeed;
                            
                            #ifdef SNAPSHOT
                                uGF.bit.DoSnap = 1;
                                SnapCount = 0;
                            #endif
                            break;
                        }
                        case CNTRL_CLOSED_LOOP_DBL_SPEED:
                        {
                            /* divide by 2 the speed of the motor */
                            /* and swich the state machine */
                            eStateControl = CNTRL_CLOSED_LOOP;
                            /* divide the speed by 2 */
                            iRefSpeed -= iRefSpeed/2;
                            #ifdef SNAPSHOT
                                uGF.bit.DoSnap = 1;
                                SnapCount = 0;
                            #endif
                            break;
                        }
                        default:
                        {
                            /* undefined state, stop */
                            eStateControl = CNTRL_STOP;
                            /* disable the PWM module */
                            pinPWMOutputEnable_ = 1;
                            break;
                        }
                    }
                }
            }
            /* check which button was pressed */
            /* perhaps button 1 was the one */
            else if(uGF.bit.Btn1Pressed)
            {
                /* if yes */
                /* clear the button flag for future usage */
                uGF.bit.Btn1Pressed = 0;
                /* and command not locked */
                /* check if command not locked */
                if(!uGF.bit.TLock)
                {
                    /* lock command for Tlock_multiple */
                    uGF.bit.TLock = 1;        /* command locked */
                    iLockLoopCnt = 0;         /* reset counter */
                    /* increase speed with SPEED_STEP */
                    iRefSpeed += SPEED_STEP;
                }
            }
            /* it was button 2, but checking */
            else if(uGF.bit.Btn2Pressed)
            {
                /* if yes */
                /* clear the button flag for future usage */
                uGF.bit.Btn2Pressed = 0;
                /* and command not locked */
                /* check if command not locked */
                if(!uGF.bit.TLock)
                {
                    /* lock command for Tlock_multiple */
                    uGF.bit.TLock = 1;        /* command locked */
                    iLockLoopCnt = 0;         /* reset counter */
                    /* decrease speed with SPEED_STEP */
                    iRefSpeed -= SPEED_STEP;
                }
            }
            
            /** limit the reference to 60Hz */
            if( iRefSpeed > MAX_SPEED_UP )
            {
                iRefSpeed = MAX_SPEED_UP;
            }
            /** limit the reference to 60Hz */
            if((signed short)iRefSpeed < (signed short)MAX_SPEED_DOWN )
            {
                iRefSpeed = MAX_SPEED_DOWN;
            }
            
            /** update the global speed reference */
            CtrlParm.qVelRef = iRefSpeed;
            
            if( uGF.bit.SnapDone )
            { 
                uGF.bit.SnapDone=0;
            }
        }   // End of Run Motor loop
    } // End of Main loop
    
    // should never get here
    while(1){}
}
Esempio n. 9
0
void main(void) {
    uint16_t v;
    uint8_t i;
    int16_t pad;
    uint32_t padsNow=0;
    uint32_t padsLast=0;
    int8_t  lastKey;
    uint8_t cnt=0;
    uint16_t lastEncValue;
    uint8_t encStep;
    int16_t senseDelta;
    uint8_t easteregg;

    SetupBoard();
    SetupCTMU();

    encStep=1;
    encValue=0;
    lastEncValue=0;
    octave=3;
    encMin=0;
    encMax=14;
    senseDelta=99;
    OpenTimer4(TIMER_INT_ON & T4_PS_1_1 & T4_POST_1_1); // Timer4 - Rotary Encoder polling
    WriteTimer4(0xFF);

    TMR4IF=0;
    OpenTimer2(TIMER_INT_ON & T2_PS_1_4 & T2_POST_1_8); // Timer2 = Display Refresh
    WriteTimer2(0xFF);
    TMR2IF=0;

    GIE=1;
    PEIE=1;
    ei();

    disp[0]=0x00;
    disp[1]=0x00;
    disp[2]=0x00;

    keys=0;
    easteregg=0;

    leds=0x7fff;
    __delay_ms(25);
    leds=0x0000;
    CalibratePads();
    leds=0x7fff;
    __delay_ms(25);
    leds=0x0000;


//
//    encMin=1;
//    encMax=24;
//    encValue=1;
//    for (;;) {
//        pad=ReadPad(encValue);
//        DispValue(pad);
//        leds=0;
//        if ((encValue>=1) && (encValue<=9))   {setbit(leds,encValue-1);   setbit(leds,10);}
//        if ((encValue>=10) && (encValue<=19)) {setbit(leds,encValue-10);setbit(leds,11);}
//        if ((encValue>=20) && (encValue<=29)) {setbit(leds,encValue-20);setbit(leds,12);}
//        __delay_ms(25);
//    }



    for (;;) {
        // Check for tones H+A+D
        if (padsLast==0b000000000000101000000100) EasterEgg(1);
        if (padsLast==0b101000000100000000000000) EasterEgg(2);

        padsNow=0;
        for (i=0; i<PADS; i++) {
            pad=ReadPad(i);
            if (GetPadBaseValue(i)-pad>senseDelta) {
                setbit(padsNow,i);
            }
        }
        for (i=0; i<PADS; i++) {
            if (testbit(padsNow,i) != testbit(padsLast,i)) {
                if (testbit(padsNow,i)) {
                    SendNoteOn(octave*12+i);
                } else {
                    SendNoteOff(octave*12+i);
                }
            }
        }
        padsLast=padsNow;

        for (i=0; i<KEYS; i++) {
            if (testbit(keys,i)) {
                disp[0]=charmap[butSettings[i].txt[0]-32];
                disp[1]=charmap[butSettings[i].txt[1]-32];
                disp[2]=charmap[butSettings[i].txt[2]-32];
                lastKey=i;
                encMin=butSettings[i].min;
                encMax=butSettings[i].max;
                encValue=butSettings[i].value;
                encStep=butSettings[i].stepSize;
                lastEncValue=encValue;
                break;
            }
        }

        if ((encValue!=lastEncValue) && (lastKey!=-1)) {
            lastEncValue=encValue;
            if (butSettings[lastKey].cc==127) {  // OCTAVE
                DispValue(encValue*encStep);
                octave=encValue;
                butSettings[lastKey].value=encValue;
                DispValue(encValue*encStep);
            } else if (butSettings[lastKey].cc==126) {  // SENSE DELTA
                senseDelta=encValue;
                butSettings[lastKey].value=senseDelta;
                DispValue(senseDelta);
                if (senseDelta&1) setbit(leds,0); else clrbit(leds,0);
            } else {
                SendCC(butSettings[lastKey].cc, encValue*encStep);
                DispValue(encValue*encStep);
            }
        }


        __delay_ms(10);

    }
}
Esempio n. 10
0
void main(void) {
    static BYTE ledtrig;
    BYTE OutByte;

    SetupBoard(); //setup the hardware, USB
    SetupRC5();
    usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // TODO: Remove magic with macro
    initCDC(); // JTR this function has been highly modified It no longer sets up CDC endpoints.
    usb_start();
    //usbbufflush(); //flush USB input buffer system

    ledtrig = 1; //only shut LED off once
    //	Never ending loop services each task in small increments
    while (1) {
        do {
           // if (!TestGlobalUsbInterruptEnabled()) //JTR3 added
                usb_handler(); ////service USB tasks Guaranteed one pass in polling mode even when usb_device_state == CONFIGURED_STATE
            if ((usb_device_state < DEFAULT_STATE)) { // JTR2 no suspendControl available yet || (USBSuspendControl==1) ){
                LedOff();
            } else if (usb_device_state < CONFIGURED_STATE) {
                LedOff();
            } else if ((ledtrig == 1) && (usb_device_state == CONFIGURED_STATE)) {
               // LedOn();
                ledtrig = 0;
            }
        } while(usb_device_state < CONFIGURED_STATE);

        //TRISB &= 0x7f;
        //TRISB |= 0x40;
        //LATB |= 0x40;

        //mode = IRWIDGET;
        //irWidgetservice();

#ifdef UARTONLY
        //mode = USB_UART;
        Usb2UartService(); // Never returns
#endif

        // Test for commands: 0, 1, 2 (Entry to SUMP MODE.)
        // Do not remove from input buffer, just take a PEEK.
        // SUMPLogicCommand will remove from input buffer
        // (Standardized coding)

        if (peek_getc_cdc(&OutByte)) {
            switch (OutByte) {
                case 0: //SUMP clear
                case 1: //SUMP run
                case 2: //SUMP ID
                    mode = IR_SUMP; //put IR Toy in IR_SUMP mode
                    irSUMPservice(); // Fully self contained, does not return until exited via 0x00 command.
                    cdc_In_len = 0;
                    mode = IR_DECODER;
                    SetupRC5();
                    break;

                case 'r': //IRMAN decoder mode
                case 'R':
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    SetupRC5();
                    mode = IR_DECODER;
                    putc_cdc('O');
                    putc_cdc('K');
                    CDC_Flush_In_Now();
                    break;
                case 'S': //IRs Sampling Mode
                case 's':
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    mode = IR_S;
                    irsService(); // Fully self contained, does not return until exited via 0x00 command.
                    cdc_In_len = 0;
                    mode = IR_DECODER;
                    SetupRC5();
                    break;
                case 'U':
                case 'u':
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    mode = USB_UART;
                    Usb2UartService();
                    break;
                case 'P':
                case 'p':// IR Widget mode
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    mode = IRWIDGET;
                    GetPulseFreq(); // Never returns
                    //GetPulseTime();
                    break;

                case 'T':
                case 't'://self test
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    SelfTest(); //run the self-test
                    break;
                case 'V':
                case 'v':// Acquire Version
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    GetUsbIrToyVersion();
                    break;
                case '$'://bootloader jump
                    OutByte = getc_cdc(); // now ok to remove byte from the USB buffer
                    BootloaderJump();
                    break;

                default:
                    OutByte = getc_cdc();

            }//switch(OutByte
        } // if peek OutByte == 1
        ProcessIR(); //increment IR decoder state machine
    }//end while(1)
}//end main
Esempio n. 11
0
		Cartridge::Cartridge(Context& context)
		: Image(CARTRIDGE), board(NULL), vs(NULL), favoredSystem(context.favoredSystem)
		{
			try
			{
				ProfileEx profileEx;

				switch (Stream::In(&context.stream).Peek32())
				{
					case INES_ID:

						Ines::Load
						(
							context.stream,
							context.patch,
							context.patchBypassChecksum,
							context.patchResult,
							prg,
							chr,
							context.favoredSystem,
							profile,
							profileEx,
							context.database
						);
						break;

					case UNIF_ID:

						Unif::Load
						(
							context.stream,
							context.patch,
							context.patchBypassChecksum,
							context.patchResult,
							prg,
							chr,
							context.favoredSystem,
							profile,
							profileEx,
							context.database
						);
						break;

					default:

						Romset::Load
						(
							context.stream,
							context.patch,
							context.patchBypassChecksum,
							context.patchResult,
							prg,
							chr,
							context.favoredSystem,
							context.askProfile,
							profile
						);
						break;
				}

				if (profile.dump.state == Profile::Dump::BAD)
					context.result = RESULT_WARN_BAD_DUMP;
				else
					context.result = RESULT_OK;

				const Result result = SetupBoard( prg, chr, &board, &context, profile, profileEx, &prgCrc );

				if (NES_FAILED(result))
					throw result;

				board->Load( savefile );

				switch (profile.system.type)
				{
					case Profile::System::VS_UNISYSTEM:

						vs = VsSystem::Create
						(
							context.cpu,
							context.ppu,
							static_cast<PpuModel>(profile.system.ppu),
							prgCrc
						);

						profile.system.ppu = static_cast<Profile::System::Ppu>(vs->GetPpuModel());
						break;

					case Profile::System::VS_DUALSYSTEM:
						throw RESULT_ERR_UNSUPPORTED_VSSYSTEM;
				}

				if (Cartridge::QueryExternalDevice( EXT_DIP_SWITCHES ))
					Log::Flush( "Cartridge: DIP Switches present" NST_LINEBREAK );
			}
			catch (...)
			{
				Destroy();
				throw;
			}
		}