Undefined behavior for ABCD and SBCD

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

r57shell
Very interested
Posts: 478
Joined: Sun Dec 23, 2012 1:30 pm
Location: Russia
Contact:

Re: Undefined behavior for ABCD and SBCD

Post by r57shell » Thu Apr 27, 2017 2:32 pm

HardWareMan wrote:I do not understand, hasn't anyone looked at the CPU die shots yet?
Basic die shots. Then, Quietust has made a great contribution by isolating the metal traces. Olivier Galibert was able to make use of this layer image, with a few corrections, to produce a full transistor-level schematic of the 68000. In result, here the interactive map. You can look at ALU under the magnifying glass. I don't see any problem in getting true behavior without guessing.
After hours of pain, was able to compile https://github.com/galibert/dietools.git using Visual Studio 2010
Not all...
logx was failed to compile because of C++11 syntax.
mscheme probably bugged compilation because I had to implement what is not defined in LuaJIT.
sview a bit modified to make pins text work + vcc/gnd voltage change. In repo vcc & gnd voltage forced to 0, otherwise you'll get tons of errors "Unhandled equation system." :lol:

So. For anyone who wanna play with it:
1) Download scheme: https://og.kervella.org/m68k/schem.txt
2) Download deietools (my build): http://www.mediafire.com/file/2p5giq3fs ... ietools.7z
3) Unpack in some dir
4) Open cmd.exe there, run: sview "path_to_schem.txt". Or simply drag schem.txt and drop over sview.exe
5) ?!?!?
6) Have Fun!
Image

notaz
Very interested
Posts: 193
Joined: Mon Feb 04, 2008 11:58 pm
Location: Lithuania

Re: Undefined behavior for ABCD and SBCD

Post by notaz » Wed Sep 20, 2017 7:48 pm

Small update to flamewing's test to trigger a bug in Genesis-Plus-GX at least:
https://github.com/flamewing/68k-bcd-ve ... e3afd720bf
http://notaz.gp2x.de/md/rel/bcd-verifier-u1.zip

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Re: Undefined behavior for ABCD and SBCD

Post by Eke » Sun Sep 24, 2017 10:41 pm

notaz wrote:
Wed Sep 20, 2017 7:48 pm
Small update to flamewing's test to trigger a bug in Genesis-Plus-GX at least:
https://github.com/flamewing/68k-bcd-ve ... e3afd720bf
http://notaz.gp2x.de/md/rel/bcd-verifier-u1.zip
Well, this was indeed a very stupid bug in Musashi: upper bits of NBCD source operand were not masked when it comes from a 68k register, which would lead to incorrect calculation when those bits are not cleared before calling the instruction. Thanks for the notice.

mikro
Newbie
Posts: 2
Joined: Mon Jan 01, 2018 9:02 am

Re: Undefined behavior for ABCD and SBCD

Post by mikro » Tue Jan 09, 2018 12:52 am

Hi there,

a newcomer and non-Sega guy here. :) I found this super interesting thread, thanks for all the published code. It will help me a lot. However:
flamewing wrote:
Sun Mar 19, 2017 4:02 pm
So, I decided to conduct my own investigation into this issue, and did some HW tests, patent investigation, and number crunching; and after doing all that, I discover this thread, in which I confirm my findings that every single emulator does it wrong.
this is true only for Sega emulators I guess. UAE-based emulators (incl. Atari ones like Hatari or Aranym) do that nearly 100% correct -- only a few cases of NBCD's V flag are wrong.

flamewing
Very interested
Posts: 56
Joined: Tue Sep 23, 2014 2:39 pm
Location: France

Re: Undefined behavior for ABCD and SBCD

Post by flamewing » Thu Jan 11, 2018 8:27 am

mikro wrote:
Tue Jan 09, 2018 12:52 am
this is true only for Sega emulators I guess. UAE-based emulators (incl. Atari ones like Hatari or Aranym) do that nearly 100% correct -- only a few cases of NBCD's V flag are wrong.
Thanks for confirming that even the non-Sega emulators also got the BCD instructions wrong :-)

(even if only slightly)

By the way, BlastEm (and I think GPGX) now emulate these instructions correctly.

And welcome to the forums!

mikro
Newbie
Posts: 2
Joined: Mon Jan 01, 2018 9:02 am

Re: Undefined behavior for ABCD and SBCD

Post by mikro » Thu Jan 11, 2018 9:12 am

flamewing wrote:
Thu Jan 11, 2018 8:27 am
Thanks for confirming that even the non-Sega emulators also got the BCD instructions wrong :-)

(even if only slightly)

By the way, BlastEm (and I think GPGX) now emulate these instructions correctly.
Not anymore. :) Thanks to your code I was able to spot the slight error in WinUAE, then the change got merged into Hatari virtually straight away.

By the way, the reason why I started with those experiments is that I'm trying to find out how much feasible is to use ABCD/SBCD to 6502's ADC/SBC instructions emulation in the decimal mode (I mean mainly the carry flag and result as the other flags are handled differently).

Nemesis
Very interested
Posts: 791
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Re: Undefined behavior for ABCD and SBCD

Post by Nemesis » Thu Aug 30, 2018 1:59 am

Just wanted to bump this to say thanks for all the research and effort here guys, and especially flamewing for your example code and test rom. I've made the necessary corrections to Exodus, and these changes will be included in the next release.

Post Reply