@@ -48,7 +48,7 @@ static void DoNamcoSound(int32 *Wave, int Count);
4848static void DoNamcoSoundHQ (void );
4949static void SyncHQ (int32 ts);
5050
51- static int is210; /* Lesser mapper. */
51+ static enum NamcoType { N163, N175, N340 } type;
5252
5353static uint8 PRG[3 ];
5454static uint8 CHR[8 ];
@@ -63,15 +63,13 @@ static SFORMAT N106_StateRegs[] = {
6363 { 0 }
6464};
6565
66- static void SyncMirror ()
67- {
66+ static void N340SyncMirror () {
6867 switch (gorko) {
6968 case 0 : setmirror (MI_0); break ;
7069 case 1 : setmirror (MI_V); break ;
71- case 2 : setmirror (MI_H ); break ;
72- case 3 : setmirror (MI_0 ); break ;
70+ case 2 : setmirror (MI_1 ); break ;
71+ case 3 : setmirror (MI_H ); break ;
7372 }
74-
7573}
7674
7775static void SyncPRG (void ) {
@@ -129,9 +127,8 @@ static void FixNTAR(void) {
129127
130128static void DoCHRRAMROM (int x, uint8 V) {
131129 CHR[x] = V;
132- if (!is210 && !((gorfus >> ((x >> 2 ) + 6 )) & 1 ) && (V >= 0xE0 )) {
133- // printf("BLAHAHA: %d, %02x\n",x,V);
134- // setchr1r(0x10,x<<10,V&7);
130+ if (type == N163 && V >= 0xE0 && !(gorfus >> (x >> 2 ) & 1 )) {
131+ setchr1r (0x10 , x << 10 , V);
135132 } else
136133 setchr1 (x << 10 , V);
137134}
@@ -197,16 +194,16 @@ static DECLFW(Mapper19_write) {
197194 break ;
198195 case 0xE000 :
199196 PRG[0 ] = V & 0x3F ;
200- if (is210) {
201- gorko = V>>6 ;
202- SyncMirror ();
203- }
197+ gorko = V >> 6 ;
198+ if (type == N340)
199+ N340SyncMirror ();
204200 SyncPRG ();
205201 break ;
206202 case 0xE800 :
207- gorfus = V & 0xC0 ;
208- FixCRR ();
209203 PRG[1 ] = V & 0x3F ;
204+ gorfus = V >> 6 ;
205+ if (type == N163)
206+ FixCRR ();
210207 SyncPRG ();
211208 break ;
212209 case 0xF000 :
@@ -351,7 +348,6 @@ static void DoNamcoSound(int32 *Wave, int Count) {
351348
352349static void Mapper19_StateRestore (int version) {
353350 SyncPRG ();
354- SyncMirror ();
355351 FixNTAR ();
356352 FixCRR ();
357353 int x;
@@ -384,8 +380,8 @@ static void N106_Power(void) {
384380 int x;
385381 SetReadHandler (0x8000 , 0xFFFF , CartBR);
386382 SetWriteHandler (0x8000 , 0xffff , Mapper19_write);
387- SetWriteHandler (0x4020 , 0x5fff , Mapper19_write);
388- if (!is210 ) {
383+ SetWriteHandler (0x4800 , 0x5fff , Mapper19_write);
384+ if (type == N163 ) {
389385 SetWriteHandler (0xc000 , 0xdfff , Mapper19C0D8_write);
390386 SetReadHandler (0x4800 , 0x4fff , Namco_Read4800);
391387 SetReadHandler (0x5000 , 0x57ff , Namco_Read5000);
@@ -411,19 +407,20 @@ static void N106_Power(void) {
411407}
412408
413409void Mapper19_Init (CartInfo *info) {
414- is210 = 0 ;
410+ type = N163 ;
415411 battery = info->battery ;
416412 info->Power = N106_Power;
417413
418414 MapIRQHook = NamcoIRQHook;
419415 GameStateRestore = Mapper19_StateRestore;
420416 GameExpSound.RChange = M19SC;
421417
418+ // NTARAM can be mapped as CHR (does any game ever actually do this?)
419+ SetupCartCHRMapping (0x10 , NTARAM, 0x800 , 1 );
420+
422421 if (FSettings.SndRate )
423422 Mapper19_ESI ();
424423
425- FCEU_MemoryRand (WRAM, sizeof (WRAM), true );
426- FCEU_MemoryRand (IRAM, sizeof (IRAM), true );
427424 AddExState (WRAM, 8192 , 0 , " WRAM" );
428425 AddExState (IRAM, 128 , 0 , " IRAM" );
429426 AddExState (N106_StateRegs, ~0 , 0 , 0 );
@@ -437,13 +434,36 @@ void Mapper19_Init(CartInfo *info) {
437434static void Mapper210_StateRestore (int version) {
438435 SyncPRG ();
439436 FixCRR ();
437+ if (type == N340)
438+ N340SyncMirror ();
439+ }
440+
441+ static NamcoType Mapper210_DetectType (CartInfo *info) {
442+ if (info->ines2 && info->submapper == 1 )
443+ return N175;
444+ if (info->ines2 && info->submapper == 2 )
445+ return N340;
446+ FCEU_printf (" Submapper detected by CRC32. Use NES 2.0 if you hack the ROM image.\n " );
447+ switch (info->CRC32 ) {
448+ case 0x0c47946d : // Chibi Maruko Chan
449+ case 0xbd523011 : // Dream Master
450+ case 0xc247cc80 : // Family Circuit '91
451+ case 0x808606f0 : // Famista '91
452+ case 0x81b7f1a8 : // Heisei Tensai Bakabon
453+ return N175;
454+ default :
455+ return N340;
456+ }
440457}
441458
442459void Mapper210_Init (CartInfo *info) {
443- is210 = 1 ;
460+ type = Mapper210_DetectType (info);
461+ battery = info->battery ;
444462 GameStateRestore = Mapper210_StateRestore;
445463 info->Power = N106_Power;
446- FCEU_MemoryRand (WRAM, sizeof (WRAM), true );
447464 AddExState (WRAM, 8192 , 0 , " WRAM" );
448465 AddExState (N106_StateRegs, ~0 , 0 , 0 );
466+
467+ if (info->battery )
468+ info->addSaveGameBuf ( WRAM, 8192 );
449469}
0 commit comments