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

@ -56,12 +56,14 @@ static void GetValueR(FILE *fp, char *str, void *v, int c)
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))) if(!(*(char **)v=(char*)malloc(s)))
goto gogl; goto gogl;
fread(*(char **)v,1,s,fp); fread(*(char **)v,1,s,fp);
continue; continue;
} }
@ -71,30 +73,41 @@ static void GetValueR(FILE *fp, char *str, void *v, int c)
fseek(fp,s,SEEK_CUR); fseek(fp,s,SEEK_CUR);
continue; continue;
} }
fread((uint8*)v,1,c,fp); fread((uint8*)v,1,c,fp);
} }
else else
{
fseek(fp,s,SEEK_CUR); fseek(fp,s,SEEK_CUR);
} }
}
fseek(fp,4,SEEK_SET); 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.
*
* @param cfgst The configuration structure.
* @param fp File handle.
**/
void SaveParse(const 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
{ {
SaveParse((CFGSTRUCT*)cfgst[x].ptr,fp); // Recursion is sexy. I could SaveParse((CFGSTRUCT*)cfgst[x].ptr, fp); // Recursion is sexy. I could
// save a little stack space if I made // save a little stack space if I made
// the file pointer a non-local // the file pointer a non-local
// variable... // variable...
@ -102,51 +115,84 @@ static void SaveParse(CFGSTRUCT *cfgst, FILE *fp)
continue; continue;
} }
if(cfgst[x].len) // Plain data if(cfgst[x].len)
{
// Plain data
SetValueR(fp,cfgst[x].name,cfgst[x].ptr,cfgst[x].len); 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. else
SetValueR(fp,cfgst[x].name,*(char **)cfgst[x].ptr, {
strlen(*(char **)cfgst[x].ptr)+1); // 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++; x++;
} }
} }
void SaveFCEUConfig(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,"wb"); if(fp==NULL)
if(fp==NULL) return; {
return;
}
SaveParse(cfgst,fp); SaveParse(cfgst, fp);
fclose(fp); fclose(fp);
} }
static void LoadParse(CFGSTRUCT *cfgst, FILE *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; 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); LoadParse((CFGSTRUCT*)cfgst[x].ptr, fp);
x++; x++;
continue; continue;
} }
GetValueR(fp,cfgst[x].name,cfgst[x].ptr,cfgst[x].len);
GetValueR(fp, cfgst[x].name, cfgst[x].ptr, cfgst[x].len);
x++; x++;
} }
} }
void LoadFCEUConfig(char *filename, CFGSTRUCT *cfgst) /**
* Loads config information from the config file.
*
* @param filename Name of the config file.
**/
void LoadFCEUConfig(const char *filename, CFGSTRUCT *cfgst)
{ {
FILE *fp; FILE *fp = fopen(filename,"rb");
if(fp==NULL)
{
return;
}
LoadParse(cfgst, fp);
fp=fopen(filename,"rb");
if(fp==NULL) return;
LoadParse(cfgst,fp);
fclose(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]),
@ -128,10 +131,12 @@ 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);
for(x=0; x < sizeof(jlist) / sizeof(*jlist); x++)
{ {
FCEUI_SetDirOverride(jlist[x], DOvers[x]); FCEUI_SetDirOverride(jlist[x], DOvers[x]);
} }
if(DOvers[5]) if(DOvers[5])
{
FCEUI_SetBaseDirectory(DOvers[5]); FCEUI_SetBaseDirectory(DOvers[5]);
}
else else
{
FCEUI_SetBaseDirectory(BaseDirectory); FCEUI_SetBaseDirectory(BaseDirectory);
}
} }
/* Remove empty, unused directories. */ /* Remove empty, unused directories. */
void RemoveDirs(void) void RemoveDirs(void)
@ -110,29 +125,43 @@ 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]); sprintf(TempArray, "%s\\%s", DOvers[5] ? DOvers[5] : BaseDirectory, defaultds[x]);
CreateDirectory(TempArray,0); 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]=='/') if(BaseDirectory[i]=='\\' || BaseDirectory[i]=='/')
{BaseDirectory[x]=0;break;} {
BaseDirectory[i] = 0;
return;
}
} }
} }
@ -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,14 +375,17 @@ 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);
@ -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(); FCEUSS_CheckStates();
}
else if(which == FCEUIOD_MISC) else if(which == FCEUIOD_MISC)
{
FCEUMOV_CheckMovies(); 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

@ -66,36 +66,37 @@ static void makeppulut(void)
{ {
int x; int x;
int y; int y;
int cc,xo,pixel;
for(x=0;x<256;x++) for(x=0;x<256;x++)
{ {
ppulut1[x]=0; ppulut1[x] = 0;
for(y=0;y<8;y++) for(y=0;y<8;y++)
ppulut1[x]|=((x>>(7-y))&1)<<(y*4); {
ppulut2[x]=ppulut1[x]<<1; ppulut1[x] |= ((x>>(7-y))&1)<<(y*4);
} }
{ ppulut2[x] = ppulut1[x] << 1;
}
int cc,xo,pixel;
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; int shiftr;
shiftr=(pixel+xo)/8; shiftr = ( pixel + xo ) / 8;
shiftr*=2; shiftr *= 2;
ppulut3[xo|(cc<<3)]|=(( cc>>shiftr )&3)<<(2+pixel*4); 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,6 +1213,9 @@ void FCEUPPU_SetVideoSystem(int w)
} }
} }
/**
* Initializes the PPU
**/
void FCEUPPU_Init(void) void FCEUPPU_Init(void)
{ {
makeppulut(); makeppulut();

View File

@ -74,45 +74,61 @@ 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))) || if(!(XBuf= (uint8*) (FCEU_malloc(256 * 256 + 8))) ||
!(XBackBuf= (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)
{ {
uint32 m; return 0;
m=(uint32)XBuf; }
m=(4-m)&3;
#endif //_USE_SHARED_MEMORY_
xbsave = XBuf;
if( sizeof(uint8*) == 4 )
{
uint32 m = (uint32)XBuf;
m = ( 4 - m) & 3;
XBuf+=m; XBuf+=m;
} }
memset(XBuf,128,256*256); //*240); memset(XBuf,128,256*256); //*240);
memset(XBackBuf,128,256*256); memset(XBackBuf,128,256*256);
return 1; return 1;
} }

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)