Mappers 83/264: Added submapper 3, rewrote to incorporate new findings

This commit is contained in:
NewRisingSun
2026-04-05 02:24:19 +02:00
parent e81b5e0370
commit ba25f9107b
7 changed files with 244 additions and 251 deletions

240
src/boards/83_264.c Normal file
View File

@@ -0,0 +1,240 @@
/* FCEUmm - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2026 NewRisingSun
*
* 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"
#include "cartram.h"
static uint8 reg[16];
static uint8 scratch[4];
static uint8 flags;
static uint8 pad;
static int mapper;
static uint8 submapper;
static SFORMAT stateRegs[] = {
{ reg, 16, "REGS" },
{ scratch, 4, "SCRA" },
{&flags, 1, "FLAG" },
{&pad, 1, "DIPS" },
{ 0 }
};
static void sync () {
int prgAND = mapper == 264 || submapper == 3? 0x0F: 0x1F;
switch(reg[1] &0x18) {
case 0x00:
setprg16(0x8000, reg[0]);
setprg16(0xC000, reg[0] | prgAND >>1);
break;
case 0x08:
setprg16(0x8000, reg[0]);
setprg16(0xC000, reg[0]);
break;
case 0x10: case 0x18:
setprg8(0x8000, reg[0] <<1 &~prgAND | reg[4] &prgAND);
setprg8(0xA000, reg[0] <<1 &~prgAND | reg[5] &prgAND);
setprg8(0xC000, reg[0] <<1 &~prgAND | reg[6] &prgAND);
setprg8(0xE000, reg[0] <<1 &~prgAND | 0xFF &prgAND);
break;
}
if (submapper == 2 && PRGsize[0x10])
setprg8r(0x10, 0x6000, reg[0] >>6);
else
setprg8(0x6000, reg[7]);
if (submapper == 2 || reg[1] &0x20) {
SetReadHandler (0x6000, 0x7FFF, CartBR);
SetWriteHandler(0x6000, 0x7FFF, CartBW);
} else {
SetReadHandler (0x6000, 0xFFFF, CartBROB);
SetWriteHandler(0x6000, 0x7FFF, NULL);
}
switch(mapper == 264? 1: submapper) {
case 0:
setchr1(0x0000, reg[8 | 0]);
setchr1(0x0400, reg[8 | 1]);
setchr1(0x0800, reg[8 | 2]);
setchr1(0x0C00, reg[8 | 3]);
setchr1(0x1000, reg[8 | 4]);
setchr1(0x1400, reg[8 | 5]);
setchr1(0x1800, reg[8 | 6]);
setchr1(0x1C00, reg[8 | 7]);
break;
case 1:
setchr2(0x0000, reg[8 | 0]);
setchr2(0x0800, reg[8 | 1]);
setchr2(0x1000, reg[8 | 6]);
setchr2(0x1800, reg[8 | 7]);
break;
case 2:
setchr1(0x0000, reg[0] <<4 &~0xFF | reg[8 | 0]);
setchr1(0x0400, reg[0] <<4 &~0xFF | reg[8 | 1]);
setchr1(0x0800, reg[0] <<4 &~0xFF | reg[8 | 2]);
setchr1(0x0C00, reg[0] <<4 &~0xFF | reg[8 | 3]);
setchr1(0x1000, reg[0] <<4 &~0xFF | reg[8 | 4]);
setchr1(0x1400, reg[0] <<4 &~0xFF | reg[8 | 5]);
setchr1(0x1800, reg[0] <<4 &~0xFF | reg[8 | 6]);
setchr1(0x1C00, reg[0] <<4 &~0xFF | reg[8 | 7]);
break;
case 3:
setchr1(0x0000, reg[0] <<2 &~0xFF | reg[8 | 0]);
setchr1(0x0400, reg[0] <<2 &~0xFF | reg[8 | 1]);
setchr1(0x0800, reg[0] <<2 &~0xFF | reg[8 | 2]);
setchr1(0x0C00, reg[0] <<2 &~0xFF | reg[8 | 3]);
setchr1(0x1000, reg[0] <<2 &~0xFF | reg[8 | 4]);
setchr1(0x1400, reg[0] <<2 &~0xFF | reg[8 | 5]);
setchr1(0x1800, reg[0] <<2 &~0xFF | reg[8 | 6]);
setchr1(0x1C00, reg[0] <<2 &~0xFF | reg[8 | 7]);
break;
}
switch (reg[1] &0x03) {
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
}
static DECLFR (readPadScratch) {
if (A &(mapper == 264? 0x400: 0x100))
return scratch[A &3];
else
return pad;
}
static DECLFW (writeScratch) {
scratch[A &3] = V;
}
static DECLFW (writeReg) {
if (mapper == 264) A = A >>2 &~0x3F | A &0x3F;
switch (A &0x318) {
case 0x000: case 0x008: case 0x010: case 0x018: case 0x100: case 0x108: case 0x110: case 0x118:
reg[A >>8 &1] = V;
sync();
break;
case 0x200: case 0x208: case 0x210: case 0x218:
reg[2 | A &1] = V;
if (A &1)
flags = flags &~0x80 | reg[1] &0x80; /* Copy "counting" flag from Misc. register to internal flag register */
else
X6502_IRQEnd(FCEU_IQEXT);
break;
case 0x300: case 0x308:
reg[4 | A &3] = V;
sync();
break;
case 0x310:
reg[8 | A &7] = V;
sync();
break;
case 0x318:
flags = flags &~0x40 | V &0x40;
break;
}
}
void clockCounter (void) {
uint16 counter = reg[2] | reg[3] <<8;
if (flags &0x80 && counter) {
if (reg[1] &0x40)
counter--;
else
counter++;
if (!counter) {
X6502_IRQBegin(FCEU_IQEXT);
flags &= ~0x80;
}
}
reg[2] = counter &0xFF;
reg[3] = counter >>8 &0xFF;
}
void FP_FASTAPASS(1) cycleCounter (int a) {
while (a--) if (~flags &0x40) clockCounter();
}
void scanlineCounter() {
if (flags &0x40) {
clockCounter();
clockCounter();
clockCounter();
clockCounter();
clockCounter();
clockCounter();
clockCounter();
clockCounter();
}
}
static void reset () {
int i;
for (int i = 0; i < 16; i++) reg[i] = 0;
pad++;
X6502_IRQEnd(FCEU_IQEXT);
sync();
}
static void power () {
int i;
SetReadHandler(0x5000, 0x5FFF, readPadScratch);
SetWriteHandler(0x5000, 0x5FFF, writeScratch);
SetReadHandler (0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, writeReg);
MapIRQHook = cycleCounter;
GameHBIRQHook = scanlineCounter;
for (int i = 0; i < 16; i++) reg[i] = 0;
for (int i = 4; i < 4; i++) scratch[i] = 0;
pad = 0;
sync();
}
void restore (int version) {
sync();
}
void Mapper83_Init (CartInfo *info) {
mapper = 83;
submapper = info->submapper;
if (!info->iNES2) {
if (info->CHRRomSize ==512*1024) submapper = 1; else
if (info->PRGRomSize ==1024*1024) submapper = 2; else
if (info->PRGRomSize ==512*1024) submapper = 3;
}
if (submapper == 2) WRAM_init(info, 32);
info->Power = power;
info->Reset = reset;
GameStateRestore = restore;
AddExState(stateRegs, ~0, 0, 0);
}
void Mapper264_Init (CartInfo *info) {
mapper = 264;
submapper = info->submapper;
info->Power = power;
info->Reset = reset;
GameStateRestore = restore;
AddExState(stateRegs, ~0, 0, 0);
}

View File

@@ -224,6 +224,7 @@ static void VRC2_configure (void (*sync)(), int A0, int A1, int (*prg)(uint8), i
VRC24_cbGetCHRBank = chr? chr: VRC24_getCHRBank;
VRC24_cbReadWRAM = read;
VRC24_cbWriteWRAM = write;
VRC24_cbExternalSelect = NULL;
}
static void VRC4_configure (void (*sync)(), int A0, int A1, uint8 useRepeatBit, int (*prg)(uint8), int (*chr)(uint8), DECLFR((*read)), DECLFW((*write)), DECLFW((*externalSelect))) {

View File

@@ -1,248 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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
*
* YOKO mapper, almost the same as 83, TODO: figure out difference
* Mapper 83 - 30-in-1 mapper, two modes for single game carts, one mode for
* multigame Dragon Ball Z Party
*
* Mortal Kombat 2 YOKO
* N-CXX(M), XX - PRG+CHR, 12 - 128+256, 22 - 256+256, 14 - 128+512
*
*/
#include "mapinc.h"
static uint8 mode, bank, reg[11], low[4], dip, IRQa;
static int32 IRQCount;
static uint8 *WRAM = NULL;
static uint32 WRAMSIZE;
static uint8 is2kbank, dbzParty, isYoko;
static SFORMAT StateRegs[] =
{
{ &mode, 1, "MODE" },
{ &bank, 1, "BANK" },
{ &IRQCount, 4, "IRQC" },
{ &IRQa, 1, "IRQA" },
{ reg, 11, "REGS" },
{ low, 4, "LOWR" },
{ &is2kbank, 1, "IS2K" },
{ 0 }
};
static void UNLYOKOSync(void) {
setmirror((mode & 1) ^ 1);
setchr2(0x0000, reg[3]);
setchr2(0x0800, reg[4]);
setchr2(0x1000, reg[5]);
setchr2(0x1800, reg[6]);
if (mode & 0x10) {
uint32 base = (bank & 8) << 1;
setprg8(0x8000, (reg[0] & 0x0f) | base);
setprg8(0xA000, (reg[1] & 0x0f) | base);
setprg8(0xC000, (reg[2] & 0x0f) | base);
setprg8(0xE000, 0x0f | base);
} else {
if (mode & 8)
setprg32(0x8000, bank >> 1);
else {
setprg16(0x8000, bank);
setprg16(0xC000, ~0);
}
}
}
static void M83Sync(void) {
switch (mode & 3) { /* check if it is true */
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
if (is2kbank) {
setchr2(0x0000, reg[0]);
setchr2(0x0800, reg[1]);
setchr2(0x1000, reg[6]);
setchr2(0x1800, reg[7]);
} else {
int x;
for (x = 0; x < 8; x++)
setchr1(x << 10, reg[x] | ((bank & 0x30) << 4));
}
setprg8r(0x10, 0x6000, 0);
switch (mode >>3 &3) {
case 0:
setprg16(0x8000, bank);
setprg16(0xC000, bank |0x0F);
break;
case 1:
setprg32(0x8000, bank >>1);
break;
case 2:
case 3:
setprg8(0x8000, bank <<1 &~0x1F | reg[8] &0x1F);
setprg8(0xA000, bank <<1 &~0x1F | reg[9] &0x1F);
setprg8(0xC000, bank <<1 &~0x1F | reg[10]&0x1F);
setprg8(0xE000, bank <<1 &~0x1F | 0x1F);
break;
}
}
static DECLFW(UNLYOKOWrite) {
switch (A & 0x8C17) {
case 0x8000: bank = V; UNLYOKOSync(); break;
case 0x8400: mode = V; UNLYOKOSync(); break;
case 0x8800: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break;
case 0x8801: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break;
case 0x8c00: reg[0] = V; UNLYOKOSync(); break;
case 0x8c01: reg[1] = V; UNLYOKOSync(); break;
case 0x8c02: reg[2] = V; UNLYOKOSync(); break;
case 0x8c10: reg[3] = V; UNLYOKOSync(); break;
case 0x8c11: reg[4] = V; UNLYOKOSync(); break;
case 0x8c16: reg[5] = V; UNLYOKOSync(); break;
case 0x8c17: reg[6] = V; UNLYOKOSync(); break;
}
}
static DECLFW(M83Write) {
switch (A &0x31F) {
case 0x000: bank = V; M83Sync(); break;
case 0x100: mode = V; M83Sync(); break;
case 0x200: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break;
case 0x201: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break;
case 0x300: reg[8] = V; mode &= 0xBF; M83Sync(); break;
case 0x301: reg[9] = V; mode &= 0xBF; M83Sync(); break;
case 0x302: reg[10] = V; mode &= 0xBF; M83Sync(); break;
case 0x310: reg[0] = V; M83Sync(); break;
case 0x311: reg[1] = V; M83Sync(); break;
case 0x312: reg[2] = V; M83Sync(); break;
case 0x313: reg[3] = V; M83Sync(); break;
case 0x314: reg[4] = V; M83Sync(); break;
case 0x315: reg[5] = V; M83Sync(); break;
case 0x316: reg[6] = V; M83Sync(); break;
case 0x317: reg[7] = V; M83Sync(); break;
}
}
static DECLFR(UNLYOKOReadDip) {
return (X.DB & 0xFC) | dip;
}
static DECLFR(UNLYOKOReadLow) {
return low[A & 3];
}
static DECLFW(UNLYOKOWriteLow) {
low[A & 3] = V;
}
static void UNLYOKOPower(void) {
mode = bank = 0;
dip = 3;
UNLYOKOSync();
SetReadHandler(0x5000, 0x53FF, UNLYOKOReadDip);
SetReadHandler(0x5400, 0x5FFF, UNLYOKOReadLow);
SetWriteHandler(0x5400, 0x5FFF, UNLYOKOWriteLow);
SetReadHandler(0x8000, 0xFFFF, CartBR);
SetWriteHandler(0x8000, 0xFFFF, UNLYOKOWrite);
}
static void M83Power(void) {
mode = bank = 0;
dip = 0;
M83Sync();
SetReadHandler(0x5000, 0x5000, UNLYOKOReadDip);
SetReadHandler(0x5100, 0x5103, UNLYOKOReadLow);
SetWriteHandler(0x5100, 0x5103, UNLYOKOWriteLow);
SetReadHandler(0x6000, 0x7fff, CartBR);
SetWriteHandler(0x6000, 0x7fff, CartBW);
SetReadHandler(0x8000, 0xffff, CartBR);
SetWriteHandler(0x8000, 0xffff, M83Write);
FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM);
}
static void UNLYOKOReset(void) {
dip = (dip + 1) & 3;
mode = bank = 0;
UNLYOKOSync();
}
static void M83Reset(void) {
dip ^= 1;
mode = bank = 0;
M83Sync();
}
static void M83Close(void) {
if (WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}
static void FP_FASTAPASS(1) UNLYOKOIRQHook(int a) {
if (IRQa) {
IRQCount -= a;
if (IRQCount < 0) {
X6502_IRQBegin(FCEU_IQEXT);
IRQa = 0;
IRQCount = 0xFFFF;
}
}
}
static void UNLYOKOStateRestore(int version) {
UNLYOKOSync();
}
static void M83StateRestore(int version) {
M83Sync();
}
void UNLYOKO_Init(CartInfo *info) {
info->Power = UNLYOKOPower;
info->Reset = UNLYOKOReset;
MapIRQHook = UNLYOKOIRQHook;
GameStateRestore = UNLYOKOStateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper83_Init(CartInfo *info) {
info->Power = M83Power;
info->Reset = M83Reset;
info->Close = M83Close;
MapIRQHook = UNLYOKOIRQHook;
GameStateRestore = M83StateRestore;
if (info->iNES2) {
is2kbank =info->submapper ==1;
dbzParty =info->submapper ==2;
} else {
is2kbank = info->CHRRomSize ==512*1024;
dbzParty = info->PRGRomSize ==1024*1024;
}
if (dbzParty) {
WRAMSIZE = 8192;
WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
}
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@@ -719,7 +719,7 @@ INES_BOARD_BEGIN()
INES_BOARD( "810544-C-A1", 261, BMC810544CA1_Init )
INES_BOARD( "SHERO", 262, UNLSHeroes_Init )
INES_BOARD( "KOF97", 263, UNLKOF97_Init )
INES_BOARD( "YOKO", 264, UNLYOKO_Init )
INES_BOARD( "YOKO", 264, Mapper264_Init )
INES_BOARD( "T-262", 265, Mapper265_Init )
INES_BOARD( "CITYFIGHT", 266, UNLCITYFIGHT_Init )
INES_BOARD( "8-in-1 JY-119", 267, Mapper267_Init )

View File

@@ -250,6 +250,7 @@ void Mapper252_Init(CartInfo *);
void Mapper253_Init(CartInfo *);
void Mapper254_Init(CartInfo *);
void Mapper255_Init(CartInfo *);
void Mapper264_Init(CartInfo *);
void Mapper270_Init(CartInfo *);
void Mapper272_Init(CartInfo *);
void Mapper273_Init(CartInfo *);

View File

@@ -563,7 +563,7 @@ static BMAPPING bmap[] = {
{ "UNROM-512-32", 30, UNROM512_Init, BMCFLAG_32KCHRR },
{ "UOROM", 2, UNROM_Init, 0 },
{ "VRC7", 85, UNLVRC7_Init, 0 },
{ "YOKO", 264, UNLYOKO_Init, 0 },
{ "YOKO", 264, Mapper264_Init, 0 },
{ "COOLBOY", 268, COOLBOY_Init, BMCFLAG_256KCHRR },
{ "MINDKIDS", 268, MINDKIDS_Init, BMCFLAG_256KCHRR },
{ "158B", 258, UNL8237_Init, 0 },

View File

@@ -135,7 +135,6 @@ void UNLSMB2J_Init(CartInfo *info);
void UNLT230_Init(CartInfo *info);
void UNLTF1201_Init(CartInfo *info);
void UNLVRC7_Init(CartInfo *info);
void UNLYOKO_Init(CartInfo *info);
void UNROM_Init(CartInfo *info);
void UNROM512_Init(CartInfo *info);
void COOLBOY_Init(CartInfo *info);