home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / epsonq / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  5.0 KB  |  210 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. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  27. char outputBuffer[];
  28. UWORD *command;
  29. BYTE *vline;
  30. BYTE *currentVMI;
  31. BYTE *crlfFlag;
  32. UBYTE Parms[];
  33. {
  34.     extern struct PrinterData *PD;
  35.  
  36.     int x = 0, y = 0;
  37.     /*
  38.         00-01    \0335        italics off
  39.         02-04    \033-\000    underline off
  40.         05-06    \033F        boldface off
  41.         07-08    \033P        elite off
  42.         09-09    \022        condensed fine off
  43.         10-12    \033W\000    enlarge off
  44.         13-14    \033H        double strike off
  45.         15-17    \033x\000    NLQ off
  46.         18-19    \033T        normalize the line
  47.         20-22    \033R\000    US char set
  48.         23-25    \033p0        proportional off
  49.         26-27    \0332        6 lpi
  50.         28-28    \015        carriage-return
  51.     */
  52.     static char initThisPrinter[29] =
  53.         {0x1b,'5',0x1b,'-',0xfe,0x1b,'F',0x1b,'P',0x12,0x1b,'W',0xfe,0x1b,'H',
  54.          0x1b,'x',0xfe,0x1b,'T',0x1b,'R',0xfe,0x1b,'p','0',0x1b,'2',0x0d};
  55.  
  56.     static char initMarg[] = {0xfd,0x1b,'l','L',0x1b,'Q','R',0xfd};
  57.  
  58.     static BYTE ISOcolorTable[] = {0, 5, 6, 4, 3, 1, 2, 0};
  59.  
  60.     if (*command == aRIN) { /* initialize */
  61.         while(x < 29) {
  62.             if ((outputBuffer[x] = initThisPrinter[x]) == -2) {
  63.                 outputBuffer[x] = 0;
  64.             }
  65.             x++;
  66.         }
  67.  
  68.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  69.             outputBuffer[17] = 1;
  70.         }
  71.  
  72.         *currentVMI = 30; /* assume 1/6 line spacing */
  73.         if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  74.             outputBuffer[27] = '0';
  75.             *currentVMI = 22;
  76.         }
  77.  
  78.         if (PD->pd_Preferences.PrintPitch == ELITE) {
  79.             outputBuffer[8] = 'M';
  80.         }
  81.         else if (PD->pd_Preferences.PrintPitch == FINE) {
  82.             outputBuffer[9] = 15;
  83.         }
  84.  
  85.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  86.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  87.         *command=aSLRM;
  88.     }
  89.  
  90.     if (*command == aCAM) { /* cancel margins */
  91.         y = PD->pd_Preferences.PaperSize == W_TRACTOR ? 136 : 80;
  92.         if (PD->pd_Preferences.PrintPitch == PICA) {
  93.             Parms[1] = (10 * y) / 10;
  94.         }
  95.         else if (PD->pd_Preferences.PrintPitch == ELITE) {
  96.             Parms[1] = (12 * y) / 10;
  97.         }
  98.         else { /* fine */
  99.             Parms[1] = (17 * y) / 10;
  100.         }
  101.         Parms[0] = 1;
  102.         y = 0;
  103.         *command = aSLRM;
  104.     }
  105.  
  106.     if (*command == aSLRM) { /* set left&right margins */
  107.         PD->pd_PWaitEnabled = 253; /* wait after this character */
  108.         if (Parms[0] == 0) {
  109.             initMarg[3] = 0;
  110.         }
  111.         else {
  112.             initMarg[3] = Parms[0] - 1;
  113.         }
  114.         initMarg[6] = Parms[1];
  115.         while (y < 8) {
  116.             outputBuffer[x++] = initMarg[y++];
  117.         }
  118.         return(x);
  119.     }
  120.  
  121.     if (*command == aPLU) { /* partial line up */
  122.         if (*vline == 0) {
  123.             *vline = 1;
  124.             *command = aSUS2;
  125.             return(0);
  126.         }
  127.         if (*vline < 0) {
  128.             *vline = 0;
  129.             *command = aSUS3;
  130.             return(0);
  131.         }
  132.         return(-1);
  133.     }
  134.  
  135.     if (*command == aPLD) { /* partial line down */
  136.         if (*vline == 0) {
  137.             *vline = -1;
  138.             *command = aSUS4;
  139.             return(0);
  140.         }
  141.         if (*vline > 0) {
  142.             *vline = 0;
  143.             *command = aSUS1;
  144.             return(0);
  145.         }
  146.         return(-1);
  147.     }
  148.  
  149.     if (*command == aSUS0) { /* normalize the line */
  150.         *vline = 0;
  151.     }
  152.  
  153.     if (*command == aSUS1) { /* superscript off */
  154.         *vline = 0;
  155.     }
  156.  
  157.     if (*command == aSUS2) { /* superscript on */
  158.         *vline = 1;
  159.     }
  160.  
  161.     if (*command == aSUS3) { /* subscript off */
  162.         *vline = 0;
  163.     }
  164.  
  165.     if (*command == aSUS4) { /* subscript on */
  166.         *vline = -1;
  167.     }
  168.  
  169.     if (*command == aVERP0) { /* 8 LPI */
  170.         *currentVMI = 22;
  171.     }
  172.  
  173.     if (*command == aVERP1) { /* 6 LPI */
  174.         *currentVMI = 30;
  175.     }
  176.  
  177.     if (*command == aSFC) { /* set foreground/background color */
  178.         if (Parms[0] == 39) {
  179.             Parms[0] = 30; /* set default (black) */
  180.         }
  181.         if (Parms[0] > 37) {
  182.             return(0); /* ni or background color change */
  183.         }
  184.         outputBuffer[x++] = 27;
  185.         outputBuffer[x++] = 'r';
  186.         outputBuffer[x++] = ISOcolorTable[Parms[0] - 30];
  187.         return(x);
  188.     }
  189.  
  190.     if (*command == aSLPP) { /* set form length */
  191.         outputBuffer[x++] = 27;
  192.         outputBuffer[x++] = 'C';
  193.         outputBuffer[x++] = Parms[0];
  194.         return(x);
  195.     }
  196.  
  197.     if (*command == aPERF) { /* perf skip n */
  198.         outputBuffer[x++] = 27;
  199.         outputBuffer[x++] = 'N';
  200.         outputBuffer[x++] = Parms[0];
  201.         return(x);
  202.     }
  203.  
  204.     if (*command == aRIS) { /* reset */
  205.         PD->pd_PWaitEnabled = 253;
  206.     }
  207.  
  208.     return(0);
  209. }
  210.