Beispiel #1
0
void internal_ControllerCommand(int Control, BYTE *Command)
{
   switch (Command[2])
     {
      case 0x00: // check
      case 0xFF:
	if ((Command[1] & 0x80))
	  break;
	if (Controls[Control].Present)
	  {
	     Command[3] = 0x05;
	     Command[4] = 0x00;
	     switch(Controls[Control].Plugin)
	       {
		case PLUGIN_MEMPAK:
		  Command[5] = 1;
		  break;
		case PLUGIN_RAW:
		  Command[5] = 1;
		  break;
		default:
		  Command[5] = 0;
		  break;
	       }
	  }
	else
	  Command[1] |= 0x80;
	break;
      case 0x01:
	if (!Controls[Control].Present)
	  Command[1] |= 0x80;
	break;
      case 0x02: // read controller pack
	if (Controls[Control].Present)
	  {
	     switch(Controls[Control].Plugin)
	       {
		case PLUGIN_MEMPAK:
		    {
		       int address = (Command[3] << 8) | Command[4];
		       if (address == 0x8001)
			 {
			    memset(&Command[5], 0, 0x20);
			    Command[0x25] = mempack_crc(&Command[5]);
			 }
		       else
			 {
			    address &= 0xFFE0;
			    if (address <= 0x7FE0)
			      {
				 char *filename;
				 FILE *f;
				 filename = malloc(strlen(get_savespath())+
						   strlen(ROM_SETTINGS.goodname)+4+1);
				 strcpy(filename, get_savespath());
				 strcat(filename, ROM_SETTINGS.goodname);
				 if (UseSave == 1)
                 strcat(filename, ".mpk");
                 else
                 strcat(filename,".net");
				 f = fopen(filename, "rb");
				 if (f)
				   {
				      fread(mempack[0], 1, 0x8000, f);
				      fread(mempack[1], 1, 0x8000, f);
				      fread(mempack[2], 1, 0x8000, f);
				      fread(mempack[3], 1, 0x8000, f);
				      fclose(f);
				   }
				 else format_mempacks();
				 free(filename);
				 memcpy(&Command[5], &mempack[Control][address], 0x20);
			      }
			    else
			      {
				 memset(&Command[5], 0, 0x20);
			      }
			    Command[0x25] = mempack_crc(&Command[5]);
			 }
		    }
		  break;
		case PLUGIN_RAW:
		  if (controllerCommand) controllerCommand(Control, Command);
		  break;
		default:
		  memset(&Command[5], 0, 0x20);
		  Command[0x25] = 0;
	       }
	  }
	else
	  Command[1] |= 0x80;
	break;
      case 0x03: // write controller pack
	if (Controls[Control].Present)
	  {
	     switch(Controls[Control].Plugin)
	       {
		case PLUGIN_MEMPAK:
		    {
		       int address = (Command[3] << 8) | Command[4];
		       if (address == 0x8001) 
			 Command[0x25] = mempack_crc(&Command[5]);
		       else
			 {
			    address &= 0xFFE0;
			    if (address <= 0x7FE0)
			      {
				 char *filename;
				 FILE *f;
				 filename = malloc(strlen(get_savespath())+
						   strlen(ROM_SETTINGS.goodname)+4+1);
				 strcpy(filename, get_savespath());
				 strcat(filename, ROM_SETTINGS.goodname);
				 if (UseSave == 1)
                 strcat(filename, ".mpk");
                 else
                 strcat(filename,".net");
				 f = fopen(filename, "rb");
				 if (f)
				   {
				      fread(mempack[0], 1, 0x8000, f);
				      fread(mempack[1], 1, 0x8000, f);
				      fread(mempack[2], 1, 0x8000, f);
				      fread(mempack[3], 1, 0x8000, f);
				      fclose(f);
				   }
				 else format_mempacks();
				 memcpy(&mempack[Control][address], &Command[5], 0x20);
				 f = fopen(filename, "wb");
				 fwrite(mempack[0], 1, 0x8000, f);
				 fwrite(mempack[1], 1, 0x8000, f);
				 fwrite(mempack[2], 1, 0x8000, f);
				 fwrite(mempack[3], 1, 0x8000, f);
				 fclose(f);
				 free(filename);
			      }
			    Command[0x25] = mempack_crc(&Command[5]);
			 }
		    }
		  break;
		case PLUGIN_RAW:
		  if (controllerCommand) controllerCommand(Control, Command);
		  break;
		default:
		  Command[0x25] = mempack_crc(&Command[5]);
	       }
	  }
	else
	  Command[1] |= 0x80;
	break;
     }
}
int loadROM(fileBrowser_file* rom){
  int ret = 0;
  savestates_job = 0; //clear all pending save states
	// First, if there's already a loaded ROM
	if(hasLoadedROM){
		// Unload it, and deinit everything
		cpu_deinit();
		eepromWritten = FALSE;
		mempakWritten = FALSE;
		sramWritten = FALSE;
		flashramWritten = FALSE;
		romClosed_RSP();
		romClosed_input();
		romClosed_audio();
		romClosed_gfx();
		closeDLL_RSP();
		closeDLL_input();
		closeDLL_audio();
		closeDLL_gfx();

		ROMCache_deinit();
		free_memory();
#ifndef HW_RVL
		ARAM_manager_deinit();
#endif
	}
	format_mempacks();
	reset_flashram();
	init_eeprom();
	hasLoadedROM = TRUE;
#ifndef HW_RVL
	ARAM_manager_init();
#endif
#ifdef USE_TLB_CACHE
	TLBCache_init();
#else
	tlb_mem2_init();
#endif
	//romFile_init(rom);
	ret = rom_read(rom);
	if(ret){	// Something failed while trying to read the ROM.
		hasLoadedROM = FALSE;
		return ret;
	}

	// Init everything for this ROM
	init_memory();

	gfx_set_fb(xfb[0], xfb[1]);
	if (screenMode == SCREENMODE_16x9_PILLARBOX)
		gfx_set_window( 78, 0, 483, 480);
	else
		gfx_set_window( 0, 0, 640, 480);

	gfx_info_init();
	audio_info_init();
//	control_info_init();
	rsp_info_init();

	romOpen_gfx();
//	gfx_set_fb(xfb[0], xfb[1]);
	romOpen_audio();
	romOpen_input();

	cpu_init();

  if(autoSave==AUTOSAVE_ENABLE) {
    switch (nativeSaveDevice)
    {
    	case NATIVESAVEDEVICE_SD:
    	case NATIVESAVEDEVICE_USB:
    		// Adjust saveFile pointers
    		saveFile_dir = (nativeSaveDevice==NATIVESAVEDEVICE_SD) ? &saveDir_libfat_Default:&saveDir_libfat_USB;
    		saveFile_readFile  = fileBrowser_libfat_readFile;
    		saveFile_writeFile = fileBrowser_libfat_writeFile;
    		saveFile_init      = fileBrowser_libfat_init;
    		saveFile_deinit    = fileBrowser_libfat_deinit;
    		break;
    	case NATIVESAVEDEVICE_CARDA:
    	case NATIVESAVEDEVICE_CARDB:
    		// Adjust saveFile pointers
    		saveFile_dir       = (nativeSaveDevice==NATIVESAVEDEVICE_CARDA) ? &saveDir_CARD_SlotA:&saveDir_CARD_SlotB;
    		saveFile_readFile  = fileBrowser_CARD_readFile;
    		saveFile_writeFile = fileBrowser_CARD_writeFile;
    		saveFile_init      = fileBrowser_CARD_init;
    		saveFile_deinit    = fileBrowser_CARD_deinit;
    		break;
    }
    // Try loading everything
  	int result = 0;
  	saveFile_init(saveFile_dir);
  	result += loadEeprom(saveFile_dir);
  	result += loadSram(saveFile_dir);
  	result += loadMempak(saveFile_dir);
  	result += loadFlashram(saveFile_dir);
  	saveFile_deinit(saveFile_dir);

  	switch (nativeSaveDevice)
  	{
  		case NATIVESAVEDEVICE_SD:
//			if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from SD card");
  			if (result) autoSaveLoaded = NATIVESAVEDEVICE_SD;
  			break;
  		case NATIVESAVEDEVICE_USB:
//			if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from USB device");
  			if (result) autoSaveLoaded = NATIVESAVEDEVICE_USB;
  			break;
  		case NATIVESAVEDEVICE_CARDA:
//			if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from memcard in slot A");
  			if (result) autoSaveLoaded = NATIVESAVEDEVICE_CARDA;
  			break;
  		case NATIVESAVEDEVICE_CARDB:
 //			if (result) menu::MessageBox::getInstance().setMessage("Found & loaded save from memcard in slot B");
  			if (result) autoSaveLoaded = NATIVESAVEDEVICE_CARDB;
  			break;
  	}
  }
	return 0;
}