Home | History | Annotate | Line # | Download | only in dev
diofb_mono.c revision 1.1
      1  1.1  tsutsui /*	$NetBSD: diofb_mono.c,v 1.1 2011/02/06 18:26:51 tsutsui Exp $	*/
      2  1.1  tsutsui /*	$OpenBSD: diofb_mono.c,v 1.3 2006/08/11 18:33:13 miod Exp $	*/
      3  1.1  tsutsui 
      4  1.1  tsutsui /*
      5  1.1  tsutsui  * Copyright (c) 2005, Miodrag Vallat.
      6  1.1  tsutsui  * All rights reserved.
      7  1.1  tsutsui  *
      8  1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      9  1.1  tsutsui  * modification, are permitted provided that the following conditions
     10  1.1  tsutsui  * are met:
     11  1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     12  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     13  1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     16  1.1  tsutsui  *
     17  1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     19  1.1  tsutsui  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     20  1.1  tsutsui  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     21  1.1  tsutsui  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     22  1.1  tsutsui  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     23  1.1  tsutsui  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  1.1  tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     25  1.1  tsutsui  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     26  1.1  tsutsui  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  1.1  tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     28  1.1  tsutsui  *
     29  1.1  tsutsui  */
     30  1.1  tsutsui /*-
     31  1.1  tsutsui  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
     32  1.1  tsutsui  * All rights reserved.
     33  1.1  tsutsui  *
     34  1.1  tsutsui  * This code is derived from software contributed to The NetBSD Foundation
     35  1.1  tsutsui  * by Jason R. Thorpe.
     36  1.1  tsutsui  *
     37  1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
     38  1.1  tsutsui  * modification, are permitted provided that the following conditions
     39  1.1  tsutsui  * are met:
     40  1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     41  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     42  1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     43  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     44  1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     45  1.1  tsutsui  *
     46  1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     47  1.1  tsutsui  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     48  1.1  tsutsui  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     49  1.1  tsutsui  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     50  1.1  tsutsui  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     51  1.1  tsutsui  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     52  1.1  tsutsui  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     53  1.1  tsutsui  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     54  1.1  tsutsui  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     55  1.1  tsutsui  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     56  1.1  tsutsui  * POSSIBILITY OF SUCH DAMAGE.
     57  1.1  tsutsui  */
     58  1.1  tsutsui 
     59  1.1  tsutsui /*
     60  1.1  tsutsui  * Copyright (c) 1991 University of Utah.
     61  1.1  tsutsui  * Copyright (c) 1990, 1993
     62  1.1  tsutsui  *	The Regents of the University of California.  All rights reserved.
     63  1.1  tsutsui  *
     64  1.1  tsutsui  * This code is derived from software contributed to Berkeley by
     65  1.1  tsutsui  * the Systems Programming Group of the University of Utah Computer
     66  1.1  tsutsui  * Science Department and Mark Davies of the Department of Computer
     67  1.1  tsutsui  * Science, Victoria University of Wellington, New Zealand.
     68  1.1  tsutsui  *
     69  1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
     70  1.1  tsutsui  * modification, are permitted provided that the following conditions
     71  1.1  tsutsui  * are met:
     72  1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     73  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     74  1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     75  1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     76  1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     77  1.1  tsutsui  * 3. Neither the name of the University nor the names of its contributors
     78  1.1  tsutsui  *    may be used to endorse or promote products derived from this software
     79  1.1  tsutsui  *    without specific prior written permission.
     80  1.1  tsutsui  *
     81  1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     82  1.1  tsutsui  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     83  1.1  tsutsui  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     84  1.1  tsutsui  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     85  1.1  tsutsui  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     86  1.1  tsutsui  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     87  1.1  tsutsui  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     88  1.1  tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     89  1.1  tsutsui  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     90  1.1  tsutsui  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     91  1.1  tsutsui  * SUCH DAMAGE.
     92  1.1  tsutsui  *
     93  1.1  tsutsui  * from: Utah $Hdr: grf_hy.c 1.2 93/08/13$
     94  1.1  tsutsui  *
     95  1.1  tsutsui  *	@(#)grf_hy.c	8.4 (Berkeley) 1/12/94
     96  1.1  tsutsui  */
     97  1.1  tsutsui 
     98  1.1  tsutsui /*
     99  1.1  tsutsui  * Graphics routines for real 1bpp frame buffers (i.e. pixels not being
    100  1.1  tsutsui  * byte-addressed)
    101  1.1  tsutsui  */
    102  1.1  tsutsui 
    103  1.1  tsutsui #include <sys/param.h>
    104  1.1  tsutsui #include <sys/systm.h>
    105  1.1  tsutsui #include <sys/bus.h>
    106  1.1  tsutsui 
    107  1.1  tsutsui #include <dev/wscons/wsconsio.h>
    108  1.1  tsutsui #include <dev/wscons/wsdisplayvar.h>
    109  1.1  tsutsui #include <dev/rasops/rasops.h>
    110  1.1  tsutsui 
    111  1.1  tsutsui #include <hp300/dev/diofbreg.h>
    112  1.1  tsutsui #include <hp300/dev/diofbvar.h>
    113  1.1  tsutsui 
    114  1.1  tsutsui #include <dev/rasops/rasops_masks.h>
    115  1.1  tsutsui #include <hp300/dev/maskbits.h>
    116  1.1  tsutsui 
    117  1.1  tsutsui int
    118  1.1  tsutsui diofb_mono_windowmove(struct diofb *fb, u_int16_t sx, u_int16_t sy,
    119  1.1  tsutsui     u_int16_t dx, u_int16_t dy, u_int16_t cx, u_int16_t cy, int16_t rop,
    120  1.1  tsutsui     int16_t planemask /* ignored */)
    121  1.1  tsutsui {
    122  1.1  tsutsui 	int width;		/* add to get to same position in next line */
    123  1.1  tsutsui 
    124  1.1  tsutsui 	unsigned int *psrcLine, *pdstLine;
    125  1.1  tsutsui 				/* pointers to line with current src and dst */
    126  1.1  tsutsui 	unsigned int *psrc;	/* pointer to current src longword */
    127  1.1  tsutsui 	unsigned int *pdst;	/* pointer to current dst longword */
    128  1.1  tsutsui 
    129  1.1  tsutsui 				/* following used for looping through a line */
    130  1.1  tsutsui 	unsigned int startmask, endmask;  /* masks for writing ends of dst */
    131  1.1  tsutsui 	int nlMiddle;		/* whole longwords in dst */
    132  1.1  tsutsui 	int nl;			/* temp copy of nlMiddle */
    133  1.1  tsutsui 	int xoffSrc;		/* offset (>= 0, < 32) from which to
    134  1.1  tsutsui 				   fetch whole longwords fetched in src */
    135  1.1  tsutsui 	int nstart;		/* number of ragged bits at start of dst */
    136  1.1  tsutsui 	int nend;		/* number of ragged bits at end of dst */
    137  1.1  tsutsui 	int srcStartOver;	/* pulling nstart bits from src
    138  1.1  tsutsui 				   overflows into the next word? */
    139  1.1  tsutsui 
    140  1.1  tsutsui 	width = fb->fbwidth >> 5;
    141  1.1  tsutsui 
    142  1.1  tsutsui 	if (sy < dy) {	/* start at last scanline of rectangle */
    143  1.1  tsutsui 		psrcLine = ((u_int *)fb->fbkva) + ((sy + cy - 1) * width);
    144  1.1  tsutsui 		pdstLine = ((u_int *)fb->fbkva) + ((dy + cy - 1) * width);
    145  1.1  tsutsui 		width = -width;
    146  1.1  tsutsui 	} else {	/* start at first scanline */
    147  1.1  tsutsui 		psrcLine = ((u_int *)fb->fbkva) + (sy * width);
    148  1.1  tsutsui 		pdstLine = ((u_int *)fb->fbkva) + (dy * width);
    149  1.1  tsutsui 	}
    150  1.1  tsutsui 
    151  1.1  tsutsui 	/* x direction doesn't matter for < 1 longword */
    152  1.1  tsutsui 	if (cx <= 32) {
    153  1.1  tsutsui 		int srcBit, dstBit;	/* bit offset of src and dst */
    154  1.1  tsutsui 
    155  1.1  tsutsui 		pdstLine += (dx >> 5);
    156  1.1  tsutsui 		psrcLine += (sx >> 5);
    157  1.1  tsutsui 		psrc = psrcLine;
    158  1.1  tsutsui 		pdst = pdstLine;
    159  1.1  tsutsui 
    160  1.1  tsutsui 		srcBit = sx & 0x1f;
    161  1.1  tsutsui 		dstBit = dx & 0x1f;
    162  1.1  tsutsui 
    163  1.1  tsutsui 		while (cy--) {
    164  1.1  tsutsui 			getandputrop(psrc, srcBit, dstBit, cx, pdst, rop);
    165  1.1  tsutsui 			pdst += width;
    166  1.1  tsutsui 			psrc += width;
    167  1.1  tsutsui 		}
    168  1.1  tsutsui 	} else {
    169  1.1  tsutsui 		maskbits(dx, cx, startmask, endmask, nlMiddle);
    170  1.1  tsutsui 		if (startmask)
    171  1.1  tsutsui 			nstart = 32 - (dx & 0x1f);
    172  1.1  tsutsui 		else
    173  1.1  tsutsui 			nstart = 0;
    174  1.1  tsutsui 		if (endmask)
    175  1.1  tsutsui 			nend = (dx + cx) & 0x1f;
    176  1.1  tsutsui 		else
    177  1.1  tsutsui 			nend = 0;
    178  1.1  tsutsui 
    179  1.1  tsutsui 		xoffSrc = ((sx & 0x1f) + nstart) & 0x1f;
    180  1.1  tsutsui 		srcStartOver = ((sx & 0x1f) + nstart) > 31;
    181  1.1  tsutsui 
    182  1.1  tsutsui 		if (sx >= dx) {	/* move left to right */
    183  1.1  tsutsui 			pdstLine += (dx >> 5);
    184  1.1  tsutsui 			psrcLine += (sx >> 5);
    185  1.1  tsutsui 
    186  1.1  tsutsui 			while (cy--) {
    187  1.1  tsutsui 				psrc = psrcLine;
    188  1.1  tsutsui 				pdst = pdstLine;
    189  1.1  tsutsui 
    190  1.1  tsutsui 				if (startmask) {
    191  1.1  tsutsui 					getandputrop(psrc, (sx & 0x1f),
    192  1.1  tsutsui 					    (dx & 0x1f), nstart, pdst, rop);
    193  1.1  tsutsui 					pdst++;
    194  1.1  tsutsui 					if (srcStartOver)
    195  1.1  tsutsui 						psrc++;
    196  1.1  tsutsui 				}
    197  1.1  tsutsui 
    198  1.1  tsutsui 				/* special case for aligned operations */
    199  1.1  tsutsui 				if (xoffSrc == 0) {
    200  1.1  tsutsui 					nl = nlMiddle;
    201  1.1  tsutsui 					while (nl--) {
    202  1.1  tsutsui 						if (rop == RR_CLEAR)
    203  1.1  tsutsui 							*pdst = 0;
    204  1.1  tsutsui 						else
    205  1.1  tsutsui 							*pdst = *psrc;
    206  1.1  tsutsui 						psrc++;
    207  1.1  tsutsui 						pdst++;
    208  1.1  tsutsui 					}
    209  1.1  tsutsui 				} else {
    210  1.1  tsutsui 					nl = nlMiddle + 1;
    211  1.1  tsutsui 					while (--nl) {
    212  1.1  tsutsui 						if (rop == RR_CLEAR)
    213  1.1  tsutsui 							*pdst = 0;
    214  1.1  tsutsui 						else
    215  1.1  tsutsui 							getunalignedword(psrc,
    216  1.1  tsutsui 							    xoffSrc, *pdst);
    217  1.1  tsutsui 						pdst++;
    218  1.1  tsutsui 						psrc++;
    219  1.1  tsutsui 					}
    220  1.1  tsutsui 				}
    221  1.1  tsutsui 
    222  1.1  tsutsui 				if (endmask) {
    223  1.1  tsutsui 					getandputrop(psrc, xoffSrc, 0, nend,
    224  1.1  tsutsui 					    pdst, rop);
    225  1.1  tsutsui 				}
    226  1.1  tsutsui 
    227  1.1  tsutsui 				pdstLine += width;
    228  1.1  tsutsui 				psrcLine += width;
    229  1.1  tsutsui 			}
    230  1.1  tsutsui 		} else {	/* move right to left */
    231  1.1  tsutsui 			pdstLine += ((dx + cx) >> 5);
    232  1.1  tsutsui 			psrcLine += ((sx + cx) >> 5);
    233  1.1  tsutsui 			/*
    234  1.1  tsutsui 			 * If fetch of last partial bits from source crosses
    235  1.1  tsutsui 			 * a longword boundary, start at the previous longword
    236  1.1  tsutsui 			 */
    237  1.1  tsutsui 			if (xoffSrc + nend >= 32)
    238  1.1  tsutsui 				--psrcLine;
    239  1.1  tsutsui 
    240  1.1  tsutsui 			while (cy--) {
    241  1.1  tsutsui 				psrc = psrcLine;
    242  1.1  tsutsui 				pdst = pdstLine;
    243  1.1  tsutsui 
    244  1.1  tsutsui 				if (endmask) {
    245  1.1  tsutsui 					getandputrop(psrc, xoffSrc, 0, nend,
    246  1.1  tsutsui 					    pdst, rop);
    247  1.1  tsutsui 				}
    248  1.1  tsutsui 
    249  1.1  tsutsui 				nl = nlMiddle + 1;
    250  1.1  tsutsui 				while (--nl) {
    251  1.1  tsutsui 					--psrc;
    252  1.1  tsutsui 					--pdst;
    253  1.1  tsutsui 					if (rop == RR_CLEAR)
    254  1.1  tsutsui 						*pdst = 0;
    255  1.1  tsutsui 					else
    256  1.1  tsutsui 						getunalignedword(psrc, xoffSrc,
    257  1.1  tsutsui 						    *pdst);
    258  1.1  tsutsui 				}
    259  1.1  tsutsui 
    260  1.1  tsutsui 				if (startmask) {
    261  1.1  tsutsui 					if (srcStartOver)
    262  1.1  tsutsui 						--psrc;
    263  1.1  tsutsui 					--pdst;
    264  1.1  tsutsui 					getandputrop(psrc, (sx & 0x1f),
    265  1.1  tsutsui 					    (dx & 0x1f), nstart, pdst, rop);
    266  1.1  tsutsui 				}
    267  1.1  tsutsui 
    268  1.1  tsutsui 				pdstLine += width;
    269  1.1  tsutsui 				psrcLine += width;
    270  1.1  tsutsui 			}
    271  1.1  tsutsui 		}
    272  1.1  tsutsui 	}
    273  1.1  tsutsui 
    274  1.1  tsutsui 	return (0);
    275  1.1  tsutsui }
    276