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