Skip to content

Commit

Permalink
Added support to mapper 517.
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Nov 19, 2023
1 parent 0c3dcef commit ea537c9
Show file tree
Hide file tree
Showing 7 changed files with 145 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, 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).
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/core/mappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/core/mappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
108 changes: 108 additions & 0 deletions src/core/mappers/mapper_517.c
Original file line number Diff line number Diff line change
@@ -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 <string.h>
#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 = <microphone> * 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);
}
30 changes: 30 additions & 0 deletions src/core/mappers/mapper_517.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_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_ */

0 comments on commit ea537c9

Please sign in to comment.