home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GDEVPCFB.H < prev    next >
C/C++ Source or Header  |  1994-07-27  |  6KB  |  168 lines

  1. /* Copyright (C) 1989, 1992, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevpcfb.h */
  20. /* IBM PC frame buffer definitions */
  21. #ifdef __MSDOS__
  22. #  include "dos_.h"
  23. typedef union REGS registers;
  24. #endif
  25.  
  26. /* For testing, the 16-color display may be defined as a monochrome, */
  27. /* 8-color, or 16-color device. */
  28. #define ega_bits_of_color 2        /* 0, 1, or 2 */
  29. #define rgb_max ega_bits_of_color
  30.  
  31. #ifndef USE_ASM
  32. #  define USE_ASM 0            /* don't use assembly language */
  33. #endif
  34.  
  35. /* Define the short (integer) version of "transparent" color. */
  36. /* ****** Depends on gx_no_color_index being all 1's. ******/
  37. #define no_color ((int)gx_no_color_index)
  38.  
  39. /* Procedures */
  40.  
  41.     /* See gxdevice.h for the definitions of the procedures. */
  42.  
  43. dev_proc_open_device(ega_open);
  44. dev_proc_close_device(ega_close);
  45. dev_proc_fill_rectangle(ega_fill_rectangle);
  46. dev_proc_tile_rectangle(ega_tile_rectangle);
  47. dev_proc_copy_mono(ega_copy_mono);
  48. dev_proc_copy_color(ega_copy_color);
  49. dev_proc_get_bits(ega_get_bits);
  50.  
  51. /* Procedures used by gdevpcfb.c */
  52. void    ega_set_signals(P1(gx_device *));
  53. int    ega_get_mode(P0());
  54. void    ega_set_mode(P1(int));
  55.  
  56. /* Types for frame buffer pointers. */
  57. typedef byte *fb_ptr;
  58. typedef volatile byte *volatile_fb_ptr;
  59.  
  60. /* Define the nominal page height in inches. */
  61. #ifdef A4
  62. #  define PAGE_HEIGHT_INCHES 11.0
  63. #else
  64. #  define PAGE_HEIGHT_INCHES 11.69
  65. #endif
  66.  
  67. /* The device descriptor */
  68. typedef struct gx_device_ega_s gx_device_ega;
  69. struct gx_device_ega_s {
  70.     gx_device_common;
  71.     int raster;            /* frame buffer bytes per line */
  72.     int fb_seg_mult;        /* multiplier for segment part */
  73.                     /* of frame buffer pointer */
  74.     int fb_byte_mult;        /* multiplier for word part ditto */
  75. #define mk_fb_ptr(x, y)\
  76.   (fb_dev->fb_byte_mult == 0 ?\
  77.    (fb_ptr)MK_PTR(regen + (y) * (fb_dev->fb_seg_mult), (x) >> 3) :\
  78.    (fb_ptr)MK_PTR(regen + ((y) >> 4) * (fb_dev->fb_seg_mult),\
  79.          (((y) & 15) * fb_dev->fb_byte_mult) + ((x) >> 3)))
  80.     int video_mode;
  81. };
  82.  
  83. /* Macro for creating instances */
  84. /* The initial parameters map an appropriate fraction of */
  85. /* the screen to a full-page coordinate space. */
  86. /* This may or may not be what is desired! */
  87. #define ega_device(dev_name, procs, fb_raster, screen_height, aspect_ratio, video_mode)\
  88.    {    sizeof(gx_device_ega),\
  89.     &procs,\
  90.     dev_name,\
  91.     fb_raster * 8, screen_height,\
  92.       (screen_height * (aspect_ratio)) / PAGE_HEIGHT_INCHES,    /* x dpi */\
  93.       screen_height / PAGE_HEIGHT_INCHES,        /* y dpi */\
  94.     no_margins,\
  95.        {    (rgb_max ? 3 : 1),    /* num_components */\
  96.         4,            /* depth */\
  97.         (rgb_max ? rgb_max : 1),    /* gray_max */\
  98.         rgb_max,\
  99.         3,            /* dither_gray */\
  100.         (rgb_max ? rgb_max + 1 : 0)    /* dither_rgb */\
  101.        },\
  102.     dev_init_misc,\
  103.     { 0 },            /* std_procs */\
  104.     fb_raster,\
  105.     (fb_raster & 15 ? fb_raster : fb_raster >> 4),\
  106.     (fb_raster & 15 ? fb_raster : 0),\
  107.     video_mode\
  108.    }
  109.  
  110. /* Define the device port and register numbers, and the regen map base */
  111. #define seq_addr 0x3c4
  112. #define s_map 2
  113. #define set_s_map(mask) outport2(seq_addr, s_map, mask)
  114. #define graph_addr 0x3ce
  115. #define g_const 0            /* set/reset */
  116. #define set_g_const(color) outport2(graph_addr, g_const, color)
  117. #define g_const_map 1            /* enable set/reset */
  118. #define set_g_const_map(map) outport2(graph_addr, g_const_map, map)
  119. #define g_function 3
  120. #  define gf_WRITE 0
  121. #  define gf_AND 8
  122. #  define gf_OR 0x10
  123. #  define gf_XOR 0x18
  124. #define set_g_function(func) outport2(graph_addr, g_function, func)
  125. #define g_read_plane 4
  126. #define set_g_read_plane(plane) outport2(graph_addr, g_read_plane, plane)
  127. #define g_mode 5
  128. #  define gm_DATA 0
  129. #  define gm_FILL 2
  130. #define set_g_mode(mode) outport2(graph_addr, g_mode, mode)
  131. #define g_mask 8
  132. #define set_g_mask(mask) outport2(graph_addr, g_mask, mask)
  133. #define select_g_mask() outportb(graph_addr, g_mask)
  134. #define out_g_mask(mask) outportb(graph_addr+1, mask)
  135. #define regen 0xa000
  136.  
  137. /* Define access to the frame buffer and the video registers */
  138. /* according to whether we are on a DOS system or a Unix system. */
  139.  
  140. #if defined(M_UNIX) || defined(M_XENIX) || defined(UNIX) || defined(SYSV)
  141.  
  142.         /* SCO Unix/Xenix or AT&T SVR4. */
  143.  
  144. #undef outportb
  145. void    outportb(P2(uint, byte));
  146. void    outport2(P3(uint, byte, byte));
  147.  
  148. /* Redefine mk_fb_ptr -- no segmented addressing. */
  149.  
  150. #undef mk_fb_ptr
  151. extern fb_ptr fb_addr;
  152. #define mk_fb_ptr(x, y)    (fb_addr + (y) * (fb_dev->raster) + ((x) >> 3))
  153.  
  154. #else
  155.  
  156.         /* MS-DOS */
  157.  
  158. /* outportb is defined in dos_.h */
  159. #define outport2(port, index, data)\
  160.   (outportb(port, index), outportb((port)+1, data))
  161.  
  162. #endif
  163.  
  164. /* Fetch and discard a byte.  Prevent the compiler from */
  165. /* optimizing this away. */
  166. static unsigned char byte_discard_;
  167. #define byte_discard(expr) byte_discard_ = (expr)
  168.