home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff345.lzh / X2X / x2x_2.c < prev    next >
C/C++ Source or Header  |  1990-04-16  |  22KB  |  906 lines

  1. /*SCCS header -          %W%   %G%                                     */
  2. /************************************************************************ 
  3. *                                                                       * 
  4. *            File   :          x2x_2.c                *
  5. *                       Version:        0.0                             * 
  6. *                       Author :        Gary Duncan                     * 
  7. *                    24 Inkster St                   *
  8. *                    Kambah ACT 2902                 *
  9. *                    Australia                       *
  10. *                                                                       * 
  11. *-----------------------------------------------------------------------* 
  12. * Modification record 
  13. * ------------------- 
  14. * Date         By whom             Change 
  15. * ----         -------             ------ 
  16. * 12 Apr 89     GMD                AMIGA'd
  17. * 01 Jul 89    "           Changed K64 to K64K
  18. *
  19. *------------------------------------------------------------------------ 
  20.  
  21.  
  22. *------------------------------------------------------------------------------ 
  23. * Contents 
  24. * ------- 
  25. *+ 
  26. *+              rite_rec        writes DLL record to disc 
  27. *+              get_rtype       validates input file as INTEL/MOTOROLA/TEK.. 
  28. *+              f_reset         resets file pointer to start 
  29. *+              dll_Irec        builds an INTEL  record 
  30. *+              dll_Mrec        builds a MOTOROLA  record 
  31. *+              dll_Trec        builds a TEKTRONIX  record 
  32. *+              dll_Txrec       builds a TEKTRONIX-extended  record 
  33. *+              dll_Qrec        builds a QTAM  record 
  34. *+              sum_get         gets a checksum on a string 
  35. *+              xgetc           gets a DLL byte     
  36. *+              xputc           puts a DLL addr/byte pair in buffer 
  37. *+              fill_ipbuf      replenish i/p buffer 
  38. *+              get_len         determine # of contiguous bytes in record 
  39. *+  
  40. ******************************************************************************/ 
  41.  
  42. #include "x2x_amiga.h"
  43. #include "x2x_data.c"
  44.  
  45.  
  46. /*************************************************************************** 
  47.  
  48.  
  49.   Function :     rite_rec 
  50.  
  51.  
  52.   Purpose  :     Puts DLL record into buffer and writes to disc when  
  53.                  full , or when forced 
  54.  
  55.   Entry    : 
  56.  
  57.  
  58.   Returns  :   
  59.  
  60.  
  61. ****************************************************************************/ 
  62.  
  63.  
  64. int   rite_rec ( fptr , fmadr , len )  
  65.  
  66. int fptr ; 
  67. char *fmadr ; 
  68. int len ; 
  69.  
  70.  
  71.   while ( len-- ) 
  72.       { 
  73.          dlldbuf [odccon++] = *fmadr++ ;    /* copy to buffer */    
  74.          if ( odccon == OPBUFLEN )         /* if full write */ 
  75.            { 
  76.             if ( write( fptr , dlldbuf , OPBUFLEN) != OPBUFLEN ) 
  77.               {    
  78.                  fprintf (stderr,"(rite_rec) - write error" ); 
  79.                  perror("Disc write error: "); 
  80.                  exit(3); 
  81.               } 
  82.             odccon = 0 ;  
  83.       } 
  84.        } 
  85.  
  86.  
  87. /*************************************************************************** 
  88.  
  89.  
  90.   Function :     get_rtype      
  91.  
  92.  
  93.   Purpose  :     Determines type of DLL file 
  94.  
  95.   Entry    : 
  96.  
  97.  
  98.   Returns  :   with file type 
  99.  
  100.  
  101. ****************************************************************************/ 
  102.  
  103. int   get_rtype ( ) 
  104.  
  105.   int ch  ; 
  106.   int retval = 1 ; 
  107.    
  108.   ch = Ichar () ;              /* 1st chara assumed to define file type !*/ 
  109.   switch ( ch ) 
  110.     { 
  111.      case ':'  :                  /* INTEL */ 
  112.          break ; 
  113.   
  114.      case 'S'  :                  /* MOTOROLA */ 
  115.         ch = Ichar() -'0' ;       /* get type 1,2,3 */ 
  116.         switch (ch) 
  117.       { 
  118.       case 3 :  ++retval ; 
  119.       case 2 :  ++retval ; 
  120.       case 1 :  ++retval ; 
  121.               xiMaddr = retval + 1 ; 
  122.               break ; 
  123.       default : 
  124.             retval = 0 ; 
  125.       } 
  126.         break ; 
  127.  
  128.      case '/'  :                  /* TEKTRONIX */ 
  129.  
  130.        retval = 5 ; 
  131.        break ;         
  132.  
  133.      case '%'  :                  /* TEKTRONIX - extended  */ 
  134.  
  135.        retval = 6 ; 
  136.        break ;         
  137.  
  138.      case 'Q'  :                  /* QTAM  */ 
  139.  
  140.        retval = 7 ; 
  141.        break ;         
  142.  
  143.      default : 
  144.        retval = 0 ; 
  145.        break ;                   /* ?????????  */ 
  146.  
  147.      } 
  148.  
  149.    f_reset () ;      /* reset file ptrs */ 
  150.  
  151.    return ( retval -1 ) ; 
  152.  
  153.  
  154. /*************************************************************************** 
  155.  
  156.  
  157.   Function :       f_reset     
  158.  
  159.  
  160.   Purpose  :      resets pointers to DLL file- ensures read starts at 
  161.                   beginning 
  162.  
  163.   Entry    : 
  164.  
  165.  
  166.   Returns  :     TRUE -  
  167.  
  168.                  FALSE-  
  169.  
  170.  
  171. ****************************************************************************/ 
  172.  
  173.  
  174. int f_reset () 
  175.  
  176.  
  177.     boffs = 0 ; 
  178.     disclen = 0 ; 
  179.   
  180.   if (  lseek ( iffp , 0L  , L_SET ) == -1 )   /* reset file ptr */ 
  181.     { 
  182.         fprintf (stderr, "lseek fail\n" ) ; 
  183.         exit(1) ; 
  184.     } 
  185.  
  186.  
  187. /*************************************************************************** 
  188.  
  189.  
  190.   Function :     dll_Irec 
  191.  
  192.  
  193.   Purpose  :     builds an INTEL  DLL record 
  194.  
  195.   Entry    : 
  196.  
  197.  
  198.   Returns  :    # of charas in record 
  199.  
  200.  
  201.  
  202. ****************************************************************************/ 
  203.  
  204.  
  205. int  dll_Irec ( tipe , addr ,  len ) 
  206.  
  207. int tipe , len ; 
  208. long addr ; 
  209.  
  210. int count , j ; 
  211. uchar ch ; 
  212. int t2data ; 
  213.  
  214.  
  215.      t2data =  addr << 12  ;           /* convert to  seg offset   */ 
  216.      if ( tipe == 2 ) 
  217.         addr = 0 ; 
  218.  
  219.     /*----------- calc checksum --------------------------------*/ 
  220.  
  221.      Icsum = 0 ;  
  222.      Icsum += sum_get ( 'I' , &addr , 2 ) ;      /* addr  */ 
  223.      Icsum += sum_get ( 'I' , &tipe , 1 ) ;      /* type  */ 
  224.      Icsum += sum_get ( 'I' , &len , 1 ) ;       /*  len   */ 
  225.  
  226.    /* -----------now build buffer ------------------------*/ 
  227.  
  228.    opbuf [0] = ':'                   ; 
  229.     
  230.    chcon = convc2 ( len ) ; 
  231.    opbuf [IRLEN] = chcon >> 8 ; 
  232.    opbuf [IRLEN+1] = chcon & 0xFF ; 
  233.  
  234.    chcon = convc2 ( tipe ) ;                   /* rec type - data= 0 */ 
  235.    opbuf [IRTYPE] = chcon >> 8 ; 
  236.    opbuf [IRTYPE+1] = chcon & 0xFF ; 
  237.  
  238.    chcon = convc2 ( (int)(addr >> 8) ) ;           /* load addr - hi */ 
  239.    opbuf [IRADDR] = chcon >> 8 ; 
  240.    opbuf [IRADDR+1] = chcon & 0xFF ; 
  241.  
  242.    chcon = convc2 ( (int)addr ) ;           /* load addr - lo */ 
  243.    opbuf [IRADDR+2] = chcon >> 8 ; 
  244.    opbuf [IRADDR+3] = chcon & 0xFF ; 
  245.  
  246.  
  247.    for ( count = 0 , j = 0; count < len ; ++ count, j += 2 )   /* now the 
  248.                                                                      data */ 
  249.      { 
  250.        if ( tipe == 2 )                        /* fudge for USBA record */ 
  251.           { 
  252.             ch = t2data >> 8 ; 
  253.             t2data <<= 8 ; 
  254.           } 
  255.        else   
  256.            ch = xgetc ( )  ;                  /* get data chara */ 
  257.         
  258.        Icsum += sum_get ( 'I' , &ch , 1 ) ;       /* accum c/sum   */ 
  259.        chcon = convc2 ( ch ) ;        
  260.    
  261.        opbuf [IRDATA +   j ] = chcon >> 8 ; 
  262.        opbuf [IRDATA+1 + j ] = chcon & 0xFF ; 
  263.      } 
  264.     
  265.    Icsum =  - Icsum ; 
  266.    chcon = convc2 ( Icsum ) ;           /* checksum  */ 
  267.    opbuf [IRDATA +    j ] = chcon >> 8 ; 
  268.    opbuf [IRDATA + 1 +j ] = chcon & 0xFF ; 
  269.  
  270.    return ( IRDATA + 2 + j ) ;     /* return length */ 
  271.  
  272. /*************************************************************************** 
  273.  
  274.  
  275.   Function :     dll_Mrec 
  276.  
  277.  
  278.   Purpose  :     builds a MOTOROLA 68000  DLL record 
  279.  
  280.   Entry    : 
  281.  
  282.  
  283.   Returns  :     TRUE -  
  284.  
  285.                  FALSE-  
  286.  
  287.  
  288. ****************************************************************************/ 
  289.  
  290.  
  291.  
  292. int  dll_Mrec ( tipe , addr ,  len ) 
  293.  
  294. int tipe  , len ; 
  295. long addr ; 
  296.  
  297.  
  298. int count , j ; 
  299. uchar ch ; 
  300. static int size ; 
  301. int offs ; 
  302.  
  303.  
  304.     /*------------- abort if S1 and addr > K64K ----------------------------*/ 
  305.  
  306.     if ( (xoMaddr == 2) && ( (addr+len) > K64K ) ) 
  307.       { 
  308.          fprintf ( stderr ,  
  309.               "\007\nAbort: address overflow! ( %ld )\n" ,addr+len ); 
  310.          exit (1) ; 
  311.       } 
  312.    offs = 2 * ( xoMaddr - 2) ;   /* addr offset start */ 
  313.  
  314.    size = len + 1 + offs/2 + 2 ; 
  315.  
  316.  
  317.    /*----------- calc  checksum --------------------------------*/ 
  318.  
  319.     Icsum = 0 ;  
  320.     Icsum += sum_get ( 'I' , &addr , 4 ) ;      /* addr  */ 
  321.     Icsum += sum_get ( 'I' , &size , 1 ) ;      /*  len   */ 
  322.  
  323.    /* -----------now build buffer ------------------------*/ 
  324.  
  325.    opbuf [0] = 'S'                   ; 
  326.    opbuf [1] =  tipe                ; 
  327.     
  328.  
  329.    chcon = convc2 ( size ) ; 
  330.    opbuf [MRLEN]   = chcon >> 8 ; 
  331.    opbuf [MRLEN+1] = chcon & 0xFF ; 
  332.  
  333.    /*----------------- now the variable address length ------------------*/ 
  334.  
  335.    for ( count=0 , j = 2*xoMaddr-2 ; count < (xoMaddr) ; ++count , j -= 2  ) 
  336.      { 
  337.        ch = addr ; 
  338.        addr >>= 8 ; 
  339.        chcon = convc2 ( ch ) ;                /* byte -> 2 ASCII hex */ 
  340.        opbuf [MRADDR+ j + 0] = chcon >> 8 ; 
  341.        opbuf [MRADDR+ j + 1] = chcon & 0xFF ; 
  342.      }  
  343.  
  344.   /*---------------------- now the data ----------------------------------*/ 
  345.    for ( count = 0 , j = 0; count < len ; ++ count, j += 2 ) 
  346.                                                       /* now the data */ 
  347.      { 
  348.        ch = xgetc ( ) ;       
  349.        Icsum += sum_get ( 'I' , &ch , 1 ) ;       /* accum c/sum   */ 
  350.        chcon = convc2 ( ch ) ;        
  351.  
  352.        opbuf [MRDATA + offs +  j ] = chcon >> 8 ; 
  353.        opbuf [MRDATA+1 + offs +j ] = chcon & 0xFF ; 
  354.      } 
  355.     
  356.    Icsum = ~Icsum ;                 /* 1s complement */ 
  357.    chcon = convc2 ( Icsum ) ;           /* checksum  */ 
  358.    opbuf [MRDATA + offs +   j ] = chcon >> 8 ; 
  359.    opbuf [MRDATA + offs + 1 +j ] = chcon & 0xFF ; 
  360.  
  361.    return ( MRDATA + offs + 2 + j ) ;     /* return length */ 
  362.  
  363.  
  364. /*************************************************************************** 
  365.  
  366.  
  367.   Function :     dll_Trec 
  368.  
  369.  
  370.   Purpose  :     builds a TEKTRONIX DLL record 
  371.  
  372.   Entry    : 
  373.  
  374.  
  375.   Returns  :     TRUE -  
  376.  
  377.                  FALSE-  
  378.  
  379.  
  380. ****************************************************************************/ 
  381.  
  382.  
  383. int  dll_Trec ( tipe , addr ,  len ) 
  384.  
  385. int tipe , len ; 
  386. long addr ; 
  387.  
  388. int count , j ; 
  389. uchar ch ; 
  390.  
  391.     /*------------- abort if addr > K64K ----------------------------*/ 
  392.  
  393.     if ( (addr+len) > K64K ) 
  394.       { 
  395.          fprintf ( stderr ,  
  396.               "\007\nAbort: address overflow! ( %ld )\n" ,addr+len ); 
  397.          exit (1) ; 
  398.       } 
  399.  
  400.     /*----------- calc load checksum --------------------------------*/ 
  401.  
  402.      Tcsum = 0 ;  
  403.      Tcsum += sum_get ( 'T' , &addr , 2 ) ;      /* addr  */ 
  404.      Tcsum += sum_get ( 'T' , &len , 1 ) ;       /*  len   */ 
  405.  
  406.      chcon = convc2 ( Tcsum ) ;           /* put checksum in record   */ 
  407.      opbuf [ TRSUM  ]    = chcon >> 8 ; 
  408.      opbuf [ TRSUM + 1 ] = chcon & 0xFF ; 
  409.  
  410.  
  411.    /* -----------now build buffer ------------------------*/ 
  412.  
  413.    opbuf [0] = '/'                   ; 
  414.     
  415.  
  416.    chcon = convc2 ( len ) ; 
  417.    opbuf [TRLEN] = chcon >> 8 ; 
  418.    opbuf [TRLEN+1] = chcon & 0xFF ; 
  419.  
  420.    chcon = convc2 ( (int)(addr >> 8) ) ;           /* load addr - hi */ 
  421.    opbuf [TRADDR] = chcon >> 8 ; 
  422.    opbuf [TRADDR+1] = chcon & 0xFF ; 
  423.  
  424.    chcon = convc2 ( (int) addr ) ;                /* load addr - lo */ 
  425.    opbuf [TRADDR+2] = chcon >> 8 ; 
  426.    opbuf [TRADDR+3] = chcon & 0xFF ; 
  427.  
  428.  
  429.  
  430.    /* -----------now build buffer ------------------------*/ 
  431.  
  432.    Tcsum = 0 ;  
  433.  
  434.    for ( count = 0 , j = 0; count < len ; ++ count, j += 2 ) 
  435.                                                       /* now the data */ 
  436.      {  
  437.        ch = xgetc ( ) ;       
  438.        Tcsum += sum_get ( 'T' , &ch , 1 ) ;       /* accum c/sum   */ 
  439.        chcon = convc2 ( ch ) ; 
  440.  
  441.        opbuf [TRDATA +   j ] = chcon >> 8 ; 
  442.        opbuf [TRDATA+1 + j ] = chcon & 0xFF ; 
  443.      } 
  444.  
  445.   if ( len )                            /* last record , skip  (small fudge)*/ 
  446.    {    
  447.      chcon = convc2 ( Tcsum ) ;           /* checksum  */ 
  448.      opbuf [TRDATA +    j ] = chcon >> 8 ; 
  449.       opbuf [TRDATA + 1 +j ] = chcon & 0xFF ; 
  450.    } 
  451.   else 
  452.      j -= 2 ; 
  453.    return ( TRDATA + 2 + j ) ;     /* return length */ 
  454.  
  455.  
  456. /*************************************************************************** 
  457.  
  458.  
  459.   Function :     dll_Txrec 
  460.  
  461.  
  462.   Purpose  :     builds a TEKTRONIX - extended DLL record 
  463.  
  464.   Entry    : 
  465.  
  466.  
  467.   Returns  :     TRUE -  
  468.  
  469.                  FALSE-  
  470.  
  471.  
  472. ****************************************************************************/ 
  473.  
  474.  
  475. int  dll_Txrec ( tipe , addr ,  len ) 
  476.  
  477. int tipe , len ; 
  478. long addr ; 
  479.  
  480. int count , j , k; 
  481. uchar ch ; 
  482.  
  483. int nochars = 2*len +14 ;        /* chara count in record */ 
  484.  
  485.    opbuf [0] = '%'  ;            /* record header chara   */ 
  486.  
  487.    opbuf [ nochars + 2 ] = 0 ; 
  488.  
  489.     /*----------- record length (#of charas) -------------------------------*/ 
  490.     /* ( make addr field max of 8 charas ( 32 bit address )                 */ 
  491.  
  492.      chcon = convc2 ( nochars ) ;           /* put checksum in record   */ 
  493.      opbuf [ TRXLEN + 0 ]    = chcon >> 8 ; 
  494.      opbuf [ TRXLEN + 1 ]    = chcon & 0xFF ; 
  495.  
  496.     /*-------------- now the record type ------------------------------------*/ 
  497.  
  498.      opbuf [ TRXTYPE  ]    = tipe ; 
  499.      
  500.     /*--------------- now a fake csum ---------------------------------------*/ 
  501.  
  502.      opbuf [ TRXSUM ]    = '0' ; 
  503.      opbuf [ TRXSUM +1 ] = '0' ; 
  504.  
  505.     /*-------------- now the addr length ( 8 for now ) ----------------------*/ 
  506.  
  507.    opbuf [ TRXADDR ] = '8' ;                  /* # of charas   */ 
  508.  
  509.    count = addr >> 24 ;                        /* top 8 bits */ 
  510.    chcon = convc2 ( count ) ; 
  511.    opbuf [TRXADDR + 1 ]   = chcon >> 8 ; 
  512.    opbuf [TRXADDR + 2 ]   = chcon & 0xFF ; 
  513.  
  514.    count = addr >> 16 ;                       /*  next 8 bits */ 
  515.    chcon = convc2 ( count ) ; 
  516.    opbuf [TRXADDR + 3 ]   = chcon >> 8 ; 
  517.    opbuf [TRXADDR + 4 ]   = chcon & 0xFF ; 
  518.  
  519.    count = addr >> 8 ;                       /* next 8 bits */ 
  520.    chcon = convc2 ( count ) ; 
  521.    opbuf [TRXADDR + 5 ]   = chcon >> 8 ; 
  522.    opbuf [TRXADDR + 6 ]   = chcon & 0xFF ; 
  523.  
  524.    count = addr ;                            /* low 8 bits */ 
  525.    chcon = convc2 ( count ) ; 
  526.    opbuf [TRXADDR + 7 ]   = chcon >> 8 ; 
  527.    opbuf [TRXADDR + 8 ]   = chcon & 0xFF ; 
  528.  
  529.   /*-------------- now put data in buffer -----------------------------*/ 
  530.  
  531.    for ( count = 0 , j = 0; count < len ; ++ count, j += 2 ) 
  532.                                                       /* now the data */ 
  533.      {  
  534.        ch = xgetc ( ) ;       
  535.        chcon = convc2 ( ch ) ; 
  536.  
  537.        opbuf [TRXDATA +   j ] = chcon >> 8 ; 
  538.        opbuf [TRXDATA+1 + j ] = chcon & 0xFF ; 
  539.      } 
  540.  
  541.   /*----------------- now build and store checksum -----------------------*/ 
  542.  
  543.  
  544.    for ( count = 0 , k = 0 ; count < nochars ; ++count ) 
  545.      { 
  546.        if ( (j = get_hex (opbuf [count + 1])) == -1) 
  547.        { 
  548.              fprintf ( stderr , "dll_TXrec bad hex chara\n" ) ; 
  549.              fprintf ( stderr , opbuf ) ; 
  550.              exit ( 1 ) ; 
  551.            } 
  552.        k += j ;         /* accum checksum */ 
  553.      } 
  554.  
  555.        chcon = convc2 ( k ) ;              /* put in buffer  */ 
  556.   
  557.        opbuf [TRXSUM     ] = chcon >> 8 ; 
  558.        opbuf [TRXSUM + 1 ] = chcon & 0xFF ; 
  559.  
  560.  
  561.    return ( nochars + 1 ) ;     /* return length */ 
  562.  
  563.  
  564. /*************************************************************************** 
  565.  
  566.  
  567.   Function :     dll_Qrec 
  568.  
  569.  
  570.   Purpose  :     gen  a QTAM record 
  571.  
  572.   Entry    : 
  573.  
  574.   Returns  :     TRUE -  
  575.  
  576.                  FALSE- 
  577.  
  578.  
  579. ****************************************************************************/ 
  580.  
  581.  
  582. int  dll_Qrec ( tipe , addr ,  len ) 
  583.  
  584. int tipe , len ; 
  585. long addr ; 
  586.  
  587.  
  588. int count , j ; 
  589. uchar ch ; 
  590.  
  591.  
  592.    /* -----------now build buffer ------------------------*/ 
  593.  
  594.    opbuf [0] = 'Q'   ; 
  595.    opbuf [1] =  len  ; 
  596.  
  597.    opbuf [2] = addr >> 16 ; 
  598.    opbuf [3] = addr >> 8  ; 
  599.    opbuf [4] = addr  ; 
  600.  
  601.    for ( count = 0 ; count < len ; ++ count)  /* put data in buffer */  
  602.      { 
  603.        ch = xgetc ( )  ;        
  604.        opbuf [ 5 + count ] = ch ; 
  605.      } 
  606.  
  607.    for ( count = 0 , j = 0 ; count < (len + 4) ; ++ count )   /*  calc c/sum */ 
  608.       j += opbuf [ 1 + count] ; 
  609.  
  610.    opbuf [ 1 + count ] = - j  ;        /* put c/sum in buffer */ 
  611.     
  612.    return ( len + 6 ) ;                    /* return length */ 
  613.  
  614.  
  615.  
  616. /*************************************************************************** 
  617.  
  618.  
  619.   Function :       sum_get      
  620.  
  621.  
  622.   Purpose  :     Accumulates a checksum on a string 
  623.  
  624.   Entry    :     "I" / "T"  
  625.                  ptr to char string 
  626.                  length  
  627.  
  628.   Returns  :     uchar : checksum 
  629.  
  630.  
  631.  
  632. ****************************************************************************/ 
  633.  
  634.  
  635. int  sum_get  ( type , ptr , len ) 
  636.  
  637.  
  638. char *ptr ; 
  639. int type , len ; 
  640.  
  641. int csum  ; 
  642. int count ; 
  643.  
  644. switch ( type ) 
  645.   { 
  646.   case 'I' : 
  647.         
  648.        for (  count = 0 , csum = 0 ; count < len ; ++count , ++ptr ) 
  649.             csum +=  *ptr & 0xFF  ;               
  650.  
  651.        break ; 
  652.  
  653.      case 'T' : 
  654.         
  655.        for (  count = 0 , csum = 0 ; count < len ; ++count , ++ptr) 
  656.             csum +=  (*ptr & 0xF) + ((*ptr >> 4) & 0xF ) ;               
  657.  
  658.        break ; 
  659.  
  660.      } 
  661.  
  662.    return ( csum & 0xFF ) ; 
  663.  
  664. /*************************************************************************** 
  665.  
  666.  
  667.   Function :       xgetc      
  668.  
  669.  
  670.   Purpose  :       gets next chara from input buffer 
  671.  
  672.   Entry    : 
  673.  
  674.  
  675.   Returns  :     chara , or -1 ( empty ) 
  676.                  *ptr = addr 
  677.  
  678. ***************************************************************************/ 
  679.  
  680.  
  681. int xgetc (  ) 
  682.  
  683.  
  684. int ch , temp  ; 
  685. char *ptr = mallocptr ; 
  686.  
  687.     if ( !xccnt ) 
  688.       return -1 ;           /* empty */ 
  689.  
  690.     ch = xipbuf [xnrp].bite ;    /* get chara */     
  691.  
  692.     /* if mode 3 ( checksum gen ) , put byte in array */ 
  693.  
  694.     if ( xmode == 3 ) 
  695.       { 
  696.         if ( (temp = xipbuf[xnrp].addr) > 0xFFFF ) 
  697.            { 
  698.              fprintf ( stderr , "(xgetc) : addr > K64K !\n" ) ; 
  699.              exit (1) ; 
  700.            }  
  701.         ptr += temp ;         
  702.         *ptr = ch ;                  /* plant byte in array */     
  703.       } 
  704.  
  705.     --xccnt ; 
  706.     if ( ++xnrp == IPLEN ) 
  707.        xnrp = 0 ; 
  708.  
  709.     return ( ch & 0xFF ) ; 
  710.  
  711. /*************************************************************************** 
  712.  
  713.  
  714.   Function :       xputc      
  715.  
  716.  
  717.   Purpose  :       loads an addr/ data chara pair from DLL record to xipbuf 
  718.  
  719.  
  720.   Entry    : 
  721.  
  722.  
  723.   Returns  :     TRUE -  buffer not full 
  724.  
  725.                  FALSE-  buffer full 
  726.  
  727. ***************************************************************************/ 
  728.  
  729.  
  730.  
  731. int xputc ( addr , bite )  
  732.  
  733.  
  734. long addr ; 
  735. uchar bite ; 
  736.  
  737. {     
  738.       if ( csum > 255 ) 
  739.            csum = (++csum) & 0xFF ;    /* wrap prev carry  */ 
  740.   
  741.       csum +=  bite ;                /* accum checksum */ 
  742.  
  743.      xipbuf [xnwp].addr = addr ; 
  744.      xipbuf [xnwp++].bite = bite ; 
  745.  
  746.      if ( xnwp == IPLEN ) 
  747.        xnwp = 0 ; 
  748.  
  749.      if ( ++xccnt == IPLEN )       /* full check */ 
  750.         return ( FALSE ) ; 
  751.      else 
  752.         return ( TRUE ) ;     
  753.  
  754. /*************************************************************************** 
  755.  
  756.  
  757.   Function :      fill_ipbuf      
  758.  
  759.  
  760.   Purpose  :      fills up xipbuf with addr/data pairs made from DLL 
  761.                   file records 
  762.  
  763.   Entry    : 
  764.  
  765.  
  766.   Returns  :     TRUE - ip file not empty  
  767.  
  768.                  FALSE- ip fill now empty 
  769.  
  770. ***************************************************************************/ 
  771.  
  772.  
  773. int fill_ipbuf () 
  774.  
  775.  
  776.  while ( (xccnt < (IPLEN-300))  && xeof   ) 
  777.                    /* read DLL records until EOF or enough for o/p */ 
  778.    { 
  779.      switch ( ipftype ) 
  780.      { 
  781.        case 0 : 
  782.  
  783.          xeof = get_Irec () ;       /* get INTEL record -- deASCIIed */ 
  784.          break ; 
  785.   
  786.        case 1 :               /* MOTOROLA  */ 
  787.        case 2 : 
  788.        case 3 :   
  789.  
  790.           xeof =  get_Mrec()  ; 
  791.             break ; 
  792.  
  793.        case 4 :                   /* TEKTRONIX  */ 
  794.  
  795.           xeof = get_Trec () ; 
  796.           break ; 
  797.  
  798.        case 5 :                   /* TEKTRONIX - extended  */ 
  799.  
  800.           xeof = get_trec () ; 
  801.           break ; 
  802.  
  803.        case 6 :                   /* QTAM  */ 
  804.            
  805.           xeof = get_Qrec () ; 
  806.           break ; 
  807.  
  808.        }  ; 
  809.    } 
  810.  
  811. /*************************************************************************** 
  812.  
  813.  
  814.   Function :      get_len  
  815.  
  816.  
  817.   Purpose  :      scans i/p data buffer to see how many contiguous  
  818.                   bytes there are ( up to reclen ) 
  819.                   - does not allow overflow past K64K boundary if dest. 
  820.                     file is INTEL ( to allow type 2 tec gen. ) 
  821.   
  822.   Entry    : 
  823.  
  824.  
  825.   Returns  :      # of bytes 
  826.                   *ptr = addr field of start byte 
  827.  
  828. ***************************************************************************/ 
  829.  
  830. int  get_len ( aptr )  
  831.  
  832. long *aptr ; 
  833.  
  834. int count = 0 ; 
  835. long addr ; 
  836. int ptr ; 
  837.  
  838.  
  839.   ptr = xnrp ;                         /* scan from read ptr */ 
  840.        
  841.   addr = xipbuf [ptr].addr ; 
  842.   *aptr = addr ;                      /* hold start addr for external use   */ 
  843.   ousban= addr >> 16 ;            /* for INTEL , hold K64 seg # */  
  844.  
  845.   if ( !xccnt  )                      /* check odd conditions */ 
  846.      { 
  847.        *aptr = 0 ; 
  848.        return ( xccnt ) ; 
  849.      } 
  850.    else if ( xccnt == 1 ) 
  851.        return ( xccnt ) ; 
  852.  
  853.  
  854.   while ( count++ != xccnt )          /* read up to what's in buffer */ 
  855.     { 
  856.  
  857.       if ( ptr == IPLEN ) 
  858.          ptr = 0 ;                          /* wrap buffer ptr */ 
  859.  
  860.       if ( xipbuf [++ptr].addr != ++addr )  /* contiguous ? */ 
  861.      break ; 
  862.  
  863.      if ( count == reclen )             /* ( up to selected data length ) */ 
  864.          break ;  
  865.     
  866.      if ( !opftype ) 
  867.       { 
  868.         if (ousban != (addr >> 16) )  /* if INTEL check for K64 overflow */ 
  869.          break ;  
  870.       } 
  871.  
  872.    } 
  873.  
  874.   return ( count ) ; 
  875.  
  876.