It is currently Sun Jul 21, 2019 1:57 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Thu Jan 17, 2019 7:46 am 
Offline
User avatar

Joined: Mon Jul 16, 2018 2:57 pm
Posts: 38
Hi All,

So, during the title screen demo, my Donkey Kong bonus score starts at 5000, but then goes to FF00, then F700, then 5800 and keeps going up. It should of course instead be going down to 4900, 4800, etc.

I think this is probably caused by a CPU bug, but I don't see an obvious bug in the tests. I remember there being an annotated version of the Donkey Kong source code somewhere? I was hoping I could look at that to see what instructions set the Bonus score. I thought it was ADC or SBC probably, but I think my implementations are okay.

Thanks in advance.


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 6:06 am 
Offline

Joined: Thu Sep 15, 2005 9:23 am
Posts: 1236
Location: Berlin, Germany
Sounds like a CPU bug. Do other games have the same problem?

Please post your CPU source code for us to review.


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 6:16 am 
Offline
User avatar

Joined: Mon Jul 16, 2018 2:57 pm
Posts: 38
Turns out it was a bug in ADC/SBC. Specifically, overflow was not set correctly. Thanks.


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 12:43 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 4156
Location: A world gone mad
Subject of these two opcodes continues to come up over and over and over. I still maintain they're (specifically the overflow flag and two's complement) the #1 cause of frustration and bugs for people trying to emulate 65xxx series CPUs.

Anyway, reference material -- don't overlook the last line in my post: viewtopic.php?p=224802#p224802


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 1:49 pm 
Offline
User avatar

Joined: Mon Jul 16, 2018 2:57 pm
Posts: 38
I agree it's the most confusing thing to implement CPU wise. I had no problem with the carry (which the linked to threads go into in some detail). I had a lot more trouble with overflow, which the linked posts go into a lot less detail about. As mentioned in the linked threads, nestest will pass, but Blargg's tests will not with an incorrect SDC/ADC in some situations. I'm passing the tests now, but it took a while, and I'm still not quite sure I understand why my original implementation didn't work.


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 2:23 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 4156
Location: A world gone mad
You're right. But the subject has still been discussed to death on the forum. :-) Here's something more relevant for you (entire thread from this point on is useful, including some code): viewtopic.php?p=60520#p60520


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 9:13 pm 
Offline
User avatar

Joined: Wed Apr 18, 2018 1:09 am
Posts: 38
Location: Australia
If you still need the Donkey Kong annotated disassembly then you can find it at the below link. I used it a lot when trying to work out the bugs in my PPU.

https://www.romhacking.net/documents/540/


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 9:16 pm 
Offline
User avatar

Joined: Wed Apr 18, 2018 1:09 am
Posts: 38
Location: Australia
I had so much trouble with SDC that I ended up copying a line of code from someone else's emulator to make it work. Not my proudest moment, I have attributed the line in my source code, but still.


Top
 Profile  
 
PostPosted: Fri Jan 18, 2019 9:41 pm 
Offline
User avatar

Joined: Mon Jul 16, 2018 2:57 pm
Posts: 38
iOSBrett wrote:
I had so much trouble with SDC that I ended up copying a line of code from someone else's emulator to make it work. Not my proudest moment, I have attributed the line in my source code, but still.


Yeah same I ended up looking up the line for the overflow in mynes and attributing it in my README. Hey, by the way you inspired me by your posts to keep going and now I have sprites working in Donkey Kong—they're just the wrong colors :).


Top
 Profile  
 
PostPosted: Sat Jan 19, 2019 11:52 pm 
Offline

Joined: Sat Jun 01, 2013 11:55 am
Posts: 36
Location: Maine, U.S.A.
It's easier to implement ADC/SBC from scratch once you know that overflow or carry only occur when the sign bit changes, and that SBC is really an inverted add (a+~b+c). In C code with larger int sizes, it's easy to just check if the add result is larger than 0xFF for carry, and only otherwise can overflow occur.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group