xref: /netbsd-src/sys/arch/hp300/stand/common/ite_dumb.c (revision 8448487e704668efb4dc7a0968d659270341fd19)
1 /*	$NetBSD: ite_dumb.c,v 1.2 2023/01/15 06:19:46 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (c) 2011 Izumi Tsutsui.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 /*
27  * Copyright (c) 1988 University of Utah.
28  * Copyright (c) 1990, 1993
29  *	The Regents of the University of California.  All rights reserved.
30  *
31  * This code is derived from software contributed to Berkeley by
32  * the Systems Programming Group of the University of Utah Computer
33  * Science Department and Mark Davies of the Department of Computer
34  * Science, Victoria University of Wellington, New Zealand.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. Neither the name of the University nor the names of its contributors
45  *    may be used to endorse or promote products derived from this software
46  *    without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  * from: Utah $Hdr: ite_subr.c 1.2 92/01/20$
61  *
62  *	@(#)ite_subr.c  8.1 (Berkeley) 6/10/93
63  */
64 
65 #ifdef ITECONSOLE
66 
67 #include <sys/param.h>
68 
69 #include <hp300/stand/common/samachdep.h>
70 #include <hp300/stand/common/itereg.h>
71 #include <hp300/stand/common/itevar.h>
72 
73 static void dumb_fontinit(struct ite_data *ip);
74 static void dumb_writeglyph(struct ite_data *, uint8_t *fbmem, uint8_t *);
75 static void dumb_flip_cursor(struct ite_data *ip);
76 static void dumb_windowmove(struct ite_data *, int, int, int, int, int, int,
77     int);
78 
79 static uint8_t *font;
80 
81 void
dumb_init(struct ite_data * ip)82 dumb_init(struct ite_data *ip)
83 {
84 
85 	ip->bmv = dumb_windowmove;	/* unused */
86 	ite_fontinfo(ip);
87 	dumb_clear(ip, 0, 0, ip->rows, ip->cols);
88 	dumb_fontinit(ip);
89 }
90 
91 static void
dumb_fontinit(struct ite_data * ip)92 dumb_fontinit(struct ite_data *ip)
93 {
94 	int bytewidth = (((ip->ftwidth - 1) / 8) + 1);
95 	int glyphsize = bytewidth * ip->ftheight;
96 	uint8_t fontbuf[500];
97 	uint8_t *dp, *fontp;
98 	int c, i, romp;
99 
100 	/*
101 	 * We don't bother to copy font glyph into fbmem
102 	 * since there is no hardware windowmove ops.
103 	 * Prepare font data into contiguous memory instead.
104 	 */
105 	font = alloc((ip->ftwidth * ip->ftheight) * 128);
106 	romp = getword(ip, getword(ip, FONTROM) + FONTADDR) + FONTDATA;
107 
108 	for (c = 0; c < 128; c++) {
109 		/* get font glyph from FONTROM */
110 		dp = fontbuf;
111 		for (i = 0; i < glyphsize; i++) {
112 			*dp++ = getbyte(ip, romp);
113 			romp += 2;
114 		}
115 
116 		/* setup font data for 8bpp fbmem */
117 		fontp = &font[(ip->ftwidth * ip->ftheight) * c];
118 		dumb_writeglyph(ip, fontp, fontbuf);
119 	}
120 }
121 
122 static void
dumb_writeglyph(struct ite_data * ip,uint8_t * fontmem,uint8_t * glyphp)123 dumb_writeglyph(struct ite_data *ip, uint8_t *fontmem, uint8_t *glyphp)
124 {
125 	int bn;
126 	int b, l;
127 
128 	for (l = 0; l < ip->ftheight; l++) {
129 		bn = 7;
130 		for (b = 0; b < ip->ftwidth; b++) {
131 			if ((1 << bn) & *glyphp)
132 				*fontmem++ = 0x01;
133 			else
134 				*fontmem++ = 0x00;
135 			if (--bn < 0) {
136 				bn = 7;
137 				glyphp++;
138 			}
139 		}
140 		if (bn < 7)
141 			glyphp++;
142 	}
143 }
144 
145 static void
dumb_flip_cursor(struct ite_data * ip)146 dumb_flip_cursor(struct ite_data *ip)
147 {
148 	int l, w;
149 	uint8_t *pc;
150 	uint32_t *pc32;
151 
152 	pc = (uint8_t *)ip->fbbase +
153 	    ((ip->ftheight * ip->cursory) * ip->fbwidth) +
154 	    ip->ftwidth * ip->cursorx;
155 
156 	for (l = 0; l < ip->ftheight; l++) {
157 		/* assume (ip->ftwidth % sizeof(uint32_t) == 0) */
158 		pc32 = (uint32_t *)pc;
159 		for (w = 0; w < ip->ftwidth / sizeof(uint32_t); w++)
160 			pc32[w] ^= 0x01010101;
161 		pc += ip->fbwidth;
162 	}
163 }
164 
165 void
dumb_cursor(struct ite_data * ip,int flag)166 dumb_cursor(struct ite_data *ip, int flag)
167 {
168 
169 	switch (flag) {
170 	case MOVE_CURSOR:
171 		dumb_flip_cursor(ip);
172 		/* FALLTHROUGH */
173 	case DRAW_CURSOR:
174 		ip->cursorx = ip->curx;
175 		ip->cursory = ip->cury;
176 		/* FALLTHROUGH */
177 	default:
178 		dumb_flip_cursor(ip);
179 		break;
180 	}
181 }
182 
183 void
dumb_putc(struct ite_data * ip,int c,int dy,int dx)184 dumb_putc(struct ite_data *ip, int c, int dy, int dx)
185 {
186 	int l, w;
187 	uint8_t *pc;
188 	uint32_t *pc32;
189 	uint32_t *fontp;
190 
191 	pc = (uint8_t *)ip->fbbase +
192 	    ((ip->ftheight * ip->cursory) * ip->fbwidth) +
193 	    ip->ftwidth * ip->cursorx;
194 	fontp = (uint32_t *)&font[(ip->ftwidth * ip->ftheight) * c];
195 
196 	for (l = 0; l < ip->ftheight; l++) {
197 		/* assume (ip->ftwidth % sizeof(uint32_t) == 0) */
198 		pc32 = (uint32_t *)pc;
199 		for (w = 0; w < ip->ftwidth / sizeof(uint32_t); w++)
200 			pc32[w] = *fontp++;
201 		pc += ip->fbwidth;
202 	}
203 }
204 
205 void
dumb_clear(struct ite_data * ip,int sy,int sx,int h,int w)206 dumb_clear(struct ite_data *ip, int sy, int sx, int h, int w)
207 {
208 	int l;
209 	uint8_t *pdst;
210 
211 	pdst = (uint8_t *)ip->fbbase +
212 	    ((ip->ftheight * sy) * ip->fbwidth) + ip->ftwidth * sx;
213 
214 	for (l = 0; l < ip->ftheight * h; l++) {
215 		/* slow, but just works */
216 		memset(pdst, 0, ip->ftwidth * w);
217 		pdst += ip->fbwidth;
218 	}
219 }
220 
221 void
dumb_scroll(struct ite_data * ip)222 dumb_scroll(struct ite_data *ip)
223 {
224 	int l, h, w;
225 	uint8_t *psrc, *pdst;
226 
227 	dumb_flip_cursor(ip);
228 
229 	psrc = (uint8_t *)ip->fbbase + (ip->ftheight * ip->fbwidth);
230 	pdst = (uint8_t *)ip->fbbase;
231 
232 	h = (ip->rows - 1) * ip->ftheight;
233 	w = ip->cols * ip->ftwidth;
234 
235 	for (l = 0; l < h; l++) {
236 		/* slow, but just works and no scroll if no retry */
237 		memmove(pdst, psrc, w);
238 		psrc += ip->fbwidth;
239 		pdst += ip->fbwidth;
240 	}
241 }
242 
243 static void
dumb_windowmove(struct ite_data * ip,int sy,int sx,int dy,int dx,int w,int h,int func)244 dumb_windowmove(struct ite_data *ip, int sy, int sx, int dy, int dx,
245     int w, int h, int func)
246 {
247 
248 	/* for sanity check */
249 	printf("%s: called\n", __func__);
250 }
251 #endif
252