// Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator
// From input file "/var/home/pantec/src/turbo/ucdas/dasunit2.p"


//$O+


#include <p2c/p2c.h>


#include <p2c/exithandler.h>

#define DASUNIT2_G
#include "/software/include/p2c/dasunit2.h"


//unsigned short CurrentLabel = 0;
int HighestLabel = 0;
//unsigned short daBaseAddr = 0;


//
//const
//     DPos       : byte = 128;
//

struct OpCdRec {
  uchar Len, Operands;
  Str24 Str2;
  Str12 Str3_;
  schar AdrType;
};

typedef OpCdRec OpCodeBufTyp[MaxOpcodes + 1];
typedef uchar Array256Type[256];
//typedef LabelRecType LabelRecArrayType[MaxLRec + 1];


long DoubleList[9], TripleList[9];
Array256Type IndOpcode[3];

FILE *DFile;
unsigned short step, MaxCodes;

OpCdRec*        OpcodeBuffer;
LabelRecType**  LBuf;
unsigned short* HashList;


ExitProcType SavePtr;
char DFile_NAME[_FNSIZE];


char* HexaByte(char *__Result__, uchar bt, boolean Srt)
{
  char Hex[32];

  strcpy(Hex,"0123456789abcdef");
  if (Srt)
     sprintf(__Result__, "%c%ch",Hex[bt >> 4],Hex[bt & 0x0f]);
  else
     sprintf(__Result__, "%c%c" ,Hex[bt >> 4],Hex[bt & 0x0f]);
  
  return __Result__;
}


char *HexaWord(char *__Result__, unsigned short wd)
{
  char STR_[20], STR_1[20];

  sprintf(__Result__, "%s%s",
	  HexaByte(STR_, wd >> 8, false), HexaByte(STR_1, wd & 255, true));
  
  return __Result__;
}



void WriteSymbols(char *st)
{
  FILE *f = fopen(st, "w+b");
  
  _SETIO(f != NULL, FileNotFound);
  if (P_ioresult == 0)
    {
     unsigned short k = 0;
     int w = fwrite(&HighestLabel, 1, sizeof(unsigned short), f);
     int i = 0;

#ifdef DEBUG
     fprintf(stderr,"WriteSymbols(%s,%d)\n",st,HighestLabel);
#endif

     for (i=0;i<HighestLabel;i++)
       {        
        k = HashList[i];

#ifdef DEBUG
        fprintf(stderr,"WriteSymbols(%d,%d,%s)\n",i,k,LBuf[k]->S);
#endif
        w = fwrite(&k, 1, sizeof(unsigned short), f);
        w = fwrite(&(LBuf[k]->I), 1, sizeof(LabelRecType), f);
       }

     if (f != NULL)
       fclose(f);
     f = NULL;
    }
  if (f != NULL)
    fclose(f);
}


//$F+
static void OpcodeExit(void)
{
//  OpcodeBuffer = new OpCdRec[MaxOpcodes + 1];
//  HashList = new unsigned short[MaxLabels];
//  LBuf = new (LabelRecType*)[MaxLabels];
  
  for (int i = 0; i < MaxLabels; i++)
     delete [] LBuf[i];

  delete [] LBuf;
  delete [] HashList;
  delete [] OpcodeBuffer;
 
#ifdef DEBUG
  fprintf(stderr,"DAsUnit2.Done\n");
#endif   
}


//$F-

boolean ReadCodes(char *FN)
{
  boolean ready = false;
  unsigned short Index = 0;
  Str79 CdStr, MStr;

  uchar Opcode[3];
  long SET_[9];
  char STR_[256];


  for (int i = 0; i <= MaxOpcodes; i++)
    {
     OpCdRec *WITH_ = &OpcodeBuffer[i];
     WITH_->Len = 1;
     WITH_->Operands = 0;
     strcpy(WITH_->Str2, "    illegal Opcode");
     *WITH_->Str3_ = '\0';
     WITH_->AdrType = 0;
    }

  P_expset(DoubleList, 0);
  P_expset(TripleList, 0);
  //
  //DPos:=128;
  //
  *CdStr = '\0';
  strcpy(DFile_NAME, FN);
  if (DFile != NULL)
    DFile = freopen(DFile_NAME, "r", DFile);
  else
    DFile = fopen(DFile_NAME, "r");
  _SETIO(DFile != NULL, FileNotFound);
  if (P_ioresult != 0 || *FN == '\0')
    {
     ready = false;
     return ready;
    }
  fgets(CdStr, 128, DFile);
  char *TEMP_ = strchr(CdStr, '\n');
  if (TEMP_ != NULL)
    *TEMP_ = 0;
  fgets(CdStr, 128, DFile);
  TEMP_ = strchr(CdStr, '\n');
  if (TEMP_ != NULL)
    *TEMP_ = 0;

  while (!P_eof(DFile) && strcmp(CdStr, "ENDE") != 0 && Index < MaxOpcodes)
    {
//     puts(CdStr);
//     putch(13);
  
     //$EndIf
     Index++;
     OpCdRec *WITH_ = &OpcodeBuffer[Index];

     //
     //MStr:=copy(CdStr,1,4);
     //
     for (int i = 0; i <= 1; i++)
       {
	strsub(MStr, CdStr, i * 6 + 1, 5);
#ifdef DEBUG
        fprintf(stderr,"%s ",MStr);
#endif

	int VCode = sscanf(MStr, "%x", &Opcode[i]) == 0;
	if (VCode != 0)
	  {
	   ready = true;
#ifdef DEBUG           
	   fprintf(stderr,"Error in Opcode%d %u [%s]\n", i, Index,MStr);
#endif           
	  }
       }

     strsub(MStr, CdStr, 13, 1);
#ifdef DEBUG
        fprintf(stderr,"%s ",MStr);
#endif


     int VCode = sscanf(MStr, "%d", &WITH_->Len) == 0;
     if (VCode != 0)
       {
	ready = true;
#ifdef DEBUG        
	fprintf(stderr,"Error in Length %u [%s]\n", Index, MStr);
#endif        
       }

     switch (WITH_->Len)
       {

	 case 1:
	IndOpcode[0][Opcode[0]] = Index & 255;
	break;

	 case 2:
	IndOpcode[0][Opcode[0]] = Index >> 8;
	IndOpcode[2][Opcode[1]] = Index & 255;
	P_addset(DoubleList, Opcode[0]);
	break;

	 case 3:
	IndOpcode[0][Opcode[0]] = Index >> 8;
	IndOpcode[1][Opcode[1]] = (Index & 255) >> 4;
	IndOpcode[2][Opcode[2]] = Index & 15;
	P_addset(TripleList, Opcode[0]);
	break;
       }


     strsub(MStr, CdStr, 15, 1);
#ifdef DEBUG
        fprintf(stderr,"%s ",MStr);
#endif

     VCode = (sscanf(MStr, "%d", &WITH_->Operands) == 0);
     if (VCode != 0)
       {
	ready = true;
#ifdef DEBUG
	fprintf(stderr,"Error in Operands %u [%s]\n", Index,MStr);
#endif        
       }

     strsub(MStr, CdStr, 17, 3);
#ifdef DEBUG
        fprintf(stderr,"%s ",MStr);
#endif

     VCode = (sscanf(MStr, "%d", &WITH_->AdrType) == 0);
     if (VCode != 0)
       {
	ready = true;
#ifdef DEBUG
	fprintf(stderr,"Error in AdrType %u [%s]\n", Index,MStr);
#endif        
       }

     strsub(WITH_->Str2, CdStr, 21, 23);
#ifdef DEBUG
        fprintf(stderr,"%s ",WITH_->Str2);
#endif

     while (WITH_->Str2[strlen(WITH_->Str2) - 1] == ' ')
       {
	sprintf(STR_, "%.*s", int(strlen(WITH_->Str2) - 1), WITH_->Str2);
	strcpy(WITH_->Str2, STR_);
// p2c: /var/home/pantec/src/turbo/ucdas/dasunit2.p, line 256:
// * Note: Possible string truncation in assignment [145]
       }

     strsub(WITH_->Str3_, CdStr, 44, 12);
#ifdef DEBUG
        fprintf(stderr,"%s\n",WITH_->Str3_);
#endif

     fgets(CdStr, 128, DFile);
     TEMP_ = strchr(CdStr, '\n');
     if (TEMP_ != NULL)
       *TEMP_ = 0;
    }
// p2c: /var/home/pantec/src/turbo/ucdas/dasunit2.p, line 196:
// * Note: Turbo Pascal conditional compilation directive was ignored [218]
  //$IfDef Test
  if (DFile != NULL)
    fclose(DFile);
  DFile = NULL;

  MaxCodes = Index - 1;

#ifdef DEBUG
  fprintf(stderr,"%u opcodes read\n", MaxCodes);
#endif
  
  ready = true;

  return ready;
}


void InstallOpcodeExit(void)
{
//  SavePtr = ExitProc;
  SavePtr.proc = ExitProc.proc;
  SavePtr.link = ExitProc.link;

  ExitProc.proc = OpcodeExit;
  ExitProc.link = (long int)&SavePtr;

  DFile = NULL;

  OpcodeBuffer = new OpCdRec[MaxOpcodes + 1];
  HashList = new unsigned short[MaxLabels];
  LBuf = new (LabelRecType*)[MaxLabels];
  
  for (int i = 0; i < MaxLabels; i++)
    {
     LBuf[i] = new LabelRecType;
     LBuf[i]->I = free_;
     LBuf[i]->Hash = 0;
     strcpy(LBuf[i]->S,"\0");
    }
}


boolean MatchAdr(unsigned short idx/*, uchar &B, unsigned short &W*/)
{
#ifdef DEBUG
  fprintf(stderr,"MatchAdr(%d)\n",idx);
#endif
  
  if (LBuf[idx]->I != free_)
       return TRUE;
    else
       return FALSE;   
}


void WriteLabelStr(unsigned short wd, char *LStr)
{
//  boolean ready;

  if (!MatchAdr(wd))
    {
//     CurrentLabel++;
     
     LBuf[wd]->Hash = HighestLabel;
     HashList[HighestLabel]=wd;
     HighestLabel++;
    } 

  strcpy(LBuf[wd]->S, LStr);
  LBuf[wd]->I = Lab;
//  return true;
}


void WriteTableStr(unsigned short wd, char *LStr, uchar b)
{
//  boolean ready;

  if (MatchAdr(wd))
    {
     strcpy(LBuf[wd]->S, LStr);
     return; 
    }

  TableRecType *TP = (TableRecType *)(&(LBuf[wd]->I));
  strcpy(TP->S, LStr);
  TP->B = b;
  TP->I = Table;
  TP->Hash = HighestLabel;
  HashList[HighestLabel]=wd;
  HighestLabel++;

//  CurrentLabel++;
//  return true;
}



void *GetLabelObj(unsigned short wd)
{
  void *__Result__ = NULL;

  if (MatchAdr(wd))
       return (&(LBuf[wd]->I));

  return NULL;
}


int GetLabelNum(int i)
{
  if (i<HighestLabel)
     return HashList[i];
     
  return -1;   
}


boolean GetLabelStr(unsigned short wd, char *LStr)
{
  boolean ready;

  if (!MatchAdr(wd))
    return false;

  strcpy(LStr, LBuf[wd]->S);
  return true;
}


boolean GetTableStr(unsigned short wd, char *LStr, uchar &b)
{
  boolean ready;

  if (!MatchAdr(wd))
    return false;

  TableRecType *TP = (TableRecType *)(&(LBuf[wd]->I));

  if (TP->I != Table)
     return false;

  strcpy(LStr, TP->S);
  b = TP->B;

  return true;
}


boolean AddLabel(unsigned short wd, char *LStr)
{
  boolean ready;

  if (MatchAdr(wd))
    return false;

  WriteLabelStr(wd,LStr);

/*
//  CurrentLabel++;
  strcpy(LBuf[wd]->S, LStr);
  LBuf[wd]->I = Lab;

  LBuf[wd]->Hash = HighestLabel;
  HashList[HighestLabel]=wd;
  HighestLabel++;
*/
  return true;
}


boolean AddTable(unsigned short wd, char *LStr, uchar b)
{
  boolean ready;

  if (MatchAdr(wd))
    return false;

  WriteTableStr(wd,LStr,b);

/*
  TableRecType *TP = (TableRecType *)(&(LBuf[wd]->I));
//  CurrentLabel++;

  sprintf(TP->S, "%.8s", LStr);
  TP->I = Table;
  TP->B = b;
  TP->Hash = HighestLabel;
  HashList[HighestLabel]=wd;
  HighestLabel++;
*/
  return true;
}


boolean DeleteLabel(unsigned short wd)
{
  boolean ready;

  if (!MatchAdr(wd))
    return false;

  //clear labels memory
  strcpy(LBuf[wd]->S,"\0");
  LBuf[wd]->I = free_;

  // sort the hashlist
  int j=0;
  for (int i=0; i<HighestLabel; i++)
    {
     if ((HashList[i] == wd) && (j == 0))
       j++;
    
     if (j>0)
        {
         HashList[i]=HashList[i+j]; 
         LBuf[HashList[i]]->Hash=i;
        } 
    }

  HighestLabel--;
  return true;
}


void AutomaticLabel(unsigned short JAdr)
{
  Str6 STR_,STR_1;

  if (MatchAdr(JAdr))
    return;

  sprintf(STR_, "L_%s", HexaWord(STR_1, JAdr));
  WriteLabelStr(JAdr,STR_);

//  CurrentLabel++;
/*
  LBuf[JAdr]->I = Lab;
  sprintf(LBuf[JAdr]->S, "L_%s", HexaWord(STR_, JAdr));

  LBuf[JAdr]->Hash = HighestLabel;
  HashList[HighestLabel]=JAdr;
  HighestLabel++;
*/  
}



void ClearAllLabels(void)
{
  HighestLabel = 0;

#ifdef DEBUG
  fprintf(stderr,"ClearAllLabels()\n");
#endif

  for (int Sg = 0; Sg < MaxLabels; Sg++)
    {
     LBuf[Sg]->I = free_;
     strcpy(LBuf[Sg]->S, "            ");
     strcpy(LBuf[Sg]->S, "\0");
     LBuf[Sg]->Hash=0;
    }
}


void ReadSymbols(char *st)
{
  unsigned short l;

  ClearAllLabels();

#ifdef DEBUG
  fprintf(stderr,"ReadSymbols(%s)\n",st);
#endif       
        
  FILE *f = fopen(st, "r+b");
  _SETIO(f != NULL, FileNotFound);
  if (P_ioresult == 0)
    {
     unsigned short k = 0;
     unsigned short r = fread(&HighestLabel, 1, sizeof(unsigned short), f);

     while ((k < HighestLabel) && (r > 0))
       {

	r = fread(&l, 1, sizeof(unsigned short), f);
	r = fread(&(LBuf[l]->I), 1, sizeof(LabelRecType), f);

#ifdef DEBUG
        fprintf(stderr,"l:%d\tk:%d\ts:%s\n",l,k,LBuf[l]->S);
#endif       

        LBuf[l]->Hash = k;
        HashList[k]=l;

	k++;
       }

     HighestLabel=k; 

     if (f != NULL)
       fclose(f);
     f = NULL;
    }
  if (f != NULL)
    fclose(f);
}


boolean GetTable(unsigned short &Index, char *LStr, const int MAX_LStr)
{
  unsigned short sg = Index;
  
  if (!MatchAdr(sg))
    return false;

  if (LBuf[sg]->I != Table)
    return false;

  TableRecType *TP = (TableRecType *)&(LBuf[sg]->I);

#ifdef DEBUG
  fprintf(stderr,"GetTable(%d,%s,%d)\n",Index,TP->S,TP->B);
#endif

  sprintf(LStr, "%s:  db   ", TP->S);
  Index += TP->B;

  return true;
}


char *GetCode(char *__Result__, uchar *CByte, unsigned short &Index)
{
  Str79 MsgStr, MsgStr2;
  unsigned short Match = 0;
  unsigned short JmpAdr; 

  TableRecType *TP;
  char STR_[256];
  Str3 STR_1, STR_2;
  Str6 STR_3;
  char STR_4[130];

  *MsgStr = '\0';

  if (P_inset(CByte[0], TripleList))
    Match = IndOpcode[0][CByte[0]] * 256 + IndOpcode[1][CByte[1]] * 16 +
	    IndOpcode[2][CByte[2]];
  else if (P_inset(CByte[0], DoubleList))
    Match = IndOpcode[0][CByte[0]] * 256 + IndOpcode[2][CByte[1]];
  else
    Match = IndOpcode[0][CByte[0]];

  schar counts = OpcodeBuffer[Match].Len + OpcodeBuffer[Match].Operands;
  strcat(MsgStr, "  ");
  Index += counts;

  sprintf(MsgStr + strlen(MsgStr), " %s", OpcodeBuffer[Match].Str2);

  unsigned short FORLIM_ = strlen(OpcodeBuffer[Match].Str2);
  for (step = 6; step >= FORLIM_ + 1; step--)
    strcat(MsgStr, " ");


  OpCdRec *WITH_ = &OpcodeBuffer[Match];

  switch (WITH_->AdrType)
    {

      case -1:
     strcpy(MsgStr2, " #");
     break;

      case -8:
     strcpy(MsgStr2, "#");
     break;

      case -5:
      case -6:
      case -9:
      case -11:
      case -32:
      case -21:
     *MsgStr2 = '\0';
     break;

      default:
     strcpy(MsgStr2, "  ");
     break;
    }

#ifdef DEBUG
  fprintf(stderr,"GetCode(case %d)\n",WITH_->AdrType);
#endif
  switch (WITH_->AdrType)
    {
      case -1:
      case -21:
     if (WITH_->Operands > 1)
       if (WITH_->AdrType > -20)
	 sprintf(MsgStr2 + strlen(MsgStr2), "%s%s",
		 HexaByte(STR_1, CByte[WITH_->Len], false),
		 HexaByte(STR_2, CByte[WITH_->Len + 1], true));
       else
	 sprintf(MsgStr2 + strlen(MsgStr2), "%s%s",
		 HexaByte(STR_1, CByte[WITH_->Len + 1], false),
		 HexaByte(STR_2, CByte[WITH_->Len], true));
     else
       strcat(MsgStr2, HexaByte(STR_1, CByte[WITH_->Len], true));
     break;

      case -2:
      case -22:
     JmpAdr = CByte[WITH_->Len];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -22)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -43:
      case -63:
      case -3:
      case -23:
     if (WITH_->AdrType < -30)
       JmpAdr = (unsigned short)(CByte[WITH_->Len + 1] << 8) + CByte[WITH_->Len];
     else
       JmpAdr = (unsigned short)(CByte[WITH_->Len] << 8) + CByte[WITH_->Len + 1];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -23 || WITH_->AdrType == -63)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -4:
     if (CByte[counts-1] > 0x80)
       JmpAdr = Index + CByte[counts-1] - 0x100;
     else
       JmpAdr = Index + CByte[counts-1];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -5:
     strcat(MsgStr2, HexaByte(STR_1, CByte[WITH_->Len], true));
     break;

      case -6:
     sprintf(MsgStr2 + strlen(MsgStr2), "%s, %s",
	     HexaByte(STR_1, CByte[WITH_->Len], true),
	     HexaByte(STR_2, CByte[WITH_->Len + 1], true));
     break;

      case -7:
      case -27:
     JmpAdr = CByte[WITH_->Len];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -27)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }

     sprintf(MsgStr2 + strlen(MsgStr2), ", %s",
	     HexaByte(STR_1, CByte[WITH_->Len + 1], true));
     break;

      case -8:
     if (CByte[counts-1] > 0x80)
       JmpAdr = Index + CByte[counts-1] - 0x100;
     else
       JmpAdr = Index + CByte[counts-1];

     sprintf(MsgStr2 + strlen(MsgStr2), "%s, ",
	     HexaByte(STR_1, CByte[WITH_->Len], true));

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -9:
     sprintf(MsgStr2 + strlen(MsgStr2), "%s, ",
	     HexaByte(STR_1, CByte[WITH_->Len], true));

     if (CByte[counts-1] > 0x80)
       JmpAdr = Index + CByte[counts-1] - 0x100;
     else
       JmpAdr = Index + CByte[counts-1];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -10:
      case -30:

     JmpAdr = CByte[WITH_->Len];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -30)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }

     strcat(MsgStr2, ",");
     if (CByte[counts-1] > 0x80)
       JmpAdr = Index + CByte[counts-1] - 0x100;
     else
       JmpAdr = Index + CByte[counts-1];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -11:
      case -12:
      case -32:
     if (CByte[counts-1] > 0x80)
       JmpAdr = Index + CByte[counts-1] - 0x100;
     else
       JmpAdr = Index + CByte[counts-1];

     if (WITH_->AdrType == -11)
       strcat(MsgStr2, HexaByte(STR_1, CByte[WITH_->Len], true));
     else if (MatchAdr(CByte[WITH_->Len]))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[CByte[WITH_->Len]]->S);
     else
       {
	if (WITH_->AdrType == -32)
	  AutomaticLabel(CByte[WITH_->Len]);
	strcat(MsgStr2, HexaByte(STR_1, CByte[WITH_->Len], true));
       }

     sprintf(MsgStr2 + strlen(MsgStr2), ",%s,",
	     HexaByte(STR_1, CByte[WITH_->Len + 1], true));

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -13:
      case -33:
      case -44:
      case -64:
     if (WITH_->AdrType > -40)
       JmpAdr = ((CByte[0] & 31) << 8) | CByte[1];
     else
       JmpAdr = ((CByte[1] & 31) << 8) | CByte[0];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -33 || WITH_->AdrType == -64)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;

      case -15:
      case -35:
     JmpAdr = CByte[WITH_->Len];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -35)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }

     sprintf(MsgStr2 + strlen(MsgStr2), ", #%s",
	     HexaByte(STR_1, CByte[counts-1], true));
     break;

      case -17:
      case -37:
     JmpAdr = CByte[WITH_->Len];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -37)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }

     strcat(MsgStr2, ",");
     JmpAdr = CByte[WITH_->Len + 1];

     if (MatchAdr(JmpAdr))
       sprintf(MsgStr2 + strlen(MsgStr2), " %s", LBuf[JmpAdr]->S);
     else
       {
	if (WITH_->AdrType == -37)
	  AutomaticLabel(JmpAdr);
	strcat(MsgStr2, HexaWord(STR_3, JmpAdr));
       }
     break;
    }

  strcat(MsgStr, MsgStr2);

  strcat(MsgStr, WITH_->Str3_);
  FORLIM_ = strlen(MsgStr);
  for (step = 30; step >= FORLIM_; step--)
    strcat(MsgStr, " ");

  // the remainder as  charstring , adress, bytes
  strcat(MsgStr, "; ");
  for (step = 1; step <= counts; step++)
    // remove unwanted chars
    if (CByte[step-1] >= 32 && CByte[step-1] <= 126)
      sprintf(MsgStr + strlen(MsgStr), "%c", CByte[step-1]);
    else
      strcat(MsgStr, ".");

  // refill to 36 chars
  FORLIM_ = strlen(MsgStr);
  for (step = 36; step >= FORLIM_; step--)
    strcat(MsgStr, " ");

  if (Index - counts == 0)
    sprintf(MsgStr, "\n\015%s", strcpy(STR_4, MsgStr));

  unsigned short LabelIdx = Index - counts;
  if (MatchAdr(LabelIdx))
    {
     sprintf(MsgStr, "%s:\n\015%s",
	     LBuf[LabelIdx]->S, strcpy(STR_, MsgStr));

     if (LBuf[LabelIdx]->S[0] != '.' &&
	 LBuf[LabelIdx]->S[0] != '@' && LBuf[LabelIdx]->S[0] != '_')
       sprintf(MsgStr, "\n\015%s", strcpy(STR_4, MsgStr));
    }

  sprintf(MsgStr + strlen(MsgStr), "  %s   ", HexaWord(STR_3, LabelIdx ));
  sprintf(MsgStr + strlen(MsgStr), "%s ", HexaByte(STR_1, CByte[0], false));

  for (step = 2; step <= counts; step++)
    sprintf(MsgStr + strlen(MsgStr), "%s ",
	    HexaByte(STR_1, CByte[step-1], false));

  return strcpy(__Result__, MsgStr);
}


void _DAsUnit2_init(void)
{
  static int _was_initialized = 0;
  if (_was_initialized++)
    return;
}
// p2c: Note: Remember to call _DAsUnit2_init() in main program [215]




// End.
