Super Mario triggers hidden blocks

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
w1n5t0n
Posts: 2
Joined: Tue May 04, 2021 12:52 am

Super Mario triggers hidden blocks

Post by w1n5t0n »

I've been working on my emulator https://github.com/w1n5t0n99/rustnes and Super Mario has an odd glitch I haven't been able to track down. Every time Mario jumps he triggers an invisible box. He will climb invincible steps and eventually fall in invisible hole. Visually everything appears as it should and my CPU passes nestest. Any help would be greatly appreciated.
User avatar
Quietust
Posts: 1918
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Super Mario triggers hidden blocks

Post by Quietust »

I would recommend running blargg's tests (especially "instr_test_v5"), since there are apparently several potential bugs that "nestest" fails to detect.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
w1n5t0n
Posts: 2
Joined: Tue May 04, 2021 12:52 am

Re: Super Mario triggers hidden blocks

Post by w1n5t0n »

Quietust wrote: Tue May 04, 2021 12:56 pm I would recommend running blargg's tests (especially "instr_test_v5"), since there are apparently several potential bugs that "nestest" fails to detect.
Thanks for the tip. It seems ADC, RRA, and AXS are failing. I imagine it's a flag but I'm not sure what Blaarg is checking for that nestest isn't.
User avatar
Quietust
Posts: 1918
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: Super Mario triggers hidden blocks

Post by Quietust »

w1n5t0n wrote: Wed May 05, 2021 10:44 am Thanks for the tip. It seems ADC, RRA, and AXS are failing. I imagine it's a flag but I'm not sure what Blaarg is checking for that nestest isn't.
Your logic for setting the Overflow flag is incorrect:

Code: Select all

            cpu.a = result;

            if ((cpu.ops.dl ^ result) & (cpu.a & result) & 0x80) == 0x80 { cpu.p.set(StatusRegister::OVERFLOW, true) } else { cpu.p.set(StatusRegister::OVERFLOW, false) };
First, you need to calculate the flag before updating the accumulator.
Second, the correct expression for Overflow should be (~(cpu.a ^ cpu.ops.dl) & (cpu.a ^ result) & 0x80).

Looking at nestest, it appears to test the following expressions:
  • 0 + 105 = 105 -> no overflow
  • 1 + 105 + C = 107 -> no overflow
  • 127 + 127 + C = -1 -> overflow
  • 127 + -128 = -1 -> no overflow
  • 127 + -128 + C = 0 -> no overflow
Notably, it does not test any "negative + negative = positive" scenarios.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.
Post Reply