Home | History | Annotate | Line # | Download | only in boot
      1  1.10   andvar /*	$NetBSD: bmd.c,v 1.10 2024/07/05 19:28:36 andvar Exp $	*/
      2   1.1  tsutsui 
      3   1.1  tsutsui /*
      4   1.1  tsutsui  * Copyright (c) 1992 OMRON Corporation.
      5   1.1  tsutsui  *
      6   1.1  tsutsui  * This code is derived from software contributed to Berkeley by
      7   1.1  tsutsui  * OMRON Corporation.
      8   1.1  tsutsui  *
      9   1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
     10   1.1  tsutsui  * modification, are permitted provided that the following conditions
     11   1.1  tsutsui  * are met:
     12   1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     13   1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     14   1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     16   1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     17   1.1  tsutsui  * 3. All advertising materials mentioning features or use of this software
     18   1.1  tsutsui  *    must display the following acknowledgement:
     19   1.1  tsutsui  *	This product includes software developed by the University of
     20   1.1  tsutsui  *	California, Berkeley and its contributors.
     21   1.1  tsutsui  * 4. Neither the name of the University nor the names of its contributors
     22   1.1  tsutsui  *    may be used to endorse or promote products derived from this software
     23   1.1  tsutsui  *    without specific prior written permission.
     24   1.1  tsutsui  *
     25   1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26   1.1  tsutsui  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27   1.1  tsutsui  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28   1.1  tsutsui  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29   1.1  tsutsui  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30   1.1  tsutsui  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31   1.1  tsutsui  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32   1.1  tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33   1.1  tsutsui  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34   1.1  tsutsui  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35   1.1  tsutsui  * SUCH DAMAGE.
     36   1.1  tsutsui  *
     37   1.1  tsutsui  *	@(#)bmd.c	8.2 (Berkeley) 8/15/93
     38   1.1  tsutsui  */
     39   1.1  tsutsui /*
     40   1.1  tsutsui  * Copyright (c) 1992, 1993
     41   1.1  tsutsui  *	The Regents of the University of California.  All rights reserved.
     42   1.1  tsutsui  *
     43   1.1  tsutsui  * This code is derived from software contributed to Berkeley by
     44   1.1  tsutsui  * OMRON Corporation.
     45   1.1  tsutsui  *
     46   1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
     47   1.1  tsutsui  * modification, are permitted provided that the following conditions
     48   1.1  tsutsui  * are met:
     49   1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     50   1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     51   1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     52   1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     53   1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     54   1.1  tsutsui  * 3. Neither the name of the University nor the names of its contributors
     55   1.1  tsutsui  *    may be used to endorse or promote products derived from this software
     56   1.1  tsutsui  *    without specific prior written permission.
     57   1.1  tsutsui  *
     58   1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59   1.1  tsutsui  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60   1.1  tsutsui  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61   1.1  tsutsui  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62   1.1  tsutsui  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63   1.1  tsutsui  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64   1.1  tsutsui  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65   1.1  tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66   1.1  tsutsui  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67   1.1  tsutsui  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68   1.1  tsutsui  * SUCH DAMAGE.
     69   1.1  tsutsui  *
     70   1.1  tsutsui  *	@(#)bmd.c	8.2 (Berkeley) 8/15/93
     71   1.1  tsutsui  */
     72   1.1  tsutsui /*
     73   1.1  tsutsui 
     74   1.1  tsutsui  * bmd.c --- Bitmap-Display raw-level driver routines
     75   1.1  tsutsui  *
     76   1.1  tsutsui  *	by A.Fujita, SEP-09-1992
     77   1.1  tsutsui  */
     78   1.1  tsutsui 
     79   1.1  tsutsui 
     80   1.1  tsutsui #include <sys/param.h>
     81   1.1  tsutsui #include <luna68k/stand/boot/samachdep.h>
     82   1.8  tsutsui #include <machine/board.h>
     83   1.1  tsutsui 
     84   1.1  tsutsui /*
     85   1.1  tsutsui  *  RFCNT register
     86   1.1  tsutsui  */
     87   1.1  tsutsui 
     88   1.1  tsutsui union bmd_rfcnt {
     89   1.1  tsutsui 	struct {
     90   1.5  tsutsui 		int16_t	rfc_hcnt;
     91   1.5  tsutsui 		int16_t	rfc_vcnt;
     92   1.1  tsutsui 	} p;
     93   1.1  tsutsui 	uint32_t u;
     94   1.1  tsutsui };
     95   1.1  tsutsui 
     96   1.3  tsutsui #define isprint(c)	((c) >= 0x20 && (c) < 0x7f)
     97   1.1  tsutsui 
     98   1.1  tsutsui /*
     99   1.3  tsutsui  *  Width & Height
    100   1.1  tsutsui  */
    101   1.1  tsutsui 
    102   1.8  tsutsui #define BMAP_OFFSET	8
    103   1.8  tsutsui 
    104   1.3  tsutsui #define PB_WIDTH	2048			/* Plane Width   (Bit) */
    105  1.10   andvar #define PB_HEIGHT	1024			/* Plane Height  (Bit) */
    106   1.3  tsutsui #define PL_WIDTH	64			/* Plane Width  (long) */
    107   1.3  tsutsui #define PS_WIDTH	128			/* Plane Width  (long) */
    108   1.3  tsutsui #define P_WIDTH		256			/* Plane Width  (Byte) */
    109   1.1  tsutsui 
    110   1.3  tsutsui #define SB_WIDTH	1280			/* Screen Width  (Bit) */
    111  1.10   andvar #define SB_HEIGHT	1024			/* Screen Height (Bit) */
    112   1.3  tsutsui #define SL_WIDTH	40			/* Screen Width (Long) */
    113   1.3  tsutsui #define S_WIDTH		160			/* Screen Width (Byte) */
    114   1.1  tsutsui 
    115   1.3  tsutsui #define FB_WIDTH	12			/* Font Width    (Bit) */
    116  1.10   andvar #define FB_HEIGHT	20			/* Font Height   (Bit) */
    117   1.1  tsutsui 
    118   1.1  tsutsui 
    119   1.4  tsutsui #define NEXT_LINE(addr)			(addr +  (PL_WIDTH * FB_HEIGHT))
    120   1.4  tsutsui #define SKIP_NEXT_LINE(addr)		(addr += (PL_WIDTH - SL_WIDTH))
    121   1.1  tsutsui 
    122   1.1  tsutsui 
    123   1.7  tsutsui static void	bmd_draw_char(uint8_t *, uint8_t *, int, int, int);
    124   1.7  tsutsui static void	bmd_reverse_char(uint8_t *, uint8_t *, int, int);
    125   1.7  tsutsui static void	bmd_erase_char(uint8_t *, uint8_t *, int, int);
    126   1.7  tsutsui static void	bmd_erase_screen(volatile uint32_t *);
    127   1.7  tsutsui static void	bmd_scroll_screen(volatile uint32_t *, volatile uint32_t *,
    128   1.7  tsutsui 		    int, int, int, int);
    129   1.1  tsutsui 
    130   1.1  tsutsui 
    131   1.1  tsutsui struct bmd_linec {
    132   1.1  tsutsui 	struct bmd_linec *bl_next;
    133   1.1  tsutsui 	struct bmd_linec *bl_prev;
    134   1.1  tsutsui 	int	bl_col;
    135   1.1  tsutsui 	int	bl_end;
    136   1.5  tsutsui 	uint8_t	bl_line[128];
    137   1.1  tsutsui };
    138   1.1  tsutsui 
    139   1.1  tsutsui struct bmd_softc {
    140   1.1  tsutsui 	int	bc_stat;
    141   1.5  tsutsui 	uint8_t *bc_raddr;
    142   1.5  tsutsui 	uint8_t *bc_waddr;
    143   1.1  tsutsui 	int	bc_xmin;
    144   1.1  tsutsui 	int	bc_xmax;
    145   1.1  tsutsui 	int	bc_ymin;
    146   1.1  tsutsui 	int	bc_ymax;
    147   1.1  tsutsui 	int	bc_col;
    148   1.1  tsutsui 	int	bc_row;
    149   1.1  tsutsui 	struct bmd_linec *bc_bl;
    150   1.1  tsutsui 	char	bc_escseq[8];
    151   1.1  tsutsui 	char   *bc_esc;
    152   1.1  tsutsui 	void  (*bc_escape)(int);
    153   1.1  tsutsui };
    154   1.1  tsutsui 
    155   1.3  tsutsui #define STAT_NORMAL	0x0000
    156   1.3  tsutsui #define STAT_ESCAPE	0x0001
    157   1.3  tsutsui #define STAT_INSERT	0x0100
    158   1.1  tsutsui 
    159   1.7  tsutsui static struct	bmd_softc bmd_softc;
    160   1.7  tsutsui static struct	bmd_linec bmd_linec[52];
    161   1.1  tsutsui 
    162   1.7  tsutsui static void	bmd_escape(int);
    163   1.7  tsutsui static void	bmd_escape_0(int);
    164   1.7  tsutsui #if 0
    165   1.7  tsutsui static void	bmd_escape_1(int);
    166   1.7  tsutsui #endif
    167   1.1  tsutsui 
    168   1.1  tsutsui 
    169   1.1  tsutsui /*
    170   1.1  tsutsui  * Escape-Sequence
    171   1.1  tsutsui  */
    172   1.1  tsutsui 
    173   1.7  tsutsui static void
    174   1.1  tsutsui bmd_escape(int c)
    175   1.1  tsutsui {
    176   1.1  tsutsui 	struct bmd_softc *bp = &bmd_softc;
    177   1.1  tsutsui 
    178   1.1  tsutsui 	switch (c) {
    179   1.1  tsutsui 
    180   1.1  tsutsui 	case '[':
    181   1.1  tsutsui 		bp->bc_escape = bmd_escape_0;
    182   1.1  tsutsui 		break;
    183   1.1  tsutsui 
    184   1.1  tsutsui 	default:
    185   1.1  tsutsui 		bp->bc_stat &= ~STAT_ESCAPE;
    186   1.1  tsutsui 		bp->bc_esc = &bp->bc_escseq[0];
    187   1.1  tsutsui 		bp->bc_escape = bmd_escape;
    188   1.1  tsutsui 		break;
    189   1.1  tsutsui 	}
    190   1.1  tsutsui }
    191   1.1  tsutsui 
    192   1.7  tsutsui static void
    193   1.1  tsutsui bmd_escape_0(int c)
    194   1.1  tsutsui {
    195   1.1  tsutsui 	struct bmd_softc *bp = &bmd_softc;
    196   1.1  tsutsui 	struct bmd_linec *bq = bp->bc_bl;
    197   1.1  tsutsui 
    198   1.1  tsutsui 	switch (c) {
    199   1.1  tsutsui 
    200   1.1  tsutsui 	case 'A':
    201   1.1  tsutsui 		if (bp->bc_row > bp->bc_ymin) {
    202   1.1  tsutsui 			bp->bc_row--;
    203   1.1  tsutsui 		}
    204   1.1  tsutsui 		break;
    205   1.1  tsutsui 
    206   1.1  tsutsui 	case 'C':
    207   1.1  tsutsui 		if (bq->bl_col < bp->bc_xmax - 1) {
    208   1.1  tsutsui 			bq->bl_col++;
    209   1.1  tsutsui 		}
    210   1.1  tsutsui 		break;
    211   1.1  tsutsui 
    212   1.1  tsutsui 	case 'K':
    213   1.1  tsutsui 		if (bq->bl_col < bp->bc_xmax) {
    214   1.1  tsutsui 			int col;
    215   1.1  tsutsui 			for (col = bq->bl_col; col < bp->bc_xmax; col++)
    216   1.1  tsutsui 				bmd_erase_char(bp->bc_raddr,
    217   1.1  tsutsui 					       bp->bc_waddr,
    218   1.1  tsutsui 					       col, bp->bc_row);
    219   1.1  tsutsui 		}
    220   1.1  tsutsui 		bq->bl_end = bq->bl_col;
    221   1.1  tsutsui 		break;
    222   1.1  tsutsui 
    223   1.1  tsutsui 	case 'H':
    224   1.1  tsutsui 		bq->bl_col = bq->bl_end = bp->bc_xmin;
    225   1.1  tsutsui 		bp->bc_row = bp->bc_ymin;
    226   1.1  tsutsui 		break;
    227   1.1  tsutsui 
    228   1.1  tsutsui 	default:
    229   1.3  tsutsui #if 0
    230   1.1  tsutsui 		*bp->bc_esc++ = c;
    231   1.1  tsutsui 		bp->bc_escape = bmd_escape_1;
    232   1.1  tsutsui 		return;
    233   1.3  tsutsui #endif
    234   1.1  tsutsui 		break;
    235   1.1  tsutsui 	}
    236   1.1  tsutsui 
    237   1.1  tsutsui 	bp->bc_stat &= ~STAT_ESCAPE;
    238   1.1  tsutsui 	bp->bc_esc = &bp->bc_escseq[0];
    239   1.1  tsutsui 	bp->bc_escape = bmd_escape;
    240   1.1  tsutsui }
    241   1.1  tsutsui 
    242   1.7  tsutsui #if 0
    243   1.7  tsutsui static void
    244   1.1  tsutsui bmd_escape_1(int c)
    245   1.1  tsutsui {
    246   1.1  tsutsui 	struct bmd_softc *bp = &bmd_softc;
    247   1.1  tsutsui 	struct bmd_linec *bq = bp->bc_bl;
    248   1.1  tsutsui 	int col = 0, row = 0;
    249   1.1  tsutsui 	char *p;
    250   1.1  tsutsui 
    251   1.1  tsutsui 	switch (c) {
    252   1.1  tsutsui 
    253   1.1  tsutsui 	case 'J':
    254   1.1  tsutsui 		bp->bc_stat &= ~STAT_ESCAPE;
    255   1.1  tsutsui 		bp->bc_esc = &bp->bc_escseq[0];
    256   1.1  tsutsui 		bp->bc_escape = bmd_escape;
    257   1.1  tsutsui 		break;
    258   1.1  tsutsui 
    259   1.1  tsutsui 	case 'H':
    260   1.1  tsutsui 		for (p = &bp->bc_escseq[0]; *p != ';'; p++)
    261   1.1  tsutsui 			row = (row * 10) + (*p - 0x30);
    262   1.1  tsutsui 		p++;
    263   1.1  tsutsui 		for (p = &bp->bc_escseq[0]; p != bp->bc_esc; p++)
    264   1.1  tsutsui 			col = (col * 10) + (*p - 0x30);
    265   1.1  tsutsui 
    266   1.1  tsutsui 		bq->bl_col = col + bp->bc_xmin;
    267   1.1  tsutsui 		bp->bc_row = row + bp->bc_ymin;
    268   1.1  tsutsui 
    269   1.1  tsutsui 		bp->bc_stat &= ~STAT_ESCAPE;
    270   1.1  tsutsui 		bp->bc_esc = &bp->bc_escseq[0];
    271   1.1  tsutsui 		bp->bc_escape = bmd_escape;
    272   1.1  tsutsui 		break;
    273   1.1  tsutsui 
    274   1.1  tsutsui 	default:
    275   1.1  tsutsui 		*bp->bc_esc++ = c;
    276   1.1  tsutsui 		break;
    277   1.1  tsutsui 	}
    278   1.1  tsutsui }
    279   1.7  tsutsui #endif
    280   1.1  tsutsui 
    281   1.1  tsutsui /*
    282   1.1  tsutsui  * Entry Routine
    283   1.1  tsutsui  */
    284   1.1  tsutsui 
    285   1.1  tsutsui void
    286   1.1  tsutsui bmdinit(void)
    287   1.1  tsutsui {
    288   1.8  tsutsui 	volatile uint32_t *bmd_rfcnt = (uint32_t *)BMAP_RFCNT;
    289   1.8  tsutsui 	volatile uint32_t *bmd_bmsel = (uint32_t *)BMAP_BMSEL;
    290   1.1  tsutsui 	struct bmd_softc *bp = &bmd_softc;
    291   1.1  tsutsui 	struct bmd_linec *bq;
    292   1.1  tsutsui 	int i;
    293   1.1  tsutsui 	union bmd_rfcnt rfcnt;
    294   1.1  tsutsui 
    295   1.1  tsutsui 	/*
    296   1.1  tsutsui 	 *  adjust plane position
    297   1.1  tsutsui 	 */
    298   1.1  tsutsui 
    299   1.6  tsutsui 	/* plane-0 hardware address */
    300   1.8  tsutsui 	bp->bc_raddr = (uint8_t *)(BMAP_BMAP0 + BMAP_OFFSET);
    301   1.6  tsutsui 	/* common bitmap hardware address */
    302   1.8  tsutsui 	bp->bc_waddr = (uint8_t *)(BMAP_BMP   + BMAP_OFFSET);
    303   1.6  tsutsui 
    304   1.3  tsutsui 	rfcnt.p.rfc_hcnt = 7;			/* shift left   16 dot */
    305   1.3  tsutsui 	rfcnt.p.rfc_vcnt = -27;			/* shift down    1 dot */
    306   1.1  tsutsui 	*bmd_rfcnt = rfcnt.u;
    307   1.1  tsutsui 
    308   1.1  tsutsui 	bp->bc_stat  = STAT_NORMAL;
    309   1.1  tsutsui 
    310   1.1  tsutsui 	bp->bc_xmin  = 8;
    311   1.1  tsutsui 	bp->bc_xmax  = 96;
    312   1.1  tsutsui 	bp->bc_ymin  = 2;
    313   1.1  tsutsui 	bp->bc_ymax  = 48;
    314   1.1  tsutsui 
    315   1.1  tsutsui 	bp->bc_row = bp->bc_ymin;
    316   1.1  tsutsui 
    317   1.1  tsutsui 	for (i = bp->bc_ymin; i < bp->bc_ymax; i++) {
    318   1.4  tsutsui 		bmd_linec[i].bl_next = &bmd_linec[i + 1];
    319   1.4  tsutsui 		bmd_linec[i].bl_prev = &bmd_linec[i - 1];
    320   1.1  tsutsui 	}
    321   1.4  tsutsui 	bmd_linec[bp->bc_ymax - 1].bl_next = &bmd_linec[bp->bc_ymin];
    322   1.4  tsutsui 	bmd_linec[bp->bc_ymin].bl_prev = &bmd_linec[bp->bc_ymax - 1];
    323   1.1  tsutsui 
    324   1.1  tsutsui 	bq = bp->bc_bl = &bmd_linec[bp->bc_ymin];
    325   1.1  tsutsui 	bq->bl_col = bq->bl_end = bp->bc_xmin;
    326   1.1  tsutsui 
    327   1.1  tsutsui 	bp->bc_col = bp->bc_xmin;
    328   1.1  tsutsui 
    329   1.1  tsutsui 	bp->bc_esc = &bp->bc_escseq[0];
    330   1.1  tsutsui 	bp->bc_escape = bmd_escape;
    331   1.1  tsutsui 
    332   1.1  tsutsui 	*bmd_bmsel = 0xff;				/* all planes */
    333   1.3  tsutsui 	bmd_erase_screen((uint32_t *)bp->bc_waddr);	/* clear screen */
    334   1.1  tsutsui 	*bmd_bmsel = 0x01;				/* 1 plane */
    335   1.1  tsutsui 
    336   1.6  tsutsui 	/* turn on cursor */
    337   1.1  tsutsui 	bmd_reverse_char(bp->bc_raddr,
    338   1.1  tsutsui 			 bp->bc_waddr,
    339   1.1  tsutsui 			 bq->bl_col, bp->bc_row);
    340   1.1  tsutsui }
    341   1.1  tsutsui 
    342   1.1  tsutsui void
    343   1.5  tsutsui bmdadjust(int16_t hcnt, int16_t vcnt)
    344   1.1  tsutsui {
    345   1.8  tsutsui 	volatile uint32_t *bmd_rfcnt = (uint32_t *)BMAP_RFCNT;
    346   1.1  tsutsui 	union bmd_rfcnt rfcnt;
    347   1.1  tsutsui 
    348   1.1  tsutsui 	printf("bmdadjust: hcnt = %d, vcnt = %d\n", hcnt, vcnt);
    349   1.1  tsutsui 
    350   1.1  tsutsui 	rfcnt.p.rfc_hcnt = hcnt;		/* shift left   16 dot */
    351   1.1  tsutsui 	rfcnt.p.rfc_vcnt = vcnt;		/* shift down    1 dot */
    352   1.1  tsutsui 
    353   1.1  tsutsui 	*bmd_rfcnt = rfcnt.u;
    354   1.1  tsutsui }
    355   1.1  tsutsui 
    356   1.1  tsutsui int
    357   1.1  tsutsui bmdputc(int c)
    358   1.1  tsutsui {
    359   1.1  tsutsui 	struct bmd_softc *bp = &bmd_softc;
    360   1.1  tsutsui 	struct bmd_linec *bq = bp->bc_bl;
    361   1.1  tsutsui 	int i;
    362   1.1  tsutsui 
    363   1.1  tsutsui 	c &= 0x7F;
    364   1.6  tsutsui 
    365   1.6  tsutsui 	/* turn off cursor */
    366   1.1  tsutsui 	bmd_reverse_char(bp->bc_raddr,
    367   1.1  tsutsui 			 bp->bc_waddr,
    368   1.1  tsutsui 			 bq->bl_col, bp->bc_row);
    369   1.6  tsutsui 
    370   1.6  tsutsui 	/* do escape-sequence */
    371   1.1  tsutsui 	if (bp->bc_stat & STAT_ESCAPE) {
    372   1.1  tsutsui 		*bp->bc_esc++ = c;
    373   1.1  tsutsui 		(*bp->bc_escape)(c);
    374   1.1  tsutsui 		goto done;
    375   1.1  tsutsui 	}
    376   1.1  tsutsui 
    377   1.1  tsutsui 	if (isprint(c)) {
    378   1.1  tsutsui 		bmd_draw_char(bp->bc_raddr, bp->bc_waddr,
    379   1.1  tsutsui 			      bq->bl_col, bp->bc_row, c);
    380   1.1  tsutsui 		bq->bl_col++;
    381   1.1  tsutsui 		bq->bl_end++;
    382   1.1  tsutsui 		if (bq->bl_col >= bp->bc_xmax) {
    383   1.1  tsutsui 			bq->bl_col = bq->bl_end = bp->bc_xmin;
    384   1.1  tsutsui 			bp->bc_row++;
    385   1.1  tsutsui 			if (bp->bc_row >= bp->bc_ymax) {
    386   1.3  tsutsui 				bmd_scroll_screen((uint32_t *)bp->bc_raddr,
    387   1.3  tsutsui 						  (uint32_t *)bp->bc_waddr,
    388   1.1  tsutsui 						  bp->bc_xmin, bp->bc_xmax,
    389   1.1  tsutsui 						  bp->bc_ymin, bp->bc_ymax);
    390   1.1  tsutsui 
    391   1.1  tsutsui 				bp->bc_row = bp->bc_ymax - 1;
    392   1.1  tsutsui 			}
    393   1.1  tsutsui 		}
    394   1.1  tsutsui 	} else {
    395   1.1  tsutsui 		switch (c) {
    396   1.1  tsutsui 		case 0x08:				/* BS */
    397   1.1  tsutsui 			if (bq->bl_col > bp->bc_xmin) {
    398   1.1  tsutsui 				bq->bl_col--;
    399   1.1  tsutsui 			}
    400   1.1  tsutsui 			break;
    401   1.1  tsutsui 
    402   1.1  tsutsui 		case 0x09:				/* HT */
    403   1.1  tsutsui 		case 0x0B:				/* VT */
    404   1.1  tsutsui 			i = ((bq->bl_col / 8) + 1) * 8;
    405   1.1  tsutsui 			if (i < bp->bc_xmax) {
    406   1.1  tsutsui 				bq->bl_col = bq->bl_end = i;
    407   1.1  tsutsui 			}
    408   1.1  tsutsui 			break;
    409   1.1  tsutsui 
    410   1.1  tsutsui 		case 0x0A:				/* NL */
    411   1.1  tsutsui 			bp->bc_row++;
    412   1.1  tsutsui 			if (bp->bc_row >= bp->bc_ymax) {
    413   1.3  tsutsui 				bmd_scroll_screen((uint32_t *)bp->bc_raddr,
    414   1.3  tsutsui 						  (uint32_t *)bp->bc_waddr,
    415   1.1  tsutsui 						  bp->bc_xmin, bp->bc_xmax,
    416   1.1  tsutsui 						  bp->bc_ymin, bp->bc_ymax);
    417   1.1  tsutsui 
    418   1.1  tsutsui 				bp->bc_row = bp->bc_ymax - 1;
    419   1.1  tsutsui 			}
    420   1.1  tsutsui 			break;
    421   1.1  tsutsui 
    422   1.1  tsutsui 		case 0x0D:				/* CR */
    423   1.1  tsutsui 			bq->bl_col = bp->bc_xmin;
    424   1.1  tsutsui 			break;
    425   1.1  tsutsui 
    426   1.6  tsutsui 		case 0x1B:				/* ESC */
    427   1.1  tsutsui 			bp->bc_stat |= STAT_ESCAPE;
    428   1.1  tsutsui 			*bp->bc_esc++ = 0x1b;
    429   1.1  tsutsui 			break;
    430   1.1  tsutsui 
    431   1.1  tsutsui 		case 0x7F:				/* DEL */
    432   1.1  tsutsui 			if (bq->bl_col > bp->bc_xmin) {
    433   1.1  tsutsui 				bq->bl_col--;
    434   1.1  tsutsui 				bmd_erase_char(bp->bc_raddr,
    435   1.1  tsutsui 					       bp->bc_waddr,
    436   1.1  tsutsui 					       bq->bl_col, bp->bc_row);
    437   1.1  tsutsui 			}
    438   1.1  tsutsui 			break;
    439   1.1  tsutsui 
    440   1.1  tsutsui 		default:
    441   1.1  tsutsui 			break;
    442   1.1  tsutsui 		}
    443   1.1  tsutsui 	}
    444   1.1  tsutsui 
    445   1.1  tsutsui  done:
    446   1.6  tsutsui 	/* turn on  cursor */
    447   1.1  tsutsui 	bmd_reverse_char(bp->bc_raddr,
    448   1.1  tsutsui 			 bp->bc_waddr,
    449   1.1  tsutsui 			 bq->bl_col, bp->bc_row);
    450   1.1  tsutsui 
    451   1.4  tsutsui 	return c;
    452   1.1  tsutsui }
    453   1.1  tsutsui 
    454   1.1  tsutsui void
    455   1.1  tsutsui bmdclear(void)
    456   1.1  tsutsui {
    457   1.1  tsutsui 	struct bmd_softc *bp = &bmd_softc;
    458   1.1  tsutsui 	struct bmd_linec *bq = bp->bc_bl;
    459   1.1  tsutsui 
    460   1.6  tsutsui 	/* clear screen */
    461   1.6  tsutsui 	bmd_erase_screen((uint32_t *)bp->bc_waddr);
    462   1.1  tsutsui 
    463   1.1  tsutsui 	bq->bl_col = bq->bl_end = bp->bc_xmin;
    464   1.1  tsutsui 	bp->bc_row = bp->bc_ymin;
    465   1.1  tsutsui 
    466   1.6  tsutsui 	/* turn on cursor */
    467   1.1  tsutsui 	bmd_reverse_char(bp->bc_raddr,
    468   1.1  tsutsui 			 bp->bc_waddr,
    469   1.6  tsutsui 			 bq->bl_col, bp->bc_row);
    470   1.1  tsutsui }
    471   1.1  tsutsui 
    472   1.1  tsutsui 
    473   1.1  tsutsui /*
    474   1.9  tsutsui  *  character operation routines
    475   1.1  tsutsui  */
    476   1.1  tsutsui 
    477   1.7  tsutsui static void
    478   1.5  tsutsui bmd_draw_char(uint8_t *raddr, uint8_t *waddr, int col, int row, int c)
    479   1.1  tsutsui {
    480   1.3  tsutsui 	volatile uint16_t *p, *q;
    481   1.3  tsutsui 	volatile uint32_t *lp, *lq;
    482   1.3  tsutsui 	const uint16_t *fp;
    483   1.1  tsutsui 	int i;
    484   1.1  tsutsui 
    485   1.1  tsutsui 	fp = &bmdfont[c][0];
    486   1.1  tsutsui 
    487   1.1  tsutsui 	switch (col % 4) {
    488   1.1  tsutsui 
    489   1.1  tsutsui 	case 0:
    490   1.3  tsutsui 		p = (uint16_t *)(raddr + ((row * FB_HEIGHT) << 8)
    491   1.3  tsutsui 		    + ((col / 4) * 6));
    492   1.3  tsutsui 		q = (uint16_t *)(waddr + ((row * FB_HEIGHT) << 8)
    493   1.3  tsutsui 		    + ((col / 4) * 6));
    494   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    495   1.1  tsutsui 			*q = (*p & 0x000F) | (*fp & 0xFFF0);
    496   1.1  tsutsui 			p += 128;
    497   1.1  tsutsui 			q += 128;
    498   1.1  tsutsui 			fp++;
    499   1.1  tsutsui 		}
    500   1.1  tsutsui 		break;
    501   1.1  tsutsui 
    502   1.1  tsutsui 	case 1:
    503   1.3  tsutsui 		lp = (uint32_t *)(raddr + ((row * FB_HEIGHT) << 8)
    504   1.3  tsutsui 		    + ((col / 4) * 6));
    505   1.3  tsutsui 		lq = (uint32_t *)(waddr + ((row * FB_HEIGHT) << 8)
    506   1.3  tsutsui 		    + ((col / 4) * 6));
    507   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    508   1.3  tsutsui 			*lq = (*lp & 0xFFF000FF) |
    509   1.3  tsutsui 			    ((uint32_t)(*fp & 0xFFF0) << 4);
    510   1.1  tsutsui 			lp += 64;
    511   1.1  tsutsui 			lq += 64;
    512   1.1  tsutsui 			fp++;
    513   1.1  tsutsui 		}
    514   1.1  tsutsui 		break;
    515   1.1  tsutsui 
    516   1.1  tsutsui 	case 2:
    517   1.3  tsutsui 		lp = (uint32_t *)(raddr + ((row * FB_HEIGHT) << 8)
    518   1.3  tsutsui 		    + ((col / 4) * 6) + 2);
    519   1.3  tsutsui 		lq = (uint32_t *)(waddr + ((row * FB_HEIGHT) << 8)
    520   1.3  tsutsui 		    + ((col / 4) * 6) + 2);
    521   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    522   1.3  tsutsui 			*lq = (*lp & 0xFF000FFF) |
    523   1.3  tsutsui 			    ((uint32_t)(*fp & 0xFFF0) << 8);
    524   1.1  tsutsui 			lp += 64;
    525   1.1  tsutsui 			lq += 64;
    526   1.1  tsutsui 			fp++;
    527   1.1  tsutsui 		}
    528   1.1  tsutsui 		break;
    529   1.1  tsutsui 
    530   1.1  tsutsui 	case 3:
    531   1.3  tsutsui 		p = (uint16_t *)(raddr + ((row * FB_HEIGHT) << 8)
    532   1.3  tsutsui 		    + ((col / 4) * 6) + 4);
    533   1.3  tsutsui 		q = (uint16_t *)(waddr + ((row * FB_HEIGHT) << 8)
    534   1.3  tsutsui 		    + ((col / 4) * 6) + 4);
    535   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    536   1.1  tsutsui 			*q = (*p & 0xF000) | ((*fp & 0xFFF0) >> 4);
    537   1.1  tsutsui 			p += 128;
    538   1.1  tsutsui 			q += 128;
    539   1.1  tsutsui 			fp++;
    540   1.1  tsutsui 		}
    541   1.1  tsutsui 		break;
    542   1.1  tsutsui 
    543   1.1  tsutsui 	default:
    544   1.1  tsutsui 		break;
    545   1.1  tsutsui 	}
    546   1.1  tsutsui }
    547   1.1  tsutsui 
    548   1.7  tsutsui static void
    549   1.5  tsutsui bmd_reverse_char(uint8_t *raddr, uint8_t *waddr, int col, int row)
    550   1.1  tsutsui {
    551   1.3  tsutsui 	volatile uint16_t *p, *q;
    552   1.3  tsutsui 	volatile uint32_t *lp, *lq;
    553   1.1  tsutsui 	int i;
    554   1.1  tsutsui 
    555   1.3  tsutsui 	switch (col % 4) {
    556   1.1  tsutsui 
    557   1.1  tsutsui 	case 0:
    558   1.3  tsutsui 		p = (uint16_t *)(raddr + ((row * FB_HEIGHT) << 8)
    559   1.3  tsutsui 		    + ((col / 4) * 6));
    560   1.3  tsutsui 		q = (uint16_t *)(waddr + ((row * FB_HEIGHT) << 8)
    561   1.3  tsutsui 		    + ((col / 4) * 6));
    562   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    563   1.1  tsutsui 			*q = (*p & 0x000F) | (~(*p) & 0xFFF0);
    564   1.1  tsutsui 			p += 128;
    565   1.1  tsutsui 			q += 128;
    566   1.1  tsutsui 		}
    567   1.1  tsutsui 		break;
    568   1.1  tsutsui 
    569   1.1  tsutsui 	case 1:
    570   1.3  tsutsui 		lp = (uint32_t *)(raddr + ((row * FB_HEIGHT) << 8)
    571   1.3  tsutsui 		    + ((col / 4) * 6));
    572   1.3  tsutsui 		lq = (uint32_t *)(waddr + ((row * FB_HEIGHT) << 8)
    573   1.3  tsutsui 		    + ((col / 4) * 6));
    574   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    575   1.1  tsutsui 			*lq = (*lp & 0xFFF000FF) | (~(*lp) & 0x000FFF00);
    576   1.1  tsutsui 			lp += 64;
    577   1.1  tsutsui 			lq += 64;
    578   1.1  tsutsui 		}
    579   1.1  tsutsui 		break;
    580   1.1  tsutsui 
    581   1.1  tsutsui 	case 2:
    582   1.3  tsutsui 		lp = (uint32_t *)(raddr + ((row * FB_HEIGHT) << 8)
    583   1.3  tsutsui 		    + ((col / 4) * 6) + 2);
    584   1.3  tsutsui 		lq = (uint32_t *)(waddr + ((row * FB_HEIGHT) << 8)
    585   1.3  tsutsui 		    + ((col / 4) * 6) + 2);
    586   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    587   1.1  tsutsui 			*lq = (*lp & 0xFF000FFF) | (~(*lp) & 0x00FFF000);
    588   1.1  tsutsui 			lp += 64;
    589   1.1  tsutsui 			lq += 64;
    590   1.1  tsutsui 		}
    591   1.1  tsutsui 		break;
    592   1.1  tsutsui 
    593   1.1  tsutsui 	case 3:
    594   1.3  tsutsui 		p = (uint16_t *)(raddr + ((row * FB_HEIGHT) << 8)
    595   1.3  tsutsui 		    + ((col / 4) * 6) + 4);
    596   1.3  tsutsui 		q = (uint16_t *)(waddr + ((row * FB_HEIGHT) << 8)
    597   1.3  tsutsui 		    + ((col / 4) * 6) + 4);
    598   1.3  tsutsui 		for (i = 0; i < FB_HEIGHT; i++) {
    599   1.1  tsutsui 			*q = (*p & 0xF000) | (~(*p) & 0x0FFF);
    600   1.1  tsutsui 			p += 128;
    601   1.1  tsutsui 			q += 128;
    602   1.1  tsutsui 		}
    603   1.1  tsutsui 		break;
    604   1.1  tsutsui 
    605   1.1  tsutsui 	default:
    606   1.1  tsutsui 		break;
    607   1.1  tsutsui 	}
    608   1.1  tsutsui }
    609   1.1  tsutsui 
    610   1.7  tsutsui static void
    611   1.5  tsutsui bmd_erase_char(uint8_t *raddr, uint8_t *waddr, int col, int row)
    612   1.1  tsutsui {
    613   1.3  tsutsui 
    614   1.1  tsutsui 	bmd_draw_char(raddr, waddr, col, row, 0);
    615   1.1  tsutsui }
    616   1.1  tsutsui 
    617   1.1  tsutsui 
    618   1.1  tsutsui /*
    619   1.1  tsutsui  * screen operation routines
    620   1.1  tsutsui  */
    621   1.1  tsutsui 
    622   1.7  tsutsui static void
    623   1.3  tsutsui bmd_erase_screen(volatile uint32_t *lp)
    624   1.1  tsutsui {
    625   1.1  tsutsui 	int i, j;
    626   1.1  tsutsui 
    627   1.3  tsutsui 	for (i = 0; i < SB_HEIGHT; i++) {
    628   1.1  tsutsui 		for (j = 0; j < SL_WIDTH; j++)
    629   1.1  tsutsui 			*lp++ = 0;
    630   1.1  tsutsui 		SKIP_NEXT_LINE(lp);
    631   1.1  tsutsui 	}
    632   1.1  tsutsui }
    633   1.1  tsutsui 
    634   1.7  tsutsui static void
    635   1.3  tsutsui bmd_scroll_screen(volatile uint32_t *lp, volatile uint32_t *lq,
    636   1.1  tsutsui     int xmin, int xmax, int ymin, int ymax)
    637   1.1  tsutsui {
    638   1.1  tsutsui 	int i, j;
    639   1.1  tsutsui 
    640   1.3  tsutsui 	lp += ((PL_WIDTH * FB_HEIGHT) * (ymin + 1));
    641   1.3  tsutsui 	lq += ((PL_WIDTH * FB_HEIGHT) *  ymin);
    642   1.1  tsutsui 
    643   1.3  tsutsui 	for (i = 0; i < ((ymax - ymin -1) * FB_HEIGHT); i++) {
    644   1.1  tsutsui 		for (j = 0; j < SL_WIDTH; j++) {
    645   1.1  tsutsui 			*lq++ = *lp++;
    646   1.1  tsutsui 		}
    647   1.1  tsutsui 		lp += (PL_WIDTH - SL_WIDTH);
    648   1.1  tsutsui 		lq += (PL_WIDTH - SL_WIDTH);
    649   1.1  tsutsui 	}
    650   1.1  tsutsui 
    651   1.3  tsutsui 	for (i = 0; i < FB_HEIGHT; i++) {
    652   1.1  tsutsui 		for (j = 0; j < SL_WIDTH; j++) {
    653   1.1  tsutsui 			*lq++ = 0;
    654   1.1  tsutsui 		}
    655   1.1  tsutsui 		lq += (PL_WIDTH - SL_WIDTH);
    656   1.1  tsutsui 	}
    657   1.1  tsutsui }
    658