示例#1
0
文件: main.c 项目: ichitakasan/emulGB
/************************************************************************************
 *                                MAIN FUNCTION
 ************************************************************************************/
int main(int argc, char *argv[]) {

	// Initialisation ...
	int out = initialiseScreen();
	if (out)
		return out;
	initialiseCPU();

	// Load ROM file ...
	loadROM("roms/Tetris (W) (V1.0) [!].gb");

	// Print game info ...
	printGameInfo();

	// program main loop
	int done = 0;
	while (!done) {

		updateCPU();
//		drawScreen();
		done = listen();
		manageKeys();
	}

	printf("Exited cleanly\n");
	exitProgram();
	return 0;
}
示例#2
0
void Application::setAudioEnabled(const bool b)
{
	bool reset = false;
	if (b != snd.enabled)
	{
		reset = true;
	}

	if (b)
	{
		//snd.enabled = 1;

		_audioInitialized = true;
	}
	else
	{
		//snd.enabled = 0;

		_audioInitialized = false;
	}

	if (reset)
	{
		// TODO: wont catch auto saves
		loadROM(_currentRom);
	}
}
示例#3
0
void Application::setAudioSampleRate(int rate)
{
	bool hardReset = false;
	if (_sampleRate != rate)
	{
		hardReset = true;
	}

	_sampleRate = rate;

	if (_romLoaded && hardReset)
	{
		// TODO: wont catch auto saves
		loadROM(_currentRom);
	}
}
示例#4
0
int main(int argc, char *argv[])
{
	gp2x_init(1000, 16, 11025,16,1,60, 1);
	gp2x_sound_volume(100,100);

	screen16 = (unsigned short *)gp2x_video_RGB[0].screen;

	int i,j;
	char temp[255];

	FILE *in = NULL;
    
    if(argc <= 1) {
		printf("\nnot enough arguments\n");
		//return(TRUE);
	} else {
	
		// the hard-core UI, a command line:
		for (i=0; (i < argc || argv[i] != NULL); i++) {
		
			if(strcmp(argv[i], "--double") == 0) {
				//screen_size = 1;
			}
			if(strcmp(argv[i], "--color white") == 0) {
				supervision_set_colour_scheme(COLOUR_SCHEME_DEFAULT);
			}
			if(strcmp(argv[i], "--color amber") == 0) {
				supervision_set_colour_scheme(COLOUR_SCHEME_AMBER);
			}
			if(strcmp(argv[i], "--color green") == 0) {
				supervision_set_colour_scheme(COLOUR_SCHEME_GREEN);
			}
			if(strcmp(argv[i], "--color blue") == 0) {
				supervision_set_colour_scheme(COLOUR_SCHEME_BLUE);
			}
		}
	
		romname = strdup(argv[1]);
		in = fopen(romname, "r");
	
		if(in == NULL) {
			printf("The file %s doesn't exist.\n",romname);
			exit(0);
		}
		fflush(in);
		fclose(in);
	}
		
	supervision_init(); //Init the emulator

	getRunDir();

	if(romname!=NULL){
		loadROM(romname);
		supervision_load((u8*)buffer, (uint32)buffer_size);
	} else {
		handleFileMenu(); // File menu
	}

	emu_ReadConfig();

	gp2x_sound_volume(255,255);
	gp2x_sound_pause(0);

	while(1)
	{
	  CheckKeys();

	  while(!paused)
	  {
		 CheckKeys(); //key control

		 controls_update();

		 switch(currentConfig.videoMode){
			case 0: 
				supervision_exec((int16*)screenbuffer,1);

				for(j=0; j < 160; j++) 
		 			gp2x_memcpy(screen16+(80+(j+40)*320),screenbuffer+(j * 160),160*2);
				break;
			case 1: 
				supervision_exec2((int16*)screen16,1); 
				break;
			case 2: 
				supervision_exec3((int16*)screen16,1);
				break;
			default: break;
		 }

		 /*gp2x_video_waitvsync();

		 sprintf(temp,"FPS: %3d", FPS);
		 gp2x_printf(NULL,0,0,temp);
		 ++svFrm;*/

		 gp2x_video_RGB_flip(0);


		 controls_reset();
	  }
	}
	supervision_done(); //shutsdown the system
	gp2x_deinit();
}
示例#5
0
// service a client request; test the opcode and then do appropriate servicing
void CPicoServSession::DispatchMessageL(const RMessage &aMessage)
{
	switch (aMessage.Function()) {
		case PicoMsgLoadState: 
			if(!rom_data) User::Leave(-1); // no ROM
			User::LeaveIfError(saveLoadGame(1));
			gamestate = PGS_Running;
			return;

		case PicoMsgSaveState:
			if(!rom_data) User::Leave(-1);
			User::LeaveIfError(saveLoadGame(0));
			gamestate = PGS_Running;
			return;

		case PicoMsgLoadROM:
			loadROM();
			return;
		
		case PicoMsgResume:
			if(rom_data) gamestate = PGS_Running;
			return;

		case PicoMsgReset: 
			if(rom_data) {
				PicoReset(0);
				pico_was_reset = 1;
				gamestate = PGS_Running;
			}
			return;

		case PicoMsgKeys:
			gamestate = PGS_KeyConfig;
			return;

		case PicoMsgPause:
			gamestate = PGS_Paused;
			return;

		case PicoMsgQuit:
			DEBUGPRINT(_L("got quit msg."));
			gamestate = PGS_Quit;
			return;

		// config change
		case PicoMsgConfigChange: // launcher -> emu
			changeConfig();
			return;

		case PicoMsgRetrieveConfig: // emu -> launcher
			sendConfig();
			return;

		case PicoMsgRetrieveDebugStr: // emu -> launcher
			sendDebug();
			return;

		// requests we don't understand at all are a different thing,
		// so panic the client here, this function also completes the message
		default:
			PanicClient(EBadRequest);
			return;
	}
}
示例#6
0
void filewidget::loadbuttonclicked()
	{
	emit(loadROM());
	}
示例#7
0
EmuSettings::EmuSettings(QWidget *parent)
    : QMainWindow(parent)
{
	loadSettings();
	
	ui.setupUi(this);
	showFullScreen();
	
	saveSlotIndexChanged(gpspsettings.iLastSlot);
	//int audioOn, int samplerte, int stereoOn, int volume, bool enablespeedhack, QWidget *parent 
	//TODO: read settings
	audiosettings = new AudioSettings(gpspsettings.iAudioOn, gpspsettings.iVolume, this );
	audiosettings->setGeometry(QRect(0, 0, 640, 150));
	audiosettings->hide();
	
	antvideosettings =new videosettings( gpspsettings.iFrameSkip, 
			gpspsettings.iShowFPS, gpspsettings.ikeepAspectRatio, this );
	antvideosettings->setGeometry(QRect(0, 0, 640, 150));
	antvideosettings->hide();
	
	fileview = new filewidget( gpspsettings.iLastROM, gpspsettings.iBios,
			this );
	fileview->setGeometry(QRect(0, 0, 640, 150));
	fileview->hide();
		
	keysettings =new controlsettings( gpspsettings.iScreenSettings, this );
	keysettings->setGeometry(QRect(0, 0, 640, 150));
	keysettings->hide();
	
	currentWidget = EMainWidget;
	
	ui.saveSlotBox->setCurrentIndex(gpspsettings.iLastSlot);
	
	//connect buttons
	connect(ui.fileButton, SIGNAL(clicked()), this, SLOT(showFileMenu()));
	connect(ui.audioButton, SIGNAL(clicked()), this, SLOT(showAudioSettings()));
	connect(ui.videoButton, SIGNAL(clicked()), this, SLOT(showVideoSettings()));
	connect(ui.controlsButton, SIGNAL(clicked()), this, SLOT(showControlSettings()));
	connect(ui.exitButton, SIGNAL(clicked()), this, SLOT(exit()));
	connect(ui.loadStateButton, SIGNAL(clicked()), this, SLOT(loadStateButtonClicked()));
	connect(ui.saveStateButton, SIGNAL(clicked()), this, SLOT(saveStateButtonClicked()));
	connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(resetButtonClicked()));
	connect(ui.ContinueButton, SIGNAL(clicked()), this, SLOT(continueClicked()));
	connect(ui.aboutButton, SIGNAL(clicked()), this, SLOT(aboutClicked()));
	connect(ui.saveSlotBox, SIGNAL(currentIndexChanged(int)), this, SLOT(saveSlotIndexChanged(int)));
	
	//connect audio settins
	connect( audiosettings, SIGNAL(AudioOn(int)), this, SLOT( setAudioOn(int)));
	connect( audiosettings, SIGNAL(Volume(int)), this, SLOT( setVolume(int)));
	
	//connect video settings
	connect( antvideosettings, SIGNAL(frameskip(int)), this, SLOT( frameskip(int) ));
	connect( antvideosettings, SIGNAL(showFPS(bool)), this, SLOT( showFPS(bool) ));
	connect( antvideosettings, SIGNAL(setAspectRatio(bool)), this, SLOT( setAspectRatio(bool) ));

	//connect filewidget
	connect( fileview, SIGNAL(loadROM()), this, SLOT( loadROM()));
	connect( fileview, SIGNAL(setBios()), this, SLOT( setBios()));
	
	//connect control settings
	connect( keysettings, SIGNAL(runkeyconfig()), this, SLOT( keyConfig() ));
	connect( keysettings, SIGNAL(screensettings(int)), this, SLOT( screensettings(int) ));
	
	romloaded = false;
	settingsChanged = false;
	errorDialog = NULL;
}
示例#8
0
void handleFileMenu(void)
{

	BOOL isSelected = FALSE;
	s32 curFile = 0;
	int virtualFile = 0;
		
	fillList();
	textClear();
	while(!isSelected) {
		unsigned long pad = gp2x_joystick_read(0);
		printList(curFile);
		gp2x_printf(0, 170, 1, "VirtualFile = %d",virtualFile);
		gp2x_printf(0, 170, 10, "File Count = %d",fileCounter);

		if(FileList[virtualFile].isRunable){
			gp2x_default_font.fg = 0x6700;
			gp2x_printf(NULL, 0, (33 + (virtualFile*8)), "->");
		} else {
			gp2x_default_font.fg = 0xFFFF;
			gp2x_printf(NULL, 0, (33 + (virtualFile*8)), "->");
		}

		gp2x_default_font.fg = 0xFFFF;
			
		if(curFile)
			gp2x_printf(NULL, 200, 22, "^\n|");
			
		if((curFile + 18 != fileCounter) && fileCounter > 19)
			gp2x_printf(NULL, 200, 200, "|\nv");

		gp2x_video_RGB_flip(0);
			
		if(pad & GP2X_RIGHT) {
			virtualFile += 5;
			if(virtualFile > 18)
				curFile += virtualFile - 18;
			textClear();
		}
			
		if(pad & GP2X_LEFT) {
			virtualFile -= 5;
			if(virtualFile < 0)
				curFile += virtualFile;
			textClear();
		}
			
		if(pad & GP2X_DOWN) {
			virtualFile++;
			textClear();
		}
			
		if(pad & GP2X_UP) {
			virtualFile--;
			textClear();
		}

		if(pad & GP2X_VOL_DOWN) if(pad & GP2X_START) 
			exitMenu();
			
		if(pad & GP2X_X) {
			if(FileList[curFile + virtualFile].fType == FT_DIR) {
				chdir(FileList[curFile + virtualFile].fName);
				fillList();
				virtualFile = curFile = 0;
			} else if(FileList[curFile + virtualFile].isRunable) {
				//textClear();
				//gp2x_printf(0, 1, 1, "Loading...\n\n%s", FileList[curFile + virtualFile].fName);
				//gp2x_video_RGB_flip(0);
				RESIZE();
				loadROM(FileList[curFile + virtualFile].fName);
				textClear();
				supervision_load((u8*)buffer, (uint32)buffer_size);
				textClear();
				return;
			}
		}

		//if(pad & GP2X_A) return;
		
		if(virtualFile < 0) {
			virtualFile = 0;
			--curFile;
			if(curFile < 0)
				curFile = 0;
		}
			
		if(fileCounter < 19) {
			if(virtualFile >= fileCounter)
				virtualFile = fileCounter-1;
		} else {
			if(virtualFile > 18) {
				virtualFile = 18;
				++curFile;
				if(curFile + 18 > fileCounter)
					curFile = fileCounter - 19;
			}
		}
		
		while(pad == gp2x_joystick_read(0));
		pad = gp2x_joystick_read(0);

		textClear();
	}
}
void fileBrowserFrame_LoadFile(int i)
{
	if(dir_entries[i].attr & FILE_BROWSER_ATTR_DIR){
		// Here we are 'recursing' into a subdirectory
		// We have to do a little dance here to avoid a dangling pointer
		fileBrowser_file* dir = (fileBrowser_file*)malloc( sizeof(fileBrowser_file) );
		memcpy(dir, dir_entries+i, sizeof(fileBrowser_file));
		fileBrowserFrame_OpenDirectory(dir);
		free(dir);
		menu::Focus::getInstance().clearPrimaryFocus();
	} else {
		// We must select this file
		int ret = loadROM( &dir_entries[i] );
		
		if(!ret){	// If the read succeeded.
			strcpy(feedback_string, "Loaded ");
			strncat(feedback_string, filenameFromAbsPath(dir_entries[i].name), 36-7);

			char RomInfo[512] = "";
			char buffer [50];
			char buffer2 [50];
			strcat(RomInfo,feedback_string);
			sprintf(buffer,"\n\nRom name: %s\n",ROM_SETTINGS.goodname);
			strcat(RomInfo,buffer);
			sprintf(buffer,"Rom size: %d Mb\n",rom_length/1024/1024);
			strcat(RomInfo,buffer);
			if(ROM_HEADER->Manufacturer_ID == 'N') sprintf(buffer,"Manufacturer: Nintendo\n");
			else sprintf(buffer,"Manufacturer: %x\n", (unsigned int)(ROM_HEADER->Manufacturer_ID));
			strcat(RomInfo,buffer);
		    countrycodestring(ROM_HEADER->Country_code&0xFF, buffer2);
			sprintf(buffer,"Country: %s\n",buffer2);
			strcat(RomInfo,buffer);
			switch (autoSaveLoaded)
			{
			case NATIVESAVEDEVICE_NONE:
				break;
			case NATIVESAVEDEVICE_SD:
				strcat(RomInfo,"\nFound & loaded save from SD card\n");
				break;
			case NATIVESAVEDEVICE_USB:
				strcat(RomInfo,"\nFound & loaded save from USB device\n");
				break;
			case NATIVESAVEDEVICE_CARDA:
				strcat(RomInfo,"\nFound & loaded save from memcard in slot A\n");
				break;
			case NATIVESAVEDEVICE_CARDB:
				strcat(RomInfo,"\nFound & loaded save from memcard in slot B\n");
				break;
			}
			autoSaveLoaded = NATIVESAVEDEVICE_NONE;

			menu::MessageBox::getInstance().setMessage(RomInfo);
		}
		else		// If not.
		{
  		switch(ret) {
    		case ROM_CACHE_ERROR_READ:
			    strcpy(feedback_string,"A read error occured");
			    break;
			  case ROM_CACHE_INVALID_ROM:
			   strcpy(feedback_string,"Invalid ROM type");
			    break;
			  default:
			    strcpy(feedback_string,"An error has occured");
			    break;
		  }

			menu::MessageBox::getInstance().setMessage(feedback_string);
		}

/*		//disable all buttons
		for (int i = 0; i < NUM_FRAME_BUTTONS; i++)
			FRAME_BUTTONS[i].button->setActive(false);
		//set first entry to report 'success'/'error' and return to main menu
		FRAME_BUTTONS[2].buttonString = feedback_string;
		FRAME_BUTTONS[2].button->setClicked(Func_ReturnFromFileBrowserFrame);
		FRAME_BUTTONS[2].button->setActive(true);
		FRAME_BUTTONS[2].button->setNextFocus(menu::Focus::DIRECTION_UP, NULL);
		FRAME_BUTTONS[2].button->setNextFocus(menu::Focus::DIRECTION_DOWN, NULL);
		for (int i = 1; i<NUM_FILE_SLOTS; i++)
			FRAME_BUTTONS[i+2].buttonString = FRAME_STRINGS[2];
		pMenuContext->getFrame(MenuContext::FRAME_FILEBROWSER)->setDefaultFocus(FRAME_BUTTONS[2].button);
		menu::Focus::getInstance().clearPrimaryFocus();*/

		pMenuContext->setActiveFrame(MenuContext::FRAME_MAIN);
		if(hasLoadedROM) Func_SetPlayGame();
	}
}
示例#10
0
文件: main.c 项目: NanoCoaster/Cinoop
int main(int argc, char **argv) {
	char *filename = NULL;
	
	printf("Starting...\n");
	
	dpy = XOpenDisplay(NULL);
	
	if(dpy == NULL) {
		printf("Cannot connect to X server!\n");
		exit(0);
	}
	
	root = DefaultRootWindow(dpy);
	
	vi = glXChooseVisual(dpy, 0, att);
	
	if(vi == NULL) {
		printf("No appropriate visual found!\n");
		exit(0);
	}
	
	cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
	
	swa.colormap = cmap;
	swa.event_mask = ExposureMask | KeyPressMask;
	
	win = XCreateWindow(dpy, root, 0, 0, 160, 144, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);
	
	XMapWindow(dpy, win);
	XStoreName(dpy, win, "Cinoop");
	
	glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);
	glXMakeCurrent(dpy, win, glc);
	
	printf("argc = %d\n", argc);
	int i;
	for(i = 1; i < argc; i++) {
		filename = argv[i];
	}
	
	if(filename == NULL) {
		printf("No ROM input\n");
		
		quit();
		return 1;
	}
	
	printf("Loading file \"%s\"...\n", filename);
	
	if(!loadROM(filename)) {
		printf("Failed!\n");
		
		quit();
		return 1;
	}
	
	printf("Passed!\n");
	
	srand(time(NULL));
	reset();
	
	while(1) {
		if(XPending(dpy)) {
			XNextEvent(dpy, &xev);
			
			if(xev.type == KeyPress || xev.type == KeyRelease) {
				switch(xev.xkey.keycode) {
					//case XK_BackSpace:
					case 59:
						keys.select = (xev.type == KeyPress ? 1 : 0);
						break;
					
					//case XK_Return:
					case 44:
						keys.start = (xev.type == KeyPress ? 1 : 0);
						break;
					
					//case XK_z:
					case 14:
						keys.b = (xev.type == KeyPress);
						break;
					
					//case XK_x:
					case 15:
						keys.a = (xev.type == KeyPress);
						break;
					
					//case XK_Left:
					case 131:
						keys.left = (xev.type == KeyPress);
						break;
					
					//case XK_Right:
					case 132:
						keys.right = (xev.type == KeyPress);
						break;
					
					//case XK_Up:
					case 134:
						keys.up = (xev.type == KeyPress);
						break;
					
					//case XK_Down:
					case 133:
						keys.down = (xev.type == KeyPress);
						break;
				}
			}
		}
		
		cpuStep();
		gpuStep();
		interruptStep();
	}
	
	quit();
	
	return 0;
}