Cleaned up some code.

This commit is contained in:
rheiny 2007-02-05 20:41:23 +00:00
parent 54ff3f3b9d
commit be3ec4a072
12 changed files with 404 additions and 217 deletions

View File

@ -50,103 +50,149 @@ static int FReadString(FILE *fp, char *str, int n)
static void GetValueR(FILE *fp, char *str, void *v, int c) static void GetValueR(FILE *fp, char *str, void *v, int c)
{ {
char buf[256]; char buf[256];
int s; int s;
while(FReadString(fp,buf,256)) while(FReadString(fp,buf,256))
{ {
fread(&s,1,4,fp); fread(&s,1,4,fp);
if(!strcmp(str, buf))
{ if(!strcmp(str, buf))
if(!c) // String, allocate some memory. {
{ if(!c) // String, allocate some memory.
if(!(*(char **)v=(char*)malloc(s))) {
goto gogl; if(!(*(char **)v=(char*)malloc(s)))
fread(*(char **)v,1,s,fp); goto gogl;
continue;
} fread(*(char **)v,1,s,fp);
else if(s>c || s<c) continue;
{ }
gogl: else if(s>c || s<c)
fseek(fp,s,SEEK_CUR); {
continue; gogl:
} fseek(fp,s,SEEK_CUR);
fread((uint8*)v,1,c,fp); continue;
} }
else
fseek(fp,s,SEEK_CUR); fread((uint8*)v,1,c,fp);
} }
fseek(fp,4,SEEK_SET); else
{
fseek(fp,s,SEEK_CUR);
}
}
fseek(fp,4,SEEK_SET);
} }
static void SetValueR(FILE *fp, char *str, void *v, int c) void SetValueR(FILE *fp, const char *str, void *v, int c)
{ {
fwrite(str,1,strlen(str)+1,fp); fwrite(str,1,strlen(str)+1,fp);
fwrite((uint8*)&c,1,4,fp); fwrite((uint8*)&c,1,4,fp);
fwrite((uint8*)v,1,c,fp); fwrite((uint8*)v,1,c,fp);
} }
static void SaveParse(CFGSTRUCT *cfgst, FILE *fp) /**
{ * Parses a configuration structure and saves information from the structure into a file.
int x=0; *
* @param cfgst The configuration structure.
while(cfgst[x].ptr) * @param fp File handle.
{ **/
if(!cfgst[x].name) // Link to new config structure void SaveParse(const CFGSTRUCT *cfgst, FILE *fp)
{
SaveParse((CFGSTRUCT*)cfgst[x].ptr,fp); // Recursion is sexy. I could
// save a little stack space if I made
// the file pointer a non-local
// variable...
x++;
continue;
}
if(cfgst[x].len) // Plain data
SetValueR(fp,cfgst[x].name,cfgst[x].ptr,cfgst[x].len);
else // String
if(*(char **)cfgst[x].ptr) // Only save it if there IS a string.
SetValueR(fp,cfgst[x].name,*(char **)cfgst[x].ptr,
strlen(*(char **)cfgst[x].ptr)+1);
x++;
}
}
void SaveFCEUConfig(char *filename, CFGSTRUCT *cfgst)
{
FILE *fp;
fp=fopen(filename,"wb");
if(fp==NULL) return;
SaveParse(cfgst,fp);
fclose(fp);
}
static void LoadParse(CFGSTRUCT *cfgst, FILE *fp)
{ {
int x=0; int x=0;
while(cfgst[x].ptr) while(cfgst[x].ptr)
{ {
if(!cfgst[x].name) // Link to new config structure
{ if(!cfgst[x].name) // Link to new config structure
LoadParse((CFGSTRUCT*)cfgst[x].ptr,fp); {
x++; SaveParse((CFGSTRUCT*)cfgst[x].ptr, fp); // Recursion is sexy. I could
continue; // save a little stack space if I made
} // the file pointer a non-local
GetValueR(fp,cfgst[x].name,cfgst[x].ptr,cfgst[x].len); // variable...
x++; x++;
} continue;
}
if(cfgst[x].len)
{
// Plain data
SetValueR(fp,cfgst[x].name,cfgst[x].ptr,cfgst[x].len);
}
else
{
// String
if(*(char **)cfgst[x].ptr)
{
// Only save it if there IS a string.
SetValueR(fp,cfgst[x].name,*(char **)cfgst[x].ptr, strlen(*(char **)cfgst[x].ptr)+1);
}
}
x++;
}
} }
void LoadFCEUConfig(char *filename, CFGSTRUCT *cfgst) /**
* Stores information from a configuration struct into a configuration file.
*
* @param filename Name of the configuration file
* @param cfgst The configuration struct
**/
void SaveFCEUConfig(const char *filename, const CFGSTRUCT *cfgst)
{ {
FILE *fp; FILE *fp = fopen(filename,"wb");
fp=fopen(filename,"rb"); if(fp==NULL)
if(fp==NULL) return; {
LoadParse(cfgst,fp); return;
fclose(fp); }
SaveParse(cfgst, fp);
fclose(fp);
}
/**
* Parses information from a file into a configuration structure.
*
* @param cfgst The configuration structure.
* @param fp File handle.
**/
void LoadParse(CFGSTRUCT *cfgst, FILE *fp)
{
int x = 0;
while(cfgst[x].ptr)
{
if(!cfgst[x].name) // Link to new config structure
{
LoadParse((CFGSTRUCT*)cfgst[x].ptr, fp);
x++;
continue;
}
GetValueR(fp, cfgst[x].name, cfgst[x].ptr, cfgst[x].len);
x++;
}
}
/**
* Loads config information from the config file.
*
* @param filename Name of the config file.
**/
void LoadFCEUConfig(const char *filename, CFGSTRUCT *cfgst)
{
FILE *fp = fopen(filename,"rb");
if(fp==NULL)
{
return;
}
LoadParse(cfgst, fp);
fclose(fp);
} }

View File

@ -5,8 +5,8 @@ typedef struct {
int len; int len;
} CFGSTRUCT; } CFGSTRUCT;
void SaveFCEUConfig(char *filename, CFGSTRUCT *cfgst); void SaveFCEUConfig(const char *filename, const CFGSTRUCT *cfgst);
void LoadFCEUConfig(char *filename, CFGSTRUCT *cfgst); void LoadFCEUConfig(const char *filename, CFGSTRUCT *cfgst);
/* Macros for building CFGSTRUCT structures. */ /* Macros for building CFGSTRUCT structures. */

View File

@ -20,6 +20,9 @@
#include "../common/args.h" #include "../common/args.h"
/**
* Parses commandline arguments
**/
char *ParseArgies(int argc, char *argv[]) char *ParseArgies(int argc, char *argv[])
{ {
//int x; //mbg merge 7/17/06 removed //int x; //mbg merge 7/17/06 removed
@ -33,8 +36,12 @@ char *ParseArgies(int argc, char *argv[])
{"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE}, {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE},
}; };
if(argc<=1) return(0); if(argc <= 1)
{
return(0);
}
ParseArguments(argc-2, &argv[1], FCEUArgs); ParseArguments(argc-2, &argv[1], FCEUArgs);
return(argv[argc-1]); return(argv[argc-1]);
} }

View File

@ -26,7 +26,10 @@
/* */ /* */
/****************************************************************/ /****************************************************************/
static CFGSTRUCT fceuconfig[]={ /**
* Structure that contains configuration information
**/
static CFGSTRUCT fceuconfig[] = {
ACS(rfiles[0]), ACS(rfiles[0]),
ACS(rfiles[1]), ACS(rfiles[1]),
@ -125,13 +128,15 @@ static CFGSTRUCT fceuconfig[]={
static void SaveConfig(char *filename) static void SaveConfig(char *filename)
{ {
SaveFCEUConfig(filename,fceuconfig); SaveFCEUConfig(filename,fceuconfig);
} }
static void LoadConfig(char *filename) void LoadConfig(const char *filename)
{ {
FCEUI_GetNTSCTH(&ntsctint,&ntschue); FCEUI_GetNTSCTH(&ntsctint, &ntschue);
LoadFCEUConfig(filename,fceuconfig);
FCEUI_SetNTSCTH(ntsccol,ntsctint,ntschue); LoadFCEUConfig(filename, fceuconfig);
FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
} }

View File

@ -1291,8 +1291,11 @@ void ApplyDefaultCommandMapping(void)
int i; int i;
memset(FCEUD_CommandMapping, 0, sizeof(FCEUD_CommandMapping)); memset(FCEUD_CommandMapping, 0, sizeof(FCEUD_CommandMapping));
for(i=0; i<NUM_DEFAULT_MAPPINGS; ++i) for(i=0; i<NUM_DEFAULT_MAPPINGS; ++i)
{
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd] = DefaultCommandMapping[i].key; FCEUD_CommandMapping[DefaultCommandMapping[i].cmd] = DefaultCommandMapping[i].key;
}
} }
int FCEUD_TestCommandState(int c) int FCEUD_TestCommandState(int c)

View File

@ -75,27 +75,42 @@ HRESULT ddrval;
// cheats, misc, nonvol, states, snaps, ..., base // cheats, misc, nonvol, states, snaps, ..., base
static char *DOvers[6]={0,0,0,0,0,0}; static char *DOvers[6]={0,0,0,0,0,0};
static char *defaultds[5]={"cheats","sav","fcs","snaps","movie"}; static const char *defaultds[5]={"cheats","sav","fcs","snaps","movie"};
static char TempArray[2048]; static char TempArray[2048];
/**
* Contains the base directory of FCE
**/
static char BaseDirectory[2048]; static char BaseDirectory[2048];
void SetDirs(void) void SetDirs(void)
{ {
int x; int x;
static int jlist[6]=
{FCEUIOD_CHEATS,FCEUIOD_MISC,FCEUIOD_NV,FCEUIOD_STATE,FCEUIOD_SNAPS, FCEUIOD__COUNT};
FCEUI_SetSnapName(eoptions&EO_SNAPNAME); static int jlist[6]= {
FCEUIOD_CHEATS,
FCEUIOD_MISC,
FCEUIOD_NV,
FCEUIOD_STATE,
FCEUIOD_SNAPS,
FCEUIOD__COUNT};
for(x=0;x<6;x++) FCEUI_SetSnapName(eoptions & EO_SNAPNAME);
{
FCEUI_SetDirOverride(jlist[x], DOvers[x]); for(x=0; x < sizeof(jlist) / sizeof(*jlist); x++)
} {
if(DOvers[5]) FCEUI_SetDirOverride(jlist[x], DOvers[x]);
FCEUI_SetBaseDirectory(DOvers[5]); }
else
FCEUI_SetBaseDirectory(BaseDirectory); if(DOvers[5])
{
FCEUI_SetBaseDirectory(DOvers[5]);
}
else
{
FCEUI_SetBaseDirectory(BaseDirectory);
}
} }
/* Remove empty, unused directories. */ /* Remove empty, unused directories. */
void RemoveDirs(void) void RemoveDirs(void)
@ -110,30 +125,44 @@ void RemoveDirs(void)
} }
} }
/**
* Creates the default directories.
**/
void CreateDirs(void) void CreateDirs(void)
{ {
int x; int x;
for(x=0;x<5;x++) for(x = 0; x < sizeof(defaultds) / sizeof(*defaultds); x++)
if(!DOvers[x]) {
{ if(!DOvers[x])
sprintf(TempArray,"%s\\%s",DOvers[5]?DOvers[5]:BaseDirectory,defaultds[x]); {
CreateDirectory(TempArray,0); sprintf(TempArray, "%s\\%s", DOvers[5] ? DOvers[5] : BaseDirectory, defaultds[x]);
} CreateDirectory(TempArray,0);
}
}
} }
static char *gfsdir=0; static char *gfsdir=0;
/**
* Fills the BaseDirectory string
*
* TODO: Potential buffer overflow caused by limited size of BaseDirectory?
**/
void GetBaseDirectory(void) void GetBaseDirectory(void)
{ {
int x; unsigned int i;
BaseDirectory[0]=0; GetModuleFileName(0, (LPTSTR)BaseDirectory, sizeof(BaseDirectory) - 1);
GetModuleFileName(0,(LPTSTR)BaseDirectory,2047);
for(x=strlen(BaseDirectory);x>=0;x--) // Search for the last / or \ in the directory and terminate the string there
{ for(i = strlen(BaseDirectory); i >= 0 ; i--)
if(BaseDirectory[x]=='\\' || BaseDirectory[x]=='/') {
{BaseDirectory[x]=0;break;} if(BaseDirectory[i]=='\\' || BaseDirectory[i]=='/')
} {
BaseDirectory[i] = 0;
return;
}
}
} }
static int exiting=0; static int exiting=0;
@ -333,7 +362,6 @@ static void DriverKill(void)
} }
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
void ApplyDefaultCommandMapping(void); void ApplyDefaultCommandMapping(void);
@ -347,25 +375,28 @@ void _updateMemWatch() {
HANDLE mapGameMemBlock; HANDLE mapGameMemBlock;
HANDLE mapRAM; HANDLE mapRAM;
uint32 *BotInput; uint32 *BotInput;
void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM) {
void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM)
{
mapGameMemBlock = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 131072,"fceu.GameMemBlock"); mapGameMemBlock = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 131072,"fceu.GameMemBlock");
if(mapGameMemBlock == NULL || GetLastError() == ERROR_ALREADY_EXISTS) if(mapGameMemBlock == NULL || GetLastError() == ERROR_ALREADY_EXISTS)
{ {
//mbg 7/38/06 - is this the proper error handling? //mbg 7/28/06 - is this the proper error handling?
//do we need to indicate to user somehow that this failed in this emu instance? //do we need to indicate to user somehow that this failed in this emu instance?
CloseHandle(mapGameMemBlock); CloseHandle(mapGameMemBlock);
mapGameMemBlock = NULL; mapGameMemBlock = NULL;
*GameMemBlock = (uint8 *) malloc(131072); *GameMemBlock = (uint8 *) malloc(131072);
*RAM = (uint8 *) malloc(2048); *RAM = (uint8 *) malloc(2048);
} }
else else
{ {
*GameMemBlock = (uint8 *)MapViewOfFile(mapGameMemBlock, FILE_MAP_WRITE, 0, 0, 0); *GameMemBlock = (uint8 *)MapViewOfFile(mapGameMemBlock, FILE_MAP_WRITE, 0, 0, 0);
// set up shared memory mappings // set up shared memory mappings
mapRAM = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 0x800,"fceu.RAM"); mapRAM = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 0x800,"fceu.RAM");
*RAM = (uint8 *)MapViewOfFile(mapRAM, FILE_MAP_WRITE, 0, 0, 0); *RAM = (uint8 *)MapViewOfFile(mapRAM, FILE_MAP_WRITE, 0, 0, 0);
} }
// Give RAM pointer to state structure // Give RAM pointer to state structure
@ -412,6 +443,13 @@ void win_FreeBuffers(uint8 *GameMemBlock, uint8 *RAM) {
} }
#endif #endif
void do_exit()
{
DriverKill();
timeEndPeriod(1);
FCEUI_Kill();
}
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
char *t; char *t;
@ -424,61 +462,89 @@ int main(int argc,char *argv[])
InitCommonControls(); InitCommonControls();
if(!FCEUI_Initialize()) if(!FCEUI_Initialize())
goto doexito; {
do_exit();
return 1;
}
ApplyDefaultCommandMapping(); ApplyDefaultCommandMapping();
srand(GetTickCount()); // rand() is used for some GUI sillyness. srand(GetTickCount()); // rand() is used for some GUI sillyness.
fceu_hInstance=GetModuleHandle(0); fceu_hInstance = GetModuleHandle(0);
// Get the base directory
GetBaseDirectory(); GetBaseDirectory();
// Load the config information
sprintf(TempArray,"%s\\fceu98.cfg",BaseDirectory); sprintf(TempArray,"%s\\fceu98.cfg",BaseDirectory);
LoadConfig(TempArray); LoadConfig(TempArray);
t=ParseArgies(argc,argv); // Parse the commandline arguments
t = ParseArgies(argc, argv);
/* Bleh, need to find a better place for this. */ /* Bleh, need to find a better place for this. */
{ {
palyo&=1; palyo &= 1;
FCEUI_SetVidSystem(palyo); FCEUI_SetVidSystem(palyo);
genie&=1;
genie &= 1;
FCEUI_SetGameGenie(genie); FCEUI_SetGameGenie(genie);
fullscreen&=1;
soundo&=1; fullscreen &= 1;
soundo &= 1;
FCEUI_SetSoundVolume(soundvolume); FCEUI_SetSoundVolume(soundvolume);
FCEUI_SetSoundQuality(soundquality); FCEUI_SetSoundQuality(soundquality);
} }
ParseGIInput(NULL); /* Since a game doesn't have to be ParseGIInput(NULL); /* Since a game doesn't have to be
loaded before the GUI can be used, make loaded before the GUI can be used, make
sure the temporary input type variables sure the temporary input type variables
are set. are set.
*/ */
// Initialize default directories
CreateDirs(); CreateDirs();
SetDirs(); SetDirs();
DoVideoConfigFix(); DoVideoConfigFix();
DoTimingConfigFix(); DoTimingConfigFix();
if(eoptions&EO_CPALETTE) if(eoptions & EO_CPALETTE)
{
FCEUI_SetPaletteArray(cpalette); FCEUI_SetPaletteArray(cpalette);
}
if(!t) fullscreen=0; if(!t)
{
fullscreen=0;
}
CreateMainWindow(); CreateMainWindow();
if(!InitDInput()) if(!InitDInput())
goto doexito; {
do_exit();
return 1;
}
if(!DriverInitialize()) if(!DriverInitialize())
goto doexito; {
do_exit();
return 1;
}
UpdateMenu(); UpdateMenu();
if(t) if(t)
{
ALoad(t); ALoad(t);
else if(eoptions&EO_FOAFTERSTART) }
else if(eoptions & EO_FOAFTERSTART)
{
LoadNewGamey(hAppWnd, 0); LoadNewGamey(hAppWnd, 0);
}
doloopy: doloopy:
UpdateFCEUWindow(); UpdateFCEUWindow();
@ -514,7 +580,6 @@ doloopy:
if(!exiting) if(!exiting)
goto doloopy; goto doloopy;
doexito:
DriverKill(); DriverKill();
timeEndPeriod(1); timeEndPeriod(1);
FCEUI_Kill(); FCEUI_Kill();

View File

@ -176,14 +176,20 @@ uint8 *RAM;
//--------- //---------
//windows might need to allocate these differently, so we have some special code //windows might need to allocate these differently, so we have some special code
static void AllocBuffers() { static void AllocBuffers()
#ifdef _USE_SHARED_MEMORY_ {
#ifdef _USE_SHARED_MEMORY_
void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM); void win_AllocBuffers(uint8 **GameMemBlock, uint8 **RAM);
win_AllocBuffers(&GameMemBlock, &RAM); win_AllocBuffers(&GameMemBlock, &RAM);
#else
#else
GameMemBlock = (uint8*)FCEU_gmalloc(131072); GameMemBlock = (uint8*)FCEU_gmalloc(131072);
RAM = (uint8*)FCEU_gmalloc(0x800); RAM = (uint8*)FCEU_gmalloc(0x800);
#endif
#endif
} }
static void FreeBuffers() { static void FreeBuffers() {
@ -347,21 +353,30 @@ FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode)
} }
/**
* Return: Flag that indicates whether the function was succesful or not.
**/
int FCEUI_Initialize(void) int FCEUI_Initialize(void)
{ {
if(!FCEU_InitVirtualVideo()) if(!FCEU_InitVirtualVideo())
{
return 0; return 0;
}
AllocBuffers(); AllocBuffers();
// Initialize some parts of the settings structure
memset(&FSettings,0,sizeof(FSettings)); memset(&FSettings,0,sizeof(FSettings));
FSettings.UsrFirstSLine[0]=8; FSettings.UsrFirstSLine[0]=8;
FSettings.UsrFirstSLine[1]=0; FSettings.UsrFirstSLine[1]=0;
FSettings.UsrLastSLine[0]=231; FSettings.UsrLastSLine[0]=231;
FSettings.UsrLastSLine[1]=239; FSettings.UsrLastSLine[1]=239;
FSettings.SoundVolume=100; FSettings.SoundVolume=100;
FCEUPPU_Init(); FCEUPPU_Init();
X6502_Init(); X6502_Init();
return 1; return 1;
} }

View File

@ -588,27 +588,38 @@ static char FileExt[2048]; /* Includes the . character, as in ".nes" */
static char FileBaseDirectory[2048]; static char FileBaseDirectory[2048];
/**
* Updates the base directory
**/
void FCEUI_SetBaseDirectory(const char *dir) void FCEUI_SetBaseDirectory(const char *dir)
{ {
strncpy(BaseDirectory,dir,2047); strncpy(BaseDirectory, dir, sizeof(BaseDirectory));
BaseDirectory[2047]=0;
// TODO: Necessary?
BaseDirectory[2047] = 0;
} }
static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0}; // odirs, odors. ^_^ static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0}; // odirs, odors. ^_^
void FCEUI_SetDirOverride(int which, char *n) void FCEUI_SetDirOverride(int which, char *n)
{ {
// FCEU_PrintError("odirs[%d]=%s->%s", which, odirs[which], n); // FCEU_PrintError("odirs[%d]=%s->%s", which, odirs[which], n);
if(which < FCEUIOD__COUNT) if (which < FCEUIOD__COUNT)
odirs[which]=n; {
odirs[which] = n;
}
if(GameInfo) /* Rebuild cache of present states/movies. */ if(GameInfo) /* Rebuild cache of present states/movies. */
{ {
if(which==FCEUIOD_STATE) if(which==FCEUIOD_STATE)
FCEUSS_CheckStates(); {
else if(which == FCEUIOD_MISC) FCEUSS_CheckStates();
FCEUMOV_CheckMovies(); }
} else if(which == FCEUIOD_MISC)
{
FCEUMOV_CheckMovies();
}
}
} }
#ifndef HAVE_ASPRINTF #ifndef HAVE_ASPRINTF

View File

@ -267,8 +267,8 @@ void WritePalette(void)
void FCEUI_GetNTSCTH(int *tint, int *hue) void FCEUI_GetNTSCTH(int *tint, int *hue)
{ {
*tint=ntsctint; *tint = ntsctint;
*hue=ntschue; *hue = ntschue;
} }
static int controlselect=0; static int controlselect=0;

View File

@ -64,38 +64,39 @@ static uint32 ppulut3[128];
static void makeppulut(void) static void makeppulut(void)
{ {
int x; int x;
int y; int y;
int cc,xo,pixel;
for(x=0;x<256;x++)
{
ppulut1[x]=0;
for(y=0;y<8;y++)
ppulut1[x]|=((x>>(7-y))&1)<<(y*4);
ppulut2[x]=ppulut1[x]<<1;
}
{ for(x=0;x<256;x++)
{
ppulut1[x] = 0;
for(y=0;y<8;y++)
{
ppulut1[x] |= ((x>>(7-y))&1)<<(y*4);
}
int cc,xo,pixel; ppulut2[x] = ppulut1[x] << 1;
}
for(cc=0;cc<16;cc++) for(cc=0;cc<16;cc++)
{ {
for(xo=0;xo<8;xo++) for(xo=0;xo<8;xo++)
{ {
ppulut3[xo|(cc<<3)]=0; ppulut3[ xo | ( cc << 3 ) ] = 0;
for(pixel=0;pixel<8;pixel++)
{ for(pixel=0;pixel<8;pixel++)
int shiftr; {
shiftr=(pixel+xo)/8; int shiftr;
shiftr*=2; shiftr = ( pixel + xo ) / 8;
ppulut3[xo|(cc<<3)]|=(( cc>>shiftr )&3)<<(2+pixel*4); shiftr *= 2;
} ppulut3[ xo | (cc<<3) ] |= ( ( cc >> shiftr ) & 3 ) << ( 2 + pixel * 4 );
// printf("%08x\n",ppulut3[xo|(cc<<3)]); }
} // printf("%08x\n",ppulut3[xo|(cc<<3)]);
} }
}
}
} }
static int ppudead=1; static int ppudead=1;
@ -1212,9 +1213,12 @@ void FCEUPPU_SetVideoSystem(int w)
} }
} }
/**
* Initializes the PPU
**/
void FCEUPPU_Init(void) void FCEUPPU_Init(void)
{ {
makeppulut(); makeppulut();
} }
void FCEUPPU_Reset(void) void FCEUPPU_Reset(void)

View File

@ -74,46 +74,62 @@ void FCEU_KillVirtualVideo(void)
//} //}
} }
/**
* Return: Flag that indicates whether the function was succesful or not.
*
* TODO: This function is Windows-only. It should probably be moved.
**/
int FCEU_InitVirtualVideo(void) int FCEU_InitVirtualVideo(void)
{ {
if(!XBuf) /* Some driver code may allocate XBuf externally. */ if(!XBuf) /* Some driver code may allocate XBuf externally. */
/* 256 bytes per scanline, * 240 scanline maximum, +8 for alignment, /* 256 bytes per scanline, * 240 scanline maximum, +8 for alignment,
*/ */
#ifdef _USE_SHARED_MEMORY_ #ifdef _USE_SHARED_MEMORY_
mapXBuf = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 256 * 256 + 8,"fceu.XBuf");
mapXBuf = CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE, 0, 256 * 256 + 8, "fceu.XBuf");
if(mapXBuf == NULL || GetLastError() == ERROR_ALREADY_EXISTS) if(mapXBuf == NULL || GetLastError() == ERROR_ALREADY_EXISTS)
{ {
CloseHandle(mapXBuf); CloseHandle(mapXBuf);
mapXBuf = NULL; mapXBuf = NULL;
XBuf= (uint8*) (FCEU_malloc(256 * 256 + 8)); XBuf = (uint8*) (FCEU_malloc(256 * 256 + 8));
XBackBuf= (uint8*) (FCEU_malloc(256 * 256 + 8)); XBackBuf = (uint8*) (FCEU_malloc(256 * 256 + 8));
} }
else else
{ {
XBuf = (uint8 *)MapViewOfFile(mapXBuf, FILE_MAP_WRITE, 0, 0, 0); XBuf = (uint8 *)MapViewOfFile(mapXBuf, FILE_MAP_WRITE, 0, 0, 0);
XBackBuf = (uint8*) (FCEU_malloc(256 * 256 + 8)); XBackBuf = (uint8*) (FCEU_malloc(256 * 256 + 8));
} }
if (!XBuf || !XBackBuf) if (!XBuf || !XBackBuf)
{
return 0; return 0;
}
#else #else
if(!(XBuf= (uint8*) (FCEU_malloc(256 * 256 + 8))) ||
!(XBackBuf= (uint8*) (FCEU_malloc(256 * 256 + 8))))
return 0;
#endif //_USE_SHARED_MEMORY_
xbsave=XBuf;
if(sizeof(uint8*)==4) if(!(XBuf= (uint8*) (FCEU_malloc(256 * 256 + 8))) ||
{ !(XBackBuf= (uint8*) (FCEU_malloc(256 * 256 + 8))))
uint32 m; {
m=(uint32)XBuf; return 0;
m=(4-m)&3; }
XBuf+=m;
} #endif //_USE_SHARED_MEMORY_
memset(XBuf,128,256*256); //*240);
memset(XBackBuf,128,256*256); xbsave = XBuf;
return 1;
if( sizeof(uint8*) == 4 )
{
uint32 m = (uint32)XBuf;
m = ( 4 - m) & 3;
XBuf+=m;
}
memset(XBuf,128,256*256); //*240);
memset(XBackBuf,128,256*256);
return 1;
} }
int howlong; int howlong;

View File

@ -363,16 +363,31 @@ void X6502_Reset(void)
{ {
_IRQlow=FCEU_IQRESET; _IRQlow=FCEU_IQRESET;
} }
/**
* Initializes the 6502 CPU
**/
void X6502_Init(void) void X6502_Init(void)
{ {
int x; unsigned int i;
// Initialize the CPU structure
memset((void *)&X,0,sizeof(X)); memset((void *)&X,0,sizeof(X));
for(x=0;x<256;x++)
if(!x) ZNTable[x]=Z_FLAG; for(i = 0; i < sizeof(ZNTable); i++)
else if(x&0x80) ZNTable[x]=N_FLAG; {
else ZNTable[x]=0; if(!i)
{
ZNTable[i] = Z_FLAG;
}
else if ( i & 0x80 )
{
ZNTable[i] = N_FLAG;
}
else
{
ZNTable[i] = 0;
}
}
} }
void X6502_Power(void) void X6502_Power(void)