home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Printer / hp / render.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-03  |  8.6 KB  |  194 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.  *        HP_LaserJet driver.
  29.  */
  30.  
  31. #include <exec/types.h>
  32. #include <exec/nodes.h>
  33. #include <exec/lists.h>
  34. #include <exec/memory.h>
  35. #include <devices/prtbase.h>
  36. #include <devices/printer.h>
  37.  
  38. #define NUMSTARTCMD     7       /* # of cmd bytes before binary data */
  39. #define NUMENDCMD       0       /* # of cmd bytes after binary data */
  40. #define NUMTOTALCMD (NUMSTARTCMD + NUMENDCMD)   /* total of above */
  41.  
  42. extern SetDensity();
  43. /*
  44.         00-04   \033&l0L        perf skip mode off
  45.         05-11   \033*t075R      set raster graphics resolution (dpi)
  46.         12-16   \033*r0A        start raster graphics
  47. */
  48. char StartCmd[18] = "\033&l0L\033*t075R\033*r0A";
  49.  
  50. Render(ct, x, y, status)
  51. long ct, x, y, status;
  52. {
  53.         extern void *AllocMem(), FreeMem();
  54.  
  55.         extern struct PrinterData *PD;
  56.         extern struct PrinterExtendedData *PED;
  57.  
  58.         static UWORD RowSize, BufSize, TotalBufSize, dataoffset;
  59.         static UWORD huns, tens, ones; /* used to program buffer size */
  60.         UBYTE *ptr, *ptrstart;
  61.         int i, err;
  62.  
  63.         err=PDERR_NOERR;
  64.         switch(status) {
  65.                 case 0 : /* Master Initialization */
  66.                         /*
  67.                                 ct      - pointer to IODRPReq structure.
  68.                                 x       - width of printed picture in pixels.
  69.                                 y       - height of printed picture in pixels.
  70.                         */
  71.                         RowSize = (x + 7) / 8;
  72.                         BufSize = RowSize + NUMTOTALCMD;
  73.                         TotalBufSize = BufSize * 2;
  74.                         PD->pd_PrintBuf = AllocMem(TotalBufSize, MEMF_PUBLIC);
  75.                         if (PD->pd_PrintBuf == NULL) {
  76.                                 err = PDERR_BUFFERMEMORY; /* no mem */
  77.                         }
  78.                         else {
  79.                                 ptr = PD->pd_PrintBuf;
  80.                                 *ptr++ = 27;
  81.                                 *ptr++ = '*';
  82.                                 *ptr++ = 'b';   /* transfer raster graphics */
  83.                                 *ptr++ = huns | '0';
  84.                                 *ptr++ = tens | '0';
  85.                                 *ptr++ = ones | '0';    /* printout width */
  86.                                 *ptr = 'W';             /* terminator */
  87.                                 ptr = &PD->pd_PrintBuf[BufSize];
  88.                                 *ptr++ = 27;
  89.                                 *ptr++ = '*';
  90.                                 *ptr++ = 'b';   /* transfer raster graphics */
  91.                                 *ptr++ = huns | '0';
  92.                                 *ptr++ = tens | '0';
  93.                                 *ptr++ = ones | '0';    /* printout width */
  94.                                 *ptr = 'W';             /* terminator */
  95.                                 dataoffset = NUMSTARTCMD;
  96.                         /* perf skip mode off, set dpi, start raster gfx */
  97.                                 err = (*(PD->pd_PWrite))(StartCmd, 17);
  98.                         }
  99.                         break;
  100.  
  101.                 case 1 : /* Scale, Dither and Render */
  102.                         /*
  103.                                 ct      - pointer to PrtInfo structure.
  104.                                 x       - 0.
  105.                                 y       - row # (0 to Height - 1).
  106.                         */
  107.                         Transfer(ct, y, &PD->pd_PrintBuf[dataoffset]);
  108.                         err = PDERR_NOERR; /* all ok */
  109.                         break;
  110.  
  111.                 case 2 : /* Dump Buffer to Printer */
  112.                         /*
  113.                                 ct      - 0.
  114.                                 x       - 0.
  115.                                 y       - # of rows sent (1 to NumRows).
  116.  
  117.                                 White-space strip.
  118.                         */
  119.                         i = RowSize;
  120.                         ptrstart = &PD->pd_PrintBuf[dataoffset - NUMSTARTCMD];
  121.                         ptr = ptrstart + NUMSTARTCMD + i - 1;
  122.                         while (i > 0 && *ptr == 0) {
  123.                                 i--;
  124.                                 ptr--;
  125.                         }
  126.                         ptr = ptrstart + 3; /* get ptr to density info */
  127.                         *ptr++ = (huns = i / 100) | '0';
  128.                         *ptr++ = (i - huns * 100) / 10 | '0';
  129.                         *ptr = i % 10 | '0'; /* set printout width */
  130.                         err = (*(PD->pd_PWrite))(ptrstart, i + NUMTOTALCMD);
  131.                         if (err == PDERR_NOERR) {
  132.                                 dataoffset = (dataoffset == NUMSTARTCMD ?
  133.                                         BufSize : 0) + NUMSTARTCMD;
  134.                         }
  135.                         break;
  136.  
  137.                 case 3 : /* Clear and Init Buffer */
  138.                         /*
  139.                                 ct      - 0.
  140.                                 x       - 0.
  141.                                 y       - 0.
  142.                         */
  143.                         ptr = &PD->pd_PrintBuf[dataoffset];
  144.                         i = RowSize;
  145.                         do {
  146.                                 *ptr++ = 0;
  147.                         } while (--i);
  148.                         break;
  149.  
  150.                 case 4 : /* Close Down */
  151.                         /*
  152.                                 ct      - error code.
  153.                                 x       - io_Special flag from IODRPReq struct
  154.                                 y       - 0.
  155.                         */
  156.                         err = PDERR_NOERR; /* assume all ok */
  157.                         /* if user did not cancel the print */
  158.                         if (ct != PDERR_CANCEL) {
  159.                                 /* end raster graphics, perf skip mode on */
  160.                                 if ((err = (*(PD->pd_PWrite))
  161.                                         ("\033*rB\033&l1L", 9)) == PDERR_NOERR) {
  162.                                         /* if want to unload paper */
  163.                                         if (!(x & SPECIAL_NOFORMFEED)) {
  164.                                                 /* eject paper */
  165.                                                 err = (*(PD->pd_PWrite))
  166.                                                         ("\014", 1);
  167.                                         }
  168.                                 }
  169.                         }
  170.                         /*
  171.                                 flag that there is no alpha data waiting that
  172.                                 needs a formfeed (since we just did one)
  173.                         */
  174.                         PED->ped_PrintMode = 0;
  175.                          /* wait for both buffers to empty */
  176.                         (*(PD->pd_PBothReady))();
  177.                         if (PD->pd_PrintBuf != NULL) {
  178.                                 FreeMem(PD->pd_PrintBuf, TotalBufSize);
  179.                         }
  180.                         break;
  181.  
  182.                 case 5 : /* Pre-Master Initialization */
  183.                         /*
  184.                                 ct      - 0 or pointer to IODRPReq structure.
  185.                                 x       - io_Special flag from IODRPReq struct
  186.                                 y       - 0.
  187.                         */
  188.                         /* select density */
  189.                         SetDensity(x & SPECIAL_DENSITYMASK);
  190.                         break;
  191.         }
  192.         return(err);
  193. }
  194.