Skip to content

Commit

Permalink
Adde mapper 555 (#342).
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Nov 14, 2023
1 parent 69ba0ca commit 1e9e1ca
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Changelog:
- Added full support for the NES 2.0 header format.
- Added video filter : "NTSC CRT LMP88959" and "NTSC NES LMP88959" (https://github.com/LMP88959/NTSC-CRT, Thx to LMP88959 for is great work).
- Added video filter : "PAL CRT LMP88959" and "PAL NES LMP88959" (https://github.com/LMP88959/PAL-CRT, Thx to LMP88959 for is great work).
- Added support to mapper : 100, 122, 157, 272, 291, 311, 334, 362, 366, 384, 421, 446, 471, 551, 552, 561.
- Added support to mapper : 100, 122, 157, 272, 291, 311, 334, 362, 366, 384, 421, 446, 471, 551, 552, 555, 561.
- Added support to UNIF mapper : Transformer, UNROM, AMROM, AOROM, LH09, A60AS, T4A54A, FC-28-5027, 150in1A, 212-HONG-KONG, GKCXIN, 113in1JY110, 820561C, M2C52A, S-2009.
- Added full support for the Detach Barcode Reader of mapper 157.
- Added support for nes20db.xml and dip.cfg (many thx to NewRisingSun for is for his immense work).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ To see a list of available command-line options, start puNES with the `-h` argum
| | 518 | 519 | | 521 | 522 | | 524 | 525 | 526 | 527 |
| 528 | 529 | 530 | | 532 | | 534 | | 536 | 537 | 538 |
| 539 | 540 | 541 | | 543 | | | | 547 | | |
| 550 | 551 | 552 | | 554 | | 556 | 557 | 558 | 559 | 560 |
| 550 | 551 | 552 | | 554 | 555 | 556 | 557 | 558 | 559 | 560 |
| 561 | | | | | | | | | | |


Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ set(core_srcs
core/mappers/mapper_547.c
core/mappers/mapper_550.c
core/mappers/mapper_554.c
core/mappers/mapper_555.c
core/mappers/mapper_556.c
core/mappers/mapper_557.c
core/mappers/mapper_558.c
Expand Down
3 changes: 3 additions & 0 deletions src/core/mappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,9 @@ BYTE map_init(void) {
case 554:
map_init_554();
break;
case 555:
map_init_555();
break;
case 556:
map_init_556();
break;
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@
#include "mappers/mapper_547.h"
#include "mappers/mapper_550.h"
#include "mappers/mapper_554.h"
#include "mappers/mapper_555.h"
#include "mappers/mapper_556.h"
#include "mappers/mapper_557.h"
#include "mappers/mapper_558.h"
Expand Down
143 changes: 143 additions & 0 deletions src/core/mappers/mapper_555.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (C) 2010-2023 Fabio Cavallo (aka FHorse)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <string.h>
#include "mappers.h"
#include "irqA12.h"
#include "save_slot.h"
#include "clock.h"
#include "gui.h"

void prg_swap_mmc3_555(WORD address, WORD value);
void wram_fix_mmc3_555(void);
void chr_swap_mmc3_555(WORD address, WORD value);

struct _m555 {
BYTE reg[2];
struct _counter_m555 {
BYTE disabled;
uint32_t timer;
} counter;
} m555;

void map_init_555(void) {
EXTCL_AFTER_MAPPER_INIT(MMC3);
EXTCL_CPU_WR_MEM(555);
EXTCL_CPU_RD_MEM(555);
EXTCL_SAVE_MAPPER(555);
EXTCL_CPU_EVERY_CYCLE(555);
EXTCL_PPU_000_TO_34X(MMC3);
EXTCL_PPU_000_TO_255(MMC3);
EXTCL_PPU_256_TO_319(MMC3);
EXTCL_PPU_320_TO_34X(MMC3);
EXTCL_UPDATE_R2006(MMC3);
mapper.internal_struct[0] = (BYTE *)&m555;
mapper.internal_struct_size[0] = sizeof(m555);
mapper.internal_struct[1] = (BYTE *)&mmc3;
mapper.internal_struct_size[1] = sizeof(mmc3);

if (info.reset >= HARD) {
memset(&nes[0].irqA12, 0x00, sizeof(nes[0].irqA12));
}

memset(&m555, 0x00, sizeof(m555));

init_MMC3(HARD);
MMC3_prg_swap = prg_swap_mmc3_555;
MMC3_wram_fix = wram_fix_mmc3_555;
MMC3_chr_swap = chr_swap_mmc3_555;

info.mapper.extend_wr = TRUE;

nes[0].irqA12.present = TRUE;
irqA12_delay = 1;
}
void extcl_cpu_wr_mem_555(BYTE nidx, WORD address, BYTE value) {
if ((address >= 0x5000) && (address <= 0x5FFF)) {
if (address & 0x0800) {
m555.reg[(address & 0x400) >> 10] = value;
MMC3_prg_fix();
MMC3_chr_fix();
return;
}
wram_wr(nidx, address, value);
return;
}
if (address >= 0x8000) {
extcl_cpu_wr_mem_MMC3(nidx, address, value);
}
}
BYTE extcl_cpu_rd_mem_555(UNUSED(BYTE nidx), WORD address, UNUSED(BYTE openbus)) {
if ((address >= 0x5000) && (address <= 0x5FFF)) {
if (address & 0x0800) {
return ((m555.counter.disabled ? 0x80 : 0x00) | 0x5C);
}
}
return (wram_rd(nidx, address));
}
BYTE extcl_save_mapper_555(BYTE mode, BYTE slot, FILE *fp) {
save_slot_ele(mode, slot, m555.reg);
save_slot_ele(mode, slot, m555.counter.disabled);
save_slot_ele(mode, slot, m555.counter.timer);
return (extcl_save_mapper_MMC3(mode, slot, fp));
}
void extcl_cpu_every_cycle_555(BYTE nidx) {
extcl_cpu_every_cycle_MMC3(nidx);
if (!(m555.reg[0] & 0x08)) {
m555.counter.timer = 0;
m555.counter.disabled = FALSE;
} else {
uint32_t timer = 0x20000000 | (dipswitch.value << 25);
uint32_t cpu_hz = (uint32_t)machine.cpu_hz;

if (++m555.counter.timer == timer) {
m555.counter.disabled = TRUE;
}
if ((m555.counter.timer % cpu_hz) == 0) {
uint32_t seconds = (timer - m555.counter.timer) / cpu_hz;
char buffer[50];

snprintf(buffer, sizeof(buffer), "Time left: %02i:%02i", seconds / 60, seconds % 60);
gui_overlay_info_append_subtitle(buffer);
}
}
}

void prg_swap_mmc3_555(WORD address, WORD value) {
WORD base = (m555.reg[0] & 0x04) << 3;
WORD mask = ((m555.reg[0] & 0x03) << 3) | 0x07;

prg_swap_MMC3_base(address, (base | (value & mask)));
}
void wram_fix_mmc3_555(void) {
memmap_auto_4k(0, MMCPU(0x5000), 2);
wram_fix_MMC3_base();
}
void chr_swap_mmc3_555(WORD address, WORD value) {
WORD base = (m555.reg[0] & 0x04) << 5;

if ((m555.reg[0] & 0x06) == 0x02) {
if ((value & 0x40) && (vram_size(0))) {
memmap_vram_1k(0, MMPPU(address), (base | (value & 0x07)));
} else {
memmap_chrrom_1k(0, MMPPU(address), (base | value));
}
} else {
chr_swap_MMC3_base(address, (base | (value & 0x7F)));
}
}
30 changes: 30 additions & 0 deletions src/core/mappers/mapper_555.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2010-2023 Fabio Cavallo (aka FHorse)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef MAPPER_555_H_
#define MAPPER_555_H_

#include "common.h"

void map_init_555(void);
void extcl_cpu_wr_mem_555(BYTE nidx, WORD address, BYTE value);
BYTE extcl_cpu_rd_mem_555(UNUSED(BYTE nidx), WORD address, BYTE openbus);
BYTE extcl_save_mapper_555(BYTE mode, BYTE slot, FILE *fp);
void extcl_cpu_every_cycle_555(BYTE nidx);

#endif /* MAPPER_555_H_ */

0 comments on commit 1e9e1ca

Please sign in to comment.