1/*	$NetBSD: grfabs_reg.h,v 1.15 2023/01/06 10:28:28 tsutsui Exp $	*/
2
3/*
4 * Copyright (c) 1995 Leo Weppelman
5 * Copyright (c) 1994 Christian E. Hopps
6 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *      This product includes software developed by Christian E. Hopps.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef _GRFABS_REG_H
34#define _GRFABS_REG_H
35
36struct point {
37    long	x;
38    long	y;
39};
40typedef struct point point_t;
41
42struct dimension {
43    u_long	width;
44    u_long	height;
45};
46typedef struct dimension dimen_t;
47
48struct box {
49    long	x;
50    long	y;
51    u_long	width;
52    u_long	height;
53};
54typedef struct box box_t;
55
56struct rectangle {
57    long	left;
58    long	top;
59    long	right;
60    long	bottom;
61};
62typedef struct rectangle rect_t;
63
64typedef struct bitmap bmap_t;
65typedef struct colormap colormap_t;
66typedef struct display_mode dmode_t;
67
68/*
69 * View stuff.
70 */
71
72struct view {
73    bmap_t	*bitmap;	/* bitmap.				*/
74    box_t	display;	/* viewable area.			*/
75    dmode_t	*mode;		/* the mode for this view		*/
76    colormap_t	*colormap;	/* the colormap for this view		*/
77    int		flags;
78    void	*save_area;	/* Save frame-buffer when not on screen	*/
79};
80typedef struct view view_t;
81
82/* View-flags: */
83#define	VF_DISPLAY	1	/* view is on the air now		*/
84
85/*
86 * Bitmap stuff.
87 */
88struct bitmap {
89    u_short	bytes_per_row;	/* number of bytes per display row.	*/
90    u_short	rows;		/* number of display rows.		*/
91    u_short	depth;		/* depth of bitmap.			*/
92    u_char	*plane;		/* plane data for bitmap/vga.		*/
93    u_char	*hw_address;	/* mappable linear bitplane pointer.	*/
94    u_char	*vga_address;	/* mappable vga bitplane pointer	*/
95    u_char	*regs;		/* where the registers are		*/
96    u_char	*hw_regs;	/* mappable registers			*/
97    u_short	reg_size;	/* size of the register area		*/
98    u_int	phys_mappable;	/* amount of mappable lin. plane mem.	*/
99    u_int	vga_mappable;	/* amount of mappable vga plane mem.	*/
100    u_int	lin_base;	/* linear framebuffer card base		*/
101    u_int	vga_base;	/* vga memory card base			*/
102};
103
104/*
105 * Colormap stuff.
106 */
107struct colormap {
108    u_char	type;		/* what type of entries these are.	*/
109    union {
110        u_char	grey;		/* CM_GREYSCALE				*/
111        struct {		/* CM_COLOR				*/
112            u_char	red;
113            u_char	green;
114            u_char	blue;
115        } rgb_mask;
116    } valid_mask;
117    u_short	first;		/* color register entry[0] refers to	*/
118    u_short	size;		/* number of entries			*/
119    u_long	*entry;		/* the table of actual color values	*/
120};
121
122/*
123 * Mask short-hands
124 */
125#define grey_mask  valid_mask.grey
126#define red_mask   valid_mask.rgb_mask.red
127#define green_mask valid_mask.rgb_mask.green
128#define blue_mask  valid_mask.rgb_mask.blue
129
130enum colormap_type {
131	CM_MONO,		/* only on or off allowed		*/
132	CM_GREYSCALE,		/* grey values				*/
133	CM_COLOR		/* RGB values				*/
134};
135
136#define	MAX_CENTRIES		256		/* that all there is	*/
137/*
138 * Create a colormap entry
139 */
140#define	MAKE_COLOR_ENTRY(r,g,b)	(((r & 0xff)<<16)|((g & 0xff)<<8)|(b & 0xff))
141#define MAKE_MONO_ENTRY(x)	((x) ? 1 : 0)
142#define MAKE_GREY_ENTRY(l)	(l & 0xff)
143
144struct grfabs_sw {
145	void	 (*display_view)(view_t*);
146	view_t	* (*alloc_view)(dmode_t *, dimen_t *, u_char);
147	void	 (*free_view)(view_t *);
148	void	 (*remove_view)(view_t *);
149	void	 (*save_view)(view_t *);
150	int	 (*use_colormap)(view_t *, colormap_t *);
151};
152
153/* display mode */
154struct display_mode {
155    LIST_ENTRY(display_mode)	link;
156    const u_char		*name;		/* logical name for mode. */
157    dimen_t			size;		/* screen size		  */
158    u_char			depth;		/* screen depth		  */
159    void			*data;		/* opaque driver data	  */
160    struct grfabs_sw		*grfabs_funcs;	/* hardware switch table  */
161    view_t			*current_view;	/* view displaying me	  */
162};
163
164/*
165 * Definition of available graphic mode list.
166 */
167typedef LIST_HEAD(modelist, display_mode) MODES;
168
169/*
170 * Misc draw related macros.
171 */
172#define INIT_BOX(b,xx,yy,ww,hh)						\
173	do {								\
174		(b)->x = xx;						\
175		(b)->y = yy;						\
176		(b)->width = ww;					\
177		(b)->height = hh;					\
178	} while(0)
179
180
181/*
182 * Prototype for the probe function
183 */
184typedef void (*grf_probe_t)(MODES *);
185
186/*
187 * Common variables
188 */
189extern view_t		gra_con_view;
190extern colormap_t	gra_con_cmap;
191extern long		gra_con_colors[MAX_CENTRIES];
192extern u_long		gra_def_color16[16];
193
194/*
195 * Prototypes:
196 */
197int	grfabs_probe(grf_probe_t);
198view_t	*grf_alloc_view(dmode_t *d, dimen_t *dim, u_char depth);
199dmode_t	*grf_get_best_mode(dimen_t *dim, u_char depth);
200void	grf_display_view(view_t *v);
201void	grf_remove_view(view_t *v);
202void	grf_free_view(view_t *v);
203int	grf_get_colormap(view_t *, colormap_t *);
204int	grf_use_colormap(view_t *, colormap_t *);
205void	grf_save_view(view_t *v);
206
207#endif /* _GRFABS_REG_H */
208