mirror of
https://github.com/libretro/beetle-wswan-libretro.git
synced 2024-12-02 13:28:06 +00:00
Cleanups
This commit is contained in:
parent
5d3cbae300
commit
33776fe17c
18
libretro.cpp
18
libretro.cpp
@ -202,8 +202,8 @@ static int Load(const char *name, MDFNFILE *fp)
|
||||
|
||||
if(GET_FSIZE_PTR(fp) < 65536)
|
||||
{
|
||||
MDFN_PrintError(_("%s ROM image is too small."), MDFNGameInfo->fullname);
|
||||
return(0);
|
||||
/* ROM image is too small. */
|
||||
return(0);
|
||||
}
|
||||
|
||||
real_rom_size = (GET_FSIZE_PTR(fp) + 0xFFFF) & ~0xFFFF;
|
||||
@ -219,12 +219,12 @@ static int Load(const char *name, MDFNFILE *fp)
|
||||
|
||||
memcpy(wsCartROM + (rom_size - real_rom_size), GET_FDATA_PTR(fp), GET_FSIZE_PTR(fp));
|
||||
|
||||
MDFN_printf(_("ROM: %dKiB\n"), real_rom_size / 1024);
|
||||
printf(_("ROM: %dKiB\n"), real_rom_size / 1024);
|
||||
md5_context md5;
|
||||
md5.starts();
|
||||
md5.update(wsCartROM, rom_size);
|
||||
md5.finish(MDFNGameInfo->MD5);
|
||||
MDFN_printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
|
||||
printf(_("ROM MD5: 0x%s\n"), md5_context::asciistr(MDFNGameInfo->MD5, 0).c_str());
|
||||
|
||||
uint8 header[10];
|
||||
memcpy(header, wsCartROM + rom_size - 10, 10);
|
||||
@ -239,7 +239,7 @@ static int Load(const char *name, MDFNFILE *fp)
|
||||
break;
|
||||
}
|
||||
}
|
||||
MDFN_printf(_("Developer: %s (0x%02x)\n"), developer_name, header[0]);
|
||||
printf(_("Developer: %s (0x%02x)\n"), developer_name, header[0]);
|
||||
}
|
||||
|
||||
uint32 SRAMSize = 0;
|
||||
@ -260,17 +260,17 @@ static int Load(const char *name, MDFNFILE *fp)
|
||||
//printf("%02x\n", header[5]);
|
||||
|
||||
if(eeprom_size)
|
||||
MDFN_printf(_("EEPROM: %d bytes\n"), eeprom_size);
|
||||
printf(_("EEPROM: %d bytes\n"), eeprom_size);
|
||||
|
||||
if(SRAMSize)
|
||||
MDFN_printf(_("Battery-backed RAM: %d bytes\n"), SRAMSize);
|
||||
printf(_("Battery-backed RAM: %d bytes\n"), SRAMSize);
|
||||
|
||||
MDFN_printf(_("Recorded Checksum: 0x%04x\n"), header[8] | (header[9] << 8));
|
||||
printf(_("Recorded Checksum: 0x%04x\n"), header[8] | (header[9] << 8));
|
||||
{
|
||||
uint16 real_crc = 0;
|
||||
for(unsigned int i = 0; i < rom_size - 2; i++)
|
||||
real_crc += wsCartROM[i];
|
||||
MDFN_printf(_("Real Checksum: 0x%04x\n"), real_crc);
|
||||
printf(_("Real Checksum: 0x%04x\n"), real_crc);
|
||||
}
|
||||
|
||||
if((header[8] | (header[9] << 8)) == 0x8de1 && (header[0]==0x01)&&(header[2]==0x27)) /* Detective Conan */
|
||||
|
@ -46,10 +46,6 @@ MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
std::vector<FileExtensionSpecStruct> valid_iae;
|
||||
MDFNGameInfo = &EmulatedWSwan;
|
||||
|
||||
MDFN_printf(_("Loading %s...\n"),name);
|
||||
|
||||
MDFN_indent(1);
|
||||
|
||||
// Construct a NULL-delimited list of known file extensions for MDFN_fopen()
|
||||
const FileExtensionSpecStruct *curexts = MDFNGameInfo->FileExtensions;
|
||||
|
||||
@ -65,20 +61,9 @@ MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
MDFN_printf(_("Using module: %s(%s)\n\n"), MDFNGameInfo->shortname, MDFNGameInfo->fullname);
|
||||
MDFN_indent(1);
|
||||
|
||||
//
|
||||
// Load per-game settings
|
||||
//
|
||||
// Maybe we should make a "pgcfg" subdir, and automatically load all files in it?
|
||||
// End load per-game settings
|
||||
//
|
||||
|
||||
if(MDFNGameInfo->Load(name, &GameFile) <= 0)
|
||||
{
|
||||
GameFile.Close();
|
||||
MDFN_indent(-2);
|
||||
MDFNGameInfo = NULL;
|
||||
return(0);
|
||||
}
|
||||
@ -86,8 +71,6 @@ MDFNGI *MDFNI_LoadGame(const char *force_module, const char *name)
|
||||
MDFN_LoadGameCheats(NULL);
|
||||
MDFNMP_InstallReadPatches();
|
||||
|
||||
MDFN_indent(-2);
|
||||
|
||||
if(!MDFNGameInfo->name)
|
||||
{
|
||||
unsigned int x;
|
||||
@ -135,93 +118,3 @@ int MDFNI_Initialize(const char *basedir)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
static int curindent = 0;
|
||||
|
||||
void MDFN_indent(int indent)
|
||||
{
|
||||
curindent += indent;
|
||||
}
|
||||
|
||||
static uint8 lastchar = 0;
|
||||
|
||||
void MDFN_printf(const char *format, ...)
|
||||
{
|
||||
char *format_temp;
|
||||
char *temp;
|
||||
unsigned int x, newlen;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
|
||||
|
||||
// First, determine how large our format_temp buffer needs to be.
|
||||
uint8 lastchar_backup = lastchar; // Save lastchar!
|
||||
for(newlen=x=0;x<strlen(format);x++)
|
||||
{
|
||||
if(lastchar == '\n' && format[x] != '\n')
|
||||
{
|
||||
int y;
|
||||
for(y=0;y<curindent;y++)
|
||||
newlen++;
|
||||
}
|
||||
newlen++;
|
||||
lastchar = format[x];
|
||||
}
|
||||
|
||||
format_temp = (char *)malloc(newlen + 1); // Length + NULL character, duh
|
||||
|
||||
// Now, construct our format_temp string
|
||||
lastchar = lastchar_backup; // Restore lastchar
|
||||
for(newlen=x=0;x<strlen(format);x++)
|
||||
{
|
||||
if(lastchar == '\n' && format[x] != '\n')
|
||||
{
|
||||
int y;
|
||||
for(y=0;y<curindent;y++)
|
||||
format_temp[newlen++] = ' ';
|
||||
}
|
||||
format_temp[newlen++] = format[x];
|
||||
lastchar = format[x];
|
||||
}
|
||||
|
||||
format_temp[newlen] = 0;
|
||||
|
||||
temp = trio_vaprintf(format_temp, ap);
|
||||
free(format_temp);
|
||||
|
||||
MDFND_Message(temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void MDFN_PrintError(const char *format, ...)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
temp = trio_vaprintf(format, ap);
|
||||
MDFND_PrintError(temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void MDFN_DebugPrintReal(const char *file, const int line, const char *format, ...)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
|
||||
temp = trio_vaprintf(format, ap);
|
||||
fprintf(stderr, "%s:%d %s\n", file, line, temp);
|
||||
free(temp);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
@ -35,12 +35,6 @@ extern MDFNGI *MDFNGameInfo;
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
void MDFN_PrintError(const char *format, ...);
|
||||
void MDFN_printf(const char *format, ...);
|
||||
void MDFN_DispMessage(const char *format, ...);
|
||||
|
||||
void MDFN_DebugPrintReal(const char *file, const int line, const char *format, ...);
|
||||
|
||||
void MDFN_LoadGameCheats(void *override);
|
||||
void MDFN_FlushGameCheats(int nosave);
|
||||
|
||||
|
@ -165,11 +165,6 @@ void MDFNMP_RemoveReadPatches(void)
|
||||
MDFNGameInfo->RemoveReadPatches();
|
||||
}
|
||||
|
||||
static void CheatMemErr(void)
|
||||
{
|
||||
MDFN_PrintError(_("Error allocating memory for cheat data."));
|
||||
}
|
||||
|
||||
/* This function doesn't allocate any memory for "name" */
|
||||
static int AddCheatEntry(char *name, char *conditions, uint32 addr, uint64 val, uint64 compare, int status, char type, unsigned int length, bool bigendian)
|
||||
{
|
||||
@ -209,117 +204,111 @@ static bool SeekToOurSection(void *fp_ptr)
|
||||
|
||||
void MDFN_LoadGameCheats(void *override_ptr)
|
||||
{
|
||||
char linebuf[2048];
|
||||
FILE *fp;
|
||||
FILE *override = (FILE*)override_ptr;
|
||||
char linebuf[2048];
|
||||
FILE *fp;
|
||||
FILE *override = (FILE*)override_ptr;
|
||||
|
||||
unsigned int addr;
|
||||
unsigned long long val;
|
||||
unsigned int status;
|
||||
char type;
|
||||
unsigned long long compare;
|
||||
unsigned int x;
|
||||
unsigned int length;
|
||||
unsigned int icount;
|
||||
bool bigendian;
|
||||
unsigned int addr;
|
||||
unsigned long long val;
|
||||
unsigned int status;
|
||||
char type;
|
||||
unsigned long long compare;
|
||||
unsigned int x;
|
||||
unsigned int length;
|
||||
unsigned int icount;
|
||||
bool bigendian;
|
||||
|
||||
int tc=0;
|
||||
int tc=0;
|
||||
|
||||
savecheats=0;
|
||||
savecheats=0;
|
||||
|
||||
if(override)
|
||||
fp = override;
|
||||
else
|
||||
{
|
||||
std::string fn = MDFN_MakeFName(MDFNMKF_CHEAT,0,0).c_str();
|
||||
|
||||
MDFN_printf("\n");
|
||||
MDFN_printf(_("Loading cheats from %s...\n"), fn.c_str());
|
||||
MDFN_indent(1);
|
||||
|
||||
if(!(fp = fopen(fn.c_str(),"rb")))
|
||||
{
|
||||
ErrnoHolder ene(errno);
|
||||
|
||||
MDFN_printf(_("Error opening file: %s\n"), ene.StrError());
|
||||
MDFN_indent(-1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(SeekToOurSection(fp))
|
||||
{
|
||||
while(fgets(linebuf,2048,fp) > 0)
|
||||
{
|
||||
char namebuf[2048];
|
||||
char *tbuf=linebuf;
|
||||
|
||||
addr=val=compare=status=type=0;
|
||||
bigendian = 0;
|
||||
icount = 0;
|
||||
|
||||
if(tbuf[0] == '[') // No more cheats for this game, so sad :(
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if(tbuf[0] == '\n' || tbuf[0] == '\r' || tbuf[0] == '\t' || tbuf[0] == ' ') // Don't parse if the line starts(or is just) white space
|
||||
continue;
|
||||
|
||||
if(tbuf[0] != 'R' && tbuf[0] != 'C' && tbuf[0] != 'S')
|
||||
{
|
||||
MDFN_printf(_("Invalid cheat type: %c\n"), tbuf[0]);
|
||||
break;
|
||||
}
|
||||
type = tbuf[0];
|
||||
namebuf[0] = 0;
|
||||
|
||||
char status_tmp, endian_tmp;
|
||||
if(type == 'C')
|
||||
trio_sscanf(tbuf, "%c %c %d %c %d %08x %16llx %16llx %.2047[^\r\n]", &type, &status_tmp, &length, &endian_tmp, &icount, &addr, &val, &compare, namebuf);
|
||||
if(override)
|
||||
fp = override;
|
||||
else
|
||||
trio_sscanf(tbuf, "%c %c %d %c %d %08x %16llx %.2047[^\r\n]", &type, &status_tmp, &length, &endian_tmp, &icount, &addr, &val, namebuf);
|
||||
|
||||
status = (status_tmp == 'A') ? 1 : 0;
|
||||
bigendian = (endian_tmp == 'B') ? 1 : 0;
|
||||
|
||||
for(x=0;x<strlen(namebuf);x++)
|
||||
{
|
||||
if(namebuf[x]==10 || namebuf[x]==13)
|
||||
{
|
||||
namebuf[x]=0;
|
||||
break;
|
||||
}
|
||||
else if(namebuf[x]<0x20) namebuf[x]=' ';
|
||||
/* Loading cheats */
|
||||
std::string fn = MDFN_MakeFName(MDFNMKF_CHEAT,0,0).c_str();
|
||||
|
||||
if(!(fp = fopen(fn.c_str(),"rb")))
|
||||
{
|
||||
/* Error opening file. */
|
||||
ErrnoHolder ene(errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// November 9, 2009 return value fix.
|
||||
if(fgets(linebuf, 2048, fp) == NULL)
|
||||
linebuf[0] = 0;
|
||||
|
||||
for(x=0;x<strlen(linebuf);x++)
|
||||
if(SeekToOurSection(fp))
|
||||
{
|
||||
if(linebuf[x]==10 || linebuf[x]==13)
|
||||
{
|
||||
linebuf[x]=0;
|
||||
break;
|
||||
}
|
||||
else if(linebuf[x]<0x20) linebuf[x]=' ';
|
||||
while(fgets(linebuf,2048,fp) > 0)
|
||||
{
|
||||
char namebuf[2048];
|
||||
char *tbuf=linebuf;
|
||||
|
||||
addr=val=compare=status=type=0;
|
||||
bigendian = 0;
|
||||
icount = 0;
|
||||
|
||||
if(tbuf[0] == '[') // No more cheats for this game, so sad :(
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if(tbuf[0] == '\n' || tbuf[0] == '\r' || tbuf[0] == '\t' || tbuf[0] == ' ') // Don't parse if the line starts(or is just) white space
|
||||
continue;
|
||||
|
||||
if(tbuf[0] != 'R' && tbuf[0] != 'C' && tbuf[0] != 'S')
|
||||
{
|
||||
/* Invalid cheat type */
|
||||
break;
|
||||
}
|
||||
type = tbuf[0];
|
||||
namebuf[0] = 0;
|
||||
|
||||
char status_tmp, endian_tmp;
|
||||
if(type == 'C')
|
||||
trio_sscanf(tbuf, "%c %c %d %c %d %08x %16llx %16llx %.2047[^\r\n]", &type, &status_tmp, &length, &endian_tmp, &icount, &addr, &val, &compare, namebuf);
|
||||
else
|
||||
trio_sscanf(tbuf, "%c %c %d %c %d %08x %16llx %.2047[^\r\n]", &type, &status_tmp, &length, &endian_tmp, &icount, &addr, &val, namebuf);
|
||||
|
||||
status = (status_tmp == 'A') ? 1 : 0;
|
||||
bigendian = (endian_tmp == 'B') ? 1 : 0;
|
||||
|
||||
for(x=0;x<strlen(namebuf);x++)
|
||||
{
|
||||
if(namebuf[x]==10 || namebuf[x]==13)
|
||||
{
|
||||
namebuf[x]=0;
|
||||
break;
|
||||
}
|
||||
else if(namebuf[x]<0x20) namebuf[x]=' ';
|
||||
}
|
||||
|
||||
// November 9, 2009 return value fix.
|
||||
if(fgets(linebuf, 2048, fp) == NULL)
|
||||
linebuf[0] = 0;
|
||||
|
||||
for(x=0;x<strlen(linebuf);x++)
|
||||
{
|
||||
if(linebuf[x]==10 || linebuf[x]==13)
|
||||
{
|
||||
linebuf[x]=0;
|
||||
break;
|
||||
}
|
||||
else if(linebuf[x]<0x20) linebuf[x]=' ';
|
||||
}
|
||||
|
||||
AddCheatEntry(strdup(namebuf), strdup(linebuf), addr, val, compare, status, type, length, bigendian);
|
||||
tc++;
|
||||
}
|
||||
}
|
||||
|
||||
AddCheatEntry(strdup(namebuf), strdup(linebuf), addr, val, compare, status, type, length, bigendian);
|
||||
tc++;
|
||||
}
|
||||
}
|
||||
RebuildSubCheats();
|
||||
|
||||
RebuildSubCheats();
|
||||
|
||||
if(!override)
|
||||
{
|
||||
MDFN_printf(_("%lu cheats loaded.\n"), (unsigned long)cheats.size());
|
||||
MDFN_indent(-1);
|
||||
fclose(fp);
|
||||
}
|
||||
if(!override)
|
||||
{
|
||||
/* Cheats loaded. */
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteOurCheats(FILE *tmp_fp, bool needheader)
|
||||
@ -449,27 +438,27 @@ void MDFN_FlushGameCheats(int nosave)
|
||||
|
||||
int MDFNI_AddCheat(const char *name, uint32 addr, uint64 val, uint64 compare, char type, unsigned int length, bool bigendian)
|
||||
{
|
||||
char *t;
|
||||
char *t;
|
||||
|
||||
if(!(t = strdup(name)))
|
||||
{
|
||||
CheatMemErr();
|
||||
return(0);
|
||||
}
|
||||
if(!(t = strdup(name)))
|
||||
{
|
||||
/* Error allocating memory for cheat data */
|
||||
return(0);
|
||||
}
|
||||
|
||||
if(!AddCheatEntry(t, NULL, addr,val,compare,1,type, length, bigendian))
|
||||
{
|
||||
free(t);
|
||||
return(0);
|
||||
}
|
||||
if(!AddCheatEntry(t, NULL, addr,val,compare,1,type, length, bigendian))
|
||||
{
|
||||
free(t);
|
||||
return(0);
|
||||
}
|
||||
|
||||
savecheats = 1;
|
||||
savecheats = 1;
|
||||
|
||||
MDFNMP_RemoveReadPatches();
|
||||
RebuildSubCheats();
|
||||
MDFNMP_InstallReadPatches();
|
||||
MDFNMP_RemoveReadPatches();
|
||||
RebuildSubCheats();
|
||||
MDFNMP_InstallReadPatches();
|
||||
|
||||
return(1);
|
||||
return(1);
|
||||
}
|
||||
|
||||
int MDFNI_DelCheat(uint32 which)
|
||||
|
Loading…
Reference in New Issue
Block a user