Some pipes lead to weird non-rooms in Super Mario Bros.

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

spieglt
Posts: 6
Joined: Thu Jan 02, 2020 1:19 pm

Some pipes lead to weird non-rooms in Super Mario Bros.

Post by spieglt » Thu Jan 02, 2020 1:44 pm

Hi! Long time lurker, first time poster. I'm working on an NES Emulator: https://github.com/spieglt/nestur. I just got the square and triangle audio channels working the other day (not merged to master yet) and before I finish audio and implement some mappers I want to take care of a strange bug I noticed a while back. In Super Mario Bros., the pipe in World 1-1 which leads to some coins works fine. The Warp Zone pipes in World 1-2 which take you to worlds 2, 3, or 4 also work fine. But some pipes, like the first in World 1-2 which is supposed to lead to a long shelf of coins with a pipe below, instead take Mario to a strange empty room with no pipe or coins. It doesn't scroll. All you can do is run back and forth until time runs out. Image of the room and the pipe that leads to it are attached. Has anyone seen anything like this before? I'm guessing it's a subtle PPU bug but I have no idea how to go about troubleshooting it. Thanks for any help you can provide!
room.png
pipe.png

FrankWDoom
Posts: 241
Joined: Mon Jan 23, 2012 11:27 pm

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by FrankWDoom » Fri Jan 03, 2020 11:13 am

Smb has some level data stored in chr iirc. Do you have chr data streaming working? I dont know where in the game that actually happens.

User avatar
Dwedit
Posts: 4356
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by Dwedit » Fri Jan 03, 2020 11:37 am

As fas as I know, it's not level data in CHR ROM, it's the title screen.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

spieglt
Posts: 6
Joined: Thu Jan 02, 2020 1:19 pm

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by spieglt » Sat Jan 04, 2020 1:33 pm

Thanks FrankWDoom and Dwedit. I do believe I have CHR-ROM mapped properly for NROM. I'm not sure what you mean by data streaming exactly. So Dwedit, that would mean it's in PRG-ROM? Someone on Reddit sent me the disassembly (https://gist.github.com/1wErt3r/4048722) for SMB, and I've been reading that trying to find where/how WarpZoneControl gets modified. The executed instructions seem to be correct when I go down the pipe compared to a good emulator. HandlePipeEntry reads WarpZoneControl repeatedly. But I'm wondering if, since WZC's value is 0, meaning not a proper "warp zone" that takes you to another World, it determines which room to drop you in another way.

I believe that the L_UndergroundArea3 symbol is the level data for the coin bonus rooms, and those bytes are at 0x2D79 in the ROM, meaning they'd be mapped to 0xAD29 in memory. I'm not sure what that level data means/does exactly, though. Won't hurt to verify that it is where I think it is and is loaded properly, though I don't see how it could be messed up.

turboxray
Posts: 104
Joined: Thu Oct 31, 2019 12:56 am

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by turboxray » Sat Jan 04, 2020 4:37 pm

Thought it was just the title screen that was in chr-rom (it's been too long so I can't remember; I emulated SMB on the PCE). But if there is more related data in PPU address space; maybe it has to do something with the "first read from PPU memory after address set needs to be ignored" issue?

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

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by lidnariq » Sat Jan 04, 2020 4:41 pm

My hunch is that there's some subtle CPU implementation bug instead of PPU wonkiness. This just doesn't feel like a PPU implementation failure to me .... well, at least as long as the sprite 0 hit is continuing to happen.

spieglt
Posts: 6
Joined: Thu Jan 02, 2020 1:19 pm

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by spieglt » Sun Jan 05, 2020 1:33 pm

I've verified that L_UndergroundArea3 is at 0xAD79 in memory and is accessed whenever Mario goes down a pipe to a coin room, and the memory at that location is correct both on my emulator and one that works.

Edit: Also, WarpZoneControl seems to be written to identically in both emulators. It's set to 0 at the start of a level and when entering a coin room, 1 when running above a Warp Zone, 4 when dropping down to the Warp Zone pipes, and back to 0 at the start of the next level. So the WarpZoneControl is correct, the level data for the coin room is correct... I'm not sure what else it can be.

Second edit: I've also verified that the enemy and level data for the underground bonus rooms are not changed when the pipe is taken to the bad room.

User avatar
tokumaru
Posts: 11869
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by tokumaru » Sun Jan 05, 2020 5:01 pm

Maybe compare logs against a known good emulator?

User avatar
dougeff
Posts: 2749
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by dougeff » Sun Jan 05, 2020 7:19 pm

lidnariq wrote:
Sat Jan 04, 2020 4:41 pm
My hunch is that there's some subtle CPU implementation bug instead of PPU wonkiness. This just doesn't feel like a PPU implementation failure to me .... well, at least as long as the sprite 0 hit is continuing to happen.
I second this. Probably forgot some processor flag setting or clearing for 1 or more instruction.

or, maybe incorrectly calculating an indirect address.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
Dwedit
Posts: 4356
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by Dwedit » Mon Jan 06, 2020 12:42 pm

Start with the basics.

First confirm that you pass CPU tests.

Then confirm that the memory map is correct, and that when you read a byte, the correct byte is read, including page crossing and zeropage wrapping.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

spieglt
Posts: 6
Joined: Thu Jan 02, 2020 1:19 pm

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by spieglt » Mon Jan 06, 2020 4:53 pm

Dwedit wrote:
Mon Jan 06, 2020 12:42 pm
Start with the basics.

First confirm that you pass CPU tests.

Then confirm that the memory map is correct, and that when you read a byte, the correct byte is read, including page crossing and zeropage wrapping.
It's passed the popular nestest.nes ROM (which includes zero page but possibly not page cross tests) since before I started on the PPU. What else specifically do you recommend?

User avatar
Dwedit
Posts: 4356
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by Dwedit » Mon Jan 06, 2020 6:28 pm

Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

spieglt
Posts: 6
Joined: Thu Jan 02, 2020 1:19 pm

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by spieglt » Mon Jan 06, 2020 9:14 pm

Thanks. Looks like I can't run the ones in instr_test-v5.zip as I haven't implemented mapper 1 yet, so maybe I'll take a detour and do that soon.

User avatar
Dwedit
Posts: 4356
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by Dwedit » Tue Jan 07, 2020 11:27 am

I think the ROM Singles are mapper 0, so you can just run those for now.
Note that they test unofficial instructions too, so if you're not trying for those at the moment, you can ignore errors regarding them.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

spieglt
Posts: 6
Joined: Thu Jan 02, 2020 1:19 pm

Re: Some pipes lead to weird non-rooms in Super Mario Bros.

Post by spieglt » Wed Jan 08, 2020 6:15 pm

Dwedit wrote:
Tue Jan 07, 2020 11:27 am
I think the ROM Singles are mapper 0, so you can just run those for now.
Note that they test unofficial instructions too, so if you're not trying for those at the moment, you can ignore errors regarding them.
Wow, thank you so much! Case closed. Test 11 crashed, which led me to find that branching to a value of 0x80 (-128) would cause an overflow because of a bad cast of i8 to usize. This fixed the pipe bug. Tests 15 and 16 also helped fix a bug with my BRK instruction. Now I only fail test 3, because I'm missing some unofficial opcodes (AAC, ASR, ARR, ATX, and AXS), and test 7 which crashes. Not sure why it crashes (tries to execute 0x9C in absolute_x mode), but it goes into an infinite loop on another emulator that seems to work well. Also, thank you again for spotting the problem with my vertical sprite flip a while back!

Post Reply