void
HARD_Breakpoint_Handler(
    UINT32 *registers,
    UINT32 sp,
    UINT32 lr
    )
{    
#if !defined(ABORTS_REDUCESIZE)

    if(1 == ++ABORT_recursion_counter)
    {
        GLOBAL_LOCK(irq);

        //Verify_RAMConstants((void *) FALSE);

        ABORT_HandlerDisplay(registers, sp, lr, 4, "", TRUE);

        CPU_Halt();
    }

#else

    CPU_Reset();

#endif  // !defined(ABORTS_REDUCESIZE)
}
void ApplicationEntryPoint()
{
    CLR_SETTINGS clrSettings;

    InitCRuntime();

    CPU_Initialize();

    Time_Initialize();

    HAL_Initialize();
    
    // CLR entry point 
    memset(&clrSettings, 0, sizeof(CLR_SETTINGS));

    clrSettings.MaxContextSwitches         = 50;
    clrSettings.WaitForDebugger            = false;
    clrSettings.EnterDebuggerLoopAfterExit = true;

    ClrStartup( clrSettings );

    HAL_Uninitialize();

    Time_Uninitialize();

#if !defined(BUILD_RTM)
    debug_printf( "Exiting.\r\n" );
    CPU_Halt();
#else
    CPU_Reset();
#endif

}
Esempio n. 3
0
void Atari800_Warmstart(void)
{
#ifdef MACOSX
	MacCapsLockStateReset();
#endif	
	if (Atari800_machine_type == Atari800_MACHINE_OSA || Atari800_machine_type == Atari800_MACHINE_OSB) {
		/* A real Axlon homebanks on reset */
		/* XXX: what does Mosaic do? */
		if (MEMORY_axlon_enabled) MEMORY_PutByte(0xcfff, 0);
		/* RESET key in 400/800 does not reset chips,
		   but only generates RNMI interrupt */
		ANTIC_NMIST = 0x3f;
		CPU_NMI();
	}
	else {
		PBI_Reset();
		PIA_Reset();
		ANTIC_Reset();
		/* CPU_Reset() must be after PIA_Reset(),
		   because Reset routine vector must be read from OS ROM */
		CPU_Reset();
		/* note: POKEY and GTIA have no Reset pin */
	}
	Devices_WarmCold_Start();
#ifdef __PLUS
	HandleResetEvent();
#endif
}
Esempio n. 4
0
bool StartROM(char* path)
{
	char temppath[300];
	Result res;
	
	// load the ROM
	strncpy(temppath, "/snes/", 6);
	strncpy(&temppath[6], path, 0x106);
	temppath[6+0x106] = '\0';
	bprintf("Loading %s...\n", temppath);
	
	if (!SNES_LoadROM(temppath))
		return false;

	running = 1;
	framecount = 0;
	
	CPU_Reset();
	
	SPC_Reset();

	// SPC700 thread (running on syscore)
	res = svcCreateThread(&spcthread, SPCThread, 0, (u32*)(spcthreadstack+0x400), 0x3F, 1);
	if (res)
	{
		bprintf("Failed to create SPC700 thread:\n -> %08X\n", res);
		spcthread = NULL;
	}
	
	bprintf("ROM loaded, running...\n");
	
	return true;
}
static void UpdateSslSeedValue(void* arg)
{
    if(!HAL_CONFIG_BLOCK::UpdateBlockWithName( g_SSL_SeedData.Config.GetDriverName(), &g_SSL_SeedData.Config, sizeof(g_SSL_SeedData.Config), TRUE ))
    {
        ASSERT(FALSE);
        CPU_Reset();
    }
}
Esempio n. 6
0
 void HARD_Breakpoint_Handler(UINT32 *registers)
 {    
 #if !defined(BUILD_RTM)
     GLOBAL_LOCK(irq);
     FAULT_HandlerDisplay(registers, 0);
     CPU_Halt();
 #else
     CPU_Reset();
 #endif  // !defined(BUILD_RTM)
 }
Esempio n. 7
0
 void FAULT_Handler( UINT32* registers, UINT32 exception )
 {    
     ASSERT_IRQ_MUST_BE_OFF();
 #if !defined(BUILD_RTM)
     FAULT_HandlerDisplay(registers, exception);
     CPU_Halt();
 #else
     CPU_Reset();
 #endif  // !defined(BUILD_RTM)
 }
void StackOverflow( UINT32 sp )
{
    ASSERT_IRQ_MUST_BE_OFF();

#if !defined(ABORTS_REDUCESIZE) && !defined(PLATFORM_ARM_OS_PORT)
    lcd_printf("\fSTACK OVERFLOW\r\nsp=0x%08x\r\nStackBottom:\r\n0x%08x", sp, (UINT32)&StackBottom);

    CPU_Halt();
#else
    CPU_Reset();
#endif  // !defined(ABORTS_REDUCESIZE)
}
void ABORTD_Handler( UINT32* registers, UINT32 sp, UINT32 lr )
{
    ASSERT_IRQ_MUST_BE_OFF();

#if !defined(ABORTS_REDUCESIZE)
    Verify_RAMConstants((void *) FALSE);

    ABORT_HandlerDisplay(registers, sp, lr, 8, "ABORT Data", TRUE);

    CPU_Halt();
#else
    CPU_Reset();
#endif  // !defined(ABORTS_REDUCESIZE)
}
Esempio n. 10
0
BYTE StartChangeFirmware( void ){
  BYTE bStatus;

  if ( e2prom_read( (BYTE*)&bStatus, BOOT_LDR_ST_ADDR, sizeof( BYTE )) == FALSE ){
    return FALSE;
  }

  bStatus |= BOOT_LOADER_CHANGE_FW;

  if ( e2prom_write( (BYTE*)&bStatus, BOOT_LDR_ST_ADDR, sizeof( BYTE )) == FALSE ){
    return FALSE;
  }

  CPU_Reset();
 
  return TRUE;
}
Esempio n. 11
0
void Atari800_Coldstart(void)
{
#ifdef MACOSX
	ANTIC_screenline_cpu_clock = 0;
	MacSoundReset();
	MacCapsLockStateReset();
#endif	
	PBI_Reset();
	PIA_Reset();
	ANTIC_Reset();
	/* CPU_Reset() must be after PIA_Reset(),
	   because Reset routine vector must be read from OS ROM */
	CPU_Reset();
	/* note: POKEY and GTIA have no Reset pin */
#ifdef __PLUS
	HandleResetEvent();
#endif
	/* reset cartridge to power-up state */
	CARTRIDGE_Start();
	/* set Atari OS Coldstart flag */
	MEMORY_dPutByte(0x244, 1);
	/* handle Option key (disable BASIC in XL/XE)
	   and Start key (boot from cassette) */
	GTIA_consol_index = 2;
	GTIA_consol_table[2] = 0x0f;
	if (Atari800_disable_basic && !BINLOAD_loading_basic) {
		/* hold Option during reboot */
		GTIA_consol_table[2] &= ~INPUT_CONSOL_OPTION;
	}
	if (CASSETTE_hold_start) {
		/* hold Start during reboot */
		GTIA_consol_table[2] &= ~INPUT_CONSOL_START;
	}
	GTIA_consol_table[1] = GTIA_consol_table[2];
	Devices_WarmCold_Start();
}
Esempio n. 12
0
int main(void)
{
#if PLATFORM_ARM_OS_PORT
    ClrThreadId = osThreadGetId();
#endif
    BootstrapCode_GPIO();
    HAL_Time_Initialize();

    HAL_Initialize();

#if !defined(BUILD_RTM) 
    DEBUG_TRACE4( STREAM_LCD, ".NetMF v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
    DEBUG_TRACE3(TRACE_ALWAYS, "%s, Build Date:\r\n\t%s %s\r\n", HalName, __DATE__, __TIME__);
#if defined(__GNUC__)
    DEBUG_TRACE1(TRACE_ALWAYS, "GNU Compiler version %d\r\n", __GNUC__);
#else
    DEBUG_TRACE1(TRACE_ALWAYS, "ARM Compiler version %d\r\n", __ARMCC_VERSION);
#endif

    UINT8* BaseAddress;
    UINT32 SizeInBytes;

    HeapLocation( BaseAddress,    SizeInBytes );
    memset      ( BaseAddress, 0, SizeInBytes );

    debug_printf("\f");

    debug_printf("%-15s\r\n", HalName);
    debug_printf("%-15s\r\n", "Build Date:");
    debug_printf("  %-13s\r\n", __DATE__);
    debug_printf("  %-13s\r\n", __TIME__);

#endif  // !defined(BUILD_RTM)

    /***********************************************************************************/

    {
#if defined(FIQ_SAMPLING_PROFILER)
        FIQ_Profiler_Init();
#endif
    }

    // the runtime is by default using a watchdog 
   
    Watchdog_GetSetTimeout ( WATCHDOG_TIMEOUT , TRUE );
    Watchdog_GetSetBehavior( WATCHDOG_BEHAVIOR, TRUE );
    Watchdog_GetSetEnabled ( WATCHDOG_ENABLE, TRUE );

 
    // HAL initialization completed.  Interrupts are enabled.  Jump to the Application routine
    ApplicationEntryPoint();

    debug_printf("main exited!!???.  Halting CPU\r\n");

#if defined(BUILD_RTM)
    CPU_Reset();
#else
    CPU_Halt();
#endif
    return -1;
}
Esempio n. 13
0
int main(int argc,char **argv)
{
    unsigned char *romPtr;
	int running=1;
	int a;
	
	for (a=0;a<256;a++)
	{
		keyUpArray[a]=1;
	}
       
	// Initialize GLFW 
	glfwInit(); 
	// Open an OpenGL window 
	if( !glfwOpenWindow( AMI_LINE_LENGTH, HEIGHT, 0,0,0,0,0,0, GLFW_WINDOW ) ) 
	{ 
		glfwTerminate(); 
		return 1; 
	} 
	
	glfwSetWindowTitle("MinAmi");
	glfwSetWindowPos(670,700);
	
	setupGL(AMI_LINE_LENGTH,HEIGHT);	
	
    romPtr=load_rom("../../out.rom");
    if (!romPtr)
    {
		romPtr=load_rom("out.rom");
		if (!romPtr)
		{
			printf("[ERR] Failed to load rom image\n");
			glfwTerminate(); 
			return 1; 
		}
    }
	
    CPU_BuildTable();
	
    MEM_Initialise(romPtr);
	
	CST_InitialiseCustom();
	CPR_InitialiseCopper();
	CIA_InitialiseCustom();
	BLT_InitialiseBlitter();
	DSP_InitialiseDisplay();
	DSK_InitialiseDisk();
	SPR_InitialiseSprites();
	KBD_InitialiseKeyboard();
	
    CPU_Reset();

    glfwSetKeyCallback(kbHandler);
    
	while (running)
	{
		KBD_Update();
		SPR_Update();
		DSP_Update();			// Note need to priority order these ultimately
		CST_Update();
		DSK_Update();
		CPR_Update();
		CIA_Update();
		BLT_Update();
		CPU_Step();
		
		if (g_newScreenNotify)
		{
			static int lmx=0,lmy=0;
			int mx,my;
		
			DrawScreen();
			
			glfwSwapBuffers();
			
			g_newScreenNotify=0;

			glfwGetMousePos(&mx,&my);
			
			if ((mx>=1 && mx<=AMI_LINE_LENGTH && my>=1 && my <=HEIGHT) || captureMouse)
			{
				int vertMove = my-lmy;
				int horiMove = mx-lmx;
				int oldMoveX = CST_GETWRDU(CST_JOY0DAT,0x00FF);
				int oldMoveY = CST_GETWRDU(CST_JOY0DAT,0xFF00)>>8;
				if (horiMove>127)
					horiMove=127;
				if (horiMove<-128)
					horiMove=-128;
				if (vertMove>127)
					vertMove=127;
				if (vertMove<-128)
					vertMove=-128;
				oldMoveX+=horiMove;
				oldMoveY+=vertMove;
				
				CST_SETWRD(CST_JOY0DAT,((oldMoveY&0xFF)<<8)|(oldMoveX&0xFF),0xFFFF);
				lmx=mx;
				lmy=my;
				
				if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT))
				{
					leftMouseUp=0;
				}
				else
				{
					leftMouseUp=1;
				}
				if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_MIDDLE))
				{
					if (captureMouse)
					{
						captureMouse=0;
						glfwEnable(GLFW_MOUSE_CURSOR);
					}
					else
					{
						captureMouse=1;
						glfwDisable(GLFW_MOUSE_CURSOR);
					}
				}
				if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT))
				{
					rightMouseUp=0;
				}
				else
				{
					rightMouseUp=1;
				}
			}
		}
		
		// Check if ESC key was pressed or window was closed 
		running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED ); 
	}
void ABORT_HandlerDisplay(
    UINT32 *registers_const,
    UINT32 sp,
    UINT32 lr,
    UINT32 pc_offset,
    const char *Title,
    BOOL SerialOutput
    )
{
    UINT32              cpsr;
    UINT32              pc;
    int                 i;
    int                 j;
#if !defined(PLATFORM_ARM_OS_PORT)
    UINT8*              stackbytes;
    const UINT32* const stackwords = (UINT32 *)sp;
#endif
    int                 page;
    UINT32*             registers;

#if defined(PLATFORM_ARM_MC9328)
    UINT32              URXDn_X;
    MC9328MXL_USART&    USART = MC9328MXL::USART( ConvertCOM_ComPort(USART_DEFAULT_PORT) );
#else
    // TODO ???
#endif
            
    ++ABORT_recursion_counter;

dump_again:

    page = 0;
    registers = registers_const;

    cpsr =  *registers++;
    pc   = (*registers++) - pc_offset;

    if(SerialOutput)
    {
        // unprotect the GPIO pins for USART, allowing USART output

        USART_Initialize( ConvertCOM_ComPort(USART_DEFAULT_PORT), USART_DEFAULT_BAUDRATE, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE );

        monitor_debug_printf("ERROR: %s\r\n", Title);
        monitor_debug_printf("  cpsr=0x%08x\r\n", cpsr);
        monitor_debug_printf("  pc  =0x%08x\r\n", pc);
        monitor_debug_printf("  lr  =0x%08x\r\n", lr);

        for(i = 0; i <= 12; i++)
        {
            monitor_debug_printf("  r%d=0x%08x\r\n", i, registers[i]);
        }

        monitor_debug_printf("  sp  =0x%08x\r\n", sp);

        RegisterDump();
    }

    // don't let the screen go away if the watchdog was enabled.
    Watchdog_Disable();

    //Flash_ChipReadOnly(TRUE);

    // first dump stuff to the com port, then go interactive with the buttons and LCD

    if(SerialOutput)
    {
        monitor_debug_printf("ERROR: %s\r\n", Title);
        monitor_debug_printf("  cpsr=0x%08x\r\n", cpsr);
        monitor_debug_printf("  pc  =0x%08x\r\n", pc);
        monitor_debug_printf("  lr  =0x%08x\r\n", lr);
        for(i = 0; i <= 12; i++)
        {
            monitor_debug_printf("  r%d=0x%08x\r\n", i, registers[i]);
        }
        monitor_debug_printf("  sp  =0x%08x\r\n", sp);

#if !defined(PLATFORM_ARM_OS_PORT)
        stackbytes = (UINT8 *)sp;
        for(i = 0; i < 16; i++)
        {
            monitor_debug_printf("[0x%08x] :", (UINT32)&stackbytes[i*16]);
            for(j = 0; j < 16; j++)
            {
                // don't cause a data abort here!
                if((UINT32) &stackbytes[i*16 + j] < (UINT32) &StackTop)
                {
                    monitor_debug_printf(" %02x", stackbytes[i*16 + j]);
                }
                else
                {
                    monitor_debug_printf("   ");
                }
            }
            monitor_debug_printf(" ");
            for(j = 0; j < 16; j++)
            {
                if((UINT32) &stackbytes[i*16 + j] < (UINT32) &StackTop)
                {
                    monitor_debug_printf("%c", (stackbytes[i*16 + j] >= ' ') ? stackbytes[i*16 + j] : '.');
                }
            }
            monitor_debug_printf("\r\n");
        }
#endif
    }

    //--//

    // make sure USART is ready to go (clock enabled, pins set active) regardless of charger state, idem potent call if it was already on
    CPU_ProtectCommunicationGPIOs( FALSE );

#if defined(PLATFORM_ARM_MC9328)
    while(USART.URXDn_X[0] & MC9328MXL_USART::URXDn__CHARRDY);
#else
    // TODO ???
#endif

    //--//

    // go interactive with the buttons and LCD
    while(true)
    {
        UINT32 CurrentButtonsState;

        lcd_printf("\f");

        switch(page)
        {
        case 0:
            lcd_printf("%-12s \r\n\r\n", Title);
            lcd_printf("Build Date:\r\n");
            lcd_printf("%-12s \r\n"    , __DATE__);
            lcd_printf("%-12s \r\n"    , __TIME__);
            lcd_printf("\r\n");
            lcd_printf("cps=0x%08x\r\n", cpsr);
            lcd_printf("pc =0x%08x\r\n", pc);
            lcd_printf("lr =0x%08x\r\n", lr);
            lcd_printf("sp =0x%08x\r\n", sp);
            break;

        case 1:
            lcd_printf("Registers 1\r\n\r\n");
            for(i = 0; i < 10; i++)
            {
                lcd_printf("r%1d =0x%08x\r\n", i, registers[i]);
            }
            break;

        case 2:
            lcd_printf("Registers 2\r\n\r\n");
            for(i = 10; i < 13; i++)
            {
                lcd_printf("r%2d=0x%08x\r\n", i, registers[i]);
            }
            break;

        case 3:
        default:
            {
#if !defined(PLATFORM_ARM_OS_PORT)
                UINT32 index =  (page-3)*10;

                lcd_printf("Stack %08x\r\n\r\n", (UINT32)&stackwords[index]);

                for(i = 0; i < 10; i++)
                {
                    stackbytes = (UINT8 *)&stackwords[index+i];

                    // don't cause a data abort displaying past the end of the stack!
                    if((UINT32) &stackwords[index+i] < (UINT32) &StackTop)
                    {
                        lcd_printf("%08x %c%c%c%c\r\n", stackwords[index+i],
                            (stackbytes[0] >= ' ') ? stackbytes[0] : '.',
                            (stackbytes[1] >= ' ') ? stackbytes[1] : '.',
                            (stackbytes[2] >= ' ') ? stackbytes[2] : '.',
                            (stackbytes[3] >= ' ') ? stackbytes[3] : '.'
                            );
                    }
                    else
                    {
                        lcd_printf("             \r\n");
                    }
                }
#endif
            }
            break;
        }


        // wait for a button press
        while(0 == (CurrentButtonsState = Buttons_CurrentHWState()))
        {
#if defined(PLATFORM_ARM_MC9328)
            if(USART.URXDn_X[0] & MC9328MXL_USART::URXDn__CHARRDY)
            {
                goto StartMonitorMode;
            }
#else
    // TODO ???
#endif
        }

        // wait for 10 mSec
        HAL_Time_Sleep_MicroSeconds(10000/64);
        
        // wait for it to release
        while(0 == (CurrentButtonsState ^ Buttons_CurrentHWState()));
        
        // wait for 10 mSec        
        HAL_Time_Sleep_MicroSeconds(10000/64);
        
        if(CurrentButtonsState & BUTTON_B5)
        {
            page = (page + 1);  // no limit of stack pages
            LCD_Clear();
        }

        if(CurrentButtonsState & BUTTON_B2)
        {
            page = (page > 0) ? page - 1 : 0;
            LCD_Clear();
        }

        if((CurrentButtonsState & BUTTON_B4) || (CurrentButtonsState & BUTTON_B0))
        {
            goto dump_again;
        }

        continue;


#if defined(PLATFORM_ARM_MC9328)
StartMonitorMode:
#endif 
        {
            char   data[16];
            UINT32 pos = 0;

            LCD_Clear();
            lcd_printf("\fMONITOR MODE\r\n");

            HAL_Time_Sleep_MicroSeconds(10000);

            while(1)
            {
#if defined(PLATFORM_ARM_MC9328)

                URXDn_X = USART.URXDn_X[0];
                
                if(URXDn_X & MC9328MXL_USART::URXDn__CHARRDY)
                {
                    data[pos++] = (char)(URXDn_X & MC9328MXL_USART::URXDn__DATA_mask);
#else
                if(false)
                {
    // TODO ???
#endif

                    switch(data[0])
                    {        
                    case 'L':
                        monitor_debug_printf("rb=0x%08x\r\n", HalSystemConfig.RAM1.Base  );
                        monitor_debug_printf("rs=0x%08x\r\n", HalSystemConfig.RAM1.Size  );
                        monitor_debug_printf("fb=0x%08x\r\n", HalSystemConfig.FLASH.Base);
                        monitor_debug_printf("fs=0x%08x\r\n", HalSystemConfig.FLASH.Size);
                        break;
                        
                    case 'M':
                        if(pos < 12) continue;
                        
                        {
                            UINT8* start = *(UINT8**)&data[4];
                            UINT8* end   = *(UINT8**)&data[8];

                            lcd_printf( "\f\r\n\r\nREAD:\r\n  %08x\r\n  %08x", (UINT32)start, (UINT32)end );

                            if(AbortHandler_CheckMemoryRange( start, end ))
                            {   
                                while(start < end)
                                {
                                    monitor_debug_printf("[0x%08x]", (UINT32)start);
                                    for(j = 0; j < 128; j++)
                                    {
                                        monitor_debug_printf("%02x", *start++);

                                        if(start == end) break;
                                    }
                                    monitor_debug_printf("\r\n");
                                }
                            }
                            else
                            {
                                monitor_debug_printf("ERROR: invalid range: %08x-%08x\r\n", (UINT32)start, (UINT32)end );
                            }
                        }
                        break;

                    case 'R':
                        for(i = 0; i <= 12; i++)
                        {
                            monitor_debug_printf("r%d=%08x\r\n", i, registers[i]);
                        }

                        monitor_debug_printf("sp=%08x\r\n", sp);
                        monitor_debug_printf("lr=%08x\r\n", lr);
                        monitor_debug_printf("pc=%08x\r\n", pc);
                        monitor_debug_printf("cpsr=%08x\r\n", cpsr);
#if defined(PLATFORM_ARM_MC9328)
                        monitor_debug_printf("BWA=%08x\r\n", 0);
                        monitor_debug_printf("BWC=%08x\r\n", 0);
#else
    // TODO ???
#endif
                        break;

                    case '\r':
                    case '\n':
                    case ' ':
                        break;

                    default:
                        monitor_debug_printf("ERROR: unknown command %c\r\n", data[0] );
                        break;
                    }

                    pos = 0;
                }
                else if(Buttons_CurrentHWState())
                {
                    // wait for it to release
                    while (Buttons_CurrentHWState());

                    LCD_Clear();
                    break;
                }
            }
        }
    }
}

#endif  // !defined(ABORTS_REDUCESIZE)

extern "C"
{
    
void UNDEF_Handler( UINT32* registers, UINT32 sp, UINT32 lr )
{    
    ASSERT_IRQ_MUST_BE_OFF();
    
#if !defined(ABORTS_REDUCESIZE)
    Verify_RAMConstants((void *) FALSE);

    ABORT_HandlerDisplay(registers, sp, lr, 4, "Undef Instr", TRUE);

    CPU_Halt();
#else
    CPU_Reset();
#endif  // !defined(ABORTS_REDUCESIZE)
}
Esempio n. 15
0
void DecodeKey( word keyCode, word keyFlags )
{
    static bool resetState = false;

    bool flagKeyRelease = ( keyFlags & fKeyRelease ) != 0;

    bool reset1 = ( keyFlags & ( fKeyCtrlLeft | fKeyCtrlRight ) ) == ( fKeyCtrlLeft | fKeyCtrlRight );

    static bool reset2 = false;
    if( keyCode == KEY_POWER && !flagKeyRelease ) reset2 = true;
    if( keyCode == KEY_POWER && flagKeyRelease ) reset2 = false;

    static bool reset3 = false;
    if( keyCode == KEY_PRNTSCR && !flagKeyRelease ) reset3 = true;
    if( keyCode == KEY_PRNTSCR && flagKeyRelease ) reset3 = false;

    if( ( reset1 || reset2 || reset3 ) != resetState )
    {
        resetState = reset1 || reset2 || reset3;
        CPU_Reset( resetState );
        DelayMs( 100 );
    }

    //------------------------------------------------------

    if( !flagKeyRelease )
    {
        if( ( keyFlags & fKeyCtrl ) != 0 )
        {
            switch( keyCode )
            {
                case KEY_1 :
                    specConfig.specVideoMode = 0;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_2 :
                    specConfig.specVideoMode = 1;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_3 :
                    specConfig.specVideoMode = 2;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_4 :
                    specConfig.specVideoMode = 3;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_5 :
                    specConfig.specVideoMode = 4;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_F12 :
                    CPU_NMI();
                    break;
            }
        }
        else if ( fKeyAlt & keyFlags )
        {
            int kc;

            switch ( keyCode )
            {
                case KEY_0:
                    kc = 0;
                    break;
                case KEY_1:
                    kc = 1;
                    break;
                case KEY_2:
                    kc = 2;
                    break;
                case KEY_3:
                    kc = 3;
                    break;
                case KEY_4:
                    kc = 4;
                    break;
                case KEY_5:
                    kc = 5;
                    break;
                case KEY_6:
                    kc = 6;
                    break;
                case KEY_7:
                    kc = 7;
                    break;
                case KEY_8:
                    kc = 8;
                    break;
                case KEY_9:
                    kc = 9;
                    break;
                default:
                    kc = -1;
                    break;
            }
            if ( kc >= 0 )
            {
                char snaName[ 0x10 ];
                sniprintf( snaName, sizeof(snaName), "!slot_%.1d.sna", kc );
                SaveSnapshot( snaName );
            }
        }

        else
        {
            switch( keyCode )
            {
                case KEY_ESC :
                    Debugger_Enter();
                    break;

                case KEY_PAUSE :
                    Shell_Pause();
                    break;

                case KEY_F1 :
                    specConfig.specTurbo = 0;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F2 :
                    specConfig.specTurbo = 1;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F3 :
                    specConfig.specTurbo = 2;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F4 :
                    specConfig.specTurbo = 3;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;

                case KEY_F5 :
                    SystemBus_Write( 0xc00000, 0x00004 );
                    break;
                case KEY_F6 :
                    {
                        CPU_Stop();

                        byte specPort7ffd = SystemBus_Read( 0xc00017 );

                        byte page = ( specPort7ffd & ( 1 << 3 ) ) != 0 ? 7 : 5;
                        dword addr = 0x800000 | ( page << 13 );

                        SystemBus_Write( 0xc00020, 0 );  // use bank 0

                        for( int i = 0x1800; i < 0x1b00; i += 2 )
                        {
                            SystemBus_Write( addr + ( i >> 1 ), 0x3838 );
                        }

                        CPU_Start();
                    }
                    break;

                case KEY_F9 :
                    Shell_SettingsMenu();
                    break;

                case KEY_F10 :
                    Shell_DisksMenu();
                    break;

                case KEY_F11 :
                    if( ( keyFlags & fKeyShift ) != 0 ) Shell_SaveSnapshot();
                    else SaveSnapshot( UpdateSnaName() );
                    break;

                case KEY_F12 :
                    Shell_Browser();
                    break;

                case KEY_EQUALS :
                case KEY_KP_PLUS :
                    if( !Tape_Started() ) Tape_Restart();
                    break;

                case KEY_MINUS :
                case KEY_KP_MINUS :
                    if( !Tape_Started() ) Tape_Start();
                    else Tape_Stop();
                    break;

                case KEY_INSERT :
                    specConfig.specMouseSwap = !specConfig.specMouseSwap;
                    break;
            }
        }
    }
}
BOOL MicroBooterUpdateProvider::InstallUpdate( MFUpdate* pUpdate, UINT8* pValidation, INT32 validationLen )
{
    if(pUpdate->Providers->Storage == NULL) return FALSE;

    if(!pUpdate->IsValidated()) return FALSE;

    switch(pUpdate->Header.UpdateType)
    {
        case MFUPDATE_UPDATETYPE_FIRMWARE:
            {
                HAL_UPDATE_CONFIG cfg;

                if(sizeof(cfg.UpdateSignature) < validationLen) return FALSE;
                
                cfg.Header.Enable = TRUE;
                cfg.UpdateID = pUpdate->Header.UpdateID;

                if(validationLen == sizeof(UINT32))
                {
                    cfg.UpdateSignType = HAL_UPDATE_CONFIG_SIGN_TYPE__CRC;
                }
                else
                {
                    cfg.UpdateSignType = HAL_UPDATE_CONFIG_SIGN_TYPE__SIGNATURE;
                }
                
                memcpy( cfg.UpdateSignature, pValidation, validationLen );

                if(HAL_CONFIG_BLOCK::UpdateBlockWithName(cfg.GetDriverName(), &cfg, sizeof(cfg), FALSE))
                {
                    CPU_Reset();
                }
            }
            break;
            
        case MFUPDATE_UPDATETYPE_ASSEMBLY:
            {
                BlockStorageStream stream;
                
                if(NULL == BlockStorageList::GetFirstDevice())
                {
                    BlockStorageList::Initialize();
                
                    BlockStorage_AddDevices();
                
                    BlockStorageList::InitializeDevices();
                }

                if(stream.Initialize(BlockUsage::DEPLOYMENT))
                {
                    if(pUpdate->Header.UpdateSubType == MFUPDATE_UPDATESUBTYPE_ASSEMBLY_REPLACE_DEPLOY)
                    {
                        do
                        {
                            stream.Erase(stream.Length);
                        }
                        while(stream.NextStream());

                        stream.Initialize(BlockUsage::DEPLOYMENT);
                    }
                    
                    do
                    {
                        UINT8 buf[512];
                        INT32 offset = 0;
                        INT32 len = sizeof(buf);
                        const BlockDeviceInfo* deviceInfo = stream.Device->GetDeviceInfo();
                        BOOL isXIP = deviceInfo->Attribute.SupportsXIP;
                        
                        const CLR_RECORD_ASSEMBLY* header;
                        INT32  headerInBytes = sizeof(CLR_RECORD_ASSEMBLY);
                        BYTE * headerBuffer  = NULL;
                        
                        if(!isXIP)
                        {
                            headerBuffer = (BYTE*)private_malloc( headerInBytes );  if(!headerBuffer) return FALSE;
                            memset( headerBuffer, 0,  headerInBytes );
                        }
                        
                        while(TRUE)
                        {
                            if(!stream.Read( &headerBuffer, headerInBytes )) break;
                        
                            header = (const CLR_RECORD_ASSEMBLY*)headerBuffer;
                        
                            // check header first before read
                            if(!header->GoodHeader())
                            {
                                stream.Seek(-headerInBytes);
                                
                                if(stream.IsErased(pUpdate->Header.UpdateSize))
                                {
                                    while(offset < pUpdate->Header.UpdateSize)
                                    {
                                        if((pUpdate->Header.UpdateSize - offset) < len)
                                        {
                                            len = pUpdate->Header.UpdateSize - offset;
                                        }
                                        
                                        offset += pUpdate->Providers->Storage->Read(pUpdate->StorageHandle, offset, buf, len);

                                        stream.Write(buf, len);
                                    }

                                    ClrReboot();
                                    return TRUE;
                                }
                                break;
                            }
                        
                            UINT32 AssemblySizeInByte = ROUNDTOMULTIPLE(header->TotalSize(), CLR_UINT32);
                        
                            stream.Seek( AssemblySizeInByte );
                        }
                        if(!isXIP) private_free( headerBuffer );
                    
                    }
                    while(stream.NextStream());
                }

            }
            break;
    }
    
    return FALSE;
}
Esempio n. 17
0
int main(void)
{
	int i;
	
	defaultExceptionHandler();
	
	irqEnable(IRQ_VBLANK);
	irqEnable(IRQ_HBLANK);
	
	irqSet(IRQ_VBLANK, vblank_idle);
	
	fifoSetValue32Handler(FIFO_USER_02, arm7print, NULL);
	fifoSetValue32Handler(FIFO_USER_03, sleepMode, NULL);
	
	//vramSetBankA(VRAM_A_LCD);
	videoSetMode(MODE_0_2D);

	// map some VRAM
	// bank C to ARM7, bank H for subscreen graphics
	*(vu8*)0x04000242 = 0x82;
	*(vu8*)0x04000248 = 0x81;
	
	videoSetModeSub(MODE_0_2D);
	consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 2, 0, false, true);
	
	*(vu16*)0x0400100A = 0x0300;
	
	setBackdropColorSub(0x7C00);
	
	// configure BLDCNT so that backdrop becomes black
	*(vu16*)0x04001050 = 0x00E0;
	*(vu8*)0x04001054 = 16;
	
	// enable window 0 and disable color effects inside it
	*(vu16*)0x04001000 |= 0x2000;
	*(vu16*)0x04001048 = 0x001F;
	*(vu16*)0x0400104A = 0x003F;
	
	toggleConsole(false);
	
#ifdef NITROFS_ROM
	if (!nitroFSInit())
#else
	if (!fatInitDefault())
#endif
	{
		toggleConsole(true);
		iprintf("FAT init failed\n");
		return -1;
	}
	
	makeROMList();
	
	makeMenu();

	iprintf("lolSnes " VERSION " -- by Mega-Mario\n");
	
	for (;;)
	{
		if (keypress != 0x03FF)
		{
			if (!(keypress & 0x0040)) // up
			{
				menusel--;
				if (menusel < 0) menusel = 0;
				if (menusel < menuscroll) menuscroll = menusel;
				makeMenu();
			}
			else if (!(keypress & 0x0080)) // down
			{
				menusel++;
				if (menusel > nfiles-1) menusel = nfiles-1;
				if (menusel-21 > menuscroll) menuscroll = menusel-21;
				makeMenu();
			}
			else if ((keypress & 0x0003) != 0x0003) // A/B
			{
				strncpy(fullpath, "snes/", 5);
				strncpy(fullpath + 5, &filelist[menusel << 8], 256);
				
				if (!Mem_LoadROM(fullpath))
				{
					iprintf("ROM loading failed\n");
					continue;
				}
				
				*(vu16*)0x04001000 &= 0xDFFF;
				toggleConsole(true);
				iprintf("ROM loaded, running\n");

				CPU_Reset();
				fifoSendValue32(FIFO_USER_01, 1);
				
				swiWaitForVBlank();
				fifoSendValue32(FIFO_USER_01, 2);
				
				irqSet(IRQ_VBLANK, vblank);
				irqSet(IRQ_HBLANK, PPU_HBlank);

				swiWaitForVBlank();
				CPU_Run();
			}
			
			keypress = 0x03FF;
		}
		
		swiWaitForVBlank();
	}

	return 0;
}