home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / hp_laserjet_dospecial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  6.3 KB  |  233 lines

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