Merge pull request #322 from negativeExponent/updates

add prg and chr checksum, rom info log cleanup, readability updates
This commit is contained in:
hizzlekizzle
2020-02-16 09:46:36 -06:00
committed by GitHub
11 changed files with 111 additions and 96 deletions

View File

@@ -88,7 +88,7 @@ static void M226Reset(void) {
void Mapper226_Init(CartInfo *info) {
isresetbased = 0;
/* 1536KiB PRG roms have different bank order */
reorder_banks = ((info->prgRom * 16) == 1536) ? 1 : 0;
reorder_banks = ((info->PRGRomSize * 16) == 1536) ? 1 : 0;
info->Power = M226Power;
info->Reset = M226Reset;
AddExState(&StateRegs, ~0, 0, 0);

View File

@@ -555,10 +555,10 @@ static void maketables(uint32 c, uint32 r) {
}
}
OPLL *OPLL_new(uint32 clk, uint32 rate) {
OPLL *OPLL_new(uint32 _clk, uint32 _rate) {
OPLL *opll;
maketables(clk, rate);
maketables(_clk, _rate);
opll = (OPLL*)calloc(sizeof(OPLL), 1);
if (opll == NULL)

View File

@@ -1,3 +1,6 @@
#ifndef _MMC3_H
#define _MMC3_H
extern uint8 MMC3_cmd;
extern uint8 mmc3opts;
extern uint8 A000B;
@@ -24,3 +27,5 @@ DECLFW(MMC3_CMDWrite);
DECLFW(MMC3_IRQWrite);
void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery);
#endif /* _MMC3_H */

View File

@@ -217,9 +217,9 @@ void UNROM512_Init(CartInfo *info) {
flash_bank = 0;
flash_save = info->battery;
if (info->chrRam == 8192)
if (info->CHRRamSize == 8192)
chrram_mask = 0;
else if (info->chrRam == 16384)
else if (info->CHRRamSize == 16384)
chrram_mask = 0x20;
else
chrram_mask = 0x60;
@@ -236,7 +236,7 @@ void UNROM512_Init(CartInfo *info) {
SetupCartMirroring(MI_0, 0, NULL);
break;
case 3: /* hard four screen, last 8k of 32k RAM (flags: 4-screen + vertical) */
SetupCartMirroring(4, 1, VROM + (info->chrRam - 8192));
SetupCartMirroring(4, 1, VROM + (info->CHRRamSize - 8192));
break;
}
bus_conflict = !info->battery;

View File

@@ -20,15 +20,17 @@ typedef struct {
* set to mapper 4.
*/
int battery; /* Presence of an actual battery. */
int prgRom; /* total prg rom size in 16 K chunks */
int chrRom; /* total chr rom size in 8 K chunks */
int prgRam; /* prg ram size (volatile) */
int chrRam; /* chr ram size (volatile) */
int prgRam_battery; /* prg ram size (non-volatile or battery backed) */
int chrRam_battery; /* chr ram size (non-volatile or battery backed) */
int PRGRomSize; /* total prg rom size in 16 K chunks */
int CHRRomSize; /* total chr rom size in 8 K chunks */
int PRGRamSize; /* prg ram size (volatile) */
int CHRRamSize; /* chr ram size (volatile) */
int PRGRamSaveSize; /* prg ram size (non-volatile or battery backed) */
int CHRRamSaveSize; /* chr ram size (non-volatile or battery backed) */
int region; /* video system timing (ntsc, pal, dendy */
uint8 MD5[16];
uint32 PRGCRC32;
uint32 CHRCRC32;
uint32 CRC32; /* Should be set by the iNES/UNIF loading
* code, used by mapper/board code, maybe
* other code in the future.

View File

@@ -417,7 +417,7 @@ int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int compare
if (name) {
char *t;
if ((t = (char*)realloc(next->name, strlen(name + 1)))) {
if ((t = (char*)realloc(next->name, strlen(name) + 1))) {
next->name = t;
strcpy(next->name, name);
} else

View File

@@ -83,16 +83,19 @@ static const unsigned long crc_table[256] = {
static unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len)
{
if (buf == 0) return 0L;
crc = crc ^ 0xffffffffL;
while (len >= 8)
{
DO8_CRC32(buf);
len -= 8;
}
if (len) do {
DO1_CRC32(buf);
} while (--len);
const unsigned char *p;
crc = crc ^ 0xffffffffL;
p = (const unsigned char*)buf;
if (p) {
while (len >= 8)
{
DO8_CRC32(p);
len -= 8;
}
if (len) do {
DO1_CRC32(p);
} while (--len);
}
return crc ^ 0xffffffffL;
}

View File

@@ -2089,8 +2089,6 @@ static char slash = '\\';
static char slash = '/';
#endif
extern uint32_t iNESGameCRC32;
bool retro_load_game(const struct retro_game_info *game)
{
unsigned i, j;
@@ -2227,7 +2225,7 @@ bool retro_load_game(const struct retro_game_info *game)
for (i = 0; i < fourscore_len; i++)
{
if (fourscore_db_list[i].crc == iNESGameCRC32)
if (fourscore_db_list[i].crc == iNESCart.CRC32)
{
FCEUI_DisableFourScore(0);
enable_4player = true;
@@ -2237,7 +2235,7 @@ bool retro_load_game(const struct retro_game_info *game)
for (i = 0; i < famicom_4p_len; i++)
{
if (famicom_4p_db_list[i].crc == iNESGameCRC32)
if (famicom_4p_db_list[i].crc == iNESCart.CRC32)
{
GameInfo->inputfc = SIFC_4PLAYER;
FCEUI_SetInputFC(SIFC_4PLAYER, &JSReturn, 0);

View File

@@ -114,8 +114,6 @@ static void iNESGI(int h) {
}
}
uint32 iNESGameCRC32 = 0;
struct CRCMATCH {
uint32 crc;
char *name;
@@ -205,7 +203,7 @@ static void SetInput(void) {
int x = 0;
while (moo[x].input1 >= 0 || moo[x].input2 >= 0 || moo[x].inputfc >= 0) {
if (moo[x].crc32 == iNESGameCRC32) {
if (moo[x].crc32 == iNESCart.CRC32) {
GameInfo->input[0] = moo[x].input1;
GameInfo->input[1] = moo[x].input2;
GameInfo->inputfc = moo[x].inputfc;
@@ -307,7 +305,7 @@ static void CheckHInfo(void) {
x = 0;
do {
if (moo[x].crc32 == iNESGameCRC32) {
if (moo[x].crc32 == iNESCart.CRC32) {
if (moo[x].mapper >= 0) {
if (moo[x].mapper & 0x800 && VROM_size) {
VROM_size = 0;
@@ -810,10 +808,10 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
chrRom |= ((uint32)head.upper_PRG_CHR_size << 4) & 0xF00;
subMapper = (head.ROM_type3 >> 4) & 0x0F;
iNESCart.prgRam = (head.PRGRAM_size & 0x0F) ? (64 << (head.PRGRAM_size & 0x0F)) : 0;
iNESCart.chrRam = (head.CHRRAM_size & 0x0F) ? (64 << (head.CHRRAM_size & 0x0F)) : 0;
iNESCart.prgRam_battery = (head.PRGRAM_size & 0xF0) ? (64 << ((head.PRGRAM_size & 0xF0) >> 4)) : 0;
iNESCart.chrRam_battery = (head.CHRRAM_size & 0xF0) ? (64 << ((head.CHRRAM_size & 0xF0) >> 4)) : 0;
iNESCart.PRGRamSize = (head.PRGRAM_size & 0x0F) ? (64 << (head.PRGRAM_size & 0x0F)) : 0;
iNESCart.CHRRamSize = (head.CHRRAM_size & 0x0F) ? (64 << (head.CHRRAM_size & 0x0F)) : 0;
iNESCart.PRGRamSaveSize = (head.PRGRAM_size & 0xF0) ? (64 << ((head.PRGRAM_size & 0xF0) >> 4)) : 0;
iNESCart.CHRRamSaveSize = (head.CHRRAM_size & 0xF0) ? (64 << ((head.CHRRAM_size & 0xF0) >> 4)) : 0;
region = (head.Region & 3);
} else {
if (!prgRom)
@@ -834,8 +832,8 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
} else if (romSize < filesize)
FCEU_PrintError(" File contains %llu bytes of unused data\n", filesize - romSize);
iNESCart.prgRom = prgRom;
iNESCart.chrRom = chrRom;
iNESCart.PRGRomSize = prgRom;
iNESCart.CHRRomSize = chrRom;
ROM_size = uppow2(prgRom);
@@ -864,19 +862,60 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
if (VROM_size)
FCEU_fread(VROM, 0x2000, chrRom, fp);
iNESCart.PRGCRC32 = CalcCRC32(0, ROM, prgRom * 0x4000);
iNESCart.CHRCRC32 = CalcCRC32(0, VROM, chrRom * 0x2000);
iNESCart.CRC32 = CalcCRC32(iNESCart.PRGCRC32, VROM, chrRom * 0x2000);
md5_starts(&md5);
md5_update(&md5, ROM, prgRom << 14);
iNESGameCRC32 = CalcCRC32(0, ROM, prgRom << 14);
if (VROM_size) {
iNESGameCRC32 = CalcCRC32(iNESGameCRC32, VROM, chrRom << 13);
if (VROM_size)
md5_update(&md5, VROM, chrRom << 13);
}
md5_finish(&md5, iNESCart.MD5);
memcpy(&GameInfo->MD5, &iNESCart.MD5, sizeof(iNESCart.MD5));
iNESCart.CRC32 = iNESGameCRC32;
mappername = "Not Listed";
for (mappertest = 0; mappertest < (sizeof bmap / sizeof bmap[0]) - 1; mappertest++) {
if (bmap[mappertest].number == MapperNo) {
mappername = (char*)bmap[mappertest].name;
break;
}
}
FCEU_printf(" PRG-ROM CRC32: 0x%08X\n", iNESCart.PRGCRC32);
FCEU_printf(" PRG+CHR CRC32: 0x%08X\n", iNESCart.CRC32);
FCEU_printf(" PRG+CHR MD5: 0x%s\n", md5_asciistr(iNESCart.MD5));
FCEU_printf(" PRG-ROM: %3d x 16KiB\n", prgRom);
FCEU_printf(" CHR-ROM: %3d x 8KiB\n", chrRom);
if (iNES2) {
const char *tv_region[] = { "NTSC", "PAL", "Multi-region", "Dendy" };
unsigned PRGRAM = iNESCart.PRGRamSize + iNESCart.PRGRamSaveSize;
unsigned CHRRAM = iNESCart.CHRRamSize + iNESCart.CHRRamSaveSize;
FCEU_printf(" NES 2.0 extended iNES.\n");
FCEU_printf(" Mapper #: %3d\n", MapperNo);
FCEU_printf(" Sub Mapper #: %3d\n", subMapper);
FCEU_printf(" Mapper name: %s\n", mappername);
if (PRGRAM || CHRRAM) {
FCEU_printf(" PRG RAM: %d KB\n", PRGRAM / 1024);
FCEU_printf(" CHR RAM: %d KB\n", CHRRAM / 1024);
if (head.ROM_type & 0x02) {
FCEU_printf(" PRG RAM backed by battery: %d KiB\n", iNESCart.PRGRamSaveSize / 1024);
FCEU_printf(" CHR RAM backed by battery: %d KiB\n", iNESCart.CHRRamSaveSize / 1024);
}
}
FCEU_printf(" Mirroring: %s\n", Mirroring == 2 ? "None (Four-screen)" : Mirroring ? "Vertical" : "Horizontal");
FCEU_printf(" System: %s\n", tv_region[region]);
FCEU_printf(" Trained: %s\n", (head.ROM_type & 4) ? "Yes" : "No");
} else {
FCEU_printf(" Mapper #: %3d\n", MapperNo);
FCEU_printf(" Mapper name: %s\n", mappername);
FCEU_printf(" Mirroring: %s\n", Mirroring == 2 ? "None (Four-screen)" : Mirroring ? "Vertical" : "Horizontal");
FCEU_printf(" Battery-backed: %s\n", (head.ROM_type & 2) ? "Yes" : "No");
FCEU_printf(" Trained: %s\n", (head.ROM_type & 4) ? "Yes" : "No");
}
SetInput();
CheckHInfo();
@@ -911,48 +950,6 @@ int iNESLoad(const char *name, FCEUFILE *fp) {
iNESCart.battery = (head.ROM_type & 2) ? 1 : 0;
iNESCart.mirror = Mirroring;
mappername = "Not Listed";
for (mappertest = 0; mappertest < (sizeof bmap / sizeof bmap[0]) - 1; mappertest++) {
if (bmap[mappertest].number == MapperNo) {
mappername = (char*)bmap[mappertest].name;
break;
}
}
if (iNES2) FCEU_printf(" NES 2.0 extended iNES.\n");
FCEU_printf(" ROM CRC32: 0x%08lx\n", iNESGameCRC32);
FCEU_printf(" ROM MD5: 0x%s\n", md5_asciistr(iNESCart.MD5));
FCEU_printf(" PRG ROM: %3d x 16KiB\n", prgRom);
FCEU_printf(" CHR ROM: %3d x 8KiB\n", chrRom);
if (iNES2) {
const char *tv_region[] = { "NTSC", "PAL", "Multi-region", "Dendy" };
unsigned PRGRAM = iNESCart.prgRam + iNESCart.prgRam_battery;
unsigned CHRRAM = iNESCart.chrRam + iNESCart.chrRam_battery;
FCEU_printf(" Mapper #: %3d\n", MapperNo);
FCEU_printf(" Sub Mapper #: %3d\n", subMapper);
FCEU_printf(" Mapper name: %s\n", mappername);
if (PRGRAM || CHRRAM) {
FCEU_printf(" PRG RAM: %d KiB\n", PRGRAM / 1024);
FCEU_printf(" CHR RAM: %d KiB\n", CHRRAM / 1024);
if (head.ROM_type & 0x02) {
FCEU_printf(" PRG RAM backed by battery: %d KiB\n", iNESCart.prgRam_battery / 1024);
FCEU_printf(" CHR RAM backed by battery: %d KiB\n", iNESCart.chrRam_battery / 1024);
}
}
FCEU_printf(" Mirroring: %s\n", Mirroring == 2 ? "None (Four-screen)" : Mirroring ? "Vertical" : "Horizontal");
FCEU_printf(" System: %s\n", tv_region[region]);
FCEU_printf(" Trained: %s\n", (head.ROM_type & 4) ? "Yes" : "No");
} else {
FCEU_printf(" Mapper #: %3d\n", MapperNo);
FCEU_printf(" Mapper name: %s\n", mappername);
FCEU_printf(" Mirroring: %s\n", Mirroring == 2 ? "None (Four-screen)" : Mirroring ? "Vertical" : "Horizontal");
FCEU_printf(" Battery-backed: %s\n", (head.ROM_type & 2) ? "Yes" : "No");
FCEU_printf(" Trained: %s\n", (head.ROM_type & 4) ? "Yes" : "No");
}
if (!iNES_Init(MapperNo)) {
FCEU_printf("\n");
FCEU_PrintError(" iNES mapper #%d is not supported at all.\n", MapperNo);
@@ -1014,7 +1011,7 @@ static int iNES_Init(int num) {
UNIFchrrama = 0; /* need here for compatibility with UNIF mapper code */
if (!VROM_size) {
if (iNESCart.iNES2) {
CHRRAMSize = iNESCart.chrRam + iNESCart.chrRam_battery;
CHRRAMSize = iNESCart.CHRRamSize + iNESCart.CHRRamSaveSize;
} else {
switch (num) { /* FIXME, mapper or game data base with the board parameters and ROM/RAM sizes */
case 13: CHRRAMSize = 16 * 1024; break;
@@ -1029,7 +1026,7 @@ static int iNES_Init(int num) {
case 268: CHRRAMSize = 256 * 1024; break;
default: CHRRAMSize = 8 * 1024; break;
}
iNESCart.chrRam = CHRRAMSize;
iNESCart.CHRRamSize = CHRRAMSize;
FCEU_printf(" CHR-RAM: %3d KiB\n", CHRRAMSize / 1024);
}
if (CHRRAMSize) { /* TODO: CHR-RAM are sometimes handled in mappers e.g. MMC1 using submapper 1/2/4 and CHR-RAM can be zero here */

View File

@@ -1,3 +1,6 @@
#ifndef _SHARE_H
#define _SHARE_H
#include "../fceu-types.h"
#include "../input.h"
#include "../fceu.h"
@@ -9,3 +12,5 @@
void FCEUMOV_AddJoy(uint8 *js);
void FCEU_DrawCursor(uint8 *buf, int xc, int yc);
void FCEU_DrawGunSight(uint8 *buf, int xc, int yc);
#endif /* _SHARE_H */

View File

@@ -740,10 +740,10 @@ int UNIFLoad(const char *name, FCEUFILE *fp) {
if (!LoadUNIFChunks(fp))
goto aborto;
UNIFCart.prgRom = (UNIF_PRGROMSize / 0x1000) + ((UNIF_PRGROMSize % 0x1000) ? 1 : 0);
UNIFCart.prgRom = (UNIFCart.prgRom >> 2) + ((UNIFCart.prgRom & 3) ? 1: 0);
UNIFCart.chrRom = (UNIF_CHRROMSize / 0x400) + ((UNIF_CHRROMSize % 0x400) ? 1 : 0);
UNIFCart.chrRom = (UNIFCart.chrRom >> 3) + ((UNIFCart.chrRom & 7) ? 1: 0);
UNIFCart.PRGRomSize = (UNIF_PRGROMSize / 0x1000) + ((UNIF_PRGROMSize % 0x1000) ? 1 : 0);
UNIFCart.PRGRomSize = (UNIFCart.PRGRomSize >> 2) + ((UNIFCart.PRGRomSize & 3) ? 1: 0);
UNIFCart.CHRRomSize = (UNIF_CHRROMSize / 0x400) + ((UNIF_CHRROMSize % 0x400) ? 1 : 0);
UNIFCart.CHRRomSize = (UNIFCart.CHRRomSize >> 3) + ((UNIFCart.CHRRomSize & 7) ? 1: 0);
ROM_size = FixRomSize(UNIF_PRGROMSize, 2048);
if (UNIF_CHRROMSize)
@@ -771,6 +771,10 @@ int UNIFLoad(const char *name, FCEUFILE *fp) {
}
}
UNIFCart.PRGCRC32 = CalcCRC32(0, ROM, UNIF_PRGROMSize);
UNIFCart.CHRCRC32 = CalcCRC32(0, VROM, UNIF_CHRROMSize);
UNIFCart.CRC32 = CalcCRC32(UNIFCart.PRGCRC32, VROM, UNIF_CHRROMSize);
md5_starts(&md5);
md5_update(&md5, ROM, UNIF_PRGROMSize);
if (VROM_size)
@@ -787,13 +791,14 @@ int UNIFLoad(const char *name, FCEUFILE *fp) {
if (!InitializeBoard())
goto aborto;
FCEU_printf(" PRG-ROM CRC32: 0x%08X\n", UNIFCart.PRGCRC32);
FCEU_printf(" PRG+CHR CRC32: 0x%08X\n", UNIFCart.CRC32);
FCEU_printf(" PRG+CHR MD5 : 0x%s\n", md5_asciistr(UNIFCart.MD5));
if (UNIFCart.mapper)
FCEU_printf(" [Unif] Mapper: %d\n", UNIFCart.mapper);
FCEU_printf(" [Unif] SubMapper: %d\n", UNIFCart.submapper);
FCEU_printf(" [Unif] PRG ROM: %d KiB\n", UNIF_PRGROMSize / 1024);
if (VROM_size)
FCEU_printf(" [Unif] CHR ROM: %d KiB\n", UNIF_CHRROMSize / 1024);
FCEU_printf(" [Unif] ROM MD5: 0X%s\n", md5_asciistr(UNIFCart.MD5));
FCEU_printf(" [Unif] PRG ROM: %ull KiB\n", UNIF_PRGROMSize / 1024);
FCEU_printf(" [Unif] CHR ROM: %ull KiB\n", UNIF_CHRROMSize / 1024);
GameInterface = UNIFGI;
return 1;