Page 1 of 1

Glitch when Mario stops running in SMB

Posted: Tue Sep 04, 2018 10:17 am
by stickzman
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

Re: Glitch when Mario stops running in SMB

Posted: Tue Sep 04, 2018 11:07 am
by zeroone
Does your emulator pass the CPU test ROMs?

Re: Glitch when Mario stops running in SMB

Posted: Tue Sep 04, 2018 11:17 am
by stickzman
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!

Re: Glitch when Mario stops running in SMB

Posted: Tue Sep 04, 2018 11:51 am
by koitsu
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.

Re: Glitch when Mario stops running in SMB

Posted: Fri Sep 07, 2018 7:38 am
by stickzman
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!