Super Mario Bros slides too much

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Super Mario Bros slides too much

Post by DarkMoe »

Hi ! After 2 weeks of programming my first NES emulator, I managed to get Donkey Kong working, Karateka working, and probably some others.

Super Mario Bros demanded lots of changes, I had to rewrite my entire video handling since the top bar keep flickering and missing sprite 0 hits, but now it works perfectly.

Except, for some weird reason, Mario has too many momentum, and if I run, he will only stop after 2 seconds. I have no idea what is causing this.

I think it should be logic related, but my cpu is passing all the official opcodes with that nestest rom.

Also, in the demo, Mario dies with the first goomba, again, probably because he cannot stop quick enough to jump !

Since most people here know every emulation bug on SMB, do you have any hints or idea of what may be causing this weird behaviour ?
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Super Mario Bros slides too much

Post by thefox »

NESTest is not conclusive. Try blargg's CPU test ROMs.

It definitely sounds like a CPU bug.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
x0000
Posts: 43
Joined: Thu Feb 28, 2013 11:14 am
Contact:

Re: Super Mario Bros slides too much

Post by x0000 »

My first step would be verifying ROM checksums and checking if it is runs the same way in other emulators. It is definitely CPU bug assuming you have a good rom.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Super Mario Bros slides too much

Post by Dwedit »

Even if the instructions are executed correctly, sometimes the RAM or memory map implementation might have bugs. Not sure if that's the case here or not.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: Super Mario Bros slides too much

Post by Zepper »

Perhaps non-sense, but did you check your joypad polling ($4016/17)?
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Super Mario Bros slides too much

Post by DarkMoe »

I'm trying to implement MMC1 for that test rom, since it requires it.

I'm gonna check the joypad inputs, weird since they seem to work correctly for other games. I'll see what I can find
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Super Mario Bros slides too much

Post by tokumaru »

DarkMoe wrote:I'm gonna check the joypad inputs, weird since they seem to work correctly for other games. I'll see what I can find
Games read the controllers in different ways... Some rely on open bus, or use more than 1 bit from the byte read from the controller register, or expect different results when reading them more than 8 times... There's plenty that can go wrong with input handling, even if it works fine in most games.
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Super Mario Bros slides too much

Post by DarkMoe »

Ok so my current logic is this:

when writting to 4016, bit 0 is strobe bit.
When reading 4016, I have an internal pointer that gets a bit from my buttons status, if strobe is 1, returns the current bit of the buttons (ored with 0x40, read somewhere that paperboy needed that), increment the pointer (wraps at 8). If strobe is 0, always return the first bit of the buttons status (A button).

Seems like Mario is always writting 0 and 1 to strobe, and then proceeds to read the 8 bits for the buttons, so it doesn't look like it relies on weird behaviour. But you are the experts =)

any leads ?
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Super Mario Bros slides too much

Post by rainwarrior »

It doesn't wrap at 8. Usually it will start returning all 1 bits after 8 (though some devices have other behaviour).

Games don't normally read more than 8, though, unless because of the DPCM glitch.
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Super Mario Bros slides too much

Post by DarkMoe »

Ok, changed the behaviour for not wrapping that pointer. Of course this didn't fix Mario's movement but thanks
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Super Mario Bros slides too much

Post by koitsu »

I'd still maintain this is a CPU emulation instruction or addressing mode bug.

An alternate approach would be to implement a trace log identical to Nintendulator or FCEUX, then compare the results to your emulator.

Also, are you zeroing the memory contents of $0000-07FF in your emulator before the game starts up? Uninitialised areas of allocated memory could result in odd behaviour.
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Super Mario Bros slides too much

Post by DarkMoe »

Yes sir, Im doing all that.

I will come back with results once I can run those cpu tests, again, I need to implement MMC1.

Thanks for your help !
fred
Posts: 67
Joined: Fri Dec 30, 2011 7:15 am
Location: Sweden

Re: Super Mario Bros slides too much

Post by fred »

All the "rom_singles" tests in instr_test do not need MMC1, so you could try that.
User avatar
Quietust
Posts: 1920
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Super Mario Bros slides too much

Post by Quietust »

DarkMoe wrote: When reading 4016, I have an internal pointer that gets a bit from my buttons status, if strobe is 1, returns the current bit of the buttons (ored with 0x40, read somewhere that paperboy needed that), increment the pointer (wraps at 8). If strobe is 0, always return the first bit of the buttons status (A button).
Er, I'm pretty sure that's backwards - strobe=1 is when the button states are copied into the shift register, and strobe=0 is what allows them to be read back.
DarkMoe wrote:Seems like Mario is always writting 0 and 1 to strobe, and then proceeds to read the 8 bits for the buttons.
Actually, it writes 1 followed by 0, just like every other NES game which uses standard controllers.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Super Mario Bros slides too much

Post by DarkMoe »

Managed to fix it.

Turns out my shift left function, was setting carry flag from bit 7 of Accumulator, instead of using the operator passed to the function.

Figured it out implementing unofficial opcodes that use the ASL function.
Post Reply