MMC1 - DQ4

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

MMC1 - DQ4

Post by Disch »

I've been having trouble with Dragon Quest 4 in my emu... it just gives me a grey screen.

I traced the code somewhat, and I found that it's swapping to an improper bank and running garbage code. I figure I must be doing the > 256k swapping wrong or something -- I haven't had any other problems with any other MMC1 games I've tried.

Here's a somewhat edited version of my MMC1 code. 'a' is the register written to on the final write (0-3), 'v' is the complete 5 bit written value:

Code: Select all

	switch(a)
	{
	case 0:		/* $8000 - $9FFF		*/
		if(v & 0x02)
		{
			if(v & 0x01)	DoHorzMirror();
			else			DoVertMirror();
		}
		else				Do1ScrMirror(v & 0x01);

		mprPRGSwapBank =	v & 0x04;
		mprPRGSwapSize =	v & 0x08;
		mprCHRSwapSize =	v & 0x10;
		break;

	case 1:		/* $A000 - $BFFF		*/
		if(bChrRam)
			mprPRGHighBit =	(v & 0x10);
		else if(mprCHRSwapSize)
			SwapCHR(0,4,v);
		else
			SwapCHR(0,8,v >> 1);
		break;

	case 2:		/* $C000 - $DFFF		*/
		if(!bChrRam && mprCHRSwapSize)
			SwapCHR(4,4,v);
		break;

	case 3:		/* $E000 - $FFFF		*/
  // wram disable stuff here -- removed for this paste
		v = (v & 0x0F) | (u8)(mprPRGHighBit & 0x10);
		if(mprPRGSwapSize)
		{
			if(mprPRGSwapBank)	SwapPRG(0,4,v);
			else				SwapPRG(4,4,v);
		}
		else
			SwapPRG(0,8,v >> 1);
		break;
	}
The high swap bit is taken from the $A000-$BFFF register, no? or is it both that register and the other CHR register ($C000-$DFFF)?

This is the 512k DQ4 ROM ("Dragon Quest 4 (J).nes") -- I know there's supposedly a 1024k overdump ROM out there or something, but I think I have the right one.

Anyone have any ideas? Thanks. =)
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Post by Quietust »

On the SUROM board, the upper PRG bank select bit is simply connected to the upper CHR ROM select line - this means that simply changing CHR banks will also instantly change your PRG ROM banks. It also means if you use 4KB CHR banks, both banks MUST have the SAME value in the upper bit, otherwise the PRG bank will constantly change as the PPU renders.

This is similar to the MMC3 issue posted in the other thread, in that it is easily fixed by using a single 'Sync' function for the mapper.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

Awesome... that makes a whole lot of sense -- I'll try that out in a second.

Another thing that puzzled me about MMC1 is how it reacts when you abrupty change modes. Perhaps you could clarify that for me too? ^^

Say you're in 16k PRG swapping mode, and you have bank 0 swapped in at $8000 and bank F (last bank) in at $C000, then you switch to 32k mode... does that change what ROM is accessed where? or does new stuff sort of get swapped in? Ditto for the CHR setup... do things change if you switch from 4k CHR swapping to 8k? And vice versa? Do any games actually do this?

Anyway, thanks again for the tip ^^
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Post by Quietust »

It's the same as changing the bank flipping in MMC3 - if you change MMC1 reg0, it will immediately update PRG and CHR banks as well.
Also, when using the MMC1, there is only ONE PRG bank register. If you set it to 32KB PRG bank mode, it will use that register to map a single bank at 8000-FFFF using the value in reg3 (ignoring the bottom bit). If you set it to 16KB bank mode, you can either map 16KB bank [reg3] at 8000-BFFF and the last 16KB bank at C000-FFFF or the first 16KB bank at 8000-BFFF and 16KB bank [reg3] at C000-FFFF.
The mode select register does NOT allow you to select between multiple PRG bank registers - it simply changes the way the one PRG bank register is used.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

Ah. Excellent.

Thanks again ^^
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

Finally got it all working. The game was running up until you started a game -- or a bit after the big "IV" shows on the title screen.. at which point it would crash. The one thing that was throwing me off was when the game changes the high bit (the 256k selection bit) that also determines which 16k gets swapped into $C000-$FFFF.

DQ4 leaves that range 'hard-wired' and only swaps out $8000-$BFFF... but when it changes which 256k block it's putting in $8000 that also changes which 256k block is used when taking the 16k for $C000-$FFFF

Just thought I'd bring that up just in case anyone else had the same problems as me. ^^

Thanks again Q
Post Reply