Super Mario Bros freezes when Mario reaches upper screen

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Paul_Atreides
Posts: 9
Joined: Mon Apr 13, 2020 5:24 am

Super Mario Bros freezes when Mario reaches upper screen

Post by Paul_Atreides » Thu Apr 30, 2020 1:19 pm

I'm in the process of developing my own NES emulator, strictly for learning purposes. It is an enjoyable project!

The game is playable, renders OK. However, when the Mario character reaches too high in the screen, the game freezes completely.

A way to trigger this error is to climb to the top of a floating box that's quite high, and then do a jump.

The moment Mario's sprites reach a certain 'altitude', or certain coordinates on the screen, the image freezes. The PPU keeps rendering the same image, so my deduction is the CPU isn't doing its job.

Here I'm about to climb to the highest box:
2020-04-30 21_57_37-Window.png
Here I've climbed to that box and jumped:
2020-04-30 22_10_43-.png
I'm wondering if some of you guys already have some suspicions just by hearing this description.
Thanks!

lidnariq
Posts: 9379
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Super Mario Bros freezes when Mario reaches upper screen

Post by lidnariq » Thu Apr 30, 2020 1:20 pm

I'd guess something's going wrong with your sprite 0 hit code.

User avatar
Quietust
Posts: 1555
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Super Mario Bros freezes when Mario reaches upper screen

Post by Quietust » Thu Apr 30, 2020 2:46 pm

Mario is actually always made of 8 sprites, even when he's small - in this case, the invisible sprites that would normally form Big Mario's head seem to be interfering with sprite zero (i.e. the bottom of the coin icon in the status bar).

It's also possible (though unlikely) that there's a bug in the modified version of SMB1 you're using (which has "MONDO" and "TEMPO" instead of "WORLD" and "TIME").
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

Paul_Atreides
Posts: 9
Joined: Mon Apr 13, 2020 5:24 am

Re: Super Mario Bros freezes when Mario reaches upper screen

Post by Paul_Atreides » Fri May 01, 2020 11:03 pm

It was a programming issue affecting sprite 0 hit.

I was iterating over all sprites in OAM, from 0 -> 63.
If sprite at index 0 was hit, I did the following:

sprite0Hit = spriteIdx == 0;

Which means that, if a scanline was in collision with sprite 0 AND yet another sprite, then the boolean sprite0Hit was reverted to false at spriteIdx == 1.

When Mario jumped high enough to touch the same scanline as the little coin (sprite 0), sprite 0 was never hit and the system entered an infinite loop.

This is the sort of appalling mistake that makes you question your validity as a programmer. :D

Thanks for the help. ;)

Post Reply