Fix size inconsistency for prg and chr

- Unif shows ROM_size and VROM_size in bytes, while codebase expects these to be
in chunks of 16K for prg and 8K for chr. Update Unif to represent size as its
expected to be.

- Change PRGRomSize and CHRRomSize to represent sizes in bytes to make it consistent
with the rest of the size-related variables in struct CartInfo.
This commit is contained in:
negativeExponent
2020-03-05 21:07:33 +08:00
parent a0458bbf98
commit e9eb314311
5 changed files with 40 additions and 32 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->PRGRomSize * 16) == 1536) ? 1 : 0;
reorder_banks = ((info->PRGRomSize / 1024) == 1536) ? 1 : 0;
info->Power = M226Power;
info->Reset = M226Reset;
AddExState(&StateRegs, ~0, 0, 0);

View File

@@ -20,12 +20,12 @@ typedef struct {
* set to mapper 4.
*/
int battery; /* Presence of an actual battery. */
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 PRGRomSize; /* prg rom size in bytes */
int CHRRomSize; /* chr rom size in bytes */
int PRGRamSize; /* prg ram size in bytes (volatile) */
int CHRRamSize; /* chr ram size in bytes (volatile) */
int PRGRamSaveSize; /* prg ram size in bytes (non-volatile or battery backed) */
int CHRRamSaveSize; /* chr ram size in bytes (non-volatile or battery backed) */
int region; /* video system timing (ntsc, pal, dendy */
uint8 MD5[16];

View File

@@ -659,7 +659,7 @@ static BMAPPINGLocal bmap[] = {
{(uint8_t*)"OK-411", 361, GN45_Init}, /* OK-411 is emulated together with GN-45 */
{(uint8_t*)"HUMMER/JY-052", 281, Mapper281_Init},
{(uint8_t*)"GN-45", 366, GN45_Init},
{(uint8_t*)"GKCX1", 288, Mapper288_Init },
{(uint8_t*)"Bit Corp 4-in-1", 357, Mapper357_Init },
{(uint8_t*)"MMC3 PIRATE SFC-12", 372, Mapper372_Init },
@@ -856,8 +856,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.PRGRomSize = prgRom;
iNESCart.CHRRomSize = chrRom;
iNESCart.PRGRomSize = prgRom << 14;
iNESCart.CHRRomSize = chrRom << 13;
ROM_size = uppow2(prgRom);
@@ -886,11 +886,11 @@ 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);
if (VROM_size)

View File

@@ -40,8 +40,8 @@ typedef struct {
extern uint8 *ROM;
extern uint8 *VROM;
extern uint32 ROM_size;
extern uint32 VROM_size;
extern uint32 ROM_size; /* prg size in 16K chunks */
extern uint32 VROM_size; /* chr size in 8K chunks */
extern iNES_HEADER head;
void NSFVRC6_Init(void);

View File

@@ -743,18 +743,23 @@ int UNIFLoad(const char *name, FCEUFILE *fp) {
if (!LoadUNIFChunks(fp))
goto aborto;
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 = (UNIF_PRGROMSize / 0x1000) + ((UNIF_PRGROMSize % 0x1000) ? 1 : 0);
ROM_size = (ROM_size >> 2) + ((ROM_size & 3) ? 1: 0);
if (UNIF_CHRROMSize) {
VROM_size = (UNIF_CHRROMSize / 0x400) + ((UNIF_CHRROMSize % 0x400) ? 1 : 0);
VROM_size = (VROM_size >> 3) + ((VROM_size & 7) ? 1: 0);
}
ROM_size = FixRomSize(UNIF_PRGROMSize, 2048);
UNIFCart.PRGRomSize = UNIF_PRGROMSize;
UNIFCart.CHRRomSize = UNIF_CHRROMSize;
UNIF_PRGROMSize = FixRomSize(UNIF_PRGROMSize, 2048);
if (UNIF_CHRROMSize)
VROM_size = FixRomSize(UNIF_CHRROMSize, 8192);
UNIF_CHRROMSize = FixRomSize(UNIF_CHRROMSize, 8192);
ROM = (uint8*)malloc(ROM_size);
if (VROM_size)
VROM = (uint8*)malloc(VROM_size);
ROM = (uint8*)malloc(UNIF_PRGROMSize);
if (UNIF_CHRROMSize)
VROM = (uint8*)malloc(UNIF_CHRROMSize);
for (x = 0; x < 16; x++) {
unsigned p = prg_idx[x];
@@ -774,22 +779,24 @@ 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);
UNIFCart.PRGCRC32 = CalcCRC32(0, ROM, PRGptr);
UNIFCart.CHRCRC32 = CalcCRC32(0, VROM, CHRptr);
UNIFCart.CRC32 = CalcCRC32(UNIFCart.PRGCRC32, VROM, CHRptr);
FCEU_printf("CHR CRC32 = %08x\n", UNIFCart.CHRCRC32);
md5_starts(&md5);
md5_update(&md5, ROM, UNIF_PRGROMSize);
if (VROM_size)
md5_update(&md5, VROM, UNIF_CHRROMSize);
md5_update(&md5, ROM, PRGptr);
if (UNIF_CHRROMSize)
md5_update(&md5, VROM, CHRptr);
md5_finish(&md5, UNIFCart.MD5);
memcpy(GameInfo->MD5, UNIFCart.MD5, sizeof(UNIFCart.MD5));
CheckHashInfo();
SetupCartPRGMapping(0, ROM, ROM_size, 0);
if (VROM_size)
SetupCartCHRMapping(0, VROM, VROM_size, 0);
SetupCartPRGMapping(0, ROM, UNIF_PRGROMSize, 0);
if (UNIF_CHRROMSize)
SetupCartCHRMapping(0, VROM, UNIF_CHRROMSize, 0);
if (!InitializeBoard())
goto aborto;
@@ -804,6 +811,7 @@ int UNIFLoad(const char *name, FCEUFILE *fp) {
FCEU_printf(" [Unif] CHR ROM: %u KiB\n", UNIF_CHRROMSize / 1024);
GameInterface = UNIFGI;
return 1;
aborto: