home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d165 / plotview.lha / PlotView / Plot2Tek / encode.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  1KB  |  89 lines

  1. #include "4107.h"
  2.  
  3. /*
  4.  * Convert xy pair to terminal encoded syntax.
  5.  */
  6. encode_xy(x,y)
  7.     register long x,y;
  8. {
  9.     static    lasthix = 0xfff,
  10.         lasthiy = 0xfff,
  11.         lastloy = 0xfff,
  12.         lastext = 0xfff;
  13.     int    hix, lox, hiy, loy, ext;
  14.  
  15.     if (x < 0)        x = 0;
  16.     else if (x >= 4096)    x = 4096 - 1;
  17.     if (y < 0)        y = 0;
  18.     else if (y >= 3133)    y = 3133 - 1;
  19.  
  20.     hix = x & 0xf80;
  21.     lox = x & 0x07c;
  22.     hiy = y & 0xf80;
  23.     loy = y & 0x07c;
  24.     ext = ((y & 0x03) << 2) | (x & 0x03);
  25.  
  26.     putchar( (hiy >> 7) | 0x20 );
  27.     putchar( ext | 0x60 );
  28.     putchar( (loy >> 2) | 0x60 );
  29.     putchar( (hix >> 7) | 0x20 );
  30.     putchar( (lox >> 2) | 0x40 );
  31. }
  32.  
  33. /*
  34.  * Convert integer parameter to terminal syntax.
  35.  */
  36. encode(i)
  37.     register long i;
  38. {
  39.     char    buffer[50];
  40.     register char    *bp = &buffer[49];
  41.  
  42.     *bp-- = '\0';
  43.     if (i < 0) {
  44.         i = -i;
  45.         *bp-- = (i & 0xf) | 0x20;
  46.     } else {
  47.         *bp-- = (i & 0xf) | 0x30;
  48.     }
  49.  
  50.     i >>= 4;
  51.     while (i > 0) {
  52.         *bp-- = (i & 0x3f) | 0x40;
  53.         i >>= 6;
  54.     }
  55.     while (*++bp)
  56.         putchar(*bp);
  57.  
  58. }
  59. /* 
  60.  *  Encode a string into an integer array
  61.  */
  62. encode_str(str)
  63. /* requires a variable length string terminated with \0 */
  64. /* encode(-135, "l")  */
  65.     char str[1];
  66. {
  67.     register i;
  68.     encode(strlen(str));
  69.     for (i=0 ; i<strlen(str); i++)
  70.     encode(str[i]);
  71. }
  72.  
  73. /*
  74.  * Decode integer report parm to binary integer.
  75.  *    input = 3 char integer report.
  76.  *    returns binary integer
  77.  */
  78.  
  79. long
  80. decode_int(parm)
  81. char *parm;
  82. {
  83.     long i;
  84.     i = ((int) parm[0] -32) * 1024;
  85.     i += ((int) parm[1] -32) * 16;
  86.     i += ((int) parm[2] -32) % 16;
  87.     return (i);
  88. }
  89.