Mapper 268, submappers 8,9 merged into 2,3 and fixed (https://www.nesdev.org/wiki/Talk:NES_2.0_Mapper_268) + refactoring

This commit is contained in:
Alexey 'Cluster' Avdyukhin 2022-12-12 17:48:56 +04:00
parent 0fb86b9740
commit 773eaa868c
4 changed files with 39 additions and 71 deletions

View File

@ -82,7 +82,7 @@ const int WRAM_CHIP = 0x10;
const int CFI_CHIP = 0x11;
const int FLASH_CHIP = 0x12;
const int FLASH_SECTOR_SIZE = 128 * 1024;
const uint32 FLASH_SECTOR_SIZE = 128 * 1024;
extern uint8* WRAM;
static uint8* CFI = NULL;
@ -94,9 +94,9 @@ static uint16 flash_buffer_a[10];
static uint8 flash_buffer_v[10];
static uint8 cfi_mode = 0;
static uint16 regs_base = 0;
static uint8 flag23 = 0;
static uint8 flag45 = 0;
static uint8 flag89 = 0;
// Macronix 256-mbit memory CFI data
const uint8 cfi_data[] =
@ -119,7 +119,7 @@ const uint8 cfi_data[] =
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
static void COOLBOYCW(uint32 A, uint8 V) {
static void AA6023CW(uint32 A, uint8 V) {
uint32 mask = 0xFF ^ (EXPREGS[0] & 0b10000000);
if (EXPREGS[3] & 0b00010000) {
if (EXPREGS[3] & 0b01000000) { // Weird mode
@ -152,7 +152,7 @@ static void COOLBOYCW(uint32 A, uint8 V) {
}
}
static void COOLBOYPW(uint32 A, uint8 V) {
static void AA6023PW(uint32 A, uint8 V) {
uint8 CREGS[] = {EXPREGS[0], EXPREGS[1], EXPREGS[2], EXPREGS[3]};
// Submappers has scrambled bits
if (flag23) {
@ -162,15 +162,16 @@ static void COOLBOYPW(uint32 A, uint8 V) {
---- ----
GHIL JKKx
|||| |||
|||| +++--- PRG offset (in order: PRG A20, A22, A21)
|||| +++--- PRG offset (in order: PRG A20, A21, A22)
|||+------- GNROM mode bank PRG size (0: 32 KiB bank, PRG A14=CPU A14; 1: 16 KiB bank, PRG A14=offset A14)
||+-------- PRG mask (PRG A20 from 0: offset; 1: MMC3)
|+--------- PRG mask (PRG A19 from 0: offset; 1: MMC3)
+---------- PRG mask (PRG A18 from 0: MMC3; 1: offset)
*/
CREGS[1] = (CREGS[1] & 0b11100000)
| ((CREGS[1] & 0b00001110) << 1) // PRG A20, A22, A21
| (((CREGS[1] & 0b00010000) ^ 0b00010000) >> 3); // GNROM mode bank PRG size
CREGS[1] = (CREGS[1] & 0b11100101)
| ((CREGS[1] & 0b00001000) << 1) // PRG A20
| ((CREGS[1] & 0b00000010) << 2) // PRG A22
| ((((CREGS[1] ^ 0b00010000) & 0b00010000) >> 3)); // GNROM mode bank PRG size
}
if (flag45) {
/*
@ -194,27 +195,10 @@ static void COOLBOYPW(uint32 A, uint8 V) {
|+--------- PRG mask (PRG A19 from 0: offset; 1: MMC3)
+---------- PRG mask (PRG A18 from 0: MMC3; 1: offset)
*/
CREGS[1] = (CREGS[1] & 0b11101011)
CREGS[1] = (CREGS[1] & 0b11100011)
| ((CREGS[0] & 0b00100000) >> 3) // PRG A21
| (CREGS[0] & 0b00010000); // PRG A20
}
if (flag89) {
/*
$xxx1
7 bit 0
---- ----
GHIL JKKx
|||| |||
|||| +++--- PRG offset (in order: A20, A21, A22)
|||+------- GNROM mode bank PRG size (0: 32 KiB bank, PRG A14=CPU A14; 1: 16 KiB bank, PRG A14=offset A14)
||+-------- PRG mask (PRG A20 from 0: offset; 1: MMC3)
|+--------- PRG mask (PRG A19 from 0: offset; 1: MMC3)
+---------- PRG mask (PRG A18 from 0: MMC3; 1: offset)
*/
CREGS[1] = (CREGS[1] & 0b11100101)
| ((CREGS[1] & 0b00001000) << 1) // PRG A20
| ((CREGS[1] & 0b00000010) << 2) // PRG A22
| ((((CREGS[1] ^ 0b00010000) & 0b00010000) >> 3)); // GNROM mode bank PRG size
CREGS[0] &= 0b11001111;
}
uint32 mask = ((0b00111111 | (CREGS[1] & 0b01000000) | ((CREGS[1] & 0b00100000) << 2)) ^ ((CREGS[0] & 0b01000000) >> 2)) ^ ((CREGS[1] & 0b10000000) >> 2);
@ -257,23 +241,14 @@ static void COOLBOYPW(uint32 A, uint8 V) {
}
}
static DECLFW(COOLBOYWrite) {
static DECLFW(AA6023WramWrite) {
if (A001B & 0x80)
CartBW(A, V);
// Deny any further writes when 7th bit is 1 AND 4th is 0
if ((EXPREGS[3] & 0x90) != 0x80) {
EXPREGS[A & 3] = V;
}
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
static DECLFW(MINDKIDSWrite) {
static DECLFW(AA6023Write) {
if (A >= 0x6000) {
if (A001B & 0x80)
CartBW(A, V);
return;
AA6023WramWrite(A, V);
}
// Deny any further writes when 7th bit is 1 AND 4th is 0
@ -284,11 +259,7 @@ static DECLFW(MINDKIDSWrite) {
FixMMC3CHR(MMC3_cmd);
}
static DECLFR(COOLBOYFlashRead) {
return CartBR(A);
}
static DECLFW(COOLBOYFlashWrite) {
static DECLFW(AA6023FlashWrite) {
if (A < 0xC000)
MMC3_CMDWrite(A, V);
else
@ -366,7 +337,7 @@ static DECLFW(COOLBOYFlashWrite) {
FixMMC3PRG(MMC3_cmd);
}
static void CommonReset(void) {
static void AA6023Reset(void) {
MMC3RegReset();
EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0;
flash_state = 0;
@ -375,28 +346,25 @@ static void CommonReset(void) {
FixMMC3CHR(MMC3_cmd);
}
static void COOLBOYPower(void) {
static void AA6023Power(void) {
GenMMC3Power();
EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
SetWriteHandler(0x5000, 0x5fff, CartBW); // some games access random unmapped areas and crashes because of KT-008 PCB hack in MMC3 source lol
SetWriteHandler(0x6000, 0x6fff, COOLBOYWrite);
SetWriteHandler(0x8000, 0xFFFF, COOLBOYFlashWrite);
SetReadHandler(0x8000, 0xFFFF, COOLBOYFlashRead);
if (regs_base != 0x5000)
SetWriteHandler(0x5000, 0x5fff, CartBW); // some games access random unmapped areas and crashes because of KT-008 PCB hack in MMC3 source lol
SetWriteHandler(0x6000, 0x7fff, AA6023WramWrite);
SetWriteHandler(regs_base, regs_base + 0x0fff, AA6023Write);
SetWriteHandler(0x8000, 0xFFFF, AA6023FlashWrite);
SetReadHandler(0x8000, 0xFFFF, CartBR);
}
static void MINDKIDSPower(void) {
GenMMC3Power();
EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0;
static void AA6023Restore(void) {
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
SetWriteHandler(0x5000, 0x7fff, MINDKIDSWrite);
SetWriteHandler(0x8000, 0xFFFF, COOLBOYFlashWrite);
SetReadHandler(0x8000, 0xFFFF, COOLBOYFlashRead);
}
static void CommonClose(void) {
static void AA6023Close(void) {
if (WRAM)
FCEU_gfree(WRAM);
if (Flash)
@ -409,31 +377,31 @@ static void CommonClose(void) {
void CommonInit(CartInfo* info, int submapper)
{
GenMMC3_Init(info, 2048, info->vram_size / 1024, !info->ines2 ? 8 : (info->wram_size + info->battery_wram_size) / 1024, info->battery);
pwrap = COOLBOYPW;
cwrap = COOLBOYCW;
pwrap = AA6023PW;
cwrap = AA6023CW;
switch (submapper)
{
case 0:
case 2:
regs_base = 0x7000;
break;
case 0:
case 4:
case 8:
info->Power = COOLBOYPower;
regs_base = 0x6000;
break;
case 1:
case 3:
case 5:
case 9:
info->Power = MINDKIDSPower;
regs_base = 0x5000;
break;
default:
FCEU_PrintError("Submapper #%d is not supported", submapper);
}
flag23 = (submapper == 2) || (submapper == 3);
flag45 = (submapper == 4) || (submapper == 5);
flag89 = (submapper == 8) || (submapper == 9);
info->Reset = CommonReset;
info->Close = CommonClose;
info->Power = AA6023Power;
info->Reset = AA6023Reset;
info->Close = AA6023Close;
flash_save = info->battery;
@ -475,6 +443,6 @@ void MINDKIDS_Init(CartInfo* info) {
}
// For NES 2.0 loader
void SMD132_SMD133_Init(CartInfo* info) {
void AA6023_Init(CartInfo* info) {
CommonInit(info, info->submapper);
}

View File

@ -26,7 +26,7 @@
#include "mapinc.h"
const uint32 SAVE_FLASH_SIZE = 1024 * 1024 * 8;
const int FLASH_SECTOR_SIZE = 128 * 1024;
const uint32 FLASH_SECTOR_SIZE = 128 * 1024;
const int ROM_CHIP = 0x00;
const int WRAM_CHIP = 0x10;
const int FLASH_CHIP = 0x11;

View File

@ -729,7 +729,7 @@ BMAPPINGLocal bmap[] = {
{"F-15 MMC3 Based", 259, BMCF15_Init},
{"HP10xx/H20xx Boards", 260, BMCHPxx_Init},
{"810544-CA-1", 261, BMC810544CA1_Init},
{"SMD132/SMD133", 268, SMD132_SMD133_Init},
{"AA6023/AA6023B", 268, AA6023_Init},
{"COOLGIRL", 342, COOLGIRL_Init },
{"Impact Soft MMC3 Flash Board", 406, Mapper406_Init },

View File

@ -162,7 +162,7 @@ void MINDKIDS_Init(CartInfo *info);
void FNS_Init(CartInfo *info);
void BS400R_Init(CartInfo *info);
void BS4040R_Init(CartInfo *info);
void SMD132_SMD133_Init(CartInfo *info);
void AA6023_Init(CartInfo *info);
void COOLGIRL_Init(CartInfo* info);
extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM