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

  1. #include <exec/types.h>
  2. #include <exec/nodes.h>
  3. #include <exec/lists.h>
  4. #include <exec/memory.h>
  5. #include <devices/printer.h>
  6. #include <devices/prtbase.h>
  7.  
  8. extern struct PrinterData *PD;
  9. extern struct PrinterExtendedData *PED;
  10.     
  11. #define PWrite (*(PD->pd_PWrite))    /* write data to device */
  12. #define PReady (*(PD->pd_PBothReady))    /* wait for both buffers ready */
  13.  
  14. #define LEAD   4        /* bytes to start each complete cycle */
  15. #define EXTRA  9        /* bytes to prefix each pass of the head */
  16. #define TAIL   2        /* bytes to end each complete cycle */
  17.  
  18. void *AllocMem();
  19.  
  20. /* these two tables wouldn't normally be bothered with but in light of
  21.  * the number of times that these operations need to be performed
  22.  * for each pass of the print head I thought they'd be worthwhile
  23.  */
  24.  
  25. /*
  26.  * this table simulates the operation   (1<<(5-(y%6)))
  27.  * for values of y between 0 and 23 (the number of pixels in a printer pass)
  28.  *
  29.  */
  30.  
  31. UBYTE bit_table[] = {
  32.             32,16,8,4,2,1,
  33.             32,16,8,4,2,1,
  34.             32,16,8,4,2,1,
  35.             32,16,8,4,2,1
  36. };
  37.  
  38. /* this table simulates  y/6 for values of y between 0 and 23 */
  39. /* saves a long division opeation */
  40. UBYTE div_table[] = {
  41.             0,0,0,0,0,0,
  42.             1,1,1,1,1,1,
  43.             2,2,2,2,2,2,
  44.             3,3,3,3,3,3
  45. };
  46.  
  47. UBYTE *GfxBuffer;
  48.  
  49. ULONG Render(ct,x,y,status)
  50. register UBYTE ct;
  51. register UWORD x,y;
  52. register UBYTE status;
  53. {
  54.     static ULONG ROWSIZE;
  55.     static ULONG COLOURSIZE;
  56.     static ULONG BUFSIZE;
  57.     static ULONG colours[4];
  58.     static ULONG centre;
  59.     static ULONG bufptr;
  60.     static UBYTE *ptr;
  61.     static ULONG psize;
  62.     int i,filler;
  63.     int err;
  64.  
  65. /* Aztec doesn't preserve a6, we need this in a printer driver */
  66. #asm
  67.     move.l    a6,-(sp)
  68. #endasm
  69.     err = 0;
  70.  
  71.     switch (status) {
  72.  
  73.     case 0:    /* alloc memory for printer buffer */
  74.  
  75.         filler        = (centre) ? ((PED->ped_MaxXDots -x ) / 2 ) : 0;
  76.         ROWSIZE    = ((x+filler)<<2) + EXTRA;
  77.         COLOURSIZE = ROWSIZE<<2;
  78.         BUFSIZE       = COLOURSIZE+LEAD+TAIL+1;    /* plus 1 for NULL */
  79.  
  80.         colours[0] = LEAD +  EXTRA + filler + ROWSIZE*0;
  81.         colours[1] = LEAD +  EXTRA + filler + ROWSIZE*1;
  82.         colours[2] = LEAD +  EXTRA + filler + ROWSIZE*2;
  83.         colours[3] = LEAD +  EXTRA + filler + ROWSIZE*3;
  84.         psize = x+filler;
  85.  
  86.         dbprintf("Size Data:\n");
  87.         dbprintf("\tfiller: %d\n",filler);
  88.         dbprintf("\tROWSIZE: %d\n",ROWSIZE);
  89.         dbprintf("\tCOLOURSIZE: %d\n",COLOURSIZE);
  90.         dbprintf("\tBUFSIZE: %d\n",BUFSIZE);
  91.         dbprintf("\tcolours: %d %d %d %d\n",
  92.             colours[0],colours[1],colours[2],colours[3]);
  93.  
  94.         GfxBuffer =  AllocMem(BUFSIZE*2,MEMF_PUBLIC);
  95.  
  96.         if (err = (GfxBuffer==0))        break;
  97.         if (err = PWrite("\x1b\x1a\x49",3)) break;
  98.         if (err = PWait(1,0))            break;
  99.  
  100.         /* set to first buffer */
  101.         bufptr  = 0;
  102.         break;
  103.  
  104.     case 1:    /* render pixel */
  105.         y %= 24; /* blecch, I wanted to avoid this calculation */
  106.         i = bufptr + (x<<2) + div_table[y] + colours[3-ct];
  107.         GfxBuffer[i] |= bit_table[y];
  108.         break;
  109.  
  110.     case 2: /* write a buffer */
  111.         dbprintf("Writing a buffer\n");
  112.  
  113.         /* BUFSIZE-1 is so that we don't send the trailing null */
  114.         if (err=PWrite(&GfxBuffer[bufptr],BUFSIZE-1)) break;
  115.         bufptr = BUFSIZE-bufptr;
  116.         break;
  117.  
  118.     case 3: /* initialize the current buffer */
  119.         dbprintf("Performing initialization\n");
  120.  
  121.         ptr = &GfxBuffer[bufptr];
  122.  
  123.         for (i=BUFSIZE;i--;) *ptr++ = 0;    /* clear buffer */
  124.  
  125.         ptr = &GfxBuffer[bufptr];
  126.         sprintf(ptr,"\x1bL07");
  127.         sprintf(ptr+LEAD           ,"\r\x1bc\x1b;%04d",psize); /* c */
  128.         sprintf(ptr+LEAD+ROWSIZE  ,"\r\x1bm\x1b;%04d",psize); /* m */
  129.         sprintf(ptr+LEAD+ROWSIZE*2,"\r\x1by\x1b;%04d",psize); /* y */
  130.         sprintf(ptr+LEAD+ROWSIZE*3,"\r\x1bb\x1b;%04d",psize); /* b */
  131.         sprintf(ptr+LEAD+ROWSIZE*4,"\r\n");    /* crlf + NULL */
  132.  
  133.         break;
  134.  
  135.     case 4: /* cleanup -- release memory */
  136.         dbprintf("Print finished -- cleanup\n");
  137.         dbprintf("waiting for printer\n");
  138.  
  139.         err = PReady();
  140.  
  141.         dbprintf("Freeing memory\n");
  142.  
  143.         FreeMem(GfxBuffer,BUFSIZE*2);
  144.  
  145.         dbprintf("Returning\n");
  146.  
  147.         break;
  148.  
  149.     case 5:    /* handle any special commands */
  150.         centre = x & SPECIAL_CENTER;
  151.         dbprintf("special: %d %d %d %d\n",ct,x,y,status);
  152.  
  153.         break;
  154.  
  155.     default:
  156.         break;
  157.     }
  158. #asm
  159.     move.l    (sp)+,a6
  160. #endasm
  161.     return(err);
  162. }
  163.