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