home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / Printer / src / HP / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.6 KB  |  242 lines

  1. /*
  2.     DoSpecial for HP_LaserJet driver.
  3.     David Berezowski - March/88.
  4.  
  5.   Copyright (c) 1988 Commodore-Amiga, Inc.
  6.  
  7.   Executables based on this information may be used in software
  8.   for Commodore Amiga computers.  All other rights reserved.
  9.  
  10.   This information is provided "as is"; no warranties are made.
  11.   All use is at your own risk, and no liability or responsibility is assumed.
  12. */
  13.  
  14.  
  15. #include "exec/types.h"
  16. #include "../printer/printer.h"
  17. #include "../printer/prtbase.h"
  18.  
  19. #define LPI        7
  20. #define CPI        15
  21. #define QUALITY        17
  22. #define INIT_LEN    30
  23. #define LPP        7
  24. #define FORM_LEN    11
  25. #define LEFT_MARG    3
  26. #define RIGHT_MARG    7
  27. #define MARG_LEN    12
  28.  
  29. DoSpecial(command, outputBuffer, vline, currentVMI, crlfFlag, Parms)
  30. char outputBuffer[];
  31. UWORD *command;
  32. BYTE *vline;
  33. BYTE *currentVMI;
  34. BYTE *crlfFlag;
  35. UBYTE Parms[];
  36. {
  37.     extern struct PrinterData *PD;
  38.     extern struct PrinterExtendedData *PED;
  39.  
  40.     UWORD textlength, topmargin;
  41.     int x, y, j;
  42.     static char initThisPrinter[INIT_LEN] =
  43.         "\033&d@\033&l6D\033(s0b10h1q0p0s3t0u12V";
  44.     static char initForm[FORM_LEN] = "\033&l002e000F";
  45.     static char initMarg[MARG_LEN] = "\033&a000l000M\015";
  46.     static char initTMarg[] = "\033&l000e000F";
  47.  
  48.     x = y = j = 0;
  49.  
  50.     if (*command == aRIN) {
  51.         while(x < INIT_LEN) {
  52.             outputBuffer[x] = initThisPrinter[x];
  53.             x++;
  54.         }
  55.         outputBuffer[x++] = '\015';
  56.  
  57.         if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  58.             outputBuffer[LPI] = '8';
  59.         }
  60.  
  61.         if (PD->pd_Preferences.PrintPitch == ELITE) {
  62.             outputBuffer[CPI] = '2';
  63.         }
  64.         else if (PD->pd_Preferences.PrintPitch == FINE) {
  65.             outputBuffer[CPI] = '5';
  66.         }
  67.  
  68.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  69.             outputBuffer[QUALITY] = '2';
  70.         }
  71.  
  72.         j = x; /* set the formlength = textlength, top margin = 2 */
  73.         textlength = PD->pd_Preferences.PaperLength;
  74.         topmargin = 2;
  75.  
  76.         while (y < FORM_LEN) {
  77.             outputBuffer[x++] = initForm[y++];
  78.         }
  79.         numberString(textlength, j + LPP, outputBuffer);
  80.  
  81.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  82.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  83.         *command = aSLRM;
  84.     }
  85.  
  86.     if (*command == aSLRM) {
  87.         j = x;
  88.         y = 0;
  89.         while(y < MARG_LEN) {
  90.             outputBuffer[x++] = initMarg[y++];
  91.         }
  92.         numberString(Parms[0] - 1, j + LEFT_MARG, outputBuffer);
  93.         numberString(Parms[1] - 1, j + RIGHT_MARG, outputBuffer);
  94.         return(x);
  95.     }
  96.  
  97.     if ((*command == aSUS2) && (*vline == 0)) {
  98.         *command = aPLU;
  99.         *vline = 1;
  100.         return(0);
  101.     }
  102.  
  103.     if ((*command == aSUS2) && (*vline < 0)) {
  104.         *command = aRI;
  105.         *vline = 1;
  106.         return(0);
  107.     }
  108.  
  109.     if ((*command == aSUS1) && (*vline > 0)) {
  110.         *command = aPLD;
  111.         *vline = 0;
  112.         return(0);
  113.     }
  114.  
  115.     if ((*command == aSUS4) && (*vline == 0)) {
  116.         *command = aPLD;
  117.         *vline = -1;
  118.         return(0);
  119.     }
  120.  
  121.     if ((*command == aSUS4) && (*vline > 0)) {
  122.         *command = aIND;
  123.         *vline = -1;
  124.         return(0);
  125.     }
  126.  
  127.     if ((*command == aSUS3) && (*vline < 0)) {
  128.         *command = aPLU;
  129.         *vline = 0;
  130.         return(0);
  131.     }
  132.  
  133.     if(*command == aSUS0) {
  134.         if (*vline > 0) {
  135.             *command = aPLD;
  136.         }
  137.         if (*vline < 0) {
  138.             *command = aPLU;
  139.         }
  140.         *vline = 0;
  141.         return(0);
  142.     }
  143.  
  144.     if (*command == aPLU) {
  145.         (*vline)++;
  146.         return(0);
  147.     }
  148.  
  149.     if (*command == aPLD){
  150.         (*vline)--;
  151.         return(0);
  152.     }
  153.  
  154.     if (*command == aSTBM) {
  155.         if (Parms[0] == 0) {
  156.             Parms[0] = topmargin;
  157.         }
  158.         else {
  159.             topmargin = --Parms[0];
  160.         }
  161.  
  162.         if (Parms[1] == 0) {
  163.             Parms[1] = textlength;
  164.         }
  165.         else {
  166.             textlength=Parms[1];
  167.         }
  168.         while (x < 11) {
  169.             outputBuffer[x] = initTMarg[x];
  170.             x++;
  171.         }
  172.         numberString(Parms[0], 3, outputBuffer);
  173.         numberString(Parms[1] - Parms[0], 7, outputBuffer);
  174.         return(x);
  175.     }
  176.  
  177.     if (*command == aSLPP) {
  178.         while(x < 11) {
  179.             outputBuffer[x] = initForm[x];
  180.             x++;
  181.         }
  182.         /*restore textlength, margin*/
  183.         numberString(topmargin, 3, outputBuffer);
  184.         numberString(textlength, 7, outputBuffer);
  185.         return(x);    
  186.     }
  187.  
  188.     if (*command == aRIS) {
  189.         PD->pd_PWaitEnabled = 253;
  190.     }
  191.  
  192.     return(0);
  193. }
  194.  
  195. numberString(Param, x, outputBuffer)
  196. UBYTE Param;
  197. int x;
  198. char outputBuffer[];
  199. {
  200.     if (Param > 199) {
  201.         outputBuffer[x++] = '2';
  202.         Param -= 200;
  203.     }
  204.     else if (Param > 99) {
  205.         outputBuffer[x++] = '1';
  206.         Param -= 100;
  207.     }
  208.     else {
  209.         outputBuffer[x++] = '0'; /* always return 3 digits */
  210.     }
  211.  
  212.     if (Param > 9) {
  213.         outputBuffer[x++] = Param / 10 + '0';
  214.     }
  215.     else {
  216.         outputBuffer[x++] = '0';
  217.     }
  218.  
  219.     outputBuffer[x++] = Param % 10 + '0';
  220. }
  221.  
  222. ConvFunc(buf, c, flag)
  223. char *buf, c;
  224. int flag; /* expand lf into lf/cr flag (0-yes, else no ) */
  225. {
  226.     if (c == '\014') { /* if formfeed (page eject) */
  227.         PED->ped_PrintMode = 0; /* no data to print */
  228.     }
  229.     return(-1); /* pass all chars back to the printer device */
  230. }
  231.  
  232. Close(ior)
  233. struct printerIO *ior;
  234. {
  235.     if (PED->ped_PrintMode) { /* if data has been printed */
  236.         (*(PD->pd_PWrite))("\014",1); /* eject page */
  237.         (*(PD->pd_PBothReady))(); /* wait for it to finish */
  238.         PED->ped_PrintMode = 0; /* no data to print */
  239.     }
  240.     return(0);
  241. }
  242.