📄 bmd.c
字号:
/* * Copyright (c) 1992 OMRON Corporation. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * OMRON Corporation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)bmd.c 8.1 (Berkeley) 6/10/93 *//* * bmd.c --- Bitmap-Display raw-level driver routines * * by A.Fujita, SEP-09-1992 */#undef BMD_PRINTF#include <sys/param.h>#include <sys/systm.h>extern u_short bmdfont[][20];#define isprint(c) ( c < 0x20 ? 0 : 1)/* * Width & Hight */#define PB_WIDTH 2048 /* Plane Width (Bit) */#define PB_HIGHT 1024 /* Plane Hight (Bit) */#define PL_WIDTH 64 /* Plane Width (long) */#define PS_WIDTH 128 /* Plane Width (long) */#define P_WIDTH 256 /* Plane Width (Byte) */#define SB_WIDTH 1280 /* Screen Width (Bit) */#define SB_HIGHT 1024 /* Screen Hight (Bit) */#define SL_WIDTH 40 /* Screen Width (Long) */#define S_WIDTH 160 /* Screen Width (Byte) */#define FB_WIDTH 12 /* Font Width (Bit) */#define FB_HIGHT 20 /* Font Hight (Bit) */#define NEXT_LINE(addr) ( addr + (PL_WIDTH * FB_HIGHT) )#define SKIP_NEXT_LINE(addr) ( addr += (PL_WIDTH - SL_WIDTH) )void bmd_add_new_line();void bmd_draw_char();void bmd_reverse_char();void bmd_erase_char();void bmd_erase_screen();void bmd_scroll_screen();void bmd_escape();struct bmd_linec { struct bmd_linec *bl_next; struct bmd_linec *bl_prev; int bl_col; int bl_end; u_char bl_line[128];};struct bmd_softc { int bc_stat; char *bc_raddr; char *bc_waddr; int bc_xmin; int bc_xmax; int bc_ymin; int bc_ymax; int bc_col; int bc_row; struct bmd_linec *bc_bl; char bc_escseq[8]; char *bc_esc; void (*bc_escape)();};#define STAT_NORMAL 0x0000#define STAT_ESCAPE 0x0001#define STAT_STOP 0x0002struct bmd_softc bmd_softc;struct bmd_linec bmd_linec[52];int bmd_initflag = 0;/* * Escape-Sequence */#define push_ESC(p, c) *(p)->bc_esc++ = c; *(p)->bc_esc = '\0'voidbmd_escape(c) int c;{ register struct bmd_softc *bp = &bmd_softc; bp->bc_stat &= ~STAT_ESCAPE; bp->bc_esc = &bp->bc_escseq[0];/* bp->bc_escape = bmd_escape; */}/* * Entry Routine */bmdinit(){ register struct bmd_softc *bp = &bmd_softc; register struct bmd_linec *bq; register int i; bp->bc_raddr = (char *) 0xB10C0008; /* plane-0 hardware address */ bp->bc_waddr = (char *) 0xB1080008; /* common bitmap hardware address */ /* * adjust plane position */ fb_adjust(7, -27); bp->bc_stat = STAT_NORMAL; bp->bc_xmin = 8; bp->bc_xmax = 96; bp->bc_ymin = 2; bp->bc_ymax = 48; bp->bc_row = bp->bc_ymin; for (i = bp->bc_ymin; i < bp->bc_ymax; i++) { bmd_linec[i].bl_next = &bmd_linec[i+1]; bmd_linec[i].bl_prev = &bmd_linec[i-1]; } bmd_linec[bp->bc_ymax-1].bl_next = &bmd_linec[bp->bc_ymin]; bmd_linec[bp->bc_ymin].bl_prev = &bmd_linec[bp->bc_ymax-1]; bq = bp->bc_bl = &bmd_linec[bp->bc_ymin]; bq->bl_col = bq->bl_end = bp->bc_xmin; bp->bc_col = bp->bc_xmin; bp->bc_esc = &bp->bc_escseq[0]; bp->bc_escape = bmd_escape; bmd_erase_screen((u_long *) bp->bc_waddr); /* clear screen */ /* turn on cursole */ bmd_reverse_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row); bmd_initflag = 1;}bmdputc(c) register int c;{ register struct bmd_softc *bp; register struct bmd_linec *bq; register int i; if (!bmd_initflag) bmdinit(); bp = &bmd_softc; bq = bp->bc_bl; /* skip out, if STAT_STOP */ if (bp->bc_stat & STAT_STOP) return(c); c &= 0x7F; /* turn off cursole */ bmd_reverse_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row); /* do escape-sequence */ if (bp->bc_stat & STAT_ESCAPE) { *bp->bc_esc++ = c; (*bp->bc_escape)(c); goto done; } if (isprint(c)) { bmd_draw_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row, c); bq->bl_col++; bq->bl_end++; if (bq->bl_col >= bp->bc_xmax) { bq->bl_col = bq->bl_end = bp->bc_xmin; bp->bc_row++; if (bp->bc_row >= bp->bc_ymax) { bmd_scroll_screen((u_long *) bp->bc_raddr, (u_long *) bp->bc_waddr, bp->bc_xmin, bp->bc_xmax, bp->bc_ymin, bp->bc_ymax); bp->bc_row = bp->bc_ymax - 1; } } } else { switch (c) { case 0x08: /* BS */ if (bq->bl_col > bp->bc_xmin) { bq->bl_col--; } break; case 0x09: /* HT */ case 0x0B: /* VT */ i = ((bq->bl_col / 8) + 1) * 8; if (i < bp->bc_xmax) { bq->bl_col = bq->bl_end = i; } break; case 0x0A: /* NL */ bp->bc_row++; if (bp->bc_row >= bp->bc_ymax) { bmd_scroll_screen((u_long *) bp->bc_raddr, (u_long *) bp->bc_waddr, bp->bc_xmin, bp->bc_xmax, bp->bc_ymin, bp->bc_ymax); bp->bc_row = bp->bc_ymax - 1; } break; case 0x0D: /* CR */ bq->bl_col = bp->bc_xmin; break; case 0x1b: /* ESC */ bmdputc('<'); bmdputc('E'); bmdputc('S'); bmdputc('C'); bmdputc('>');/* bp->bc_stat |= STAT_ESCAPE; *bp->bc_esc++ = 0x1b; */ break; case 0x7F: /* DEL */ if (bq->bl_col > bp->bc_xmin) { bq->bl_col--; bmd_erase_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row); } break; default: break; } } done: /* turn on cursole */ bmd_reverse_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row); return(c);}/* * */bmd_on(){ bmdinit();}bmd_off(){ register struct bmd_softc *bp = &bmd_softc; bp->bc_stat |= STAT_STOP; bmd_erase_screen((u_long *) bp->bc_waddr); /* clear screen */}bmd_clear(){ register struct bmd_softc *bp = &bmd_softc; register struct bmd_linec *bq = bp->bc_bl; bmd_erase_screen((u_long *) bp->bc_waddr); /* clear screen */ bmd_reverse_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row); /* turn on cursole */}bmd_home(){ register struct bmd_softc *bp = &bmd_softc; register struct bmd_linec *bq = bp->bc_bl; bmd_reverse_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row); /* turn off cursole */ bq->bl_col = bq->bl_end = bp->bc_xmin; bp->bc_row = bp->bc_ymin; bmd_reverse_char(bp->bc_raddr, bp->bc_waddr, bq->bl_col, bp->bc_row); /* turn on cursole */}/* * charactor operation routines */voidbmd_draw_char(raddr, waddr, col, row, c) char *raddr; char *waddr; int col; int row; int c;{ volatile register u_short *p, *q, *fp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -