home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / GDEVSNFB.C < prev    next >
C/C++ Source or Header  |  1992-02-28  |  3KB  |  118 lines

  1. /* Copyright (C) 1989, 1990, 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. /* gdevsnfb.c */
  21. /* Sony News frame buffer driver for GhostScript */
  22. #include "gdevprn.h"
  23. /*#include <sys/types.h> problems with ushort! */
  24. typedef    char *    caddr_t;
  25. typedef    long    off_t;
  26. #include <sys/uio.h>
  27. #include <newsiop/framebuf.h>
  28.  
  29. /* The device descriptor */
  30. private dev_proc_open_device(sonyfb_open);
  31. private dev_proc_output_page(sonyfb_output_page);
  32. private dev_proc_close_device(sonyfb_close);
  33. private gx_device_procs sonyfb_procs =
  34.   prn_procs(sonyfb_open, sonyfb_output_page, sonyfb_close);
  35. gx_device_printer gs_sonyfb_device =
  36.   prn_device(sonyfb_procs, "sonyfb",
  37.     102.4,                /* width_10ths */
  38.     103.2,                /* height_10ths */
  39.     100,                /* x_dpi */
  40.     100,                /* y_dpi */
  41.     0,0,0,0,            /* margins */
  42.     1, 0);
  43.  
  44. private int fb_file = -1;
  45. sPrimRect prect;
  46.  
  47. private int
  48. sonyfb_open(gx_device *dev)
  49. {
  50.   sScrType stype;
  51.  
  52.   if(fb_file < 0)
  53.     if((fb_file = open("/dev/fb", 2)) < 0)
  54.       perror("open failed");
  55.     else
  56.       if(ioctl(fb_file, FBIOCGETSCRTYPE, &stype) < 0)
  57.     perror("ioctl failed");
  58.       else
  59.     prect.rect = stype.visiblerect;
  60.  
  61.   return gdev_prn_open(dev);
  62. }
  63.  
  64. private int
  65. sonyfb_close(gx_device *dev)
  66. {
  67.   if(fb_file >= 0)
  68.     {
  69.       close(fb_file);
  70.       fb_file = -1;
  71.     }
  72.   return gdev_prn_close(dev);
  73. }
  74.  
  75. #define FRAME_WIDTH    1024
  76.  
  77. /* Send the page to the printer. */
  78. private int
  79. sonyfb_output_page(gx_device *dev, int num_copies, int flush)
  80. {
  81.   int l, i, byte_width, height;
  82.   unsigned char *bm, *fbs, *fb;
  83.  
  84.   byte_width = (dev->width + 7) / 8;
  85.   height = dev->height;
  86.   bm     = (typeof(bm))prn_dev->mem.base;
  87.  
  88.   prect.refPoint.x = 0;
  89.   prect.refPoint.y = 0;
  90.   prect.ptnRect = prect.rect;
  91.   
  92.   prect.ptnBM.type  = BM_MEM;
  93.   prect.ptnBM.depth = 1;
  94.   prect.ptnBM.width = (byte_width + 1) / 2;
  95.   prect.ptnBM.rect.origin.x = 0;
  96.   prect.ptnBM.rect.origin.y = 0;
  97.   prect.ptnBM.rect.extent.x = byte_width * 8; /* width in 16bit words */
  98.   prect.ptnBM.rect.extent.y = height;
  99.   prect.ptnBM.base = (typeof(prect.ptnBM.base))bm;
  100.   
  101.   prect.fore_color = 1;
  102.   prect.aux_color = 0;
  103.   prect.planemask = FB_PLANEALL;
  104.   prect.transp = 0;
  105.   prect.func = BF_S;
  106.   prect.clip = prect.rect;
  107.   prect.drawBM.type  = BM_FB;
  108.   prect.drawBM.depth = 1;
  109.   prect.drawBM.width = (prect.rect.extent.x + 15) / 16;
  110.   prect.drawBM.rect = prect.rect;
  111.   prect.drawBM.base = 0;
  112.   
  113.   if(ioctl(fb_file, FBIOCRECTANGLE, &prect) < 0)
  114.     perror("rect ioctl failed");
  115.  
  116.   return 0;
  117. }
  118.