home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / printer / hp / dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  5.6 KB  |  255 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 LPI        7
  27. #define CPI        15
  28. #define QUALITY        17
  29. #define INIT_LEN    30
  30. #define LPP        7
  31. #define FORM_LEN    11
  32. #define LEFT_MARG    3
  33. #define RIGHT_MARG    7
  34. #define MARG_LEN    12
  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.     extern struct PrinterExtendedData *PED;
  46.  
  47.     UWORD textlength, topmargin;
  48.     int x, y, j;
  49.     static char initThisPrinter[INIT_LEN] =
  50.     {0x1b,'&','d','@',0x1b,'&','l','6','D',0x1b,'(','s','0','b',
  51.     '1','0','h','1','q','0','p','0','s','3','t','0','u','1','2','V'};
  52.  
  53.     static char initForm[FORM_LEN] = 
  54.         {0x1b,'&','l','0','0','2','e','0','0','0','F'};
  55.  
  56.     static char initMarg[MARG_LEN] = 
  57.         {0x1b,'&','a','0','0','0','l','0','0','0','M',0x0d};
  58.  
  59.     static char initTMarg[] = 
  60.     {0x1b,'&','l','0','0','0','e','0','0','0','F'};
  61.     x = y = j = 0;
  62.  
  63.     if (*command == aRIN) {
  64.         while(x < INIT_LEN) {
  65.             outputBuffer[x] = initThisPrinter[x];
  66.             x++;
  67.         }
  68.         outputBuffer[x++] = '\015';
  69.  
  70.         if (PD->pd_Preferences.PrintSpacing == EIGHT_LPI) {
  71.             outputBuffer[LPI] = '8';
  72.         }
  73.  
  74.         if (PD->pd_Preferences.PrintPitch == ELITE) {
  75.             outputBuffer[CPI] = '2';
  76.         }
  77.         else if (PD->pd_Preferences.PrintPitch == FINE) {
  78.             outputBuffer[CPI] = '5';
  79.         }
  80.  
  81.         if (PD->pd_Preferences.PrintQuality == LETTER) {
  82.             outputBuffer[QUALITY] = '2';
  83.         }
  84.  
  85.         j = x; /* set the formlength = textlength, top margin = 2 */
  86.         textlength = PD->pd_Preferences.PaperLength;
  87.         topmargin = 2;
  88.  
  89.         while (y < FORM_LEN) {
  90.             outputBuffer[x++] = initForm[y++];
  91.         }
  92.         numberString(textlength, j + LPP, outputBuffer);
  93.  
  94.         Parms[0] = PD->pd_Preferences.PrintLeftMargin;
  95.         Parms[1] = PD->pd_Preferences.PrintRightMargin;
  96.         *command = aSLRM;
  97.     }
  98.  
  99.     if (*command == aSLRM) {
  100.         j = x;
  101.         y = 0;
  102.         while(y < MARG_LEN) {
  103.             outputBuffer[x++] = initMarg[y++];
  104.         }
  105.         numberString(Parms[0] - 1, j + LEFT_MARG, outputBuffer);
  106.         numberString(Parms[1] - 1, j + RIGHT_MARG, outputBuffer);
  107.         return(x);
  108.     }
  109.  
  110.     if ((*command == aSUS2) && (*vline == 0)) {
  111.         *command = aPLU;
  112.         *vline = 1;
  113.         return(0);
  114.     }
  115.  
  116.     if ((*command == aSUS2) && (*vline < 0)) {
  117.         *command = aRI;
  118.         *vline = 1;
  119.         return(0);
  120.     }
  121.  
  122.     if ((*command == aSUS1) && (*vline > 0)) {
  123.         *command = aPLD;
  124.         *vline = 0;
  125.         return(0);
  126.     }
  127.  
  128.     if ((*command == aSUS4) && (*vline == 0)) {
  129.         *command = aPLD;
  130.         *vline = -1;
  131.         return(0);
  132.     }
  133.  
  134.     if ((*command == aSUS4) && (*vline > 0)) {
  135.         *command = aIND;
  136.         *vline = -1;
  137.         return(0);
  138.     }
  139.  
  140.     if ((*command == aSUS3) && (*vline < 0)) {
  141.         *command = aPLU;
  142.         *vline = 0;
  143.         return(0);
  144.     }
  145.  
  146.     if(*command == aSUS0) {
  147.         if (*vline > 0) {
  148.             *command = aPLD;
  149.         }
  150.         if (*vline < 0) {
  151.             *command = aPLU;
  152.         }
  153.         *vline = 0;
  154.         return(0);
  155.     }
  156.  
  157.     if (*command == aPLU) {
  158.         (*vline)++;
  159.         return(0);
  160.     }
  161.  
  162.     if (*command == aPLD){
  163.         (*vline)--;
  164.         return(0);
  165.     }
  166.  
  167.     if (*command == aSTBM) {
  168.         if (Parms[0] == 0) {
  169.             Parms[0] = topmargin;
  170.         }
  171.         else {
  172.             topmargin = --Parms[0];
  173.         }
  174.  
  175.         if (Parms[1] == 0) {
  176.             Parms[1] = textlength;
  177.         }
  178.         else {
  179.             textlength=Parms[1];
  180.         }
  181.         while (x < 11) {
  182.             outputBuffer[x] = initTMarg[x];
  183.             x++;
  184.         }
  185.         numberString(Parms[0], 3, outputBuffer);
  186.         numberString(Parms[1] - Parms[0], 7, outputBuffer);
  187.         return(x);
  188.     }
  189.  
  190.     if (*command == aSLPP) {
  191.         while(x < 11) {
  192.             outputBuffer[x] = initForm[x];
  193.             x++;
  194.         }
  195.         /*restore textlength, margin*/
  196.         numberString(topmargin, 3, outputBuffer);
  197.         numberString(textlength, 7, outputBuffer);
  198.         return(x);    
  199.     }
  200.  
  201.     if (*command == aRIS) {
  202.         PD->pd_PWaitEnabled = 253;
  203.     }
  204.  
  205.     return(0);
  206. }
  207.  
  208. numberString(Param, x, outputBuffer)
  209. UBYTE Param;
  210. int x;
  211. char outputBuffer[];
  212. {
  213.     if (Param > 199) {
  214.         outputBuffer[x++] = '2';
  215.         Param -= 200;
  216.     }
  217.     else if (Param > 99) {
  218.         outputBuffer[x++] = '1';
  219.         Param -= 100;
  220.     }
  221.     else {
  222.         outputBuffer[x++] = '0'; /* always return 3 digits */
  223.     }
  224.  
  225.     if (Param > 9) {
  226.         outputBuffer[x++] = Param / 10 + '0';
  227.     }
  228.     else {
  229.         outputBuffer[x++] = '0';
  230.     }
  231.  
  232.     outputBuffer[x++] = Param % 10 + '0';
  233. }
  234.  
  235. ConvFunc(buf, c, flag)
  236. char *buf, c;
  237. int flag; /* expand lf into lf/cr flag (0-yes, else no ) */
  238. {
  239.     if (c == '\014') { /* if formfeed (page eject) */
  240.         PED->ped_PrintMode = 0; /* no data to print */
  241.     }
  242.     return(-1); /* pass all chars back to the printer device */
  243. }
  244.  
  245. Close(ior)
  246. struct printerIO *ior;
  247. {
  248.     if (PED->ped_PrintMode) { /* if data has been printed */
  249.         (*(PD->pd_PWrite))("\014",1); /* eject page */
  250.         (*(PD->pd_PBothReady))(); /* wait for it to finish */
  251.         PED->ped_PrintMode = 0; /* no data to print */
  252.     }
  253.     return(0);
  254. }
  255.