Glitch when Mario stops running in SMB

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
stickzman
Posts: 3
Joined: Tue Sep 04, 2018 10:07 am

Glitch when Mario stops running in SMB

Post by stickzman » Tue Sep 04, 2018 10:17 am

Hey guys, I'm ironing out bugs in my emulator and I found a strange glitch in Super Mario Bros and was looking for some direction on where to look for the bug.

When Mario is running to the right, the moment you let go of the right button, instead of Mario slowing to a stop, he is pulled backwards and the animation looks as if he had just been running left and is making a sharp turn. If he's moving fast enough, he will do this incorrect behavior twice in a row.

I don't think it's a problem with controller input, because the same bug appears if you watch the title screen animation. I've attached a video of the issue below.

Thanks in advance for any help!

https://drive.google.com/open?id=1kontv ... c1vMkoOiKk

User avatar
zeroone
Posts: 929
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: Glitch when Mario stops running in SMB

Post by zeroone » Tue Sep 04, 2018 11:07 am

Does your emulator pass the CPU test ROMs?

stickzman
Posts: 3
Joined: Tue Sep 04, 2018 10:07 am

Re: Glitch when Mario stops running in SMB

Post by stickzman » Tue Sep 04, 2018 11:17 am

Apparently not. Nestest works completely, but the next I tried failed (branch_timing_tests). I'll work on getting those to run correctly for now. Is there a best order in which to tackle these tests?

Thanks!

User avatar
koitsu
Posts: 4216
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Glitch when Mario stops running in SMB

Post by koitsu » Tue Sep 04, 2018 11:51 am

Random brain dump:

Problems of this nature are usually incorrect emulation of 6502 opcodes, particularly CPU flags. Bad $4016/4017 implementation is certainly a possible too, but it's always best to rule out CPU instruction issues *first*.

That said, anything is possible, so sure, it could be your $4016/4017 emulation. If you could explain how you implemented it (read: don't dump code at us, or tell us to read your code as an explici answer), that would be good. Having code to reference is helpful, but the only one who truly knows it and what all your variables are for/do/etc. is you. Sometimes explaining something to others helps you work through what could be a mistake, inducing self-realisation of the problem.

Also, if SMB is the only game you're using to test, I suggest using something else. Try some mapper 0 (NROM) games for starters, first-gen titles (Donkey Kong, Mario Bros, Clu Clu Land, Ice Hockey, etc.). SMB is a particularly "rough" game to start with. If you find similarly odd quirks in other games relating to joypad input of this nature, then that may help you.

stickzman
Posts: 3
Joined: Tue Sep 04, 2018 10:07 am

Re: Glitch when Mario stops running in SMB

Post by stickzman » Fri Sep 07, 2018 7:38 am

Fixed it! There was a bug with how I was setting the negative flag. Blargg's instr_test_v5 was a big help tracking this down.

With that, all the NROM games I tested work, as well as a number of MMC1. Woohoo!

Post Reply