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

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