grfabs_reg.h revision 1.1 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.1 chopps * $Id: grfabs_reg.h,v 1.1 1994/02/13 21:10:36 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.1 chopps typedef struct point {
37 1.1 chopps long x;
38 1.1 chopps long y;
39 1.1 chopps } point_t;
40 1.1 chopps
41 1.1 chopps typedef struct dimension {
42 1.1 chopps u_long width;
43 1.1 chopps u_long height;
44 1.1 chopps } dimen_t;
45 1.1 chopps
46 1.1 chopps typedef struct box {
47 1.1 chopps long x;
48 1.1 chopps long y;
49 1.1 chopps u_long width;
50 1.1 chopps u_long height;
51 1.1 chopps } box_t;
52 1.1 chopps
53 1.1 chopps typedef struct rectangle {
54 1.1 chopps long left;
55 1.1 chopps long top;
56 1.1 chopps long right;
57 1.1 chopps long bottom;
58 1.1 chopps } rect_t;
59 1.1 chopps
60 1.1 chopps typedef struct bitmap bmap_t;
61 1.1 chopps typedef struct colormap colormap_t;
62 1.1 chopps typedef struct view view_t;
63 1.1 chopps typedef struct display_mode dmode_t;
64 1.1 chopps typedef struct monitor monitor_t;
65 1.1 chopps
66 1.1 chopps /*
67 1.1 chopps * Bitmap stuff.
68 1.1 chopps */
69 1.1 chopps
70 1.1 chopps /* Note structure is 5 long words big. This may come in handy for
71 1.1 chopps * contiguous allocations
72 1.1 chopps *
73 1.1 chopps * Please do fill in everything correctly this is the main input for
74 1.1 chopps * all other programs. In other words all problems with RTG start here.
75 1.1 chopps * If you do not mimic everyone else exactly problems will appear.
76 1.1 chopps * If you need a template look at alloc_bitmap() in grf_cc.c.
77 1.1 chopps *
78 1.1 chopps * WARNING: the plane array is only for convience, all data for bitplanes
79 1.1 chopps * MUST be contiguous. This is for mapping purposes. The reason
80 1.1 chopps * for the plane pointers and row_mod is to support interleaving
81 1.1 chopps * on monitors that wish to support this.
82 1.1 chopps *
83 1.1 chopps * 2nd Warning: Also don't get funky with these pointers you are expected
84 1.1 chopps * to place the start of mappable plane data in ``hardware_address'',
85 1.1 chopps * ``hardware_address'' is the only thing that /dev/view checks and it expects
86 1.1 chopps * the planes to follow with no padding in between. If you have
87 1.1 chopps * special alignment requirements make use of the given fields
88 1.1 chopps * so that the entire contiguous plane data is exactly:
89 1.1 chopps * bytes_per_row*height*depth long starting at the physical address
90 1.1 chopps * contained within hardware_address.
91 1.1 chopps *
92 1.1 chopps * Final Warning: Plane data must begin on a PAGE address and the allocation must
93 1.1 chopps * be ``n'' PAGES big do to mapping requirements (otherwise the
94 1.1 chopps * user could write over non-allocated memory.
95 1.1 chopps *
96 1.1 chopps */
97 1.1 chopps struct bitmap {
98 1.1 chopps u_short bytes_per_row; /* number of bytes per display row. */
99 1.1 chopps u_short row_mod; /* number of bytes to reach next row. */
100 1.1 chopps u_short rows; /* number of display rows. */
101 1.1 chopps u_short depth; /* depth of bitmap. */
102 1.1 chopps u_short flags; /* flags. */
103 1.1 chopps u_short pad;
104 1.1 chopps u_char *blit_temp; /* private monitor buffer. */
105 1.1 chopps u_char **plane; /* plane data for bitmap. */
106 1.1 chopps u_char *hardware_address; /* mappable bitplane pointer. */
107 1.1 chopps };
108 1.1 chopps
109 1.1 chopps enum bitmap_flag_bits {
110 1.1 chopps BMB_CLEAR, /* init only. */
111 1.1 chopps BMB_INTERLEAVED, /* init/read. */
112 1.1 chopps };
113 1.1 chopps
114 1.1 chopps enum bitmap_flags {
115 1.1 chopps BMF_CLEAR = 1 << BMB_CLEAR, /* init only. */
116 1.1 chopps BMF_INTERLEAVED = 1 << BMB_INTERLEAVED, /* init/read. */
117 1.1 chopps };
118 1.1 chopps
119 1.1 chopps /* Use these macros to find misc. sizes of actual bitmap */
120 1.1 chopps #define BM_WIDTH(b) (b->bytes_per_row << 3)
121 1.1 chopps #define BM_HEIGHT(b) (b->rows)
122 1.1 chopps #define BM_ROW(b,p,l) (b->plane[p] + ((b->bytes_per_row+b->row_mod)*l))
123 1.1 chopps
124 1.1 chopps /*
125 1.1 chopps * Colormap stuff.
126 1.1 chopps */
127 1.1 chopps
128 1.1 chopps /* valid masks are a bitfield of zeros followed by ones that indicate
129 1.1 chopps * which mask are valid for each component. The ones and zeros will
130 1.1 chopps * be contiguous so adding one to this value yields the number of
131 1.1 chopps * levels for that component.
132 1.1 chopps * -ch
133 1.1 chopps */
134 1.1 chopps
135 1.1 chopps struct colormap {
136 1.1 chopps u_char type; /* what type of entries these are. */
137 1.1 chopps union {
138 1.1 chopps /* CM_GREYSCALE */
139 1.1 chopps u_char grey;
140 1.1 chopps #define grey_mask valid_mask.grey
141 1.1 chopps /* CM_COLOR */
142 1.1 chopps struct {
143 1.1 chopps u_char red;
144 1.1 chopps #define red_mask valid_mask.rgb_mask.red
145 1.1 chopps u_char green;
146 1.1 chopps #define green_mask valid_mask.rgb_mask.green
147 1.1 chopps u_char blue;
148 1.1 chopps #define blue_mask valid_mask.rgb_mask.blue
149 1.1 chopps } rgb_mask;
150 1.1 chopps } valid_mask;
151 1.1 chopps u_short first; /* what color register does entry[0] refer to. */
152 1.1 chopps u_short size; /* number of entries */
153 1.1 chopps u_long *entry;/* the table of actual color values. */
154 1.1 chopps };
155 1.1 chopps
156 1.1 chopps enum colormap_type {
157 1.1 chopps CM_MONO, /* only on or off allowed */
158 1.1 chopps CM_GREYSCALE, /* grey vals. */
159 1.1 chopps CM_COLOR /* RGB vals. */
160 1.1 chopps };
161 1.1 chopps
162 1.1 chopps #define CM_FIXVAL(x) (0xff&x)
163 1.1 chopps
164 1.1 chopps /* these macros are for creating entries */
165 1.1 chopps #define MAKE_COLOR_ENTRY(r,g,b) (CM_FIXVAL(r) << 16 | CM_FIXVAL(g) << 8 | CM_FIXVAL(b))
166 1.1 chopps #define MAKE_MONO_ENTRY(x) (x ? 1 : 0)
167 1.1 chopps #define MAKE_GREY_ENTRY(l) CM_FIXVAL(l)
168 1.1 chopps
169 1.1 chopps #define CM_LTOW(v) (((0x000F0000&v)>>8)|((0x00000F00&v)>>4)|(0xF&v))
170 1.1 chopps #define CM_WTOL(v) (((0xF00&v)<<8)|((0x0F0&v)<<4)|(0xF&v))
171 1.1 chopps
172 1.1 chopps /*
173 1.1 chopps * View stuff.
174 1.1 chopps */
175 1.1 chopps typedef void remove_view_func (view_t *v);
176 1.1 chopps typedef void free_view_func (view_t *v);
177 1.1 chopps typedef void display_view_func (view_t *v);
178 1.1 chopps typedef dmode_t *get_mode_func (view_t *v);
179 1.1 chopps typedef int get_colormap_func (view_t *v, colormap_t *);
180 1.1 chopps typedef int use_colormap_func (view_t *v, colormap_t *);
181 1.1 chopps
182 1.1 chopps struct view {
183 1.1 chopps bmap_t *bitmap; /* bitmap. */
184 1.1 chopps box_t display; /* viewable area. */
185 1.1 chopps void *data; /* view specific data. */
186 1.1 chopps
187 1.1 chopps /* functions */
188 1.1 chopps display_view_func *display_view; /* make this view active */
189 1.1 chopps remove_view_func *remove_view; /* remove this view if active */
190 1.1 chopps free_view_func *free_view; /* free this view */
191 1.1 chopps get_mode_func *get_display_mode; /* get the mode this view belongs to */
192 1.1 chopps get_colormap_func *get_colormap; /* get a color map for registers */
193 1.1 chopps use_colormap_func *use_colormap; /* use color map to load registers */
194 1.1 chopps };
195 1.1 chopps
196 1.1 chopps #define VDISPLAY_LINE(v, p, l) ((v)->bitmap->plane[p] +\
197 1.1 chopps (((v)->bitmap->bytes_per_row+(v)->bitmap->row_mod)*l))
198 1.1 chopps
199 1.1 chopps /*
200 1.1 chopps * Mode stuff
201 1.1 chopps */
202 1.1 chopps
203 1.1 chopps typedef view_t *alloc_view_func (dmode_t *mode, dimen_t *dim, u_char depth);
204 1.1 chopps typedef view_t *get_current_view_func (dmode_t *);
205 1.1 chopps typedef monitor_t *get_monitor_func (dmode_t *);
206 1.1 chopps
207 1.1 chopps struct display_mode {
208 1.1 chopps dll_node_t node; /* a link into a monitor's mode list. */
209 1.1 chopps u_char *name; /* logical name for mode. */
210 1.1 chopps dimen_t nominal_size; /* best fit. */
211 1.1 chopps void *data; /* mode specific flags. */
212 1.1 chopps
213 1.1 chopps /* mode functions */
214 1.1 chopps alloc_view_func *alloc_view; /* allocate a view for this mode. */
215 1.1 chopps get_current_view_func *get_current_view; /* get active view. */
216 1.1 chopps get_monitor_func *get_monitor; /* get monitor that mode belongs to */
217 1.1 chopps };
218 1.1 chopps
219 1.1 chopps /*
220 1.1 chopps * Monitor stuff.
221 1.1 chopps */
222 1.1 chopps typedef void vbl_handler_func (void *);
223 1.1 chopps typedef dmode_t *get_next_mode_func (dmode_t *);
224 1.1 chopps typedef dmode_t *get_current_mode_func (void);
225 1.1 chopps typedef dmode_t *get_best_mode_func (dimen_t *size, u_char depth);
226 1.1 chopps typedef bmap_t *alloc_bitmap_func (u_short w, u_short h, u_short d, u_short f);
227 1.1 chopps typedef void free_bitmap_func (bmap_t *bm);
228 1.1 chopps
229 1.1 chopps struct monitor {
230 1.1 chopps dll_node_t node; /* a link into the database. */
231 1.1 chopps u_char *name; /* a logical name for this monitor. */
232 1.1 chopps void *data; /* monitor specific data. */
233 1.1 chopps
234 1.1 chopps /* funciton interface to this monitor. */
235 1.1 chopps vbl_handler_func *vbl_handler; /* gets called on every vbl if not NULL */
236 1.1 chopps get_next_mode_func *get_next_mode; /* return next mode in list */
237 1.1 chopps get_current_mode_func *get_current_mode; /* return active mode or NULL */
238 1.1 chopps get_best_mode_func *get_best_mode; /* return mode that best fits */
239 1.1 chopps
240 1.1 chopps alloc_bitmap_func *alloc_bitmap; /* allocate a bitmap for use with this monitor */
241 1.1 chopps free_bitmap_func *free_bitmap; /* free a bitmap */
242 1.1 chopps };
243 1.1 chopps
244 1.1 chopps /*
245 1.1 chopps * Misc draw related macros.
246 1.1 chopps */
247 1.1 chopps
248 1.1 chopps #define BOX_2_RECT(b,r) do { \
249 1.1 chopps (r)->left = (b)->x; (r)->top = (b)->y; \
250 1.1 chopps (r)->right = (b)->x + (b)->width -1; \
251 1.1 chopps (r)->bottom = (b)->y + (b)->height -1; \
252 1.1 chopps } while (0)
253 1.1 chopps
254 1.1 chopps #define RECT_2_BOX(r,b) do { \
255 1.1 chopps (b)->x = (r)->left; \
256 1.1 chopps (b)->y = (r)->top; \
257 1.1 chopps (b)->width = (r)->right - (r)->left +1; \
258 1.1 chopps (b)->height = (r)->bottom - (r)->top +1; \
259 1.1 chopps } while (0)
260 1.1 chopps
261 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)
262 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)
263 1.1 chopps #define INIT_POINT(p,xx,yy) do {(p)->x = xx; (p)->y = yy;} while (0)
264 1.1 chopps #define INIT_DIM(d,w,h) do {(d)->width = w; (d)->height = h;} while (0)
265 1.1 chopps
266 1.1 chopps
267 1.1 chopps /*
268 1.1 chopps * Prototypes
269 1.1 chopps */
270 1.1 chopps
271 1.1 chopps #if defined (__STDC__)
272 1.1 chopps /* views */
273 1.1 chopps view_t * grf_alloc_view (dmode_t *d, dimen_t *dim, u_char depth);
274 1.1 chopps void grf_display_view (view_t *v);
275 1.1 chopps void grf_remove_view (view_t *v);
276 1.1 chopps void grf_free_view (view_t *v);
277 1.1 chopps dmode_t *grf_get_display_mode (view_t *v);
278 1.1 chopps int grf_get_colormap (view_t *v, colormap_t *cm);
279 1.1 chopps int grf_use_colormap (view_t *v, colormap_t *cm);
280 1.1 chopps /* modes */
281 1.1 chopps view_t *grf_get_current_view (dmode_t *d);
282 1.1 chopps monitor_t *grf_get_monitor (dmode_t *d);
283 1.1 chopps /* monitors */
284 1.1 chopps dmode_t * grf_get_next_mode (monitor_t *m, dmode_t *d);
285 1.1 chopps dmode_t * grf_get_current_mode (monitor_t *);
286 1.1 chopps dmode_t * grf_get_best_mode (monitor_t *m, dimen_t *size, u_char depth);
287 1.1 chopps bmap_t * grf_alloc_bitmap (monitor_t *m, u_short w, u_short h, u_short d, u_short f);
288 1.1 chopps void grf_free_bitmap (monitor_t *m, bmap_t *bm);
289 1.1 chopps #endif /* __STDC__ */
290 1.1 chopps
291 1.1 chopps #endif /* _GRFABS_REG_H */
292