Page 2 of 3

Re: 68000 instruction test suite QL

Posted: Tue Apr 13, 2021 11:13 am
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

Re: 68000 instruction test suite QL

Posted: Tue Apr 13, 2021 12:18 pm
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).

Re: 68000 instruction test suite QL

Posted: Tue Apr 13, 2021 4:31 pm
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.

Re: 68000 instruction test suite QL

Posted: Tue Apr 13, 2021 9:52 pm
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);

Re: 68000 instruction test suite QL

Posted: Tue Apr 13, 2021 11:59 pm
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.

Re: 68000 instruction test suite QL

Posted: Wed Apr 14, 2021 12:04 am
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.

Re: 68000 instruction test suite QL

Posted: Wed Apr 14, 2021 9:44 am
by mk79
Congrats :-)

Re: 68000 instruction test suite QL

Posted: Wed Apr 14, 2021 10:05 pm
by XorA
And thanks to the guidance of Marcel the master.
Screenshot 2021-04-14 at 22.02.35.png

Re: 68000 instruction test suite QL

Posted: Thu Apr 15, 2021 12:21 am
by mk79
Master of my veeeery small domain :D Cool! How long do you estimate does the whole test take on your M1?

Re: 68000 instruction test suite QL

Posted: Thu Apr 15, 2021 10:13 am
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.