home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gs252b.lzh / GS252B / GDEVSLM.C < prev    next >
C/C++ Source or Header  |  1993-07-30  |  4KB  |  155 lines

  1. /* Copyright (C) 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gdevslm.c */
  21.  
  22. /* SLM 804 driver for the Atari ST. This driver was hacked
  23.  * from the 'stmono' device with the aid of code originally written
  24.  * by Hauke Hess and Tim Gallivan.   Robert Stabl 9/2/91
  25.  */
  26.  
  27. #include <stdio.h>
  28. #include <osbind.h>
  29. #include "gdevprn.h"
  30.  
  31. /* Define the default device parameters. */
  32.  
  33. #ifndef X_DPI
  34. #define X_DPI 300
  35. #endif
  36. #ifndef Y_DPI
  37. #define Y_DPI 300
  38. #endif
  39. #define WIDTH_10THS 85
  40. #define HEIGHT_10THS 110
  41.  
  42. private dev_proc_print_page(slm_print_page);
  43.  
  44. gx_device_printer gs_slm_device =
  45.   prn_device(prn_std_procs, "slm",
  46.     WIDTH_10THS, HEIGHT_10THS,
  47.     X_DPI, Y_DPI,
  48.     0,0,0,0,            /* margins */
  49.     1, slm_print_page);
  50.  
  51. /* Structure for the Diablo emulator (Atari SLM 804)
  52. */
  53.  
  54. typedef struct {
  55.   char *s_form;
  56.   short s_xmin,
  57.         s_ymin,
  58.         s_nxln,
  59.         b_width,
  60.         b_height,
  61.         d_xmin,
  62.         d_ymin,
  63.         scalefac;
  64. } SLM;
  65.  
  66. private int
  67. slm_print_page(gx_device_printer *dev, FILE *dummy)
  68. {
  69.     /*  scanbuf = buffer for a scan line,
  70.      *  slmbuf  = buffer for entire image,
  71.      *  scanptr = long pointer to scan buffer,
  72.      *  slmptr  = long pointer to slm buffer.
  73.      */
  74.  
  75.     byte *scanbuf, *slmbuf;
  76.     long *scanptr, *slmptr;
  77.  
  78.     int byte_width, x_res_slm, y_res_slm;
  79.     int line, count, sizlong;
  80.  
  81.     FILE *fp;
  82.     SLM o;
  83.  
  84.     /*  byte_width = width of image in bytes,
  85.      *  x_res_slm  = width of image in longs,
  86.      *  y_res_slm  = height of image in lines.
  87.      */
  88.  
  89.     sizlong = sizeof(long);
  90.  
  91.     byte_width = gdev_mem_bytes_per_scan_line((gx_device *)dev);
  92.     x_res_slm = (byte_width + sizlong - 1) / sizlong;
  93.     y_res_slm = prn_dev->height;
  94.  
  95.     /* Allocate a buffer for a single scan line. */
  96.  
  97.     if ((scanbuf = (byte *)calloc(byte_width + sizlong - 1, 1)) == NULL) {
  98.         puts("gdevslm: Could not allocate memory for scan line!");
  99.         return(-1);
  100.     }
  101.         
  102.     /* Allocate a buffer for the printer bitmap. */
  103.  
  104.     if ((slmbuf = (byte *)calloc((byte_width + sizlong - 1) * y_res_slm,
  105.              1)) == NULL) {
  106.         puts("gdevslm: Could not allocate memory for printer bitmap!");
  107.         return(-1);
  108.     }
  109.         
  110.     scanptr = (long *)scanbuf;
  111.     slmptr =  (long *)slmbuf;
  112.  
  113.     o.s_form   =     (char *)slmbuf;
  114.     o.s_xmin   =     (short)0;
  115.     o.s_ymin   =     (short)0;
  116.       o.s_nxln   =     (short)(byte_width + 1);
  117.       o.b_width  =     (short)(prn_dev->width);
  118.       o.b_height =     (short)(prn_dev->height);
  119.       o.d_xmin   =     (short)0;
  120.       o.d_ymin   =     (short)0;
  121.       o.scalefac =     (short)1;
  122.  
  123.     /* Copy the bitmap to the slm buffer, one scan line at a time.
  124.      * Scan lines are copied as longs rather than bytes (for speed?).
  125.      */
  126.  
  127.     for (line = 0; line < y_res_slm; line++) {
  128.  
  129.         /* Copy (line)th scan line to scanbuf. */
  130.  
  131.         gdev_prn_copy_scan_lines(prn_dev, line
  132.                        , scanbuf, byte_width);
  133.  
  134.         /* Copy scanbuf to the slm buffer. */
  135.  
  136.         for (count = 0; count < x_res_slm; count++ )
  137.             *slmptr++ = scanptr[count];
  138.  
  139.     }
  140.  
  141.     fp = fopen("PRN:", "w");
  142.  
  143.     /* Send the image directly to the printer. */
  144.  
  145.       fprintf(fp, "\033\022G%08lx \n\f", &o);
  146.  
  147.       fclose(fp);
  148.     
  149.     free(slmbuf);
  150.     free(scanbuf);
  151.  
  152.     return (0);
  153.  
  154. }
  155.