Testing the DAA instruction on the Master 512 / 80186 Co Pro

want to talk about MESS/model b/beebem/b-em/electrem/elkulator? do it here!
Post Reply
User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Thu Feb 23, 2017 1:16 pm

Hello all,

We're trying to get the behaviour of the DAA instruction correct on Pi Tube Direct.

Please could someone with a real 80186 Co Pro run the following test program and upload the results?

Code: Select all

   10 REM DAA TEST SUITE
   20 @%=&902
   30 DIM code% 256
   40 P%=code%
   50 [OPT 0
   60 DAA
   70 PUSHF
   80 POP DX
   90 RETF
  100 ]
  110 FOR cf=0 TO 1
  120   FOR af=0 TO 1
  130     FOR al=&00 TO &FF
  140       A%=al
  150       F%=cf+&10*af
  160       R%=USR(code%)
  170       alout=R% AND &FF
  180       cfout=(R% AND &10000) DIV &10000
  190       afout=(R% AND &100000) DIV &100000
  200       PRINT "cf=";cf;" af=";af;" al=",~al;" : ";
  210       PRINT "cfout=";cfout;" afout=";afout;" alout=",~alout
  220     NEXT
  230   NEXT
  240 NEXT
It also looks like there might be bugs in the Matchbox, and in B-Em, which this will help to clarify.

The way I got the results was a bit tortuous:

Code: Select all

A> cd BBCBASIC
A> BBCBASIC
> LOAD "DAA"
> *SPOOL DAARES
> RUN
> ... lots of output
> *SPOOL
> *BYE
A> PUTFILE DAARES :0.DAARES
Now this file is in the root directory of your ADFS hard disk, it's easier to work with.

At this point I switched to the 6502 Co Pro and from the * prompt:

Code: Select all

* ADFS
* INFO DAARES
* LOAD DAARES 800
* MMFS
* DIN 12
* SAVE DAARES 800 +BA80
And finally I used MMB Tools (on Linux) to extract the file.

A serial cable might have been easier!

Many thanks

Dave

User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Thu Feb 23, 2017 4:01 pm

And if anyone is feeling particularly generous with their time, then a second run with:

Code: Select all

   60 DAA
changed to:

Code: Select all

   60 DAS
would be very handy.

Dave

User avatar
jgharston
Posts: 3832
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by jgharston » Thu Feb 23, 2017 5:49 pm

The closest I can get to real hardware:
http://mdfs.net/temp/DAAbbdos.txt BBC BASIC for DOS running on RISC OS PCEm
http://mdfs.net/temp/DAAbb4w.txt BBC BASIC for Windows
The way I got the results was a bit tortuous:
Rather simpler for me.
Copy the program text. Paste into BB4W IDE. Save locally.
From Master: *MOVE -hostfs-:H.DAA/bbc -net-&.temp.DAA/bbc
From RISC OS: Drag -net-&.temp.DAA/bbc to -adfs-:A5000.DOSDEV.Testing.DAA/bbc
Boot PCem
CD testing
bbcbasic
*Spool daatest.txt
CH."DAA"
*Spool
Quit PCEm
Drag -adfs-:A5000.DOSDEV.Testing.daatest.txt to -net-&.temp.daatest
From Master: *MOVE -net-&.temp.daatest -hostfs-:H.daatest/txt
From Windows: Upload to website.
:)

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Thu Feb 23, 2017 7:06 pm

Jonathan,

The one from BBC Basic on Windows does not correctly extract the flags, because of differences in the return value of USR(). I have a slightly hacked version of the test that fixes this. I'm using this as my reference until someone posts the results from a real 186 Co Pro.

The one from RISC OS PCEm is interesting:
- DAA is I think correct, and matches what I see on an Intel Windows PC
- DAS is different in a few places to the values I get on an Intel Windows PC, but actually matches what I think is a buggy implementation in PiTubeDirect

Dave

User avatar
jgharston
Posts: 3832
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by jgharston » Thu Feb 23, 2017 11:01 pm

hoglet wrote:The one from BBC Basic on Windows does not correctly extract the flags, because of differences in the return value of USR(). I have a slightly hacked version of the test that fixes this. I'm using this as my reference until someone posts the results from a real 186 Co Pro.
Do'h. I forgot that. DOS BASIC returns DX:AX but Windows BASIC returns EAX. I should have checked for that before spooling the output, I could have popped the flags into the top of EAX to return.
hoglet wrote:The one from RISC OS PCEm is interesting:
- DAA is I think correct, and matches what I see on an Intel Windows PC
- DAS is different in a few places to the values I get on an Intel Windows PC, but actually matches what I think is a buggy implementation in PiTubeDirect
I've been looking through the PcEm code to see if I could track down the DAA and DAS code, but it's rather complicated and it uses a lot of self-modifying code. I think it also uses several depths of byte-code dispatch as I found some blocks of opcode instructions that were 32 bytes long (MOV PC,rx,ry,LSL #5), some that are 64 bytes long (MOV PC,rx,ry,LSL #6) and some that are 128 bytes long (MOV PC,rx,ry,LSL #7).

If somebody wants to look through it it's here.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Fri Feb 24, 2017 8:22 am

jgharston wrote: Do'h. I forgot that. DOS BASIC returns DX:AX but Windows BASIC returns EAX. I should have checked for that before spooling the output, I could have popped the flags into the top of EAX to return.
Yes, that's what I ended up doing:

Code: Select all

   10 REM DAA TEST SUITE FOR BBC BASIC ON WINDOWS
   20 @%=&902
   30 DIM code% 256
   40 P%=code%
   50 [OPT 0
   60 DAA
   70 PUSHF
   80 POP DX
   81 AND DX,&FF
   82 SHL AX, &8
   83 OR AX, DX
   90 RETF
  100 ]
  110 FOR cf=0 TO 1
  120   FOR af=0 TO 1
  130     FOR al=&00 TO &FF
  140       A%=al
  150       F%=cf+&10*af
  160       R%=USR(code%)
  170       alout=(R% AND &FF00) DIV &100
  180       cfout=(R% AND &1)
  190       afout=(R% AND &10) DIV &10
  200       PRINT "cf=";cf;" af=";af;" al=",~al;" : ";
  210       PRINT "cfout=";cfout;" afout=";afout;" alout=",~alout
  220     NEXT
  230   NEXT
  240 NEXT
jgharston wrote: I've been looking through the PcEm code to see if I could track down the DAA and DAS code, but it's rather complicated and it uses a lot of self-modifying code. I think it also uses several depths of byte-code dispatch as I found some blocks of opcode instructions that were 32 bytes long (MOV PC,rx,ry,LSL #5), some that are 64 bytes long (MOV PC,rx,ry,LSL #6) and some that are 128 bytes long (MOV PC,rx,ry,LSL #7).

If somebody wants to look through it it's here.
Ooh that, I might just do that.

I still thing the gold reference would be the results from a real 186 Co Pro if someone can help.

Dave

dp11
Posts: 979
Joined: Sun Aug 12, 2012 8:47 pm
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by dp11 » Fri Feb 24, 2017 11:47 am

I did some thinking about the logic behind the DAA instruction never clearing the carry flag.

Assume you when to add to 16bit BCD numbers together

Clear carry flag
ADD two LSB together
- > may set carry flag
DAA
ADC two MSB together ;// here we need the carry flag from the previous ADD so it can never be cleared by DAA
DAA

PhilYoung
Posts: 203
Joined: Sun Jun 12, 2011 4:55 pm
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by PhilYoung » Fri Feb 24, 2017 4:05 pm

hoglet wrote: I still thing the gold reference would be the results from a real 186 Co Pro if someone can help.

Dave
OK, here are my results from a real 186 Co Pro (after a bit of an epic session with the DataCentre)
results_real_80186.zip
(9.85 KiB) Downloaded 25 times
If you need any more let me know, I think I'm all set up for it at the moment,

Cheers,

Phil Young

User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Fri Feb 24, 2017 5:06 pm

Thanks Phil.

Those results are very interesting, as they actually differ in some cases from the behaviour with current Intel processors.

We'll probably continue the analysis in the github issue:
https://github.com/hoglet67/PiTubeDirect/issues/42

Many thanks for taking the time to do this.

Is there any chance you could post a close-up picture of the 186 in your Co Pro?

Dave

PhilYoung
Posts: 203
Joined: Sun Jun 12, 2011 4:55 pm
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by PhilYoung » Fri Feb 24, 2017 5:45 pm

hoglet wrote:Thanks Phil.

Those results are very interesting, as they actually differ in some cases from the behaviour with current Intel processors.

We'll probably continue the analysis in the github issue:
https://github.com/hoglet67/PiTubeDirect/issues/42

Many thanks for taking the time to do this.

Is there any chance you could post a close-up picture of the 186 in your Co Pro?

Dave
Sure, here we go:
my_80186.jpg
Let me know if you would like any further tests run (or rerun)

Cheers,

Phil Young

User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Fri Feb 24, 2017 5:54 pm

Thanks for the photo.

Interesting that it's a AMD processor rather than an Intel one.
PhilYoung wrote: Let me know if you would like any further tests run (or rerun)
The tests you ran were exhaustive in that they test every possible combination of inputs (1024 combinations). So we shouldn't need any more for DAA and DAS.

Thanks again,

Dave

PhilYoung
Posts: 203
Joined: Sun Jun 12, 2011 4:55 pm
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by PhilYoung » Fri Feb 24, 2017 6:13 pm

hoglet wrote:Thanks for the photo.

Interesting that it's a AMD processor rather than an Intel one.
PhilYoung wrote: Let me know if you would like any further tests run (or rerun)
The tests you ran were exhaustive in that they test every possible combination of inputs (1024 combinations). So we shouldn't need any more for DAA and DAS.

Thanks again,

Dave
I didn't notice that it was an AMD part. I do have another faulty 186 copro, if it's a different 80186 I'll try swapping them and re-run the tests. If I can find the time and the courage that is,

Cheers,

Phil

dp11
Posts: 979
Joined: Sun Aug 12, 2012 8:47 pm
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by dp11 » Fri Feb 24, 2017 6:16 pm

Do we need to double check AAA and AAS ?

User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Fri Feb 24, 2017 6:19 pm

PhilYoung wrote: I didn't notice that it was an AMD part. I do have another faulty 186 copro, if it's a different 80186 I'll try swapping them and re-run the tests. If I can find the time and the courage that is,
I expect they are all AMD parts.

I also think they may well have used the same masks, as they were a bona-fida Intel second source (IBM insisted on this).

Dave

User avatar
hoglet
Posts: 8915
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Testing the DAA instruction on the Master 512 / 80186 Co Pro

Post by hoglet » Fri Feb 24, 2017 6:21 pm

dp11 wrote:Do we need to double check AAA and AAS ?
That's actually not a bad idea, but it's more complicated to test, because it uses AH as well. We would need to tweak the test program.

Edit: the logic is a bit simpler, so there is less to go wrong:
https://github.com/hoglet67/PiTubeDirec ... 86.c#L1901
https://github.com/hoglet67/PiTubeDirec ... 86.c#L1964

Dave

Post Reply