home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / epsonx / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  5.5 KB  |  230 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. #include <exec/types.h>
  23. #include <devices/printer.h>
  24. #include <devices/prtbase.h>
  25.  
  26. #define LMARG    3
  27. #define RMARG    6
  28. #define MARGLEN    8
  29.  
  30. #define CONDENSED    7
  31. #define PITCH        9
  32. #define QUALITY        17
  33. #define LPI        24
  34. #define INITLEN        26
  35.  
  36. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  37. char outputBuffer[];
  38. UWORD *command;
  39. BYTE *vline;
  40. BYTE *currentVMI;
  41. BYTE *crlfFlag;
  42. UBYTE Parms[];
  43. {
  44.     extern struct PrinterData *PD;
  45.  
  46.     int x = 0, y = 0;
  47.     /*
  48.         00-00    \375    wait
  49.         01-03    \033lL    set left margin
  50.         04-06    \033Qq    set right margin
  51.         07-07    \375    wait
  52.     */
  53.         static char initMarg[MARGLEN] = {0xfd,0x1b,'l','L',0x1b,'Q','q',0xfd}; 
  54.     /*
  55.         00-01    \0335        italics off
  56.         02-04    \033-\000    underline off
  57.         05-06    \033F        boldface off
  58.         07-07    \022        cancel condensed mode
  59.         08-09    \033P        select pica (10 cpi)
  60.         10-12    \033W\000    enlarge off
  61.         13-14    \033H        doublestrike off
  62.         15-17    \033x\000    draft
  63.         18-19    \033T        super/sub script off
  64.         20-22    \033p0        proportional off
  65.         23-24    \0332        6 lpi
  66.         25-25    \015        carriage return
  67.     */
  68.  
  69.         static char initThisPrinter[INITLEN] = 
  70. {0x1b,0x05,0x1b,'-',0x0,0x1b,'F',0x12,0x1b,'P',0x1b,'W',0x0,0x1b,'H',
  71.  0x1b,'x',0x0,0x1b,'T',0x1b,'p',0x0,0x1b,0x02,0x0d};
  72.     static BYTE ISOcolorTable[10] = {0, 5, 6, 4, 3, 1, 2, 0};
  73.  
  74.     if (*command == aRIN) {
  75.         while (x < INITLEN) {
  76.             outputBuffer[x] = initThisPrinter[x];
  77.             x++;
  78.         }
  79.  
  80.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  81.             outputBuffer[QUALITY] = 1;
  82.         }
  83.  
  84.         *currentVMI = 36; /* assume 1/6 line spacing (36/216 => 1/6) */
  85.         if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  86.             outputBuffer[LPI] = '0';
  87.             *currentVMI = 27; /* 27/216 => 1/8 */
  88.         }
  89.  
  90.         if (PD->pd_Preferences.PrintPitch == ELITE) {
  91.             outputBuffer[PITCH] = 'M';
  92.         }
  93.         else if (PD->pd_Preferences.PrintPitch == FINE) {
  94.             outputBuffer[CONDENSED] = '\017'; /* condensed */
  95.             outputBuffer[PITCH] = 'P'; /* pica condensed */
  96.         }
  97.  
  98.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  99.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  100.         *command = aSLRM;
  101.     }
  102.  
  103.     if (*command == aCAM) { /* cancel margins */
  104.         y = PD->pd_Preferences.PaperSize == W_TRACTOR ? 136 : 80;
  105.         if (PD->pd_Preferences.PrintPitch == PICA) {
  106.             Parms[1] = (10 * y) / 10;
  107.         }
  108.         else if (PD->pd_Preferences.PrintPitch == ELITE) {
  109.             Parms[1] = (12 * y) / 10;
  110.         }
  111.         else { /* fine */
  112.             Parms[1] = (17 * y) / 10;
  113.         }
  114.         Parms[0] = 1;
  115.         y = 0;
  116.         *command = aSLRM;
  117.     }
  118.  
  119.     if (*command == aSLRM) { /* set left and right margins */
  120.         PD->pd_PWaitEnabled = 253;
  121.         if (Parms[0] == 0) {
  122.             initMarg[LMARG] = 0;
  123.         }
  124.         else {
  125.             initMarg[LMARG] = Parms[0] - 1;
  126.         }
  127.         initMarg[RMARG] = Parms[1];
  128.         while (y < MARGLEN) {
  129.             outputBuffer[x++] = initMarg[y++];
  130.         }
  131.         return(x);
  132.     }
  133.  
  134.     if (*command == aPLU) {
  135.         if (*vline == 0) {
  136.             *vline = 1;
  137.             *command = aSUS2;
  138.             return(0);
  139.         }
  140.         if (*vline < 0) {
  141.             *vline = 0;
  142.             *command = aSUS3;
  143.             return(0);
  144.         }
  145.         return(-1);
  146.     }
  147.  
  148.     if (*command == aPLD) {
  149.         if (*vline == 0) {
  150.             *vline = -1;
  151.             *command = aSUS4;
  152.             return(0);
  153.         }
  154.         if (*vline > 0) {
  155.             *vline = 0;
  156.             *command = aSUS1;
  157.             return(0);
  158.         }
  159.         return(-1);
  160.     }
  161.  
  162.     if (*command == aSUS0) {
  163.         *vline = 0;
  164.     }
  165.     if (*command == aSUS1) {
  166.         *vline = 0;
  167.     }
  168.     if (*command == aSUS2) {
  169.         *vline = 1;
  170.     }
  171.     if (*command == aSUS3) {
  172.         *vline = 0;
  173.     }
  174.     if (*command == aSUS4) {
  175.         *vline = -1;
  176.     }
  177.  
  178.     if (*command == aVERP0) {
  179.         *currentVMI = 27;
  180.     }
  181.  
  182.     if (*command == aVERP1) {
  183.         *currentVMI = 36;
  184.     }
  185.  
  186.     if (*command == aIND) { /* lf */
  187.         outputBuffer[x++] = '\033';
  188.         outputBuffer[x++] = 'J';
  189.         outputBuffer[x++] = *currentVMI;
  190.         return(x);
  191.     }
  192.  
  193.     if (*command == aRI) { /* reverse lf */
  194.         outputBuffer[x++] = '\033';
  195.         outputBuffer[x++] = 'j';
  196.         outputBuffer[x++] = *currentVMI;
  197.         return(x);
  198.     }
  199.  
  200.     if (*command == aSFC) {
  201.         if (Parms[0] == 39) {
  202.             Parms[0] = 30; /* set defaults */
  203.         }
  204.         if (Parms[0] > 37) {
  205.             return(0); /* ni or background color change */
  206.         }
  207.         outputBuffer[x++] = '\033';
  208.         outputBuffer[x++] = 'r';
  209.         outputBuffer[x++] = ISOcolorTable[Parms[0] - 30];
  210.         /*
  211.         Kludge to get this to work on a CBM_MPS-1250  which interprets
  212.         'ESCr' as go into reverse print mode.  The 'ESCt' tells it to
  213.         get out of reverse print mode.  The 'NULL' is ignored by the
  214.         CBM_MPS-1250 and required by all Epson printers as the
  215.         terminator for the 'ESCtNULL' command which means select
  216.         normal char set (which has no effect).
  217.         */
  218.         outputBuffer[x++] = '\033';
  219.         outputBuffer[x++] = 't';
  220.         outputBuffer[x++] = 0;
  221.         return(x);
  222.     }
  223.  
  224.     if (*command == aRIS) {
  225.         PD->pd_PWaitEnabled = 253;
  226.     }
  227.  
  228.     return(0);
  229. }
  230.