#include <stdio.h>
#include "kdefs.h"
#include "ktable.h"
#define SKIP 0xa1 + 0xff - 0xfe
#ifdef __STDC__
KCHAR packtocomp(KCHAR comb2)
#else
KCHAR packtocomp(comb2)
KCHAR comb2;
#endif
{
KCHAR comp2 ;
short Ci_val;
short V_val ;
short Cf_val;
short mask ;
int disp, k;
long Cfbit ;
#if defined(i386) || defined(__ppc)
comb2 = ((comb2 & 0xff00) >> 8) | ((comb2 & 0x00ff) << 8);
#endif
Ci_val = INITIAL_SOUND((unsigned int)comb2) - 0x0a;
V_val = MIDDLE_SOUND((unsigned int)comb2) - (MIDDLE_SOUND((unsigned int)comb2)/4 + 2);
Cf_val = FINAL_SOUND(comb2);
if ( V_val < 0 )
#if defined(i386) || defined(__ppc)
{
comp2 = 0xa4a0 + Y19_32[INITIAL_SOUND((unsigned int)comb2)
- 0x09];
return(((comp2 & 0x00ff) << 8)|((comp2 & 0xff00) >> 8));
}
#else
return(0xa4a0 + Y19_32[INITIAL_SOUND((unsigned int)comb2)
- 0x09]);
#endif
if (Ci_val < 0 )
{
if (Cf_val <= 1)
#if defined(i386) || defined(__ppc)
{
comp2 = 0xa4bf + MIDDLE_SOUND((unsigned int)comb2)
- MIDDLE_SOUND((unsigned int)comb2)/4 - 2;
return(((comp2 & 0x00ff) << 8)|((comp2 & 0xff00) >> 8));
}
#else
return(0xa4bf + MIDDLE_SOUND((unsigned int)comb2)
- MIDDLE_SOUND((unsigned int)comb2)/4 - 2);
#endif
return(K_ILLEGAL);
}
Cfbit = cmp_bitmap[Ci_val][V_val] ;
for (disp = 0, k = 0; k < Cf_val; k++)
{
if (Cfbit & BIT_MASK)
disp++ ;
Cfbit >>= 1 ;
}
if (!(Cfbit & BIT_MASK))
return(K_ILLEGAL) ;
comp2 = cmp_srchtbl[Ci_val][V_val] + disp ;
mask = cmp_srchtbl[Ci_val][V_val] & 0xff ;
if ((mask + disp) > 0xfe)
comp2 += SKIP ;
#if defined(i386) || defined(__ppc)
return(((comp2 & 0x00ff) << 8)|((comp2 & 0xff00) >> 8));
#else
return(comp2);
#endif
}
#ifdef TESTP
main()
{
unsigned int comb2, comp2;
for(;;) {
scanf("%x",&comb2);
comp2 = packtocomp(comb2);
printf("/n completion code = 0x%x\n", comp2);
}
}
#endif