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