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