M468: Cleanups and bugfixes

This commit is contained in:
NewRisingSun
2023-01-03 01:01:38 +01:00
parent 07284ca4af
commit 03fd8fb1b8
4 changed files with 109 additions and 60 deletions

View File

@@ -7,7 +7,7 @@
* 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
@@ -18,9 +18,34 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* BlazePro CPLD-based multicarts
/* BlazePro CPLD-based multicarts
Unsolved issue: how is CHR RAM write-protection triggered?
Known problems:
Forever Duo of NES 852-in-1 (rev1):
#A370 Time Lord: Hangs with glitchy status bar on NTSC and PAL but not Dendy
#A133 Galactic Crusader: Wrong mirroring
#A249 Mission Cobra: Wrong mirroring
Legendary Games of NES 509-in-1:
#189 Huang Di Battle of Zhuolu: Wrong mirroring during intro
#227 Kid Niki Niki 2: Title screen animation flickers and looks strange
#234 Klax: Screen in wrong position during options screen
#365 Rocman X: Graphical garbage in waterfall (middle) level
#403 Star Wars: Blank tiles due to lack of CHR RAM write-protection
#404 The Empire Strikes Back: Blank tiles due to lack of CHR RAM write-protection
#460 Twin Dragons: Wrong mirroring
Unlicensed Collection 142-in-1:
#59 Huang Di: Wrong mirroring during intro
#84 Ms. Pac-Man: Wrong mirroring
#102 Rocman X: Graphical garbage in waterfall (middle) level
#132 Trolls on Treasure Island: Wrong mirroring during map
Unreleased Collection 73-in-1 (v1.01):
#38 Holy Diver: Wrong mirroring during first scene
*/
#include "mapinc.h"
@@ -79,20 +104,38 @@ static SFORMAT stateRegs[] = {
{ 0 }
};
static const uint16 lut509[512] ={ /* Strange look-up table, used only by Legendary Games of NES 509-in-1 */
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 0, 1, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 4, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123,
124, 125, 126, 127, 128, 129, 2, 3, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 5, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 238, 239, 240, 241,
242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 256, 6, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281,
282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321,
322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362,
363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402,
403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482,
483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 512, 513, 514, 515, 516, 517
};
void setPins(uint8 select, uint8 newClock, uint8 newData) { /* Serial EEPROM */
if (select)
state =0;
else
if (!clock && newClock) {
if (!clock && !!newClock) {
if (state <8) {
command =command <<1 | newData*1;
command =command <<1 | !!(newData)*1;
if (++state ==8 && (command &0xF0) !=0x50 && (command &0xF0) !=0xA0) state =0;
} else {
int mask =1 <<(15 -state);
int address =command &0x0F;
if ((command &0xF0) ==0xA0)
eeprom[address] =eeprom[address] &~mask | newData*mask;
else
if ((command &0xF0) ==0xA0) {
eeprom[address] =eeprom[address] &~mask | !!(newData)*mask;
/* The "write" command also silently returns the content of a strange lookup table */
output =!!(lut509[eeprom[0] | eeprom[1] | eeprom[2] <<8 &0x1FF] >>(address &1? 0: 8) &mask);
} else
if ((command &0xF0) ==0x50)
output =!!(eeprom[address] &mask);
@@ -159,8 +202,10 @@ static DECLFW(writeReg) {
case 0x5601:
if (~misc &0x80) {
misc =V;
if (submapper !=1) prgOR =prgOR &~0x2000 | V <<9 &0x2000;
sync();
if (submapper !=1) {
prgOR =prgOR &~0x2000 | V <<9 &0x2000;
sync();
}
}
if (submapper ==1) setPins(!!(V &0x10), !!(V &0x02), !!(V &0x01));
break;
@@ -177,7 +222,8 @@ static DECLFW(writeReg) {
case 0x5702:
if (submapper ==1) {
misc2 =V;
sync();
prgOR =prgOR &~0x2000 | V <<9 &0x2000;
setMapper(0); /* The misc2 value is required for prgAND by MMC3 and UNROM */
}
break;
}
@@ -187,6 +233,7 @@ static void reset(void) {
mapper =submapper <<4;
mapperFlags =0x0F;
misc =0;
misc2 =0;
prgOR =0x7FF0;
clock =command =output =1;
command =state =0;

View File

@@ -34,17 +34,16 @@ static void UNROM_sync () {
}
static DECLFW(DISCRETE_writeLatch) {
if (mapper ==0x09 && mapperFlags ==0xE && A ==0xA000 && V ==0x00)
V =0x06; // UNROM: Strange hack, needed to get #282 "Portopia Serial Murder Case" on 852-in-1 running
latch =V;
sync();
}
static DECLFW(GNROM_writeLatch) {
if (~prgOR &0x2000 || mapper ==0x1C || mapper==0x1D)
V =V >>4 &0xF | V <<4 &0xF0; // Color Dreams: swap nibbles to mimic GNROM
latch =V;
sync();
static DECLFW(Portopia_writeLatch) {
DISCRETE_writeLatch(A, A ==0xA000 && V ==0x00? 0x06: V); /* Strange hack, needed to get #282 "Portopia Serial Murder Case" on 852-in-1 running */
}
static DECLFW(ColorDreams_writeLatch) {
DISCRETE_writeLatch(A, V >>4 &0xF | V <<4 &0xF0); /* Sswap nibbles to mimic GNROM */
}
@@ -59,15 +58,15 @@ void ANROM_BNROM_reset(uint8 clearRegs) {
void GNROM_reset(uint8 clearRegs) {
sync =GNROM_sync;
prgAND =mapperFlags &8? 0x07: 0x0F;
SetWriteHandler(0x8000, 0xFFFF, GNROM_writeLatch);
SetWriteHandler(0x8000, 0xFFFF, misc &0x10 && mapper &~0x10? DISCRETE_writeLatch: ColorDreams_writeLatch);
latch =0;
sync();
}
void UNROM_reset(uint8 clearRegs) {
sync =UNROM_sync;
prgAND =mapper ==0x0B || mapper ==0x17 &&~mapperFlags &8? 0x3F: mapperFlags &2? 0x0F: 0x1F;
SetWriteHandler(0x8000, 0xFFFF, DISCRETE_writeLatch);
prgAND =mapper ==0x0B || misc2 &0x10? 0x3F: mapperFlags &2? 0x0F: 0x1F;
SetWriteHandler(0x8000, 0xFFFF, mapper ==0x09 && mapperFlags ==0xE? Portopia_writeLatch: DISCRETE_writeLatch);
sync();
}

View File

@@ -1,41 +1,40 @@
#define MMC1_reg regByte
#define MMC1_shift regByte[4]
#define MMC1_count regByte[5]
#define MMC1_filter regByte[6]
#define MMC1_reg regByte
#define MMC1_control regByte[0]
#define MMC1_chr0 regByte[1]
#define MMC1_chr1 regByte[2]
#define MMC1_prg regByte[3]
#define MMC1_shift regByte[4]
#define MMC1_count regByte[5]
#define MMC1_filter regByte[6]
static void MMC1_sync () {
int AND =prgAND >>1;
int OR =prgOR >>1 | (mapper &0x01? (MMC1_reg[1] &0x10): (mapperFlags &0x06));
if (MMC1_reg[0] &0x8) { /* 16 KiB mode */
if (MMC1_reg[0] &0x04) { /* OR logic */
setprg16(0x8000, MMC1_reg[3] &AND | OR &~AND);
setprg16(0xC000, 0xFF &AND | OR &~AND);
int OR =prgOR >>1 | (mapper &0x01? (MMC1_chr0 &0x10): (mapperFlags &0x06));
if (MMC1_control &0x08) { /* 16 KiB mode */
if (MMC1_control &0x04) { /* OR logic */
setprg16(0x8000, MMC1_prg &AND | OR &~AND);
setprg16(0xC000, 0xFF &AND | OR &~AND);
} else { /* AND logic */
setprg16(0x8000, 0x00 &AND | OR &~AND);
setprg16(0xC000, MMC1_reg[3] &AND | OR &~AND);
setprg16(0x8000, 0 &AND | OR &~AND);
setprg16(0xC000, MMC1_prg &AND | OR &~AND);
}
} else
setprg32(0x8000, (MMC1_reg[3] &AND | OR &~AND) >>1);
AND =mapper &0x01? 0x0F: 0x1F;
if (MMC1_reg[0] &0x10) { /* 4 KiB mode */
setchr4(0x0000, MMC1_reg[1] &AND);
setchr4(0x1000, MMC1_reg[2] &AND);
} else /* 8 KiB mode */
setchr8(MMC1_reg[1] >>1 &(AND >>1));
setprg32(0x8000, (MMC1_prg &AND | OR &~AND) >>1);
switch(MMC1_reg[0] &3) {
case 0: setmirror(MI_0); break;
case 1: setmirror(MI_1); break;
case 2: setmirror(MI_V); break;
case 3: setmirror(MI_H); break;
}
AND =mapper &0x01? 0x0F: 0x1F; /* SUROM needs to have the upper PRG bank bit, which is in the CHR registers, masked off */
if (MMC1_control &0x10) { /* 4 KiB mode */
setchr4(0x0000, MMC1_chr0 &AND);
setchr4(0x1000, MMC1_chr1 &AND);
} else /* 8 KiB mode */
setchr8(MMC1_chr0 >>1 &(AND >>1));
setmirror(MMC1_control &2? (MMC1_control &1? MI_H: MI_V): (MMC1_control &1? MI_1: MI_0));
}
static DECLFW(MMC1_writeReg) {
if (V &0x80) {
MMC1_shift =MMC1_count =0;
MMC1_reg[0] |=0x0C;
MMC1_control |=0x0C;
sync();
} else
if (!MMC1_filter) {
@@ -59,12 +58,15 @@ void MMC1_reset(uint8 clearRegs) {
MapIRQHook =MMC1_cpuCycle;
prgAND =mapperFlags &2? (mapperFlags &8? 0x07: 0x0F): 0x1F;
SetWriteHandler(0x8000, 0xFFFF, MMC1_writeReg);
if (clearRegs) MMC1_reg[0] =0x0C;
if (clearRegs) MMC1_control =0x0C;
sync();
}
#undef MMC1_reg
#undef MMC1_control
#undef MMC1_chr0
#undef MMC1_chr1
#undef MMC1_prg
#undef MMC1_shift
#undef MMC1_count
#undef MMC1_filter

View File

@@ -1,19 +1,19 @@
#define MMC3_reg regByte
#define MMC3_index regByte[8]
#define MMC3_reg regByte
#define MMC3_index regByte[8]
#define MMC3_mirroring regByte[9]
#define MMC3_wram regByte[10]
#define MMC3_reload regByte[11]
#define MMC3_count regByte[12]
#define MMC3_irq regByte[13]
#define MMC3_lastReg regByte[14]
#define MMC3_wram regByte[10]
#define MMC3_reload regByte[11]
#define MMC3_count regByte[12]
#define MMC3_irq regByte[13]
#define MMC3_lastReg regByte[14]
static void MMC3_sync () {
int chrAND =mapper &0x01? 0xFF: 0x7F;
int OR =prgOR | (misc2 &1? 12: 0);
setprg8(0x8000 ^(MMC3_index <<8 &0x4000), MMC3_reg[6] &prgAND | prgOR &~prgAND);
setprg8(0xA000, MMC3_reg[7] &prgAND | prgOR &~prgAND);
setprg8(0xC000 ^(MMC3_index <<8 &0x4000), 0xFE &prgAND | prgOR &~prgAND);
setprg8(0xE000, 0xFF &prgAND | prgOR &~prgAND);
setprg8(0x8000 ^(MMC3_index <<8 &0x4000), MMC3_reg[6] &prgAND | OR &~prgAND);
setprg8(0xA000, MMC3_reg[7] &prgAND | OR &~prgAND);
setprg8(0xC000 ^(MMC3_index <<8 &0x4000), 0xFE &prgAND | OR &~prgAND);
setprg8(0xE000, 0xFF &prgAND | OR &~prgAND);
setchr1(0x0000 ^(MMC3_index <<5 &0x1000),(MMC3_reg[0] &0xFE)&chrAND);
setchr1(0x0400 ^(MMC3_index <<5 &0x1000),(MMC3_reg[0] |0x01)&chrAND);
setchr1(0x0800 ^(MMC3_index <<5 &0x1000),(MMC3_reg[1] &0xFE)&chrAND);
@@ -29,7 +29,7 @@ static void MMC3_sync () {
case 2: setmirror(MMC3_reg[MMC3_lastReg] &0x80? MI_1: MI_0); break;
case 3: setmirror(MI_1); break;
} else
setmirror(MMC3_mirroring &1 ^1);
setmirror(MMC3_mirroring &1? MI_H: MI_V);
}
static DECLFW(MMC3_writeReg) {
@@ -66,6 +66,7 @@ void MMC3_reset(uint8 clearRegs) {
if (mapper &2) PPU_hook =MMC3_ppuHook;
prgAND =mapperFlags &8? (mapperFlags &4? (mapperFlags &2? (misc2 &2? 0x07: 0x0F): 0x1F): 0x3F): 0x7F;
SetWriteHandler(0x8000, 0xFFFF, MMC3_writeReg);
MMC3_mirroring =1; /* "Legendary Games of NES' 509-in-1"'s menu runs as MMC3 with H mirroring and expects that setting to stay when running a mapper 206 game such as Legend of Valkyrie. */
sync();
}