[Coco] Basic09 6309 version

Walter Zambotti zambotti at iinet.net.au
Fri May 26 03:14:55 EDT 2017


Further my last. DIVQ div by zero uses 21 less and not 13 less (which is for DIVD)

Anyway with that here are the two hopefully corrected instructions including corrected
cycle times and div by zero trapping.


		case DIVQ_E: //11BE Phase 5 6309 CHECK
			postword=MemRead16(IMMADDRESS(PC_REG));
			if(postword)
			{
				temp32=Q_REG;
				W_REG=temp32/(postword);
				D_REG=temp32%(postword);
				cc[N] = NTEST16(W_REG);
				cc[Z] = ZTEST(W_REG);
				cc[C] = W_REG&1;
				cc[V] =1;
				//NOT DONE
				PC_REG+=2;
				CycleCounter+=InsCycles[md[NATIVE6309]][M3726];
			}
			else
			{
				CycleCounter+=InsCycles[md[NATIVE6309]][M3726]-21;
				DivByZero();
			}
			break;

		case DIVQ_X: //11AE Phase 5 6309 CHECK
			postword=MemRead16(INDADDRESS(PC_REG++));
			if(postword)
			{
				temp32=Q_REG;
				W_REG=temp32/(postword);
				D_REG=temp32%(postword);
				cc[N] = NTEST16(W_REG);
				cc[Z] = ZTEST(W_REG);
				cc[C] = W_REG&1;
				cc[V] =1;
				//NOT DONE
				CycleCounter+=InsCycles[md[NATIVE6309]][M3635];
			{
			else
			{
				CycleCounter+=InsCycles[md[NATIVE6309]][M3635]-21;
				DivByZero();
			}
			break;


-----Original Message-----
From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of Walter Zambotti
Sent: Friday, 26 May 2017 3:03 PM
To: 'CoCoList for Color Computer Enthusiasts' <coco at maltedmedia.com>
Subject: Re: [Coco] Basic09 6309 version

I have had a look at hd6309.c and there are a number of 'concerns' relating to the 6309 emulation.

If you look at the DIVD_M/E/D instructions for instance the:

1. CycleCounter appears to be erroneously incremented twice in the E & D variants:
2. The divide by zero cycle counter appears to be just plain wrong 25-13 should be 12 for instance.

There is an implementation of DIVQ_E how ever it doesn't implement the correct cycle count for division by zero nor does it raise the div by zero interrupt.  I have added this to the X variant suggestion.

But given that I have provided an X variant suggestion further below.

Also the 6309 instruction set manual says this about the cycle counter for most of the DIV instructions:

If a range overflow occurs, DIV? use 13 fewer cycles than what is shown in the table.

Since determining an overflow still requires the full results to be produced there should no difference to the cycle counter.  I suggest the manual should have said if a div by zero occurs then ...

It seems that incorrect cycle counters probably don't stop the emulator from working fully but may affect timing dependant code.

		case DIVD_M: //118D 6309 NITRO
			*spostbyte=(signed char)MemRead8(PC_REG++);
			if (*spostbyte)
			{	
				*spostword=D_REG;
				stemp16= (signed short)D_REG / *spostbyte;
				A_REG = (signed short)D_REG % *spostbyte;
				B_REG=(unsigned char)stemp16;

				cc[Z] = ZTEST(B_REG);
				cc[N] = NTEST16(D_REG);
				cc[C] = B_REG & 1;
				cc[V] =(stemp16 >127) | (stemp16 <-128);

				if ( (stemp16 > 255) | (stemp16 < -256) ) //Abort
				{
					D_REG=abs (*spostword);
					cc[N] = NTEST16(D_REG);
					cc[Z] = ZTEST(D_REG);
				}
				CycleCounter+=25;  
			}
			else
			{
				CycleCounter+=17;
				DivbyZero();				
			}
		break;

		case DIVD_E: //11BD 6309 02292008 Untested
			*spostbyte=(signed char)MemRead8(IMMADDRESS(PC_REG));
			if (*spostbyte)
			{	
				*spostword=D_REG;
				stemp16= (signed short)D_REG / *spostbyte;
				A_REG = (signed short)D_REG % *spostbyte;
				B_REG=(unsigned char)stemp16;

				cc[Z] = ZTEST(B_REG);
				cc[N] = NTEST16(D_REG);
				cc[C] = B_REG & 1;
				cc[V] =(stemp16 >127) | (stemp16 <-128);

				if ( (stemp16 > 255) | (stemp16 < -256) ) //Abort
				{
					D_REG=abs (*spostword);
					cc[N] = NTEST16(D_REG);
					cc[Z] = ZTEST(D_REG);
				}
				CycleCounter+=25; // So either this
			}
			else
			{
				CycleCounter+=17; //and this
				DivbyZero();				
			}
			CycleCounter+=InsCycles[md[NATIVE6309]][M2827];//or this but not both
		break;

		case DIVD_D: //119D 6309 02292008
			*spostbyte=(signed char)MemRead8(DPADDRESS(PC_REG++));
			if (*spostbyte)
			{	
				*spostword=D_REG;
				stemp16= (signed short)D_REG / *spostbyte;
				A_REG = (signed short)D_REG % *spostbyte;
				B_REG=(unsigned char)stemp16;

				cc[Z] = ZTEST(B_REG);
				cc[N] = NTEST16(D_REG);
				cc[C] = B_REG & 1;
				cc[V] =(stemp16 >127) | (stemp16 <-128);

				if ( (stemp16 > 255) | (stemp16 < -256) ) //Abort
				{
					D_REG=abs (*spostword);
					cc[N] = NTEST16(D_REG);
					cc[Z] = ZTEST(D_REG);
				}
				CycleCounter+=27; // Increment here
			}
			else
			{
				CycleCounter+=19; // and here 27 -13 should be 14
				DivbyZero();				
			}
			CycleCounter+=InsCycles[md[NATIVE6309]][M2726]; // but NOT also here
		break;

		case DIVQ_E: //11BE Phase 5 6309 CHECK
			postword=MemRead16(IMMADDRESS(PC_REG));
			temp32=Q_REG;
			W_REG=temp32/(postword);
			D_REG=temp32%(postword);
			cc[N] = NTEST16(W_REG);
			cc[Z] = ZTEST(W_REG);
			cc[C] = W_REG&1;
			cc[V] =1;
			//NOT DONE
			PC_REG+=2;
			CycleCounter+=InsCycles[md[NATIVE6309]][M3726];
		break;

Suggested DIVQ_X instruction (based on DIVQ_E)

		case DIVQ_X: //11AE Phase 5 6309 CHECK
			postword=MemRead16(INDADDRESS(PC_REG++));
			if(postword)
			{
				temp32=Q_REG;
				W_REG=temp32/(postword);
				D_REG=temp32%(postword);
				cc[N] = NTEST16(W_REG);
				cc[Z] = ZTEST(W_REG);
				cc[C] = W_REG&1;
				cc[V] =1;
				//NOT DONE
				CycleCounter+=InsCycles[md[NATIVE6309]][M3635];
			{
			else
			{
				CycleCounter+=InsCycles[md[NATIVE6309]][M3635]-13;
				DivByZero();
			}
			break;



-----Original Message-----
From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of David Ladd
Sent: Friday, 26 May 2017 1:19 PM
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Subject: Re: [Coco] Basic09 6309 version

James,

Thank you for pointing that out.

Actually I went through reviewing the hd6309.c file and found several 6309 OpCodes that aren't implemented yet.

So we need to stay vigilant on making sure to test programs on real CoCo's with real 6309's first before blaming the code/programs.  As we are finding out that VCC has some CPU instructions related to the 6309 that aren't supported yet.

Walter, good find and bringing this to the list.  I am personally surprised that we haven't had this happen more often.

More stuff to add to the list of things to work on.

+-----------------------------------------------------------------------+
| David Ladd a.k.a. PacoOtaktay a.k.a. Drencor                          |
| YouTube: http://www.youtube.com/user/PacoOtaktay                      |
| YouTube Gaming Live: https://gaming.youtube.com/user/PacoOtaktay/live |
| Websites: http://dwladd.com     &     http://www.theterrorzone.com    |
| G+:  https://plus.google.com/113262444659438038657                    |
| G+:  https://plus.google.com/+DavidLaddPacoOtaktay                    |
|                                                                       |
| Do you have your CoCo 3 yet?                                          |
+-----------------------------------------------------------------------+


On Thu, May 25, 2017 at 4:13 PM, James Jones <jejones3141 at gmail.com> wrote:

> If https://github.com/VCCE/VCC is any indication, a number of the 
> DIVQ_* cases in hd6309.c sit unimplemented--or more accurately, it 
> looks like only DIVQ_E is implemented. The rest mostly emit a log 
> message and all count the number of cycles the instruction takes.
>
> On Thu, May 25, 2017 at 3:22 PM, Wayne Campbell <asa.rand at gmail.com>
> wrote:
>
> > I was just covering the bases. In the julian day thread it was 
> > suggested
> I
> > try running the 6809 version in VCC and see what happens, so I did.
> >
> > On Thu, May 25, 2017 at 12:07 PM, Bill Pierce via Coco < 
> > coco at maltedmedia.com
> > > wrote:
> >
> > > The 6809 version of basic09 would not have a "divq" instruction as
> that's
> > > exclusive to the 6309 processor, so it's only logical that if the 
> > > divq function of VCC is bugged, the 6809 software should run fine. 
> > > This only seems to be happening when that instruction is encountered.
> > >
> > >
> > >
> > >
> > >
> > > Bill Pierce
> > > "Charlie stole the handle, and the train it won't stop going, no 
> > > way to slow down!" - Ian Anderson - Jethro Tull
> > >
> > > My Music from the Tandy/Radio Shack Color Computer 2 & 3 
> > > https://sites.google.com/site/dabarnstudio/
> > > Co-Contributor, Co-Editor for CocoPedia 
> > > http://www.cocopedia.com/wiki/index.php/Main_Page
> > >
> > > E-Mail: ooogalapasooo at aol.com
> > >
> > >
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: Wayne Campbell <asa.rand at gmail.com>
> > > To: CoCoList <coco at maltedmedia.com>
> > > Sent: Thu, May 25, 2017 1:54 pm
> > > Subject: Re: [Coco] Basic09 6309 version
> > >
> > > Oh, and I was still emulating the 6309 processor.On May 25, 2017 
> > > 10:53
> > AM,
> > > "Wayne Campbell" <asa.rand at gmail.com> wrote:> I put the 6809 
> > > version
> of
> > > B09 in the CMDS directory and ran a copy of the> JD procedure with 
> > > no
> > > FLOAT() functions. It ran without errors and no> Hitting DIVQ_X 
> > > error
> in
> > > VCC.>>> On May 25, 2017 2:17 AM, "Bill Pierce via Coco" < 
> > > coco at maltedmedia.com>> wrote:>>> I did a search through the 
> > > nitros9 sources and only found 6 references to>> "divq". 2 were in 
> > > asm and
> disasm
> > > which were only references for the>> programs asm/disasm 
> > > functionality
> > and
> > > no actual running code, 2 were in 2>> of Boisy's test routines in 
> > > one
> of
> > > his folders (not used for anything), and>> the other 2 were in 
> > > basic09
> > and
> > > runb. So they are the only 2 nitros9>> modules that would rare 
> > > their
> ugly
> > > heads on this.>>>> I do remember some years ago when Joseph was
> > developing
> > > VCC that there>> was some mention of something being missing in 
> > > the
> 6309
> > > core. I've searched>> but couldn't find where I saw it (it was 
> > > loooong ago). I've even mentioned>> it in the issues on the VCC 
> > > repo issues
> page.
> > > We may have found what it was.>>>>>>>>>>>> Bill Pierce>> "Charlie 
> > > stole
> > the
> > > handle, and the train it won't stop going, no way to>> slow down!" 
> > > -
> Ian
> > > Anderson - Jethro Tull>>>> My Music from the Tandy/Radio Shack 
> > > Color Computer 2 & 3>> 
> > > https://sites.google.com/site/dabarnstudio/>>
> > > Co-Contributor, Co-Editor for CocoPedia>>
> http://www.cocopedia.com/wiki/
> > > index.php/Main_Page>>>> E-Mail: ooogalapasooo at aol.com>>>>>>>>>>>> 
> > > -----Original Message----->> From: Walter Zambotti <
> > zambotti at iinet.net.au>>>
> > > To: 'CoCoList for Color Computer Enthusiasts' 
> > > <coco at maltedmedia.com>>>
> > > Sent: Thu, May 25, 2017 3:31 am>> Subject: Re: [Coco] Basic09 6309
> > > version>>>> >This could explain the Hitting DIVQ_X error that VCC 
> > > version>>>> >keeps
> > > complaining>> about.This error could be isolated to either VCC or
> > > BASIC09_6309.We can>> eliminate which one is the problem by 
> > > running the
> > > BASIC09_6309 version on a>> real 6309 coco and not in VCC.  If the 
> > > same problem persists then the>> problem in in BASIC09_6309.  If 
> > > it does not persist then the problem is in>> VCC.I don't have a 
> > > 6309 in my CoCo so
> I
> > > can't volunteer to help.Any takers>> out there?Walter-----Original
> > > Message-----From: Coco [mailto:>> coco-bounces at maltedmedia.com] On
> > Behalf
> > > Of Wayne CampbellSent: Thursday,>> 25 May 2017 12:11 PMTo: 
> > > CoCoList <
> > > coco at maltedmedia.com>Subject: Re:>> [Coco] Basic09 6309 
> > > versionThis
> > could
> > > explain the Hitting DIVQ_X error that>> VCC keeps complaining 
> > > about.On
> > May
> > > 24, 2017 8:52 PM, "William Astle" <>> lost at l-w.ca> wrote:My guess 
> > > is
> the
> > > VCC isn't implementing DIVQ>> correctly, probably by not providing 
> > > the remainder unless regular integer>> division is also 
> > > failing.--Coco
> > mailing
> > > listCoco at maltedmedia.comhttps://>> pairlist5.pair.net/mailman/
> > > listinfo/coco-- Coco mailing>> listCoco at maltedmedia.comhttps:// 
> > > pairlist5.pair.net/mailman/listinfo/coco>>>> -->> Coco mailing 
> > > list>> Coco at maltedmedia.com>> https://pairlist5.pair.net/
> mailman/listinfo/coco
> > >>>--
> > > Coco mailing listCoco at maltedmedia.comhttps://
> pairlist5.pair.net/mailman/
> > > listinfo/coco
> > >
> > > --
> > > Coco mailing list
> > > Coco at maltedmedia.com
> > > https://pairlist5.pair.net/mailman/listinfo/coco
> > >
> >
> >
> >
> > --
> > Wayne
> >
> > The Structure of I-Code
> > http://www.cocopedia.com/wiki/index.php/The_Structure_of_I-Code
> >
> > decode
> > http://cococoding.com/wayne/
> >
> > --
> > Coco mailing list
> > Coco at maltedmedia.com
> > https://pairlist5.pair.net/mailman/listinfo/coco
> >
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>

--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco


-- 
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco



More information about the Coco mailing list