xref: /netbsd/sys/arch/atari/dev/grfabs_fal.c (revision ef074b30)
1 /*	$NetBSD: grfabs_fal.c,v 1.6 1996/09/16 06:43:33 leo Exp $	*/
2 
3 /*
4  * Copyright (c) 1995 Thomas Gerner.
5  * Copyright (c) 1995 Leo Weppelman.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Leo Weppelman.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifdef FALCON_VIDEO
35 /*
36  *  atari abstract graphics driver: Falcon-interface
37  */
38 #include <sys/param.h>
39 #include <sys/queue.h>
40 #include <sys/malloc.h>
41 #include <sys/device.h>
42 #include <sys/systm.h>
43 
44 #include <machine/iomap.h>
45 #include <machine/video.h>
46 #include <machine/mfp.h>
47 #include <atari/atari/device.h>
48 #include <atari/atari/stalloc.h>
49 #include <atari/dev/grfabs_reg.h>
50 #include <atari/dev/grfabs_fal.h>
51 
52 /*
53  * Function decls
54  */
55 static void       init_view __P((view_t *, bmap_t *, dmode_t *, box_t *));
56 static bmap_t	  *alloc_bitmap __P((u_long, u_long, u_char));
57 static colormap_t *alloc_colormap __P((dmode_t *));
58 static void 	  free_bitmap __P((bmap_t *));
59 static void	  falcon_display_view __P((view_t *));
60 static view_t	  *falcon_alloc_view __P((dmode_t *, dimen_t *, u_char));
61 static void	  falcon_free_view __P((view_t *));
62 static void	  falcon_remove_view __P((view_t *));
63 static int	  falcon_use_colormap __P((view_t *, colormap_t *));
64 static void	  falcon_detect __P((dmode_t *));
65 static struct videl *falcon_getreg __P((u_short));
66 
67 /*
68  * Our function switch table
69  */
70 struct grfabs_sw fal_vid_sw = {
71 	falcon_display_view,
72 	falcon_alloc_view,
73 	falcon_free_view,
74 	falcon_remove_view,
75 	falcon_use_colormap
76 };
77 
78 struct falcon_hwregs {
79 	u_short		fal_mode;	/* falcon mode		  */
80 	struct videl	*fal_regs;	/* videl register values  */
81 };
82 #define vm_mode(dm)	(((struct falcon_hwregs*)(dm->data))->fal_mode)
83 #define vm_regs(dm)	(((struct falcon_hwregs*)(dm->data))->fal_regs)
84 
85 /*
86  * Note that the order of this table *must* match the order of
87  * the table below!
88  */
89 static struct falcon_hwregs fal_hwregs[] = {
90 	{ RES_FALAUTO    },
91 	{ RES_FAL_STHIGH },
92 	{ RES_FAL_STMID  },
93 	{ RES_FAL_STLOW  },
94 	{ RES_FAL_TTLOW  },
95 	{ RES_VGA2       },
96 	{ RES_VGA4       },
97 	{ RES_VGA16      },
98 	{ RES_VGA256     },
99 	{ RES_DIRECT     }
100 };
101 
102 
103 static dmode_t vid_modes[] = {
104     { {NULL,NULL}, "falauto", {   0,  0 },  0, NULL, &fal_vid_sw},
105     { {NULL,NULL}, "sthigh",  { 640,400 },  1, NULL, &fal_vid_sw},
106     { {NULL,NULL}, "stmid",   { 640,200 },  2, NULL, &fal_vid_sw},
107     { {NULL,NULL}, "stlow",   { 320,200 },  4, NULL, &fal_vid_sw},
108     { {NULL,NULL}, "ttlow",   { 320,480 },  8, NULL, &fal_vid_sw},
109     { {NULL,NULL}, "vga2",    { 640,480 },  1, NULL, &fal_vid_sw},
110     { {NULL,NULL}, "vga4",    { 640,480 },  2, NULL, &fal_vid_sw},
111     { {NULL,NULL}, "vga16",   { 640,480 },  4, NULL, &fal_vid_sw},
112     { {NULL,NULL}, "vga256",  { 640,480 },  8, NULL, &fal_vid_sw},
113     { {NULL,NULL}, "highcol", { 320,200 }, 16, NULL, &fal_vid_sw},
114     { {NULL,NULL},  NULL,  }
115 };
116 
117 /*
118  * The following table contains timing values for the various video modes.
119  * I have only a multisync display, therefore I can not say if this values
120  * are useful at other displays.
121  * Use other video modes at YOUR OWN RISK.
122  * THERE IS NO WARRENTY ABOUT THIS VALUES TO WORK WITH A PARTICULAR
123  * DISPLAY. -- Thomas
124  */
125 static struct videl videlinit[] = {
126 	{ RES_FALAUTO,		    /* autodedect			    */
127 	0x0, 0x0, 0x0,   0x0, 0x0,   0x0,  0x0,  0x0,  0x0,   0x0,  0x0,  0x0,
128 	0x0, 0x0,   0x0,   0x0,  0x0,  0x0,   0x0,   0x0,   0x0 },
129 
130 	{ FAL_VGA | RES_FAL_STHIGH, /* sthigh, 640x400, 2 colors	    */
131 	0x2, 0x0, 0x28,  0x0, 0x400, 0xc6, 0x8d, 0x15, 0x273, 0x50, 0x96, 0x0,
132 	0x0, 0x419, 0x3af, 0x8f, 0x8f, 0x3af, 0x415, 0x186, 0x8 },
133 
134 #if 0 /* not yet */
135 	{ FAL_SM | RES_FAL_STHIGH,  /* sthigh, 640x400, 2 colors	    */
136 	0x0, 0x0, 0x28,  0x2, 0x0,   0x1a, 0x0,  0x0,  0x20f, 0xc,  0x14, 0x0,
137 	0x0, 0x3e9, 0x0,   0x0,  0x43, 0x363, 0x3e7, 0x80,  0x8 },
138 #endif
139 
140 	{ FAL_VGA | RES_FAL_STMID,  /* stmid, 640x200, 4 colors		    */
141 	0x2, 0x0, 0x50,  0x1, 0x0,   0x17, 0x12, 0x1,  0x20e, 0xd,  0x11, 0x0,
142 	0x0, 0x419, 0x3af, 0x8f, 0x8f, 0x3af, 0x415, 0x186, 0x9 },
143 
144 	{ FAL_VGA | RES_FAL_STLOW,  /* stlow, 320x200, 16 colors	    */
145 	0x2, 0x0, 0x50,  0x0, 0x0,   0x17, 0x12, 0x1,  0x20e, 0xd,  0x11, 0x0,
146 	0x0, 0x419, 0x3af, 0x8f, 0x8f, 0x3af, 0x415, 0x186, 0x5 },
147 
148 	{ FAL_VGA | RES_FAL_TTLOW,  /* ttlow, 320x480, 256 colors	    */
149 	0x2, 0x0, 0xa0,  0x0, 0x10,  0xc6, 0x8d, 0x15, 0x29a, 0x7b, 0x96, 0x0,
150 	0x0, 0x419, 0x3ff, 0x3f, 0x3f, 0x3ff, 0x415, 0x186, 0x4 },
151 
152 	{ FAL_VGA | RES_VGA2,	    /* vga, 640x480, 2 colors		    */
153 	0x2, 0x0, 0x28,  0x0, 0x400, 0xc6, 0x8d, 0x15, 0x273, 0x50, 0x96, 0x0,
154 	0x0, 0x419, 0x3ff, 0x3f, 0x3f, 0x3ff, 0x415, 0x186, 0x8 },
155 
156 	{ FAL_VGA | RES_VGA4,	    /* vga, 640x480, 4 colors		    */
157 	0x2, 0x0, 0x50,  0x1, 0x0,   0x17, 0x12, 0x1,  0x20e, 0xd,  0x11, 0x0,
158 	0x0, 0x419, 0x3ff, 0x3f, 0x3f, 0x3ff, 0x415, 0x186, 0x8 },
159 
160 	{ FAL_VGA | RES_VGA16,	    /* vga, 640x480, 16 colors		    */
161 	0x2, 0x0, 0xa0,  0x1, 0x0,   0xc6, 0x8d, 0x15, 0x2a3, 0x7c, 0x96, 0x0,
162 	0x0, 0x419, 0x3ff, 0x3f, 0x3f, 0x3ff, 0x415, 0x186, 0x8 },
163 
164 	{ FAL_VGA | RES_VGA256,	    /* vga, 640x480, 256 colors		    */
165 	0x2, 0x0, 0x140, 0x1, 0x10,  0xc6, 0x8d, 0x15, 0x2ab, 0x84, 0x96, 0x0,
166 	0x0, 0x419, 0x3ff, 0x3f, 0x3f, 0x3ff, 0x415, 0x186, 0x8 },
167 
168 	{ FAL_VGA | RES_DIRECT,	    /* direct video, 320x200, 65536 colors  */
169 	0x2, 0x0, 0x140, 0x0, 0x100, 0xc6, 0x8d, 0x15, 0x2ac, 0x91, 0x96, 0x0,
170 	0x0, 0x419, 0x3ff, 0x3f, 0x3f, 0x3ff, 0x415, 0x186, 0x4 },
171 
172 	{ 0xffff }		    /* end of list			    */
173 };
174 
175 static u_short mon_type;
176 /*
177  * XXX: called from ite console init routine.
178  * Initialize list of posible video modes.
179  */
180 void
181 falcon_probe_video(modelp)
182 MODES	*modelp;
183 {
184 	dmode_t	*dm;
185 	struct videl *vregs;
186 	int	i;
187 
188 	mon_type = *(volatile unsigned char *)(AD_FAL_MON_TYPE);
189 	mon_type = (mon_type & 0xc0) << 2;
190 
191 	/*
192 	 * get all posible modes
193 	 */
194 
195 	for (i = 0; (dm = &vid_modes[i])->name != NULL; i++) {
196 		dm->data = (void *)&fal_hwregs[i];
197 		if (vm_mode(dm) == RES_FALAUTO) {
198 			vm_regs(dm) = falcon_getreg(RES_FALAUTO);
199 			falcon_detect(dm);
200 			LIST_INSERT_HEAD(modelp, dm, link);
201 		} else {
202 			vregs = falcon_getreg(vm_mode(dm) | mon_type);
203 			if (vregs) {
204 				vm_regs(dm) = vregs;
205 				LIST_INSERT_HEAD(modelp, dm, link);
206 			}
207 		}
208 	}
209 
210 	/*
211 	 * This seems to prevent bordered screens.
212 	 */
213 	for (i=0; i < 16; i++)
214 		VIDEO->vd_fal_rgb[i] = CM_L2FAL(gra_def_color16[i]);
215 }
216 
217 static struct videl *
218 falcon_getreg(mode)
219 u_short mode;
220 {
221 	int i;
222 	struct videl *vregs;
223 
224 	for (i = 0; (vregs = &videlinit[i])->video_mode != 0xffff; i++)
225 		if ((vregs->video_mode) == mode)
226 			return vregs;
227 
228 	return NULL; /* mode not found */
229 }
230 
231 static void
232 falcon_detect(dm)
233 dmode_t *dm;
234 {
235 	u_short	falshift, stshift;
236 	struct videl *vregs = vm_regs(dm);
237 
238 	/*
239 	 * First get the the videl register values
240 	 */
241 
242 	vregs->vd_syncmode	= VIDEO->vd_sync;
243 	vregs->vd_line_wide	= VIDEO->vd_line_wide;
244 	vregs->vd_vert_wrap	= VIDEO->vd_vert_wrap;
245 	vregs->vd_st_res	= VIDEO->vd_st_res;
246 	vregs->vd_fal_res	= VIDEO->vd_fal_res;
247 	vregs->vd_h_hold_tim	= VIDEO->vd_h_hold_tim;
248 	vregs->vd_h_bord_beg	= VIDEO->vd_h_bord_beg;
249 	vregs->vd_h_bord_end	= VIDEO->vd_h_bord_end;
250 	vregs->vd_h_dis_beg	= VIDEO->vd_h_dis_beg;
251 	vregs->vd_h_dis_end	= VIDEO->vd_h_dis_end;
252 	vregs->vd_h_ss		= VIDEO->vd_h_ss;
253 	vregs->vd_h_fs		= VIDEO->vd_h_fs;
254 	vregs->vd_h_hh		= VIDEO->vd_h_hh;
255 	vregs->vd_v_freq_tim	= VIDEO->vd_v_freq_tim;
256 	vregs->vd_v_bord_beg	= VIDEO->vd_v_bord_beg;
257 	vregs->vd_v_bord_end	= VIDEO->vd_v_bord_end;
258 	vregs->vd_v_dis_beg	= VIDEO->vd_v_dis_beg;
259 	vregs->vd_v_dis_end	= VIDEO->vd_v_dis_end;
260 	vregs->vd_v_ss		= VIDEO->vd_v_ss;
261 	vregs->vd_fal_ctrl	= VIDEO->vd_fal_ctrl;
262 	vregs->vd_fal_mode	= VIDEO->vd_fal_mode;
263 
264 
265 	/*
266 	 * Calculate the depth of the screen
267 	 */
268 
269 	falshift = vregs->vd_fal_res;
270 	stshift = vregs->vd_st_res;
271 
272 	if (falshift & 0x400)		/* 2 color */
273 		dm->depth = 1;
274 	else if (falshift & 0x100)	/* high color, direct */
275 		dm->depth = 16;
276 	else if (falshift & 0x10)	/* 256 color */
277 		dm->depth = 8;
278 	else if (stshift == 0)		/* 16 color */
279 		dm->depth = 4;
280 	else if (stshift == 1)		/* 4 color */
281 		dm->depth = 2;
282 	else dm->depth = 1;		/* 2 color */
283 
284 	/*
285 	 * Now calculate the screen hight
286 	 */
287 
288 	dm->size.height = vregs->vd_v_dis_end - vregs->vd_v_dis_beg;
289 	if (!((vregs->vd_fal_mode & 0x2) >> 1)) /* if not interlaced */
290 		dm->size.height >>=1;
291 	if (vregs->vd_fal_mode & 0x1)		/* if doublescan */
292 		dm->size.height >>=1;
293 
294 	/*
295 	 * And the width
296 	 */
297 
298 	dm->size.width = vregs->vd_vert_wrap * 16 / dm->depth;
299 
300 }
301 
302 static void
303 falcon_display_view(v)
304 view_t *v;
305 {
306 	dmode_t	*dm = v->mode;
307 	bmap_t	*bm = v->bitmap;
308 	struct videl *vregs = vm_regs(v->mode);
309 
310 	if (dm->current_view) {
311 		/*
312 		 * Mark current view for this mode as no longer displayed
313 		 */
314 		dm->current_view->flags &= ~VF_DISPLAY;
315 	}
316 	dm->current_view = v;
317 	v->flags |= VF_DISPLAY;
318 
319 	falcon_use_colormap(v, v->colormap);
320 
321 	/* XXX: should use vbl for this */
322 
323 	VIDEO->vd_raml   =  (u_long)bm->hw_address & 0xff;
324 	VIDEO->vd_ramm   = ((u_long)bm->hw_address >>  8) & 0xff;
325 	VIDEO->vd_ramh   = ((u_long)bm->hw_address >> 16) & 0xff;
326 
327 	/*
328 	 * Write to videl registers only on VGA displays
329 	 * This is only a hack. Must be fixed soon. XXX -- Thomas
330 	 */
331 	if(mon_type != FAL_VGA) return;
332 
333 	VIDEO->vd_v_freq_tim	= vregs->vd_v_freq_tim;
334 	VIDEO->vd_v_ss		= vregs->vd_v_ss;
335 	VIDEO->vd_v_bord_beg	= vregs->vd_v_bord_beg;
336 	VIDEO->vd_v_bord_end	= vregs->vd_v_bord_end;
337 	VIDEO->vd_v_dis_beg	= vregs->vd_v_dis_beg;
338 	VIDEO->vd_v_dis_end	= vregs->vd_v_dis_end;
339 	VIDEO->vd_h_hold_tim	= vregs->vd_h_hold_tim;
340 	VIDEO->vd_h_ss		= vregs->vd_h_ss;
341 	VIDEO->vd_h_bord_beg	= vregs->vd_h_bord_beg;
342 	VIDEO->vd_h_bord_end	= vregs->vd_h_bord_end;
343 	VIDEO->vd_h_dis_beg	= vregs->vd_h_dis_beg;
344 	VIDEO->vd_h_dis_end	= vregs->vd_h_dis_end;
345 #if 0 /* This seems not to be necessary -- Thomas */
346 	VIDEO->vd_h_fs		= vregs->vd_h_fs;
347 	VIDEO->vd_h_hh		= vregs->vd_h_hh;
348 #endif
349 	VIDEO->vd_sync          = vregs->vd_syncmode;
350 	VIDEO->vd_fal_res       = 0;
351 	if (dm->depth == 2)
352 		VIDEO->vd_st_res        = vregs->vd_st_res;
353 	else {
354 		VIDEO->vd_st_res        = 0;
355 		VIDEO->vd_fal_res       = vregs->vd_fal_res;
356 	}
357 	VIDEO->vd_vert_wrap     = vregs->vd_vert_wrap;
358 	VIDEO->vd_line_wide     = vregs->vd_line_wide;
359 	VIDEO->vd_fal_ctrl      = vregs->vd_fal_ctrl;
360 	VIDEO->vd_fal_mode      = vregs->vd_fal_mode;
361 }
362 
363 static void
364 falcon_remove_view(v)
365 view_t *v;
366 {
367 	dmode_t *mode = v->mode;
368 
369 	if (mode->current_view == v) {
370 #if 0
371 		if (v->flags & VF_DISPLAY)
372 			panic("Cannot shutdown display\n"); /* XXX */
373 #endif
374 		mode->current_view = NULL;
375 	}
376 	v->flags &= ~VF_DISPLAY;
377 }
378 
379 static void
380 falcon_free_view(v)
381 view_t *v;
382 {
383 	if (v) {
384 		falcon_remove_view(v);
385 		if (v->colormap != &gra_con_cmap)
386 			free(v->colormap, M_DEVBUF);
387 		free_bitmap(v->bitmap);
388 		if (v != &gra_con_view)
389 			free(v, M_DEVBUF);
390 	}
391 }
392 
393 static int
394 falcon_use_colormap(v, cm)
395 view_t		*v;
396 colormap_t	*cm;
397 {
398 	dmode_t			*dm;
399 	volatile u_short	*creg;
400 	volatile u_long		*fcreg;
401 	u_long			*src;
402 	colormap_t		*vcm;
403 	u_long			*vcreg;
404 	u_short			ncreg;
405 	int			i;
406 
407 	dm  = v->mode;
408 	vcm = v->colormap;
409 
410 	/*
411 	 * I guess it seems reasonable to require the maps to be
412 	 * of the same type...
413 	 */
414 	if (cm->type != vcm->type)
415 		return (EINVAL);
416 
417 	/*
418 	 * First get the colormap addresses an calculate
419 	 * howmany colors are in it.
420 	 */
421 	if (dm->depth == 16) /* direct color, no colormap;
422 				but also not (yet) supported */
423 		return(0);
424 	fcreg = &VIDEO->vd_fal_rgb[0];
425 	creg  = &VIDEO->vd_st_rgb[0];
426 	ncreg = 1 << dm->depth;
427 
428 	/* If first entry specified beyond capabilities -> error */
429 	if (cm->first >= ncreg)
430 		return (EINVAL);
431 
432 	/*
433 	 * A little tricky, the actual colormap pointer will be NULL
434 	 * when view is not displaying, valid otherwise.
435 	 */
436 	if (v->flags & VF_DISPLAY)
437 		creg = &creg[cm->first];
438 	else creg = NULL;
439 
440 	vcreg  = &vcm->entry[cm->first];
441 	ncreg -= cm->first;
442 	if (cm->size > ncreg)
443 		return (EINVAL);
444 	ncreg = cm->size;
445 
446 	for (i = 0, src = cm->entry; i < ncreg; i++, vcreg++) {
447 		*vcreg = *src++;
448 
449 		/*
450 		 * If displaying, also update actual color register.
451 		 */
452 		if (creg != NULL) {
453 			*fcreg++ = CM_L2FAL(*vcreg);
454 			if (i < 16 )
455 				*creg++ = CM_L2ST(*vcreg);
456 		}
457 	}
458 	return (0);
459 }
460 
461 static view_t *
462 falcon_alloc_view(mode, dim, depth)
463 dmode_t	*mode;
464 dimen_t	*dim;
465 u_char   depth;
466 {
467 	view_t *v;
468 	bmap_t *bm;
469 
470 	if (!atari_realconfig)
471 		v = &gra_con_view;
472 	else v = malloc(sizeof(*v), M_DEVBUF, M_NOWAIT);
473 	if (v == NULL)
474 		return(NULL);
475 
476 	bm = alloc_bitmap(mode->size.width, mode->size.height, mode->depth);
477 	if (bm) {
478 		box_t   box;
479 
480 		v->colormap = alloc_colormap(mode);
481 		if (v->colormap) {
482 			INIT_BOX(&box,0,0,mode->size.width,mode->size.height);
483 			init_view(v, bm, mode, &box);
484 			return(v);
485 		}
486 		free_bitmap(bm);
487 	}
488 	if (v != &gra_con_view)
489 		free(v, M_DEVBUF);
490 	return (NULL);
491 }
492 
493 static void
494 init_view(v, bm, mode, dbox)
495 view_t	*v;
496 bmap_t	*bm;
497 dmode_t	*mode;
498 box_t	*dbox;
499 {
500 	v->bitmap = bm;
501 	v->mode   = mode;
502 	v->flags  = 0;
503 	bcopy(dbox, &v->display, sizeof(box_t));
504 }
505 
506 /* bitmap functions */
507 
508 static bmap_t *
509 alloc_bitmap(width, height, depth)
510 u_long	width, height;
511 u_char	depth;
512 {
513 	u_long  total_size, bm_size;
514 	void	*hw_address;
515 	bmap_t	*bm;
516 
517 	/*
518 	 * Sigh, it seems for mapping to work we need the bitplane data to
519 	 *  1: be aligned on a page boundry.
520 	 *  2: be n pages large.
521 	 *
522 	 * why? because the user gets a page aligned address, if this is before
523 	 * your allocation, too bad.  Also it seems that the mapping routines
524 	 * do not watch to closely to the allowable length. so if you go over
525 	 * n pages by less than another page, the user gets to write all over
526 	 * the entire page. Since you did not allocate up to a page boundry
527 	 * (or more) the user writes into someone elses memory. -ch
528 	 */
529 	bm_size    = atari_round_page((width * height * depth) / NBBY);
530 	total_size = bm_size + sizeof(bmap_t) + NBPG;
531 
532 	if ((bm = (bmap_t*)alloc_stmem(total_size, &hw_address)) == NULL)
533 		return(NULL);
534 
535 	bm->plane         = (u_char*)bm + sizeof(bmap_t);
536 	bm->plane         = (u_char*)atari_round_page(bm->plane);
537 	bm->hw_address    = (u_char*)hw_address + sizeof(bmap_t);
538 	bm->hw_address    = (u_char*)atari_round_page(bm->hw_address);
539 	bm->bytes_per_row = (width * depth) / NBBY;
540 	bm->rows          = height;
541 	bm->depth         = depth;
542 	bm->regs = bm->hw_regs = bm->reg_size = 0;
543 
544 	bzero(bm->plane, bm_size);
545 	return (bm);
546 }
547 
548 static void
549 free_bitmap(bm)
550 bmap_t *bm;
551 {
552 	if (bm)
553 		free_stmem(bm);
554 }
555 
556 static colormap_t *
557 alloc_colormap(dm)
558 dmode_t		*dm;
559 {
560 	int		nentries, i;
561 	colormap_t	*cm;
562 	u_char		type = CM_COLOR;
563 
564 	if (dm->depth == 16) /* direct color, no colormap;
565 				not (yet) supported */
566 		nentries = 0;
567 	else
568 		nentries = 1 << dm->depth;
569 
570 	if (!atari_realconfig) {
571 		cm = &gra_con_cmap;
572 		cm->entry = gra_con_colors;
573 	}
574 	else {
575 		int size;
576 
577 		size = sizeof(*cm) + (nentries * sizeof(cm->entry[0]));
578 		cm   = malloc(size, M_DEVBUF, M_NOWAIT);
579 		if (cm == NULL)
580 			return(NULL);
581 		cm->entry = (long *)&cm[1];
582 
583 	}
584 
585 	if ((cm->type = type) == CM_COLOR)
586 		cm->red_mask = cm->green_mask = cm->blue_mask = 0x3f;
587 
588 	cm->first = 0;
589 	cm->size  = nentries;
590 
591 	for (i = 0; i < nentries; i++)
592 		cm->entry[i] = gra_def_color16[i % 16];
593 	return (cm);
594 }
595 #endif /* FALCON_VIDEO */
596