Skip to content

Commit

Permalink
Improved management of the mapper's internal data structures.
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Nov 29, 2023
1 parent 3a76f6f commit f59c218
Show file tree
Hide file tree
Showing 368 changed files with 517 additions and 996 deletions.
6 changes: 3 additions & 3 deletions src/core/bck_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ void bck_states_op_keyframe(BYTE mode, void *data, size_t *index, uint64_t *size

// mapper
bck_states_on_struct(mode, mapper, data, (*index), (*size_buff))
for (unsigned int i = 0; i < LENGTH(mapper.internal_struct); i++) {
if (mapper.internal_struct[i]) {
bck_states_on_mem(mode, mapper.internal_struct[i], mapper.internal_struct_size[i], data, (*index), (*size_buff))
for (unsigned int i = 0; i < mapper.structs.count; i++) {
if (mapper.structs.s[i].data) {
bck_states_on_mem(mode, mapper.structs.s[i].data, mapper.structs.s[i].size, data, (*index), (*size_buff))
}
}

Expand Down
15 changes: 12 additions & 3 deletions src/core/mappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ BYTE map_init(void) {
// di default la routine di salvataggio
// di una possibile struttura interna
// di dati della mapper e' NULL.
for (unsigned int i = 0; i < LENGTH(mapper.internal_struct); i++) {
mapper.internal_struct[i] = 0;
}
map_internal_struct_quit();
// disabilito gli accessori
for (int nesidx = 0; nesidx < NES_CHIPS_MAX; nesidx++) {
nes[nesidx].irqA12.present = FALSE;
Expand Down Expand Up @@ -1371,3 +1369,14 @@ void map_quit(void) {
extcl_mapper_quit();
}
}

void map_internal_struct_init(BYTE *strct, size_t size) {
if (mapper.structs.count < INT_STRUCT) {
mapper.structs.s[mapper.structs.count].data = strct;
mapper.structs.s[mapper.structs.count].size = size;
mapper.structs.count++;
}
}
void map_internal_struct_quit(void) {
memset(&mapper.structs, 0x00, sizeof(_mapper_int_structs));
}
15 changes: 13 additions & 2 deletions src/core/mappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,27 @@
#include "mappers/VRC7.h"

enum mappers_op_battery { RD_BAT, WR_BAT };
enum mappers_internal_struct { INT_STRUCT = 10 };

typedef struct _mapper_int_struct {
BYTE *data;
size_t size;
} _mapper_int_struct;
typedef struct _mapper_int_structs {
unsigned int count;
_mapper_int_struct s[INT_STRUCT];
} _mapper_int_structs;
typedef struct _mapper {
BYTE mirroring;
BYTE *internal_struct[10];
WORD internal_struct_size[10];
_mapper_int_structs structs;
} _mapper;

extern _mapper mapper;

BYTE map_init(void);
void map_quit(void);

void map_internal_struct_init(BYTE *strct, size_t size);
void map_internal_struct_quit(void);

#endif /* MAPPERS_H_ */
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_001.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void map_init_001(void) {
EXTCL_CPU_WR_MEM(MMC1);
EXTCL_CPU_RD_RAM(001);
EXTCL_SAVE_MAPPER(MMC1);
mapper.internal_struct[0] = (BYTE *)&mmc1;
mapper.internal_struct_size[0] = sizeof(mmc1);
map_internal_struct_init((BYTE *)&mmc1, sizeof(mmc1));

if (info.format != NES_2_0) {
if (!chrrom_size()) {
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_002.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ void map_init_002(void) {
EXTCL_AFTER_MAPPER_INIT(002);
EXTCL_CPU_WR_MEM(002);
EXTCL_SAVE_MAPPER(002);
mapper.internal_struct[0] = (BYTE *)&m002;
mapper.internal_struct_size[0] = sizeof(m002);
map_internal_struct_init((BYTE *)&m002, sizeof(m002));

if (info.reset >= HARD) {
memset(&m002, 0x00, sizeof(m002));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_003.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void map_init_003() {
EXTCL_CPU_WR_MEM(003);
EXTCL_SAVE_MAPPER(003);
EXTCL_CPU_EVERY_CYCLE(003);
mapper.internal_struct[0] = (BYTE *)&m003;
mapper.internal_struct_size[0] = sizeof(m003);
map_internal_struct_init((BYTE *)&m003, sizeof(m003));

if (info.reset >= HARD) {
memset(&m003, 0x00, sizeof(m003));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_004.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ void map_init_004(void) {
EXTCL_PPU_256_TO_319(MMC3);
EXTCL_PPU_320_TO_34X(MMC3);
EXTCL_UPDATE_R2006(MMC3);
mapper.internal_struct[0] = (BYTE *)&mmc3;
mapper.internal_struct_size[0] = sizeof(mmc3);
map_internal_struct_init((BYTE *)&mmc3, sizeof(mmc3));

if (info.reset >= HARD) {
memset(&nes[0].irqA12, 0x00, sizeof(nes[0].irqA12));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_005.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void map_init_005(void) {
EXTCL_LENGTH_CLOCK(005);
EXTCL_ENVELOPE_CLOCK(005);
EXTCL_APU_TICK(005);
mapper.internal_struct[0] = (BYTE *)&m005;
mapper.internal_struct_size[0] = sizeof(m005);
map_internal_struct_init((BYTE *)&m005, sizeof(m005));

if (info.reset >= HARD) {
memset(&m005, 0x00, sizeof(m005));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_006.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ void map_init_006(void) {
EXTCL_PPU_256_TO_319(006);
EXTCL_PPU_320_TO_34X(006);
EXTCL_UPDATE_R2006(006);
mapper.internal_struct[0] = (BYTE *)&m006;
mapper.internal_struct_size[0] = sizeof(m006);
map_internal_struct_init((BYTE *)&m006, sizeof(m006));

m006tmp.chr = NULL;

Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_007.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void map_init_007(void) {
EXTCL_AFTER_MAPPER_INIT(007);
EXTCL_CPU_WR_MEM(007);
EXTCL_SAVE_MAPPER(007);
mapper.internal_struct[0] = (BYTE *)&m007;
mapper.internal_struct_size[0] = sizeof(m007);
map_internal_struct_init((BYTE *)&m007, sizeof(m007));

if (info.reset >= HARD) {
memset(&m007, 0x00, sizeof(m007));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_009.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ void map_init_009(void) {
EXTCL_SAVE_MAPPER(MMC2);
EXTCL_AFTER_RD_CHR(MMC2);
EXTCL_UPDATE_R2006(MMC2);
mapper.internal_struct[0] = (BYTE *)&mmc2;
mapper.internal_struct_size[0] = sizeof(mmc2);
map_internal_struct_init((BYTE *)&mmc2, sizeof(mmc2));

init_MMC2(info.reset);
MMC2_prg_swap = prg_swap_mmc2_009;
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_010.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ void map_init_010(void) {
EXTCL_SAVE_MAPPER(MMC4);
EXTCL_AFTER_RD_CHR(MMC4);
EXTCL_UPDATE_R2006(MMC4);
mapper.internal_struct[0] = (BYTE *)&mmc4;
mapper.internal_struct_size[0] = sizeof(mmc4);
map_internal_struct_init((BYTE *)&mmc4, sizeof(mmc4));

init_MMC4(info.reset);
MMC4_prg_swap = prg_swap_mmc4_010;
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_011.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void map_init_011(void) {
EXTCL_AFTER_MAPPER_INIT(011);
EXTCL_CPU_WR_MEM(011);
EXTCL_SAVE_MAPPER(011);
mapper.internal_struct[0] = (BYTE *)&m011;
mapper.internal_struct_size[0] = sizeof(m011);
map_internal_struct_init((BYTE *)&m011, sizeof(m011));

if (info.reset >= HARD) {
memset(&m011, 0x00, sizeof(m011));
Expand Down
6 changes: 2 additions & 4 deletions src/core/mappers/mapper_012.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ void map_init_012(void) {
EXTCL_PPU_256_TO_319(MMC3);
EXTCL_PPU_320_TO_34X(MMC3);
EXTCL_UPDATE_R2006(MMC3);
mapper.internal_struct[0] = (BYTE *)&m012;
mapper.internal_struct_size[0] = sizeof(m012);
mapper.internal_struct[1] = (BYTE *)&mmc3;
mapper.internal_struct_size[1] = sizeof(mmc3);
map_internal_struct_init((BYTE *)&m012, sizeof(m012));
map_internal_struct_init((BYTE *)&mmc3, sizeof(mmc3));

if (info.reset >= HARD) {
memset(&nes[0].irqA12, 0x00, sizeof(nes[0].irqA12));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_013.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void map_init_013(void) {
EXTCL_AFTER_MAPPER_INIT(013);
EXTCL_CPU_WR_MEM(013);
EXTCL_SAVE_MAPPER(013);
mapper.internal_struct[0] = (BYTE *)&m013;
mapper.internal_struct_size[0] = sizeof(m013);
map_internal_struct_init((BYTE *)&m013, sizeof(m013));

if (info.reset >= HARD) {
memset(&m013, 0x00, sizeof(m013));
Expand Down
9 changes: 3 additions & 6 deletions src/core/mappers/mapper_014.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ void map_init_014(void) {
EXTCL_PPU_256_TO_319(014);
EXTCL_PPU_320_TO_34X(014);
EXTCL_UPDATE_R2006(014);
mapper.internal_struct[0] = (BYTE *)&m014;
mapper.internal_struct_size[0] = sizeof(m014);
mapper.internal_struct[1] = (BYTE *)&mmc3;
mapper.internal_struct_size[1] = sizeof(mmc3);
mapper.internal_struct[2] = (BYTE *)&vrc2and4;
mapper.internal_struct_size[2] = sizeof(vrc2and4);
map_internal_struct_init((BYTE *)&m014, sizeof(m014));
map_internal_struct_init((BYTE *)&mmc3, sizeof(mmc3));
map_internal_struct_init((BYTE *)&vrc2and4, sizeof(vrc2and4));

if (info.reset >= HARD) {
memset(&nes[0].irqA12, 0x00, sizeof(nes[0].irqA12));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_015.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void map_init_015(void) {
EXTCL_AFTER_MAPPER_INIT(015);
EXTCL_CPU_WR_MEM(015);
EXTCL_SAVE_MAPPER(015);
mapper.internal_struct[0] = (BYTE *)&m015;
mapper.internal_struct_size[0] = sizeof(m015);
map_internal_struct_init((BYTE *)&m015, sizeof(m015));

memset(&m015, 0x00, sizeof(m015));
}
Expand Down
9 changes: 3 additions & 6 deletions src/core/mappers/mapper_016.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ void map_init_016(void) {
EXTCL_CPU_WR_MEM(LZ93D50);
EXTCL_SAVE_MAPPER(LZ93D50);
EXTCL_CPU_EVERY_CYCLE(LZ93D50);
mapper.internal_struct[0] = (BYTE *)&lz93d50;
mapper.internal_struct_size[0] = sizeof(lz93d50);
map_internal_struct_init((BYTE *)&lz93d50, sizeof(lz93d50));

init_LZ93D50(TRUE, info.reset);
LZ93D50_prg_swap = prg_swap_lz93d50_016;
Expand All @@ -57,8 +56,7 @@ void map_init_016(void) {
EXTCL_CPU_WR_MEM(FCG);
EXTCL_SAVE_MAPPER(FCG);
EXTCL_CPU_EVERY_CYCLE(FCG);
mapper.internal_struct[0] = (BYTE *)&fcg;
mapper.internal_struct_size[0] = sizeof(fcg);
map_internal_struct_init((BYTE *)&fcg, sizeof(fcg));

init_FCG(info.reset);
FCG_prg_swap = prg_swap_fcg_016;
Expand All @@ -71,8 +69,7 @@ void map_init_016(void) {
EXTCL_CPU_RD_MEM(LZ93D50);
EXTCL_SAVE_MAPPER(LZ93D50);
EXTCL_CPU_EVERY_CYCLE(LZ93D50);
mapper.internal_struct[0] = (BYTE *)&lz93d50;
mapper.internal_struct_size[0] = sizeof(lz93d50);
map_internal_struct_init((BYTE *)&lz93d50, sizeof(lz93d50));

init_LZ93D50(FALSE, info.reset);
LZ93D50_prg_swap = prg_swap_lz93d50_016;
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_019.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void map_init_019(void) {
EXTCL_CPU_EVERY_CYCLE(019);
EXTCL_BATTERY_IO(019);
EXTCL_APU_TICK(019);
mapper.internal_struct[0] = (BYTE *)&m019;
mapper.internal_struct_size[0] = sizeof(m019);
map_internal_struct_init((BYTE *)&m019, sizeof(m019));

if ((info.reset == CHANGE_ROM) || (info.reset == POWER_UP)) {
memmap_wram_region_init(0, S2K);
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_021.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ void map_init_021(void) {
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
mapper.internal_struct_size[0] = sizeof(vrc2and4);
map_internal_struct_init((BYTE *)&vrc2and4, sizeof(vrc2and4));

switch (info.mapper.submapper) {
default:
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_022.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ void map_init_022(void) {
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
mapper.internal_struct_size[0] = sizeof(vrc2and4);
map_internal_struct_init((BYTE *)&vrc2and4, sizeof(vrc2and4));

init_VRC2and4(VRC24_VRC2, 0x02, 0x01, TRUE, info.reset);
VRC2and4_prg_swap = prg_swap_vrc2and4_022;
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_023.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ void map_init_023(void) {
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
mapper.internal_struct_size[0] = sizeof(vrc2and4);
map_internal_struct_init((BYTE *)&vrc2and4, sizeof(vrc2and4));

switch (info.mapper.submapper) {
default:
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_024.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void map_init_024(void) {
EXTCL_SAVE_MAPPER(VRC6);
EXTCL_CPU_EVERY_CYCLE(VRC6);
EXTCL_APU_TICK(VRC6);
mapper.internal_struct[0] = (BYTE *)&vrc6;
mapper.internal_struct_size[0] = sizeof(vrc6);
map_internal_struct_init((BYTE *)&vrc6, sizeof(vrc6));

init_VRC6(0x01, 0x02, info.reset);
VRC6_prg_swap = prg_swap_vrc6_024;
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_025.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ void map_init_025(void) {
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
mapper.internal_struct_size[0] = sizeof(vrc2and4);
map_internal_struct_init((BYTE *)&vrc2and4, sizeof(vrc2and4));

switch (info.mapper.submapper) {
default:
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_026.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void map_init_026(void) {
EXTCL_SAVE_MAPPER(VRC6);
EXTCL_CPU_EVERY_CYCLE(VRC6);
EXTCL_APU_TICK(VRC6);
mapper.internal_struct[0] = (BYTE *)&vrc6;
mapper.internal_struct_size[0] = sizeof(vrc6);
map_internal_struct_init((BYTE *)&vrc6, sizeof(vrc6));

init_VRC6(0x02, 0x01, info.reset);
VRC6_prg_swap = prg_swap_vrc6_026;
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_027.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ void map_init_027(void) {
EXTCL_AFTER_MAPPER_INIT(027);
EXTCL_CPU_WR_MEM(027);
EXTCL_SAVE_MAPPER(027);
mapper.internal_struct[0] = (BYTE *)&m027;
mapper.internal_struct_size[0] = sizeof(m027);
map_internal_struct_init((BYTE *)&m027, sizeof(m027));

if (info.reset >= HARD) {
memset(&m027, 0x00, sizeof(m027));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_028.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ void map_init_028(void) {
EXTCL_AFTER_MAPPER_INIT(028);
EXTCL_CPU_WR_MEM(028);
EXTCL_SAVE_MAPPER(028);
mapper.internal_struct[0] = (BYTE *)&m028;
mapper.internal_struct_size[0] = sizeof(m028);
map_internal_struct_init((BYTE *)&m028, sizeof(m028));

if (info.reset >= HARD) {
memset(&m028, 0xFF, sizeof(m028));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_029.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void map_init_029(void) {
EXTCL_AFTER_MAPPER_INIT(029);
EXTCL_CPU_WR_MEM(029);
EXTCL_SAVE_MAPPER(029);
mapper.internal_struct[0] = (BYTE *)&m029;
mapper.internal_struct_size[0] = sizeof(m029);
map_internal_struct_init((BYTE *)&m029, sizeof(m029));

if (info.reset >= HARD) {
memset(&m029, 0x00, sizeof(m029));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_030.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ void map_init_030(void) {
EXTCL_AFTER_MAPPER_INIT(030);
EXTCL_CPU_WR_MEM(030);
EXTCL_SAVE_MAPPER(030);
mapper.internal_struct[0] = (BYTE *)&m030;
mapper.internal_struct_size[0] = sizeof(m030);
map_internal_struct_init((BYTE *)&m030, sizeof(m030));

if (info.reset >= HARD) {
memset(&m030, 0x00, sizeof(m030));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_031.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void map_init_031(void) {
EXTCL_AFTER_MAPPER_INIT(031);
EXTCL_CPU_WR_MEM(031);
EXTCL_SAVE_MAPPER(031);
mapper.internal_struct[0] = (BYTE *)&m031;
mapper.internal_struct_size[0] = sizeof(m031);
map_internal_struct_init((BYTE *)&m031, sizeof(m031));

if ((info.reset == CHANGE_ROM) || (info.reset == POWER_UP)) {
memmap_prg_region_init(0, S4K);
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_032.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ void map_init_032() {
EXTCL_AFTER_MAPPER_INIT(032);
EXTCL_CPU_WR_MEM(032);
EXTCL_SAVE_MAPPER(032);
mapper.internal_struct[0] = (BYTE *)&m032;
mapper.internal_struct_size[0] = sizeof(m032);
map_internal_struct_init((BYTE *)&m032, sizeof(m032));

if (info.reset >= HARD) {
memset(&m032, 0x00, sizeof(m032));
Expand Down
3 changes: 1 addition & 2 deletions src/core/mappers/mapper_033.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void map_init_033(void) {
EXTCL_AFTER_MAPPER_INIT(033);
EXTCL_CPU_WR_MEM(033);
EXTCL_SAVE_MAPPER(033);
mapper.internal_struct[0] = (BYTE *)&m033;
mapper.internal_struct_size[0] = sizeof(m033);
map_internal_struct_init((BYTE *)&m033, sizeof(m033));

if (info.reset >= HARD) {
memset(&m033, 0x00, sizeof(m033));
Expand Down
Loading

0 comments on commit f59c218

Please sign in to comment.