Broken FDS emulation: Kiki Kaikai - Dotou Hen

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

procyon
Posts: 1
Joined: Thu Jun 17, 2010 12:57 pm

Broken FDS emulation: Kiki Kaikai - Dotou Hen

Post by procyon »

Hi everyone. I began to write a guide on how to play this FDS port of the Taito arcade game Kiki Kaikai (the series that came to be known as Pocky & Rocky on the SNES), but I have come across a strange problem. There are two boss fights that crash just about every modern NES emulator that I have tried, including FCEUX, Nestopia, Nintendulator, Mednafen, and VirtuaNES. The _only_ emulator that the game works properly on is the "old" emulator NNNesterJ. It's very strange, where those five other emulators hang, NNNesterJ goes swimmingly right along. (Interesting to note, for those of you who can read Japanese, a warning to this effect is present on this page: http://www25.atwiki.jp/famicomall/pages/244.html which you can run through Google Translator if need be.)

It's not too hard to get to the crash point, although it takes a few minutes of walking (if you avoid all of the enemies.) The ROM that I'm using (and the only one that seems to be available) is from the TOSEC set with a CRC of 4C791779. From the start point, walk straight up. Keep following the path north until you get the first chance to travel east (you'll cross a few bridges just before that point.) Head east as soon as you are able, and then take the very next path south. This will lead you down and around to the entrance of a cave. You need 50 Ofuda cards to enter the cave, which is what you start with (you earn Ofuda cards by defeating enemies with your wand). Once inside, the path to the boss never branches. You travel north, then east, and the north. At the top of the second north path is the boss room. The expected result (and the one which NNNesterJ produces) is that the room scrolls into view, turns blue, and a large boss starts to attack you. The actual result in the rest of the emulators I've tried is that they hang before the room turns blue, stuck playing one note.

I know this is the sort of thing that is incredibly low priority in the grand scheme of things, but I thought it might be interesting for some of the more active emulator developers to look at and try to figure out what NNNesterJ is doing differently (correctly or perhaps incorrectly) that allows the game to play in this one particular emulator. I would love to know myself. Thanks for taking a look!

Procyon
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Post by *Spitfire_NES* »

no to raise the dead but thats interesting. just tried this game out and i wonder what the problem could be....
Drag
Posts: 1350
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Post by Drag »

Does it actually crash the emulator into closing itself, or does the game just freeze?
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Post by *Spitfire_NES* »

Drag wrote:Does it actually crash the emulator into closing itself, or does the game just freeze?
the emulator neither freezes nor crashes, the game hangs when you enter the boss's room. Weird how nesterj could play this right but no others...seems like something blocks the boss from appearing or something...

Give it a try in nestopia, when you reach one of the boss's rooms it just kinda hangs, and nothing happens, the music freezes on one note, i used rewind to leave the room, but i know the emu does not crash.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Illegal opcodes maybe? Maybe one not documented very well? Weird thing. And you can't track it down?
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Post by *Spitfire_NES* »

3gengames wrote:Illegal opcodes maybe? Maybe one not documented very well? Weird thing. And you can't track it down?
i have no clue whats causing it, i always thought fds was pretty much 100 percent working and great. i came across this thread yesterday and since then it has peaked my interest. comparing code from NNNnesterj to nestopia is hard to do lol, :shock:


***update. My mistake the game does in fact crash.
User avatar
Gilbert
Posts: 479
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Post by Gilbert »

The linked page indeed said that VirtuaNES reported an illegal opcode error.
Maybe someone who have time would try to trace the code there with a debugger enabled emulator (Nintendulator, FCE*whatever* or even No$NES).
User avatar
plasturion
Posts: 63
Joined: Thu Jun 02, 2011 2:05 am
Contact:

Post by plasturion »

I walked to the 1st boss with Nestopia debug mode and it throws illegal opcodes BRK and JAM causing CPU JAM! At titlescreen throws Expression: modulator.writing with Fds::Sound::WriteReg7.
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Post by *Spitfire_NES* »

plasturion wrote:I walked to the 1st boss with Nestopia debug mode and it throws illegal opcodes BRK and JAM causing CPU JAM! At titlescreen throws Expression: modulator.writing with Fds::Sound::WriteReg7.
so we need to erase/modify the illegal opcodes then... so it threw an error with sound, writereg7...hmm.
User avatar
plasturion
Posts: 63
Joined: Thu Jun 02, 2011 2:05 am
Contact:

Post by plasturion »

I think maybe something cause that this opcodes appears. So best way is try to find out if WriteReg7 don't make any mess.

Let's see what is doing - Nestopia NstFds.cpp

Code: Select all

		NES_POKE_D(Fds,4088)
		{
			sound.WriteReg7( data );
		}
		
		void Fds::Sound::WriteReg7(uint data)
		{
			NST_VERIFY( modulator.writing );

			if (modulator.writing)
			{
				Update();
				std::memmove( modulator.table, modulator.table + 1, Modulator::SIZE-1 );
				modulator.table[Modulator::SIZE-1] = Modulator::steps[data & REG8_MOD_DATA];
			}
		}
and NNNesterJ 0.23 in fdssnd.c

Code: Select all

static void FDSSoundWrite(uint32 address, uint8 value)
{
	if (0x4040 <= address && address <= 0x407F)
	{
		apu->fdssound.op[1].wave[address - 0x4040] = LinearToLog(((int32)value & 0x3f) - 0x20);
	}
	else if (0x4080 <= address && address <= 0x408F)
	{
		int ch = (address < 0x4084);
		FDS_FMOP *pop = &apu->fdssound.op[ch];
		apu->fdssound.reg[address - 0x4080] = value;
		switch (address & 15)
		{
...
			case 8:
				{
					static int8 lfotbl[8] = { 0,1,2,3,-4,-3,-2,-1 };
					uint32 v = LinearToLog(lfotbl[value & 7]);
					apu->fdssound.op[0].wave[apu->fdssound.waveaddr++] = v;
					apu->fdssound.op[0].wave[apu->fdssound.waveaddr++] = v;
					if (apu->fdssound.waveaddr == 0x40)
					{
						apu->fdssound.waveaddr = 0;
					}
				}
				break;
that's only suggest, I'm not sure it can be somehow connected with this issue, however the soundtrack is changing while the boss appears. It takes only last hex digit of address, so we're looking case 8?

Damn... I need to register if I want using VC++ express. The time trial has expired. Maybe this time someone else wants to have fun ;).
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Is it running code from RAM? Maybe your CPU is causing something in RAM to be changed wrong and crash?
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Post by *Spitfire_NES* »

3gengames wrote:Is it running code from RAM? Maybe your CPU is causing something in RAM to be changed wrong and crash?
whatever it is, 5 diff emus are all proving to do the same thing including nestopia, virtuanes and others....
Drag
Posts: 1350
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Post by Drag »

Perhaps the image really seriously is broken (bad "dump", I guess), and the fact that nesterj allowed the game to run was due to a bug?

It could also be the result of copy protection of some kind; I know disk-based c64 software had some hardware-implemented copy protections, such as purposefully unreadable sectors.
User avatar
plasturion
Posts: 63
Joined: Thu Jun 02, 2011 2:05 am
Contact:

Post by plasturion »

I've checked where fce ultra debug tool stuck when the boss seems to appear and...

Code: Select all

00:803B:03        UNDEFINED
00:803C:01 03     ORA ($03,X) @ $02F3 = #$72
00:803E:61 62     ADC ($62,X) @ $0000 = #$D3
00:8040:F0 00     BEQ $8042
00:8042:00        BRK
00:8043:00        BRK
00:8044:92        UNDEFINED // Here debug trace stuck 
00:8045:24 49     BIT $0049 = #$00
00:8047:92        UNDEFINED
00:8048:24 49     BIT $0049 = #$00
00:804A:DB        UNDEFINED
00:804B:B6 6D     LDX $006D,Y @ $0080 = #$FE
00:804D:DB        UNDEFINED
00:804E:B6 6D     LDX $006D,Y @ $0080 = #$FE
00:8050:04        UNDEFINED
looks like this is not so good place to code execute.
User avatar
*Spitfire_NES*
Posts: 306
Joined: Fri May 21, 2010 4:10 pm

Post by *Spitfire_NES* »

So looks like something needs to be added or modified...maybe an exception to address while boss appears and music changing. Isn't fce issue the same as nestopia?
Post Reply