home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / xerox / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  6.0 KB  |  250 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 PITCH        4
  27. #define    QUALITY        9
  28. #define INITLEN        16
  29.  
  30. #define TABLEN        34
  31.  
  32. #define PITCHMARG    2
  33. #define LMARG        5
  34. #define RMARG        11
  35. #define MARGLEN        15
  36. /*
  37.     00-02    \033F0        - assure correct pitch        PMARG
  38.     03-08    \033l000\015    - set left margin to '000'    LMARG
  39.     09-14    \033r000\015    - set right margin to '000'    RMARG
  40. */
  41. UBYTE MargBuf[MARGLEN] = 
  42.     {0x1b,'F','0',0x1b,'l','0','0','0',0x0d,0x1b,'r','0','0','0',0x0d};
  43. UBYTE pitch;
  44.  
  45. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  46. char outputBuffer[];
  47. UWORD *command;
  48. BYTE *vline;
  49. UBYTE *currentVMI; /* used for color on this printer */
  50. BYTE *crlfFlag;
  51. UBYTE Parms[];
  52. {
  53.     extern struct PrinterData *PD;
  54.  
  55.     int x = 0, y= 0;
  56.     static BYTE ISOcolorTable[10] =
  57.         {49, 51, 53, 52, 55, 50, 54, 48, 49, 49};
  58.     /*       K   R   G   Y   B   M   C   W   K   K */
  59.  
  60.     /*
  61.         00-01    \033R    - underline off
  62.         02-04    \033F0    - 10 cpi            PITCH
  63.         05-06    \033&    - enlarge off
  64.         07-09    \033wb    - nlq off            QUALITY
  65.         10-11    \033s    - super/sub script off
  66.         12-14    \033we    - standard graphics mode
  67.         15-15    \015    - carriage return
  68.     */
  69.     static char initThisPrinter[INITLEN] =
  70. {0x1b,'R',0x1b,'F','0',0x1b,'&',0x1b,'w','b',0x1b,'s',0x1b,'w','e',0x0d};
  71.  
  72.     static unsigned char initTabs[TABLEN] =
  73. {0x1b,'i','9',' ','1','7',' ','2','5',' ','3','3',' ','4','1',' ','4','9',
  74.  ' ','5','7','6','5',' ','7','3',' ','8','1',' ','8','9',0x0d};
  75.  
  76.  
  77.     if (*command == aRIN) {
  78.         while(x < INITLEN) {
  79.             outputBuffer[x] = initThisPrinter[x];
  80.             x++;
  81.         }
  82.         while (y < TABLEN) {
  83.             outputBuffer[x++] = initTabs[y++];
  84.         }
  85.         y = 0;
  86.  
  87.         *currentVMI = 0x70; /* white background, black text */
  88.  
  89.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  90.             outputBuffer[QUALITY] = 'a';
  91.         }
  92.  
  93.         if (PD->pd_Preferences.PrintPitch == PICA) {
  94.             pitch = 10;
  95.             outputBuffer[PITCH] = '0';
  96.         }
  97.         else if (PD->pd_Preferences.PrintPitch == ELITE) {
  98.             pitch = 12;
  99.             outputBuffer[PITCH] = '2';
  100.         }
  101.         else { /* FINE */
  102.             pitch = 17;
  103.             outputBuffer[PITCH] = '4';
  104.         }
  105.  
  106.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  107.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  108.         *command = aSLRM;
  109.     }
  110.  
  111.     if (*command == aCAM) {
  112.         Parms[0] = 1;
  113.         Parms[1] = (95 * 17 + 5) / 10; /* max is 9.5 inches @ 17 cpi */
  114.         *command = aSLRM;
  115.     }
  116.  
  117.     if (*command == aSLRM) {
  118.         CalcMarg(Parms[0], Parms[1]);
  119.         while (y < MARGLEN) {
  120.             outputBuffer[x++] = MargBuf[y++];
  121.         }
  122.         return(x);
  123.     }
  124.  
  125.     /* normal pitch, or elite off, or condensed off, or normal char set */
  126.     if (*command == aSHORP0 || *command == aSHORP1 || *command == aSHORP3
  127.         || *command == aSGR0) {
  128.         pitch = 10;
  129.     }
  130.     else if (*command == aSHORP2) { /* elite on */
  131.         pitch = 12;
  132.     }
  133.     else if (*command == aSHORP4) { /* fine on */
  134.         pitch = 17;
  135.     }
  136.  
  137.     if (*command == aSFC) { /* set foreground/background color */
  138.         if (Parms[0] == 39) {
  139.             Parms[0] = 30; /* set defaults */
  140.         }
  141.         if (Parms[0] == 49) {
  142.             Parms[0] = 47;
  143.         }
  144.         if (Parms[0] < 40) {
  145.             *currentVMI = (*currentVMI & 240) + (Parms[0] - 30);
  146.         }
  147.         else {
  148.             *currentVMI = (*currentVMI & 15) + (Parms[0] - 40) *
  149.                 16;
  150.         }
  151.         outputBuffer[x++] = '\033';
  152.         outputBuffer[x++] = '@';
  153.         outputBuffer[x++] = ISOcolorTable[*currentVMI & 15];
  154.         outputBuffer[x++] = ISOcolorTable[(*currentVMI & 240) / 16];
  155.         return(x);
  156.     }
  157.  
  158.     if (*command == aPLU) {
  159.         if (*vline == 0) {
  160.             *vline = 1;
  161.             *command = aSUS2;
  162.             return(0);
  163.         }
  164.         if (*vline < 0) {
  165.             *vline = 0;
  166.             *command = aSUS3;
  167.             return(0);
  168.         }
  169.         return(-1);
  170.     }
  171.  
  172.     if (*command == aPLD) {
  173.         if (*vline == 0) {
  174.             *vline = -1;
  175.             *command = aSUS4;
  176.             return(0);
  177.         }
  178.         if (*vline > 0) {
  179.             *vline = 0;
  180.             *command = aSUS1;
  181.             return(0);
  182.         }
  183.         return(-1);
  184.     }
  185.  
  186.     if (*command == aSUS0) {
  187.         *vline = 0;
  188.     }
  189.     if (*command == aSUS1) {
  190.         *vline = 0;
  191.     }
  192.     if (*command == aSUS2) {
  193.         *vline = 1;
  194.     }
  195.     if (*command == aSUS3) {
  196.         *vline = 0;
  197.     }
  198.     if (*command == aSUS4) {
  199.         *vline = -1;
  200.     }
  201.  
  202.     if (*command == aRIS) {
  203.         PD->pd_PWaitEnabled = 253;
  204.         pitch = 10;
  205.     }
  206.  
  207.     return(0);
  208. }
  209.  
  210. CalcMarg(left, right)
  211. int left, right;
  212. {
  213.     int i, offset, max;
  214.  
  215.     /*
  216.         The minimum left margin on the Xerox_4020 is .5 inches.  Thus
  217.         a left margin of 1 (ie. no left margin) is ...
  218.         5/10 => .5, 6/12 => .5, 8.5/17 => .5
  219.         The maximum print width is 9.5 inches.
  220.     */
  221.     if (pitch == 10) { /* PICA */
  222.         MargBuf[PITCHMARG] = '0';
  223.         offset = 40;
  224.         max = (95 * 10 + 5) / 10;
  225.     }
  226.     else if (pitch == 12) { /* ELITE */
  227.         MargBuf[PITCHMARG] = '2';
  228.         offset = 50;
  229.         max = (95 * 12 + 5) / 10;
  230.     }
  231.     else { /* FINE */
  232.         MargBuf[PITCHMARG] = '4';
  233.         offset = 75;
  234.         max = (95 * 17 + 5) / 10;
  235.     }
  236.     if ((i = (left * 10 + offset + 5) / 10) > max) {
  237.         i = max;
  238.     }
  239.     MargBuf[LMARG] = ((i % 1000) / 100) + '0';
  240.     MargBuf[LMARG + 1] = ((i % 100) / 10) + '0';
  241.     MargBuf[LMARG + 2] = (i % 10) + '0';
  242.     if ((i = (right * 10 + offset + 15) / 10) > max) {
  243.         i = max;
  244.     }
  245.     MargBuf[RMARG] = ((i % 1000) / 100) + '0';
  246.     MargBuf[RMARG + 1] = ((i % 100) / 10) + '0';
  247.     MargBuf[RMARG + 2] = (i % 10) + '0';
  248.     return(MARGLEN);
  249. }
  250.