home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 10 / amigaformatcd10.iso / -readerstuff- / peter_hutchison / misc-drivers.lzx / Tek4695 / render.c < prev    next >
C/C++ Source or Header  |  1996-11-27  |  2KB  |  99 lines

  1. /**********************************************************************/
  2. #include <exec/types.h>
  3. #include <exec/nodes.h>
  4. #include <exec/lists.h>
  5. #include <exec/memory.h>
  6. #include "devices/printer.h"
  7. #include "devices/prtbase.h"
  8. #include <functions.h>
  9.  
  10. extern struct PrinterData *PD;
  11.  
  12. /* for the Tektronix 4695 */
  13. long Render(ct,x,y,status)
  14. register ULONG ct;    /* was UBYTE for Lattice compiler */
  15. register ULONG x,y;    /* was UWORD for Lattice compiler */
  16. ULONG status;    /* was UBYTE for Lattice compiler */
  17. {
  18.     static UWORD ROWSIZE;
  19.     static UWORD COLORSIZE;
  20.     static UWORD BUFSIZE;
  21.     static UWORD colors[4];
  22.     static BYTE huns,tens,ones;
  23.     static UWORD bufptr;
  24.     register struct PrinterData *pp = PD;
  25.     register UBYTE *ptr;
  26.     UWORD i;
  27.     BYTE err; 
  28.  
  29.     switch((UBYTE)status) {
  30.  
  31.         case 0:    /* alloc memory for printer buffer (uses dbl buf) */
  32.             ROWSIZE = ((UWORD)x+7)/8;
  33.             huns = ROWSIZE/100;
  34.             tens = (ROWSIZE - huns*100)/10;
  35.             ones = (ROWSIZE - huns*100 - tens*10);
  36.             ROWSIZE += 6;
  37.             COLORSIZE = ROWSIZE*4;
  38.             BUFSIZE = COLORSIZE*4+2;
  39.             colors[0] = 6;
  40.             colors[1] = COLORSIZE*2+6;
  41.             colors[2] = COLORSIZE+6;
  42.             colors[3] = COLORSIZE*3+6;
  43.             pp->pd_PrintBuf = (UBYTE *)
  44.                 AllocMem((long)BUFSIZE*2,(long)MEMF_PUBLIC);
  45.             if(err = (pp->pd_PrintBuf==0)) 
  46.                 return(err);
  47.             if(err = (*(pp->pd_PWrite))("\0334",2L)) 
  48.                 return(err);
  49.             if(err = PWait(1L,0L)) 
  50.                 return(err);
  51.             bufptr = 0;
  52.             return(0);
  53.             break;
  54.  
  55.         case 1:    /* put pixel in buffer (called a max of 16384 
  56.              * times per print cycle */
  57.             i = bufptr+(UWORD)x/8+((UWORD)y&3)*ROWSIZE+colors[(UBYTE)ct];
  58.             pp->pd_PrintBuf[i] |= (1 << (7-((UWORD)x&7)));
  59.             return(0);
  60.             break;
  61.  
  62.         case 2: /* dump buffer to printer */
  63.             if (err = (*(pp->pd_PWrite))(&pp->pd_PrintBuf[bufptr],
  64.                                 (long)BUFSIZE))
  65.                 return (err);
  66.             bufptr = BUFSIZE - bufptr;
  67.             return(0);
  68.             break;
  69.  
  70.         case 3: /* clear and init buffer */
  71.             ptr = &pp->pd_PrintBuf[bufptr];
  72.             i = BUFSIZE;
  73.             while(i--) 
  74.                 *ptr++ = 0;
  75.             for (i = 0; i < 16; i++) {
  76.                 ptr = &pp->pd_PrintBuf[bufptr+i*ROWSIZE];
  77.                 *ptr++ = 27;
  78.                 *ptr++ = 'I';
  79.                 *ptr++ = i+'0';
  80.                 *ptr++ = huns+'0';
  81.                 *ptr++ = tens+'0';
  82.                 *ptr++ = ones+'0';
  83.             }
  84.             pp->pd_PrintBuf[bufptr+BUFSIZE-2] = 27;
  85.             pp->pd_PrintBuf[bufptr+BUFSIZE-1] = 'A';
  86.             return(0);
  87.             break;
  88.  
  89.         case 4:    /* free the print buffer memory */
  90.             err = (*(pp->pd_PBothReady))();
  91.             FreeMem(pp->pd_PrintBuf,(long)BUFSIZE*2L);
  92.             return(err);
  93.             break;
  94.  
  95.         default:
  96.             return(0);
  97.     }
  98. }
  99.