1 1.13 tsutsui /* $NetBSD: ite_subr.c,v 1.13 2025/05/31 18:11:50 tsutsui Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /* 4 1.7 rmind * Copyright (c) 1988 University of Utah. 5 1.1 thorpej * Copyright (c) 1990, 1993 6 1.1 thorpej * The Regents of the University of California. All rights reserved. 7 1.2 agc * 8 1.2 agc * This code is derived from software contributed to Berkeley by 9 1.2 agc * the Systems Programming Group of the University of Utah Computer 10 1.2 agc * Science Department. 11 1.2 agc * 12 1.2 agc * Redistribution and use in source and binary forms, with or without 13 1.2 agc * modification, are permitted provided that the following conditions 14 1.2 agc * are met: 15 1.2 agc * 1. Redistributions of source code must retain the above copyright 16 1.2 agc * notice, this list of conditions and the following disclaimer. 17 1.2 agc * 2. Redistributions in binary form must reproduce the above copyright 18 1.2 agc * notice, this list of conditions and the following disclaimer in the 19 1.2 agc * documentation and/or other materials provided with the distribution. 20 1.2 agc * 3. Neither the name of the University nor the names of its contributors 21 1.2 agc * may be used to endorse or promote products derived from this software 22 1.2 agc * without specific prior written permission. 23 1.2 agc * 24 1.2 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 1.2 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 1.2 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 1.2 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 1.2 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 1.2 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 1.2 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 1.2 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 1.2 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 1.2 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 1.2 agc * SUCH DAMAGE. 35 1.2 agc * 36 1.2 agc * from: Utah $Hdr: ite_subr.c 1.2 92/01/20$ 37 1.2 agc * 38 1.2 agc * @(#)ite_subr.c 8.1 (Berkeley) 6/10/93 39 1.2 agc */ 40 1.1 thorpej 41 1.1 thorpej #ifdef ITECONSOLE 42 1.1 thorpej 43 1.1 thorpej #include <sys/param.h> 44 1.1 thorpej 45 1.6 tsutsui #include <hp300/stand/common/itereg.h> 46 1.1 thorpej 47 1.1 thorpej #include <hp300/stand/common/samachdep.h> 48 1.1 thorpej #include <hp300/stand/common/itevar.h> 49 1.1 thorpej 50 1.13 tsutsui static void ite_writeglyph(struct ite_data *, uint8_t *, uint8_t *); 51 1.8 tsutsui 52 1.3 tsutsui void 53 1.4 tsutsui ite_fontinfo(struct ite_data *ip) 54 1.1 thorpej { 55 1.13 tsutsui uint32_t fontaddr = getword(ip, getword(ip, FONTROM) + FONTADDR); 56 1.1 thorpej 57 1.1 thorpej ip->ftheight = getbyte(ip, fontaddr + FONTHEIGHT); 58 1.1 thorpej ip->ftwidth = getbyte(ip, fontaddr + FONTWIDTH); 59 1.1 thorpej ip->rows = ip->dheight / ip->ftheight; 60 1.1 thorpej ip->cols = ip->dwidth / ip->ftwidth; 61 1.1 thorpej 62 1.1 thorpej if (ip->fbwidth > ip->dwidth) { 63 1.1 thorpej /* 64 1.1 thorpej * Stuff goes to right of display. 65 1.1 thorpej */ 66 1.1 thorpej ip->fontx = ip->dwidth; 67 1.1 thorpej ip->fonty = 0; 68 1.1 thorpej ip->cpl = (ip->fbwidth - ip->dwidth) / ip->ftwidth; 69 1.1 thorpej ip->cblankx = ip->dwidth; 70 1.1 thorpej ip->cblanky = ip->fonty + ((128 / ip->cpl) +1) * ip->ftheight; 71 1.10 tsutsui } else { 72 1.1 thorpej /* 73 1.1 thorpej * Stuff goes below the display. 74 1.1 thorpej */ 75 1.1 thorpej ip->fontx = 0; 76 1.1 thorpej ip->fonty = ip->dheight; 77 1.1 thorpej ip->cpl = ip->fbwidth / ip->ftwidth; 78 1.1 thorpej ip->cblankx = 0; 79 1.1 thorpej ip->cblanky = ip->fonty + ((128 / ip->cpl) + 1) * ip->ftheight; 80 1.1 thorpej } 81 1.1 thorpej } 82 1.1 thorpej 83 1.3 tsutsui void 84 1.9 tsutsui ite_fontinit1bpp(struct ite_data *ip) 85 1.9 tsutsui { 86 1.13 tsutsui uint8_t *fbmem, *dp; 87 1.9 tsutsui int c, l, b; 88 1.9 tsutsui int stride, width; 89 1.9 tsutsui 90 1.13 tsutsui dp = (uint8_t *)(getword(ip, getword(ip, FONTROM) + FONTADDR) + 91 1.13 tsutsui (uint8_t *)ip->regbase) + FONTDATA; 92 1.9 tsutsui stride = ip->fbwidth >> 3; 93 1.9 tsutsui width = (ip->ftwidth + 7) / 8; 94 1.9 tsutsui 95 1.9 tsutsui for (c = 0; c < 128; c++) { 96 1.13 tsutsui fbmem = (uint8_t *)FBBASE + 97 1.10 tsutsui (ip->fonty + (c / ip->cpl) * ip->ftheight) * stride; 98 1.9 tsutsui fbmem += (ip->fontx >> 3) + (c % ip->cpl) * width; 99 1.9 tsutsui for (l = 0; l < ip->ftheight; l++) { 100 1.9 tsutsui for (b = 0; b < width; b++) { 101 1.9 tsutsui *fbmem++ = *dp; 102 1.9 tsutsui dp += 2; 103 1.9 tsutsui } 104 1.9 tsutsui fbmem -= width; 105 1.9 tsutsui fbmem += stride; 106 1.9 tsutsui } 107 1.9 tsutsui } 108 1.9 tsutsui } 109 1.9 tsutsui 110 1.9 tsutsui void 111 1.9 tsutsui ite_fontinit8bpp(struct ite_data *ip) 112 1.1 thorpej { 113 1.1 thorpej int bytewidth = (((ip->ftwidth - 1) / 8) + 1); 114 1.1 thorpej int glyphsize = bytewidth * ip->ftheight; 115 1.13 tsutsui uint8_t fontbuf[500]; 116 1.13 tsutsui uint8_t *dp, *fbmem; 117 1.1 thorpej int c, i, romp; 118 1.1 thorpej 119 1.1 thorpej romp = getword(ip, getword(ip, FONTROM) + FONTADDR) + FONTDATA; 120 1.1 thorpej for (c = 0; c < 128; c++) { 121 1.13 tsutsui fbmem = (uint8_t *)(FBBASE + 122 1.1 thorpej (ip->fonty + (c / ip->cpl) * ip->ftheight) * ip->fbwidth + 123 1.1 thorpej (ip->fontx + (c % ip->cpl) * ip->ftwidth)); 124 1.1 thorpej dp = fontbuf; 125 1.1 thorpej for (i = 0; i < glyphsize; i++) { 126 1.1 thorpej *dp++ = getbyte(ip, romp); 127 1.1 thorpej romp += 2; 128 1.1 thorpej } 129 1.8 tsutsui ite_writeglyph(ip, fbmem, fontbuf); 130 1.1 thorpej } 131 1.1 thorpej } 132 1.1 thorpej 133 1.8 tsutsui static void 134 1.13 tsutsui ite_writeglyph(struct ite_data *ip, uint8_t *fbmem, uint8_t *glyphp) 135 1.1 thorpej { 136 1.3 tsutsui int bn; 137 1.3 tsutsui int l, b; 138 1.1 thorpej 139 1.1 thorpej for (l = 0; l < ip->ftheight; l++) { 140 1.1 thorpej bn = 7; 141 1.1 thorpej for (b = 0; b < ip->ftwidth; b++) { 142 1.1 thorpej if ((1 << bn) & *glyphp) 143 1.1 thorpej *fbmem++ = 1; 144 1.1 thorpej else 145 1.1 thorpej *fbmem++ = 0; 146 1.1 thorpej if (--bn < 0) { 147 1.1 thorpej bn = 7; 148 1.1 thorpej glyphp++; 149 1.1 thorpej } 150 1.1 thorpej } 151 1.1 thorpej if (bn < 7) 152 1.1 thorpej glyphp++; 153 1.1 thorpej fbmem -= ip->ftwidth; 154 1.1 thorpej fbmem += ip->fbwidth; 155 1.1 thorpej } 156 1.1 thorpej } 157 1.10 tsutsui 158 1.10 tsutsui /* 159 1.10 tsutsui * The cursor is just an inverted space. 160 1.10 tsutsui */ 161 1.10 tsutsui #define flip_cursor(ip) \ 162 1.10 tsutsui (*ip->bmv)(ip, ip->cblanky, ip->cblankx, ip->cursory * ip->ftheight, \ 163 1.10 tsutsui ip->cursorx * ip->ftwidth, ip->ftheight, ip->ftwidth, RR_XOR) 164 1.10 tsutsui 165 1.10 tsutsui void 166 1.10 tsutsui ite_dio_cursor(struct ite_data *ip, int flag) 167 1.10 tsutsui { 168 1.10 tsutsui 169 1.10 tsutsui switch (flag) { 170 1.10 tsutsui case MOVE_CURSOR: 171 1.10 tsutsui flip_cursor(ip); 172 1.10 tsutsui /* FALLTHROUGH */ 173 1.10 tsutsui case DRAW_CURSOR: 174 1.10 tsutsui ip->cursorx = ip->curx; 175 1.10 tsutsui ip->cursory = ip->cury; 176 1.10 tsutsui /* FALLTHROUGH */ 177 1.12 tsutsui case ERASE_CURSOR: 178 1.10 tsutsui default: 179 1.10 tsutsui flip_cursor(ip); 180 1.10 tsutsui break; 181 1.10 tsutsui } 182 1.10 tsutsui } 183 1.10 tsutsui 184 1.10 tsutsui void 185 1.10 tsutsui ite_dio_putc1bpp(struct ite_data *ip, int c, int dy, int dx) 186 1.10 tsutsui { 187 1.10 tsutsui 188 1.10 tsutsui ite_dio_windowmove1bpp(ip, charY(ip, c), charX1bpp(ip, c), 189 1.10 tsutsui dy * ip->ftheight, dx * ip->ftwidth, 190 1.10 tsutsui ip->ftheight, ip->ftwidth, RR_COPY); 191 1.10 tsutsui } 192 1.10 tsutsui 193 1.10 tsutsui void 194 1.10 tsutsui ite_dio_putc8bpp(struct ite_data *ip, int c, int dy, int dx) 195 1.10 tsutsui { 196 1.10 tsutsui 197 1.10 tsutsui (*ip->bmv)(ip, charY(ip, c), charX(ip, c), 198 1.10 tsutsui dy * ip->ftheight, dx * ip->ftwidth, 199 1.10 tsutsui ip->ftheight, ip->ftwidth, RR_COPY); 200 1.10 tsutsui } 201 1.10 tsutsui 202 1.10 tsutsui void 203 1.10 tsutsui ite_dio_clear(struct ite_data *ip, int sy, int sx, int h, int w) 204 1.10 tsutsui { 205 1.10 tsutsui 206 1.10 tsutsui (*ip->bmv)(ip, sy * ip->ftheight, sx * ip->ftwidth, 207 1.10 tsutsui sy * ip->ftheight, sx * ip->ftwidth, 208 1.10 tsutsui h * ip->ftheight, w * ip->ftwidth, RR_CLEAR); 209 1.10 tsutsui } 210 1.10 tsutsui 211 1.10 tsutsui void 212 1.10 tsutsui ite_dio_scroll(struct ite_data *ip) 213 1.10 tsutsui { 214 1.10 tsutsui 215 1.10 tsutsui (*ip->bmv)(ip, ip->ftheight, 0, 0, 0, (ip->rows - 1) * ip->ftheight, 216 1.10 tsutsui ip->cols * ip->ftwidth, RR_COPY); 217 1.10 tsutsui } 218 1.10 tsutsui 219 1.10 tsutsui #include <hp300/stand/common/maskbits.h> 220 1.10 tsutsui 221 1.10 tsutsui /* NOTE: 222 1.10 tsutsui * the first element in starttab could be 0xffffffff. making it 0 223 1.10 tsutsui * lets us deal with a full first word in the middle loop, rather 224 1.10 tsutsui * than having to do the multiple reads and masks that we'd 225 1.10 tsutsui * have to do if we thought it was partial. 226 1.10 tsutsui */ 227 1.13 tsutsui static const uint32_t starttab[32] = { 228 1.10 tsutsui 0x00000000, 229 1.10 tsutsui 0x7FFFFFFF, 230 1.10 tsutsui 0x3FFFFFFF, 231 1.10 tsutsui 0x1FFFFFFF, 232 1.10 tsutsui 0x0FFFFFFF, 233 1.10 tsutsui 0x07FFFFFF, 234 1.10 tsutsui 0x03FFFFFF, 235 1.10 tsutsui 0x01FFFFFF, 236 1.10 tsutsui 0x00FFFFFF, 237 1.10 tsutsui 0x007FFFFF, 238 1.10 tsutsui 0x003FFFFF, 239 1.10 tsutsui 0x001FFFFF, 240 1.10 tsutsui 0x000FFFFF, 241 1.10 tsutsui 0x0007FFFF, 242 1.10 tsutsui 0x0003FFFF, 243 1.10 tsutsui 0x0001FFFF, 244 1.10 tsutsui 0x0000FFFF, 245 1.10 tsutsui 0x00007FFF, 246 1.10 tsutsui 0x00003FFF, 247 1.10 tsutsui 0x00001FFF, 248 1.10 tsutsui 0x00000FFF, 249 1.10 tsutsui 0x000007FF, 250 1.10 tsutsui 0x000003FF, 251 1.10 tsutsui 0x000001FF, 252 1.10 tsutsui 0x000000FF, 253 1.10 tsutsui 0x0000007F, 254 1.10 tsutsui 0x0000003F, 255 1.10 tsutsui 0x0000001F, 256 1.10 tsutsui 0x0000000F, 257 1.10 tsutsui 0x00000007, 258 1.10 tsutsui 0x00000003, 259 1.10 tsutsui 0x00000001 260 1.10 tsutsui }; 261 1.10 tsutsui 262 1.13 tsutsui static const uint32_t endtab[32] = { 263 1.10 tsutsui 0x00000000, 264 1.10 tsutsui 0x80000000, 265 1.10 tsutsui 0xC0000000, 266 1.10 tsutsui 0xE0000000, 267 1.10 tsutsui 0xF0000000, 268 1.10 tsutsui 0xF8000000, 269 1.10 tsutsui 0xFC000000, 270 1.10 tsutsui 0xFE000000, 271 1.10 tsutsui 0xFF000000, 272 1.10 tsutsui 0xFF800000, 273 1.10 tsutsui 0xFFC00000, 274 1.10 tsutsui 0xFFE00000, 275 1.10 tsutsui 0xFFF00000, 276 1.10 tsutsui 0xFFF80000, 277 1.10 tsutsui 0xFFFC0000, 278 1.10 tsutsui 0xFFFE0000, 279 1.10 tsutsui 0xFFFF0000, 280 1.10 tsutsui 0xFFFF8000, 281 1.10 tsutsui 0xFFFFC000, 282 1.10 tsutsui 0xFFFFE000, 283 1.10 tsutsui 0xFFFFF000, 284 1.10 tsutsui 0xFFFFF800, 285 1.10 tsutsui 0xFFFFFC00, 286 1.10 tsutsui 0xFFFFFE00, 287 1.10 tsutsui 0xFFFFFF00, 288 1.10 tsutsui 0xFFFFFF80, 289 1.10 tsutsui 0xFFFFFFC0, 290 1.10 tsutsui 0xFFFFFFE0, 291 1.10 tsutsui 0xFFFFFFF0, 292 1.10 tsutsui 0xFFFFFFF8, 293 1.10 tsutsui 0xFFFFFFFC, 294 1.10 tsutsui 0xFFFFFFFE 295 1.10 tsutsui }; 296 1.10 tsutsui 297 1.10 tsutsui void 298 1.10 tsutsui ite_dio_windowmove1bpp(struct ite_data *ip, int sy, int sx, int dy, int dx, 299 1.10 tsutsui int h, int w, int func) 300 1.10 tsutsui { 301 1.10 tsutsui int width; /* add to get to same position in next line */ 302 1.10 tsutsui 303 1.13 tsutsui uint32_t *psrcLine, *pdstLine; 304 1.10 tsutsui /* pointers to line with current src and dst */ 305 1.13 tsutsui uint32_t *psrc; /* pointer to current src longword */ 306 1.13 tsutsui uint32_t *pdst; /* pointer to current dst longword */ 307 1.10 tsutsui 308 1.10 tsutsui /* following used for looping through a line */ 309 1.13 tsutsui uint32_t startmask, endmask; /* masks for writing ends of dst */ 310 1.10 tsutsui int nlMiddle; /* whole longwords in dst */ 311 1.10 tsutsui int nl; /* temp copy of nlMiddle */ 312 1.13 tsutsui uint32_t tmpSrc; /* place to store full source word */ 313 1.10 tsutsui int xoffSrc; /* offset (>= 0, < 32) from which to 314 1.10 tsutsui fetch whole longwords fetched 315 1.10 tsutsui in src */ 316 1.10 tsutsui int nstart; /* number of ragged bits at start of dst */ 317 1.10 tsutsui int nend; /* number of ragged bits at end of dst */ 318 1.10 tsutsui int srcStartOver; /* pulling nstart bits from src 319 1.10 tsutsui overflows into the next word? */ 320 1.10 tsutsui 321 1.10 tsutsui if (h == 0 || w == 0) 322 1.10 tsutsui return; 323 1.10 tsutsui 324 1.10 tsutsui width = ip->fbwidth >> 5; 325 1.13 tsutsui psrcLine = ((uint32_t *)ip->fbbase) + (sy * width); 326 1.13 tsutsui pdstLine = ((uint32_t *)ip->fbbase) + (dy * width); 327 1.10 tsutsui 328 1.10 tsutsui /* x direction doesn't matter for < 1 longword */ 329 1.10 tsutsui if (w <= 32) { 330 1.10 tsutsui int srcBit, dstBit; /* bit offset of src and dst */ 331 1.10 tsutsui 332 1.10 tsutsui pdstLine += (dx >> 5); 333 1.10 tsutsui psrcLine += (sx >> 5); 334 1.10 tsutsui psrc = psrcLine; 335 1.10 tsutsui pdst = pdstLine; 336 1.10 tsutsui 337 1.10 tsutsui srcBit = sx & 0x1f; 338 1.10 tsutsui dstBit = dx & 0x1f; 339 1.10 tsutsui 340 1.13 tsutsui while (h-- > 0) { 341 1.10 tsutsui getandputrop(psrc, srcBit, dstBit, w, pdst, func); 342 1.10 tsutsui pdst += width; 343 1.10 tsutsui psrc += width; 344 1.10 tsutsui } 345 1.10 tsutsui } else { 346 1.10 tsutsui maskbits(dx, w, startmask, endmask, nlMiddle); 347 1.13 tsutsui if (startmask != 0) 348 1.10 tsutsui nstart = 32 - (dx & 0x1f); 349 1.10 tsutsui else 350 1.10 tsutsui nstart = 0; 351 1.13 tsutsui if (endmask != 0) 352 1.10 tsutsui nend = (dx + w) & 0x1f; 353 1.10 tsutsui else 354 1.10 tsutsui nend = 0; 355 1.10 tsutsui 356 1.10 tsutsui xoffSrc = ((sx & 0x1f) + nstart) & 0x1f; 357 1.10 tsutsui srcStartOver = ((sx & 0x1f) + nstart) > 31; 358 1.10 tsutsui 359 1.10 tsutsui pdstLine += (dx >> 5); 360 1.10 tsutsui psrcLine += (sx >> 5); 361 1.10 tsutsui 362 1.13 tsutsui while (h-- > 0) { 363 1.10 tsutsui psrc = psrcLine; 364 1.10 tsutsui pdst = pdstLine; 365 1.10 tsutsui 366 1.13 tsutsui if (startmask != 0) { 367 1.10 tsutsui getandputrop(psrc, (sx & 0x1f), (dx & 0x1f), 368 1.10 tsutsui nstart, pdst, func); 369 1.10 tsutsui pdst++; 370 1.13 tsutsui if (srcStartOver != 0) 371 1.10 tsutsui psrc++; 372 1.10 tsutsui } 373 1.10 tsutsui 374 1.10 tsutsui /* special case for aligned operations */ 375 1.10 tsutsui if (xoffSrc == 0) { 376 1.10 tsutsui nl = nlMiddle; 377 1.13 tsutsui while (nl-- > 0) { 378 1.10 tsutsui DoRop(*pdst, func, *psrc++, *pdst); 379 1.10 tsutsui pdst++; 380 1.10 tsutsui } 381 1.10 tsutsui } else { 382 1.10 tsutsui nl = nlMiddle + 1; 383 1.13 tsutsui while (--nl > 0) { 384 1.10 tsutsui getunalignedword(psrc, xoffSrc, tmpSrc); 385 1.10 tsutsui DoRop(*pdst, func, tmpSrc, *pdst); 386 1.10 tsutsui pdst++; 387 1.10 tsutsui psrc++; 388 1.10 tsutsui } 389 1.10 tsutsui } 390 1.10 tsutsui 391 1.13 tsutsui if (endmask != 0) { 392 1.10 tsutsui getandputrop0(psrc, xoffSrc, nend, pdst, func); 393 1.10 tsutsui } 394 1.10 tsutsui 395 1.10 tsutsui pdstLine += width; 396 1.10 tsutsui psrcLine += width; 397 1.10 tsutsui } 398 1.10 tsutsui } 399 1.10 tsutsui } 400 1.1 thorpej #endif 401