2025-09-09 10:57:02 +02:00
|
|
|
/* FCE Ultra - NES/Famicom Emulator
|
2022-07-27 13:35:33 +02:00
|
|
|
*
|
|
|
|
|
* Copyright notice for this file:
|
2025-09-09 10:57:02 +02:00
|
|
|
* Copyright (C) 2025 NewRisingSun
|
2022-07-27 13:35:33 +02:00
|
|
|
*
|
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "mapinc.h"
|
2025-09-09 10:57:02 +02:00
|
|
|
#include "asic_latch.h"
|
2022-07-27 13:35:33 +02:00
|
|
|
|
2026-04-06 15:37:30 -04:00
|
|
|
static uint8 submapper;
|
2025-09-09 10:57:02 +02:00
|
|
|
uint8 pad;
|
|
|
|
|
uint8 padSelect;
|
2022-07-27 13:35:33 +02:00
|
|
|
|
2025-09-12 21:59:27 +02:00
|
|
|
static DECLFR (readPad_submapper0) {
|
2025-09-09 10:57:02 +02:00
|
|
|
return CartBR(A &~0xF | pad &0xF);
|
|
|
|
|
}
|
2022-07-27 13:35:33 +02:00
|
|
|
|
2025-09-12 21:59:27 +02:00
|
|
|
static DECLFR (readPad_submapper1) {
|
2025-09-09 10:57:02 +02:00
|
|
|
return pad;
|
2022-07-27 13:35:33 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 21:59:27 +02:00
|
|
|
static DECLFR (readPad_submapper2) {
|
2025-09-09 10:57:02 +02:00
|
|
|
return CartBR(A &~0x3 | pad &0x3);
|
2022-07-28 21:14:59 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-09 10:57:02 +02:00
|
|
|
static void sync () {
|
|
|
|
|
int prg = Latch_address >>2 &0x1F | Latch_address >>3 &0x20 | Latch_address >>4 &0x40;
|
|
|
|
|
if (Latch_address &0x080) {
|
|
|
|
|
if (Latch_address &0x001)
|
|
|
|
|
setprg32(0x8000, prg >>1);
|
|
|
|
|
else {
|
|
|
|
|
setprg16(0x8000, prg);
|
|
|
|
|
setprg16(0xC000, prg);
|
|
|
|
|
}
|
|
|
|
|
setmirror(Latch_data &0x10? MI_1: MI_0);
|
|
|
|
|
} else {
|
|
|
|
|
setprg16(0x8000, prg);
|
|
|
|
|
setprg16(0xC000, prg | 7);
|
|
|
|
|
}
|
|
|
|
|
SetupCartCHRMapping(0, CHRptr[0], CHRsize[0], submapper == 0 && Latch_address &0x80? 0: 1);
|
|
|
|
|
setchr8(Latch_data);
|
|
|
|
|
setmirror(Latch_address &0x002? MI_H: MI_V);
|
|
|
|
|
SetReadHandler(0x8000, 0xFFFF, submapper == 0 && Latch_address &0x200? readPad_submapper0: submapper == 2 && padSelect &1? readPad_submapper2: CartBR);
|
2023-03-27 21:24:28 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 21:59:27 +02:00
|
|
|
static DECLFW (writePad_submapper2) {
|
2025-09-09 10:57:02 +02:00
|
|
|
padSelect = V;
|
|
|
|
|
sync();
|
2022-07-27 13:35:33 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-09 10:57:02 +02:00
|
|
|
static void power () {
|
|
|
|
|
pad = padSelect = 0;
|
|
|
|
|
Latch_power();
|
|
|
|
|
if (submapper == 1)
|
|
|
|
|
SetReadHandler(0x5000, 0x5FFF, readPad_submapper1);
|
|
|
|
|
else
|
|
|
|
|
if (submapper == 2)
|
|
|
|
|
SetWriteHandler(0x6000, 0x7FFF, writePad_submapper2);
|
2022-07-27 13:35:33 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-09 10:57:02 +02:00
|
|
|
static void reset () {
|
|
|
|
|
pad++;
|
|
|
|
|
padSelect = 0;
|
2025-09-12 21:59:27 +02:00
|
|
|
Latch_clear();
|
2022-07-27 13:35:33 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-09 10:57:02 +02:00
|
|
|
void Mapper449_Init (CartInfo *info) {
|
|
|
|
|
submapper = info->submapper;
|
|
|
|
|
Latch_init(info, sync, 0x8000, 0xFFFF, NULL);
|
|
|
|
|
info->Power = power;
|
|
|
|
|
info->Reset = reset;
|
|
|
|
|
AddExState(&pad, 1, 0, "DIPS");
|
|
|
|
|
if (submapper == 2) AddExState(&padSelect, 1, 0, "DIPE");
|
|
|
|
|
}
|