Home | History | Annotate | Line # | Download | only in dev
      1  1.10   msaitoh /*	$NetBSD: grfabs_reg.h,v 1.10 2021/12/05 04:28:53 msaitoh Exp $	*/
      2   1.4       cgd 
      3   1.1    chopps /*
      4   1.1    chopps  * Copyright (c) 1994 Christian E. Hopps
      5   1.1    chopps  * All rights reserved.
      6   1.1    chopps  *
      7   1.1    chopps  * Redistribution and use in source and binary forms, with or without
      8   1.1    chopps  * modification, are permitted provided that the following conditions
      9   1.1    chopps  * are met:
     10   1.1    chopps  * 1. Redistributions of source code must retain the above copyright
     11   1.1    chopps  *    notice, this list of conditions and the following disclaimer.
     12   1.1    chopps  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1    chopps  *    notice, this list of conditions and the following disclaimer in the
     14   1.1    chopps  *    documentation and/or other materials provided with the distribution.
     15   1.1    chopps  * 3. All advertising materials mentioning features or use of this software
     16   1.1    chopps  *    must display the following acknowledgement:
     17   1.1    chopps  *      This product includes software developed by Christian E. Hopps.
     18   1.1    chopps  * 4. The name of the author may not be used to endorse or promote products
     19   1.1    chopps  *    derived from this software without specific prior written permission
     20   1.1    chopps  *
     21   1.1    chopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1    chopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1    chopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1    chopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1    chopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1    chopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1    chopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1    chopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1    chopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1    chopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     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.7   aymeric  * contiguous allocations
     81   1.7   aymeric  *
     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.10   msaitoh  * WARNING: the plane array is only for convenience, 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.7   aymeric  *	on monitors that wish to support this.
     91   1.7   aymeric  *
     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.7   aymeric  *
    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.7   aymeric  *
    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.7   aymeric  * valid masks are a bitfield of zeros followed by ones that indicate
    142   1.7   aymeric  * 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.7   aymeric  * levels for that component.
    145   1.7   aymeric  * -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.6  jandberg 
    188   1.6  jandberg #define CM_GET_RED(entry)    (((entry) & 0xFF0000) >> 16)
    189   1.6  jandberg #define CM_GET_GREEN(entry)  (((entry) & 0x00FF00) >> 8)
    190   1.6  jandberg #define CM_GET_BLUE(entry)   (((entry) & 0x0000FF))
    191   1.6  jandberg #define CM_GET_GREY(entry)   (((entry) & 0x0000FF))
    192   1.6  jandberg #define CM_GET_MONO(entry)   (((entry) & 0x000001))
    193   1.1    chopps 
    194   1.1    chopps /*
    195   1.1    chopps  * View stuff.
    196   1.1    chopps  */
    197   1.7   aymeric typedef void remove_view_func (view_t *v);
    198   1.7   aymeric typedef void free_view_func (view_t *v);
    199   1.7   aymeric typedef void display_view_func (view_t *v);
    200   1.7   aymeric typedef dmode_t *get_mode_func (view_t *v);
    201   1.1    chopps typedef int get_colormap_func (view_t *v, colormap_t *);
    202   1.1    chopps typedef int use_colormap_func (view_t *v, colormap_t *);
    203   1.1    chopps 
    204   1.1    chopps struct view {
    205   1.2    chopps     bmap_t  *bitmap;			/* bitmap. */
    206   1.2    chopps     box_t    display;			/* viewable area. */
    207   1.2    chopps     void    *data;			/* view specific data. */
    208   1.1    chopps 
    209   1.1    chopps     /* functions */
    210   1.2    chopps     display_view_func *display_view;	/* make this view active */
    211   1.2    chopps     remove_view_func  *remove_view;	/* remove this view if active */
    212   1.2    chopps     free_view_func    *free_view;	/* free this view */
    213   1.2    chopps     get_mode_func     *get_display_mode;/* get the mode this view belongs to */
    214   1.2    chopps     get_colormap_func *get_colormap;	/* get a color map for registers */
    215   1.2    chopps     use_colormap_func *use_colormap;	/* use color map to load registers */
    216   1.1    chopps };
    217   1.1    chopps 
    218   1.2    chopps #define VDISPLAY_LINE(v, p, l) ((v)->bitmap->plane[(p)] +\
    219   1.2    chopps 	(((v)->bitmap->bytes_per_row + (v)->bitmap->row_mod) * l))
    220   1.1    chopps 
    221   1.1    chopps /*
    222   1.1    chopps  * Mode stuff
    223   1.1    chopps  */
    224   1.1    chopps 
    225   1.1    chopps typedef view_t *alloc_view_func (dmode_t *mode, dimen_t *dim, u_char depth);
    226   1.1    chopps typedef view_t *get_current_view_func (dmode_t *);
    227   1.1    chopps typedef monitor_t  *get_monitor_func (dmode_t *);
    228   1.7   aymeric 
    229   1.1    chopps struct display_mode {
    230   1.2    chopps     LIST_ENTRY(display_mode) link;
    231   1.8       jmc     const u_char    *name;		/* logical name for mode. */
    232   1.2    chopps     dimen_t    nominal_size;		/* best fit. */
    233   1.2    chopps     void      *data;			/* mode specific flags. */
    234   1.2    chopps     alloc_view_func       *alloc_view;	/* allocate a view for this mode. */
    235   1.2    chopps     get_current_view_func *get_current_view;	/* get active view. */
    236   1.2    chopps     get_monitor_func      *get_monitor;	/* get monitor that mode belongs to */
    237   1.1    chopps };
    238   1.1    chopps 
    239   1.1    chopps /*
    240   1.1    chopps  * Monitor stuff.
    241   1.1    chopps  */
    242   1.1    chopps typedef void     vbl_handler_func (void *);
    243   1.1    chopps typedef dmode_t *get_next_mode_func (dmode_t *);
    244   1.1    chopps typedef dmode_t *get_current_mode_func (void);
    245   1.1    chopps typedef dmode_t *get_best_mode_func (dimen_t *size, u_char depth);
    246   1.1    chopps typedef bmap_t *alloc_bitmap_func (u_short w, u_short h, u_short d, u_short f);
    247   1.1    chopps typedef void    free_bitmap_func (bmap_t *bm);
    248   1.1    chopps 
    249   1.1    chopps struct monitor {
    250   1.2    chopps     LIST_ENTRY(monitor) link; /* a link into the database. */
    251   1.8       jmc     const u_char     *name;   /* a logical name for this monitor. */
    252   1.2    chopps     void       *data;	/* monitor specific data. */
    253   1.2    chopps     get_current_mode_func *get_current_mode;
    254   1.2    chopps     vbl_handler_func	*vbl_handler;	/* called on every vbl if not NULL */
    255   1.2    chopps     get_next_mode_func	*get_next_mode;	/* return next mode in list */
    256   1.2    chopps     get_best_mode_func	*get_best_mode; /* return mode that best fits */
    257   1.7   aymeric 
    258   1.2    chopps     alloc_bitmap_func	*alloc_bitmap;
    259   1.2    chopps     free_bitmap_func	*free_bitmap;
    260   1.1    chopps };
    261   1.1    chopps 
    262   1.1    chopps /*
    263   1.1    chopps  * Misc draw related macros.
    264   1.1    chopps  */
    265   1.1    chopps 
    266   1.1    chopps #define BOX_2_RECT(b,r) do { \
    267   1.2    chopps     (r)->left = (b)->x; (r)->top = (b)->y; \
    268   1.2    chopps     (r)->right = (b)->x + (b)->width -1; \
    269   1.2    chopps     (r)->bottom = (b)->y + (b)->height -1; \
    270   1.2    chopps     } while (0)
    271   1.1    chopps 
    272   1.1    chopps #define RECT_2_BOX(r,b) do { \
    273   1.2    chopps     (b)->x = (r)->left; \
    274   1.2    chopps     (b)->y = (r)->top; \
    275   1.2    chopps     (b)->width = (r)->right - (r)->left +1; \
    276   1.2    chopps     (b)->height = (r)->bottom - (r)->top +1; \
    277   1.2    chopps     } while(0)
    278   1.1    chopps 
    279   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)
    280   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)
    281   1.1    chopps #define INIT_POINT(p,xx,yy) do {(p)->x = xx; (p)->y = yy;} while (0)
    282   1.1    chopps #define INIT_DIM(d,w,h) do {(d)->width = w; (d)->height = h;} while (0)
    283   1.1    chopps 
    284   1.1    chopps 
    285   1.1    chopps /*
    286   1.1    chopps  * Prototypes
    287   1.1    chopps  */
    288   1.1    chopps 
    289   1.1    chopps /* views */
    290   1.7   aymeric view_t * grf_alloc_view(dmode_t *d, dimen_t *dim, u_char depth);
    291   1.7   aymeric void grf_display_view(view_t *v);
    292   1.7   aymeric void grf_remove_view(view_t *v);
    293   1.7   aymeric void grf_free_view(view_t *v);
    294   1.7   aymeric dmode_t *grf_get_display_mode(view_t *v);
    295   1.7   aymeric int grf_get_colormap(view_t *v, colormap_t *cm);
    296   1.7   aymeric int grf_use_colormap(view_t *v, colormap_t *cm);
    297   1.5     veego 
    298   1.1    chopps /* modes */
    299   1.7   aymeric view_t *grf_get_current_view(dmode_t *d);
    300   1.7   aymeric monitor_t *grf_get_monitor(dmode_t *d);
    301   1.5     veego 
    302   1.1    chopps /* monitors */
    303   1.7   aymeric dmode_t * grf_get_next_mode(monitor_t *m, dmode_t *d);
    304   1.7   aymeric dmode_t * grf_get_current_mode(monitor_t *);
    305   1.7   aymeric dmode_t * grf_get_best_mode(monitor_t *m, dimen_t *size, u_char depth);
    306   1.7   aymeric bmap_t  * grf_alloc_bitmap(monitor_t *m, u_short w, u_short h,
    307   1.7   aymeric 				u_short d, u_short f);
    308   1.7   aymeric void grf_free_bitmap(monitor_t *m, bmap_t *bm);
    309   1.5     veego 
    310   1.7   aymeric int grfcc_probe(void);
    311   1.1    chopps 
    312   1.1    chopps #endif /* _GRFABS_REG_H */
    313