Example #1
0
/**
 * Read a custom pallete from a file and load it into the core.
 */
int
LoadCPalette(const std::string &file)
{
	uint8 tmpp[192];
	FILE *fp;

	if(!(fp = FCEUD_UTF8fopen(file.c_str(), "rb"))) {
		char errorMsg[256];
		strcpy(errorMsg, "Error loading custom palette from file: ");
		strcat(errorMsg, file.c_str());
		FCEUD_PrintError(errorMsg);
		return 0;
	}
	size_t result = fread(tmpp, 1, 192, fp);
	if(result != 192) {
		char errorMsg[256];
		strcpy(errorMsg, "Error loading custom palette from file: ");
		strcat(errorMsg, file.c_str());
		FCEUD_PrintError(errorMsg);
		return 0;
	}
	FCEUI_SetUserPalette(tmpp, result/3);
	fclose(fp);
	return 1;
}
Example #2
0
int KeyboardInitialize(void) {
	if (lpdid)
		return(1);

	ddrval = IDirectInput7_CreateDeviceEx(lpDI, &GUID_SysKeyboard, &IID_IDirectInputDevice7, (LPVOID*)&lpdid, 0);
	if (ddrval != DI_OK) {
		FCEUD_PrintError("DirectInput: Error creating keyboard device.");
		return 0;
	}

	ddrval = IDirectInputDevice7_SetCooperativeLevel(lpdid, hAppWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
	if (ddrval != DI_OK) {
		FCEUD_PrintError("DirectInput: Error setting keyboard cooperative level.");
		return 0;
	}

	ddrval = IDirectInputDevice7_SetDataFormat(lpdid, &c_dfDIKeyboard);
	if (ddrval != DI_OK) {
		FCEUD_PrintError("DirectInput: Error setting keyboard data format.");
		return 0;
	}

	ddrval = IDirectInputDevice7_Acquire(lpdid);
	/* Not really a fatal error. */
	//if(ddrval != DI_OK)
	//{
	// FCEUD_PrintError("DirectInput: Error acquiring keyboard.");
	// return 0;
	//}
	return 1;
}
Example #3
0
void ConfigAddCheat(HWND wnd) {
    if (!GI) {
        FCEUD_PrintError("You must have a game loaded before you can manipulate cheats.");
        return;
    }

    if (GI->type == GIT_NSF) {
        FCEUD_PrintError("Sorry, you can't cheat with NSFs.");
        return;
    }

    DialogBox(fceu_hInstance, "ADDCHEAT", wnd, AddCheatCallB);
}
Example #4
0
int NSFLoad(int fp)
{
  int x;

  FCEU_fseek(fp,0,SEEK_SET);
  FCEU_fread(&NSFHeader,1,0x80,fp);
  if(memcmp(NSFHeader.ID,"NESM\x1a",5))
                  return 0;
  NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0;

  LoadAddr=NSFHeader.LoadAddressLow;
  LoadAddr|=NSFHeader.LoadAddressHigh<<8;

  if(LoadAddr<0x6000)
  {
   FCEUD_PrintError("Invalid load address.");
   return(0);
  }
  InitAddr=NSFHeader.InitAddressLow;
  InitAddr|=NSFHeader.InitAddressHigh<<8;

  PlayAddr=NSFHeader.PlayAddressLow;
  PlayAddr|=NSFHeader.PlayAddressHigh<<8;

  NSFSize=FCEU_fgetsize(fp)-0x80;

  NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096);
  NSFMaxBank=uppow2(NSFMaxBank);

  if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096)))
   return 0;

  FCEU_fseek(fp,0x80,SEEK_SET);
  memset(NSFDATA,0x00,NSFMaxBank*4096);
  FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp);

  NSFMaxBank--;

  BSon=0;
  for(x=0;x<8;x++)
   BSon|=NSFHeader.BankSwitch[x];

 FCEUGameInfo.type=GIT_NSF;
 FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD;
 FCEUGameInfo.cspecial=SIS_NSF;

 for(x=0;;x++)
 {
  if(NSFROM[x]==0x20)
  {
   NSFROM[x+1]=InitAddr&0xFF;
   NSFROM[x+2]=InitAddr>>8;
   NSFROM[x+8]=PlayAddr&0xFF;
   NSFROM[x+9]=PlayAddr>>8;
   break;
  }
 }
Example #5
0
int InitDInput(void) {
    HRESULT ddrval;

    ddrval = DirectInputCreateEx(fceu_hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput7, (LPVOID*)&lpDI, 0);
    if (ddrval != DI_OK) {
        FCEUD_PrintError("DirectInput: Error creating DirectInput object.");
        return 0;
    }
    return 1;
}
Example #6
0
void FCEU_PrintError(char *format, ...) {
	char temp[2048];

	va_list ap;

	va_start(ap, format);
	vsprintf(temp, format, ap);
	FCEUD_PrintError(temp);

	va_end(ap);
}
Example #7
0
void BeginDSeq(HWND hParent)
{
 if(dwin)
 {
  SetFocus(dwin);
  return;
 }
 if(!GI)
 {
  FCEUD_PrintError("You must have a game loaded before you can screw up a game.");
  return;
 }

 dwin=CreateDialog(fceu_hInstance,"DEBUGGER",0,DebugCon);
}
Example #8
0
static void UpdateBackgroundAccess(bool enable) {
	if(!deviceHandle)
		return;

	static bool bkgModeEnabled = false;
	if(bkgModeEnabled != enable) {
		bkgModeEnabled = enable;

		if(!directinput::SetCoopLevel(deviceHandle, GetMainHWND(), bkgModeEnabled))
		{
			FCEUD_PrintError("DirectInput: Error setting keyboard cooperative level.");
			return;
		}

		directinput::Acquire(deviceHandle);
	}
}
Example #9
0
bool SetPalette(const char* nameo)
{
	FILE *fp;
	if((fp = FCEUD_UTF8fopen(nameo, "rb")))
	{
		fread(cpalette, 1, 192, fp);
		fclose(fp);
		FCEUI_SetPaletteArray(cpalette);
		eoptions |= EO_CPALETTE;
		return true;
	}
	else
	{
		FCEUD_PrintError("Error opening palette file!");
		return false;
	}
}
Example #10
0
void cfg_NewToOld(CFGSTRUCT *cfgst)
{
	int x=0;

	while(cfgst[x].ptr)
	{
		//structure contains another embedded structure. recurse.
		if(!cfgst[x].name) {
			cfg_NewToOld((CFGSTRUCT*)cfgst[x].ptr);
			x++;
			continue;
		}

		//if the key was not found, skip it
		if(cfgmap.find(std::string(cfgst[x].name)) == cfgmap.end())
		{
			x++;
			continue;
		}

		if(cfgst[x].len)
		{
			//binary data
			if(!StringToBytes(cfgmap[cfgst[x].name],cfgst[x].ptr,cfgst[x].len))
				FCEUD_PrintError("Config error: error parsing parameter");
		}
		else
		{
			//string data
			if(*(char*)cfgst[x].ptr)
				free(cfgst[x].ptr);
			std::string& str = cfgmap[cfgst[x].name];
			if(str == "")
				*(char**)cfgst[x].ptr = 0;
			else
				*(char**)cfgst[x].ptr = strdup(cfgmap[cfgst[x].name].c_str());
		}

		x++;
	}
}
Example #11
0
//Show the record movie dialog and record a movie.
void FCEUD_MovieRecordTo()
{
	if (RA_HardcoreModeIsActive())
	{
		MessageBox(nullptr, ("Hardcore Mode is active. Movie Recording/Playback is disabled."), ("Warning"), MB_OK);
		return;
	}

	if (!GameInfo) return;
	static struct CreateMovieParameters p;
	p.szFilename = strdup(FCEU_MakeFName(FCEUMKF_MOVIE,0,0).c_str());
	if(p.recordFrom >= 2) p.recordFrom=1;

	if(DialogBoxParam(fceu_hInstance, "IDD_RECORDINP", hAppWnd, RecordDialogProc, (LPARAM)&p))
	{
		if(p.recordFrom >= 2)
		{
			// attempt to load the savestate
			// FIXME:  pop open a messagebox if this fails
			FCEUI_LoadState(p.szSavestateFilename.c_str());
			{
				extern int loadStateFailed;

				if(loadStateFailed)
				{
					char str [1024];
					sprintf(str, "Failed to load save state \"%s\".\nRecording from current state instead...", p.szSavestateFilename.c_str());
					FCEUD_PrintError(str);
				}
			}
		}

		EMOVIE_FLAG flags = MOVIE_FLAG_NONE;
		if(p.recordFrom == 0) flags = MOVIE_FLAG_FROM_POWERON;
		FCEUI_SaveMovie(p.szFilename.c_str(), flags, p.authorName);
	}
}
Example #12
0
/**
 * Attempts to initialize the graphical video display.  Returns 0 on
 * success, -1 on failure.
 */
int
InitVideo(FCEUGI *gi)
{
	// XXX soules - const?  is this necessary?
	const SDL_VideoInfo *vinf;
	int error, flags = 0;
	int doublebuf, xstretch, ystretch, xres, yres, show_fps;

	FCEUI_printf("Initializing video...");

	// load the relevant configuration variables
	g_config->getOption("SDL.Fullscreen", &s_fullscreen);
	g_config->getOption("SDL.DoubleBuffering", &doublebuf);
#ifdef OPENGL
	g_config->getOption("SDL.OpenGL", &s_useOpenGL);
#endif
	g_config->getOption("SDL.SpecialFilter", &s_sponge);
	g_config->getOption("SDL.XStretch", &xstretch);
	g_config->getOption("SDL.YStretch", &ystretch);
	g_config->getOption("SDL.LastXRes", &xres);
	g_config->getOption("SDL.LastYRes", &yres);
	g_config->getOption("SDL.ClipSides", &s_clipSides);
	g_config->getOption("SDL.NoFrame", &noframe);
	g_config->getOption("SDL.ShowFPS", &show_fps);

	// check the starting, ending, and total scan lines
	FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline);
	s_tlines = s_erendline - s_srendline + 1;

	// check if we should auto-set x/y resolution

    // check for OpenGL and set the global flags
#if OPENGL
	if(s_useOpenGL && !s_sponge) {
		flags = SDL_OPENGL;
	}
#endif

	// initialize the SDL video subsystem if it is not already active
	if(!SDL_WasInit(SDL_INIT_VIDEO)) {
		error = SDL_InitSubSystem(SDL_INIT_VIDEO);
		if(error) {
			FCEUD_PrintError(SDL_GetError());
			return -1;
		}
	}
	s_inited = 1;

	// shows the cursor within the display window
	SDL_ShowCursor(1);

	// determine if we can allocate the display on the video card
	vinf = SDL_GetVideoInfo();
	if(vinf->hw_available) {
		flags |= SDL_HWSURFACE;
	}
    
	// get the monitor's current resolution if we do not already have it
	if(s_nativeWidth < 0) {
		s_nativeWidth = vinf->current_w;
	}
	if(s_nativeHeight < 0) {
		s_nativeHeight = vinf->current_h;
	}

	// check to see if we are showing FPS
	FCEUI_SetShowFPS(show_fps);
    
	// check if we are rendering fullscreen
	if(s_fullscreen) {
		int no_cursor;
		g_config->getOption("SDL.NoFullscreenCursor", &no_cursor);
		flags |= SDL_FULLSCREEN;
		SDL_ShowCursor(!no_cursor);
	}
	else {
		SDL_ShowCursor(1);
	}
    
	if(noframe) {
		flags |= SDL_NOFRAME;
	}

	// gives the SDL exclusive palette control... ensures the requested colors
	// flags |= SDL_HWPALETTE;

	// enable double buffering if requested and we have hardware support
#ifdef OPENGL
	if(s_useOpenGL) {
		FCEU_printf("Initializing with OpenGL (Disable with '--opengl 0').\n");
		if(doublebuf) {
			 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		}
	} else
#endif
		if(doublebuf && (flags & SDL_HWSURFACE)) {
			flags |= SDL_DOUBLEBUF;
		}

	if(s_fullscreen) {
		int desbpp, autoscale;
		g_config->getOption("SDL.BitsPerPixel", &desbpp);
		g_config->getOption("SDL.AutoScale", &autoscale);
		if (autoscale)
		{
			double auto_xscale = GetXScale(xres);
			double auto_yscale = GetYScale(yres);
			double native_ratio = ((double)NWIDTH) / s_tlines;
			double screen_ratio = ((double)xres) / yres;
			int keep_ratio;
            
			g_config->getOption("SDL.KeepRatio", &keep_ratio);
            
			// Try to choose resolution
			if (screen_ratio < native_ratio)
			{
				// The screen is narrower than the original. Maximizing width will not clip
				auto_xscale = auto_yscale = GetXScale(xres);
				if (keep_ratio) 
					auto_yscale = GetYScale(yres);
			}
			else
			{
				auto_yscale = auto_xscale = GetYScale(yres);
				if (keep_ratio) 
					auto_xscale = GetXScale(xres);
			}
			s_exs = auto_xscale;
			s_eys = auto_yscale;
		}
		else
		{
			g_config->getOption("SDL.XScale", &s_exs);
			g_config->getOption("SDL.YScale", &s_eys);
		}
		g_config->getOption("SDL.SpecialFX", &s_eefx);

#ifdef OPENGL
		if(!s_useOpenGL) {
			s_exs = (int)s_exs;
			s_eys = (int)s_eys;
		} else {
			desbpp = 0;
		}
        
		// -Video Modes Tag-
		if(s_sponge) {
			if(s_sponge == 4 || s_sponge == 5) {
				s_exs = s_eys = 3;
			} else {
				s_exs = s_eys = 2;
			}
			s_eefx = 0;
			if(s_sponge == 1 || s_sponge == 4) {
				desbpp = 32;
			}
		}

		if((s_useOpenGL && !xstretch) || !s_useOpenGL)
#endif
			if(xres < (NWIDTH * s_exs) || s_exs <= 0.01) {
				FCEUD_PrintError("xscale out of bounds.");
				KillVideo();
				return -1;
			}

#ifdef OPENGL
		if((s_useOpenGL && !ystretch) || !s_useOpenGL)
#endif
			if(yres < s_tlines * s_eys || s_eys <= 0.01) {
				FCEUD_PrintError("yscale out of bounds.");
				KillVideo();
				return -1;
			}

#ifdef OPENGL
		s_screen = SDL_SetVideoMode(s_useOpenGL ? s_nativeWidth : xres,
									s_useOpenGL ? s_nativeHeight : yres,
									desbpp, flags);
#else
		s_screen = SDL_SetVideoMode(xres, yres, desbpp, flags);
#endif

		if(!s_screen) {
			FCEUD_PrintError(SDL_GetError());
			return -1;
		}
	} else {
		int desbpp;
		g_config->getOption("SDL.BitsPerPixel", &desbpp);

		g_config->getOption("SDL.XScale", &s_exs);
		g_config->getOption("SDL.YScale", &s_eys);
		g_config->getOption("SDL.SpecialFX", &s_eefx);
        
		// -Video Modes Tag-
		if(s_sponge) {
			if(s_sponge >= 4) {
				s_exs = s_eys = 3;
			} else {
				s_exs = s_eys = 2;
			}
			s_eefx = 0;
		}

#ifdef OPENGL
		if(!s_useOpenGL) {
			s_exs = (int)s_exs;
			s_eys = (int)s_eys;
		}
		if(s_exs <= 0.01) {
			FCEUD_PrintError("xscale out of bounds.");
			KillVideo();
			return -1;
		}
		if(s_eys <= 0.01) {
			FCEUD_PrintError("yscale out of bounds.");
			KillVideo();
			return -1;
		}
		if(s_sponge && s_useOpenGL) {
			FCEUD_PrintError("scalers not compatible with openGL mode.");
			KillVideo();
			return -1;
		}
#endif

#if defined(_GTK) && defined(SDL_VIDEO_DRIVER_X11)
		if(noGui == 0)
		{
			while (gtk_events_pending())
				gtk_main_iteration_do(FALSE);
        
			char SDL_windowhack[128];
			sprintf(SDL_windowhack, "SDL_WINDOWID=%u", (unsigned int)GDK_WINDOW_XID(gtk_widget_get_window(evbox)));
			SDL_putenv(SDL_windowhack);
        
			// init SDL video
			if (SDL_WasInit(SDL_INIT_VIDEO))
				SDL_QuitSubSystem(SDL_INIT_VIDEO);
			if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 )
			{
				fprintf(stderr, "Couldn't init SDL video: %s\n", SDL_GetError());
				gtk_main_quit();
			}
		}
#endif
        
		s_screen = SDL_SetVideoMode((int)(NWIDTH * s_exs),
								(int)(s_tlines * s_eys),
								desbpp, flags);
		if(!s_screen) {
			FCEUD_PrintError(SDL_GetError());
			return -1;
		}

#ifdef _GTK
		if(noGui == 0)
		{
			GtkRequisition req;
			gtk_widget_size_request(GTK_WIDGET(MainWindow), &req);
			gtk_window_resize(GTK_WINDOW(MainWindow), req.width, req.height);
		 }
#endif
		 }
	s_curbpp = s_screen->format->BitsPerPixel;
	if(!s_screen) {
		FCEUD_PrintError(SDL_GetError());
		KillVideo();
		return -1;
	}

#if 0
	// XXX soules - this would be creating a surface on the video
    //              card, but was commented out for some reason...
    s_BlitBuf = SDL_CreateRGBSurface(SDL_HWSURFACE, 256, 240,
                                     s_screen->format->BitsPerPixel,
                                     s_screen->format->Rmask,
                                     s_screen->format->Gmask,
                                     s_screen->format->Bmask, 0);
#endif

	FCEU_printf(" Video Mode: %d x %d x %d bpp %s\n",
				s_screen->w, s_screen->h, s_screen->format->BitsPerPixel,
				s_fullscreen ? "full screen" : "");

	if(s_curbpp != 8 && s_curbpp != 16 && s_curbpp != 24 && s_curbpp != 32) {
		FCEU_printf("  Sorry, %dbpp modes are not supported by FCE Ultra.  Supported bit depths are 8bpp, 16bpp, and 32bpp.\n", s_curbpp);
		KillVideo();
		return -1;
	}

	// if the game being run has a name, set it as the window name
	if(gi)
	{
		if(gi->name) {
			SDL_WM_SetCaption((const char *)gi->name, (const char *)gi->name);
		} else {
			SDL_WM_SetCaption(FCEU_NAME_AND_VERSION,"FCE Ultra");
		}
	}

	// create the surface for displaying graphical messages
#ifdef LSB_FIRST
	s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
											32, 32, 24, 32 * 3,
											0xFF, 0xFF00, 0xFF0000, 0x00);
#else
	s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
											32, 32, 24, 32 * 3,
											0xFF0000, 0xFF00, 0xFF, 0x00);
#endif
	SDL_WM_SetIcon(s_IconSurface,0);
	s_paletterefresh = 1;

	// XXX soules - can't SDL do this for us?
	 // if using more than 8bpp, initialize the conversion routines
	if(s_curbpp > 8) {
	InitBlitToHigh(s_curbpp >> 3,
						s_screen->format->Rmask,
						s_screen->format->Gmask,
						s_screen->format->Bmask,
						s_eefx, s_sponge, 0);
#ifdef OPENGL
		if(s_useOpenGL) 
		{
			int openGLip;
			g_config->getOption("SDL.OpenGLip", &openGLip);

			if(!InitOpenGL(NOFFSET, 256 - (s_clipSides ? 8 : 0),
						s_srendline, s_erendline + 1,
						s_exs, s_eys, s_eefx,
						openGLip, xstretch, ystretch, s_screen)) 
			{
				FCEUD_PrintError("Error initializing OpenGL.");
				KillVideo();
				return -1;
			}
		}
#endif
	}
Example #13
0
static void ShowDDErr(char *s)
{
	char tempo[512];
	sprintf(tempo,"DirectDraw: %s",s);
	FCEUD_PrintError(tempo);
}
Example #14
0
void NetplayUpdate(uint8 *joyp)
{
 static uint8 buf[5];  /* 4 play states, + command/extra byte */
 static uint8 joypb[4];

 memcpy(joypb,joyp,4);

 /* This shouldn't happen, but just in case.  0xFF is used as a command escape elsewhere. */
 if(joypb[0] == 0xFF)
  joypb[0] = 0xF;
 #ifdef NETWORK
 if(!netdcount)
  if(!FCEUD_SendData(joypb,numlocal))
  {
   NetError();
   return;
  }

 if(!netdcount)
 do
 {
  if(!FCEUD_RecvData(buf,5))
  {
   NetError();
   return;
  }

  switch(buf[4])
  {
   default: FCEU_DoSimpleCommand(buf[4]);break;
   case FCEUNPCMD_TEXT:
           {
      uint8 *tbuf;
      uint32 len = FCEU_de32lsb(buf);

      if(len > 100000)  // Insanity check!
      {
       NetError();
       return;
      }
      tbuf = malloc(len + 1);
      tbuf[len] = 0;
      if(!FCEUD_RecvData(tbuf, len))
      {
       NetError();
       free(tbuf);
       return;
      }
      FCEUD_NetplayText(tbuf);
      free(tbuf);
           }
           break;
   case FCEUNPCMD_SAVESTATE:
          {
             char *fn;
        FILE *fp;

        /* Send the cheats first, then the save state, since
           there might be a frame or two in between the two sendfile
           commands on the server side.
        */
        fn = FCEU_MakeFName(FCEUMKF_CHEAT,0,0);
        //if(!
        FCEUNET_SendFile(FCEUNPCMD_LOADCHEATS,fn);

             // {
             //  free(fn);
             //  return;
             // }
        free(fn);
        if(!FCEUnetplay) return;

        fn = FCEU_MakeFName(FCEUMKF_NPTEMP,0,0);
        fp = fopen(fn, "wb");
        if(FCEUSS_SaveFP(fp))
        {
         fclose(fp);
         if(!FCEUNET_SendFile(FCEUNPCMD_LOADSTATE, fn))
         {
          unlink(fn);
          free(fn);
          return;
         }
         unlink(fn);
         free(fn);
        }
        else
        {
         fclose(fp);
         FCEUD_PrintError("File error.  (K)ill, (M)aim, (D)estroy?  Now!");
         unlink(fn);
         free(fn);
         return;
        }

          }
         break;
   case FCEUNPCMD_LOADCHEATS:
        {
         FILE *fp = FetchFile(FCEU_de32lsb(buf));
         if(!fp) return;
         FCEU_FlushGameCheats(0,1);
         FCEU_LoadGameCheats(fp);
        }
        break;
 case FCEUNPCMD_LOADSTATE:
        {
         FILE *fp = FetchFile(FCEU_de32lsb(buf));
         if(!fp) return;
         if(FCEUSS_LoadFP(fp))
         {
          fclose(fp);
          FCEU_DispMessage("Remote state loaded.");
         } else FCEUD_PrintError("File error.  (K)ill, (M)aim, (D)estroy?");
          }
          break;
  }
 } while(buf[4]);
 #endif

 netdcount=(netdcount+1)%netdivisor;

 memcpy(netjoy,buf,4);
 *(uint32 *)joyp=*(uint32 *)netjoy;
}
Example #15
0
int NSFLoad(const char *name, FCEUFILE *fp)
{
	int x;

	fprintf(stderr,"NSFLoad ...\n");

	FCEU_fseek(fp,0,SEEK_SET);
	FCEU_fread(&NSFHeader,1,0x80,fp);
	if(memcmp(NSFHeader.ID,"NESM\x1a",5))
		return 0;
	NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0;

	LoadAddr=NSFHeader.LoadAddressLow;
	LoadAddr|=NSFHeader.LoadAddressHigh<<8;

	if(LoadAddr<0x6000)
	{
		FCEUD_PrintError("Invalid load address.");
		return(0);
	}
	InitAddr=NSFHeader.InitAddressLow;
	InitAddr|=NSFHeader.InitAddressHigh<<8;

	PlayAddr=NSFHeader.PlayAddressLow;
	PlayAddr|=NSFHeader.PlayAddressHigh<<8;

	NSFSize=FCEU_fgetsize(fp)-0x80;

	NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096);
	NSFMaxBank=PRGsize[0]=uppow2(NSFMaxBank);

	if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096)))
		return 0;

	FCEU_fseek(fp,0x80,SEEK_SET);
	memset(NSFDATA,0x00,NSFMaxBank*4096);
	FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp);

	NSFMaxBank--;

	BSon=0;
	for(x=0;x<8;x++)
	{
		BSon|=NSFHeader.BankSwitch[x];
	}

	if(BSon==0)
	{
		BankCounter=0x00;
   
 		if ((NSFHeader.LoadAddressHigh & 0x70) >= 0x70)
		{
			//Ice Climber, and other F000 base address tunes need this
			BSon=0xFF;
		}
		else {
			for(x=(NSFHeader.LoadAddressHigh & 0x70) / 0x10;x<8;x++)
			{
				NSFHeader.BankSwitch[x]=BankCounter;
				BankCounter+=0x01; 
			}
			BSon=0;
			}
	}

	for(x=0;x<8;x++)
		BSon|=NSFHeader.BankSwitch[x];

	GameInfo->type=GIT_NSF;
	GameInfo->input[0]=GameInfo->input[1]=SI_GAMEPAD;
	GameInfo->cspecial=SIS_NSF;

	for(x=0;;x++)
	{
		if(NSFROM[x]==0x20)
		{
			NSFROM[x+1]=InitAddr&0xFF;
			NSFROM[x+2]=InitAddr>>8;
			NSFROM[x+8]=PlayAddr&0xFF;
			NSFROM[x+9]=PlayAddr>>8;
			break;
		}
	}
Example #16
0
static int avi_open(const char* filename, const BITMAPINFOHEADER* pbmih, const WAVEFORMATEX* pwfex, const struct VideoSystemInfo* vsi)
{
	int error = 1;
	int result = 0;

	do
	{
		// close existing first
		FCEUI_AviEnd();

		if(!truncate_existing(filename))
			break;

		if(!pbmih)
			break;

		// create the object
		avi_create(&avi_file);

		// set video size and framerate
		avi_file->start_scanline = vsi->start_scanline;
		avi_file->end_scanline = vsi->end_scanline;
		//zero 20-oct-2012 - AVIFileClose has bugs in it which cause overflows in the calculation of dwTotalFrames, so some programs are unhappy with the resulting files.
		//so I reduced the precision here by the minimum number of shifts necessary to make it not overflow
		avi_file->fps = vsi->fps >> 3;
		avi_file->fps_scale = (16 * 1024 * 1024) >> 3;
		avi_file->convert_buffer = (uint8*)malloc(VIDEO_WIDTH*(vsi->end_scanline-vsi->start_scanline)*3);

		// open the file
		if(FAILED(AVIFileOpen(&avi_file->avi_file, filename, OF_CREATE | OF_WRITE, NULL)))
			break;

		// create the video stream
		set_video_format(pbmih, avi_file);

		memset(&avi_file->avi_video_header, 0, sizeof(AVISTREAMINFO));
		avi_file->avi_video_header.fccType = streamtypeVIDEO;
		avi_file->avi_video_header.dwScale = avi_file->fps_scale;
		avi_file->avi_video_header.dwRate = avi_file->fps;
		avi_file->avi_video_header.dwSuggestedBufferSize = avi_file->bitmap_format.biSizeImage;
		if(FAILED(AVIFileCreateStream(avi_file->avi_file, &avi_file->streams[VIDEO_STREAM], &avi_file->avi_video_header)))
			break;

		if(use_prev_options)
		{
			avi_file->compress_options[VIDEO_STREAM] = saved_avi_info.compress_options[VIDEO_STREAM];
			avi_file->compress_options_ptr[VIDEO_STREAM] = &avi_file->compress_options[0];
		}
		else
		{
			// get compression options
			memset(&avi_file->compress_options[VIDEO_STREAM], 0, sizeof(AVICOMPRESSOPTIONS));
			avi_file->compress_options_ptr[VIDEO_STREAM] = &avi_file->compress_options[0];
//retryAviSaveOptions: //mbg merge 7/17/06 removed
			error = 0;
			if(!AVISaveOptions(hAppWnd, 0, 1, &avi_file->streams[VIDEO_STREAM], &avi_file->compress_options_ptr[VIDEO_STREAM]))
				break;
			error = 1;
		}

		// create compressed stream
		if(FAILED(AVIMakeCompressedStream(&avi_file->compressed_streams[VIDEO_STREAM], avi_file->streams[VIDEO_STREAM], &avi_file->compress_options[VIDEO_STREAM], NULL)))
			break;

		// set the stream format
		if(FAILED(AVIStreamSetFormat(avi_file->compressed_streams[VIDEO_STREAM], 0, (void*)&avi_file->bitmap_format, avi_file->bitmap_format.biSize)))
			break;

		// add sound (if requested)
		if(pwfex)
		{
			// add audio format
			set_sound_format(pwfex, avi_file);

			// create the audio stream
			memset(&avi_file->avi_sound_header, 0, sizeof(AVISTREAMINFO));
			avi_file->avi_sound_header.fccType = streamtypeAUDIO;
			avi_file->avi_sound_header.dwQuality = (DWORD)-1;
			avi_file->avi_sound_header.dwScale = avi_file->wave_format.nBlockAlign;
			avi_file->avi_sound_header.dwRate = avi_file->wave_format.nAvgBytesPerSec;
			avi_file->avi_sound_header.dwSampleSize = avi_file->wave_format.nBlockAlign;
			avi_file->avi_sound_header.dwInitialFrames = 1;
			if(FAILED(AVIFileCreateStream(avi_file->avi_file, &avi_file->streams[AUDIO_STREAM], &avi_file->avi_sound_header)))
				break;

			// AVISaveOptions doesn't seem to work for audio streams
			// so here we just copy the pointer for the compressed stream
			avi_file->compressed_streams[AUDIO_STREAM] = avi_file->streams[AUDIO_STREAM];

			// set the stream format
			if(FAILED(AVIStreamSetFormat(avi_file->compressed_streams[AUDIO_STREAM], 0, (void*)&avi_file->wave_format, sizeof(WAVEFORMATEX))))
				break;
		}

		// initialize counters
		avi_file->video_frames = 0;
		avi_file->sound_samples = 0;
		avi_file->tBytes = 0;
		avi_file->ByteBuffer = 0;
		avi_file->audio_buffer_pos = 0;

		// success
		error = 0;
		result = 1;
		avi_file->valid = 1;

	} while(0);

	if(!result)
	{
		avi_destroy(&avi_file);
		if(error)
			FCEUD_PrintError("Error writing AVI file");
	}

	return result;
}
Example #17
0
int driver::input::keyboard::Init() {
	if(deviceHandle)
		return(1);

	deviceHandle = directinput::CreateDevice(GUID_SysKeyboard);
	if(deviceHandle == NULL)
	{
		FCEUD_PrintError("DirectInput: Error creating keyboard device.");
		return 0;
	}

	if(!directinput::SetCoopLevel(deviceHandle, GetMainHWND(), (backgroundInputBits!=0)))
	{
		FCEUD_PrintError("DirectInput: Error setting keyboard cooperative level.");
		return 0;
	}
	
	directinput::Acquire(deviceHandle);

	// any key with scancode not in this list will be ignored
	validKeyMask[DIK_ESCAPE] = 1;
	validKeyMask[DIK_1] = 1;
	validKeyMask[DIK_2] = 1;
	validKeyMask[DIK_3] = 1;
	validKeyMask[DIK_4] = 1;
	validKeyMask[DIK_5] = 1;
	validKeyMask[DIK_6] = 1;
	validKeyMask[DIK_7] = 1;
	validKeyMask[DIK_8] = 1;
	validKeyMask[DIK_9] = 1;
	validKeyMask[DIK_0] = 1;
	validKeyMask[DIK_MINUS] = 1;
	validKeyMask[DIK_EQUALS] = 1;
	validKeyMask[DIK_BACK] = 1;
	validKeyMask[DIK_TAB] = 1;
	validKeyMask[DIK_Q] = 1;
	validKeyMask[DIK_W] = 1;
	validKeyMask[DIK_E] = 1;
	validKeyMask[DIK_R] = 1;
	validKeyMask[DIK_T] = 1;
	validKeyMask[DIK_Y] = 1;
	validKeyMask[DIK_U] = 1;
	validKeyMask[DIK_I] = 1;
	validKeyMask[DIK_O] = 1;
	validKeyMask[DIK_P] = 1;
	validKeyMask[DIK_LBRACKET] = 1;
	validKeyMask[DIK_RBRACKET] = 1;
	validKeyMask[DIK_RETURN] = 1;
	validKeyMask[DIK_LCONTROL] = 1;
	validKeyMask[DIK_A] = 1;
	validKeyMask[DIK_S] = 1;
	validKeyMask[DIK_D] = 1;
	validKeyMask[DIK_F] = 1;
	validKeyMask[DIK_G] = 1;
	validKeyMask[DIK_H] = 1;
	validKeyMask[DIK_J] = 1;
	validKeyMask[DIK_K] = 1;
	validKeyMask[DIK_L] = 1;
	validKeyMask[DIK_SEMICOLON] = 1;
	validKeyMask[DIK_APOSTROPHE] = 1;
	validKeyMask[DIK_GRAVE] = 1;
	validKeyMask[DIK_LSHIFT] = 1;
	validKeyMask[DIK_BACKSLASH] = 1;
	validKeyMask[DIK_Z] = 1;
	validKeyMask[DIK_X] = 1;
	validKeyMask[DIK_C] = 1;
	validKeyMask[DIK_V] = 1;
	validKeyMask[DIK_B] = 1;
	validKeyMask[DIK_N] = 1;
	validKeyMask[DIK_M] = 1;
	validKeyMask[DIK_COMMA] = 1;
	validKeyMask[DIK_PERIOD] = 1;
	validKeyMask[DIK_SLASH] = 1;
	validKeyMask[DIK_RSHIFT] = 1;
	validKeyMask[DIK_MULTIPLY] = 1;
	validKeyMask[DIK_LMENU] = 1;
	validKeyMask[DIK_SPACE] = 1;
	validKeyMask[DIK_CAPITAL] = 1;
	validKeyMask[DIK_F1] = 1;
	validKeyMask[DIK_F2] = 1;
	validKeyMask[DIK_F3] = 1;
	validKeyMask[DIK_F4] = 1;
	validKeyMask[DIK_F5] = 1;
	validKeyMask[DIK_F6] = 1;
	validKeyMask[DIK_F7] = 1;
	validKeyMask[DIK_F8] = 1;
	validKeyMask[DIK_F9] = 1;
	validKeyMask[DIK_F10] = 1;
	validKeyMask[DIK_NUMLOCK] = 1;
	validKeyMask[DIK_SCROLL] = 1;
	validKeyMask[DIK_NUMPAD7] = 1;
	validKeyMask[DIK_NUMPAD8] = 1;
	validKeyMask[DIK_NUMPAD9] = 1;
	validKeyMask[DIK_SUBTRACT] = 1;
	validKeyMask[DIK_NUMPAD4] = 1;
	validKeyMask[DIK_NUMPAD5] = 1;
	validKeyMask[DIK_NUMPAD6] = 1;
	validKeyMask[DIK_ADD] = 1;
	validKeyMask[DIK_NUMPAD1] = 1;
	validKeyMask[DIK_NUMPAD2] = 1;
	validKeyMask[DIK_NUMPAD3] = 1;
	validKeyMask[DIK_NUMPAD0] = 1;
	validKeyMask[DIK_DECIMAL] = 1;
	validKeyMask[DIK_OEM_102] = 1;
	validKeyMask[DIK_F11] = 1;
	validKeyMask[DIK_F12] = 1;
	validKeyMask[DIK_F13] = 1;
	validKeyMask[DIK_F14] = 1;
	validKeyMask[DIK_F15] = 1;
	validKeyMask[DIK_KANA] = 1;
	validKeyMask[DIK_ABNT_C1] = 1;
	validKeyMask[DIK_CONVERT] = 1;
	validKeyMask[DIK_NOCONVERT] = 1;
	validKeyMask[DIK_YEN] = 1;
	validKeyMask[DIK_ABNT_C2] = 1;
	validKeyMask[DIK_NUMPADEQUALS] = 1;
	validKeyMask[DIK_PREVTRACK] = 1;
	validKeyMask[DIK_AT] = 1;
	validKeyMask[DIK_COLON] = 1;
	validKeyMask[DIK_UNDERLINE] = 1;
	validKeyMask[DIK_KANJI] = 1;
	validKeyMask[DIK_STOP] = 1;
	validKeyMask[DIK_AX] = 1;
	validKeyMask[DIK_UNLABELED] = 1;
	validKeyMask[DIK_NEXTTRACK] = 1;
	validKeyMask[DIK_NUMPADENTER] = 1;
	validKeyMask[DIK_RCONTROL] = 1;
	validKeyMask[DIK_MUTE] = 1;
	validKeyMask[DIK_CALCULATOR] = 1;
	validKeyMask[DIK_PLAYPAUSE] = 1;
	validKeyMask[DIK_MEDIASTOP] = 1;
	validKeyMask[DIK_VOLUMEDOWN] = 1;
	validKeyMask[DIK_VOLUMEUP] = 1;
	validKeyMask[DIK_WEBHOME] = 1;
	validKeyMask[DIK_NUMPADCOMMA] = 1;
	validKeyMask[DIK_DIVIDE] = 1;
	validKeyMask[DIK_SYSRQ] = 1;
	validKeyMask[DIK_RMENU] = 1;
	validKeyMask[DIK_PAUSE] = 1;
	validKeyMask[DIK_HOME] = 1;
	validKeyMask[DIK_UP] = 1;
	validKeyMask[DIK_PRIOR] = 1;
	validKeyMask[DIK_LEFT] = 1;
	validKeyMask[DIK_RIGHT] = 1;
	validKeyMask[DIK_END] = 1;
	validKeyMask[DIK_DOWN] = 1;
	validKeyMask[DIK_NEXT] = 1;
	validKeyMask[DIK_INSERT] = 1;
	validKeyMask[DIK_DELETE] = 1;
	validKeyMask[DIK_LWIN] = 1;
	validKeyMask[DIK_RWIN] = 1;
	validKeyMask[DIK_APPS] = 1;
	validKeyMask[DIK_POWER] = 1;
	validKeyMask[DIK_SLEEP] = 1;
	validKeyMask[DIK_WAKE] = 1;
	validKeyMask[DIK_WEBSEARCH] = 1;
	validKeyMask[DIK_WEBFAVORITES] = 1;
	validKeyMask[DIK_WEBREFRESH] = 1;
	validKeyMask[DIK_WEBSTOP] = 1;
	validKeyMask[DIK_WEBFORWARD] = 1;
	validKeyMask[DIK_WEBBACK] = 1;
	validKeyMask[DIK_MYCOMPUTER] = 1;
	validKeyMask[DIK_MAIL] = 1;
	validKeyMask[DIK_MEDIASELECT] = 1;

	return 1;
}
Example #18
0
int InitVideo(FCEUGI *gi)
{
	// This is a big TODO.  Stubbing this off into its own function,
	// as the SDL surface routines have changed drastically in SDL2
	// TODO - SDL2
	const char * window_name;
	int error, flags = 0;
	int doublebuf, xstretch, ystretch, xres, yres, show_fps;
	uint32_t  Amask, Rmask, Gmask, Bmask;
	int   bpp;

	FCEUI_printf("Initializing video (SDL2.x) ...");

	// load the relevant configuration variables
	g_config->getOption("SDL.Fullscreen", &s_fullscreen);
	g_config->getOption("SDL.DoubleBuffering", &doublebuf);
#ifdef OPENGL
	g_config->getOption("SDL.OpenGL", &s_useOpenGL);
#endif
	g_config->getOption("SDL.SpecialFilter", &s_sponge);
	g_config->getOption("SDL.XStretch", &xstretch);
	g_config->getOption("SDL.YStretch", &ystretch);
	g_config->getOption("SDL.LastXRes", &xres);
	g_config->getOption("SDL.LastYRes", &yres);
	g_config->getOption("SDL.ClipSides", &s_clipSides);
	g_config->getOption("SDL.NoFrame", &noframe);
	g_config->getOption("SDL.ShowFPS", &show_fps);

	// check the starting, ending, and total scan lines
	FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline);
	s_tlines = s_erendline - s_srendline + 1;

#if OPENGL
	if( !s_useOpenGL || s_sponge )
	{
		FCEUD_PrintError("SDL2 Does not support non-OpenGL rendering or special filters\n");
		KillVideo();
		return -1;
	}
#endif

	// initialize the SDL video subsystem if it is not already active
	if(!SDL_WasInit(SDL_INIT_VIDEO)) {
		error = SDL_InitSubSystem(SDL_INIT_VIDEO);
		if(error) {
			FCEUD_PrintError(SDL_GetError());
			return -1;
		}
	}
	s_inited = 1;

	// For simplicity, hard-code this to 32bpp for now...
	s_curbpp = 32;

	// If game is running, set window name accordingly
	if( gi )
	{
		window_name = (const char *) gi->name;
	}
	else
	{
		window_name = "FCE Ultra";
	}

	s_exs = 1.0;
	s_eys = 1.0;
	if(s_fullscreen) {
		s_window = SDL_CreateWindow( window_name,
		                             SDL_WINDOWPOS_UNDEFINED,
		                             SDL_WINDOWPOS_UNDEFINED,
		                             0, 0,  // Res not specified in full-screen mode
		                             SDL_WINDOW_FULLSCREEN_DESKTOP);
	} else {
#if defined(_GTK) && defined(SDL_VIDEO_DRIVER_X11)
		if(noGui == 0 && strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
			s_window = SDL_CreateWindowFrom((void*)GDK_WINDOW_XID (gtk_widget_get_window(evbox)));
		}
		else
#endif
			s_window = SDL_CreateWindow( window_name,
				                         SDL_WINDOWPOS_UNDEFINED,
				                         SDL_WINDOWPOS_UNDEFINED,
				                         xres, yres,
				                         0);
	}

	// This stuff all applies regardless of full-screen vs windowed mode.
	s_renderer =  SDL_CreateRenderer(s_window, -1, 0);

	// Set logical rendering size & specify scaling mode.  All rendering is
	// now done to the renderer rather than directly to the screen surface.
	// The renderer takes care of any scaling necessary.
	//
	// NOTE: setting scale quality to "nearest" will result in a blown-up but
	// pixelated while "linear" will tend to blur everything.
	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
	SDL_RenderSetLogicalSize(s_renderer, xres, yres);


	//
	// Create the texture that will ultimately be rendered.
	// s_screen is used to build up an image, then the texture will be updated
	// all at once when it's ready
	s_texture = SDL_CreateTexture(s_renderer,
	                              SDL_PIXELFORMAT_ARGB8888,
	                              SDL_TEXTUREACCESS_STREAMING,
	                              xres, yres);
	//
	// Create a surface to draw pixels onto
	//
	SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ARGB8888, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
	s_screen = SDL_CreateRGBSurface(0, xres, yres, bpp,
	                                Rmask, Gmask, Bmask, Amask);

	if( !s_screen )
	{
		FCEUD_PrintError(SDL_GetError());
		return -1;
	}

	//
	// Setup Icon surface
	//
#ifdef LSB_FIRST
	s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
	                32, 32, 24, 32 * 3,
	                0xFF, 0xFF00, 0xFF0000, 0x00);
#else
	s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
	                32, 32, 24, 32 * 3,
	                0xFF0000, 0xFF00, 0xFF, 0x00);
#endif

	SDL_SetWindowIcon(s_window, s_IconSurface);

	s_paletterefresh = 1;   // Force palette refresh

	// always init blit to high since bpp forced to 32 for now.
	InitBlitToHigh(s_curbpp >> 3,
	               s_screen->format->Rmask,
	               s_screen->format->Gmask,
	               s_screen->format->Bmask,
	               0, //s_eefx,  Hard-code SFX off
	               0, //s_sponge,  Hard-code special filters off.
	               0);

	return 0;
}