couple of mapper fixes (#482)
* Fix a couple of mapper issues - Implement info->Close, to free any unallocated memory (e.g. WRAM) - Add missing GameStateRestore function - Add missing state variable * Simplify header parsing * Update ines-correct.h Co-authored-by: negativeExponent <negativeExponent@users.noreply.github.com>
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#include "mapinc.h"
|
||||
#include "../ines.h"
|
||||
|
||||
static uint8 *WRAM;
|
||||
static uint32 WRAMSIZE;
|
||||
static uint8 reg[4];
|
||||
static SFORMAT StateRegs[] =
|
||||
{
|
||||
@@ -83,20 +85,36 @@ static void reset(void)
|
||||
sync();
|
||||
}
|
||||
|
||||
static void close(void)
|
||||
{
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
static void StateRestore(int version)
|
||||
{
|
||||
sync();
|
||||
}
|
||||
|
||||
void Mapper162_Init (CartInfo *info)
|
||||
{
|
||||
uint8 *WRAM;
|
||||
uint32 WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
info->Close = close;
|
||||
GameHBIRQHook = hblank;
|
||||
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
|
||||
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = info->PRGRamSaveSize;
|
||||
info->SaveGameLen[0] = WRAMSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "mapinc.h"
|
||||
#include "../ines.h"
|
||||
|
||||
static uint8 *WRAM;
|
||||
static uint32 WRAMSIZE;
|
||||
static uint8 reg[4];
|
||||
static SFORMAT StateRegs[] =
|
||||
{
|
||||
@@ -88,20 +90,36 @@ static void reset(void)
|
||||
sync();
|
||||
}
|
||||
|
||||
static void close(void)
|
||||
{
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
static void StateRestore(int version)
|
||||
{
|
||||
sync();
|
||||
}
|
||||
|
||||
void Mapper163_Init (CartInfo *info)
|
||||
{
|
||||
uint8 *WRAM;
|
||||
uint32 WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
info->Close = close;
|
||||
GameHBIRQHook = hblank;
|
||||
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
WRAMSIZE = info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize): 8192;
|
||||
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
|
||||
if (info->battery) {
|
||||
info->SaveGame[0] = WRAM;
|
||||
info->SaveGameLen[0] = info->PRGRamSaveSize;
|
||||
info->SaveGameLen[0] = WRAMSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "mapinc.h"
|
||||
#include "eeprom_93C66.h"
|
||||
|
||||
static uint8 *WRAM;
|
||||
static uint32 WRAMSIZE;
|
||||
static uint8 reg[8];
|
||||
static uint8 eeprom_data[512];
|
||||
static SFORMAT StateRegs[] =
|
||||
@@ -101,16 +103,31 @@ static void reset(void)
|
||||
sync();
|
||||
}
|
||||
|
||||
static void close(void)
|
||||
{
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
static void StateRestore(int version)
|
||||
{
|
||||
sync();
|
||||
}
|
||||
|
||||
void Mapper164_Init (CartInfo *info)
|
||||
{
|
||||
uint8 *WRAM;
|
||||
uint32 WRAMSIZE = info->iNES2? (info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF)): 8192;
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
info->Close = close;
|
||||
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
WRAMSIZE = info->iNES2? (info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF)): 8192;
|
||||
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
|
||||
eeprom_93C66_storage = eeprom_data;
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
|
||||
static uint8 *WRAM;
|
||||
static uint32 WRAMSIZE;
|
||||
static uint8 latch[2];
|
||||
|
||||
static void Mapper452_Sync(void) {
|
||||
@@ -62,18 +64,35 @@ static void Mapper452_Reset(void) {
|
||||
}
|
||||
|
||||
static void Mapper452_Power(void) {
|
||||
uint8* WRAM = (uint8*) FCEU_gmalloc(8192);
|
||||
|
||||
latch[0] =latch[1] =0;
|
||||
Mapper452_Sync();
|
||||
SetReadHandler(0x8000, 0xFFFF, CartBR);
|
||||
SetWriteHandler(0x8000, 0xDFFF, Mapper452_WriteLatch);
|
||||
SetWriteHandler(0xE000, 0xFFFF, CartBW);
|
||||
|
||||
SetupCartPRGMapping(0x10, (uint8*) FCEU_gmalloc(8192), 8192, 1);
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
}
|
||||
|
||||
static void Mapper452_Close(void) {
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
static void StateRestore(int version) {
|
||||
Mapper452_Sync();
|
||||
}
|
||||
|
||||
void Mapper452_Init(CartInfo *info) {
|
||||
info->Reset = Mapper452_Reset;
|
||||
info->Power = Mapper452_Power;
|
||||
info->Close = Mapper452_Close;
|
||||
GameStateRestore = StateRestore;
|
||||
|
||||
WRAMSIZE = 8192;
|
||||
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
|
||||
AddExState(&latch, 2, 0, "LATC");
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "eeprom_93C66.h"
|
||||
#include "../ines.h"
|
||||
|
||||
static uint8 *WRAM;
|
||||
static uint32 WRAMSIZE;
|
||||
static uint8 reg[4];
|
||||
static uint8 haveEEPROM;
|
||||
static uint8 eeprom_data[512];
|
||||
@@ -97,17 +99,32 @@ static void reset(void)
|
||||
sync();
|
||||
}
|
||||
|
||||
static void close(void)
|
||||
{
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
static void StateRestore(int version)
|
||||
{
|
||||
sync();
|
||||
}
|
||||
|
||||
void Mapper558_Init (CartInfo *info)
|
||||
{
|
||||
uint8 *WRAM;
|
||||
uint32 WRAMSIZE = info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF);
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
info->Close = close;
|
||||
GameHBIRQHook = hblank;
|
||||
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(StateRegs, ~0, 0, 0);
|
||||
|
||||
WRAMSIZE = info->PRGRamSize + (info->PRGRamSaveSize &~0x7FF);
|
||||
WRAM = (uint8*) FCEU_gmalloc(WRAMSIZE);
|
||||
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
|
||||
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
|
||||
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
|
||||
haveEEPROM =!!(info->PRGRamSaveSize &0x200);
|
||||
if (haveEEPROM)
|
||||
|
||||
@@ -139,6 +139,12 @@ static void UNLKS7032Power(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void UNLKS7032Close(void) {
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
static void StateRestore(int version) {
|
||||
Sync();
|
||||
}
|
||||
@@ -146,6 +152,7 @@ static void StateRestore(int version) {
|
||||
void UNLKS7032_Init(CartInfo *info) {
|
||||
KS7032 = 1;
|
||||
info->Power = UNLKS7032Power;
|
||||
info->Close = UNLKS7032Close;
|
||||
MapIRQHook = UNLSMB2JIRQHook;
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(&StateRegsKS7032, ~0, 0, 0);
|
||||
@@ -154,6 +161,7 @@ void UNLKS7032_Init(CartInfo *info) {
|
||||
void UNLKS202_Init(CartInfo *info) {
|
||||
KS7032 = 0;
|
||||
info->Power = UNLKS7032Power;
|
||||
info->Close = UNLKS7032Close;
|
||||
MapIRQHook = UNLSMB2JIRQHook;
|
||||
GameStateRestore = StateRestore;
|
||||
AddExState(&StateRegsKS7032, ~0, 0, 0);
|
||||
|
||||
@@ -409,6 +409,13 @@ static void JYASIC_reset (void)
|
||||
dipSwitch = (dipSwitch +0x40) &0xC0;
|
||||
}
|
||||
|
||||
static void JYASIC_close (void)
|
||||
{
|
||||
if (WRAM)
|
||||
FCEU_gfree(WRAM);
|
||||
WRAM = NULL;
|
||||
}
|
||||
|
||||
static void JYASIC_restore (int version)
|
||||
{
|
||||
sync();
|
||||
@@ -418,6 +425,7 @@ void JYASIC_init (CartInfo *info)
|
||||
{
|
||||
info->Reset = JYASIC_reset;
|
||||
info->Power = JYASIC_power;
|
||||
info->Close = JYASIC_close;
|
||||
PPU_hook = trapPPUAddressChange;
|
||||
MapIRQHook = cpuCycle;
|
||||
GameHBIRQHook2 = ppuScanline;
|
||||
|
||||
@@ -111,16 +111,18 @@
|
||||
{ 0x02863604, 2, DEFAULT, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Sukeban Deka III (Japan).nes */
|
||||
{ 0x419461d0, 2, DEFAULT, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Super Cars (USA).nes */
|
||||
|
||||
/* CNROM by default has bus conflicts enabled, these requires no bus conflict to play correctly */
|
||||
{ 0x2915faf0, 3, 1, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Incantation (Asia) (Ja) (Unl).nes */
|
||||
{ 0x8f154a0d, 3, 1, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Pu Ke Jing Ling (Asia) (Unl).nes */
|
||||
{ 0xb0c871c5, 3, 1, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Wei Lai Xiao Zi (Joy Van).nes */
|
||||
{ 0xb3be2f71, 3, 1, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Yanshan Chess (Unl).nes */
|
||||
{ 0xd04a40e6, 3, 1, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Bingo 75 (Asia) (Ja) (Unl).nes */
|
||||
{ 0xe41b440f, 3, 1, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Sidewinder (Joy Van).nes */
|
||||
{ 0xebd0644d, 3, 1, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Master Chu & The Drunkard Hu (Joy Van).nes */
|
||||
{ 0xf283cf58, 3, 1, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Colorful Dragon (Sachen).nes */
|
||||
{ 0x2deb12b8, 3, 1, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Venice Beach Volleyball (Asia) (Ja) (Super Mega) (Unl).nes */
|
||||
/* CNROM by default has bus conflicts disabled, set to submapper 2 to enable bus conflicts */
|
||||
{ 0xac8dcdea, 3, 2, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Cybernoid - The Fighting Machine (USA).nes */
|
||||
|
||||
{ 0x2915faf0, 3, 0, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Incantation (Asia) (Ja) (Unl).nes */
|
||||
{ 0x8f154a0d, 3, 0, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Pu Ke Jing Ling (Asia) (Unl).nes */
|
||||
{ 0xb0c871c5, 3, 0, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Wei Lai Xiao Zi (Joy Van).nes */
|
||||
{ 0xb3be2f71, 3, 0, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Yanshan Chess (Unl).nes */
|
||||
{ 0xd04a40e6, 3, 0, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Bingo 75 (Asia) (Ja) (Unl).nes */
|
||||
{ 0xe41b440f, 3, 0, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Sidewinder (Joy Van).nes */
|
||||
{ 0xebd0644d, 3, 0, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Master Chu & The Drunkard Hu (Joy Van).nes */
|
||||
{ 0xf283cf58, 3, 0, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Colorful Dragon (Sachen).nes */
|
||||
{ 0x2deb12b8, 3, 0, MI_V, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Venice Beach Volleyball (Asia) (Ja) (Super Mega) (Unl).nes */
|
||||
|
||||
{ 0xdbf90772, 3, DEFAULT, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* Alpha Mission (USA).nes */
|
||||
{ 0xd858033d, 3, DEFAULT, MI_H, 0, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }, /* ASO - Armored Scrum Object (J).nes */
|
||||
@@ -965,4 +967,4 @@
|
||||
|
||||
{ 0x00000000, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, NOEXTRA }
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
59
src/ines.c
59
src/ines.c
@@ -822,14 +822,7 @@ INES_BOARD_BEGIN()
|
||||
INES_BOARD( "YC-03-09", 558, Mapper558_Init )
|
||||
INES_BOARD_END()
|
||||
|
||||
static uint32 get_ines_version(void)
|
||||
{
|
||||
if ((head.ROM_type2 & 0x0C) == 0x08)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32 get_ines_mapper_id(void)
|
||||
static uint32 iNES_get_mapper_id(void)
|
||||
{
|
||||
/* If byte 7 AND $0C = $08, and the size taking into account byte 9 does not exceed the actual size of the ROM image, then NES 2.0.
|
||||
* If byte 7 AND $0C = $00, and bytes 12-15 are all 0, then iNES.
|
||||
@@ -849,26 +842,25 @@ static uint32 get_ines_mapper_id(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void rom_load_ines(void) {
|
||||
ROM_size = head.ROM_size;
|
||||
VROM_size = head.VROM_size;
|
||||
iNESCart.mirror = (head.ROM_type & 8) ? 2 : (head.ROM_type & 1);
|
||||
iNESCart.battery = (head.ROM_type & 2) ? 1 : 0;
|
||||
iNESCart.mapper = get_ines_mapper_id();
|
||||
}
|
||||
static void iNES_read_header_info(void) {
|
||||
ROM_size = head.ROM_size;
|
||||
VROM_size = head.VROM_size;
|
||||
iNESCart.mirror = (head.ROM_type & 8) ? 2 : (head.ROM_type & 1);
|
||||
iNESCart.battery = (head.ROM_type & 2) ? 1 : 0;
|
||||
iNESCart.mapper = iNES_get_mapper_id();
|
||||
iNESCart.iNES2 = (head.ROM_type2 & 0x0C) == 0x08;
|
||||
|
||||
static void rom_load_ines2(void) {
|
||||
ROM_size = head.ROM_size | ((head.upper_PRG_CHR_size >> 0) & 0xF) << 8;
|
||||
VROM_size = head.VROM_size | ((head.upper_PRG_CHR_size >> 4) & 0xF) << 8;
|
||||
iNESCart.mirror = (head.ROM_type & 8) ? 2 : (head.ROM_type & 1);
|
||||
iNESCart.battery = (head.ROM_type & 2) ? 1 : 0;
|
||||
iNESCart.mapper = get_ines_mapper_id();
|
||||
iNESCart.submapper = (head.ROM_type3 >> 4) & 0x0F;
|
||||
iNESCart.region = head.Region & 3;
|
||||
if (head.PRGRAM_size & 0x0F) iNESCart.PRGRamSize = 64 << ((head.PRGRAM_size >> 0) & 0x0F);
|
||||
if (head.PRGRAM_size & 0xF0) iNESCart.PRGRamSaveSize = 64 << ((head.PRGRAM_size >> 4) & 0x0F);
|
||||
if (head.CHRRAM_size & 0x0F) iNESCart.CHRRamSize = 64 << ((head.CHRRAM_size >> 0) & 0x0F);
|
||||
if (head.CHRRAM_size & 0xF0) iNESCart.CHRRamSaveSize = 64 << ((head.CHRRAM_size >> 4) & 0x0F);
|
||||
if (iNESCart.iNES2)
|
||||
{
|
||||
ROM_size |= ((head.upper_PRG_CHR_size >> 0) & 0xF) << 8;
|
||||
VROM_size |= ((head.upper_PRG_CHR_size >> 4) & 0xF) << 8;
|
||||
iNESCart.submapper = (head.ROM_type3 >> 4) & 0x0F;
|
||||
iNESCart.region = head.Region & 3;
|
||||
if (head.PRGRAM_size & 0x0F) iNESCart.PRGRamSize = 64 << ((head.PRGRAM_size >> 0) & 0x0F);
|
||||
if (head.PRGRAM_size & 0xF0) iNESCart.PRGRamSaveSize = 64 << ((head.PRGRAM_size >> 4) & 0x0F);
|
||||
if (head.CHRRAM_size & 0x0F) iNESCart.CHRRamSize = 64 << ((head.CHRRAM_size >> 0) & 0x0F);
|
||||
if (head.CHRRAM_size & 0xF0) iNESCart.CHRRamSaveSize = 64 << ((head.CHRRAM_size >> 4) & 0x0F);
|
||||
}
|
||||
}
|
||||
|
||||
int iNESLoad(const char *name, FCEUFILE *fp)
|
||||
@@ -879,8 +871,8 @@ int iNESLoad(const char *name, FCEUFILE *fp)
|
||||
char* mappername = NULL;
|
||||
uint32 mappertest = 0;
|
||||
#endif
|
||||
uint64 filesize = FCEU_fgetsize(fp);
|
||||
uint64 romSize = 0;
|
||||
uint64 filesize = FCEU_fgetsize(fp); /* size of file including header */
|
||||
uint64 romSize = 0; /* size of PRG + CHR rom */
|
||||
/* used for malloc and cart mapping */
|
||||
uint32 rom_size_pow2 = 0;
|
||||
uint32 vrom_size_pow2 = 0;
|
||||
@@ -888,8 +880,6 @@ int iNESLoad(const char *name, FCEUFILE *fp)
|
||||
if (FCEU_fread(&head, 1, 16, fp) != 16)
|
||||
return 0;
|
||||
|
||||
filesize -= 16; /* remove header size from total size */
|
||||
|
||||
if (memcmp(&head, "NES\x1a", 4))
|
||||
{
|
||||
FCEU_PrintError("Not an iNES file!\n");
|
||||
@@ -912,14 +902,13 @@ int iNESLoad(const char *name, FCEUFILE *fp)
|
||||
memset((char*)(&head) + 0xA, 0, 0x6);
|
||||
}
|
||||
|
||||
if ((iNESCart.iNES2 = get_ines_version()))
|
||||
rom_load_ines2();
|
||||
else
|
||||
rom_load_ines();
|
||||
iNES_read_header_info();
|
||||
|
||||
if (!ROM_size)
|
||||
ROM_size = 256;
|
||||
|
||||
filesize -= 16; /* remove header size from total size */
|
||||
|
||||
/* Trainer */
|
||||
if (head.ROM_type & 4)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user