home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / printer / epsonx / render.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  16KB  |  352 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.  *
  29.  *       EpsonX (EX/FX/JX/LX/MX/RX) driver.
  30.  */
  31.  
  32. #include <exec/types.h>
  33. #include <exec/nodes.h>
  34. #include <exec/lists.h>
  35. #include <exec/memory.h>
  36. #include "devices/printer.h"
  37. #include "devices/prtbase.h"
  38.  
  39. #define NUMSTARTCMD     7       /* # of cmd bytes before binary data */
  40. #define NUMENDCMD       1       /* # of cmd bytes after binary data */
  41. #define NUMTOTALCMD     (NUMSTARTCMD + NUMENDCMD)       /* total of above */
  42. #define NUMLFCMD        4       /* # of cmd bytes for linefeed */
  43. #define MAXCOLORBUFS    4       /* max # of color buffers */
  44.  
  45. #define STARTLEN        19
  46. #define PITCH           1
  47. #define CONDENSED       2
  48. #define LMARG           8
  49. #define RMARG           11
  50. #define DIREC           15
  51.  
  52. static ULONG TwoBufSize;
  53. static UWORD RowSize, ColorSize, NumColorBufs, dpi_code, spacing;
  54. static UWORD colorcodes[MAXCOLORBUFS];
  55.  
  56. Render(ct, x, y, status)
  57. long ct, x, y, status;
  58. {
  59.         extern void *AllocMem(), FreeMem();
  60.  
  61.         extern struct PrinterData *PD;
  62.         extern struct PrinterExtendedData *PED;
  63.  
  64.         UBYTE *CompactBuf();
  65.         static ULONG BufSize, TotalBufSize, dataoffset;
  66.         static UWORD spacing, colors[MAXCOLORBUFS];
  67.         /*
  68.                 00-01   \003P           set pitch (10 or 12 cpi)
  69.                 02-02   \022            set condensed fine (on or off)
  70.                 03-05   \033W\000       enlarge off
  71.                 06-08   \033ln          set left margin to n
  72.                 09-11   \033Qn          set right margin to n
  73.                 12-12   \015            carriage return
  74.                 13-15   \033U1          set uni-directional mode
  75.                 16-18   \033t\000       see kludge note below
  76.                 Kludge to get this to work on a CBM_MPS-1250  which interprets
  77.                 'ESCr' as go into reverse print mode.  The 'ESCt' tells it to
  78.                 get out of reverse print mode.  The 'NULL' is ignored by the
  79.                 CBM_MPS-1250 and required by all Epson printers as the
  80.                 terminator for the 'ESCtNULL' command which means select
  81.                 normal char set (which has no effect).
  82.         */
  83.  
  84.         static UBYTE StartBuf[STARTLEN+1] =
  85.                 "\033P\022\033W\000\033ln\033Qn\015\033U1\033t\000";
  86.  
  87.         UBYTE *ptr, *ptrstart;
  88.         int err;
  89.  
  90.         switch(status) {
  91.                 case 0 : /* Master Initialization */
  92.                         /*
  93.                                 ct      - pointer to IODRPReq structure.
  94.                                 x       - width of printed picture in pixels.
  95.                                 y       - height of printed picture in pixels.
  96.                         */
  97.                         RowSize = x;
  98.                         ColorSize = RowSize + NUMTOTALCMD;
  99.                         if (PD->pd_Preferences.PrintShade == SHADE_COLOR) {
  100.                                 NumColorBufs = MAXCOLORBUFS;
  101.                                 colors[0] = ColorSize * 3; /* Black */
  102.                                 colors[1] = ColorSize * 0; /* Yellow */
  103.                                 colors[2] = ColorSize * 1; /* Magenta */
  104.                                 colors[3] = ColorSize * 2; /* Cyan */
  105.                                 colorcodes[0] = 4; /* Yellow */
  106.                                 colorcodes[1] = 1; /* Magenta */
  107.                                 colorcodes[2] = 2; /* Cyan */
  108.                                 colorcodes[3] = 0; /* Black */
  109.                         }
  110.                         else { /* grey-scale or black&white */
  111.                                 NumColorBufs = 1;
  112.                                 colors[0] = ColorSize * 0; /* Black */
  113.                                 colorcodes[0] = 0; /* Black */
  114.                         }
  115.                         BufSize = ColorSize * NumColorBufs + NUMLFCMD;
  116.                         if (PED->ped_YDotsInch == 216) {
  117.                                 TwoBufSize = BufSize * 3;
  118.                                 TotalBufSize = BufSize * 6;
  119.                         }
  120.                         else if (PED->ped_YDotsInch == 144) {
  121.                                 TwoBufSize = BufSize * 2;
  122.                                 TotalBufSize = BufSize * 4;
  123.                         }
  124.                         else {
  125.                                 TwoBufSize = BufSize * 1;
  126.                                 TotalBufSize = BufSize * 2;
  127.                         }
  128.                         PD->pd_PrintBuf = AllocMem(TotalBufSize, MEMF_PUBLIC);
  129.                         if (PD->pd_PrintBuf == NULL) {
  130.                                 err = PDERR_BUFFERMEMORY;
  131.                         }
  132.                         else {
  133.                                 dataoffset = NUMSTARTCMD;
  134.                                 /*
  135.                                         This printer prints graphics within its
  136.                                         text margins.  This code makes sure the
  137.                                         printer is in 10 cpi and then sets the
  138.                                         left and right margins to their minimum
  139.                                         and maximum values (respectively).  A
  140.                                         carriage return is sent so that the
  141.                                         print head is at the leftmost position
  142.                                         as this printer starts printing from
  143.                                         the print head's position.  The printer
  144.                                         is put into unidirectional mode to
  145.                                         reduce wavy vertical lines.
  146.                                 */
  147.                                 StartBuf[PITCH] = 'P'; /* 10 cpi */
  148.                                 StartBuf[CONDENSED] = '\022'; /* off */
  149.                                 /* left margin of 1 */
  150.                                 StartBuf[LMARG] = 0;
  151.                                 /* right margin of 80 or 136 */
  152.                                 StartBuf[RMARG] = PD->pd_Preferences.
  153.                                         PaperSize == W_TRACTOR ? 136 : 80;
  154.                                 /* uni-directional mode */
  155.                                 StartBuf[DIREC] = '1';
  156.                                 err = (*(PD->pd_PWrite))(StartBuf, STARTLEN);
  157.                         }
  158.                         break;
  159.  
  160.                 case 1 : /* Scale, Dither and Render */
  161.                         /*
  162.                                 ct      - pointer to PrtInfo structure.
  163.                                 x       - 0.
  164.                                 y       - row # (0 to Height - 1).
  165.                         */
  166.                         Transfer(ct, y, &PD->pd_PrintBuf[dataoffset], colors,
  167.                                 BufSize);
  168.                         err = PDERR_NOERR; /* all ok */
  169.                         break;
  170.  
  171.                 case 2 : /* Dum