1*15805031Stsutsui /* $NetBSD: ite_dumb.c,v 1.2 2023/01/15 06:19:46 tsutsui Exp $ */
239666cb8Stsutsui
339666cb8Stsutsui /*-
439666cb8Stsutsui * Copyright (c) 2011 Izumi Tsutsui. All rights reserved.
539666cb8Stsutsui *
639666cb8Stsutsui * Redistribution and use in source and binary forms, with or without
739666cb8Stsutsui * modification, are permitted provided that the following conditions
839666cb8Stsutsui * are met:
939666cb8Stsutsui * 1. Redistributions of source code must retain the above copyright
1039666cb8Stsutsui * notice, this list of conditions and the following disclaimer.
1139666cb8Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
1239666cb8Stsutsui * notice, this list of conditions and the following disclaimer in the
1339666cb8Stsutsui * documentation and/or other materials provided with the distribution.
1439666cb8Stsutsui *
1539666cb8Stsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1639666cb8Stsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1739666cb8Stsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1839666cb8Stsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1939666cb8Stsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2039666cb8Stsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2139666cb8Stsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2239666cb8Stsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2339666cb8Stsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2439666cb8Stsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2539666cb8Stsutsui */
2639666cb8Stsutsui /*
2739666cb8Stsutsui * Copyright (c) 1988 University of Utah.
2839666cb8Stsutsui * Copyright (c) 1990, 1993
2939666cb8Stsutsui * The Regents of the University of California. All rights reserved.
3039666cb8Stsutsui *
3139666cb8Stsutsui * This code is derived from software contributed to Berkeley by
3239666cb8Stsutsui * the Systems Programming Group of the University of Utah Computer
3339666cb8Stsutsui * Science Department and Mark Davies of the Department of Computer
3439666cb8Stsutsui * Science, Victoria University of Wellington, New Zealand.
3539666cb8Stsutsui *
3639666cb8Stsutsui * Redistribution and use in source and binary forms, with or without
3739666cb8Stsutsui * modification, are permitted provided that the following conditions
3839666cb8Stsutsui * are met:
3939666cb8Stsutsui * 1. Redistributions of source code must retain the above copyright
4039666cb8Stsutsui * notice, this list of conditions and the following disclaimer.
4139666cb8Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
4239666cb8Stsutsui * notice, this list of conditions and the following disclaimer in the
4339666cb8Stsutsui * documentation and/or other materials provided with the distribution.
4439666cb8Stsutsui * 3. Neither the name of the University nor the names of its contributors
4539666cb8Stsutsui * may be used to endorse or promote products derived from this software
4639666cb8Stsutsui * without specific prior written permission.
4739666cb8Stsutsui *
4839666cb8Stsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
4939666cb8Stsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5039666cb8Stsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5139666cb8Stsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5239666cb8Stsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5339666cb8Stsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5439666cb8Stsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5539666cb8Stsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5639666cb8Stsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5739666cb8Stsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5839666cb8Stsutsui * SUCH DAMAGE.
5939666cb8Stsutsui *
6039666cb8Stsutsui * from: Utah $Hdr: ite_subr.c 1.2 92/01/20$
6139666cb8Stsutsui *
6239666cb8Stsutsui * @(#)ite_subr.c 8.1 (Berkeley) 6/10/93
6339666cb8Stsutsui */
6439666cb8Stsutsui
6539666cb8Stsutsui #ifdef ITECONSOLE
6639666cb8Stsutsui
6739666cb8Stsutsui #include <sys/param.h>
6839666cb8Stsutsui
6939666cb8Stsutsui #include <hp300/stand/common/samachdep.h>
7039666cb8Stsutsui #include <hp300/stand/common/itereg.h>
7139666cb8Stsutsui #include <hp300/stand/common/itevar.h>
7239666cb8Stsutsui
7339666cb8Stsutsui static void dumb_fontinit(struct ite_data *ip);
7439666cb8Stsutsui static void dumb_writeglyph(struct ite_data *, uint8_t *fbmem, uint8_t *);
7539666cb8Stsutsui static void dumb_flip_cursor(struct ite_data *ip);
7639666cb8Stsutsui static void dumb_windowmove(struct ite_data *, int, int, int, int, int, int,
7739666cb8Stsutsui int);
7839666cb8Stsutsui
7939666cb8Stsutsui static uint8_t *font;
8039666cb8Stsutsui
8139666cb8Stsutsui void
dumb_init(struct ite_data * ip)8239666cb8Stsutsui dumb_init(struct ite_data *ip)
8339666cb8Stsutsui {
8439666cb8Stsutsui
8539666cb8Stsutsui ip->bmv = dumb_windowmove; /* unused */
8639666cb8Stsutsui ite_fontinfo(ip);
8739666cb8Stsutsui dumb_clear(ip, 0, 0, ip->rows, ip->cols);
8839666cb8Stsutsui dumb_fontinit(ip);
8939666cb8Stsutsui }
9039666cb8Stsutsui
9139666cb8Stsutsui static void
dumb_fontinit(struct ite_data * ip)9239666cb8Stsutsui dumb_fontinit(struct ite_data *ip)
9339666cb8Stsutsui {
9439666cb8Stsutsui int bytewidth = (((ip->ftwidth - 1) / 8) + 1);
9539666cb8Stsutsui int glyphsize = bytewidth * ip->ftheight;
9639666cb8Stsutsui uint8_t fontbuf[500];
9739666cb8Stsutsui uint8_t *dp, *fontp;
9839666cb8Stsutsui int c, i, romp;
9939666cb8Stsutsui
10039666cb8Stsutsui /*
10139666cb8Stsutsui * We don't bother to copy font glyph into fbmem
10239666cb8Stsutsui * since there is no hardware windowmove ops.
10339666cb8Stsutsui * Prepare font data into contiguous memory instead.
10439666cb8Stsutsui */
10539666cb8Stsutsui font = alloc((ip->ftwidth * ip->ftheight) * 128);
10639666cb8Stsutsui romp = getword(ip, getword(ip, FONTROM) + FONTADDR) + FONTDATA;
10739666cb8Stsutsui
10839666cb8Stsutsui for (c = 0; c < 128; c++) {
10939666cb8Stsutsui /* get font glyph from FONTROM */
11039666cb8Stsutsui dp = fontbuf;
11139666cb8Stsutsui for (i = 0; i < glyphsize; i++) {
11239666cb8Stsutsui *dp++ = getbyte(ip, romp);
11339666cb8Stsutsui romp += 2;
11439666cb8Stsutsui }
11539666cb8Stsutsui
11639666cb8Stsutsui /* setup font data for 8bpp fbmem */
11739666cb8Stsutsui fontp = &font[(ip->ftwidth * ip->ftheight) * c];
11839666cb8Stsutsui dumb_writeglyph(ip, fontp, fontbuf);
11939666cb8Stsutsui }
12039666cb8Stsutsui }
12139666cb8Stsutsui
12239666cb8Stsutsui static void
dumb_writeglyph(struct ite_data * ip,uint8_t * fontmem,uint8_t * glyphp)12339666cb8Stsutsui dumb_writeglyph(struct ite_data *ip, uint8_t *fontmem, uint8_t *glyphp)
12439666cb8Stsutsui {
12539666cb8Stsutsui int bn;
12639666cb8Stsutsui int b, l;
12739666cb8Stsutsui
12839666cb8Stsutsui for (l = 0; l < ip->ftheight; l++) {
12939666cb8Stsutsui bn = 7;
13039666cb8Stsutsui for (b = 0; b < ip->ftwidth; b++) {
13139666cb8Stsutsui if ((1 << bn) & *glyphp)
13239666cb8Stsutsui *fontmem++ = 0x01;
13339666cb8Stsutsui else
13439666cb8Stsutsui *fontmem++ = 0x00;
13539666cb8Stsutsui if (--bn < 0) {
13639666cb8Stsutsui bn = 7;
13739666cb8Stsutsui glyphp++;
13839666cb8Stsutsui }
13939666cb8Stsutsui }
14039666cb8Stsutsui if (bn < 7)
14139666cb8Stsutsui glyphp++;
14239666cb8Stsutsui }
14339666cb8Stsutsui }
14439666cb8Stsutsui
14539666cb8Stsutsui static void
dumb_flip_cursor(struct ite_data * ip)14639666cb8Stsutsui dumb_flip_cursor(struct ite_data *ip)
14739666cb8Stsutsui {
14839666cb8Stsutsui int l, w;
14939666cb8Stsutsui uint8_t *pc;
15039666cb8Stsutsui uint32_t *pc32;
15139666cb8Stsutsui
15239666cb8Stsutsui pc = (uint8_t *)ip->fbbase +
15339666cb8Stsutsui ((ip->ftheight * ip->cursory) * ip->fbwidth) +
15439666cb8Stsutsui ip->ftwidth * ip->cursorx;
15539666cb8Stsutsui
15639666cb8Stsutsui for (l = 0; l < ip->ftheight; l++) {
15739666cb8Stsutsui /* assume (ip->ftwidth % sizeof(uint32_t) == 0) */
15839666cb8Stsutsui pc32 = (uint32_t *)pc;
15939666cb8Stsutsui for (w = 0; w < ip->ftwidth / sizeof(uint32_t); w++)
16039666cb8Stsutsui pc32[w] ^= 0x01010101;
16139666cb8Stsutsui pc += ip->fbwidth;
16239666cb8Stsutsui }
16339666cb8Stsutsui }
16439666cb8Stsutsui
16539666cb8Stsutsui void
dumb_cursor(struct ite_data * ip,int flag)16639666cb8Stsutsui dumb_cursor(struct ite_data *ip, int flag)
16739666cb8Stsutsui {
16839666cb8Stsutsui
16939666cb8Stsutsui switch (flag) {
17039666cb8Stsutsui case MOVE_CURSOR:
17139666cb8Stsutsui dumb_flip_cursor(ip);
17239666cb8Stsutsui /* FALLTHROUGH */
17339666cb8Stsutsui case DRAW_CURSOR:
17439666cb8Stsutsui ip->cursorx = ip->curx;
17539666cb8Stsutsui ip->cursory = ip->cury;
17639666cb8Stsutsui /* FALLTHROUGH */
17739666cb8Stsutsui default:
17839666cb8Stsutsui dumb_flip_cursor(ip);
17939666cb8Stsutsui break;
18039666cb8Stsutsui }
18139666cb8Stsutsui }
18239666cb8Stsutsui
18339666cb8Stsutsui void
dumb_putc(struct ite_data * ip,int c,int dy,int dx)18439666cb8Stsutsui dumb_putc(struct ite_data *ip, int c, int dy, int dx)
18539666cb8Stsutsui {
18639666cb8Stsutsui int l, w;
18739666cb8Stsutsui uint8_t *pc;
18839666cb8Stsutsui uint32_t *pc32;
18939666cb8Stsutsui uint32_t *fontp;
19039666cb8Stsutsui
19139666cb8Stsutsui pc = (uint8_t *)ip->fbbase +
19239666cb8Stsutsui ((ip->ftheight * ip->cursory) * ip->fbwidth) +
19339666cb8Stsutsui ip->ftwidth * ip->cursorx;
19439666cb8Stsutsui fontp = (uint32_t *)&font[(ip->ftwidth * ip->ftheight) * c];
19539666cb8Stsutsui
19639666cb8Stsutsui for (l = 0; l < ip->ftheight; l++) {
19739666cb8Stsutsui /* assume (ip->ftwidth % sizeof(uint32_t) == 0) */
19839666cb8Stsutsui pc32 = (uint32_t *)pc;
19939666cb8Stsutsui for (w = 0; w < ip->ftwidth / sizeof(uint32_t); w++)
20039666cb8Stsutsui pc32[w] = *fontp++;
20139666cb8Stsutsui pc += ip->fbwidth;
20239666cb8Stsutsui }
20339666cb8Stsutsui }
20439666cb8Stsutsui
20539666cb8Stsutsui void
dumb_clear(struct ite_data * ip,int sy,int sx,int h,int w)20639666cb8Stsutsui dumb_clear(struct ite_data *ip, int sy, int sx, int h, int w)
20739666cb8Stsutsui {
20839666cb8Stsutsui int l;
20939666cb8Stsutsui uint8_t *pdst;
21039666cb8Stsutsui
21139666cb8Stsutsui pdst = (uint8_t *)ip->fbbase +
21239666cb8Stsutsui ((ip->ftheight * sy) * ip->fbwidth) + ip->ftwidth * sx;
21339666cb8Stsutsui
21439666cb8Stsutsui for (l = 0; l < ip->ftheight * h; l++) {
21539666cb8Stsutsui /* slow, but just works */
21639666cb8Stsutsui memset(pdst, 0, ip->ftwidth * w);
21739666cb8Stsutsui pdst += ip->fbwidth;
21839666cb8Stsutsui }
21939666cb8Stsutsui }
22039666cb8Stsutsui
22139666cb8Stsutsui void
dumb_scroll(struct ite_data * ip)22239666cb8Stsutsui dumb_scroll(struct ite_data *ip)
22339666cb8Stsutsui {
22439666cb8Stsutsui int l, h, w;
22539666cb8Stsutsui uint8_t *psrc, *pdst;
22639666cb8Stsutsui
22739666cb8Stsutsui dumb_flip_cursor(ip);
22839666cb8Stsutsui
22939666cb8Stsutsui psrc = (uint8_t *)ip->fbbase + (ip->ftheight * ip->fbwidth);
23039666cb8Stsutsui pdst = (uint8_t *)ip->fbbase;
23139666cb8Stsutsui
23239666cb8Stsutsui h = (ip->rows - 1) * ip->ftheight;
23339666cb8Stsutsui w = ip->cols * ip->ftwidth;
23439666cb8Stsutsui
23539666cb8Stsutsui for (l = 0; l < h; l++) {
23639666cb8Stsutsui /* slow, but just works and no scroll if no retry */
23739666cb8Stsutsui memmove(pdst, psrc, w);
23839666cb8Stsutsui psrc += ip->fbwidth;
23939666cb8Stsutsui pdst += ip->fbwidth;
24039666cb8Stsutsui }
24139666cb8Stsutsui }
24239666cb8Stsutsui
24339666cb8Stsutsui static void
dumb_windowmove(struct ite_data * ip,int sy,int sx,int dy,int dx,int w,int h,int func)24439666cb8Stsutsui dumb_windowmove(struct ite_data *ip, int sy, int sx, int dy, int dx,
24539666cb8Stsutsui int w, int h, int func)
24639666cb8Stsutsui {
24739666cb8Stsutsui
24839666cb8Stsutsui /* for sanity check */
24939666cb8Stsutsui printf("%s: called\n", __func__);
25039666cb8Stsutsui }
25139666cb8Stsutsui #endif
252