home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / epsonx_dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  6.7 KB  |  218 lines

  1. /*
  2.         DoSpecial for EpsonX driver.
  3. */
  4.  
  5. #include "exec/types.h"
  6. #include "devices/printer.h"
  7. #include "devices/prtbase.h"
  8.  
  9. #define LMARG   3
  10. #define RMARG   6
  11. #define MARGLEN 8
  12.  
  13. #define CONDENSED       7
  14. #define PITCH           9
  15. #define QUALITY         17
  16. #define LPI             24
  17. #define INITLEN         26
  18.  
  19. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  20. char outputBuffer[];
  21. UWORD *command;
  22. BYTE *vline;
  23. BYTE *currentVMI;
  24. BYTE *crlfFlag;
  25. UBYTE Parms[];
  26. {
  27.         extern struct PrinterData *PD;
  28.  
  29.         int x = 0, y = 0;
  30.         /*
  31.                 00-00   \375    wait
  32.                 01-03   \033lL  set left margin
  33.                 04-06   \033Qq  set right margin
  34.                 07-07   \375    wait
  35.         */
  36.  
  37.         static char initMarg[MARGLEN+1] = "\375\033lL\033Qq\375";
  38.         /*
  39.                 00-01   \0335           italics off
  40.                 02-04   \033-\000       underline off
  41.                 05-06   \033F           boldface off
  42.                 07-07   \022            cancel condensed mode
  43.                 08-09   \033P           select pica (10 cpi)
  44.                 10-12   \033W\000       enlarge off
  45.                 13-14   \033H           doublestrike off
  46.                 15-17   \033x\000       draft
  47.                 18-19   \033T           super/sub script off
  48.                 20-22   \033p0          proportional off
  49.                 23-24   \0332           6 lpi
  50.                 25-25   \015            carriage return
  51.         */
  52.         static char initThisPrinter[INITLEN+1] =
  53.         "\0335\033-\000\033F\022\033P\033W\000\033H\033x\000\033T\033p0\0332\015";
  54.  
  55.         static BYTE ISOcolorTable[10] = {0, 5, 6, 4, 3, 1, 2, 0};
  56.  
  57.         if (*command == aRIN) {
  58.                 while (x < INITLEN) {
  59.                         outputBuffer[x] = initThisPrinter[x];
  60.                         x++;
  61.                 }
  62.  
  63.                 if (PD->pd_Preferences.PrintQuality == LETTER) {
  64.                         outputBuffer[QUALITY] = 1;
  65.                 }
  66.  
  67.                 *currentVMI = 36; /* assume 1/6 line spacing (36/216 => 1/6) */
  68.                 if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  69.                         outputBuffer[LPI] = '0';
  70.                         *currentVMI = 27; /* 27/216 => 1/8 */
  71.                 }
  72.  
  73.                 if (PD->pd_Preferences.PrintPitch == ELITE) {
  74.                         outputBuffer[PITCH] = 'M';
  75.                 }
  76.                 else if (PD->pd_Preferences.PrintPitch == FINE) {
  77.                         outputBuffer[CONDENSED] = '\017'; /* condensed */
  78.                         outputBuffer[PITCH] = 'P'; /* pica condensed */
  79.                 }
  80.  
  81.                 Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  82.                 Parms[1] = PD->pd_Preferences.PrintRightMargin;
  83.                 *command = aSLRM;
  84.         }
  85.  
  86.         if (*command == aCAM) { /* cancel margins */
  87.                 y = PD->pd_Preferences.PaperSize == W_TRACTOR ? 136 : 80;
  88.                 if (PD->pd_Preferences.PrintPitch == PICA) {
  89.                         Parms[1] = (10 * y) / 10;
  90.                 }
  91.                 else if (PD->pd_Preferences.PrintPitch == ELITE) {
  92.                         Parms[1] = (12 * y) / 10;
  93.                 }
  94.                 else { /* fine */
  95.                         Parms[1] = (17 * y) / 10;
  96.                 }
  97.                 Parms[0] = 1;
  98.                 y = 0;
  99.                 *command = aSLRM;
  100.         }
  101.  
  102.         if (*command == aSLRM) { /* set left and right margins */
  103.                 PD->pd_PWaitEnabled = 253;
  104.                 if (Parms[0] == 0) {
  105.                         initMarg[LMARG] = 0;
  106.                 }
  107.                 else {
  108.                         initMarg[LMARG] = Parms[0] - 1;
  109.                 }
  110.                 initMarg[RMARG] = Parms[1];
  111.                 while (y < MARGLEN) {
  112.                         outputBuffer[x++] = initMarg[y++];
  113.                 }
  114.                 return(x);
  115.         }
  116.  
  117.         if (*command == aPLU) {
  118.                 if (*vline == 0) {
  119.                         *vline = 1;
  120.                         *command = aSUS2;
  121.                         return(0);
  122.                 }
  123.                 if (*vline < 0) {
  124.                         *vline = 0;
  125.                         *command = aSUS3;
  126.                         return(0);
  127.                 }
  128.                 return(-1);
  129.         }
  130.  
  131.         if (*command == aPLD) {
  132.                 if (*vline == 0) {
  133.                         *vline = -1;
  134.                         *command = aSUS4;
  135.                         return(0);
  136.                 }
  137.                 if (*vline > 0) {
  138.                         *vline = 0;
  139.                         *command = aSUS1;
  140.                         return(0);
  141.                 }
  142.                 return(-1);
  143.         }
  144.  
  145.         if (*command == aSUS0) {
  146.                 *vline = 0;
  147.         }
  148.  
  149.         if (*command == aSUS1) {
  150.                 *vline = 0;
  151.         }
  152.  
  153.         if (*command == aSUS2) {
  154.                 *vline = 1;
  155.         }
  156.  
  157.         if (*command == aSUS3) {
  158.                 *vline = 0;
  159.         }
  160.  
  161.         if (*command == aSUS4) {
  162.                 *vline = -1;
  163.         }
  164.  
  165.         if (*command == aVERP0) {
  166.                 *currentVMI = 27;
  167.         }
  168.  
  169.         if (*command == aVERP1) {
  170.                 *currentVMI = 36;
  171.         }
  172.  
  173.         if (*command == aIND) { /* lf */
  174.                 outputBuffer[x++] = '\033';
  175.                 outputBuffer[x++] = 'J';
  176.                 outputBuffer[x++] = *currentVMI;
  177.                 return(x);
  178.         }
  179.  
  180.         if (*command == aRI) { /* reverse lf */
  181.                 outputBuffer[x++] = '\033';
  182.                 outputBuffer[x++] = 'j';
  183.                 outputBuffer[x++] = *currentVMI;
  184.                 return(x);
  185.         }
  186.  
  187.         if (*command == aSFC) {
  188.                 if (Parms[0] == 39) {
  189.                         Parms[0] = 30; /* set defaults */
  190.                 }
  191.                 if (Parms[0] > 37) {
  192.                         return(0); /* ni or background color change */
  193.                 }
  194.                 outputBuffer[x++] = '\033';
  195.                 outputBuffer[x++] = 'r';
  196.                 outputBuffer[x++] = ISOcolorTable[Parms[0] - 30];
  197.                 /*
  198.                 Kludge to get this to work on a CBM_MPS-1250  which interprets
  199.                 'ESCr' as go into reverse print mode.  The 'ESCt' tells it to
  200.                 get out of reverse print mode.  The 'NULL' is ignored by the
  201.                 CBM_MPS-1250 and required by all Epson printers as the
  202.                 terminator for the 'ESCtNULL' command which means select
  203.                 normal char set (which has no effect).
  204.                 */
  205.                 outputBuffer[x++] = '\033';
  206.                 outputBuffer[x++] = 't';
  207.                 outputBuffer[x++] = 0;
  208.                 return(x);
  209.         }
  210.  
  211.         if (*command == aRIS) {
  212.                 PD->pd_PWaitEnabled = 253;
  213.         }
  214.  
  215.         return(0);
  216. }
  217.  
  218.