Пример #1
0
void bsp_start (void)
{
  /* initialize irq management */
  BSP_rtems_irq_mngt_init ();

  /* setup console mode for lower screen */
  irqEnable (IRQ_VBLANK);
  videoSetMode (0);
  videoSetModeSub (MODE_0_2D | DISPLAY_BG0_ACTIVE);
  vramSetBankC (VRAM_C_SUB_BG);

  SUB_BG0_CR = BG_MAP_BASE (31);
  BG_PALETTE_SUB[255] = RGB15 (31, 31, 31);
  consoleInitDefault ((u16 *) SCREEN_BASE_BLOCK_SUB (31),
                      (u16 *) CHAR_BASE_BLOCK_SUB (0), 16);

  /* print status message */
  printk ("[+] kernel console started\n");

  /* set the cpu mode to system user */
  arm_cpu_mode = 0x1f;

  /* configure clock period */
  Configuration.microseconds_per_tick = 10000;  /* us */

  defaultExceptionHandler ();
}
Пример #2
0
int main(int argc, char** argv) {
	PA_Init();
	PA_InitVBL();
	
	defaultExceptionHandler();

	PA_SetScreenSpace(0);

	player = new ship();

	PA_DualLoadSpritePal(ENEMIES, (void*)ikaruga_Pal);
	for(int n = ENEMIES; n < BULLETS; n++) {
		PA_DualCreateSprite(n, (void*)ikaruga_Sprite, OBJ_SIZE_32X32, COLOR256, ENEMIES, -32, -32);
		PA_DualSetSpriteVflip(n, true);
	}
	PA_DualLoadSpritePal(BULLETS, (void*)bullets_Pal);
	for(int n = BULLETS; n < 128; n++) PA_DualCreateSprite(n, (void*)bullets_Sprite, OBJ_SIZE_8X8, COLOR256, BULLETS, -8, -8);

	for(int x = 32; x < 224; x+=32)
		for(int y = 0; y < 32; y+=32)
			enemies.push_back(new enemy(x, y));

	while(true) {
		player->update();
		std::vector<enemy*> temp;
		for(int n = 0; n < (int)enemies.size(); n++) if(enemies[n]->update()) temp.push_back(enemies[n]);
		enemies = temp;
				
		PA_WaitForVBL();
	}
	
	return 0;
}
Пример #3
0
void ExceptionSink::handleExceptions() {
   if (priv->head) {
      defaultExceptionHandler(priv->head);
      clear();
   }
   else
      priv->thread_exit = false;
}
Пример #4
0
int main()
{
	defaultExceptionHandler();
    mgr_system.init_DS();
    mgr_system.init_timer(inc_timer,&millisec);

	timerStart(0,ClockDivider_1024,timerFreqToTicks_1024(24),inc_timer);

    app_test.init( &mgr_display /*, &mgr_input */, &mgr_system);
    app_test.start();
    return 0;
}//end main
Пример #5
0
/*
	DS_SysInit

	Initializes DS specific system hardware and interrupts.
*/
LOCALPROC DS_SysInit(void)
{
	defaultExceptionHandler();
	powerOn(POWER_ALL_2D);
	lcdMainOnTop();

	irqSet(IRQ_VBLANK, DS_VBlank_IRQ);
	irqSet(IRQ_HBLANK, DS_HBlank_IRQ);
	irqSet(IRQ_TIMER1, DS_Timer1_IRQ);

	irqEnable(IRQ_VBLANK);
	irqEnable(IRQ_HBLANK);
	irqEnable(IRQ_TIMER1);

	/*
		This sets up 2 timers as a milisecond counter.
		TIMER0_DATA Will overflow roughly every 1 msec into TIMER1_DATA.
		When TIMER1_DATA overflows an interrupt will be generated
		and DS_Timer1_IRQ will be called.
	*/
	TIMER0_DATA = 32768;

	TIMER0_CR = TIMER_DIV_1 | TIMER_ENABLE;



	TIMER1_DATA = 0;

	TIMER1_CR = TIMER_ENABLE | TIMER_CASCADE | TIMER_IRQ_REQ;

	/*
		Testing.
	*/
	consoleDemoInit();
	consoleDebugInit(DebugDevice_NOCASH);

	/*
		Use the default keyboard until I design a (good) UI...
	*/
	DSKeyboard = keyboardDemoInit();
	keyboardShow();

	/*
		Drop back to a read only filesystem embedded in the
		Mini vMac binary if we cannot open a media device.
	*/
	if (! fatInitDefault()) {
		nitroFSInit();
	}
}
Пример #6
0
int main(int argc, char* argv[])
{
    REG_POWERCNT = POWER_ALL & ~(POWER_MATRIX | POWER_3D_CORE); // don't need 3D
    consoleDebugInit(DebugDevice_CONSOLE);

    defaultExceptionHandler();

    time(&rawTime);
    lastRawTime = rawTime;
    timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(1), clockUpdater);

    /* Reset the EZ3in1 if present */
    if (!__dsimode) {
        sysSetCartOwner(BUS_OWNER_ARM9);

        GBA_BUS[0x0000] = 0xF0;
        GBA_BUS[0x1000] = 0xF0;
    }

    fifoSetValue32Handler(FIFO_USER_02, fifoValue32Handler, NULL);

    sharedData = (SharedData*)memUncached(malloc(sizeof(SharedData)));
    sharedData->scalingOn = false;
    // It might make more sense to use "fifoSendAddress" here.
    // However there may have been something wrong with it in dsi mode.
    fifoSendValue32(FIFO_USER_03, ((u32)sharedData)&0x00ffffff);

    consoleOn = true;
    initConsole();
    initInput();
    readConfigFile();

    if (argc >= 2) {
        char* filename = argv[1];
        loadProgram(filename);
        initializeGameboyFirstTime();
    }
    else {
        selectRom();
    }
    consoleOn = false;
    updateScreens();

    runEmul();

    return 0;
}
Пример #7
0
int main(int argc, char *argv[])
{
    int rc;
    
    defaultExceptionHandler();
    consoleDemoInit();
    irqInit();
    irqEnable(IRQ_VBLANK);
    
    if(fatInitDefault() != 1)
    {
        return -1;
    }

    arm9_wifiConnect();
    
    rc = test_main();
    
    Wifi_DisconnectAP();
    Wifi_DisableWifi();
    
    return rc;
}
Пример #8
0
int main(void)
{
    touchPosition touch;

    defaultExceptionHandler();

    lcdMainOnBottom();
    irqEnable(IRQ_VBLANK);

    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_LCD);

    consoleDemoInit();

    ClearScreen();

    touchPosition firstTouch = { 0, 0 };
    touchPosition lastTouch = { 0, 0 };

    int colours[3] = { 31, 31, 31 };
    int colourIndex = 0;

    printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]);

    std::stack<node*>* path = NULL;
    bool searched = false;

    node start(10,10,NULL);
    node target(244,180,NULL);

    Robot robot;
    robot.setPosition(start.x,start.y);

    int nextTouch = 0;

    //we like infinite loops in console dev!
    while(1)
    {
        swiWaitForVBlank();

        scanKeys();
        touchRead(&touch);

        int kd = keysDown();
        if (kd & KEY_A)
        {
            ClearScreen();
        }

        if (kd & KEY_UP)
        {
            ++colours[colourIndex];
            if (colours[colourIndex] > 31) colours[colourIndex] = 0;
            printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]);
        }

        if (kd & KEY_DOWN)
        {
            --colours[colourIndex];
            if (colours[colourIndex] < 0) colours[colourIndex] = 31;
            printf("RGB15(%d,%d,%d)\n",colours[0],colours[1],colours[2]);
        }

        if (kd & KEY_LEFT)
        {
            --colourIndex;
            if (colourIndex < 0) colourIndex = 2;
        }

        if (kd & KEY_RIGHT)
        {
            ++colourIndex;
            if (colourIndex > 2) colourIndex = 0;
        }

        if (kd & KEY_Y)
        {
            robot.setPosition(start.x,start.y);
            path = NULL;
            node::cleanup();
        }

        if(kd & KEY_B)
        {
            printf("Working...\n");
            searched = true;
            node current(robot.getPosition().px, robot.getPosition().py,NULL);
            path = astar::generate_path( astar::search(&current,&target) );
            printf("Path found!\n");
        }

        if (kd & KEY_R)
        {
            nextTouch = 2;
        }

        if (kd & KEY_L)
        {
            nextTouch = 1;
        }

        if(kd & KEY_TOUCH)
        {
            switch (nextTouch)
            {
            case 0:
                firstTouch = touch;
                draw::plot(touch.px,touch.py,RGB15(colours[0],colours[1],colours[2]));
                break;
            case 1: // Set start
                start.x = touch.px;
                start.y = touch.py;
                robot.setPosition(touch);
                break;
            case 2: // Set target
                target.x = touch.px;
                target.y = touch.py;
                break;
            default:
                break;
            }
        }

        if(keysHeld() & KEY_TOUCH)
        {
            if (nextTouch == 0)
            {
                lastTouch = touch;
                draw::line(firstTouch.px, firstTouch.py, lastTouch.px, lastTouch.py, RGB15(colours[0],colours[1],colours[2]));
                firstTouch = touch;
                //q.push(touch);
            }
        }

        if (keysUp() & KEY_TOUCH)
        {
            nextTouch = 0;
        }

        if (path)
        {
            if (searched && !path->empty())
            {
                assert(path != NULL);
                assert(path->top() != NULL);
                robot.move(path->top()->x, path->top()->y);

                if (robot.getPosition().px == path->top()->x && robot.getPosition().py == path->top()->y) path->pop();
            }
            else if (path->empty())
            {
                node::cleanup();
                delete path;
                path = NULL;
                searched = false;
            }
        }
        robot.draw();

        draw::plot(target.x, target.y, RGB15(31,0,0));
        draw::plot(target.x+1, target.y, RGB15(31,0,0));
        draw::plot(target.x+2, target.y, RGB15(31,0,0));
        draw::plot(target.x-1, target.y, RGB15(31,0,0));
        draw::plot(target.x-2, target.y, RGB15(31,0,0));
        draw::plot(target.x, target.y+1, RGB15(31,0,0));
        draw::plot(target.x, target.y+2, RGB15(31,0,0));
        draw::plot(target.x, target.y-1, RGB15(31,0,0));
        draw::plot(target.x, target.y-2, RGB15(31,0,0));
        draw::plot(target.x+1, target.y+1, RGB15(31,0,0));
        draw::plot(target.x+1, target.y-1, RGB15(31,0,0));
        draw::plot(target.x-1, target.y+1, RGB15(31,0,0));
        draw::plot(target.x-1, target.y-1, RGB15(31,0,0));

    }

    return 0;
}
Пример #9
0
int main()
{	
	struct timeval tv;
	
	powerON(POWER_ALL);

	//set mode 0, enable BG0 and set it to 3D
	videoSetMode(MODE_0_3D);
	
	//Use console
	videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);	//sub bg 0 will be used to print text
	vramSetBankC(VRAM_C_SUB_BG); 
	SUB_BG0_CR = BG_MAP_BASE(31);
	BG_PALETTE_SUB[255] = RGB15(31,31,31);	//by default font will be rendered with color 255
	consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);
	
	//iprintf("Starting up...\n");
	
	// install the default exception handler
	defaultExceptionHandler();


	//irqs are nice
	irqInit();
	irqEnable(IRQ_VBLANK);
	
	// set the generic sound parameters
	setGenericSound(	11025,	/* sample rate */
						127,	/* volume */
						64,		/* panning */
						1 );	/* sound format*/
						

	glInit();
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
		
	//this should work the same as the normal gl call
	glViewPort(0,0,255,191);
	
	glClearColor(0,0,0,0);
	glClearDepth(0x7FFF);
	
	vramSetBankA(VRAM_A_TEXTURE);
	vramSetBankB(VRAM_B_TEXTURE);
	
	logo();

	glGenTextures(1, &textureID);
	glBindTexture(0, textureID);
	glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_256 , TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD , (u8*)die_bmp_bin);
	
	
	glGenTextures(1, &textureID2);
	glBindTexture(0, textureID2);
	glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)mario_bmp_bin);
	
	gettimeofday(&tv, NULL);
	//iprintf("Seeding with %d\n", tv.tv_usec);
    srand(tv.tv_usec);

	while(1){
		gameLoop();
	}

	return 0;
}//end main 
Пример #10
0
int main() {
    defaultExceptionHandler();
	// Setup the Main screen for 3D
	videoSetMode(MODE_0_3D);
    
	// initialize the geometry engine
	glInit();
	
	// enable antialiasing
	glEnable(GL_ANTIALIAS);
	
	// setup the rear plane
	glClearColor(0,0,0,31); // BG must be opaque for AA to work
	glClearPolyID(63); // BG must have a unique polygon ID for AA to work
	glClearDepth(0x7FFF);
    
	// Set our viewport to be the same size as the screen
	glViewport(0,0,255,191);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(70, 256.0 / 192.0, 0.1, 100);
	
	//ds specific, several attributes can be set here
	glPolyFmt(POLY_ALPHA(31) | POLY_CULL_FRONT);
	
	// Set the current matrix to be the model matrix
	glMatrixMode(GL_MODELVIEW);
	float x,y,z;
    float yOrbit;
    glClearColor(255,0,255,255);
	while (1)
	{
		// draw the scene
        
        glPushMatrix();
        glTranslatef(x,y,z);
        //gluLookAt(x,y,z,x,y,z+10,0,1,0);
        glRotatef(yOrbit,0,1,0);

		DrawGLScene();
        
        glPopMatrix(1);
		
		// flush to screen
		glFlush(0);
		
        scanKeys();
        
        if(keysHeld() & (KEY_UP))
        {
            z+=.05;
        }else
        if(keysHeld() & (KEY_DOWN))
        {
            z-=.05;
        }
        
        if(keysHeld() & (KEY_X))
        {
            y-=.05;
        }else
            if(keysHeld() & (KEY_B))
            {
                y+=.05;
            }
        
        
        if(keysHeld() & (KEY_LEFT|KEY_Y))
        {
            x+=.05;
        }else
            if(keysHeld() & (KEY_RIGHT|KEY_A))
            {
                x-=.05;
            }
        if(keysHeld() & KEY_L)
        {
            yOrbit-=1;
        }
        if(keysHeld() & KEY_R)
        {
            yOrbit+=1;
        }
		// wait for the screen to refresh
		swiWaitForVBlank();
	}
	
	return 0;
}
Пример #11
0
void initProgram()
{
	//------------------------
	// start initializing crap
	//------------------------
	defaultExceptionHandler(); // set up the exception handler

    powerON(POWER_ALL_2D); // turn on everything

	#ifndef DEBUG_MODE
	fb_init(); // initialize top screen video
	#else
	debugInit();
	#endif
	bg_init(); // initialize bottom screen video

	setNewOrientation(ORIENTATION_0);

	// set up extra vram banks to be scratch memory
	vramSetBankE(VRAM_E_LCD);
	vramSetBankF(VRAM_F_LCD);
	vramSetBankG(VRAM_G_LCD);
	vramSetBankH(VRAM_H_LCD);
	vramSetBankI(VRAM_I_LCD);

	fb_setBGColor(30653);
	bg_setBGColor(0);
	drawStartSplash();

	lcdMainOnTop(); // set fb to top screen
	fb_swapBuffers();
	bg_swapBuffers();

	// out of order for competition
	irqInit(); // initialize irqs

    irqSet(IRQ_VBLANK, startvBlank);
	irqEnable(IRQ_VBLANK);

	setMode(INITFAT);
	setSoundInterrupt(); // initialize fifo irq

	setGenericSound(11025, 127, 64, 1);
	waitForInit(); // wait until arm7 has loaded and gone to sleep
	initComplexSound(); // initialize sound variables
	initWifi();
	fixGautami();

	setCursorProperties(0, 2, 0, 0);
	initCapture();
	initClipboard();

	// set defaults to english in case we can't load the langauge file for
	// some reason also takes care of partial translations.
	initLanguage();
	initRandomList();
	fixAndTags();

	resetKeyboard();
	setDate();

	if(!DRAGON_InitFiles())
	{
		// oops, no cf card!
		setMode(DISPLAYCOW);

		setFont(font_arial_11);
		setColor(0xFFFF);

		bg_dispSprite(96, 5, errmsg, 0);
		bg_setClipping(5,25,250,181);
		bg_dispString(0,0,l_nofat);
		bg_swapBuffers();

		while(1)
		{
			// wee, la la la!
		  // More or less, we aren't going to do nothing here
		}
	}

	//--------------------------------------------------------------------
	//finished init, now check to make sure the DSOrganize dir is there...
	//--------------------------------------------------------------------

	findDataDirectory();
	makeDirectories();

	if(DRAGON_FileExists("DSOrganize") != FE_DIR)
	{
		setMode(DISPLAYCOW);

		// oops, not there, we must create!
		DRAGON_mkdir("DSOrganize");
		DRAGON_chdir("DSOrganize");
		DRAGON_mkdir("DAY");
		DRAGON_mkdir("HELP");
		DRAGON_mkdir("LANG");
		DRAGON_mkdir("RESOURCES");
		DRAGON_mkdir("REMINDER");
		DRAGON_mkdir("SCRIBBLE");
		DRAGON_mkdir("TODO");
		DRAGON_mkdir("VCARD");
		DRAGON_mkdir("ICONS");
		DRAGON_mkdir("CACHE");
		DRAGON_mkdir("COOKIES");
		DRAGON_mkdir("HOME");
		DRAGON_chdir("/");

		makeDefaultSettings();

		setFont(font_arial_11);
		setColor(0xFFFF);

		bg_dispSprite(96, 5, errmsg, 0);
		bg_setClipping(5,25,250,181);
		bg_dispString(0,0, l_createdir);
		bg_swapBuffers();

		while(!keysDown())
		{
			scanKeys();
		}
	}

	setMode(INITPLUGIN);

	//-------------------------------------------------------------------
	//finished creating dirs, now check to make sure if they extracted it
	//did their extracting program actually get all the dirs?
	//-------------------------------------------------------------------

	DRAGON_chdir(d_base);

	if(DRAGON_FileExists("Day") != FE_DIR)
	{
		DRAGON_mkdir("DAY");
	}
	if(DRAGON_FileExists("Help") != FE_DIR)
	{
		DRAGON_mkdir("HELP");
	}
	if(DRAGON_FileExists("Lang") != FE_DIR)
	{
		DRAGON_mkdir("LANG");
	}
	if(DRAGON_FileExists("Reminder") != FE_DIR)
	{
		DRAGON_mkdir("REMINDER");
	}
	if(DRAGON_FileExists("Scribble") != FE_DIR)
	{
		DRAGON_mkdir("SCRIBBLE");
	}
	if(DRAGON_FileExists("Todo") != FE_DIR)
	{
		DRAGON_mkdir("TODO");
	}
	if(DRAGON_FileExists("VCard") != FE_DIR)
	{
		DRAGON_mkdir("VCARD");
	}
	if(DRAGON_FileExists("Icons") != FE_DIR)
	{
		DRAGON_mkdir("ICONS");
	}
	if(DRAGON_FileExists("Cache") != FE_DIR)
	{
		DRAGON_mkdir("CACHE");
	}
	if(DRAGON_FileExists("Cookies") != FE_DIR)
	{
		DRAGON_mkdir("COOKIES");
	}
	if(DRAGON_FileExists("Home") != FE_DIR)
	{
		DRAGON_mkdir("HOME");
	}

	DRAGON_chdir("/");

	//-------------------------------------------
	//how about we load the settings for them eh?
	//-------------------------------------------
	loadSettings();

	DRAGON_chdir(d_base);

	if(DRAGON_FileExists("startup.wav") == FE_FILE)
	{
		char tStr[256];

		sprintf(tStr, "%sstartup.wav", d_base);
		loadWavToMemory();
		loadSound(tStr);
	}

	DRAGON_chdir("/");
	initStartScreen();

    irqSet(IRQ_VBLANK, vBlank);
	fb_setBGColor(genericFillColor);
	bg_setBGColor(genericFillColor);
}
Пример #12
0
int main(int _argc, char **_argv) {
    int framecount=0;
    int sramcount=0;

    argc=_argc, argv=_argv;
    defaultExceptionHandler();

    fifoSendValue32(FIFO_USER_06, (u32)ipc_region);

    DS_init(); //DS init.
#ifndef ROM_EMBEDED
    active_interface = fatInitDefault(); //init file operations to your external card.

    initNiFi();
#endif
    EMU_Init(); //emulation init.

    irqSet(IRQ_VBLANK, vblankinterrupt);
    irqEnable(IRQ_HBLANK);
    //fifoSetValue32Handler(FIFO_USER_06, aliveinterrupt, 0);
    //fifoSetValue32Handler(FIFO_USER_05, reg4015interrupt, 0);

    IPC_ALIVE = 0;
    IPC_APUIRQ = 0;
    IPC_REG4015 = 0;

    consoleinit(); //init subscreen to show chars.
    crcinit();	//init the crc table.

    //pre-alocate memory....
    //IPC_FILES = malloc(MAXFILES * 256 + MAXFILES * 4);
    //IPC_ROM = malloc(ROM_MAX_SIZE);

#ifndef ROM_EMBEDED
    if(!bootext()) {
        //chdir("/");
        do_rommenu(); //show a menu selecting rom files.
    }
#else
    do_romebd();
#endif

    //__emuflags |= PALSYNC;

    while(1) { // main loop to do the emulation
        framecount++;
        if(__emuflags & PALTIMING && global_playcount == 0) {
            framecount--;
        }
        if(debuginfo[VBLS]>59) {
            debuginfo[VBLS]-=60;
            debuginfo[1] = debuginfo[0];
            debuginfo[0] = 0;
            debuginfo[FPS]=framecount;
            framecount=0;
        }

        scanKeys();
        IPC_KEYS = keysCurrent();

        //change nsf states
        if(__emuflags & NSFFILE) {
            static int oldkey = 0;
            int keydown = IPC_KEYS & (~oldkey);
            oldkey = IPC_KEYS;

            if(keydown & KEY_LEFT) {
                if(__nsfsongno == 0) {
                    __nsfsongno = nsfheader.TotalSong-1;
                } else {
                    __nsfsongno--;
                }
            }
            if(keydown & KEY_RIGHT) {
                if(++__nsfsongno > nsfheader.TotalSong-1) {
                    __nsfsongno = 0;
                }
            }
            if(keydown & KEY_UP) {
                __nsfplay = 1;
                __nsfinit = 1;
            }
            if(keydown & KEY_DOWN) {
                __nsfplay = 0;
                Sound_reset();
            }
        }

        do_shortcuts();
        if((__emuflags & AUTOSRAM)) {
            if(__emuflags & NEEDSRAM) {
                sramcount = 1;
                __emuflags&=~NEEDSRAM;
            }
            if(sramcount > 0)
                sramcount++;
            if(sramcount > 120) {		//need auto save for sram.
                sramcount = 0;
                save_sram();
            }
        }

        touch_update(); // do menu functions.
        do_menu();	//do control menu.

        do_multi();
        if(nifi_stat == 0 || nifi_stat >= 5)
            play(); //emulate a frame of the NES game.
        else
            swiWaitForVBlank();
    }
}
Пример #13
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;
}