Skip to content

Commit

Permalink
Fixed mapper VRC2/VRC4 (#324).
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Oct 2, 2023
1 parent 3be91cc commit a275c7f
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/core/mappers/VRC2and4.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ void init_VRC2and4(BYTE type, WORD A0, WORD A1, BYTE irq_repeated, BYTE reset) {
vrc2and4.irq.count = 0;
vrc2and4.irq.prescaler = 0;

vrc2and4.wram_protect = ((info.format == NES_2_0) && (info.mapper.submapper > 1));
vrc2and4.wram_protect = (vrc2and4tmp.type == VRC24_VRC4) &&
(info.format == NES_2_0) && (info.mapper.submapper > 1);

nes[0].c.irq.high &= ~EXT_IRQ;

Expand Down
1 change: 0 additions & 1 deletion src/core/mappers/mapper_021.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void chr_swap_vrc2and4_021(WORD address, WORD value);
void map_init_021(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
Expand Down
5 changes: 4 additions & 1 deletion src/core/mappers/mapper_022.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void chr_swap_vrc2and4_022(WORD address, WORD value);
void map_init_022(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(022);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
Expand All @@ -35,6 +35,9 @@ void map_init_022(void) {
VRC2and4_prg_swap = prg_swap_vrc2and4_022;
VRC2and4_chr_swap = chr_swap_vrc2and4_022;
}
BYTE extcl_cpu_rd_mem_022(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
return (extcl_cpu_rd_mem_VRC2and4(nidx, address, wram_rd(nidx, address)));
}

void prg_swap_vrc2and4_022(WORD address, WORD value) {
prg_swap_VRC2and4_base(address, (value & 0x1F));
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers/mapper_022.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
#include "common.h"

void map_init_022(void);
BYTE extcl_cpu_rd_mem_022(BYTE nidx, WORD address, BYTE openbus);

#endif /* MAPPER_022_H_ */
5 changes: 4 additions & 1 deletion src/core/mappers/mapper_023.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void wired_fix_vrc2and4_023(void);
void map_init_023(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
Expand All @@ -43,13 +42,17 @@ void map_init_023(void) {
init_VRC2and4(VRC24_VRC4, 0x04, 0x08, TRUE, info.reset);
break;
case 3:
EXTCL_CPU_RD_MEM(023);
init_VRC2and4(VRC24_VRC2, 0x01, 0x02, TRUE, info.reset);
break;
}
VRC2and4_prg_swap = prg_swap_vrc2and4_023;
VRC2and4_chr_swap = chr_swap_vrc2and4_023;
VRC2and4_wired_fix = wired_fix_vrc2and4_023;
}
BYTE extcl_cpu_rd_mem_023(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
return (extcl_cpu_rd_mem_VRC2and4(nidx, address, wram_rd(nidx, address)));
}

void prg_swap_vrc2and4_023(WORD address, WORD value) {
prg_swap_VRC2and4_base(address, (value & 0x1F));
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers/mapper_023.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
#include "common.h"

void map_init_023(void);
BYTE extcl_cpu_rd_mem_023(BYTE nidx, WORD address, BYTE openbus);

#endif /* MAPPER_023_H_ */
5 changes: 4 additions & 1 deletion src/core/mappers/mapper_025.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void chr_swap_vrc2and4_025(WORD address, WORD value);
void map_init_025(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(VRC2and4);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
Expand All @@ -42,12 +41,16 @@ void map_init_025(void) {
init_VRC2and4(VRC24_VRC4, 0x08, 0x04, TRUE, info.reset);
break;
case 3:
EXTCL_CPU_RD_MEM(025);
init_VRC2and4(VRC24_VRC2, 0x02, 0x01, TRUE, info.reset);
break;
}
VRC2and4_prg_swap = prg_swap_vrc2and4_025;
VRC2and4_chr_swap = chr_swap_vrc2and4_025;
}
BYTE extcl_cpu_rd_mem_025(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
return (extcl_cpu_rd_mem_VRC2and4(nidx, address, wram_rd(nidx, address)));
}

void prg_swap_vrc2and4_025(WORD address, WORD value) {
prg_swap_VRC2and4_base(address, (value & 0x1F));
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers/mapper_025.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
#include "common.h"

void map_init_025(void);
BYTE extcl_cpu_rd_mem_025(BYTE nidx, WORD address, BYTE openbus);

#endif /* MAPPER_025_H_ */
5 changes: 4 additions & 1 deletion src/core/mappers/mapper_222.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct _m222 {
void map_init_222(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(222);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(222);
EXTCL_SAVE_MAPPER(222);
EXTCL_CPU_EVERY_CYCLE(222);
mapper.internal_struct[0] = (BYTE *)&m222;
Expand Down Expand Up @@ -81,6 +81,9 @@ void extcl_cpu_wr_mem_222(BYTE nidx, WORD address, BYTE value) {
return;
}
}
BYTE extcl_cpu_rd_mem_222(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
return (extcl_cpu_rd_mem_VRC2and4(nidx, address, wram_rd(nidx, address)));
}
BYTE extcl_save_mapper_222(BYTE mode, BYTE slot, FILE *fp) {
save_slot_ele(mode, slot, m222.prescaler);
save_slot_ele(mode, slot, m222.mode);
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers/mapper_222.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

void map_init_222(void);
void extcl_cpu_wr_mem_222(BYTE nidx, WORD address, BYTE value);
BYTE extcl_cpu_rd_mem_222(BYTE nidx, WORD address, BYTE openbus);
BYTE extcl_save_mapper_222(BYTE mode, BYTE slot, FILE *fp);
void extcl_cpu_every_cycle_222(BYTE nidx);

Expand Down
1 change: 0 additions & 1 deletion src/core/mappers/mapper_252.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct _m252 {
void map_init_252(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_SAVE_MAPPER(252);
EXTCL_WR_CHR(252);
EXTCL_CPU_EVERY_CYCLE(VRC2and4);
Expand Down
5 changes: 4 additions & 1 deletion src/core/mappers/mapper_524.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct _m524 {
void map_init_524(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(524);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(524);
EXTCL_SAVE_MAPPER(524);
EXTCL_CPU_EVERY_CYCLE(524);
mapper.internal_struct[0] = (BYTE *)&m524;
Expand Down Expand Up @@ -65,6 +65,9 @@ void extcl_cpu_wr_mem_524(BYTE nidx, WORD address, BYTE value) {
return;
}
}
BYTE extcl_cpu_rd_mem_524(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
return (extcl_cpu_rd_mem_VRC2and4(nidx, address, wram_rd(nidx, address)));
}
BYTE extcl_save_mapper_524(BYTE mode, BYTE slot, FILE *fp) {
save_slot_ele(mode, slot, m524.irq.enabled);
save_slot_ele(mode, slot, m524.irq.counter);
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers/mapper_524.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

void map_init_524(void);
void extcl_cpu_wr_mem_524(BYTE nidx, WORD address, BYTE value);
BYTE extcl_cpu_rd_mem_524(BYTE nidx, WORD address, BYTE openbus);
BYTE extcl_save_mapper_524(BYTE mode, BYTE slot, FILE *fp);
void extcl_cpu_every_cycle_524(BYTE nidx);

Expand Down
5 changes: 4 additions & 1 deletion src/core/mappers/mapper_527.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void mirroring_fix_vrc2and4_527(void);
void map_init_527(void) {
EXTCL_AFTER_MAPPER_INIT(VRC2and4);
EXTCL_CPU_WR_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(VRC2and4);
EXTCL_CPU_RD_MEM(527);
EXTCL_SAVE_MAPPER(VRC2and4);
mapper.internal_struct[0] = (BYTE *)&vrc2and4;
mapper.internal_struct_size[0] = sizeof(vrc2and4);
Expand All @@ -38,6 +38,9 @@ void map_init_527(void) {
VRC2and4_chr_swap = chr_swap_vrc2and4_527;
VRC2and4_mirroring_fix = mirroring_fix_vrc2and4_527;
}
BYTE extcl_cpu_rd_mem_527(BYTE nidx, WORD address, UNUSED(BYTE openbus)) {
return (extcl_cpu_rd_mem_VRC2and4(nidx, address, wram_rd(nidx, address)));
}

void prg_swap_vrc2and4_527(WORD address, WORD value) {
prg_swap_VRC2and4_base(address, (value & 0x1F));
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers/mapper_527.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
#include "common.h"

void map_init_527(void);
BYTE extcl_cpu_rd_mem_527(BYTE nidx, WORD address, BYTE openbus);

#endif /* MAPPER_527_H_ */

0 comments on commit a275c7f

Please sign in to comment.