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