Home | History | Annotate | Line # | Download | only in dev
grfabs_cc.c revision 1.8
      1 /*	$NetBSD: grfabs_cc.c,v 1.8 1995/06/26 01:39:55 chopps Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Christian E. Hopps
      5  * All rights reserved.
      6  *
      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 /*
     34  *  abstract interface for custom chips to the amiga abstract graphics driver.
     35  *
     36  */
     37 
     38 #include <sys/param.h>
     39 #include <sys/errno.h>
     40 #include <sys/cdefs.h>
     41 #include <sys/queue.h>
     42 
     43 #include <amiga/amiga/custom.h>
     44 #include <amiga/amiga/cc.h>
     45 
     46 #include <amiga/dev/grfabs_reg.h>
     47 #include <amiga/dev/grfabs_ccreg.h>
     48 
     49 monitor_t *m_this;
     50 mdata_t *m_this_data;
     51 char   *monitor_name = "CCMONITOR";
     52 monitor_t monitor;
     53 mdata_t monitor_data;
     54 cop_t  *null_mode_copper_list;
     55 
     56 #if defined (GRF_PAL)
     57 #  if defined (GRF_A2024)
     58 dmode_t pal_a2024_mode;
     59 dmdata_t pal_a2024_mode_data;
     60 cop_t  *pal_a2024_frames[F_QD_TOTAL];
     61 u_char *hedley_init;		/* init bitplane. */
     62 dmode_t *p24_this;
     63 dmdata_t *p24_this_data;
     64 
     65 dmode_t pal_hires_dlace_mode;
     66 dmdata_t pal_hires_dlace_mode_data;
     67 cop_t  *pal_hires_dlace_frames[F_LACE_TOTAL];
     68 dmode_t *phdl_this;
     69 dmdata_t *phdl_this_data;
     70 #  endif /* GRF_A2024 */
     71 
     72 #  if defined (GRF_AGA)
     73 dmode_t paga_mode;
     74 dmdata_t paga_mode_data;
     75 cop_t *paga_frames[F_TOTAL];
     76 dmode_t *paga_this;
     77 dmdata_t *paga_this_data;
     78 #  endif /* GRF_AGA */
     79 
     80 dmode_t pal_hires_lace_mode;
     81 dmdata_t pal_hires_lace_mode_data;
     82 cop_t  *pal_hires_lace_frames[F_LACE_TOTAL];
     83 dmode_t *phl_this;
     84 dmdata_t *phl_this_data;
     85 
     86 dmode_t pal_hires_mode;
     87 dmdata_t pal_hires_mode_data;
     88 cop_t  *pal_hires_frames[F_TOTAL];
     89 dmode_t *ph_this;
     90 dmdata_t *ph_this_data;
     91 #endif /* PAL */
     92 
     93 #if defined (GRF_NTSC)
     94 #  if defined (GRF_A2024)
     95 dmode_t a2024_mode;
     96 dmdata_t a2024_mode_data;
     97 cop_t  *a2024_frames[F_QD_TOTAL];
     98 u_char *hedley_init;		/* init bitplane. */
     99 dmode_t *a24_this;
    100 dmdata_t *a24_this_data;
    101 
    102 dmode_t hires_dlace_mode;
    103 dmdata_t hires_dlace_mode_data;
    104 cop_t  *hires_dlace_frames[F_LACE_TOTAL];
    105 dmode_t *hdl_this;
    106 dmdata_t *hdl_this_data;
    107 #  endif /* GRF_A2024 */
    108 
    109 #  if defined (GRF_AGA)
    110 dmode_t aga_mode;
    111 dmdata_t aga_mode_data;
    112 cop_t *aga_frames[F_TOTAL];
    113 dmode_t *aga_this;
    114 dmdata_t *aga_this_data;
    115 #  endif /* GRF_AGA */
    116 
    117 dmode_t hires_lace_mode;
    118 dmdata_t hires_lace_mode_data;
    119 cop_t  *hires_lace_frames[F_LACE_TOTAL];
    120 dmode_t *hl_this;
    121 dmdata_t *hl_this_data;
    122 
    123 void    display_hires_view(view_t * v);
    124 dmode_t hires_mode;
    125 dmdata_t hires_mode_data;
    126 cop_t  *hires_frames[F_TOTAL];
    127 dmode_t *h_this;
    128 dmdata_t *h_this_data;
    129 #endif /* GRF_NTSC */
    130 
    131 #ifdef GRF_AGA
    132 #define	AGA_ENABLE	0x0001
    133 #define	AGA_ENABLE2	0x0002
    134 #define AGA_TRACE	0x0004
    135 #define AGA_TRACE2	0x0008
    136 #define AGA_VGAONLY	0x0010
    137 #define AGA_VGA31KHZ	0x0020
    138 
    139 int aga_enable = 0;	/* set by start_c(), or can be patched */
    140 #endif
    141 
    142 /* monitor functions. */
    143 monitor_t *
    144 cc_init_monitor()
    145 {
    146 	cop_t  *cp;
    147 
    148 	if (m_this)
    149 		return(m_this);
    150 
    151 	cc_monitor = m_this = &monitor;
    152 	/* turn sprite DMA off. we don't support them yet. */
    153 	custom.dmacon = DMAF_SPRITE;
    154 
    155 	/* makre sure sprite data registers are clear as well */
    156 	custom.spr[0].data = 0;
    157 	custom.spr[0].datb = 0;
    158 
    159 	m_this->name = monitor_name;
    160 	m_this_data = m_this->data = &monitor_data;
    161 
    162 	m_this->get_current_mode = get_current_mode;
    163 	m_this->vbl_handler = (vbl_handler_func *) monitor_vbl_handler;
    164 	m_this->get_next_mode = get_next_mode;
    165 	m_this->get_best_mode = get_best_mode;
    166 
    167 	m_this->alloc_bitmap = alloc_bitmap;
    168 	m_this->free_bitmap = free_bitmap;
    169 
    170 	m_this_data->current_mode = NULL;
    171 	LIST_INIT(&m_this_data->modes);
    172 
    173 	cp = null_mode_copper_list = alloc_chipmem(sizeof(cop_t) * 4);
    174 	if (!cp)
    175 		panic("no chipmem for grf.");
    176 
    177 	CMOVE(cp, R_COLOR00, 0x0000);	/* background is black */
    178 	CMOVE(cp, R_BPLCON0, 0x0000);	/* no planes to fetch from */
    179 	CWAIT(cp, 255, 255);	/* COPEND */
    180 	CWAIT(cp, 255, 255);	/* COPEND really */
    181 
    182 	/* install this list and turn DMA on */
    183 	custom.cop1lc = PREP_DMA_MEM(null_mode_copper_list);
    184 	custom.copjmp1 = 0;
    185 	custom.dmacon = DMAF_SETCLR | DMAF_MASTER | DMAF_RASTER \
    186 	    |DMAF_COPPER;
    187 
    188 	cc_init_modes();
    189 	LIST_INSERT_HEAD(monitors, m_this, link);
    190 	return (m_this);
    191 }
    192 
    193 void
    194 monitor_vbl_handler(m)
    195 	monitor_t *m;
    196 {
    197 	dmdata_t *dmd;
    198 
    199 	if (m_this_data->current_mode == NULL)
    200 		return;
    201 
    202 	dmd = DMDATA(m_this_data->current_mode);
    203 	if (dmd)
    204 		dmd->vbl_handler(m_this_data->current_mode);
    205 }
    206 
    207 dmode_t *
    208 get_current_mode()
    209 {
    210 	if (m_this_data->current_mode)
    211 		return(m_this_data->current_mode);
    212 	else
    213 		return(NULL);
    214 }
    215 
    216 dmode_t *
    217 get_next_mode(d)
    218 	dmode_t *d;
    219 {
    220 	if (d)
    221 		return(d->link.le_next);
    222 	return(m_this_data->modes.lh_first);
    223 }
    224 
    225 /* XXX needs to have more control attributes */
    226 dmode_t *
    227 get_best_mode(size, depth)
    228 	dimen_t *size;
    229 	u_char depth;
    230 {
    231 	dmode_t *save;
    232 	dmode_t *dm;
    233 	long    dt, dx, dy, ct;
    234 	dmdata_t *dmd;
    235 
    236 	save = NULL;
    237 	dm = m_this_data->modes.lh_first;
    238 	while (dm != NULL) {
    239 		dmd = dm->data;
    240 		if (depth > dmd->max_depth || depth < dmd->min_depth) {
    241 			dm = dm->link.le_next;
    242 			continue;
    243 		} else if (size->width > dmd->max_size.width ||
    244 		    size->height > dmd->max_size.height) {
    245 			dm = dm->link.le_next;
    246 			continue;
    247 		} else if (size->width < dmd->min_size.width ||
    248 		    size->height < dmd->min_size.height) {
    249 			dm = dm->link.le_next;
    250 			continue;
    251 		}
    252 		dx = abs(dm->nominal_size.width - size->width);
    253 		dy = abs(dm->nominal_size.height - size->height);
    254 		ct = dx + dy;
    255 
    256 		if (ct < dt || save == NULL) {
    257 			save = dm;
    258 			dt = ct;
    259 		}
    260 		dm = dm->link.le_next;
    261 	}
    262 	return (save);
    263 }
    264 /* bitmap functions */
    265 bmap_t *
    266 alloc_bitmap(width, height, depth, flags)
    267 	u_short width, height, depth, flags;
    268 {
    269 	int     i;
    270 	u_long  total_size;
    271 #ifdef GRF_AGA
    272 	u_short lwpr = (flags & BMF_ALIGN64) ? ((width + 63) / 64) * 2 :
    273 	    (width + 31) / 32;			/* AGA needs 64 bit align */
    274 #else
    275 	u_short lwpr = (width + 31) / 32;
    276 #endif
    277 	u_short wpr = lwpr << 1;
    278 	u_short bpr = wpr << 1;
    279 	u_short array_size = sizeof(u_char *) * depth;
    280 	u_long  plane_size = bpr * height;
    281 	u_short temp_size = bpr + sizeof(u_long);
    282 	bmap_t *bm;
    283 
    284 	/* note the next allocation will give everything, also note that all
    285 	 * the stuff we want (including bitmaps) will be long short aligned.
    286 	 * This is a function of the data being allocated and the fact that
    287 	 * alloc_chipmem() returns long short aligned data. note also that
    288 	 * each row of the bitmap is long word aligned and made of exactly n
    289 	 * longwords. -ch */
    290 
    291 	/* Sigh, it seems for mapping to work we need the bitplane data to 1:
    292 	 * be aligned on a page boundry. 2: be n pages large.
    293 	 *
    294 	 * why? becuase the user gets a page aligned address, if this is before
    295 	 * your allocation, too bad.  Also it seems that the mapping routines
    296 	 * do not watch to closely to the allowable length. so if you go over
    297 	 * n pages by less than another page, the user gets to write all over
    298 	 * the entire page.  Since you did not allocate up to a page boundry
    299 	 * (or more) the user writes into someone elses memory. -ch */
    300 	total_size = amiga_round_page(plane_size * depth) +	/* for length */
    301 	    (temp_size) + (array_size) + sizeof(bmap_t) +
    302 	    NBPG;		/* for alignment */
    303 	bm = alloc_chipmem(total_size);
    304 	if (bm) {
    305 		if (flags & BMF_CLEAR) {
    306 			bzero(bm, total_size);
    307 		}
    308 		bm->bytes_per_row = bpr;
    309 		bm->rows = height;
    310 		bm->depth = depth;
    311 		bm->flags = flags;
    312 		bm->plane = (u_char **) & bm[1];
    313 		bm->blit_temp = ((u_char *) bm->plane) + array_size;
    314 		bm->plane[0] = (u_char *) amiga_round_page((u_long) (bm->blit_temp + temp_size));
    315 		if (flags & BMF_INTERLEAVED) {
    316 			bm->row_mod = bm->bytes_per_row * (depth - 1);
    317 			for (i = 1; i < depth; i++) {
    318 				bm->plane[i] = bm->plane[i - 1] + bpr;
    319 			}
    320 		} else {
    321 			bm->row_mod = 0;
    322 			for (i = 1; i < depth; i++) {
    323 				bm->plane[i] = bm->plane[i - 1] + plane_size;
    324 			}
    325 		}
    326 		bm->hardware_address = PREP_DMA_MEM(bm->plane[0]);
    327 		return (bm);
    328 	}
    329 	return (NULL);
    330 }
    331 
    332 
    333 void
    334 free_bitmap(bm)
    335 	bmap_t *bm;
    336 {
    337 	if (bm)
    338 		free_chipmem(bm);
    339 }
    340 /* load a new mode into the current display, if NULL shut display off. */
    341 void
    342 cc_load_mode(d)
    343 	dmode_t *d;
    344 {
    345 	if (d) {
    346 		m_this_data->current_mode = d;
    347 		return;
    348 	}
    349 	/* turn off display */
    350 	m_this_data->current_mode = NULL;
    351 	wait_tof();
    352 	wait_tof();
    353 	custom.cop1lc = PREP_DMA_MEM(null_mode_copper_list);
    354 }
    355 /*
    356  * CC Mode Stuff.
    357  */
    358 
    359 dmode_t *(*mode_init_funcs[]) (void) = {
    360 #if defined (GRF_NTSC)
    361 #if defined (GRF_A2024)
    362 	cc_init_ntsc_a2024,
    363 	cc_init_ntsc_hires_dlace,
    364 #endif /* GRF_A2024 */
    365 	cc_init_ntsc_hires_lace,
    366 	cc_init_ntsc_hires,
    367 #if defined (GRF_AGA)
    368 	cc_init_ntsc_aga,
    369 #endif /* GRF_AGA */
    370 #endif /* GRF_NTSC */
    371 #if defined (GRF_PAL)
    372 #if defined (GRF_A2024)
    373 	cc_init_pal_a2024,
    374 	cc_init_pal_hires_dlace,
    375 #endif /* GRF_A2024 */
    376 	cc_init_pal_hires_lace,
    377 	cc_init_pal_hires,
    378 #if defined (GRF_AGA)
    379 	cc_init_pal_aga,
    380 #endif /* GRF_AGA */
    381 #endif /* GRF_PAL */
    382 	NULL
    383 };
    384 
    385 int
    386 cc_init_modes()
    387 {
    388 	int     i = 0;
    389 	int     error = 0;
    390 	while (mode_init_funcs[i]) {
    391 		mode_init_funcs[i] ();
    392 		i++;
    393 	}
    394 	return (error);
    395 }
    396 
    397 monitor_t *
    398 cc_get_monitor(d)
    399 	dmode_t *d;
    400 {
    401 	return (DMDATA(d)->monitor);
    402 }
    403 
    404 view_t *
    405 cc_get_current_view(d)
    406 	dmode_t *d;
    407 {
    408 	return (DMDATA(d)->current_view);
    409 }
    410 
    411 
    412 view_t *
    413 cc_alloc_view(mode, dim, depth)
    414 	dmode_t *mode;
    415 	dimen_t *dim;
    416 	u_char   depth;
    417 {
    418 	view_t *v = alloc_chipmem(sizeof(*v) + sizeof(vdata_t));
    419 	if (v) {
    420 		bmap_t *bm = cc_monitor->alloc_bitmap(dim->width, dim->height,
    421 		    depth, BMF_CLEAR | (DMDATA(mode)->max_depth == 8 ? BMF_ALIGN64 : 0));
    422 		if (bm) {
    423 			int     i;
    424 			box_t   box;
    425 
    426 			v->data = &v[1];	/* at the end of view */
    427 			VDATA(v)->colormap = DMDATA(mode)->alloc_colormap(depth);
    428 			if (VDATA(v)->colormap) {
    429 				INIT_BOX(&box, 0, 0, dim->width, dim->height);
    430 				cc_init_view(v, bm, mode, &box);
    431 				return (v);
    432 			}
    433 			cc_monitor->free_bitmap(bm);
    434 		}
    435 		free_chipmem(v);
    436 	}
    437 	return (NULL);
    438 }
    439 
    440 colormap_t *
    441 cc_alloc_colormap(depth)
    442 	int depth;
    443 {
    444 	u_long  size = 1U << depth, i;
    445 	colormap_t *cm = alloc_chipmem(sizeof(u_long) * size + sizeof(*cm));
    446 
    447 	if (cm) {
    448 		cm->type = CM_COLOR;
    449 		cm->red_mask = 0x0F;
    450 		cm->green_mask = 0x0F;
    451 		cm->blue_mask = 0x0F;
    452 		cm->first = 0;
    453 		cm->size = size;
    454 		cm->entry = (u_long *) & cm[1];	/* table directly after. */
    455 		for (i = 0; i < size; i++) {
    456 			cm->entry[i] = CM_WTOL(cc_default_colors[i&31]);
    457 		}
    458 		return (cm);
    459 	}
    460 	return (NULL);
    461 }
    462 
    463 #ifdef GRF_AGA
    464 colormap_t *
    465 cc_alloc_aga_colormap(depth)
    466 	int depth;
    467 {
    468 	u_long  size = 1U << depth, i;
    469 	colormap_t *cm = alloc_chipmem(sizeof(u_long) * size + sizeof(*cm));
    470 
    471 	if (cm) {
    472 		cm->type = CM_COLOR;
    473 		cm->red_mask = 0x0FF;
    474 		cm->green_mask = 0x0FF;
    475 		cm->blue_mask = 0x0FF;
    476 		cm->first = 0;
    477 		cm->size = size;
    478 		cm->entry = (u_long *) & cm[1];	/* table directly after. */
    479 		for (i = 0; i < size; i++) {
    480 			cm->entry[i] = CM_WTOL(cc_default_colors[i&31]) |
    481 			    (CM_WTOL(cc_default_colors[i&31]) << 4);
    482 		}
    483 		return (cm);
    484 	}
    485 	return (NULL);
    486 }
    487 #endif
    488 
    489 int
    490 cc_colormap_checkvals(vcm, cm, use)
    491 	colormap_t *vcm, *cm;
    492 	int         use;
    493 {
    494 	if (use) {
    495 		/* check to see if its the view's colormap, if so just do
    496 		 * update. */
    497 		if (vcm != cm) {
    498 			if (cm->first >= vcm->size || (cm->first + cm->size) > (cm->first + vcm->size) ||
    499 			    cm->type != vcm->type) {
    500 				return (0);
    501 			}
    502 			switch (vcm->type) {
    503 			case CM_COLOR:
    504 				if (cm->red_mask != vcm->red_mask ||
    505 				    cm->green_mask != vcm->green_mask ||
    506 				    cm->blue_mask != vcm->blue_mask) {
    507 					return (0);
    508 				}
    509 				break;
    510 			case CM_GREYSCALE:
    511 				if (cm->grey_mask != vcm->grey_mask) {
    512 					return (0);
    513 				}
    514 				break;
    515 			}
    516 		}
    517 	} else {
    518 		if (cm->first >= vcm->size || (cm->first + cm->size) > (cm->first + vcm->size)) {
    519 			return (0);
    520 		}
    521 	}
    522 	return (1);
    523 }
    524 /* does sanity check on values */
    525 int
    526 cc_get_colormap(v, cm)
    527 	view_t *v;
    528 	colormap_t *cm;
    529 {
    530 	colormap_t *vcm = VDATA(v)->colormap;
    531 	int     i;
    532 
    533 	if (!cc_colormap_checkvals(vcm, cm, 0)) {
    534 		return (EINVAL);
    535 	}
    536 	cm->type = vcm->type;
    537 
    538 	switch (vcm->type) {
    539 	case CM_COLOR:
    540 		cm->red_mask = vcm->red_mask;
    541 		cm->green_mask = vcm->green_mask;
    542 		cm->blue_mask = vcm->blue_mask;
    543 		break;
    544 	case CM_GREYSCALE:
    545 		cm->grey_mask = vcm->grey_mask;
    546 		break;
    547 	}
    548 
    549 	/* copy entries into colormap. */
    550 	for (i = cm->first; i < (cm->first + cm->size); i++) {
    551 		cm->entry[i] = vcm->entry[i];
    552 	}
    553 	return (0);
    554 }
    555 
    556 /* does sanity check on values */
    557 int
    558 cc_use_colormap(v, cm)
    559 	view_t *v;
    560 	colormap_t *cm;
    561 {
    562 	colormap_t *vcm = VDATA(v)->colormap;
    563 	int     s, i;
    564 
    565 	if (!cc_colormap_checkvals(vcm, cm, 1)) {
    566 		return (EINVAL);
    567 	}
    568 	/* check to see if its the view's colormap, if so just do update. */
    569 	if (vcm != cm) {
    570 		/* copy entries into colormap. */
    571 		for (i = cm->first; i < (cm->first + cm->size); i++) {
    572 			vcm->entry[i] = cm->entry[i];
    573 		}
    574 	}
    575 	s = spltty();
    576 
    577 	/* is view currently being displayed? */
    578 	if (VDATA(v)->flags & VF_DISPLAY) {
    579 		/* yes, update the copper lists */
    580 		cop_t  *tmp, *cp;
    581 		int     nframes = 1, j;
    582 
    583 		if (DMDATA(VDATA(v)->mode)->flags & DMF_INTERLACE) {
    584 			nframes = 2;
    585 		}
    586 		for (i = 0; i < nframes; i++) {
    587 			cp = DMDATA(VDATA(v)->mode)->frames[i];
    588 
    589 			tmp = find_copper_inst(cp, CI_MOVE(R_COLOR07));
    590 			tmp -= 7;
    591 
    592 			for (j = 0; j < 32; j++) {
    593 				CMOVE(tmp, R_COLOR00 + (j << 1), CM_LTOW(vcm->entry[j]));
    594 			}
    595 		}
    596 	}
    597 	splx(s);
    598 	return (0);
    599 }
    600 
    601 #ifdef GRF_AGA
    602 /* does sanity check on values */
    603 int
    604 cc_use_aga_colormap(v, cm)
    605 	view_t *v;
    606 	colormap_t *cm;
    607 {
    608 	colormap_t *vcm = VDATA(v)->colormap;
    609 	int     s, i;
    610 
    611 	if (!cc_colormap_checkvals(vcm, cm, 1)) {
    612 		return (EINVAL);
    613 	}
    614 	/* check to see if its the view's colormap, if so just do update. */
    615 	if (vcm != cm) {
    616 		/* copy entries into colormap. */
    617 		for (i = cm->first; i < (cm->first + cm->size); i++) {
    618 			vcm->entry[i] = cm->entry[i];
    619 		}
    620 	}
    621 	s = spltty();
    622 
    623 	/* is view currently being displayed? */
    624 	if (VDATA(v)->flags & VF_DISPLAY) {
    625 		/* yes, update the copper lists */
    626 		cop_t  *tmp, *cp;
    627 		int     nframes = 1, j;
    628 
    629 		if (DMDATA(VDATA(v)->mode)->flags & DMF_INTERLACE) {
    630 			nframes = 2;
    631 		}
    632 		for (i = 0; i < nframes; i++) {
    633 			cp = DMDATA(VDATA(v)->mode)->frames[i];
    634 
    635 			tmp = find_copper_inst(cp, CI_MOVE(R_COLOR00));
    636 			for (j = 0; j < vcm->size; j += 32) {
    637 				int k;
    638 
    639 				for (k = 0; k < 32; k++) {
    640 					int ce = vcm->entry[j + k] >> 4;
    641 					CMOVE(tmp, R_COLOR00 + (k << 1), CM_LTOW(ce));
    642 				}
    643 				tmp++;
    644 				for (k = 0; k < 32; k++) {
    645 					int ce =vcm->entry[j + k];
    646 					CMOVE(tmp, R_COLOR00 + (k << 1), CM_LTOW(ce));
    647 				}
    648 				tmp++;
    649 			}
    650 		}
    651 	}
    652 	splx(s);
    653 	return (0);
    654 }
    655 #endif
    656 
    657 #if defined (GRF_A2024)
    658 colormap_t *
    659 cc_a2024_alloc_colormap(depth)
    660 	int depth;
    661 {
    662 	u_long  size = 1U << depth, i;
    663 	colormap_t *cm = alloc_chipmem(sizeof(u_long) * size + sizeof(*cm));
    664 
    665 	if (cm) {
    666 		cm->type = CM_GREYSCALE;
    667 		cm->grey_mask = 0x03;
    668 		cm->first = 0;
    669 		cm->size = size;
    670 		cm->entry = (u_long *) & cm[1];	/* table directly after. */
    671 		for (i = 0; i < size; i++) {
    672 			cm->entry[i] = CM_WTOL(cc_a2024_default_colors[i]);
    673 		}
    674 		return (cm);
    675 	}
    676 	return (NULL);
    677 }
    678 
    679 int
    680 cc_a2024_get_colormap(v, cm)
    681 	view_t *v;
    682 	colormap_t *cm;
    683 {
    684 	/* there are no differences (yet) in the way the cm's are stored */
    685 	return (cc_get_colormap(v, cm));
    686 }
    687 
    688 int
    689 cc_a2024_use_colormap(v, cm)
    690 	view_t *v;
    691 	colormap_t *cm;
    692 {
    693 	colormap_t *vcm = VDATA(v)->colormap;
    694 	int     s, i;
    695 
    696 	if (!cc_colormap_checkvals(vcm, cm, 1)) {
    697 		return (EINVAL);
    698 	}
    699 	/* check to see if its the view's colormap, if so just do update. */
    700 	if (vcm != cm) {
    701 		/* copy entries into colormap. */
    702 		for (i = cm->first; i < (cm->first + cm->size); i++) {
    703 			vcm->entry[i] = cm->entry[i];
    704 		}
    705 	}
    706 	s = spltty();
    707 
    708 	/* is view currently being displayed? */
    709 	if (VDATA(v)->flags & VF_DISPLAY) {
    710 		/* yes, update the copper lists */
    711 		cop_t  *tmp, *cp;
    712 		int     nframes = 2, nregs = cm->size == 4 ? 16 : 8, j;
    713 
    714 		if (DMDATA(VDATA(v)->mode)->flags & DMF_HEDLEY_EXP) {
    715 			nframes = 4;
    716 		}
    717 		for (i = 0; i < nframes; i++) {
    718 			cp = DMDATA(VDATA(v)->mode)->frames[i];
    719 
    720 			tmp = find_copper_inst(cp, CI_MOVE(R_COLOR07));
    721 			tmp -= 7;
    722 
    723 			for (j = 0; j < nregs; j++) {
    724 				CMOVE(tmp, R_COLOR00 + (j << 1), A2024_CM_TO_CR(vcm, j));
    725 			}
    726 		}
    727 	}
    728 	splx(s);
    729 	return (0);
    730 }
    731 #endif /* GRF_A2024 */
    732 
    733 
    734 /*
    735  * CC View stuff.
    736  */
    737 
    738 void
    739 cc_init_view(v, bm, mode, dbox)
    740 	view_t *v;
    741 	bmap_t *bm;
    742 	dmode_t *mode;
    743 	box_t *dbox;
    744 {
    745 	vdata_t *vd = VDATA(v);
    746 	v->bitmap = bm;
    747 	vd->mode = mode;
    748 	bcopy(dbox, &v->display, sizeof(box_t));
    749 
    750 	v->display_view = DMDATA(vd->mode)->display_view;
    751 	v->use_colormap = DMDATA(vd->mode)->use_colormap;
    752 	v->get_colormap = DMDATA(vd->mode)->get_colormap;
    753 	v->free_view = cc_free_view;
    754 	v->get_display_mode = cc_get_display_mode;
    755 	v->remove_view = cc_remove_view;
    756 }
    757 
    758 void
    759 cc_free_view(v)
    760 	view_t *v;
    761 {
    762 	if (v) {
    763 		vdata_t *vd = VDATA(v);
    764 		dmode_t *md = vd->mode;
    765 		v->remove_view(v);
    766 		free_chipmem(VDATA(v)->colormap);
    767 		cc_monitor->free_bitmap(v->bitmap);
    768 		free_chipmem(v);
    769 	}
    770 }
    771 
    772 void
    773 cc_remove_view(v)
    774 	view_t *v;
    775 {
    776 	dmode_t *mode = VDATA(v)->mode;
    777 
    778 	if (MDATA(cc_monitor)->current_mode == mode) {
    779 		if (DMDATA(mode)->current_view == v) {
    780 			cc_load_mode(NULL);
    781 		}
    782 	}
    783 	if (DMDATA(mode)->current_view == v) {
    784 		DMDATA(mode)->current_view = NULL;
    785 	}
    786 	VDATA(v)->flags &= ~VF_DISPLAY;
    787 }
    788 
    789 dmode_t *
    790 cc_get_display_mode(v)
    791 	view_t *v;
    792 {
    793 	return (VDATA(v)->mode);
    794 }
    795 
    796 void
    797 cc_mode_vbl_handler(d)
    798 	dmode_t *d;
    799 {
    800 	u_short vp = ((custom.vposr & 0x0007) << 8) | ((custom.vhposr) >> 8);
    801 
    802 	if (vp < 12) {
    803 		custom.cop1lc = PREP_DMA_MEM(DMDATA(d)->frames[F_LONG]);
    804 		custom.copjmp1 = 0;
    805 	}
    806 }
    807 
    808 void
    809 cc_lace_mode_vbl_handler(d)
    810 	dmode_t *d;
    811 {
    812 	u_short vp = ((custom.vposr & 0x0007) << 8) | ((custom.vhposr) >> 8);
    813 
    814 	if (vp < 12) {
    815 		if (custom.vposr & 0x8000) {
    816 			custom.cop1lc = PREP_DMA_MEM(DMDATA(d)->frames[F_LACE_LONG]);
    817 		} else {
    818 			custom.cop1lc = PREP_DMA_MEM(DMDATA(d)->frames[F_LACE_SHORT]);
    819 		}
    820 		custom.copjmp1 = 0;
    821 	}
    822 }
    823 
    824 /*
    825  * Modes. (ick)
    826  */
    827 
    828 /*
    829  * NTSC Modes
    830  */
    831 
    832 #if defined (GRF_NTSC)
    833 
    834 dmode_t *
    835 cc_init_ntsc_hires()
    836 {
    837 	/* this function should only be called once. */
    838 	if (!h_this) {
    839 		u_short len = std_copper_list_len;
    840 		cop_t  *cp;
    841 
    842 		h_this = &hires_mode;
    843 		h_this_data = &hires_mode_data;
    844 		bzero(h_this, sizeof(dmode_t));
    845 		bzero(h_this_data, sizeof(dmdata_t));
    846 
    847 		h_this->name = "ntsc: hires";
    848 		h_this->nominal_size.width = 640;
    849 		h_this->nominal_size.height = 200;
    850 		h_this_data->max_size.width = 724;
    851 		h_this_data->max_size.height = 242;
    852 		h_this_data->min_size.width = 320;
    853 		h_this_data->min_size.height = 100;
    854 		h_this_data->min_depth = 1;
    855 		h_this_data->max_depth = 4;
    856 		h_this->data = h_this_data;
    857 
    858 		h_this->get_monitor = cc_get_monitor;
    859 		h_this->alloc_view = cc_alloc_view;
    860 		h_this->get_current_view = cc_get_current_view;
    861 
    862 		h_this_data->use_colormap = cc_use_colormap;
    863 		h_this_data->get_colormap = cc_get_colormap;
    864 		h_this_data->alloc_colormap = cc_alloc_colormap;
    865 		h_this_data->display_view = display_hires_view;
    866 		h_this_data->monitor = cc_monitor;
    867 
    868 		h_this_data->frames = hires_frames;
    869 		h_this_data->frames[F_LONG] = alloc_chipmem(std_copper_list_size * F_TOTAL);
    870 		if (!h_this_data->frames[F_LONG]) {
    871 			panic("couldn't get chipmem for copper list");
    872 		}
    873 		h_this_data->frames[F_STORE_LONG] = &h_this_data->frames[F_LONG][len];
    874 
    875 		bcopy(std_copper_list, h_this_data->frames[F_STORE_LONG], std_copper_list_size);
    876 		bcopy(std_copper_list, h_this_data->frames[F_LONG], std_copper_list_size);
    877 
    878 		h_this_data->bplcon0 = 0x8200 | USE_CON3;	/* hires, color
    879 								 * composite enable */
    880 		h_this_data->std_start_x = STANDARD_VIEW_X;
    881 		h_this_data->std_start_y = STANDARD_VIEW_Y;
    882 		h_this_data->vbl_handler = (vbl_handler_func *) cc_mode_vbl_handler;
    883 #if defined (GRF_ECS)
    884 		h_this_data->beamcon0 = STANDARD_NTSC_BEAMCON;
    885 #endif
    886 
    887 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, h_this, link);
    888 	}
    889 	return (h_this);
    890 }
    891 
    892 void
    893 display_hires_view(v)
    894 	view_t *v;
    895 {
    896 	if (h_this_data->current_view != v) {
    897 		vdata_t *vd = VDATA(v);
    898 		monitor_t *monitor = h_this_data->monitor;
    899 		cop_t  *cp = h_this_data->frames[F_STORE_LONG], *tmp;
    900 		int     depth = v->bitmap->depth, i;
    901 		int     hstart, hstop, vstart, vstop, j;
    902 		int     x, y, w = v->display.width, h = v->display.height;
    903 		u_short ddfstart, ddfwidth, con1;
    904 
    905 		/* round down to nearest even width */
    906 		/* w &= 0xfffe; */
    907 		/* calculate datafetch width. */
    908 
    909 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 2) << 2;
    910 
    911 		/* This will center the any overscanned display */
    912 		/* and allow user to modify. */
    913 		x = v->display.x + h_this_data->std_start_x - ((w - 640) >> 2);
    914 		y = v->display.y + h_this_data->std_start_y - ((h - 200) >> 1);
    915 
    916 		if (y & 1)
    917 			y--;
    918 
    919 		if (!(x & 1))
    920 			x--;
    921 
    922 		hstart = x;
    923 		hstop = x + (w >> 1);
    924 		vstart = y;
    925 		vstop = y + h;
    926 		ddfstart = (hstart - 9) >> 1;
    927 
    928 		/* check for hardware limits, AGA may allow more..? */
    929 		/* anyone got a 4000 I can borrow :^) -ch */
    930 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
    931 			int     d = 0;
    932 
    933 			/* XXX anyone know the equality properties of
    934 			 * intermixed logial AND's */
    935 			/* XXX and arithmetic operators? */
    936 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
    937 				d++;
    938 			}
    939 
    940 			ddfstart -= d;
    941 			hstart -= d << 1;
    942 			hstop -= d << 1;
    943 		}
    944 		/* correct the datafetch to proper limits. */
    945 		/* delay the actual display of the data until we need it. */
    946 		ddfstart &= 0xfffc;
    947 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
    948 
    949 		if (h_this_data->current_view) {
    950 			VDATA(h_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
    951 			/* displayed. */
    952 		}
    953 		h_this_data->current_view = v;
    954 
    955 		cp = h_this_data->frames[F_STORE_LONG];
    956 #if defined GRF_ECS
    957 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON3));
    958 		tmp->cp.inst.operand = 0x0020;
    959 #if defined GRF_AGA
    960 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
    961 		tmp->cp.inst.operand = 0;
    962 #endif
    963 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
    964 		tmp->cp.inst.operand = h_this_data->beamcon0;
    965 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
    966 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
    967 #endif /* ECS */
    968 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
    969 		tmp->cp.inst.operand = h_this_data->bplcon0 | ((depth & 0x7) << 12);
    970 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
    971 		tmp->cp.inst.operand = con1;
    972 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
    973 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
    974 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
    975 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
    976 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
    977 		tmp->cp.inst.operand = ddfstart;
    978 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
    979 		tmp->cp.inst.operand = ddfstart + ddfwidth;
    980 
    981 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
    982 		for (i = 0, j = 0; i < depth; j += 2, i++) {
    983 			/* update the plane pointers */
    984 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
    985 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
    986 		}
    987 
    988 		/* set mods correctly. */
    989 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
    990 		tmp[0].cp.inst.operand = v->bitmap->row_mod;
    991 		tmp[1].cp.inst.operand = v->bitmap->row_mod;
    992 
    993 		/* set next pointers correctly */
    994 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
    995 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(h_this_data->frames[F_STORE_LONG]));
    996 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(h_this_data->frames[F_STORE_LONG]));
    997 
    998 		cp = h_this_data->frames[F_LONG];
    999 		h_this_data->frames[F_LONG] = h_this_data->frames[F_STORE_LONG];
   1000 		h_this_data->frames[F_STORE_LONG] = cp;
   1001 
   1002 		vd->flags |= VF_DISPLAY;
   1003 
   1004 		cc_use_colormap(v, vd->colormap);
   1005 	}
   1006 	cc_load_mode(h_this);
   1007 }
   1008 
   1009 dmode_t *
   1010 cc_init_ntsc_hires_lace()
   1011 {
   1012 	/* this function should only be called once. */
   1013 	if (!hl_this) {
   1014 		u_short len = std_copper_list_len;
   1015 		cop_t  *cp;
   1016 
   1017 		hl_this = &hires_lace_mode;
   1018 		hl_this_data = &hires_lace_mode_data;
   1019 		bzero(hl_this, sizeof(dmode_t));
   1020 		bzero(hl_this_data, sizeof(dmdata_t));
   1021 
   1022 		hl_this->name = "ntsc: hires interlace";
   1023 		hl_this->nominal_size.width = 640;
   1024 		hl_this->nominal_size.height = 400;
   1025 		hl_this_data->max_size.width = 724;
   1026 		hl_this_data->max_size.height = 482;
   1027 		hl_this_data->min_size.width = 320;
   1028 		hl_this_data->min_size.height = 200;
   1029 		hl_this_data->min_depth = 1;
   1030 		hl_this_data->max_depth = 4;
   1031 		hl_this->data = hl_this_data;
   1032 
   1033 		hl_this->get_monitor = cc_get_monitor;
   1034 		hl_this->alloc_view = cc_alloc_view;
   1035 		hl_this->get_current_view = cc_get_current_view;
   1036 
   1037 		hl_this_data->use_colormap = cc_use_colormap;
   1038 		hl_this_data->get_colormap = cc_get_colormap;
   1039 		hl_this_data->alloc_colormap = cc_alloc_colormap;
   1040 		hl_this_data->display_view = display_hires_lace_view;
   1041 		hl_this_data->monitor = cc_monitor;
   1042 
   1043 		hl_this_data->flags |= DMF_INTERLACE;
   1044 
   1045 		hl_this_data->frames = hires_lace_frames;
   1046 		hl_this_data->frames[F_LACE_LONG] = alloc_chipmem(std_copper_list_size * F_LACE_TOTAL);
   1047 		if (!hl_this_data->frames[F_LACE_LONG]) {
   1048 			panic("couldn't get chipmem for copper list");
   1049 		}
   1050 		hl_this_data->frames[F_LACE_SHORT] = &hl_this_data->frames[F_LACE_LONG][len];
   1051 		hl_this_data->frames[F_LACE_STORE_LONG] = &hl_this_data->frames[F_LACE_SHORT][len];
   1052 		hl_this_data->frames[F_LACE_STORE_SHORT] = &hl_this_data->frames[F_LACE_STORE_LONG][len];
   1053 
   1054 		bcopy(std_copper_list, hl_this_data->frames[F_LACE_STORE_LONG], std_copper_list_size);
   1055 		bcopy(std_copper_list, hl_this_data->frames[F_LACE_STORE_SHORT], std_copper_list_size);
   1056 		bcopy(std_copper_list, hl_this_data->frames[F_LACE_LONG], std_copper_list_size);
   1057 		bcopy(std_copper_list, hl_this_data->frames[F_LACE_SHORT], std_copper_list_size);
   1058 
   1059 		hl_this_data->bplcon0 = 0x8204 | USE_CON3;	/* hires, color
   1060 								 * composite enable,
   1061 								 * lace. */
   1062 		hl_this_data->std_start_x = STANDARD_VIEW_X;
   1063 		hl_this_data->std_start_y = STANDARD_VIEW_Y;
   1064 		hl_this_data->vbl_handler = (vbl_handler_func *) cc_lace_mode_vbl_handler;
   1065 #if defined (GRF_ECS)
   1066 		hl_this_data->beamcon0 = STANDARD_NTSC_BEAMCON;
   1067 #endif
   1068 
   1069 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, hl_this, link);
   1070 	}
   1071 	return (hl_this);
   1072 }
   1073 
   1074 void
   1075 display_hires_lace_view(v)
   1076 	view_t *v;
   1077 {
   1078 	if (hl_this_data->current_view != v) {
   1079 		vdata_t *vd = VDATA(v);
   1080 		monitor_t *monitor = hl_this_data->monitor;
   1081 		cop_t  *cp = hl_this_data->frames[F_LACE_STORE_LONG], *tmp;
   1082 		int     depth = v->bitmap->depth, i;
   1083 		int     hstart, hstop, vstart, vstop, j;
   1084 		int     x, y, w = v->display.width, h = v->display.height;
   1085 		u_short ddfstart, ddfwidth, con1;
   1086 
   1087 		/* round down to nearest even width */
   1088 		/* w &= 0xfffe; */
   1089 
   1090 
   1091 		/* calculate datafetch width. */
   1092 
   1093 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 2) << 2;
   1094 
   1095 		/* This will center the any overscanned display */
   1096 		/* and allow user to modify. */
   1097 		x = v->display.x + hl_this_data->std_start_x - ((w - 640) >> 2);
   1098 		y = v->display.y + hl_this_data->std_start_y - ((h - 400) >> 2);
   1099 
   1100 		if (y & 1)
   1101 			y--;
   1102 
   1103 		if (!(x & 1))
   1104 			x--;
   1105 
   1106 		hstart = x;
   1107 		hstop = x + (w >> 1);
   1108 		vstart = y;
   1109 		vstop = y + (h >> 1);
   1110 		ddfstart = (hstart - 9) >> 1;
   1111 
   1112 		/* check for hardware limits, AGA may allow more..? */
   1113 		/* anyone got a 4000 I can borrow :^) -ch */
   1114 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
   1115 			int     d = 0;
   1116 
   1117 			/* XXX anyone know the equality properties of
   1118 			 * intermixed logial AND's */
   1119 			/* XXX and arithmetic operators? */
   1120 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
   1121 				d++;
   1122 			}
   1123 
   1124 			ddfstart -= d;
   1125 			hstart -= d << 1;
   1126 			hstop -= d << 1;
   1127 		}
   1128 		/* correct the datafetch to proper limits. */
   1129 		/* delay the actual display of the data until we need it. */
   1130 		ddfstart &= 0xfffc;
   1131 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
   1132 
   1133 		if (hl_this_data->current_view) {
   1134 			VDATA(hl_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
   1135 			/* displayed. */
   1136 		}
   1137 		hl_this_data->current_view = v;
   1138 
   1139 		cp = hl_this_data->frames[F_LACE_STORE_LONG];
   1140 #if defined GRF_ECS
   1141 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON3));
   1142 		tmp->cp.inst.operand = 0x0020;
   1143 #if defined GRF_AGA
   1144 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
   1145 		tmp->cp.inst.operand = 0;
   1146 #endif
   1147 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
   1148 		tmp->cp.inst.operand = hl_this_data->beamcon0;
   1149 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
   1150 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
   1151 #endif /* ECS */
   1152 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
   1153 		tmp->cp.inst.operand = hl_this_data->bplcon0 | ((depth & 0x7) << 12);
   1154 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
   1155 		tmp->cp.inst.operand = con1;
   1156 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
   1157 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
   1158 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
   1159 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
   1160 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
   1161 		tmp->cp.inst.operand = ddfstart;
   1162 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
   1163 		tmp->cp.inst.operand = ddfstart + ddfwidth;
   1164 
   1165 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   1166 		for (i = 0, j = 0; i < depth; j += 2, i++) {
   1167 			/* update the plane pointers */
   1168 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   1169 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   1170 		}
   1171 
   1172 		/* set mods correctly. */
   1173 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
   1174 		tmp[0].cp.inst.operand = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   1175 		tmp[1].cp.inst.operand = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   1176 
   1177 		/* set next pointers correctly */
   1178 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   1179 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(hl_this_data->frames[F_LACE_STORE_SHORT]));
   1180 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(hl_this_data->frames[F_LACE_STORE_SHORT]));
   1181 
   1182 
   1183 		bcopy(hl_this_data->frames[F_LACE_STORE_LONG], hl_this_data->frames[F_LACE_STORE_SHORT], std_copper_list_size);
   1184 
   1185 		/* these are the only ones that are different from long frame. */
   1186 		cp = hl_this_data->frames[F_LACE_STORE_SHORT];
   1187 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   1188 		for (i = 0, j = 0; i < depth; j += 2, i++) {
   1189 			u_short mod = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   1190 			/* update plane pointers. high and low. */
   1191 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[i][mod]));
   1192 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[i][mod]));
   1193 		}
   1194 
   1195 		/* set next pointers correctly */
   1196 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   1197 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(hl_this_data->frames[F_LACE_STORE_LONG]));
   1198 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(hl_this_data->frames[F_LACE_STORE_LONG]));
   1199 
   1200 
   1201 		cp = hl_this_data->frames[F_LACE_LONG];
   1202 		hl_this_data->frames[F_LACE_LONG] = hl_this_data->frames[F_LACE_STORE_LONG];
   1203 		hl_this_data->frames[F_LACE_STORE_LONG] = cp;
   1204 
   1205 		cp = hl_this_data->frames[F_LACE_SHORT];
   1206 		hl_this_data->frames[F_LACE_SHORT] = hl_this_data->frames[F_LACE_STORE_SHORT];
   1207 		hl_this_data->frames[F_LACE_STORE_SHORT] = cp;
   1208 
   1209 		vd->flags |= VF_DISPLAY;
   1210 
   1211 		cc_use_colormap(v, vd->colormap);
   1212 	}
   1213 	cc_load_mode(hl_this);
   1214 }
   1215 #if defined (GRF_A2024)
   1216 
   1217 dmode_t *
   1218 cc_init_ntsc_hires_dlace()
   1219 {
   1220 	/* this function should only be called once. */
   1221 	if (!hdl_this) {
   1222 		u_short len = std_dlace_copper_list_len;
   1223 		cop_t  *cp;
   1224 
   1225 		hdl_this = &hires_dlace_mode;
   1226 		hdl_this_data = &hires_dlace_mode_data;
   1227 		bzero(hdl_this, sizeof(dmode_t));
   1228 		bzero(hdl_this_data, sizeof(dmdata_t));
   1229 
   1230 		hdl_this->name = "ntsc: hires double interlace";
   1231 		hdl_this->nominal_size.width = 640;
   1232 		hdl_this->nominal_size.height = 800;
   1233 		hdl_this_data->max_size.width = 724;
   1234 		hdl_this_data->max_size.height = 800;
   1235 		hdl_this_data->min_size.width = 320;
   1236 		hdl_this_data->min_size.height = 400;
   1237 		hdl_this_data->min_depth = 1;
   1238 		hdl_this_data->max_depth = 2;
   1239 		hdl_this->data = hdl_this_data;
   1240 
   1241 		hdl_this->get_monitor = cc_get_monitor;
   1242 		hdl_this->alloc_view = cc_alloc_view;
   1243 		hdl_this->get_current_view = cc_get_current_view;
   1244 
   1245 		hdl_this_data->use_colormap = cc_a2024_use_colormap;
   1246 		hdl_this_data->get_colormap = cc_a2024_get_colormap;
   1247 		hdl_this_data->alloc_colormap = cc_a2024_alloc_colormap;
   1248 		hdl_this_data->display_view = display_hires_dlace_view;
   1249 		hdl_this_data->monitor = cc_monitor;
   1250 
   1251 		hdl_this_data->flags |= DMF_INTERLACE;
   1252 
   1253 		hdl_this_data->frames = hires_dlace_frames;
   1254 		hdl_this_data->frames[F_LACE_LONG] = alloc_chipmem(std_dlace_copper_list_size * F_LACE_TOTAL);
   1255 		if (!hdl_this_data->frames[F_LACE_LONG]) {
   1256 			panic("couldn't get chipmem for copper list");
   1257 		}
   1258 		hdl_this_data->frames[F_LACE_SHORT] = &hdl_this_data->frames[F_LACE_LONG][len];
   1259 		hdl_this_data->frames[F_LACE_STORE_LONG] = &hdl_this_data->frames[F_LACE_SHORT][len];
   1260 		hdl_this_data->frames[F_LACE_STORE_SHORT] = &hdl_this_data->frames[F_LACE_STORE_LONG][len];
   1261 
   1262 		bcopy(std_dlace_copper_list, hdl_this_data->frames[F_LACE_STORE_LONG], std_dlace_copper_list_size);
   1263 		bcopy(std_dlace_copper_list, hdl_this_data->frames[F_LACE_STORE_SHORT], std_dlace_copper_list_size);
   1264 		bcopy(std_dlace_copper_list, hdl_this_data->frames[F_LACE_LONG], std_dlace_copper_list_size);
   1265 		bcopy(std_dlace_copper_list, hdl_this_data->frames[F_LACE_SHORT], std_dlace_copper_list_size);
   1266 
   1267 		hdl_this_data->bplcon0 = 0x8204 | USE_CON3;	/* hires, color
   1268 								 * composite enable,
   1269 								 * dlace. */
   1270 		hdl_this_data->std_start_x = STANDARD_VIEW_X;
   1271 		hdl_this_data->std_start_y = STANDARD_VIEW_Y;
   1272 		hdl_this_data->vbl_handler = (vbl_handler_func *) cc_lace_mode_vbl_handler;
   1273 #if defined (GRF_ECS)
   1274 		hdl_this_data->beamcon0 = STANDARD_NTSC_BEAMCON;
   1275 #endif
   1276 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, hdl_this, link);
   1277 	}
   1278 	return (hdl_this);
   1279 }
   1280 
   1281 void
   1282 display_hires_dlace_view(v)
   1283 	view_t *v;
   1284 {
   1285 	if (hdl_this_data->current_view != v) {
   1286 		vdata_t *vd = VDATA(v);
   1287 		monitor_t *monitor = hdl_this_data->monitor;
   1288 		cop_t  *cp = hdl_this_data->frames[F_LACE_STORE_LONG], *tmp;
   1289 		int     depth = v->bitmap->depth, i;
   1290 		int     hstart, hstop, vstart, vstop, j;
   1291 		int     x, y, w = v->display.width, h = v->display.height;
   1292 		u_short ddfstart, ddfwidth, con1;
   1293 		u_short mod1l, mod2l;
   1294 
   1295 		/* round down to nearest even width */
   1296 		/* w &= 0xfffe; */
   1297 
   1298 		/* calculate datafetch width. */
   1299 
   1300 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 2) << 2;
   1301 
   1302 		/* This will center the any overscanned display */
   1303 		/* and allow user to modify. */
   1304 		x = v->display.x + hdl_this_data->std_start_x - ((w - 640) >> 2);
   1305 		y = v->display.y + hdl_this_data->std_start_y - ((h - 800) >> 3);
   1306 
   1307 		if (y & 1)
   1308 			y--;
   1309 
   1310 		if (!(x & 1))
   1311 			x--;
   1312 
   1313 		hstart = x;
   1314 		hstop = x + (w >> 1);
   1315 		vstart = y;
   1316 		vstop = y + (h >> 2);
   1317 
   1318 		ddfstart = (hstart - 9) >> 1;
   1319 
   1320 		/* check for hardware limits, AGA may allow more..? */
   1321 		/* anyone got a 4000 I can borrow :^) -ch */
   1322 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
   1323 			int     d = 0;
   1324 
   1325 			/* XXX anyone know the equality properties of
   1326 			 * intermixed logial AND's */
   1327 			/* XXX and arithmetic operators? */
   1328 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
   1329 				d++;
   1330 			}
   1331 
   1332 			ddfstart -= d;
   1333 			hstart -= d << 1;
   1334 			hstop -= d << 1;
   1335 		}
   1336 		/* correct the datafetch to proper limits. */
   1337 		/* delay the actual display of the data until we need it. */
   1338 		ddfstart &= 0xfffc;
   1339 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
   1340 
   1341 		if (hdl_this_data->current_view) {
   1342 			VDATA(hdl_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
   1343 			/* displayed. */
   1344 		}
   1345 		hdl_this_data->current_view = v;
   1346 
   1347 		cp = hdl_this_data->frames[F_LACE_STORE_LONG];
   1348 #if defined GRF_ECS
   1349 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON3));
   1350 		tmp->cp.inst.operand = 0x0020;
   1351 #if defined GRF_AGA
   1352 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
   1353 		tmp->cp.inst.operand = 0;
   1354 #endif
   1355 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
   1356 		tmp->cp.inst.operand = hdl_this_data->beamcon0;
   1357 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
   1358 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
   1359 #endif /* ECS */
   1360 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
   1361 		tmp->cp.inst.operand = hdl_this_data->bplcon0 | ((depth & 0x7) << 13);	/* times two. */
   1362 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
   1363 		tmp->cp.inst.operand = con1;
   1364 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
   1365 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
   1366 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
   1367 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
   1368 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
   1369 		tmp->cp.inst.operand = ddfstart;
   1370 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
   1371 		tmp->cp.inst.operand = ddfstart + ddfwidth;
   1372 
   1373 		mod1l = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   1374 		mod2l = mod1l << 1;
   1375 
   1376 		/* update plane pointers. */
   1377 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   1378 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][0]));
   1379 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][0]));
   1380 		tmp[2].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod1l]));
   1381 		tmp[3].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod1l]));
   1382 		if (depth == 2) {
   1383 			tmp[4].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][0]));
   1384 			tmp[5].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][0]));
   1385 			tmp[6].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod1l]));
   1386 			tmp[7].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod1l]));
   1387 		}
   1388 		/* set modulos. */
   1389 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
   1390 		tmp[0].cp.inst.operand = mod2l + mod1l;
   1391 		tmp[1].cp.inst.operand = mod2l + mod1l;
   1392 
   1393 
   1394 		/* set next coper list pointers */
   1395 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   1396 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(hdl_this_data->frames[F_LACE_STORE_SHORT]));
   1397 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(hdl_this_data->frames[F_LACE_STORE_SHORT]));
   1398 
   1399 		bcopy(hdl_this_data->frames[F_LACE_STORE_LONG], hdl_this_data->frames[F_LACE_STORE_SHORT],
   1400 		    std_dlace_copper_list_size);
   1401 
   1402 		/* these are the only ones that are different from long frame. */
   1403 		cp = hdl_this_data->frames[F_LACE_STORE_SHORT];
   1404 		/* update plane pointers. */
   1405 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   1406 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l]));
   1407 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l]));
   1408 		tmp[2].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l + mod1l]));
   1409 		tmp[3].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l + mod1l]));
   1410 		if (depth == 2) {
   1411 			tmp[4].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l]));
   1412 			tmp[5].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l]));
   1413 			tmp[6].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l + mod1l]));
   1414 			tmp[7].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l + mod1l]));
   1415 		}
   1416 		/* set next copper list pointers */
   1417 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   1418 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(hdl_this_data->frames[F_LACE_STORE_LONG]));
   1419 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(hdl_this_data->frames[F_LACE_STORE_LONG]));
   1420 
   1421 		cp = hdl_this_data->frames[F_LACE_LONG];
   1422 		hdl_this_data->frames[F_LACE_LONG] = hdl_this_data->frames[F_LACE_STORE_LONG];
   1423 		hdl_this_data->frames[F_LACE_STORE_LONG] = cp;
   1424 
   1425 		cp = hdl_this_data->frames[F_LACE_SHORT];
   1426 		hdl_this_data->frames[F_LACE_SHORT] = hdl_this_data->frames[F_LACE_STORE_SHORT];
   1427 		hdl_this_data->frames[F_LACE_STORE_SHORT] = cp;
   1428 
   1429 		vd->flags |= VF_DISPLAY;
   1430 		cc_a2024_use_colormap(v, vd->colormap);
   1431 	}
   1432 	cc_load_mode(hdl_this);
   1433 }
   1434 
   1435 
   1436 dmode_t *
   1437 cc_init_ntsc_a2024()
   1438 {
   1439 	/* this function should only be called once. */
   1440 	if (!a24_this) {
   1441 		int     i;
   1442 		u_short len = std_a2024_copper_list_len;
   1443 		cop_t  *cp;
   1444 
   1445 		a24_this = &a2024_mode;
   1446 		a24_this_data = &a2024_mode_data;
   1447 		bzero(a24_this, sizeof(dmode_t));
   1448 		bzero(a24_this_data, sizeof(dmdata_t));
   1449 
   1450 		a24_this->name = "ntsc: A2024 15khz";
   1451 		a24_this->nominal_size.width = 1024;
   1452 		a24_this->nominal_size.height = 800;
   1453 		a24_this_data->max_size.width = 1024;
   1454 		a24_this_data->max_size.height = 800;
   1455 		a24_this_data->min_size.width = 1024;
   1456 		a24_this_data->min_size.height = 800;
   1457 		a24_this_data->min_depth = 1;
   1458 		a24_this_data->max_depth = 2;
   1459 		a24_this->data = a24_this_data;
   1460 
   1461 		a24_this->get_monitor = cc_get_monitor;
   1462 		a24_this->alloc_view = cc_alloc_view;
   1463 		a24_this->get_current_view = cc_get_current_view;
   1464 
   1465 		a24_this_data->use_colormap = cc_a2024_use_colormap;
   1466 		a24_this_data->get_colormap = cc_a2024_get_colormap;
   1467 		a24_this_data->display_view = display_a2024_view;
   1468 		a24_this_data->alloc_colormap = cc_a2024_alloc_colormap;
   1469 		a24_this_data->monitor = cc_monitor;
   1470 
   1471 		a24_this_data->flags |= DMF_HEDLEY_EXP;
   1472 
   1473 		a24_this_data->frames = a2024_frames;
   1474 		a24_this_data->frames[F_QD_QUAD0] = alloc_chipmem(std_a2024_copper_list_size * F_QD_TOTAL);
   1475 		if (!a24_this_data->frames[F_QD_QUAD0]) {
   1476 			panic("couldn't get chipmem for copper list");
   1477 		}
   1478 		/* setup the hedley init bitplane. */
   1479 		hedley_init = alloc_chipmem(128);
   1480 		if (!hedley_init) {
   1481 			panic("couldn't get chipmem for hedley init bitplane");
   1482 		}
   1483 		for (i = 1; i < 128; i++)
   1484 			hedley_init[i] = 0xff;
   1485 		hedley_init[0] = 0x03;
   1486 
   1487 		/* copy image of standard copper list. */
   1488 		bcopy(std_a2024_copper_list, a24_this_data->frames[0], std_a2024_copper_list_size);
   1489 
   1490 		/* set the init plane pointer. */
   1491 		cp = find_copper_inst(a24_this_data->frames[F_QD_QUAD0], CI_MOVE(R_BPL0PTH));
   1492 		cp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(hedley_init));
   1493 		cp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(hedley_init));
   1494 
   1495 		for (i = 1; i < F_QD_TOTAL; i++) {
   1496 			a24_this_data->frames[i] = &a24_this_data->frames[i - 1][len];
   1497 			bcopy(a24_this_data->frames[0], a24_this_data->frames[i], std_a2024_copper_list_size);
   1498 		}
   1499 
   1500 		a24_this_data->bplcon0 = 0x8200;	/* hires */
   1501 		a24_this_data->vbl_handler = (vbl_handler_func *) a2024_mode_vbl_handler;
   1502 
   1503 
   1504 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, a24_this, link);
   1505 	}
   1506 	return (a24_this);
   1507 }
   1508 
   1509 void
   1510 display_a2024_view(v)
   1511 	view_t *v;
   1512 {
   1513 	if (a24_this_data->current_view != v) {
   1514 		vdata_t *vd = VDATA(v);
   1515 		monitor_t *monitor = a24_this_data->monitor;
   1516 		cop_t  *cp, *tmp;
   1517 		u_char *inst_plane[2];
   1518 		u_char **plane = inst_plane;
   1519 		u_long  full_line = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   1520 		u_long  half_plane = full_line * v->bitmap->rows / 2;
   1521 
   1522 		int     line_mod = 0xbc;	/* standard 2024 15khz mod. */
   1523 		int     depth = v->bitmap->depth, i, j;
   1524 
   1525 		plane[0] = v->bitmap->plane[0];
   1526 		if (depth == 2) {
   1527 			plane[1] = v->bitmap->plane[1];
   1528 		}
   1529 		if (a24_this_data->current_view) {
   1530 			VDATA(a24_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer
   1531 											 * displayed. */
   1532 		}
   1533 		cp = a24_this_data->frames[F_QD_STORE_QUAD0];
   1534 		tmp = find_copper_inst(cp, CI_MOVE(R_COLOR1F));
   1535 		tmp = find_copper_inst(tmp, CI_MOVE(R_BPLCON0));	/* grab third one. */
   1536 		tmp->cp.inst.operand = a24_this_data->bplcon0 | ((depth & 0x7) << 13);	/* times 2 */
   1537 
   1538 		bcopy(a24_this_data->frames[F_QD_STORE_QUAD0], a24_this_data->frames[F_QD_STORE_QUAD1], std_a2024_copper_list_size);
   1539 		bcopy(a24_this_data->frames[F_QD_STORE_QUAD0], a24_this_data->frames[F_QD_STORE_QUAD2], std_a2024_copper_list_size);
   1540 		bcopy(a24_this_data->frames[F_QD_STORE_QUAD0], a24_this_data->frames[F_QD_STORE_QUAD3], std_a2024_copper_list_size);
   1541 
   1542 		/*
   1543 		 * Mark Id's
   1544 		 */
   1545 		tmp = find_copper_inst(a24_this_data->frames[F_QD_STORE_QUAD1], CI_WAIT(126, 21));
   1546 		CBUMP(tmp);
   1547 		CMOVE(tmp, R_COLOR01, QUAD1_ID);
   1548 		tmp = find_copper_inst(a24_this_data->frames[F_QD_STORE_QUAD2], CI_WAIT(126, 21));
   1549 		CBUMP(tmp);
   1550 		CMOVE(tmp, R_COLOR01, QUAD2_ID);
   1551 		tmp = find_copper_inst(a24_this_data->frames[F_QD_STORE_QUAD3], CI_WAIT(126, 21));
   1552 		CBUMP(tmp);
   1553 		CMOVE(tmp, R_COLOR01, QUAD3_ID);
   1554 
   1555 		plane[0]--;
   1556 		plane[0]--;
   1557 		if (depth == 2) {
   1558 			plane[1]--;
   1559 			plane[1]--;
   1560 		}
   1561 		/*
   1562 		 * Set bitplane pointers.
   1563 		 */
   1564 		tmp = find_copper_inst(a24_this_data->frames[F_QD_STORE_QUAD0], CI_MOVE(R_BPLMOD2));
   1565 		CBUMP(tmp);
   1566 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][0])));
   1567 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][0])));
   1568 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][full_line])));
   1569 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][full_line])));
   1570 		if (depth == 2) {
   1571 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][0])));
   1572 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][0])));
   1573 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][full_line])));
   1574 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][full_line])));
   1575 		}
   1576 #if defined (GRF_ECS)
   1577 		CMOVE(tmp, R_DIWHIGH, 0x2000);
   1578 #endif
   1579 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD1])));
   1580 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD1])));
   1581 		CEND(tmp);
   1582 		CEND(tmp);
   1583 
   1584 		tmp = find_copper_inst(a24_this_data->frames[F_QD_STORE_QUAD1], CI_MOVE(R_BPLMOD2));
   1585 		CBUMP(tmp);
   1586 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][HALF_2024_LINE])));
   1587 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][HALF_2024_LINE])));
   1588 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][full_line + HALF_2024_LINE])));
   1589 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][full_line + HALF_2024_LINE])));
   1590 		if (depth == 2) {
   1591 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][HALF_2024_LINE])));
   1592 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][HALF_2024_LINE])));
   1593 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][full_line + HALF_2024_LINE])));
   1594 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][full_line + HALF_2024_LINE])));
   1595 		}
   1596 #if defined (GRF_ECS)
   1597 		CMOVE(tmp, R_DIWHIGH, 0x2000);
   1598 #endif
   1599 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD2])));
   1600 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD2])));
   1601 		CEND(tmp);
   1602 		CEND(tmp);
   1603 
   1604 		tmp = find_copper_inst(a24_this_data->frames[F_QD_STORE_QUAD2], CI_MOVE(R_BPLMOD2));
   1605 		CBUMP(tmp);
   1606 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane])));
   1607 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane])));
   1608 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line])));
   1609 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line])));
   1610 		if (depth == 2) {
   1611 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane])));
   1612 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane])));
   1613 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line])));
   1614 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line])));
   1615 		}
   1616 #if defined (GRF_ECS)
   1617 		CMOVE(tmp, R_DIWHIGH, 0x2000);
   1618 #endif
   1619 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD3])));
   1620 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD3])));
   1621 		CEND(tmp);
   1622 		CEND(tmp);
   1623 
   1624 		tmp = find_copper_inst(a24_this_data->frames[F_QD_STORE_QUAD3], CI_MOVE(R_BPLMOD2));
   1625 		CBUMP(tmp);
   1626 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane + HALF_2024_LINE])));
   1627 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane + HALF_2024_LINE])));
   1628 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line + HALF_2024_LINE])));
   1629 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line + HALF_2024_LINE])));
   1630 		if (depth == 2) {
   1631 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane + HALF_2024_LINE])));
   1632 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane + HALF_2024_LINE])));
   1633 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line + HALF_2024_LINE])));
   1634 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line + HALF_2024_LINE])));
   1635 		}
   1636 #if defined (GRF_ECS)
   1637 		CMOVE(tmp, R_DIWHIGH, 0x2000);
   1638 #endif
   1639 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD0])));
   1640 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(a24_this_data->frames[F_QD_STORE_QUAD0])));
   1641 		CEND(tmp);
   1642 		CEND(tmp);
   1643 
   1644 		/* swap new pointers in. */
   1645 		for (i = F_QD_STORE_QUAD0, j = F_QD_QUAD0;
   1646 		    i <= F_QD_STORE_QUAD3; i++, j++) {
   1647 			cp = a24_this_data->frames[j];
   1648 			a24_this_data->frames[j] = a24_this_data->frames[i];
   1649 			a24_this_data->frames[i] = cp;
   1650 		}
   1651 
   1652 		a24_this_data->current_view = v;
   1653 		vd->flags |= VF_DISPLAY;
   1654 
   1655 		cc_a2024_use_colormap(v, vd->colormap);
   1656 	}
   1657 	cc_load_mode(a24_this);
   1658 }
   1659 
   1660 void
   1661 a2024_mode_vbl_handler(d)
   1662 	dmode_t *d;
   1663 {
   1664 	u_short vp = ((custom.vposr & 0x0007) << 8) | ((custom.vhposr) >> 8);
   1665 
   1666 	if (vp < 12) {
   1667 		custom.cop1lc = PREP_DMA_MEM(a24_this_data->frames[a24_this_data->hedley_current]);
   1668 		custom.copjmp1 = 0;
   1669 	}
   1670 	a24_this_data->hedley_current++;
   1671 	a24_this_data->hedley_current &= 0x3;	/* if 4 then 0. */
   1672 }
   1673 #endif /* GRF_A2024 */
   1674 
   1675 #if defined (GRF_AGA)
   1676 
   1677 dmode_t *
   1678 cc_init_ntsc_aga()
   1679 {
   1680 	/* this function should only be called once. */
   1681 	if (!aga_this && (custom.deniseid & 0xff) == 0xf8 &&
   1682 	    aga_enable & AGA_ENABLE) {
   1683 		u_short len = aga_copper_list_len;
   1684 		cop_t  *cp;
   1685 
   1686 		aga_this = &aga_mode;
   1687 		aga_this_data = &aga_mode_data;
   1688 		bzero(aga_this, sizeof(dmode_t));
   1689 		bzero(aga_this_data, sizeof(dmdata_t));
   1690 
   1691 		aga_this->name = "ntsc: AGA dbl";
   1692 		aga_this->nominal_size.width = 640;
   1693 		aga_this->nominal_size.height = 400;
   1694 		aga_this_data->max_size.width = 724;
   1695 		aga_this_data->max_size.height = 482;
   1696 		aga_this_data->min_size.width = 320;
   1697 		aga_this_data->min_size.height = 200;
   1698 		aga_this_data->min_depth = 1;
   1699 		aga_this_data->max_depth = 8;
   1700 		aga_this->data = aga_this_data;
   1701 
   1702 		aga_this->get_monitor = cc_get_monitor;
   1703 		aga_this->alloc_view = cc_alloc_view;
   1704 		aga_this->get_current_view = cc_get_current_view;
   1705 
   1706 		aga_this_data->use_colormap = cc_use_aga_colormap;
   1707 		aga_this_data->get_colormap = cc_get_colormap;
   1708 		aga_this_data->alloc_colormap = cc_alloc_aga_colormap;
   1709 		aga_this_data->display_view = display_aga_view;
   1710 		aga_this_data->monitor = cc_monitor;
   1711 
   1712 		aga_this_data->frames = aga_frames;
   1713 		aga_this_data->frames[F_LONG] = alloc_chipmem(aga_copper_list_size * F_TOTAL);
   1714 		if (!aga_this_data->frames[F_LONG]) {
   1715 			panic("couldn't get chipmem for copper list");
   1716 		}
   1717 		aga_this_data->frames[F_STORE_LONG] = &aga_this_data->frames[F_LONG][len];
   1718 
   1719 		bcopy(aga_copper_list, aga_this_data->frames[F_STORE_LONG], aga_copper_list_size);
   1720 		bcopy(aga_copper_list, aga_this_data->frames[F_LONG], aga_copper_list_size);
   1721 
   1722 		aga_this_data->bplcon0 = 0x0240 | USE_CON3;	/* color composite
   1723 								 * enable,
   1724 								 * shres. */
   1725 		aga_this_data->std_start_x = 0x4f /*STANDARD_VIEW_X*/;
   1726 		aga_this_data->std_start_y = 0x2b /*STANDARD_VIEW_Y*/;
   1727 		aga_this_data->vbl_handler = (vbl_handler_func *) cc_mode_vbl_handler;
   1728 		aga_this_data->beamcon0 = SPECIAL_BEAMCON ^ VSYNCTRUE;
   1729 
   1730 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes,
   1731 		    aga_this, link);
   1732 	}
   1733 	return (aga_this);
   1734 }
   1735 
   1736 /* static, so I can patch and play */
   1737 
   1738 int	AGA_htotal = 0x79;
   1739 int	AGA_hsstrt = 0xe;
   1740 int	AGA_hsstop = 0x1c;
   1741 int	AGA_hbstrt = 0x8;
   1742 int	AGA_hbstop = 0x1e;
   1743 int	AGA_vtotal = 0x1ec;
   1744 int	AGA_vsstrt = 0x3;
   1745 int	AGA_vsstop = 0x6;
   1746 int	AGA_vbstrt = 0x0;
   1747 int	AGA_vbstop = 0x19;
   1748 int	AGA_hcenter = 0x4a;
   1749 
   1750 void
   1751 display_aga_view(v)
   1752 	view_t *v;
   1753 {
   1754 	if (aga_this_data->current_view != v) {
   1755 		vdata_t *vd = VDATA(v);
   1756 		monitor_t *monitor = aga_this_data->monitor;
   1757 		cop_t  *cp = aga_this_data->frames[F_STORE_LONG], *tmp;
   1758 		int     depth = v->bitmap->depth, i;
   1759 		int     hstart, hstop, vstart, vstop, j;
   1760 		int     x, y, w = v->display.width, h = v->display.height;
   1761 		u_short ddfstart, ddfwidth, con1;
   1762 
   1763 #ifdef DEBUG
   1764 		if (aga_enable & AGA_TRACE)
   1765 			printf("display_aga_view(%dx%dx%d) %x\n", w, h,
   1766 			    depth, v);
   1767 #endif
   1768 		/* round down to nearest even width */
   1769 		/* w &= 0xfffe; */
   1770 		/* calculate datafetch width. */
   1771 
   1772 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 4) << 1;
   1773 
   1774 		/* this will center the any overscanned display */
   1775 		/* and allow user to modify. */
   1776 		x = v->display.x + aga_this_data->std_start_x - ((w - 640) >> 3);
   1777 		y = v->display.y + aga_this_data->std_start_y - ((h - 400) >> 1);
   1778 
   1779 		if (y & 1)
   1780 			y--;
   1781 
   1782 		if (!(x & 1))
   1783 			x--;
   1784 
   1785 		hstart = x;
   1786 		hstop = x + (w >> 2);
   1787 		vstart = y;
   1788 		vstop = y + (h >> 0);
   1789 		ddfstart = (hstart >> 1) - 8;
   1790 
   1791 #ifdef DEBUG
   1792 		if (aga_enable & AGA_TRACE2) {
   1793 			printf ("  ddfwidth %04x x %04x y %04x", ddfwidth,
   1794 			    x, y);
   1795 			printf (" hstart %04x hstop %04x vstart %04x vstop %04x ddfstart %04x\n",
   1796 			    hstart, hstop, vstart, vstop, ddfstart);
   1797 		}
   1798 #endif
   1799 		/* check for hardware limits, AGA may allow more..? */
   1800 		/* anyone got a 4000 I can borrow :^) -ch */
   1801 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
   1802 			int     d = 0;
   1803 
   1804 			/* XXX anyone know the equality properties of
   1805 			 * intermixed logial AND's */
   1806 			/* XXX and arithmetic operators? */
   1807 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
   1808 				d++;
   1809 			}
   1810 
   1811 			ddfstart -= d;
   1812 			hstart -= d << 1;
   1813 			hstop -= d << 1;
   1814 		}
   1815 		/* correct the datafetch to proper limits. */
   1816 		/* delay the actual display of the data until we need it. */
   1817 		ddfstart &= 0xfffc;
   1818 #ifdef DEBUG
   1819 		if (aga_enable & AGA_TRACE2) {
   1820 			printf ("  ddfwidth %04x x %04x y %04x", ddfwidth,
   1821 			    x, y);
   1822 			printf (" hstart %04x hstop %04x vstart %04x vstop %04x ddfstart %04x\n",
   1823 			    hstart, hstop, vstart, vstop, ddfstart);
   1824 		}
   1825 #endif
   1826 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
   1827 
   1828 		if (aga_this_data->current_view) {
   1829 			VDATA(aga_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
   1830 			/* displayed. */
   1831 		}
   1832 		aga_this_data->current_view = v;
   1833 
   1834 		cp = aga_this_data->frames[F_STORE_LONG];
   1835 		tmp = cp;
   1836 		for (i = 0; i < 8; ++i) {
   1837 			if (tmp == NULL)
   1838 				break;
   1839 			tmp = find_copper_inst(tmp + 1, CI_MOVE(R_BPLCON3));
   1840 			if (tmp == NULL)
   1841 				break;
   1842 			tmp->cp.inst.operand = 0x0ca1 | (i << 13);
   1843 			tmp = find_copper_inst(tmp + 1, CI_MOVE(R_BPLCON3));
   1844 			if (tmp == NULL)
   1845 				break;
   1846 			tmp->cp.inst.operand = 0x0ea1 | (i << 13);
   1847 		}
   1848 		if (tmp)
   1849 			tmp = find_copper_inst(tmp + 1, CI_MOVE(R_BPLCON3));
   1850 		if (tmp)
   1851 			tmp->cp.inst.operand = 0x0ca1;
   1852 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
   1853 		tmp->cp.inst.operand = 0x8003;
   1854 		tmp = find_copper_inst(cp, CI_MOVE(R_HTOTAL));
   1855 		tmp->cp.inst.operand = AGA_htotal; /* 81/71/73/79? */
   1856 		tmp = find_copper_inst(cp, CI_MOVE(R_HBSTRT));
   1857 		tmp->cp.inst.operand = AGA_hbstrt; /* 0x0008 */
   1858 		tmp = find_copper_inst(cp, CI_MOVE(R_HSSTRT));
   1859 		tmp->cp.inst.operand = AGA_hsstrt; /* 0x000e */
   1860 		tmp = find_copper_inst(cp, CI_MOVE(R_HSSTOP));
   1861 		tmp->cp.inst.operand = AGA_hsstop; /* 0x001c */
   1862 		tmp = find_copper_inst(cp, CI_MOVE(R_HBSTOP));
   1863 		tmp->cp.inst.operand = AGA_hsstop; /* 0x001e */
   1864 		tmp = find_copper_inst(cp, CI_MOVE(R_HCENTER));
   1865 		tmp->cp.inst.operand = AGA_hcenter; /*AGA_htotal / 2 + AGA_hsstrt */
   1866 		tmp = find_copper_inst(cp, CI_MOVE(R_VBSTRT));
   1867 		tmp->cp.inst.operand = AGA_vbstrt; /* 0x0000 */
   1868 		tmp = find_copper_inst(cp, CI_MOVE(R_VSSTRT));
   1869 		tmp->cp.inst.operand = AGA_vsstrt; /* 0x016b / AGA_htotal */
   1870 		tmp = find_copper_inst(cp, CI_MOVE(R_VSSTOP));
   1871 		tmp->cp.inst.operand = AGA_vsstop; /* 0x02d6 / AGA_htotal */
   1872 		tmp = find_copper_inst(cp, CI_MOVE(R_VBSTOP));
   1873 		tmp->cp.inst.operand = AGA_vbstop; /* 0x0bd1 / AGA_htotal */
   1874 		tmp = find_copper_inst(cp, CI_MOVE(R_VTOTAL));
   1875 		tmp->cp.inst.operand = AGA_vtotal;
   1876 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
   1877 		tmp->cp.inst.operand = aga_this_data->beamcon0;
   1878 #ifdef DEBUG
   1879 		if (aga_enable & AGA_TRACE2)
   1880 			printf("  beamcon0 %04x", tmp->cp.inst.operand);
   1881 #endif
   1882 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
   1883 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
   1884 #ifdef DEBUG
   1885 		if (aga_enable & AGA_TRACE2)
   1886 			printf(" diwhigh %04x>", tmp->cp.inst.operand);
   1887 #endif
   1888 #if 0
   1889 		tmp->cp.inst.operand = (vstop & 0x0700) | ((hstop & 0x0100) << 5);
   1890 #endif
   1891 #ifdef DEBUG
   1892 		if (aga_enable & AGA_TRACE2)
   1893 			printf("%04x", tmp->cp.inst.operand);
   1894 #endif
   1895 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
   1896 		tmp->cp.inst.operand = aga_this_data->bplcon0 |
   1897 		    ((depth & 0x7) << 12) | ((depth & 0x8) << 1);
   1898 #ifdef DEBUG
   1899 		if (aga_enable & AGA_TRACE2)
   1900 			printf(" bplcon0 %04x", tmp->cp.inst.operand);
   1901 #endif
   1902 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
   1903 		tmp->cp.inst.operand = con1;
   1904 #ifdef DEBUG
   1905 		if (aga_enable & AGA_TRACE2)
   1906 			printf(" bplcon1 %04x>0000\n", con1);
   1907 #endif
   1908 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
   1909 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
   1910 #ifdef DEBUG
   1911 		if (aga_enable & AGA_TRACE2)
   1912 			printf("  diwstart %04x", tmp->cp.inst.operand);
   1913 #endif
   1914 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
   1915 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
   1916 #ifdef DEBUG
   1917 		if (aga_enable & AGA_TRACE2)
   1918 			printf(" diwstop %04x", tmp->cp.inst.operand);
   1919 #endif
   1920 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
   1921 		tmp->cp.inst.operand = ddfstart;
   1922 #ifdef DEBUG
   1923 		if (aga_enable & AGA_TRACE2)
   1924 			printf(" ddfstart %04x", tmp->cp.inst.operand);
   1925 #endif
   1926 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
   1927 		tmp->cp.inst.operand = ddfstart + ddfwidth;
   1928 #ifdef DEBUG
   1929 		if (aga_enable & AGA_TRACE2)
   1930 			printf(" ddfstop %04x", tmp->cp.inst.operand);
   1931 #endif
   1932 
   1933 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   1934 		for (i = 0, j = 0; i < depth; j += 2, i++) {
   1935 			/* update the plane pointers */
   1936 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   1937 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   1938 #ifdef DEBUG
   1939 		if (aga_enable & AGA_TRACE2)
   1940 			printf (" bpl%dpth %08x", i, v->bitmap->plane[i]);
   1941 #endif
   1942 		}
   1943 
   1944 		/* set mods correctly. */
   1945 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
   1946 		tmp[0].cp.inst.operand = v->bitmap->row_mod;
   1947 		tmp[1].cp.inst.operand = v->bitmap->row_mod;
   1948 #ifdef DEBUG
   1949 		if (aga_enable & AGA_TRACE2)
   1950 			printf(" bplxmod %04x\n", v->bitmap->row_mod);
   1951 #endif
   1952 
   1953 		/* set next pointers correctly */
   1954 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   1955 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(aga_this_data->frames[F_STORE_LONG]));
   1956 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(aga_this_data->frames[F_STORE_LONG]));
   1957 
   1958 		cp = aga_this_data->frames[F_LONG];
   1959 		aga_this_data->frames[F_LONG] = aga_this_data->frames[F_STORE_LONG];
   1960 		aga_this_data->frames[F_STORE_LONG] = cp;
   1961 
   1962 		vd->flags |= VF_DISPLAY;
   1963 
   1964 		cc_use_aga_colormap(v, vd->colormap);
   1965 	}
   1966 	cc_load_mode(aga_this);
   1967 #ifdef DEBUG
   1968 	if (aga_enable & AGA_TRACE)
   1969 		aga_enable |= AGA_TRACE2;	/* XXXX */
   1970 #endif
   1971 }
   1972 
   1973 #endif /* GRF_AGA */
   1974 #endif /* GRF_NTSC */
   1975 
   1976 /*
   1977  * PAL modes.
   1978  */
   1979 
   1980 #if defined (GRF_PAL)
   1981 
   1982 dmode_t *
   1983 cc_init_pal_hires()
   1984 {
   1985 	/* this function should only be called once. */
   1986 	if (!ph_this) {
   1987 		u_short len = std_copper_list_len;
   1988 		cop_t  *cp;
   1989 
   1990 		ph_this = &pal_hires_mode;
   1991 		ph_this_data = &pal_hires_mode_data;
   1992 		bzero(ph_this, sizeof(dmode_t));
   1993 		bzero(ph_this_data, sizeof(dmdata_t));
   1994 
   1995 		ph_this->name = "pal: hires";
   1996 		ph_this->nominal_size.width = 640;
   1997 		ph_this->nominal_size.height = 256;
   1998 		ph_this_data->max_size.width = 724;
   1999 		ph_this_data->max_size.height = 289;
   2000 		ph_this_data->min_size.width = 320;
   2001 		ph_this_data->min_size.height = 244;
   2002 		ph_this_data->min_depth = 1;
   2003 		ph_this_data->max_depth = 4;
   2004 		ph_this->data = ph_this_data;
   2005 
   2006 		ph_this->get_monitor = cc_get_monitor;
   2007 		ph_this->alloc_view = cc_alloc_view;
   2008 		ph_this->get_current_view = cc_get_current_view;
   2009 
   2010 		ph_this_data->use_colormap = cc_use_colormap;
   2011 		ph_this_data->get_colormap = cc_get_colormap;
   2012 		ph_this_data->alloc_colormap = cc_alloc_colormap;
   2013 		ph_this_data->display_view = display_pal_hires_view;
   2014 		ph_this_data->monitor = cc_monitor;
   2015 
   2016 		ph_this_data->frames = pal_hires_frames;
   2017 		ph_this_data->frames[F_LONG] = alloc_chipmem(std_copper_list_size * F_TOTAL);
   2018 		if (!ph_this_data->frames[F_LONG]) {
   2019 			panic("couldn't get chipmem for copper list");
   2020 		}
   2021 		ph_this_data->frames[F_STORE_LONG] = &ph_this_data->frames[F_LONG][len];
   2022 
   2023 		bcopy(std_copper_list, ph_this_data->frames[F_STORE_LONG], std_copper_list_size);
   2024 		bcopy(std_copper_list, ph_this_data->frames[F_LONG], std_copper_list_size);
   2025 
   2026 		ph_this_data->bplcon0 = 0x8200 | USE_CON3;	/* pal_hires, color
   2027 								 * composite enable,
   2028 								 * lace. */
   2029 		ph_this_data->std_start_x = STANDARD_VIEW_X;
   2030 		ph_this_data->std_start_y = STANDARD_VIEW_Y;
   2031 		ph_this_data->vbl_handler = (vbl_handler_func *) cc_mode_vbl_handler;
   2032 #if defined (GRF_ECS)
   2033 		ph_this_data->beamcon0 = STANDARD_PAL_BEAMCON;
   2034 #endif
   2035 
   2036 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, ph_this, link);
   2037 	}
   2038 	return (ph_this);
   2039 }
   2040 
   2041 void
   2042 display_pal_hires_view(v)
   2043 	view_t *v;
   2044 {
   2045 	if (ph_this_data->current_view != v) {
   2046 		vdata_t *vd = VDATA(v);
   2047 		monitor_t *monitor = ph_this_data->monitor;
   2048 		cop_t  *cp = ph_this_data->frames[F_STORE_LONG], *tmp;
   2049 		int     depth = v->bitmap->depth, i;
   2050 		int     hstart, hstop, vstart, vstop, j;
   2051 		int     x, y, w = v->display.width, h = v->display.height;
   2052 		u_short ddfstart, ddfwidth, con1;
   2053 
   2054 		/* round down to nearest even width */
   2055 		/* w &= 0xfffe; */
   2056 
   2057 		/* calculate datafetch width. */
   2058 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 2) << 2;
   2059 
   2060 		/* This will center the any overscanned display */
   2061 		/* and allow user to modify. */
   2062 		x = v->display.x + ph_this_data->std_start_x - ((w - 640) >> 2);
   2063 		y = v->display.y + ph_this_data->std_start_y - ((h - 256) >> 1);
   2064 
   2065 		if (y & 1)
   2066 			y--;
   2067 
   2068 		if (!(x & 1))
   2069 			x--;
   2070 
   2071 		hstart = x;
   2072 		hstop = x + (w >> 1);
   2073 		vstart = y;
   2074 		vstop = y + h;
   2075 		ddfstart = (hstart - 9) >> 1;
   2076 		/* check for hardware limits, AGA may allow more..? */
   2077 		/* anyone got a 4000 I can borrow :^) -ch */
   2078 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
   2079 			int     d = 0;
   2080 
   2081 			/* XXX anyone know the equality properties of
   2082 			 * intermixed logial AND's */
   2083 			/* XXX and arithmetic operators? */
   2084 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
   2085 				d++;
   2086 			}
   2087 
   2088 			ddfstart -= d;
   2089 			hstart -= d << 1;
   2090 			hstop -= d << 1;
   2091 		}
   2092 		/* correct the datafetch to proper limits. */
   2093 		/* delay the actual display of the data until we need it. */
   2094 		ddfstart &= 0xfffc;
   2095 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
   2096 
   2097 		if (ph_this_data->current_view) {
   2098 			VDATA(ph_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
   2099 			/* displayed. */
   2100 		}
   2101 		ph_this_data->current_view = v;
   2102 
   2103 		cp = ph_this_data->frames[F_STORE_LONG];
   2104 #if defined GRF_ECS
   2105 #if defined GRF_AGA
   2106 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
   2107 		tmp->cp.inst.operand = 0;
   2108 #endif
   2109 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
   2110 		tmp->cp.inst.operand = ph_this_data->beamcon0;
   2111 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
   2112 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
   2113 #endif /* ECS */
   2114 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
   2115 		tmp->cp.inst.operand = ph_this_data->bplcon0 | ((depth & 0x7) << 12);
   2116 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
   2117 		tmp->cp.inst.operand = con1;
   2118 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
   2119 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
   2120 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
   2121 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
   2122 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
   2123 		tmp->cp.inst.operand = ddfstart;
   2124 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
   2125 		tmp->cp.inst.operand = ddfstart + ddfwidth;
   2126 
   2127 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   2128 		for (i = 0, j = 0; i < depth; j += 2, i++) {
   2129 			/* update the plane pointers */
   2130 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   2131 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   2132 		}
   2133 
   2134 		/* set mods correctly. */
   2135 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
   2136 		tmp[0].cp.inst.operand = v->bitmap->row_mod;
   2137 		tmp[1].cp.inst.operand = v->bitmap->row_mod;
   2138 
   2139 		/* set next pointers correctly */
   2140 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   2141 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(ph_this_data->frames[F_STORE_LONG]));
   2142 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(ph_this_data->frames[F_STORE_LONG]));
   2143 
   2144 		cp = ph_this_data->frames[F_LONG];
   2145 		ph_this_data->frames[F_LONG] = ph_this_data->frames[F_STORE_LONG];
   2146 		ph_this_data->frames[F_STORE_LONG] = cp;
   2147 
   2148 		vd->flags |= VF_DISPLAY;
   2149 		cc_use_colormap(v, vd->colormap);
   2150 	}
   2151 	cc_load_mode(ph_this);
   2152 }
   2153 
   2154 dmode_t *
   2155 cc_init_pal_hires_lace()
   2156 {
   2157 	/* this function should only be called once. */
   2158 	if (!phl_this) {
   2159 		u_short len = std_copper_list_len;
   2160 		cop_t  *cp;
   2161 
   2162 		phl_this = &pal_hires_lace_mode;
   2163 		phl_this_data = &pal_hires_lace_mode_data;
   2164 		bzero(phl_this, sizeof(dmode_t));
   2165 		bzero(phl_this_data, sizeof(dmdata_t));
   2166 
   2167 		phl_this->name = "pal: hires interlace";
   2168 		phl_this->nominal_size.width = 640;
   2169 		phl_this->nominal_size.height = 512;
   2170 		phl_this_data->max_size.width = 724;
   2171 		phl_this_data->max_size.height = 578;
   2172 		phl_this_data->min_size.width = 320;
   2173 		phl_this_data->min_size.height = 484;
   2174 		phl_this_data->min_depth = 1;
   2175 		phl_this_data->max_depth = 4;
   2176 		phl_this->data = phl_this_data;
   2177 
   2178 		phl_this->get_monitor = cc_get_monitor;
   2179 		phl_this->alloc_view = cc_alloc_view;
   2180 		phl_this->get_current_view = cc_get_current_view;
   2181 
   2182 		phl_this_data->use_colormap = cc_use_colormap;
   2183 		phl_this_data->get_colormap = cc_get_colormap;
   2184 		phl_this_data->alloc_colormap = cc_alloc_colormap;
   2185 		phl_this_data->display_view = display_pal_hires_lace_view;
   2186 		phl_this_data->monitor = cc_monitor;
   2187 
   2188 		phl_this_data->flags |= DMF_INTERLACE;
   2189 
   2190 		phl_this_data->frames = pal_hires_lace_frames;
   2191 		phl_this_data->frames[F_LACE_LONG] = alloc_chipmem(std_copper_list_size * F_LACE_TOTAL);
   2192 		if (!phl_this_data->frames[F_LACE_LONG]) {
   2193 			panic("couldn't get chipmem for copper list");
   2194 		}
   2195 		phl_this_data->frames[F_LACE_SHORT] = &phl_this_data->frames[F_LACE_LONG][len];
   2196 		phl_this_data->frames[F_LACE_STORE_LONG] = &phl_this_data->frames[F_LACE_SHORT][len];
   2197 		phl_this_data->frames[F_LACE_STORE_SHORT] = &phl_this_data->frames[F_LACE_STORE_LONG][len];
   2198 
   2199 		bcopy(std_copper_list, phl_this_data->frames[F_LACE_STORE_LONG], std_copper_list_size);
   2200 		bcopy(std_copper_list, phl_this_data->frames[F_LACE_STORE_SHORT], std_copper_list_size);
   2201 		bcopy(std_copper_list, phl_this_data->frames[F_LACE_LONG], std_copper_list_size);
   2202 		bcopy(std_copper_list, phl_this_data->frames[F_LACE_SHORT], std_copper_list_size);
   2203 
   2204 		phl_this_data->bplcon0 = 0x8204 | USE_CON3;	/* hires, color
   2205 								 * composite enable,
   2206 								 * lace. */
   2207 		phl_this_data->std_start_x = STANDARD_VIEW_X;
   2208 		phl_this_data->std_start_y = STANDARD_VIEW_Y;
   2209 		phl_this_data->vbl_handler = (vbl_handler_func *) cc_lace_mode_vbl_handler;
   2210 #if defined (GRF_ECS)
   2211 		phl_this_data->beamcon0 = STANDARD_PAL_BEAMCON;
   2212 #endif
   2213 
   2214 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, phl_this, link);
   2215 	}
   2216 	return (phl_this);
   2217 }
   2218 
   2219 void
   2220 display_pal_hires_lace_view(v)
   2221 	view_t *v;
   2222 {
   2223 	if (phl_this_data->current_view != v) {
   2224 		vdata_t *vd = VDATA(v);
   2225 		monitor_t *monitor = phl_this_data->monitor;
   2226 		cop_t  *cp = phl_this_data->frames[F_LACE_STORE_LONG], *tmp;
   2227 		int     depth = v->bitmap->depth, i;
   2228 		int     hstart, hstop, vstart, vstop, j;
   2229 		int     x, y, w = v->display.width, h = v->display.height;
   2230 		u_short ddfstart, ddfwidth, con1;
   2231 
   2232 		/* round down to nearest even width */
   2233 		/* w &= 0xfffe; */
   2234 
   2235 		/* calculate datafetch width. */
   2236 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 2) << 2;
   2237 
   2238 		/* This will center the any overscanned display */
   2239 		/* and allow user to modify. */
   2240 		x = v->display.x + phl_this_data->std_start_x - ((w - 640) >> 2);
   2241 		y = v->display.y + phl_this_data->std_start_y - ((h - 512) >> 2);
   2242 
   2243 		if (y & 1)
   2244 			y--;
   2245 
   2246 		if (!(x & 1))
   2247 			x--;
   2248 
   2249 		hstart = x;
   2250 		hstop = x + (w >> 1);
   2251 		vstart = y;
   2252 		vstop = y + (h >> 1);
   2253 		ddfstart = (hstart - 9) >> 1;
   2254 
   2255 		/* check for hardware limits, AGA may allow more..? */
   2256 		/* anyone got a 4000 I can borrow :^) -ch */
   2257 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
   2258 			int     d = 0;
   2259 
   2260 			/* XXX anyone know the equality properties of
   2261 			 * intermixed logial AND's */
   2262 			/* XXX and arithmetic operators? */
   2263 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
   2264 				d++;
   2265 			}
   2266 
   2267 			ddfstart -= d;
   2268 			hstart -= d << 1;
   2269 			hstop -= d << 1;
   2270 		}
   2271 		/* correct the datafetch to proper limits. */
   2272 		/* delay the actual display of the data until we need it. */
   2273 		ddfstart &= 0xfffc;
   2274 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
   2275 
   2276 		if (phl_this_data->current_view) {
   2277 			VDATA(phl_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
   2278 			/* displayed. */
   2279 		}
   2280 		phl_this_data->current_view = v;
   2281 
   2282 		cp = phl_this_data->frames[F_LACE_STORE_LONG];
   2283 #if defined GRF_ECS
   2284 #if defined GRF_AGA
   2285 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
   2286 		tmp->cp.inst.operand = 0;
   2287 #endif
   2288 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
   2289 		tmp->cp.inst.operand = phl_this_data->beamcon0;
   2290 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
   2291 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
   2292 #endif /* ECS */
   2293 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
   2294 		tmp->cp.inst.operand = phl_this_data->bplcon0 | ((depth & 0x7) << 12);
   2295 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
   2296 		tmp->cp.inst.operand = con1;
   2297 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
   2298 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
   2299 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
   2300 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
   2301 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
   2302 		tmp->cp.inst.operand = ddfstart;
   2303 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
   2304 		tmp->cp.inst.operand = ddfstart + ddfwidth;
   2305 
   2306 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   2307 		for (i = 0, j = 0; i < depth; j += 2, i++) {
   2308 			/* update the plane pointers */
   2309 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   2310 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   2311 		}
   2312 
   2313 		/* set mods correctly. */
   2314 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
   2315 		tmp[0].cp.inst.operand = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   2316 		tmp[1].cp.inst.operand = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   2317 
   2318 		/* set next pointers correctly */
   2319 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   2320 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(phl_this_data->frames[F_LACE_STORE_SHORT]));
   2321 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(phl_this_data->frames[F_LACE_STORE_SHORT]));
   2322 
   2323 
   2324 		bcopy(phl_this_data->frames[F_LACE_STORE_LONG], phl_this_data->frames[F_LACE_STORE_SHORT], std_copper_list_size);
   2325 
   2326 		/* these are the only ones that are different from long frame. */
   2327 		cp = phl_this_data->frames[F_LACE_STORE_SHORT];
   2328 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   2329 		for (i = 0, j = 0; i < depth; j += 2, i++) {
   2330 			u_short mod = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   2331 			/* update plane pointers. high and low. */
   2332 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[i][mod]));
   2333 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[i][mod]));
   2334 		}
   2335 
   2336 		/* set next pointers correctly */
   2337 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   2338 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(phl_this_data->frames[F_LACE_STORE_LONG]));
   2339 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(phl_this_data->frames[F_LACE_STORE_LONG]));
   2340 
   2341 
   2342 		cp = phl_this_data->frames[F_LACE_LONG];
   2343 		phl_this_data->frames[F_LACE_LONG] = phl_this_data->frames[F_LACE_STORE_LONG];
   2344 		phl_this_data->frames[F_LACE_STORE_LONG] = cp;
   2345 
   2346 		cp = phl_this_data->frames[F_LACE_SHORT];
   2347 		phl_this_data->frames[F_LACE_SHORT] = phl_this_data->frames[F_LACE_STORE_SHORT];
   2348 		phl_this_data->frames[F_LACE_STORE_SHORT] = cp;
   2349 
   2350 		vd->flags |= VF_DISPLAY;
   2351 		cc_use_colormap(v, vd->colormap);
   2352 	}
   2353 	cc_load_mode(phl_this);
   2354 }
   2355 #if defined (GRF_A2024)
   2356 
   2357 dmode_t *
   2358 cc_init_pal_hires_dlace()
   2359 {
   2360 	/* this function should only be called once. */
   2361 	if (!phdl_this) {
   2362 		u_short len = std_dlace_copper_list_len;
   2363 		cop_t  *cp;
   2364 
   2365 		phdl_this = &pal_hires_dlace_mode;
   2366 		phdl_this_data = &pal_hires_dlace_mode_data;
   2367 		bzero(phdl_this, sizeof(dmode_t));
   2368 		bzero(phdl_this_data, sizeof(dmdata_t));
   2369 
   2370 		phdl_this->name = "pal: hires double interlace";
   2371 		phdl_this->nominal_size.width = 640;
   2372 		phdl_this->nominal_size.height = 1024;
   2373 		phdl_this_data->max_size.width = 724;
   2374 		phdl_this_data->max_size.height = 1024;
   2375 		phdl_this_data->min_size.width = 320;
   2376 		phdl_this_data->min_size.height = 512;
   2377 		phdl_this_data->min_depth = 1;
   2378 		phdl_this_data->max_depth = 2;
   2379 		phdl_this->data = phdl_this_data;
   2380 
   2381 		phdl_this->get_monitor = cc_get_monitor;
   2382 		phdl_this->alloc_view = cc_alloc_view;
   2383 		phdl_this->get_current_view = cc_get_current_view;
   2384 
   2385 		phdl_this_data->use_colormap = cc_a2024_use_colormap;
   2386 		phdl_this_data->get_colormap = cc_a2024_get_colormap;
   2387 		phdl_this_data->alloc_colormap = cc_a2024_alloc_colormap;
   2388 		phdl_this_data->display_view = display_pal_hires_dlace_view;
   2389 		phdl_this_data->monitor = cc_monitor;
   2390 
   2391 		phdl_this_data->flags |= DMF_INTERLACE;
   2392 
   2393 		phdl_this_data->frames = pal_hires_dlace_frames;
   2394 		phdl_this_data->frames[F_LACE_LONG] = alloc_chipmem(std_dlace_copper_list_size * F_LACE_TOTAL);
   2395 		if (!phdl_this_data->frames[F_LACE_LONG]) {
   2396 			panic("couldn't get chipmem for copper list");
   2397 		}
   2398 		phdl_this_data->frames[F_LACE_SHORT] = &phdl_this_data->frames[F_LACE_LONG][len];
   2399 		phdl_this_data->frames[F_LACE_STORE_LONG] = &phdl_this_data->frames[F_LACE_SHORT][len];
   2400 		phdl_this_data->frames[F_LACE_STORE_SHORT] = &phdl_this_data->frames[F_LACE_STORE_LONG][len];
   2401 
   2402 		bcopy(std_dlace_copper_list, phdl_this_data->frames[F_LACE_STORE_LONG], std_dlace_copper_list_size);
   2403 		bcopy(std_dlace_copper_list, phdl_this_data->frames[F_LACE_STORE_SHORT], std_dlace_copper_list_size);
   2404 		bcopy(std_dlace_copper_list, phdl_this_data->frames[F_LACE_LONG], std_dlace_copper_list_size);
   2405 		bcopy(std_dlace_copper_list, phdl_this_data->frames[F_LACE_SHORT], std_dlace_copper_list_size);
   2406 
   2407 		phdl_this_data->bplcon0 = 0x8204 | USE_CON3;	/* hires, color
   2408 								 * composite enable,
   2409 								 * dlace. */
   2410 		phdl_this_data->std_start_x = STANDARD_VIEW_X;
   2411 		phdl_this_data->std_start_y = STANDARD_VIEW_Y;
   2412 		phdl_this_data->vbl_handler = (vbl_handler_func *) cc_lace_mode_vbl_handler;
   2413 #if defined (GRF_ECS)
   2414 		phdl_this_data->beamcon0 = STANDARD_PAL_BEAMCON;
   2415 #endif
   2416 
   2417 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, phdl_this, link);
   2418 	}
   2419 	return (phdl_this);
   2420 }
   2421 
   2422 void
   2423 display_pal_hires_dlace_view(v)
   2424 	view_t *v;
   2425 {
   2426 	if (phdl_this_data->current_view != v) {
   2427 		vdata_t *vd = VDATA(v);
   2428 		monitor_t *monitor = phdl_this_data->monitor;
   2429 		cop_t  *cp = phdl_this_data->frames[F_LACE_STORE_LONG], *tmp;
   2430 		int     depth = v->bitmap->depth, i;
   2431 		int     hstart, hstop, vstart, vstop, j;
   2432 		int     x, y, w = v->display.width, h = v->display.height;
   2433 		u_short ddfstart, ddfwidth, con1;
   2434 		u_short mod1l, mod2l;
   2435 
   2436 		/* round down to nearest even width */
   2437 		/* w &= 0xfffe; */
   2438 
   2439 		/* calculate datafetch width. */
   2440 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 2) << 2;
   2441 
   2442 		/* This will center the any overscanned display */
   2443 		/* and allow user to modify. */
   2444 		x = v->display.x + phdl_this_data->std_start_x - ((w - 640) >> 2);
   2445 		y = v->display.y + phdl_this_data->std_start_y - ((h - 1024) >> 3);
   2446 
   2447 		if (y & 1)
   2448 			y--;
   2449 
   2450 		if (!(x & 1))
   2451 			x--;
   2452 
   2453 		hstart = x;
   2454 		hstop = x + (w >> 1);
   2455 		vstart = y;
   2456 		vstop = y + (h >> 2);
   2457 		ddfstart = (hstart - 9) >> 1;
   2458 
   2459 		/* check for hardware limits, AGA may allow more..? */
   2460 		/* anyone got a 4000 I can borrow :^) -ch */
   2461 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
   2462 			int     d = 0;
   2463 
   2464 			/* XXX anyone know the equality properties of
   2465 			 * intermixed logial AND's */
   2466 			/* XXX and arithmetic operators? */
   2467 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
   2468 				d++;
   2469 			}
   2470 
   2471 			ddfstart -= d;
   2472 			hstart -= d << 1;
   2473 			hstop -= d << 1;
   2474 		}
   2475 		/* correct the datafetch to proper limits. */
   2476 		/* delay the actual display of the data until we need it. */
   2477 		ddfstart &= 0xfffc;
   2478 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
   2479 
   2480 		if (phdl_this_data->current_view) {
   2481 			VDATA(phdl_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
   2482 			/* displayed. */
   2483 		}
   2484 		phdl_this_data->current_view = v;
   2485 
   2486 		cp = phdl_this_data->frames[F_LACE_STORE_LONG];
   2487 #if defined GRF_ECS
   2488 #if defined GRF_AGA
   2489 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
   2490 		tmp->cp.inst.operand = 0;
   2491 #endif
   2492 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
   2493 		tmp->cp.inst.operand = phdl_this_data->beamcon0;
   2494 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
   2495 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
   2496 #endif /* ECS */
   2497 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
   2498 		tmp->cp.inst.operand = phdl_this_data->bplcon0 | ((depth & 0x7) << 13);	/* times two. */
   2499 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
   2500 		tmp->cp.inst.operand = con1;
   2501 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
   2502 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
   2503 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
   2504 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
   2505 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
   2506 		tmp->cp.inst.operand = ddfstart;
   2507 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
   2508 		tmp->cp.inst.operand = ddfstart + ddfwidth;
   2509 
   2510 		mod1l = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   2511 		mod2l = mod1l << 1;
   2512 
   2513 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   2514 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][0]));	/* update plane
   2515 											 * pointers. */
   2516 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][0]));	/* high and low. */
   2517 		tmp[2].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod1l]));	/* update plane
   2518 												 * pointers. */
   2519 		tmp[3].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod1l]));	/* high and low. */
   2520 		if (depth == 2) {
   2521 			tmp[4].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][0]));	/* update plane
   2522 												 * pointers. */
   2523 			tmp[5].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][0]));	/* high and low. */
   2524 			tmp[6].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod1l]));	/* update plane
   2525 													 * pointers. */
   2526 			tmp[7].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod1l]));	/* high and low. */
   2527 		}
   2528 		/* set mods correctly. */
   2529 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
   2530 		tmp[0].cp.inst.operand = mod2l + mod1l;
   2531 		tmp[1].cp.inst.operand = mod2l + mod1l;
   2532 
   2533 		/* set next pointers correctly */
   2534 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   2535 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(phdl_this_data->frames[F_LACE_STORE_SHORT]));
   2536 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(phdl_this_data->frames[F_LACE_STORE_SHORT]));
   2537 
   2538 		bcopy(phdl_this_data->frames[F_LACE_STORE_LONG], phdl_this_data->frames[F_LACE_STORE_SHORT], std_dlace_copper_list_size);
   2539 
   2540 		/* these are the only ones that are different from long frame. */
   2541 		cp = phdl_this_data->frames[F_LACE_STORE_SHORT];
   2542 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   2543 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l]));	/* update plane
   2544 												 * pointers. */
   2545 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l]));	/* high and low. */
   2546 		tmp[2].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l + mod1l]));	/* update plane
   2547 													 * pointers. */
   2548 		tmp[3].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[0][mod2l + mod1l]));	/* high and low. */
   2549 		if (depth == 2) {
   2550 			tmp[4].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l]));	/* update plane
   2551 													 * pointers. */
   2552 			tmp[5].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l]));	/* high and low. */
   2553 			tmp[6].cp.inst.operand = HIADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l + mod1l]));	/* update plane
   2554 														 * pointers. */
   2555 			tmp[7].cp.inst.operand = LOADDR(PREP_DMA_MEM(&v->bitmap->plane[1][mod2l + mod1l]));	/* high and low. */
   2556 		}
   2557 		/* set next pointers correctly */
   2558 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   2559 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(phdl_this_data->frames[F_LACE_STORE_LONG]));
   2560 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(phdl_this_data->frames[F_LACE_STORE_LONG]));
   2561 
   2562 		cp = phdl_this_data->frames[F_LACE_LONG];
   2563 		phdl_this_data->frames[F_LACE_LONG] = phdl_this_data->frames[F_LACE_STORE_LONG];
   2564 		phdl_this_data->frames[F_LACE_STORE_LONG] = cp;
   2565 
   2566 		cp = phdl_this_data->frames[F_LACE_SHORT];
   2567 		phdl_this_data->frames[F_LACE_SHORT] = phdl_this_data->frames[F_LACE_STORE_SHORT];
   2568 		phdl_this_data->frames[F_LACE_STORE_SHORT] = cp;
   2569 
   2570 		vd->flags |= VF_DISPLAY;
   2571 
   2572 		cc_a2024_use_colormap(v, vd->colormap);
   2573 	}
   2574 	cc_load_mode(phdl_this);
   2575 }
   2576 
   2577 dmode_t *
   2578 cc_init_pal_a2024()
   2579 {
   2580 	/* this function should only be called once. */
   2581 	if (!p24_this) {
   2582 		int     i;
   2583 		u_short len = std_pal_a2024_copper_list_len;
   2584 		cop_t  *cp;
   2585 
   2586 		p24_this = &pal_a2024_mode;
   2587 		p24_this_data = &pal_a2024_mode_data;
   2588 		bzero(p24_this, sizeof(dmode_t));
   2589 		bzero(p24_this_data, sizeof(dmdata_t));
   2590 
   2591 		p24_this->name = "pal: A2024 15khz";
   2592 		p24_this->nominal_size.width = 1024;
   2593 		p24_this->nominal_size.height = 1024;
   2594 		p24_this_data->max_size.width = 1024;
   2595 		p24_this_data->max_size.height = 1024;
   2596 		p24_this_data->min_size.width = 1024;
   2597 		p24_this_data->min_size.height = 1024;
   2598 		p24_this_data->min_depth = 1;
   2599 		p24_this_data->max_depth = 2;
   2600 		p24_this->data = p24_this_data;
   2601 
   2602 		p24_this->get_monitor = cc_get_monitor;
   2603 		p24_this->alloc_view = cc_alloc_view;
   2604 		p24_this->get_current_view = cc_get_current_view;
   2605 
   2606 		p24_this_data->use_colormap = cc_a2024_use_colormap;
   2607 		p24_this_data->get_colormap = cc_a2024_get_colormap;
   2608 		p24_this_data->display_view = display_pal_a2024_view;
   2609 		p24_this_data->alloc_colormap = cc_a2024_alloc_colormap;
   2610 		p24_this_data->monitor = cc_monitor;
   2611 
   2612 		p24_this_data->flags |= DMF_HEDLEY_EXP;
   2613 
   2614 		p24_this_data->frames = pal_a2024_frames;
   2615 		p24_this_data->frames[F_QD_QUAD0] = alloc_chipmem(std_pal_a2024_copper_list_size * F_QD_TOTAL);
   2616 		if (!p24_this_data->frames[F_QD_QUAD0]) {
   2617 			panic("couldn't get chipmem for copper list");
   2618 		}
   2619 		/* setup the hedley init bitplane. */
   2620 		hedley_init = alloc_chipmem(128);
   2621 		if (!hedley_init) {
   2622 			panic("couldn't get chipmem for hedley init bitplane");
   2623 		}
   2624 		for (i = 1; i < 128; i++)
   2625 			hedley_init[i] = 0xff;
   2626 		hedley_init[0] = 0x03;
   2627 
   2628 		/* copy image of standard copper list. */
   2629 		bcopy(std_pal_a2024_copper_list, p24_this_data->frames[0], std_pal_a2024_copper_list_size);
   2630 
   2631 		/* set the init plane pointer. */
   2632 		cp = find_copper_inst(p24_this_data->frames[F_QD_QUAD0], CI_MOVE(R_BPL0PTH));
   2633 		cp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(hedley_init));
   2634 		cp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(hedley_init));
   2635 
   2636 		for (i = 1; i < F_QD_TOTAL; i++) {
   2637 			p24_this_data->frames[i] = &p24_this_data->frames[i - 1][len];
   2638 			bcopy(p24_this_data->frames[0], p24_this_data->frames[i], std_pal_a2024_copper_list_size);
   2639 		}
   2640 
   2641 		p24_this_data->bplcon0 = 0x8200;	/* hires */
   2642 		p24_this_data->vbl_handler = (vbl_handler_func *) pal_a2024_mode_vbl_handler;
   2643 
   2644 
   2645 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes, p24_this, link);
   2646 	}
   2647 	return (p24_this);
   2648 }
   2649 
   2650 void
   2651 display_pal_a2024_view(v)
   2652 	view_t *v;
   2653 {
   2654 	if (p24_this_data->current_view != v) {
   2655 		vdata_t *vd = VDATA(v);
   2656 		monitor_t *monitor = p24_this_data->monitor;
   2657 		cop_t  *cp, *tmp;
   2658 		u_char *inst_plane[2];
   2659 		u_char **plane = inst_plane;
   2660 		u_long  full_line = v->bitmap->bytes_per_row + v->bitmap->row_mod;
   2661 		u_long  half_plane = full_line * v->bitmap->rows / 2;
   2662 
   2663 		int     line_mod = 0xbc;	/* standard 2024 15khz mod. */
   2664 		int     depth = v->bitmap->depth, i, j;
   2665 
   2666 		plane[0] = v->bitmap->plane[0];
   2667 		if (depth == 2) {
   2668 			plane[1] = v->bitmap->plane[1];
   2669 		}
   2670 		if (p24_this_data->current_view) {
   2671 			VDATA(p24_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer
   2672 											 * displayed. */
   2673 		}
   2674 		cp = p24_this_data->frames[F_QD_STORE_QUAD0];
   2675 		tmp = find_copper_inst(cp, CI_MOVE(R_COLOR1F));
   2676 		tmp = find_copper_inst(tmp, CI_MOVE(R_BPLCON0));	/* grab third one. */
   2677 		tmp->cp.inst.operand = p24_this_data->bplcon0 | ((depth & 0x7) << 13);	/* times 2 */
   2678 
   2679 		bcopy(p24_this_data->frames[F_QD_STORE_QUAD0], p24_this_data->frames[F_QD_STORE_QUAD1], std_pal_a2024_copper_list_size);
   2680 		bcopy(p24_this_data->frames[F_QD_STORE_QUAD0], p24_this_data->frames[F_QD_STORE_QUAD2], std_pal_a2024_copper_list_size);
   2681 		bcopy(p24_this_data->frames[F_QD_STORE_QUAD0], p24_this_data->frames[F_QD_STORE_QUAD3], std_pal_a2024_copper_list_size);
   2682 
   2683 		/*
   2684 		 * Mark Id's
   2685 		 */
   2686 		tmp = find_copper_inst(p24_this_data->frames[F_QD_STORE_QUAD1], CI_WAIT(126, 29));
   2687 		CBUMP(tmp);
   2688 		CMOVE(tmp, R_COLOR01, QUAD1_ID);
   2689 		tmp = find_copper_inst(p24_this_data->frames[F_QD_STORE_QUAD2], CI_WAIT(126, 29));
   2690 		CBUMP(tmp);
   2691 		CMOVE(tmp, R_COLOR01, QUAD2_ID);
   2692 		tmp = find_copper_inst(p24_this_data->frames[F_QD_STORE_QUAD3], CI_WAIT(126, 29));
   2693 		CBUMP(tmp);
   2694 		CMOVE(tmp, R_COLOR01, QUAD3_ID);
   2695 
   2696 		plane[0]--;
   2697 		plane[0]--;
   2698 		if (depth == 2) {
   2699 			plane[1]--;
   2700 			plane[1]--;
   2701 		}
   2702 		/*
   2703 		 * Set bitplane pointers.
   2704 		 */
   2705 		tmp = find_copper_inst(p24_this_data->frames[F_QD_STORE_QUAD0], CI_MOVE(R_BPLMOD2));
   2706 		CBUMP(tmp);
   2707 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][0])));
   2708 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][0])));
   2709 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][full_line])));
   2710 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][full_line])));
   2711 		if (depth == 2) {
   2712 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][0])));
   2713 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][0])));
   2714 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][full_line])));
   2715 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][full_line])));
   2716 		}
   2717 #if defined (GRF_ECS)
   2718 		CMOVE(tmp, R_DIWHIGH, 0x2100);
   2719 #endif
   2720 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD1])));
   2721 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD1])));
   2722 		CEND(tmp);
   2723 		CEND(tmp);
   2724 
   2725 		tmp = find_copper_inst(p24_this_data->frames[F_QD_STORE_QUAD1], CI_MOVE(R_BPLMOD2));
   2726 		CBUMP(tmp);
   2727 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][HALF_2024_LINE])));
   2728 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][HALF_2024_LINE])));
   2729 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][full_line + HALF_2024_LINE])));
   2730 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][full_line + HALF_2024_LINE])));
   2731 		if (depth == 2) {
   2732 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][HALF_2024_LINE])));
   2733 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][HALF_2024_LINE])));
   2734 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][full_line + HALF_2024_LINE])));
   2735 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][full_line + HALF_2024_LINE])));
   2736 		}
   2737 #if defined (GRF_ECS)
   2738 		CMOVE(tmp, R_DIWHIGH, 0x2100);
   2739 #endif
   2740 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD2])));
   2741 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD2])));
   2742 		CEND(tmp);
   2743 		CEND(tmp);
   2744 
   2745 		tmp = find_copper_inst(p24_this_data->frames[F_QD_STORE_QUAD2], CI_MOVE(R_BPLMOD2));
   2746 		CBUMP(tmp);
   2747 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane])));
   2748 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane])));
   2749 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line])));
   2750 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line])));
   2751 		if (depth == 2) {
   2752 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane])));
   2753 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane])));
   2754 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line])));
   2755 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line])));
   2756 		}
   2757 #if defined (GRF_ECS)
   2758 		CMOVE(tmp, R_DIWHIGH, 0x2100);
   2759 #endif
   2760 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD3])));
   2761 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD3])));
   2762 		CEND(tmp);
   2763 		CEND(tmp);
   2764 
   2765 		tmp = find_copper_inst(p24_this_data->frames[F_QD_STORE_QUAD3], CI_MOVE(R_BPLMOD2));
   2766 		CBUMP(tmp);
   2767 		CMOVE(tmp, R_BPL0PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane + HALF_2024_LINE])));
   2768 		CMOVE(tmp, R_BPL0PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane + HALF_2024_LINE])));
   2769 		CMOVE(tmp, R_BPL1PTH, HIADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line + HALF_2024_LINE])));
   2770 		CMOVE(tmp, R_BPL1PTL, LOADDR(PREP_DMA_MEM(&plane[0][half_plane + full_line + HALF_2024_LINE])));
   2771 		if (depth == 2) {
   2772 			CMOVE(tmp, R_BPL2PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane + HALF_2024_LINE])));
   2773 			CMOVE(tmp, R_BPL2PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane + HALF_2024_LINE])));
   2774 			CMOVE(tmp, R_BPL3PTH, HIADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line + HALF_2024_LINE])));
   2775 			CMOVE(tmp, R_BPL3PTL, LOADDR(PREP_DMA_MEM(&plane[1][half_plane + full_line + HALF_2024_LINE])));
   2776 		}
   2777 #if defined (GRF_ECS)
   2778 		CMOVE(tmp, R_DIWHIGH, 0x2100);
   2779 #endif
   2780 		CMOVE(tmp, R_COP1LCH, HIADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD0])));
   2781 		CMOVE(tmp, R_COP1LCL, LOADDR(PREP_DMA_MEM(p24_this_data->frames[F_QD_STORE_QUAD0])));
   2782 		CEND(tmp);
   2783 		CEND(tmp);
   2784 
   2785 		/* swap new pointers in. */
   2786 		for (i = F_QD_STORE_QUAD0, j = F_QD_QUAD0;
   2787 		    i <= F_QD_STORE_QUAD3; i++, j++) {
   2788 			cp = p24_this_data->frames[j];
   2789 			p24_this_data->frames[j] = p24_this_data->frames[i];
   2790 			p24_this_data->frames[i] = cp;
   2791 		}
   2792 
   2793 		p24_this_data->current_view = v;
   2794 		vd->flags |= VF_DISPLAY;
   2795 
   2796 		cc_a2024_use_colormap(v, vd->colormap);
   2797 	}
   2798 	cc_load_mode(p24_this);
   2799 }
   2800 
   2801 void
   2802 pal_a2024_mode_vbl_handler(d)
   2803 	dmode_t *d;
   2804 {
   2805 	u_short vp = ((custom.vposr & 0x0007) << 8) | ((custom.vhposr) >> 8);
   2806 
   2807 	if (vp < 20) {
   2808 		custom.cop1lc = PREP_DMA_MEM(p24_this_data->frames[p24_this_data->hedley_current]);
   2809 		custom.copjmp1 = 0;
   2810 	}
   2811 	p24_this_data->hedley_current++;
   2812 	p24_this_data->hedley_current &= 0x3;	/* if 4 then 0. */
   2813 }
   2814 #endif /* GRF_A2024 */
   2815 
   2816 #if defined (GRF_AGA)
   2817 
   2818 dmode_t *
   2819 cc_init_pal_aga()
   2820 {
   2821 	/* this function should only be called once. */
   2822 	if (!paga_this && (custom.deniseid & 0xff) == 0xf8 &&
   2823 	    aga_enable & AGA_ENABLE) {
   2824 		u_short len = aga_copper_list_len;
   2825 		cop_t  *cp;
   2826 
   2827 		paga_this = &paga_mode;
   2828 		paga_this_data = &paga_mode_data;
   2829 		bzero(paga_this, sizeof(dmode_t));
   2830 		bzero(paga_this_data, sizeof(dmdata_t));
   2831 
   2832 		paga_this->name = "pal: AGA dbl";
   2833 		paga_this->nominal_size.width = 640;
   2834 		paga_this->nominal_size.height = 512;
   2835 		paga_this_data->max_size.width = 720;
   2836 		paga_this_data->max_size.height = 564;
   2837 		paga_this_data->min_size.width = 320;
   2838 		paga_this_data->min_size.height = 200;
   2839 		paga_this_data->min_depth = 1;
   2840 		paga_this_data->max_depth = 8;
   2841 		paga_this->data = paga_this_data;
   2842 
   2843 		paga_this->get_monitor = cc_get_monitor;
   2844 		paga_this->alloc_view = cc_alloc_view;
   2845 		paga_this->get_current_view = cc_get_current_view;
   2846 
   2847 		paga_this_data->use_colormap = cc_use_aga_colormap;
   2848 		paga_this_data->get_colormap = cc_get_colormap;
   2849 		paga_this_data->alloc_colormap = cc_alloc_aga_colormap;
   2850 		paga_this_data->display_view = display_pal_aga_view;
   2851 		paga_this_data->monitor = cc_monitor;
   2852 
   2853 		paga_this_data->frames = paga_frames;
   2854 		paga_this_data->frames[F_LONG] = alloc_chipmem(aga_copper_list_size * F_TOTAL);
   2855 		if (!paga_this_data->frames[F_LONG]) {
   2856 			panic("couldn't get chipmem for copper list");
   2857 		}
   2858 		paga_this_data->frames[F_STORE_LONG] = &paga_this_data->frames[F_LONG][len];
   2859 
   2860 		bcopy(aga_copper_list, paga_this_data->frames[F_STORE_LONG], aga_copper_list_size);
   2861 		bcopy(aga_copper_list, paga_this_data->frames[F_LONG], aga_copper_list_size);
   2862 
   2863 		paga_this_data->bplcon0 = 0x0240 | USE_CON3;	/* color composite
   2864 								 * enable,
   2865 								 * shres. */
   2866 		paga_this_data->std_start_x = 0x4f /*STANDARD_VIEW_X*/;
   2867 		paga_this_data->std_start_y = 0x2b /*STANDARD_VIEW_Y*/;
   2868 		paga_this_data->vbl_handler = (vbl_handler_func *) cc_mode_vbl_handler;
   2869 		paga_this_data->beamcon0 = STANDARD_PAL_BEAMCON | (SPECIAL_BEAMCON ^ VSYNCTRUE);
   2870 
   2871 		LIST_INSERT_HEAD(&MDATA(cc_monitor)->modes,
   2872 		    paga_this, link);
   2873 	}
   2874 	return (paga_this);
   2875 }
   2876 
   2877 /* static, so I can patch and play (VGAOnly is commented-out) */
   2878 
   2879 int	pAGA_htotal  = 0x081;	/* 0x079 */
   2880 int	pAGA_hsstrt  = 0x00f;	/* 0x00f */
   2881 int	pAGA_hsstop  = 0x019;	/* 0x019 */
   2882 int	pAGA_hbstrt  = 0x001;	/* 0x001 */
   2883 int	pAGA_hbstop  = 0x021;	/* 0x021 */
   2884 int	pAGA_vtotal  = 0x23d;	/* 0x24d */
   2885 int	pAGA_vsstrt  = 0x001;	/* 0x001 */
   2886 int	pAGA_vsstop  = 0x008;	/* 0x008 */
   2887 int	pAGA_vbstrt  = 0x000;	/* 0x000 */
   2888 int	pAGA_vbstop  = 0x017;	/* 0x019 */
   2889 int	pAGA_hcenter = 0x04f;	/* 0x04b */
   2890 
   2891 void
   2892 display_pal_aga_view(v)
   2893 	view_t *v;
   2894 {
   2895 	if (paga_this_data->current_view != v) {
   2896 		vdata_t *vd = VDATA(v);
   2897 		monitor_t *monitor = paga_this_data->monitor;
   2898 		cop_t  *cp = paga_this_data->frames[F_STORE_LONG], *tmp;
   2899 		int     depth = v->bitmap->depth, i;
   2900 		int     hstart, hstop, vstart, vstop, j;
   2901 		int     x, y, w = v->display.width, h = v->display.height;
   2902 		u_short ddfstart, ddfwidth, con1;
   2903 
   2904 #ifdef DEBUG
   2905 		if (aga_enable & AGA_TRACE)
   2906 			printf("display_aga_view(%dx%dx%d) %x\n", w, h,
   2907 			    depth, v);
   2908 #endif
   2909 		/* round down to nearest even width */
   2910 		/* w &= 0xfffe; */
   2911 		/* calculate datafetch width. */
   2912 
   2913 		ddfwidth = ((v->bitmap->bytes_per_row >> 1) - 4) << 1;
   2914 
   2915 		/* this will center the any overscanned display */
   2916 		/* and allow user to modify. */
   2917 		x = v->display.x + paga_this_data->std_start_x - ((w - 640) >> 3);
   2918 		y = v->display.y + paga_this_data->std_start_y - ((h - 512) >> 1);
   2919 
   2920 		if (y & 1)
   2921 			y--;
   2922 
   2923 		if (!(x & 1))
   2924 			x--;
   2925 
   2926 		hstart = x;
   2927 		hstop = x + (w >> 2);
   2928 		vstart = y;
   2929 		vstop = y + (h >> 0);
   2930 		ddfstart = (hstart >> 1) - 8;
   2931 
   2932 #ifdef DEBUG
   2933 		if (aga_enable & AGA_TRACE2) {
   2934 			printf ("  ddfwidth %04x x %04x y %04x", ddfwidth,
   2935 			    x, y);
   2936 			printf (" hstart %04x hstop %04x vstart %04x vstop %04x ddfstart %04x\n",
   2937 			    hstart, hstop, vstart, vstop, ddfstart);
   2938 		}
   2939 #endif
   2940 		/* check for hardware limits, AGA may allow more..? */
   2941 		/* anyone got a 4000 I can borrow :^) -ch */
   2942 		if ((ddfstart & 0xfffc) + ddfwidth > 0xd8) {
   2943 			int     d = 0;
   2944 
   2945 			/* XXX anyone know the equality properties of
   2946 			 * intermixed logial AND's */
   2947 			/* XXX and arithmetic operators? */
   2948 			while (((ddfstart & 0xfffc) + ddfwidth - d) > 0xd8) {
   2949 				d++;
   2950 			}
   2951 
   2952 			ddfstart -= d;
   2953 			hstart -= d << 1;
   2954 			hstop -= d << 1;
   2955 		}
   2956 		/* correct the datafetch to proper limits. */
   2957 		/* delay the actual display of the data until we need it. */
   2958 		ddfstart &= 0xfffc;
   2959 #ifdef DEBUG
   2960 		if (aga_enable & AGA_TRACE2) {
   2961 			printf ("  ddfwidth %04x x %04x y %04x", ddfwidth,
   2962 			    x, y);
   2963 			printf (" hstart %04x hstop %04x vstart %04x vstop %04x ddfstart %04x\n",
   2964 			    hstart, hstop, vstart, vstop, ddfstart);
   2965 		}
   2966 #endif
   2967 		con1 = ((hstart - 9) - (ddfstart << 1)) | (((hstart - 9) - (ddfstart << 1)) << 4);
   2968 
   2969 		if (paga_this_data->current_view) {
   2970 			VDATA(paga_this_data->current_view)->flags &= ~VF_DISPLAY;	/* mark as no longer */
   2971 			/* displayed. */
   2972 		}
   2973 		paga_this_data->current_view = v;
   2974 
   2975 		cp = paga_this_data->frames[F_STORE_LONG];
   2976 		tmp = cp;
   2977 		for (i = 0; i < 8; ++i) {
   2978 			if (tmp == NULL)
   2979 				break;
   2980 			tmp = find_copper_inst(tmp + 1, CI_MOVE(R_BPLCON3));
   2981 			if (tmp == NULL)
   2982 				break;
   2983 			tmp->cp.inst.operand = 0x0ca1 | (i << 13);
   2984 			tmp = find_copper_inst(tmp + 1, CI_MOVE(R_BPLCON3));
   2985 			if (tmp == NULL)
   2986 				break;
   2987 			tmp->cp.inst.operand = 0x0ea1 | (i << 13);
   2988 		}
   2989 		if (tmp)
   2990 			tmp = find_copper_inst(tmp + 1, CI_MOVE(R_BPLCON3));
   2991 		if (tmp)
   2992 			tmp->cp.inst.operand = 0x0ca1;
   2993 		tmp = find_copper_inst(cp, CI_MOVE(R_FMODE));
   2994 		tmp->cp.inst.operand = 0x8003;
   2995 		tmp = find_copper_inst(cp, CI_MOVE(R_HTOTAL));
   2996 		tmp->cp.inst.operand = pAGA_htotal; /* 81/71/73/79? */
   2997 		tmp = find_copper_inst(cp, CI_MOVE(R_HBSTRT));
   2998 		tmp->cp.inst.operand = pAGA_hbstrt; /* 0x0008 */
   2999 		tmp = find_copper_inst(cp, CI_MOVE(R_HSSTRT));
   3000 		tmp->cp.inst.operand = pAGA_hsstrt; /* 0x000e */
   3001 		tmp = find_copper_inst(cp, CI_MOVE(R_HSSTOP));
   3002 		tmp->cp.inst.operand = pAGA_hsstop; /* 0x001c */
   3003 		tmp = find_copper_inst(cp, CI_MOVE(R_HBSTOP));
   3004 		tmp->cp.inst.operand = pAGA_hsstop; /* 0x001e */
   3005 		tmp = find_copper_inst(cp, CI_MOVE(R_HCENTER));
   3006 		tmp->cp.inst.operand = pAGA_hcenter; /*AGA_htotal / 2 + AGA_hsstrt */
   3007 		tmp = find_copper_inst(cp, CI_MOVE(R_VBSTRT));
   3008 		tmp->cp.inst.operand = pAGA_vbstrt; /* 0x0000 */
   3009 		tmp = find_copper_inst(cp, CI_MOVE(R_VSSTRT));
   3010 		tmp->cp.inst.operand = pAGA_vsstrt; /* 0x016b / AGA_htotal */
   3011 		tmp = find_copper_inst(cp, CI_MOVE(R_VSSTOP));
   3012 		tmp->cp.inst.operand = pAGA_vsstop; /* 0x02d6 / AGA_htotal */
   3013 		tmp = find_copper_inst(cp, CI_MOVE(R_VBSTOP));
   3014 		tmp->cp.inst.operand = pAGA_vbstop; /* 0x0bd1 / AGA_htotal */
   3015 		tmp = find_copper_inst(cp, CI_MOVE(R_VTOTAL));
   3016 		tmp->cp.inst.operand = pAGA_vtotal;
   3017 		tmp = find_copper_inst(cp, CI_MOVE(R_BEAMCON0));
   3018 		tmp->cp.inst.operand = paga_this_data->beamcon0;
   3019 #ifdef DEBUG
   3020 		if (aga_enable & AGA_TRACE2)
   3021 			printf("  beamcon0 %04x", tmp->cp.inst.operand);
   3022 #endif
   3023 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWHIGH));
   3024 		tmp->cp.inst.operand = CALC_DIWHIGH(hstart, vstart, hstop, vstop);
   3025 #ifdef DEBUG
   3026 		if (aga_enable & AGA_TRACE2)
   3027 			printf(" diwhigh %04x>", tmp->cp.inst.operand);
   3028 #endif
   3029 #if 0
   3030 		tmp->cp.inst.operand = (vstop & 0x0700) | ((hstop & 0x0100) << 5);
   3031 #endif
   3032 #ifdef DEBUG
   3033 		if (aga_enable & AGA_TRACE2)
   3034 			printf("%04x", tmp->cp.inst.operand);
   3035 #endif
   3036 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON0));
   3037 		tmp->cp.inst.operand = paga_this_data->bplcon0 |
   3038 		    ((depth & 0x7) << 12) | ((depth & 0x8) << 1);
   3039 #ifdef DEBUG
   3040 		if (aga_enable & AGA_TRACE2)
   3041 			printf(" bplcon0 %04x", tmp->cp.inst.operand);
   3042 #endif
   3043 		tmp = find_copper_inst(cp, CI_MOVE(R_BPLCON1));
   3044 		tmp->cp.inst.operand = con1;
   3045 #ifdef DEBUG
   3046 		if (aga_enable & AGA_TRACE2)
   3047 			printf(" bplcon1 %04x>0000\n", con1);
   3048 #endif
   3049 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTART));
   3050 		tmp->cp.inst.operand = ((vstart & 0xff) << 8) | (hstart & 0xff);
   3051 #ifdef DEBUG
   3052 		if (aga_enable & AGA_TRACE2)
   3053 			printf("  diwstart %04x", tmp->cp.inst.operand);
   3054 #endif
   3055 		tmp = find_copper_inst(cp, CI_MOVE(R_DIWSTOP));
   3056 		tmp->cp.inst.operand = ((vstop & 0xff) << 8) | (hstop & 0xff);
   3057 #ifdef DEBUG
   3058 		if (aga_enable & AGA_TRACE2)
   3059 			printf(" diwstop %04x", tmp->cp.inst.operand);
   3060 #endif
   3061 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTART));
   3062 		tmp->cp.inst.operand = ddfstart;
   3063 #ifdef DEBUG
   3064 		if (aga_enable & AGA_TRACE2)
   3065 			printf(" ddfstart %04x", tmp->cp.inst.operand);
   3066 #endif
   3067 		tmp = find_copper_inst(cp, CI_MOVE(R_DDFSTOP));
   3068 		tmp->cp.inst.operand = ddfstart + ddfwidth;
   3069 #ifdef DEBUG
   3070 		if (aga_enable & AGA_TRACE2)
   3071 			printf(" ddfstop %04x", tmp->cp.inst.operand);
   3072 #endif
   3073 
   3074 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL0PTH));
   3075 		for (i = 0, j = 0; i < depth; j += 2, i++) {
   3076 			/* update the plane pointers */
   3077 			tmp[j].cp.inst.operand = HIADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   3078 			tmp[j + 1].cp.inst.operand = LOADDR(PREP_DMA_MEM(v->bitmap->plane[i]));
   3079 #ifdef DEBUG
   3080 		if (aga_enable & AGA_TRACE2)
   3081 			printf (" bpl%dpth %08x", i, v->bitmap->plane[i]);
   3082 #endif
   3083 		}
   3084 
   3085 		/* set mods correctly. */
   3086 		tmp = find_copper_inst(cp, CI_MOVE(R_BPL1MOD));
   3087 		tmp[0].cp.inst.operand = v->bitmap->row_mod;
   3088 		tmp[1].cp.inst.operand = v->bitmap->row_mod;
   3089 #ifdef DEBUG
   3090 		if (aga_enable & AGA_TRACE2)
   3091 			printf(" bplxmod %04x\n", v->bitmap->row_mod);
   3092 #endif
   3093 
   3094 		/* set next pointers correctly */
   3095 		tmp = find_copper_inst(cp, CI_MOVE(R_COP1LCH));
   3096 		tmp[0].cp.inst.operand = HIADDR(PREP_DMA_MEM(paga_this_data->frames[F_STORE_LONG]));
   3097 		tmp[1].cp.inst.operand = LOADDR(PREP_DMA_MEM(paga_this_data->frames[F_STORE_LONG]));
   3098 
   3099 		cp = paga_this_data->frames[F_LONG];
   3100 		paga_this_data->frames[F_LONG] = paga_this_data->frames[F_STORE_LONG];
   3101 		paga_this_data->frames[F_STORE_LONG] = cp;
   3102 
   3103 		vd->flags |= VF_DISPLAY;
   3104 
   3105 		cc_use_aga_colormap(v, vd->colormap);
   3106 	}
   3107 	cc_load_mode(paga_this);
   3108 #ifdef DEBUG
   3109 	if (aga_enable & AGA_TRACE)
   3110 		aga_enable |= AGA_TRACE2;	/* XXXX */
   3111 #endif
   3112 }
   3113 
   3114 #endif /* GRF_AGA */
   3115 #endif /* GRF_PAL */
   3116