home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 1036.dms / 1036.adf / Dec_ln03 / render.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  5KB  |  117 lines

  1. /***********************************************************************
  2.  *      render.c
  3.  *              This module compiles Ok under Aztec C ver 3.4a, note
  4.  *      however that some in-line assembly was required to save reg A6
  5.  *      as the memory allocating routines trash it. (naughty Manx)
  6.  *      Also a modular 6 lookup table is used for speed of graphic dumps.
  7.  *      At the present I use the .0045" grid size on the ln03+ as this
  8.  *      seems to produce the nicest looking grey-scale picture.
  9.  *
  10.  *              written by Bernie Mentink Chistchurch N.Z 1/2/88
  11.  *
  12.  *
  13.  ***********************************************************************/
  14. #include <exec/types.h>
  15. #include <exec/nodes.h>
  16. #include <exec/lists.h>
  17. #include <exec/memory.h>
  18. #include "devices/printer.h"
  19. #include "devices/prtbase.h"
  20. #include <functions.h>
  21. #include "stdio.h"
  22.  
  23. extern struct PrinterData *PD;
  24. extern struct PrinterExtendedData *PED;
  25.  
  26. /* for the DEC LN03+ */
  27. long Render(ct,x,y,status)
  28. register ULONG ct;      /* was UBYTE for Lattice compiler */
  29. register ULONG x,y;     /* was UWORD for Lattice compiler */
  30. ULONG status;           /* was UBYTE for Lattice compiler */
  31. {
  32.         static UWORD ROWSIZE;
  33.         static UWORD COLORSIZE;
  34.         static UWORD BUFSIZE, offset,size;
  35.         static BYTE center;
  36.         static UWORD bufptr;       /* pointer to buffer 1 or 2 */
  37.         static UBYTE *lookup;      /* lookup table for sixels (modula-6) */
  38.         register struct PrinterData *pp = PD;
  39.         register UBYTE *ptr;
  40.         register UWORD i,j;
  41.         long err=0;
  42.         FILE *fp;
  43.                               /* patch to save A6 pointer */
  44.         #asm
  45.             move.l a6,-(sp)
  46.         #endasm
  47.  
  48.         switch(status) {
  49.  
  50.                 case 0: /* alloc memory for printer buffer (uses dbl buf) */
  51.                         ROWSIZE = ((UWORD)x); /* row size for lno3 */
  52.                         BUFSIZE = ROWSIZE+9;  /* buffer size plus offset */
  53.                         lookup = (UBYTE *) AllocMem(y,(long)MEMF_PUBLIC);
  54.                         size = y;             /* save size */
  55.                         for(i=1,j=0;j<y;++j)
  56.                         {
  57.                             if(i==64) i=1;     /* modular 6 */
  58.                             lookup[j] = i;     /* init lookup table */
  59.                             i <<= 1;           /* 1,2,4,8,16,32,1,2 etc  */
  60.                         }
  61.                         pp->pd_PrintBuf = (UBYTE *)
  62.                               AllocMem((long)(BUFSIZE*2),(long)MEMF_PUBLIC);
  63.                         if(err = (pp->pd_PrintBuf==0)) break;
  64.                         if(err = (*(pp->pd_PWrite))("\033c",2L))
  65.                                       break;        /* reset printer */
  66.                         if(err = PWait(1L,0L)) break;
  67.                         bufptr = 0;
  68.                         break;
  69.  
  70.                 case 1: /* put pixel in buffer  */
  71.                         pp->pd_PrintBuf[bufptr+x+7] |=  lookup[y];
  72.                                                    /* set pixel on  */
  73.                         break;
  74.  
  75.                 case 2: /* dump buffer to printer */
  76.                         for(i=bufptr+7;i<bufptr+ROWSIZE+7;++i)
  77.                             pp->pd_PrintBuf[i] += 63;    /* add 077 octal */
  78.                         if(err = (*(pp->pd_PWrite))(&pp->pd_PrintBuf[bufptr],
  79.                              (long)BUFSIZE)) break;      /* send buffer */
  80.                         bufptr = BUFSIZE-bufptr; /* switch to other buffer */
  81.                         break;
  82.  
  83.                 case 3: /* clear  buffer */
  84.                         ptr = &pp->pd_PrintBuf[bufptr];
  85.                         i = BUFSIZE;
  86.                         while(i--) *ptr++ = 0;           /* clear buffer */
  87.                         pp->pd_PrintBuf[bufptr] = 144;    /* start sixel */
  88.                         pp->pd_PrintBuf[bufptr+1] = '9';  /* 1:1 aspect  */
  89.                         pp->pd_PrintBuf[bufptr+2] = ';';
  90.                         pp->pd_PrintBuf[bufptr+3] = '0';
  91.                         pp->pd_PrintBuf[bufptr+4] = ';';
  92.                         pp->pd_PrintBuf[bufptr+5] = '3';  /* .0045" grid */
  93.                         pp->pd_PrintBuf[bufptr+6] = 'q';
  94.                         pp->pd_PrintBuf[bufptr+BUFSIZE-2] = '-'; /* CR LF */
  95.                         pp->pd_PrintBuf[bufptr+BUFSIZE-1] = 156;
  96.                         break;                           /* end of sixel  */
  97.  
  98.                 case 4:  /* free the print buffer memory */
  99.                          /*  eject page, reset printer   */
  100.                         if(err = (*(pp->pd_PWrite))("\014\033c",3L))
  101.                                 return(err);      /* eject page,reset */
  102.                         err = (*(pp->pd_PBothReady))();
  103.                         FreeMem(pp->pd_PrintBuf,(long)(BUFSIZE*2));
  104.                         FreeMem(lookup,(long)size);
  105.                         break;
  106.  
  107.                 default:
  108.                         break;
  109.         }
  110.                            /* restore A6 */
  111.         #asm
  112.             move.l (sp)+,a6
  113.         #endasm
  114.  
  115.         return(err);
  116. }
  117.