Exemple #1
0
    bool yesNoBox::getResult( const char* p_text, bool p_textAtOnce ) {
        s16 x = 8 + 64 * !!_isNamed;
        s16 y = 8;
        if( p_text && !p_textAtOnce )
            regularFont->printStringD( p_text, x, y, true );
        else if( p_text )
            regularFont->printString( p_text, x, y, true );

        u8 selIdx = (u8) -1;
        draw( 2, selIdx );
        bool result;
        loop( ) {
            swiWaitForVBlank( );
            touchPosition t;
            touchRead( &t );
            scanKeys( );
            int pressed = keysCurrent( );

            if( GET_AND_WAIT( KEY_LEFT ) ) {
                selIdx = 0;
                draw( 2, selIdx );
            } else if( GET_AND_WAIT( KEY_RIGHT ) ) {
                selIdx = 1;
                draw( 2, selIdx );
            } else if( selIdx != (u8) -1 && GET_AND_WAIT( KEY_A ) ) {
                result = !selIdx;
                break;
            }

            if( t.px >= 28 && t.py >= 102 && t.px <= 122 && t.py <= 134 ) {
                draw( 0, selIdx );
                if( !waitForTouchUp( 28, 102, 122, 134 ) ) {
                    draw( 2, selIdx );
                    continue;
                }
                draw( 2, selIdx );
                swiWaitForVBlank( );
                result = true;
                break;
            } else if( t.px >= 134 && t.py >= 102 && t.px <= 228 && t.py <= 134 ) {
                draw( 1, selIdx );
                if( !waitForTouchUp( 134, 102, 228, 134 ) ) {
                    draw( 2, selIdx );
                    continue;
                }
                draw( 2, selIdx );
                swiWaitForVBlank( );
                result = false;
                break;
            }
        }
        return result;
    }
Exemple #2
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();
    }
}
// ========================***************************==============================
void fileSelect(const char *startdir, char *out_dir, char *out_fname, netbuf *buf,
  bool allow_cancel, bool allow_up)
{
	bool select = false;
	static int size_list = 18;
	
	int num_files = 0;
	int sel_file = 0;
	int first_file = 0;
	
	// get list of files in current dir
	if (buf)
		ftpGetFileList("/", buf, num_files);
	else
		fileGetFileList(startdir, num_files);
	filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel);
		
	while (!select) {
		// get_event
		uint32 keys = keysCurrent();
		
		// handle_event
		if (keys & KEY_DOWN) {
			if (sel_file < num_files-1) {
				sel_file++;
				if (sel_file >= first_file + size_list - 1)
					first_file = sel_file - (size_list - 1);
				filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel);
			} else {
				// wrap around to top of list
				sel_file = 0;
				first_file = 0;
				filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel);
			}
		} else if (keys & KEY_UP) {
			if (sel_file > 0) {
				sel_file--;
				if (sel_file < first_file)
					first_file = sel_file;
				filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel);
			} else {
				// wrap around to bottom of list
				sel_file = num_files - 1;
				first_file = sel_file - (size_list - 1);
				filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel);
			}
		} else if (keys & KEY_A) {
			// get selected file name
			char *buf2 = (char*)data;
			char fname[128];
			for (int i = 0; i < sel_file; i++) {
				buf2 = strchr(buf2, '\n') + 1;
			}
			char c;
			sscanf(buf2, "%c%[^\n]", &c, fname); // gets 'd' or 'f' - dir or file			
			// special cases
			if (stricmp(fname, ".") == 0)
				// don't do anything
				continue;
			if (stricmp(fname, "..") == 0) {
				// return to parent function (usually results in "back to higher level")
				while (keysCurrent() & (KEY_A | KEY_B));
				if (!allow_up)
					continue;
				if (buf)
					FtpChdir("..", buf);
				return;
			}
			
			// get selected file properties
			char fullname[512];
			sprintf(fullname, "%s%s", startdir, fname);
			struct stat statbuf;
			stat(fullname, &statbuf);
			if (c == 'd') {
				char fullpath[512];
				sprintf(fullpath, "%s%s/", startdir, fname);
				if (buf)
					FtpChdir(fname, buf);
				fileSelect(fullpath, out_dir, out_fname, buf, allow_cancel, true);
				if ((keysCurrent() & (KEY_L | KEY_R)) && allow_cancel)
					return;
				while (keysCurrent() & (KEY_A | KEY_B));
				
				// did we select a file? if so, keep returning to parent calling function
				if (strlen(out_fname))
					return;
				
				// we did not select anything, so regenerate the old list
				num_files = 0;
				if (buf)
					ftpGetFileList("/", buf, num_files);
				else
					fileGetFileList(startdir, num_files);
				filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel);
				continue;
			} else {
				sprintf(out_dir, "%s", startdir);
				sprintf(out_fname, "%s", fname);
				while (keysCurrent() & (KEY_A | KEY_B));
				return;
			}
		} else if (keys & KEY_B) {
			if (!allow_up)
				continue;
			if (buf)
				FtpChdir("..", buf);
			return;
		} else if (keys & (KEY_L | KEY_R)) {
			if (allow_cancel) {
				sprintf(out_dir, "%s", startdir);
				out_fname[0] = 0;
				return;
			}
		}
		
		for (int i = 0; i < 5; i++)
			swiWaitForVBlank();
	}
}
Exemple #4
0
int get_joypad()
{
	int res = 0;

/*#define KEYS_CUR (( ((~REG_KEYINPUT)&0x3ff) | (((~IPC->buttons)&3)<<10) | \
	 			 (((~IPC->buttons)<<6) & (KEY_TOUCH|KEY_LID) ))^KEY_LID)	
	keys = KEYS_CUR;*/
	
	//scanKeys();	
	keys = keysCurrent();

#if 0
		if( (keys & KEY_L))
		{
			if ((keys & KEY_UP))
			{
				APU_MAX++;
			}
			if ((keys & KEY_DOWN))
			{
				APU_MAX--;
				if (APU_MAX < 100)
					APU_MAX = 100;
			}  
			if ((keys & KEY_LEFT))
			{
				APU_printLog();				
			}
			if ((keys & KEY_RIGHT))
			{
				LOG("%04x %04x %02x %02x %04x %04x\n", CPU.PC,
				(uint32)((sint32)PCptr+(sint32)SnesPCOffset),
				PORT_SNES_TO_SPC[1], PORT_SPC_TO_SNES[1],  
				
				 (*(uint32*)memUncached(0x2FE0000)) & 0xFFFF, *(uint16 *)(APU_RAM_ADDRESS+0x18));
				
				//PORT_SNES_TO_SPC[1] = 0x44; 		
			}
			
		}	
#endif	
	
	if ((keys & KEY_L) && ( keys & KEY_R ) && ( keys & KEY_START))
	{		
		if (keys & KEY_LEFT)
		{
			if (joypad_conf_mode)
				return 0;			
			CFG.mouse ^= 1;
/*			lcdSwap();
			if (GUI.hide)
				setBacklight(CFG.mouse ? PM_BACKLIGHT_BOTTOM : PM_BACKLIGHT_TOP);*/
			myLCDSwap();
			joypad_conf_mode = 1;
			return 0;			
		}
		if (keys & KEY_RIGHT)
		{
			if (joypad_conf_mode)
				return 0;			
			CFG.mouse = 0;
/*			lcdSwap();
			if (GUI.hide)
				setBacklight(CFG.mouse ? PM_BACKLIGHT_BOTTOM : PM_BACKLIGHT_TOP);*/
			myLCDSwap();			
			joypad_conf_mode = 1;
			return 0;				
		}		
		if (keys & KEY_UP)
		{
			if (joypad_conf_mode)
				return 0;
			PPU_ChangeLayerConf(CFG.LayersConf+1);
			joypad_conf_mode = 1;
			return 0;
		}			
		if (keys & KEY_DOWN)
		{
			if (joypad_conf_mode)
				return 0;	
			PPU_ChangeLayerConf(0);
			joypad_conf_mode = 1;
			return 0;
		}			
		joypad_conf_mode = 0;		
		return 0;
	} 
	 
#if 0	 
	if ((keys & KEY_L) && ( keys & KEY_R ) && ( keys & KEY_SELECT))
	{		
		if (keys & KEY_LEFT)
		{
			if (joypad_conf_mode)
				return 0;			
			CFG.BG_priority ^= 1;
			LOG("BG_pri = %d\n", CFG.BG_priority);
			joypad_conf_mode = 1;
			return 0;			
		}
		if (keys & KEY_RIGHT)
		{
			if (joypad_conf_mode)
				return 0;
			CFG.Debug ^= 1;
			if (CFG.Debug)
				showDebugMenu();
			joypad_conf_mode = 1;
			return 0;			
		}		
		if (keys & KEY_UP)
		{
			if (joypad_conf_mode)
				return 0;			
			CFG.Debug2 --;
			LOG("Debug = %d\n", CFG.Debug);
			return 0;			
		}				
		if (keys & KEY_DOWN)
		{
			if (joypad_conf_mode)
				return 0;			
			CFG.Debug2 ++;
			LOG("Debug = %d\n", CFG.Debug);
			return 0;			
		}		
		joypad_conf_mode = 0;		
		return 0;
	}
#endif	 	 
	 
/*	scanKeys();	
	keys = keysHeld();*/
	if( keys & KEY_B ) res |= 0x8000;
	if( keys & KEY_Y ) res |= 0x4000;
	if( keys & KEY_SELECT ) res |= 0x2000;
	if( keys & KEY_START ) res |= 0x1000;
	if( keys & KEY_UP ) res |= 0x0800;
	if( keys & KEY_DOWN ) res |= 0x0400;
	if( keys & KEY_LEFT ) res |= 0x0200;
	if( keys & KEY_RIGHT ) res |= 0x0100;
	if( keys & KEY_A ) res |= 0x0080;
	if( keys & KEY_X ) res |= 0x0040;
	if( keys & KEY_L ) res |= 0x0020;
	if( keys & KEY_R ) res |= 0x0010;	
	
	if (CFG.mouse)
	{
		if((keys & KEY_LEFT) || (keys & KEY_Y)) mouse_cur_b = 1;
		if((keys & KEY_RIGHT) || (keys & KEY_A)) mouse_cur_b = 2;
		if( ( !(keys & KEY_L) && (keys & KEY_DOWN) ) ||	
		    ( !(keys & KEY_R) && (keys & KEY_B) )) mouse_cur_b = 0;
		    
		if (keys & KEY_SELECT)
			PPU_reset();
		
		if( (keys & KEY_L) || (keys & KEY_R) )
		{
			if (((keys & KEY_UP) || (keys & KEY_X)) && GFX.YScroll > 0)
			{
				GFX.YScroll--;
				GFX.BG3YScroll = GFX.YScroll;
			}
			if (((keys & KEY_DOWN) || (keys & KEY_B)) && GFX.YScroll < 32)
			{
				GFX.YScroll++;
				GFX.BG3YScroll = GFX.YScroll;
			}  
		}

		touchPosition touchXY;
		touchRead(&touchXY);
		if (keys & KEY_TOUCH)
		{		
			int tx=0, ty=0;

			tx = touchXY.px;
			if (CFG.Scaled == 0) // No scaling
				ty = touchXY.py+GFX.YScroll;
			else if (CFG.Scaled == 1) // Half scaling
				ty = touchXY.py*208/192+12; // FIXME			
			else if (CFG.Scaled == 2) // Full screen
				ty = touchXY.py*224/192;
			
			if (CFG.MouseMode == 0)
			{
				SNES.mouse_x = tx; 
				SNES.mouse_x = ty;
			}
			else
			if (CFG.MouseMode == 1)
			{
				SNESC.RAM[CFG.MouseXAddr] = tx+CFG.MouseXOffset;
        		SNESC.RAM[CFG.MouseYAddr] = ty+CFG.MouseYOffset;				
			}
			if (CFG.MouseMode == 2)
			{		
				*(uint16 *)(&SNESC.RAM[CFG.MouseXAddr]) = tx*2;
        		*(uint16 *)(&SNESC.RAM[CFG.MouseYAddr]) = ty*2;
			}			
			if( (!(keys & KEY_L) &&  (keys & KEY_UP)) ||
				(!(keys & KEY_R) && (keys & KEY_X)) )
			{
				SNES.prev_mouse_x = SNES.mouse_x; 
				SNES.prev_mouse_y = SNES.mouse_y;
				SNES.mouse_b =  0;
			}
			else
				SNES.mouse_b =  mouse_cur_b;
		
		}
		else
		SNES.mouse_b =  0;
	}
		
	return res;
}