Home | History | Annotate | Line # | Download | only in dev
grfabs_reg.h revision 1.3
      1  1.1  chopps /*
      2  1.1  chopps  * Copyright (c) 1994 Christian E. Hopps
      3  1.1  chopps  * All rights reserved.
      4  1.1  chopps  *
      5  1.1  chopps  * Redistribution and use in source and binary forms, with or without
      6  1.1  chopps  * modification, are permitted provided that the following conditions
      7  1.1  chopps  * are met:
      8  1.1  chopps  * 1. Redistributions of source code must retain the above copyright
      9  1.1  chopps  *    notice, this list of conditions and the following disclaimer.
     10  1.1  chopps  * 2. Redistributions in binary form must reproduce the above copyright
     11  1.1  chopps  *    notice, this list of conditions and the following disclaimer in the
     12  1.1  chopps  *    documentation and/or other materials provided with the distribution.
     13  1.1  chopps  * 3. All advertising materials mentioning features or use of this software
     14  1.1  chopps  *    must display the following acknowledgement:
     15  1.1  chopps  *      This product includes software developed by Christian E. Hopps.
     16  1.1  chopps  * 4. The name of the author may not be used to endorse or promote products
     17  1.1  chopps  *    derived from this software without specific prior written permission
     18  1.1  chopps  *
     19  1.1  chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  1.1  chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  1.1  chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  1.1  chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  1.1  chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  1.1  chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  1.1  chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  1.1  chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  1.1  chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  1.1  chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  1.1  chopps  *
     30  1.3  chopps  *	$Id: grfabs_reg.h,v 1.3 1994/06/29 13:13:08 chopps Exp $
     31  1.1  chopps  */
     32  1.1  chopps 
     33  1.1  chopps #if ! defined (_GRFABS_REG_H)
     34  1.1  chopps #define _GRFABS_REG_H
     35  1.1  chopps 
     36  1.2  chopps struct point {
     37  1.1  chopps     long x;
     38  1.1  chopps     long y;
     39  1.2  chopps };
     40  1.2  chopps typedef struct point point_t;
     41  1.1  chopps 
     42  1.2  chopps struct dimension {
     43  1.1  chopps     u_long width;
     44  1.1  chopps     u_long height;
     45  1.2  chopps };
     46  1.2  chopps typedef struct dimension dimen_t;
     47  1.1  chopps 
     48  1.2  chopps struct box {
     49  1.1  chopps     long x;
     50  1.1  chopps     long y;
     51  1.1  chopps     u_long width;
     52  1.1  chopps     u_long height;
     53  1.2  chopps };
     54  1.2  chopps typedef struct box box_t;
     55  1.1  chopps 
     56  1.2  chopps struct rectangle {
     57  1.1  chopps     long left;
     58  1.1  chopps     long top;
     59  1.1  chopps     long right;
     60  1.1  chopps     long bottom;
     61  1.2  chopps };
     62  1.2  chopps 
     63  1.2  chopps typedef struct rectangle rect_t;
     64  1.1  chopps 
     65  1.1  chopps typedef struct bitmap bmap_t;
     66  1.1  chopps typedef struct colormap colormap_t;
     67  1.1  chopps typedef struct view view_t;
     68  1.1  chopps typedef struct display_mode dmode_t;
     69  1.1  chopps typedef struct monitor monitor_t;
     70  1.1  chopps 
     71  1.2  chopps LIST_HEAD(monitor_list, monitor);
     72  1.2  chopps extern struct monitor_list *monitors;
     73  1.2  chopps 
     74  1.1  chopps /*
     75  1.1  chopps  * Bitmap stuff.
     76  1.1  chopps  */
     77  1.1  chopps 
     78  1.2  chopps /*
     79  1.2  chopps  * Note structure is 5 long words big.  This may come in handy for
     80  1.1  chopps  * contiguous allocations
     81  1.1  chopps  *
     82  1.1  chopps  * Please do fill in everything correctly this is the main input for
     83  1.1  chopps  * all other programs.  In other words all problems with RTG start here.
     84  1.1  chopps  * If you do not mimic everyone else exactly problems will appear.
     85  1.1  chopps  * If you need a template look at alloc_bitmap() in grf_cc.c.
     86  1.1  chopps  *
     87  1.1  chopps  * WARNING: the plane array is only for convience, all data for bitplanes
     88  1.2  chopps  *	MUST be contiguous.  This is for mapping purposes.  The reason
     89  1.2  chopps  *	for the plane pointers and row_mod is to support interleaving
     90  1.2  chopps  *	on monitors that wish to support this.
     91  1.2  chopps  *
     92  1.1  chopps  * 2nd Warning: Also don't get funky with these pointers you are expected
     93  1.2  chopps  *	to place the start of mappable plane data in ``hardware_address'',
     94  1.2  chopps  *	``hardware_address'' is the only thing that /dev/view checks and it
     95  1.2  chopps  *	expects the planes to follow with no padding in between.  If you have
     96  1.2  chopps  *	special alignment requirements make use of the given fields
     97  1.2  chopps  *	so that the entire contiguous plane data is exactly:
     98  1.2  chopps  *	bytes_per_row*height*depth long starting at the physical address
     99  1.2  chopps  *	contained within hardware_address.
    100  1.2  chopps  *
    101  1.2  chopps  * Final Warning: Plane data must begin on a PAGE address and the allocation
    102  1.2  chopps  *	must be ``n'' PAGES big do to mapping requirements (otherwise the
    103  1.2  chopps  *	user could write over non-allocated memory.
    104  1.2  chopps  *
    105  1.1  chopps  */
    106  1.1  chopps struct bitmap {
    107  1.2  chopps     u_short   bytes_per_row;	  /* number of bytes per display row. */
    108  1.2  chopps     u_short   row_mod;		  /* number of bytes to reach next row. */
    109  1.2  chopps     u_short   rows;		  /* number of display rows. */
    110  1.2  chopps     u_short   depth;		  /* depth of bitmap. */
    111  1.2  chopps     u_short   flags;		  /* flags. */
    112  1.1  chopps     u_short   pad;
    113  1.2  chopps     u_char  *blit_temp;		  /* private monitor buffer. */
    114  1.2  chopps     u_char **plane;		  /* plane data for bitmap. */
    115  1.2  chopps     u_char  *hardware_address;	  /* mappable bitplane pointer. */
    116  1.1  chopps };
    117  1.1  chopps 
    118  1.1  chopps enum bitmap_flag_bits {
    119  1.2  chopps     BMB_CLEAR,			  /* init only. */
    120  1.2  chopps     BMB_INTERLEAVED,		  /* init/read. */
    121  1.3  chopps     BMB_ALIGN64,		  /* init/read. */
    122  1.1  chopps };
    123  1.1  chopps 
    124  1.1  chopps enum bitmap_flags {
    125  1.1  chopps     BMF_CLEAR = 1 << BMB_CLEAR,			  /* init only. */
    126  1.1  chopps     BMF_INTERLEAVED = 1 << BMB_INTERLEAVED,	  /* init/read. */
    127  1.3  chopps     BMF_ALIGN64 = 1 << BMB_ALIGN64		  /* init/read. */
    128  1.1  chopps };
    129  1.1  chopps 
    130  1.1  chopps /* Use these macros to find misc. sizes of actual bitmap */
    131  1.2  chopps #define BM_WIDTH(b)	((b)->bytes_per_row << 3)
    132  1.2  chopps #define BM_HEIGHT(b)	((b)->rows)
    133  1.2  chopps #define BM_ROW(b,p,l) \
    134  1.2  chopps     ((b)->plane[p] + (((b)->bytes_per_row + (b)->row_mod) * l))
    135  1.1  chopps 
    136  1.1  chopps /*
    137  1.1  chopps  * Colormap stuff.
    138  1.1  chopps  */
    139  1.1  chopps 
    140  1.2  chopps /*
    141  1.2  chopps  * valid masks are a bitfield of zeros followed by ones that indicate
    142  1.1  chopps  * which mask are valid for each component.  The ones and zeros will
    143  1.1  chopps  * be contiguous so adding one to this value yields the number of
    144  1.1  chopps  * levels for that component.
    145  1.1  chopps  * -ch
    146  1.1  chopps  */
    147  1.1  chopps 
    148  1.1  chopps struct colormap {
    149  1.1  chopps     u_char type;	/* what type of entries these are. */
    150  1.1  chopps     union {
    151  1.1  chopps         /* CM_GREYSCALE */
    152  1.1  chopps         u_char grey;
    153  1.1  chopps #define grey_mask  valid_mask.grey
    154  1.1  chopps         /* CM_COLOR */
    155  1.1  chopps         struct {
    156  1.1  chopps             u_char red;
    157  1.1  chopps #define red_mask   valid_mask.rgb_mask.red
    158  1.1  chopps             u_char green;
    159  1.1  chopps #define green_mask valid_mask.rgb_mask.green
    160  1.1  chopps             u_char blue;
    161  1.1  chopps #define blue_mask  valid_mask.rgb_mask.blue
    162  1.1  chopps         } rgb_mask;
    163  1.1  chopps     } valid_mask;
    164  1.1  chopps     u_short first;	/* what color register does entry[0] refer to. */
    165  1.1  chopps     u_short size;	/* number of entries */
    166  1.2  chopps     u_long *entry;	/* the table of actual color values. */
    167  1.1  chopps };
    168  1.1  chopps 
    169  1.1  chopps enum colormap_type {
    170  1.2  chopps     CM_MONO,		/* only on or off allowed */
    171  1.2  chopps     CM_GREYSCALE,	/* grey vals. */
    172  1.2  chopps     CM_COLOR		/* RGB vals. */
    173  1.1  chopps };
    174  1.1  chopps 
    175  1.2  chopps #define CM_FIXVAL(x) (0xff & (x))
    176  1.1  chopps 
    177  1.1  chopps /* these macros are for creating entries */
    178  1.2  chopps #define MAKE_COLOR_ENTRY(r,g,b) \
    179  1.2  chopps     (CM_FIXVAL(r) << 16 | CM_FIXVAL(g) << 8 | CM_FIXVAL(b))
    180  1.2  chopps #define MAKE_MONO_ENTRY(x)	((x) ? 1 : 0)
    181  1.2  chopps #define MAKE_GREY_ENTRY(l)	CM_FIXVAL(l)
    182  1.2  chopps 
    183  1.2  chopps #define CM_LTOW(v) \
    184  1.2  chopps     (((0x000F0000 & (v)) >> 8) | ((0x00000F00 & (v)) >> 4) | (0xF & (v)))
    185  1.2  chopps #define CM_WTOL(v) \
    186  1.2  chopps     (((0xF00 & (v)) << 8) | ((0x0F0 & (v)) << 4) | (0xF & (v)))
    187  1.1  chopps 
    188  1.1  chopps /*
    189  1.1  chopps  * View stuff.
    190  1.1  chopps  */
    191  1.1  chopps typedef void remove_view_func (view_t *v);
    192  1.1  chopps typedef void free_view_func (view_t *v);
    193  1.1  chopps typedef void display_view_func (view_t *v);
    194  1.1  chopps typedef dmode_t *get_mode_func (view_t *v);
    195  1.1  chopps typedef int get_colormap_func (view_t *v, colormap_t *);
    196  1.1  chopps typedef int use_colormap_func (view_t *v, colormap_t *);
    197  1.1  chopps 
    198  1.1  chopps struct view {
    199  1.2  chopps     bmap_t  *bitmap;			/* bitmap. */
    200  1.2  chopps     box_t    display;			/* viewable area. */
    201  1.2  chopps     void    *data;			/* view specific data. */
    202  1.1  chopps 
    203  1.1  chopps     /* functions */
    204  1.2  chopps     display_view_func *display_view;	/* make this view active */
    205  1.2  chopps     remove_view_func  *remove_view;	/* remove this view if active */
    206  1.2  chopps     free_view_func    *free_view;	/* free this view */
    207  1.2  chopps     get_mode_func     *get_display_mode;/* get the mode this view belongs to */
    208  1.2  chopps     get_colormap_func *get_colormap;	/* get a color map for registers */
    209  1.2  chopps     use_colormap_func *use_colormap;	/* use color map to load registers */
    210  1.1  chopps };
    211  1.1  chopps 
    212  1.2  chopps #define VDISPLAY_LINE(v, p, l) ((v)->bitmap->plane[(p)] +\
    213  1.2  chopps 	(((v)->bitmap->bytes_per_row + (v)->bitmap->row_mod) * l))
    214  1.1  chopps 
    215  1.1  chopps /*
    216  1.1  chopps  * Mode stuff
    217  1.1  chopps  */
    218  1.1  chopps 
    219  1.1  chopps typedef view_t *alloc_view_func (dmode_t *mode, dimen_t *dim, u_char depth);
    220  1.1  chopps typedef view_t *get_current_view_func (dmode_t *);
    221  1.1  chopps typedef monitor_t  *get_monitor_func (dmode_t *);
    222  1.1  chopps 
    223  1.1  chopps struct display_mode {
    224  1.2  chopps     LIST_ENTRY(display_mode) link;
    225  1.2  chopps     u_char    *name;			/* logical name for mode. */
    226  1.2  chopps     dimen_t    nominal_size;		/* best fit. */
    227  1.2  chopps     void      *data;			/* mode specific flags. */
    228  1.2  chopps     alloc_view_func       *alloc_view;	/* allocate a view for this mode. */
    229  1.2  chopps     get_current_view_func *get_current_view;	/* get active view. */
    230  1.2  chopps     get_monitor_func      *get_monitor;	/* get monitor that mode belongs to */
    231  1.1  chopps };
    232  1.1  chopps 
    233  1.1  chopps /*
    234  1.1  chopps  * Monitor stuff.
    235  1.1  chopps  */
    236  1.1  chopps typedef void     vbl_handler_func (void *);
    237  1.1  chopps typedef dmode_t *get_next_mode_func (dmode_t *);
    238  1.1  chopps typedef dmode_t *get_current_mode_func (void);
    239  1.1  chopps typedef dmode_t *get_best_mode_func (dimen_t *size, u_char depth);
    240  1.1  chopps typedef bmap_t *alloc_bitmap_func (u_short w, u_short h, u_short d, u_short f);
    241  1.1  chopps typedef void    free_bitmap_func (bmap_t *bm);
    242  1.1  chopps 
    243  1.1  chopps struct monitor {
    244  1.2  chopps     LIST_ENTRY(monitor) link; /* a link into the database. */
    245  1.2  chopps     u_char     *name;	/* a logical name for this monitor. */
    246  1.2  chopps     void       *data;	/* monitor specific data. */
    247  1.2  chopps     get_current_mode_func *get_current_mode;
    248  1.2  chopps     vbl_handler_func	*vbl_handler;	/* called on every vbl if not NULL */
    249  1.2  chopps     get_next_mode_func	*get_next_mode;	/* return next mode in list */
    250  1.2  chopps     get_best_mode_func	*get_best_mode; /* return mode that best fits */
    251  1.1  chopps 
    252  1.2  chopps     alloc_bitmap_func	*alloc_bitmap;
    253  1.2  chopps     free_bitmap_func	*free_bitmap;
    254  1.1  chopps };
    255  1.1  chopps 
    256  1.1  chopps /*
    257  1.1  chopps  * Misc draw related macros.
    258  1.1  chopps  */
    259  1.1  chopps 
    260  1.1  chopps #define BOX_2_RECT(b,r) do { \
    261  1.2  chopps     (r)->left = (b)->x; (r)->top = (b)->y; \
    262  1.2  chopps     (r)->right = (b)->x + (b)->width -1; \
    263  1.2  chopps     (r)->bottom = (b)->y + (b)->height -1; \
    264  1.2  chopps     } while (0)
    265  1.1  chopps 
    266  1.1  chopps #define RECT_2_BOX(r,b) do { \
    267  1.2  chopps     (b)->x = (r)->left; \
    268  1.2  chopps     (b)->y = (r)->top; \
    269  1.2  chopps     (b)->width = (r)->right - (r)->left +1; \
    270  1.2  chopps     (b)->height = (r)->bottom - (r)->top +1; \
    271  1.2  chopps     } while(0)
    272  1.1  chopps 
    273  1.1  chopps #define INIT_BOX(b,xx,yy,ww,hh) do{(b)->x = xx; (b)->y = yy; (b)->width = ww; (b)->height = hh;}while (0)
    274  1.1  chopps #define INIT_RECT(rc,l,t,r,b) do{(rc)->left = l; (rc)->right = r; (rc)->top = t; (rc)->bottom = b;}while (0)
    275  1.1  chopps #define INIT_POINT(p,xx,yy) do {(p)->x = xx; (p)->y = yy;} while (0)
    276  1.1  chopps #define INIT_DIM(d,w,h) do {(d)->width = w; (d)->height = h;} while (0)
    277  1.1  chopps 
    278  1.1  chopps 
    279  1.1  chopps /*
    280  1.1  chopps  * Prototypes
    281  1.1  chopps  */
    282  1.1  chopps 
    283  1.1  chopps #if defined (__STDC__)
    284  1.1  chopps /* views */
    285  1.1  chopps view_t * grf_alloc_view (dmode_t *d, dimen_t *dim, u_char depth);
    286  1.1  chopps void grf_display_view (view_t *v);
    287  1.1  chopps void grf_remove_view (view_t *v);
    288  1.1  chopps void grf_free_view (view_t *v);
    289  1.1  chopps dmode_t *grf_get_display_mode (view_t *v);
    290  1.1  chopps int grf_get_colormap (view_t *v, colormap_t *cm);
    291  1.1  chopps int grf_use_colormap (view_t *v, colormap_t *cm);
    292  1.1  chopps /* modes */
    293  1.1  chopps view_t *grf_get_current_view (dmode_t *d);
    294  1.1  chopps monitor_t *grf_get_monitor (dmode_t *d);
    295  1.1  chopps /* monitors */
    296  1.1  chopps dmode_t * grf_get_next_mode (monitor_t *m, dmode_t *d);
    297  1.1  chopps dmode_t * grf_get_current_mode (monitor_t *);
    298  1.1  chopps dmode_t * grf_get_best_mode (monitor_t *m, dimen_t *size, u_char depth);
    299  1.1  chopps bmap_t  * grf_alloc_bitmap (monitor_t *m, u_short w, u_short h, u_short d, u_short f);
    300  1.1  chopps void grf_free_bitmap (monitor_t *m, bmap_t *bm);
    301  1.1  chopps #endif /* __STDC__ */
    302  1.1  chopps 
    303  1.1  chopps #endif /* _GRFABS_REG_H */
    304