Esempio n. 1
0
/* Handle * and / operators */
Condition* Term(const char** str)
{
	Condition* t;
	Condition* t1;
	Condition* mid;

    t = (Condition*)FCEU_dmalloc(sizeof(Condition));
    if (!t)
        return NULL;

	memset(t, 0, sizeof(Condition));

	if (!Primitive(str, t))
	{
		freeTree(t);
		return 0;
	}

	while (next == '*' || next == '/')
	{
		int op = next == '*' ? OP_MULT : OP_DIV;

		scan(str);

		if (!(t1 = (Condition*)FCEU_dmalloc(sizeof(Condition))))
            return NULL;

		memset(t1, 0, sizeof(Condition));

		if (!Primitive(str, t1))
		{
			freeTree(t);
			freeTree(t1);
			return 0;
		}

		if (!(mid = (Condition*)FCEU_dmalloc(sizeof(Condition))))
            return NULL;

		memset(mid, 0, sizeof(Condition));

		mid->lhs = t;
		mid->rhs = t1;
		mid->op = op;

		t = mid;
	}

	return t;
}
Esempio n. 2
0
// Generic function to handle all infix operators but the last one in the precedence hierarchy. : '(' E ')'
Condition* InfixOperator(const char** str, Condition(*nextPart(const char**)), int(*operators)(const char**))
{
	Condition* t = nextPart(str);
	Condition* t1;
	Condition* mid;
	int op;

	while ((op = operators(str)))
	{
		scan(str);

		t1 = nextPart(str);

		if (t1 == 0)
		{
			if(t)
				freeTree(t);
			return 0;
		}

		mid = (Condition*)FCEU_dmalloc(sizeof(Condition));
		if (!mid)
			return NULL;
		memset(mid, 0, sizeof(Condition));

		mid->lhs = t;
		mid->rhs = t1;
		mid->op = op;

		t = mid;
	}

	return t;
}
Esempio n. 3
0
static FILE *FetchFile(uint32 remlen)
{
	uint32 clen = remlen;
	char *cbuf;
	uLongf len;
	char *buf;
	FILE *fp;

	if(clen > 500000)  // Sanity check
	{
		NetError();
		return(0);
	}

	//printf("Receiving file: %d...\n",clen);
	if((fp = tmpfile()))
	{
		cbuf = (char *)FCEU_dmalloc(clen); //mbg merge 7/17/06 added cast
		if(!FCEUD_RecvData(cbuf, clen))
		{
			NetError();
			fclose(fp);
			free(cbuf);
			return(0);
		}

		len = FCEU_de32lsb((uint8*)cbuf); //mbg merge 7/17/06 added cast
		if(len > 500000)    // Another sanity check
		{
			NetError();
			fclose(fp);
			free(cbuf);
			return(0);
		}
		buf = (char *)FCEU_dmalloc(len); //mbg merge 7/17/06 added cast
		uncompress((uint8*)buf, &len, (uint8*)cbuf + 4, clen - 4); //mbg merge 7/17/06 added casts

		fwrite(buf, 1, len, fp);
		free(buf);
		fseek(fp, 0, SEEK_SET);
		return(fp);
	}
	return(0);
}
Esempio n. 4
0
int FCEUNET_SendFile(uint8 cmd, char *fn)
{
	uint32 len;
	uLongf clen;
	char *buf, *cbuf;
	FILE *fp;
	struct stat sb;

	if(!(fp=FCEUD_UTF8fopen(fn,"rb"))) return(0);

	FCEUX_fstat(fileno(fp),&sb);
	len = sb.st_size;
	buf = (char*)FCEU_dmalloc(len); //mbg merge 7/17/06 added cast
	fread(buf, 1, len, fp);
	fclose(fp);

	cbuf = (char*)FCEU_dmalloc(4 + len + len / 1000 + 12); //mbg merge 7/17/06 added cast
	FCEU_en32lsb((uint8*)cbuf, len); //mbg merge 7/17/06 added cast
	compress2((uint8*)cbuf + 4, &clen, (uint8*)buf, len, 7); //mbg merge 7/17/06 added casts
	free(buf);

	//printf("Sending file: %s, %d, %d\n",fn,len,clen);

	len = clen + 4;

	if(!FCEUNET_SendCommand(cmd,len))
	{
		free(cbuf);
		return(0);
	}
	if(!FCEUD_SendData(cbuf, len))
	{
		NetError();
		free(cbuf);
		return(0);
	}
	free(cbuf);

	return(1);
}
Esempio n. 5
0
void
FCEUD_NetplayText(uint8 *text)
{
    char *tot = (char *)FCEU_dmalloc(strlen((const char *)text) + 1);
    char *tmp;
    if (!tot)
        return;
    strcpy(tot, (const char *)text);
    tmp = tot;

    while(*tmp) {
        if(*tmp < 0x20) {
            *tmp = ' ';
        }
        tmp++;
    }
    puts(tot);
    FCEU_dfree(tot);
}
Esempio n. 6
0
// returns a string suitable for use in an aboutbox
char *FCEUI_GetAboutString() {
	const char *aboutTemplate =
		FCEU_NAME_AND_VERSION "\n\n"
		"Administrators:\n"
		"zeromus, adelikat, AnS\n\n"
		"Current Contributors:\n"
		"punkrockguy318 (Lukas Sabota)\n"
		"Plombo (Bryan Cain)\n"
		"qeed, QFox, Shinydoofy, ugetab\n"
		"CaH4e3, gocha, Acmlm, DWEdit\n"
		"\n"
		"FCEUX 2.0:\n"
		"mz, nitsujrehtona, Lukas Sabota,\n"
		"SP, Ugly Joe\n"
		"\n"
		"Previous versions:\n"
		"FCE - Bero\n"
		"FCEU - Xodnizel\n"
		"FCEU XD - Bbitmaster & Parasyte\n"
		"FCEU XD SP - Sebastian Porst\n"
		"FCEU MM - CaH4e3\n"
		"FCEU TAS - blip & nitsuja\n"
		"FCEU TAS+ - Luke Gustafson\n"
		"\n"
		"FCEUX is dedicated to the fallen heroes\n"
		"of NES emulation. In Memoriam --\n"
		"ugetab\n"
		"\n"
		__TIME__ " " __DATE__ "\n";

	if(aboutString) return aboutString;

	const char *compilerString = FCEUD_GetCompilerString();

	//allocate the string and concatenate the template with the compiler string
	if (!(aboutString = (char*)FCEU_dmalloc(strlen(aboutTemplate) + strlen(compilerString) + 1)))
        return NULL;

    sprintf(aboutString,"%s%s",aboutTemplate,compilerString);
	return aboutString;
}
Esempio n. 7
0
int
FCEUD_NetworkConnect(void)
{
    struct sockaddr_in sockin;
    struct hostent *phostentb;
    unsigned long hadr;
    int TSocket, tcpopt, error;
    int netdivisor;

    // get any required configuration variables
    int port, localPlayers;
    std::string server, username, password, key;
    g_config->getOption("SDL.NetworkIP", &server);
    g_config->getOption("SDL.NetworkUsername", &username);
    g_config->getOption("SDL.NetworkPassword", &password);
    g_config->getOption("SDL.NetworkGameKey", &key);
    g_config->getOption("SDL.NetworkPort", &port);
    g_config->getOption("SDL.NetworkPlayers", &localPlayers);
    
    
    g_config->setOption("SDL.NetworkIP", "");
    g_config->setOption("SDL.NetworkPassword", "");
    g_config->setOption("SDL.NetworkGameKey", "");
    


    // only initialize if remote server is specified
    if(!server.size()) {
        return 0;
    }

    TSocket = socket(AF_INET, SOCK_STREAM, 0);
    if(TSocket < 0) {
		char* s = "Error creating stream socket.";
        puts(s);
        FCEU_DispMessage(s,0);
        FCEUD_NetworkClose();
        return 0;
    }

    // try to setup TCP_NODELAY to avoid network jitters
    tcpopt = 1;
#ifdef BEOS
    error = setsockopt(TSocket, SOL_SOCKET, TCP_NODELAY, &tcpopt, sizeof(int));
#elif WIN32
    error = setsockopt(TSocket, SOL_TCP, TCP_NODELAY,
                       (char*)&tcpopt, sizeof(int));
#else
    error = setsockopt(TSocket, SOL_TCP, TCP_NODELAY, &tcpopt, sizeof(int));
#endif
    if(error) {
        puts("Nodelay fail");
    }

    memset(&sockin, 0, sizeof(sockin));
    sockin.sin_family = AF_INET;
    hadr = inet_addr(server.c_str());
    if(hadr != INADDR_NONE) {
        sockin.sin_addr.s_addr = hadr;
    } else {
        puts("*** Looking up host name...");
        phostentb = gethostbyname(server.c_str());
        if(!phostentb) {
            puts("Error getting host network information.");
            FCEU_DispMessage("Error getting host info",0);
            close(TSocket);
            FCEUD_NetworkClose();
            return(0);
        }
        memcpy(&sockin.sin_addr, phostentb->h_addr, phostentb->h_length);
    }

    sockin.sin_port = htons(port);
    puts("*** Connecting to remote host...");
    error = connect(TSocket, (struct sockaddr *)&sockin, sizeof(sockin));
    if(error < 0) {
        puts("Error connecting to remote host.");
        FCEU_DispMessage("Error connecting to server",0);
        close(TSocket);
        FCEUD_NetworkClose();
        return 0;
    }

    s_Socket = TSocket;

    puts("*** Sending initialization data to server...");
    uint8 *sendbuf;
    uint8 buf[5];
    uint32 sblen;

    sblen = 4 + 16 + 16 + 64 + 1 + username.size();
    sendbuf = (uint8 *)FCEU_dmalloc(sblen);
    memset(sendbuf, 0, sblen);

    // XXX soules - should use htons instead of en32() from above!
    //uint32 data = htons(sblen - 4);
    //memcpy(sendbuf, &data, sizeof(data));
    en32(sendbuf, sblen - 4);

    if(key.size()) {
        struct md5_context md5;
        uint8 md5out[16];

        md5_starts(&md5);
        md5_update(&md5, (uint8*)&GameInfo->MD5.data, 16);
        md5_update(&md5, (uint8 *)key.c_str(), key.size());
        md5_finish(&md5, md5out);
        memcpy(sendbuf + 4, md5out, 16);
    } else {
        memcpy(sendbuf + 4, (uint8*)&GameInfo->MD5.data, 16);
    }

    if(password.size()) {
        struct md5_context md5;
        uint8 md5out[16];

        md5_starts(&md5);
        md5_update(&md5, (uint8 *)password.c_str(), password.size());
        md5_finish(&md5, md5out);
        memcpy(sendbuf + 4 + 16, md5out, 16);
    }

    memset(sendbuf + 4 + 16 + 16, 0, 64);

    sendbuf[4 + 16 + 16 + 64] = (uint8)localPlayers;

    if(username.size()) {
        memcpy(sendbuf + 4 + 16 + 16 + 64 + 1,
               username.c_str(), username.size());
    }

#ifdef WIN32
    send(s_Socket, (char*)sendbuf, sblen, 0);
#else
    send(s_Socket, sendbuf, sblen, 0);
#endif
    FCEU_dfree(sendbuf);

#ifdef WIN32
    recv(s_Socket, (char*)buf, 1, 0);
#else
    recv(s_Socket, buf, 1, MSG_WAITALL);
#endif
    netdivisor = buf[0];

    puts("*** Connection established.");
    FCEU_DispMessage("Connection established.",0);

    FCEUDnetplay = 1;
    FCEUI_NetplayStart(localPlayers, netdivisor);

    return 1;
}
Esempio n. 8
0
/**
 * Initialize the audio subsystem.
 */
int
InitSound()
{
	int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq;
	SDL_AudioSpec spec;

	g_config->getOption("SDL.Sound", &sound);
	if(!sound) {
		return 0;
	}

	memset(&spec, 0, sizeof(spec));
	if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
		puts(SDL_GetError());
		KillSound();
		return 0;
	}
	char driverName[8];
#if SDL_VERSION_ATLEAST(2, 0, 0)
	// TODO - SDL 2
#else
	SDL_AudioDriverName(driverName, 8);
	fprintf(stderr, "Loading SDL sound with %s driver...\n", driverName);
#endif

	// load configuration variables
	g_config->getOption("SDL.Sound.Rate", &soundrate);
	g_config->getOption("SDL.Sound.BufSize", &soundbufsize);
	g_config->getOption("SDL.Sound.Volume", &soundvolume);
	g_config->getOption("SDL.Sound.Quality", &soundq);
	g_config->getOption("SDL.Sound.TriangleVolume", &soundtrianglevolume);
	g_config->getOption("SDL.Sound.Square1Volume", &soundsquare1volume);
	g_config->getOption("SDL.Sound.Square2Volume", &soundsquare2volume);
	g_config->getOption("SDL.Sound.NoiseVolume", &soundnoisevolume);
	g_config->getOption("SDL.Sound.PCMVolume", &soundpcmvolume);

	spec.freq = soundrate;
	spec.format = AUDIO_S16SYS;
	spec.channels = 1;
	spec.samples = 512;
	spec.callback = fillaudio;
	spec.userdata = 0;

	s_BufferSize = soundbufsize * soundrate / 1000;

	// For safety, set a bare minimum:
	if (s_BufferSize < spec.samples * 2)
	s_BufferSize = spec.samples * 2;

	s_Buffer = (int *)FCEU_dmalloc(sizeof(int) * s_BufferSize);
	if (!s_Buffer)
		return 0;
	s_BufferRead = s_BufferWrite = s_BufferIn = 0;

	if(SDL_OpenAudio(&spec, 0) < 0)
	{
		puts(SDL_GetError());
		KillSound();
		return 0;
    }
	SDL_PauseAudio(0);

	FCEUI_SetSoundVolume(soundvolume);
	FCEUI_SetSoundQuality(soundq);
	FCEUI_Sound(soundrate);
	FCEUI_SetTriangleVolume(soundtrianglevolume);
	FCEUI_SetSquare1Volume(soundsquare1volume);
	FCEUI_SetSquare2Volume(soundsquare2volume);
	FCEUI_SetNoiseVolume(soundnoisevolume);
	FCEUI_SetPCMVolume(soundpcmvolume);
	return 1;
}
Esempio n. 9
0
int InitBlitToHigh(int b, uint32 rmask, uint32 gmask, uint32 bmask, int efx, int specfilt, int specfilteropt)
{

 // -Video Modes Tag-
 if(specfilt == 3) // NTSC 2x
 {
  int multi = (2 * 2);

  //nes_ntsc variables
  nes_ntsc_setup_t ntsc_setup = nes_ntsc_composite;
  
  switch (specfilteropt)
  {
  //case 0: // Composite
  //ntsc_setup = nes_ntsc_composite;
  //break;
  case 1: //S-Video
  ntsc_setup = nes_ntsc_svideo;
  break;
  case 2: //RGB
  ntsc_setup = nes_ntsc_rgb;
  break;
  case 3: //Monochrome
  ntsc_setup = nes_ntsc_monochrome;
  break;

  }

  nes_ntsc = (nes_ntsc_t*) FCEU_dmalloc( sizeof (nes_ntsc_t) );

  if ( nes_ntsc ) {
  nes_ntsc_init( nes_ntsc, &ntsc_setup, b, 2 );

  ntscblit = (uint8*)FCEU_dmalloc(256*257*b*multi); //Need to add multiplier for larger sizes
  }

 } // -Video Modes Tag-
 else if(specfilt == 2 || specfilt == 5) // scale2x and scale3x
 {
  int multi = ((specfilt == 2) ? 2 * 2 : 3 * 3);

  specbuf8bpp = (uint8*)FCEU_dmalloc(256*240*multi); //mbg merge 7/17/06 added cast

 } // -Video Modes Tag-
 else if(specfilt == 1 || specfilt == 4) // hq2x and hq3x
 { 
  if(b == 1) 
   return(0);

  if(b == 2 || b == 3)          // 8->16->(hq2x)->32-> 24 or 16.  YARGH.
  {
   uint32 tmpCBM[3];
   backBpp = b;
   tmpCBM[0]=rmask;
   tmpCBM[1]=gmask;
   tmpCBM[2]=bmask;

   CalculateShift(tmpCBM, backshiftr, backshiftl);

   if(b == 2)
   {
    // ark
    backshiftr[0] += 16;
    backshiftr[1] += 8;
    backshiftr[2] += 0;

    // Begin iffy code(requires 16bpp and 32bpp to have same RGB order)
    //backmask[0] = (rmask>>backshiftl[0]) << (backshiftr[0]);
    //backmask[1] = (gmask>>backshiftl[1]) << (backshiftr[1]);
    //backmask[2] = (bmask>>backshiftl[2]) << (backshiftr[2]);

    //int x;
    //for(x=0;x<3;x++) 
    // backshiftr[x] -= backshiftl[x];
    // End iffy code
   }
   // -Video Modes Tag-
   if(specfilt == 1) specbuf32bpp = (uint32*)FCEU_dmalloc(256*240*4*sizeof(uint32)); //mbg merge 7/17/06 added cast
   else if(specfilt == 4) specbuf32bpp = (uint32*)FCEU_dmalloc(256*240*9*sizeof(uint32)); //mbg merge 7/17/06 added cast
  }

  efx=0;
  b=2;
  rmask=0x1F<<11;
  gmask=0x3F<<5;
  bmask=0x1F;

  // -Video Modes Tag-
  if(specfilt == 4)
   hq3x_InitLUTs();
  else
   hq2x_InitLUTs();

  specbuf=(uint16*)FCEU_dmalloc(256*240*sizeof(uint16)); //mbg merge 7/17/06 added cast
 }

 silt = specfilt;

 Bpp=b;

 highefx=efx;

 if(Bpp<=1 || Bpp>4)
  return(0);

 if(efx&FVB_BLUR)
 {
  if(Bpp==2)
   palettetranslate=(uint32 *)FCEU_dmalloc(65536*4);
  else if(Bpp>=3)
   palettetranslate=(uint32 *)FCEU_dmalloc(65536*4);
 }
 else
 {
  if(Bpp==2)
   palettetranslate=(uint32*)FCEU_dmalloc(65536*4);
  else if(Bpp>=3)
   palettetranslate=(uint32*)FCEU_dmalloc(256*4);
 }

 if(!palettetranslate)
  return(0);


 CBM[0]=rmask;
 CBM[1]=gmask;
 CBM[2]=bmask;
 return(1);
}