/******************************************************************************
*									      *
*  32x32 MULTIPLY (UNSIGNED)						      *
*  11/14/06 (dkc)							      *
*									      *
*  Note: The C64 assembly language does a signed 32x32 multiply.	      *
*									      *
******************************************************************************/
unsigned int carry(unsigned int a, unsigned int b, unsigned int sum);
void midprod(unsigned int a0, unsigned int m0, unsigned int *product) {
unsigned int a1,m1,temp;
unsigned int p0,p1,p2,p3;
unsigned int s1,s2;
unsigned int c2;

a1=a0&0xffff;
a0=a0>>16;
m1=m0&0xffff;
m0=m0>>16;
p0=a0*m0;
p1=a0*m1;
p2=a1*m0;
p3=a1*m1;

s2=p3+(p2<<16);
c2=carry(p3,(p2<<16),s2);
temp=s2+(p1<<16);
c2+=carry(s2,(p1<<16),temp);
s2=temp;

s1=p0+(p2>>16);
s1=s1+(p1>>16);
s1=s1+c2;

*product=s1;
*(product+1)=s2;
return;
}