Refactoring: move extra CHR-RAM and WRAM into one CartRAM module.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static void sync () {
|
||||
VRC24_syncWRAM(0);
|
||||
|
||||
@@ -20,10 +20,8 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 *CHRRAM;
|
||||
static uint32 CHRRAMSize;
|
||||
static uint8 mask;
|
||||
static uint8 compare;
|
||||
|
||||
@@ -72,36 +70,16 @@ void Mapper253_power (void) {
|
||||
SetWriteHandler(0x2007, 0x2007, Mapper252_253_interceptPPUWrite);
|
||||
}
|
||||
|
||||
void Mapper252_253_close(void) {
|
||||
if (CHRRAM) {
|
||||
FCEU_gfree(CHRRAM);
|
||||
CHRRAM =NULL;
|
||||
}
|
||||
WRAM_close();
|
||||
}
|
||||
|
||||
void Mapper252_Init (CartInfo *info) {
|
||||
VRC4_init(info, sync, 0x4, 0x8, 1, NULL, NULL, NULL, NULL, NULL);
|
||||
WRAM_init(info, 8);
|
||||
CartRAM_init(info, 8, 2);
|
||||
info->Power =Mapper252_power;
|
||||
info->Close =Mapper252_253_close;
|
||||
AddExState(stateRegs, ~0, 0, 0);
|
||||
|
||||
CHRRAMSize =info->iNES2? (info->CHRRamSize +info->CHRRamSaveSize): 2048;
|
||||
CHRRAM =(uint8*)FCEU_gmalloc(CHRRAMSize);
|
||||
AddExState(CHRRAM, CHRRAMSize, 0, "CRAM");
|
||||
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
|
||||
}
|
||||
|
||||
void Mapper253_Init (CartInfo *info) {
|
||||
VRC4_init(info, sync, 0x4, 0x8, 1, NULL, NULL, NULL, NULL, NULL);
|
||||
WRAM_init(info, 8);
|
||||
CartRAM_init(info, 8, 2);
|
||||
info->Power =Mapper253_power;
|
||||
info->Close =Mapper252_253_close;
|
||||
AddExState(stateRegs, ~0, 0, 0);
|
||||
|
||||
CHRRAMSize =info->iNES2? (info->CHRRamSize +info->CHRRamSaveSize): 2048;
|
||||
CHRRAM =(uint8*)FCEU_gmalloc(CHRRAMSize);
|
||||
AddExState(CHRRAM, CHRRAMSize, 0, "CRAM");
|
||||
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include "asic_vrc6.h"
|
||||
#include "asic_vrc7.h"
|
||||
#include "flashrom.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 submapper;
|
||||
static uint8 reg[8];
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
static uint8 dip;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "asic_vrc3.h"
|
||||
#include "asic_vrc6.h"
|
||||
#include "asic_vrc7.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 submapper;
|
||||
static uint8 reg[4]; /* Supervisor registers */
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_mmc3.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_mmc3.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
|
||||
|
||||
@@ -22,10 +22,9 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_mmc3.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
static uint8 *CHRRAM = NULL;
|
||||
|
||||
static void sync () {
|
||||
MMC3_syncPRG(0x3F, 0x00);
|
||||
@@ -64,22 +63,10 @@ static void power () {
|
||||
SetWriteHandler(0x4020, 0x5FFF, writeReg);
|
||||
}
|
||||
|
||||
static void close () {
|
||||
if (CHRRAM) {
|
||||
FCEU_gfree(CHRRAM);
|
||||
CHRRAM = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Mapper512_Init (CartInfo *info) {
|
||||
MMC3_init(info, sync, MMC3_TYPE_AX5202P, NULL, NULL, NULL, NULL);
|
||||
WRAM_init(info, 8);
|
||||
CartRAM_init(info, 8, 8);
|
||||
info->Power = power;
|
||||
info->Reset = reset;
|
||||
info->Close = close;
|
||||
AddExState(®, 1, 0, "EXPR");
|
||||
|
||||
CHRRAM = (uint8 *)FCEU_gmalloc(8192);
|
||||
SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
|
||||
AddExState(CHRRAM, 8192, 0, "CRAM");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_latch.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 chr;
|
||||
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 *CHRRAM;
|
||||
static uint32 CHRRAMSize;
|
||||
static uint8 nt[4];
|
||||
static uint8 prg;
|
||||
static uint8 mask;
|
||||
@@ -48,7 +47,7 @@ static void sync () {
|
||||
}
|
||||
|
||||
static const uint8 compares[8] = { 0x28, 0x00, 0x4C, 0x64, 0x46, 0x7C, 0x04, 0xFF };
|
||||
static DECLFW(Mapper544_interceptPPUWrite) {
|
||||
static DECLFW (interceptPPUWrite) {
|
||||
if (~RefreshAddr &0x2000) {
|
||||
int bank =VRC24_getCHRBank(RefreshAddr >>10 &7);
|
||||
if (bank &0x80) {
|
||||
@@ -66,11 +65,11 @@ static DECLFW(Mapper544_interceptPPUWrite) {
|
||||
writePPU(A, V);
|
||||
}
|
||||
|
||||
int Mapper544_getPRGBank(uint8 bank) {
|
||||
static int getPRGBank (uint8 bank) {
|
||||
return bank ==2? prg: VRC24_getPRGBank(bank);
|
||||
}
|
||||
|
||||
DECLFW(Mapper544_externalSelect) {
|
||||
static DECLFW (externalSelect) {
|
||||
if (A &4)
|
||||
nt[A &3] =V;
|
||||
else
|
||||
@@ -79,7 +78,7 @@ DECLFW(Mapper544_externalSelect) {
|
||||
}
|
||||
|
||||
|
||||
void Mapper544_power (void) {
|
||||
void power (void) {
|
||||
mask =0xFC;
|
||||
compare =0x28;
|
||||
nt[0] =nt[1] =0xE0;
|
||||
@@ -87,24 +86,12 @@ void Mapper544_power (void) {
|
||||
prg =0xFE;
|
||||
VRC24_power();
|
||||
writePPU =GetWriteHandler(0x2007);
|
||||
SetWriteHandler(0x2007, 0x2007, Mapper544_interceptPPUWrite);
|
||||
}
|
||||
|
||||
void Mapper544_close(void) {
|
||||
if (CHRRAM) {
|
||||
FCEU_gfree(CHRRAM);
|
||||
CHRRAM =NULL;
|
||||
}
|
||||
SetWriteHandler(0x2007, 0x2007, interceptPPUWrite);
|
||||
}
|
||||
|
||||
void Mapper544_Init (CartInfo *info) {
|
||||
VRC4_init(info, sync, 0x400, 0x800, 1, Mapper544_getPRGBank, NULL, NULL, NULL, Mapper544_externalSelect);
|
||||
info->Power =Mapper544_power;
|
||||
info->Close =Mapper544_close;
|
||||
VRC4_init(info, sync, 0x400, 0x800, 1, getPRGBank, NULL, NULL, NULL, externalSelect);
|
||||
CartRAM_init(info, 8, 2);
|
||||
info->Power =power;
|
||||
AddExState(stateRegs, ~0, 0, 0);
|
||||
|
||||
CHRRAMSize =info->CHRRamSize +info->CHRRamSaveSize;
|
||||
CHRRAM =(uint8*)FCEU_gmalloc(CHRRAMSize);
|
||||
AddExState(CHRRAM, CHRRAMSize, 0, "CRAM");
|
||||
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_mmc3.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_mmc1.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
#include "../fds_apu.h"
|
||||
|
||||
static uint8 reg;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "mapinc.h"
|
||||
#include "asic_mmc3.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 reg[4];
|
||||
static uint8 index;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_n118.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static void sync() {
|
||||
setprg8r(0x10, 0x6000, 0);
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_FME7.h"
|
||||
#include "wram.h"
|
||||
|
||||
static void (*FME7_cbSync)();
|
||||
static uint8 FME7_index;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc2and4.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static void (*VRC24_cbSync)();
|
||||
static int VRC24_A0, VRC24_A1;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_vrc6.h"
|
||||
#include "wram.h"
|
||||
|
||||
static void (*VRC6_cbSync)();
|
||||
static int VRC6_A0, VRC6_A1;
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "asic_VRC7.h"
|
||||
#include "wram.h"
|
||||
#include "asic_vrc7.h"
|
||||
|
||||
static void (*VRC7_cbSync)();
|
||||
static int VRC7_A0;
|
||||
|
||||
@@ -19,22 +19,27 @@
|
||||
*/
|
||||
|
||||
#include "mapinc.h"
|
||||
#include "wram.h"
|
||||
#include "cartram.h"
|
||||
|
||||
static uint8 *CHRRAMData = NULL;
|
||||
static uint8 *WRAMData = NULL;
|
||||
uint32 CHRRAMSize = 0;
|
||||
uint32 WRAMSize = 0;
|
||||
|
||||
void WRAM_close (void) {
|
||||
void CartRAM_close (void) { /* Need to combine this in one function to avoid the problem of having to properly cascade two separate Close() functions for WRAM and CHR-RAM each */
|
||||
if (WRAMData) {
|
||||
FCEU_gfree(WRAMData);
|
||||
WRAMData =NULL;
|
||||
}
|
||||
if (CHRRAMData) {
|
||||
FCEU_gfree(CHRRAMData);
|
||||
CHRRAMData =NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void WRAM_init (CartInfo *info, uint8 defaultWRAMSizeKiB) {
|
||||
void CartRAM_init (CartInfo *info, uint8 defaultWRAMSizeKiB, uint8 defaultCHRRAMSizeKiB) {
|
||||
WRAMSize =info->iNES2? (info->PRGRamSize +info->PRGRamSaveSize): (defaultWRAMSizeKiB *1024);
|
||||
if (WRAMSize) {
|
||||
info->Close =WRAM_close;
|
||||
WRAMData =(uint8*)FCEU_gmalloc(WRAMSize);
|
||||
SetupCartPRGMapping(0x10, WRAMData, WRAMSize, 1);
|
||||
AddExState(WRAMData, WRAMSize, 0, "WRAM");
|
||||
@@ -43,4 +48,24 @@ void WRAM_init (CartInfo *info, uint8 defaultWRAMSizeKiB) {
|
||||
info->SaveGameLen[0] =WRAMSize;
|
||||
}
|
||||
}
|
||||
CHRRAMSize =info->iNES2? (info->CHRRamSize +info->CHRRamSaveSize): (defaultCHRRAMSizeKiB *1024);
|
||||
if (ROM_size == 0) CHRRAMSize = 0; /* If there is no CHR-ROM, then any CHR-RAM will not be "extra" and therefore will be handled by ines.c, not here. */
|
||||
if (CHRRAMSize) {
|
||||
CHRRAMData =(uint8*)FCEU_gmalloc(CHRRAMSize);
|
||||
SetupCartCHRMapping(0x10, CHRRAMData, CHRRAMSize, 1);
|
||||
AddExState(CHRRAMData, CHRRAMSize, 0, "CRAM");
|
||||
if (info->battery) {
|
||||
info->SaveGame[info->SaveGameLen[0]? 1: 0] =CHRRAMData;
|
||||
info->SaveGameLen[info->SaveGameLen[0]? 1: 0] =CHRRAMSize;
|
||||
}
|
||||
}
|
||||
if (WRAMSize || CHRRAMSize) info->Close =CartRAM_close;
|
||||
}
|
||||
|
||||
void CHRRAM_init (CartInfo *info, uint8 defaultCHRRAMSizeKiB) {
|
||||
CartRAM_init(info, 0, defaultCHRRAMSizeKiB);
|
||||
}
|
||||
|
||||
void WRAM_init (CartInfo *info, uint8 defaultWRAMSizeKiB) {
|
||||
CartRAM_init(info, defaultWRAMSizeKiB, 0);
|
||||
}
|
||||
@@ -18,11 +18,14 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _WRAM_H
|
||||
#define _WRAM_H
|
||||
#ifndef _CARTRAM_H
|
||||
#define _CARTRAM_H
|
||||
|
||||
extern uint32 CHRRAMSize;
|
||||
extern uint32 WRAMSize;
|
||||
void CartRAM_init (CartInfo *, uint8, uint8);
|
||||
void CHRRAM_init (CartInfo *, uint8);
|
||||
void WRAM_init (CartInfo *, uint8);
|
||||
void WRAM_close ();
|
||||
void CartRAM_close ();
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user