home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / printer / epsonx / dospecial.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  8KB  |  238 lines

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