From ea537c944ebc65b694535eddc1bf04fdec243d2a Mon Sep 17 00:00:00 2001 From: Fabio Cavallo Date: Sun, 19 Nov 2023 10:31:23 +0100 Subject: [PATCH] Added support to mapper 517. --- ChangeLog | 2 +- README.md | 2 +- src/CMakeLists.txt | 1 + src/core/mappers.c | 3 + src/core/mappers.h | 1 + src/core/mappers/mapper_517.c | 108 ++++++++++++++++++++++++++++++++++ src/core/mappers/mapper_517.h | 30 ++++++++++ 7 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 src/core/mappers/mapper_517.c create mode 100644 src/core/mappers/mapper_517.h diff --git a/ChangeLog b/ChangeLog index af2b8e863..4f9a57951 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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, 170, 272, 291, 311, 334, 362, 366, 384, 421, 446, 471, 551, 552, 555, 561. +- Added support to mapper : 100, 122, 157, 170, 272, 291, 311, 334, 362, 366, 384, 421, 446, 471, 517, 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). diff --git a/README.md b/README.md index 80ba67d49..c1d76fa00 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ To see a list of available command-line options, start puNES with the `-h` argum | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 512 | 513 | | | 516 | -| | 518 | 519 | | 521 | 522 | | 524 | 525 | 526 | 527 | +| 517 | 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 | 555 | 556 | 557 | 558 | 559 | 560 | diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08503cf49..a7487494c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -450,6 +450,7 @@ set(core_srcs core/mappers/mapper_513.c core/mappers/mapper_516.c core/mappers/mapper_518.c + core/mappers/mapper_517.c core/mappers/mapper_519.c core/mappers/mapper_521.c core/mappers/mapper_522.c diff --git a/src/core/mappers.c b/src/core/mappers.c index ce8f0aeb3..4a42a4171 100644 --- a/src/core/mappers.c +++ b/src/core/mappers.c @@ -1198,6 +1198,9 @@ BYTE map_init(void) { case 516: map_init_516(); break; + case 517: + map_init_517(); + break; case 518: map_init_518(); break; diff --git a/src/core/mappers.h b/src/core/mappers.h index 7454b2685..d0427bb01 100644 --- a/src/core/mappers.h +++ b/src/core/mappers.h @@ -383,6 +383,7 @@ #include "mappers/mapper_512.h" #include "mappers/mapper_513.h" #include "mappers/mapper_516.h" +#include "mappers/mapper_517.h" #include "mappers/mapper_518.h" #include "mappers/mapper_519.h" #include "mappers/mapper_521.h" diff --git a/src/core/mappers/mapper_517.c b/src/core/mappers/mapper_517.c new file mode 100644 index 000000000..fc6f73be7 --- /dev/null +++ b/src/core/mappers/mapper_517.c @@ -0,0 +1,108 @@ +/* + * 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 +#include "mappers.h" +#include "save_slot.h" + +INLINE static void prg_fix_517(void); + +struct _m517 { + BYTE reg; + struct _m517_adc { + int data; + int high; + int low; + BYTE state; + } adc; +} m517; + +void map_init_517(void) { + EXTCL_AFTER_MAPPER_INIT(517); + EXTCL_CPU_WR_MEM(517); + EXTCL_CPU_RD_MEM(517); + EXTCL_SAVE_MAPPER(517); + mapper.internal_struct[0] = (BYTE *)&m517; + mapper.internal_struct_size[0] = sizeof(m517); + + if (info.reset >= HARD) { + memset(&m517, 0x00, sizeof(m517)); + } + + m517.adc.data = 0; + m517.adc.state = 0; +} +void extcl_after_mapper_init_517(void) { + prg_fix_517(); +} +void extcl_cpu_wr_mem_517(UNUSED(BYTE nidx), WORD address, BYTE value) { + if ((address >= 0x8000) && (address <= 0x8FFF)) { +// TODO : gestione microfono +// m517.adc.data = * 63.0; + m517.adc.data = 0.0 * 63.0; + m517.adc.high = m517.adc.data >> 2; + m517.adc.low = 0x40 - m517.adc.high - ((m517.adc.data & 0x03) << 2); + m517.adc.state = 0; + } + m517.reg = value; + prg_fix_517(); +} +BYTE extcl_cpu_rd_mem_517(BYTE nidx, WORD address, UNUSED(BYTE openbus)) { + if ((address >= 0x6000) && (address <= 0x6FFF)) { + BYTE result = 0; + + if (address == 0x6000) { + switch(m517.adc.state) { + case 0: + m517.adc.state = 1; + result = 0; + break; + case 1: + m517.adc.state = 2; + result = 1; + break; + case 2: + if (m517.adc.low > 0) { + m517.adc.low--; + result = 1; + } else { + m517.adc.state = 0; + result = 0; + } + break; + } + } else { + result = m517.adc.high-- > 0 ? 0 : 1; + } + return (result); + } + return (wram_rd(nidx, address)); +} +BYTE extcl_save_mapper_517(BYTE mode, BYTE slot, FILE *fp) { + save_slot_ele(mode, slot, m517.reg); + save_slot_ele(mode, slot, m517.adc.data); + save_slot_ele(mode, slot, m517.adc.high); + save_slot_ele(mode, slot, m517.adc.low); + save_slot_ele(mode, slot, m517.adc.state); + return (EXIT_OK); +} + +INLINE static void prg_fix_517(void) { + memmap_auto_16k(0, MMCPU(0x8000), m517.reg); + memmap_auto_16k(0, MMCPU(0xC000), 0xFF); +} diff --git a/src/core/mappers/mapper_517.h b/src/core/mappers/mapper_517.h new file mode 100644 index 000000000..7997e440d --- /dev/null +++ b/src/core/mappers/mapper_517.h @@ -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_517_H_ +#define MAPPER_517_H_ + +#include "common.h" + +void map_init_517(void); +void extcl_after_mapper_init_517(void); +void extcl_cpu_wr_mem_517(BYTE nidx, WORD address, BYTE value); +BYTE extcl_cpu_rd_mem_517(BYTE nidx, WORD address, BYTE openbus); +BYTE extcl_save_mapper_517(BYTE mode, BYTE slot, FILE *fp); + +#endif /* MAPPER_517_H_ */