Donkey Kong bugged score and jump

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
joshop
Posts: 2
Joined: Sun Mar 21, 2021 11:36 am

Donkey Kong bugged score and jump

Post by joshop » Sun Mar 21, 2021 12:25 pm

Hello,
My NES emulator works fairly accurately (as far as I can tell) running Mario Bros. (although no audio), and it almost works with Donkey Kong. There are two main noticeable bugs:
  • Mario's jump height is seemingly infinite; he can jump from one platform to the next and is only stopped by reaching the next platform; on the top platform, jumping causes you to wrap around and die upon reaching the bottom platform.
  • The bonus display is extremely strange. It starts at 5000, and then goes to B1FF (hex digits!) and then 1365 before counting upwards 1465, 1565, ...
Does anyone have any idea what could be causing this?

strat
Posts: 393
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Re: Donkey Kong bugged score and jump

Post by strat » Sun Mar 21, 2021 1:51 pm

Looking at the disasm of Donkey Kong from rhdn, it calculates Mario's jump like this
$42C - counter to initialize jump vars
$42D - lo y pos
$01 - hi y pos
$43D/$43E - lo/hi jump velocity (always $158)
$435/$436 - lo/hi gravity

Code: Select all

if $42C > 0:
    $435/$436 += $11 ; (it's coded as $10 but the carry is always set)
else:
    $435 = 8
    $42D = $F0
    
$42D/$01 -= $43D/$43E
$42D/$01 += $435/$436
$42C += 1
The only thing I can think of is that you forgot to add the carry flag to A in ADC. Patching out the bytes at $EFA8 (ADC #$00) to NOPs makes Mario's jumping behave exactly as described. The high byte of the gravity value is never increased so Mario keeps moving up until he hits the upper floor (and his y pos simply wraps around when jumping off the top floor). This is probably also why the timer/bonus counter is screwy.

Maybe you should try the test roms
https://wiki.nesdev.com/w/index.php/Emulator_tests

P.S. I wonder if Mario Bros. got by this because instead of using "ADC #$00" for 16-bit math it uses a "bcc/inc hi_byte" combo. Don't feel like checking now.

joshop
Posts: 2
Joined: Sun Mar 21, 2021 11:36 am

Re: Donkey Kong bugged score and jump

Post by joshop » Sun Mar 21, 2021 4:55 pm

It turned out that the solution was related to those instructions, but the actual issue was that the carry flag had gotten reset in between the two ADCs. The reason that this happened was that for some reason I decided to modify the carry flag when arithmetic was performed to compute addresses for absolute X and Y addressing modes, which one of the intermediate instructions used. Also, there was an issue in my implementation of SBC. Changing those two things solved the issue.

strat
Posts: 393
Joined: Mon Apr 07, 2008 6:08 pm
Location: Missouri

Re: Donkey Kong bugged score and jump

Post by strat » Sun Mar 21, 2021 4:57 pm

Cool

Post Reply