68000 instruction test suite QL

Discussion and advice about emulating the QL on other machines.
User avatar
janbredenbeek
Super Gold Card
Posts: 629
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: 68000 instruction test suite QL

Post by janbredenbeek »

mk79 wrote:I haven't though about this stuff for 10 years, so I'm a bit rusty. But as far as I can see that is simply a bug because the TRAP shares code with other exceptions where the T bit must be cleared. Amazing that nobody including myself has ever noticed it ;)
Just tested it with a very old version (v3.12, it is dated March 2004) and tracing TRAPs worked. On v4.05 and higher it doesn't. So it must have been introduced somewhere in between :)
At first I thought this was a security feature of the 68020 (like the privileged MOVE from SR), but as I said I don't have the real hardware around to test this...

Jan


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: 68000 instruction test suite QL

Post by XorA »

mk79 wrote:
XorA wrote:It seems I could use your testsuite, as the following code from uqlx I guess means its nbcd instruction does not work.
I finally uploaded one version to https://www.kilgus.net/soft/m68k_tester_gz.zip. You probably only need to adapt the dev$ variable in the boot file. It can run very long on slower machines, days even, so it makes a screenshot after every instruction tested. Not so much a problem for an emulator like yours I guess.

Cheers, Marcel
Thanks Marcel, its currently crunching its way through on my Apple M1 (fastest CPU I have).


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: 68000 instruction test suite QL

Post by XorA »

And the result is it looks like all the BCD instructions are broken.

Ill need to double check all the results to see if anything else is, but mostly they seem ok.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: 68000 instruction test suite QL

Post by mk79 »

If you are very ambitious you can use the "all_flags_exe", it will also check the flags marked as "undefined" :-D

IIRC I used this SBCD code from the UAE emulator as a reference in later QPCs as it also preserved the 68k behaviour when the operands are not BCD values:

Code: Select all

uae_u16 newv_lo = (dst & 0x0F) - (src & 0x0F) - (GET_XFLG ? 1 : 0);
uae_u16 newv_hi = (dst & 0xF0) - (src & 0xF0);
uae_u16 newv;
int bcd = 0;

newv = newv_hi + newv_lo;

if (newv_lo & 0xF0) {
    newv -= 6; bcd = 6;
}
if ((((dst & 0xFF) - (src & 0xFF) - (GET_XFLG ? 1 : 0)) & 0x100) > 0xFF) {
    newv -= 0x60;
}
SET_CFLG ((((dst & 0xFF) - (src & 0xFF) - bcd - (GET_XFLG ? 1 : 0)) & 0x300) > 0xFF);


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: 68000 instruction test suite QL

Post by XorA »

Thanks for the hint about UAE, thats a lot more readable than Musashi I was trying to crib from.

Code: Select all

	w8 d, r;
	w8 d2, r2;
	uw16 nbcd_lo, nbcd_hi, nbcd_res;
	int nbcd_carry;

	d = ModifyAtEA_b((code >> 3) & 7, code & 7);
	nbcd_lo = - (d & 0xF) - (xflag ? 1 : 0);
        nbcd_hi = - (d & 0xF0);

        if (nbcd_lo > 9) { nbcd_lo -= 6; }
        nbcd_res = nbcd_hi + nbcd_lo;
	nbcd_carry = (nbcd_res & 0x1F0) > 0x90;
        if (nbcd_carry) nbcd_res -= 0x60;
        xflag = carry = nbcd_carry ? 1 : 0;
	zero = (zero ? 1 : 0) & (nbcd_res ? 0 : 1);

	r = nbcd_res & 0xFF;
	negative = r < 0 ? 1 : 0;
has got me a lot nearer to success
Screenshot 2021-04-13 at 23.57.06.png
Only 24 tests to go.


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: 68000 instruction test suite QL

Post by XorA »

And reading my own post noticed the mistake (using the intermediate result for zero not the final)

Code: Select all

	w8 d, r;
	uw16 nbcd_lo, nbcd_hi, nbcd_res;
	int nbcd_carry;

	d = ModifyAtEA_b((code >> 3) & 7, code & 7);
	nbcd_lo = -(d & 0xF) - (xflag ? 1 : 0);
	nbcd_hi = -(d & 0xF0);

	if (nbcd_lo > 9) {
		nbcd_lo -= 6;
	}
	nbcd_res = nbcd_hi + nbcd_lo;
	nbcd_carry = (nbcd_res & 0x1F0) > 0x90;
	if (nbcd_carry)
		nbcd_res -= 0x60;

	r = nbcd_res & 0xFF;

	/* Set the flags */
	zero = (zero ? 1 : 0) & (r ? 0 : 1);
	negative = r < 0 ? 1 : 0;
	xflag = carry = nbcd_carry ? 1 : 0;

	RewriteEA_b(r);
and all tests pass.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: 68000 instruction test suite QL

Post by mk79 »

Congrats :-)


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: 68000 instruction test suite QL

Post by XorA »

And thanks to the guidance of Marcel the master.
Screenshot 2021-04-14 at 22.02.35.png


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: 68000 instruction test suite QL

Post by mk79 »

Master of my veeeery small domain :D Cool! How long do you estimate does the whole test take on your M1?


User avatar
XorA
Site Admin
Posts: 1358
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: 68000 instruction test suite QL

Post by XorA »

mk79 wrote:Master of my veeeery small domain :D Cool! How long do you estimate does the whole test take on your M1?
I’ll have to re-run it as obviously the failing tests take much longer than passing ones with all the printing.

But even then it was only 3-4 hours or so.


Post Reply