home *** CD-ROM | disk | FTP | other *** search
- /*
- * console.c: hterm console control
- *
- * Author: HIRANO Satoshi
- * (C) 1989 Halca Computer Science Laboratory TM
- * University of Tokyo
- *
- * 2.2 89/05/16 Halca.Hirano V2.2 distribution
- * 2.3 89/06/14 Halca.Hirano
- * 1 remove #else, add #kanji
- * 2 add non direct GDC access, use CRT BIOS for PC98XA or future machines
- * 2.4 89/07/20 Halca.Hirano add 19/20/24/25 line mode, and many changes
- * 2.5 89/07/22 Halca.Hirano add history
- * ---- V2.3.-1 distribution ----
- * 2.6 89/09/15 Halca.Hirano fix download kanji bug
- * ---- V2.4.0 distribution ----
- * 2.7 89/11/10 Tominaga@Titech ported to J3100
- * ---- V2.4.2 distribution ----
- * 2.8 90/06/19 Halca.Hirano
- * rewrite conWrite() faster and support soft font
- *
- * $Header: console.cv 1.11 90/07/05 08:37:26 hirano Exp $
- *
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include "config.h"
- #include "hterm.h"
- #include "option.h"
- #include "default.h"
- #include "global.h"
-
- #ifdef KANJI
- /*
- * JIS X0208-83 keisen conversion table
- */
- static unsigned int keiConv[32] = {
- 0x240c, 0x260c, 0x300c, 0x340c, 0x3c0c, 0x380c, 0x400c, 0x500c,
- 0x480c, 0x580c, 0x600c, 0x250c, 0x270c, 0x330c, 0x370c, 0x3f0c,
- 0x3b0c, 0x470c, 0x570c, 0x4f0c, 0x5f0c, 0x6f0c, 0x440c, 0x530c,
- 0x4c0c, 0x5b0c, 0x630c, 0x410c, 0x540c, 0x490c, 0x5c0c, 0x660c
- };
- #endif /* KANJI */
-
- /*
- ** void consoleInit()
- *
- * initialize console related variables
- */
- void consoleInit()
- {
- CRTInit(); /* iniz CRT */
- attrib = eraseAttr = _NORMAL; /* normal attribute */
- border = 0; /* black border */
-
- /* set defaults */
- lineMode = DEFAULT_LINE_MODE;
- formfeed = DEFAULT_FORMFEED;
- cursor = DEFAULT_CURSOR;
- blinkCursor = DEFAULT_BLINK_CURSOR;
- blockCursor = DEFAULT_BLOCK_CURSOR;
- autoWrap = DEFAULT_AUTO_WRAP;
- printMode = DEFAULT_PRINT_MODE;
- intControl = DEFAULT_INTCONTROL;
- echoMode = DEFAULT_ECHO_MODE;
- kanjiCode = DEFAULT_KANJI_CODE; /* kanji code */
- visibleBell = DEFAULT_VISIBLE_BELL; /* visible bell */
-
- #ifdef PC98
- backQuote = HAVE_REAL_BACK_QUOTE;
- #endif /* PC98 */
- clearSavedPage(page0Save);
- }
-
- /*
- ** void consoleSetup()
- *
- * initialize CRT mode and clear current page
- */
- void consoleSetup()
- {
- cursorX = cursorY = 0; /* home position */
- wrapPending = NO; /* not pending */
- setLineMode(lineMode); /* set line mode */
- upScrRegion = 0; /* upper scroll region */
- lowScrRegion = bottomLine; /* lower scroll region */
- setCRTMode();
- setBorder(border);
- initPage();
- cursorOnOff(cursor);
- }
-
- /*
- ** void consoleEnd()
- *
- * deinitialize console
- */
- void consoleEnd()
- {
- CRTEnd(); /* deiniz CRT */
- }
-
- /*
- ** void initPage()
- *
- * initialize current console page; clear and move cursor to home
- */
- void initPage()
- {
- clearCurrentPage();
- locate(0, 0);
- wrapPending = NO;
- }
-
- /*
- ** void setLineMode(int mode)
- *
- * set line mode to 'mode'
- */
- void setLineMode(mode)
- int mode;
- {
- switch (mode) {
- case LINE_MODE_19:
- maxLine = MAX_LINE_19_MODE;
- realMaxLine = MAX_LINE_20_MODE;
- bottomLine = BOTTOM_LINE_19_MODE;
- realBottomLine = BOTTOM_LINE_20_MODE;
- break;
- case LINE_MODE_20:
- realMaxLine = maxLine = MAX_LINE_20_MODE;
- realBottomLine = bottomLine = BOTTOM_LINE_20_MODE;
- break;
- case LINE_MODE_24:
- maxLine = MAX_LINE_24_MODE;
- bottomLine = BOTTOM_LINE_24_MODE;
- realBottomLine = BOTTOM_LINE_25_MODE;
- realMaxLine = MAX_LINE_25_MODE;
- break;
- case LINE_MODE_25:
- realMaxLine = maxLine = MAX_LINE_25_MODE;
- realBottomLine = bottomLine = BOTTOM_LINE_25_MODE;
- break;
- }
- #ifdef PC98
- setCRTLineMode(realMaxLine < 21 ? 0 : 1);
- #endif /* PC98 */
- }
-
- /*
- ** void conWrite(register u_short c)
- *
- * write a char on console; char is hterm kanji code
- */
- void conWrite(c)
- register u_short c;
- {
- register u_short c2;
- int attrSave;
-
- #ifdef KANJI
- c2 = c>>8;
- if (c2) { /* kanji */
- /*
- * ensure that one kanji char never be devided into two lines
- */
- if (cursorX == LAST_COLUMN && wrapPending == NO) {
- putChar(SPACE);
- wrapPending = YES; /* force move to next line */
- }
- }
- #endif /* KANJI */
-
- /*
- * process wrap pending
- */
- if (wrapPending && cursorX == LAST_COLUMN) {
- if (cursorY == lowScrRegion) {
- cursorX = 0;
- scrlUp();
- } else if (cursorY < bottomLine) {
- cursorX = 0;
- cursorY++;
- } /* else stay LAST_COLUMN */
- locate(cursorX, cursorY);
- }
- wrapPending = NO;
-
- #ifdef SOFT_FONT
- if (softFont)
- softCursorOnOff(NO);
- #endif
-
- #ifdef KANJI
- if (c2) {
- /*
- * display kanji character
- */
- #ifdef SOFT_FONT
- if (softFont)
- softFontPutChar(c);
- #endif /* SOFT_FONT */
- #ifdef PC98
- if (0x2821 <= c && c <= 0x2840) /* keisen */
- c2 = keiConv[c - 0x2821];
- else
- c2 = ((c << 8) | (c2 - 0x20));
- putChar(c2);
- cursorX++;
- putChar(c2 | 0x8000);
- #endif /* PC98 */
- #if defined(IBMPC) || defined(J3100)
- c2 = JIStoSJIS(c2, c & 0xff);
- putChar(c2 >> 8);
- cursorX++;
- #ifdef J3100 /* the char will be written at cursor position in putChar() */
- locate(cursorX, cursorY);
- #endif
- putChar(c2 & 0xff);
- #endif /* IBMPC || J3100 */
- } else
- #endif /* KANJI */
- {
- attrSave = attrib;
- /*
- * if no interpret control mode, make reverse mode
- */
- if (intControl == NO && iscntrl(c)) {
- reverseMode();
- c = (c == 0x7f ? c : c + 0x40);
- }
- /*
- * display ascii or kana character
- */
- #ifdef SOFT_FONT
- if (softFont)
- softFontPutChar(c);
- #endif
- #ifdef PC98
- /* I don't wont to display yen mark. */
- if (c == 0x5c) /* backslash */
- c = backQuote ? c = 0xfc : 0xef; /* *real* or emitation */
- else if (c == 0x60) { /* back quote */
- if (!backQuote)
- c = 0xde; /* kana chon chon */
- }
- #endif /* PC98 */
- putChar(c);
- attrib = attrSave; /* recover from reverse mode */
- }
- /*
- * move cursor to the next position
- */
- if (++cursorX > LAST_COLUMN) { /* if kanji, already advanced one */
- cursorX = LAST_COLUMN;
- if (autoWrap == YES) {
- wrapPending = YES;
- }
- }
-
- /*
- * cursor optimization;
- * set cursor only if no more chars coming
- * because locate() makes BIOS call which is very time consuming
- */
- #ifndef J3100
- if (!checkSerial() || mode != M_COMM || !online)
- #else /* J3100 will use BIOS for next putChar() */
- if (!checkSerial() || mode != M_COMM || !online || softFont == NO)
- #endif /* J3100 */
- locate(cursorX, cursorY);
- noLocate:
-
- /*
- * printing and logging
- */
- if (printMode)
- outPrinter(c);
- if (logging == LOG_CONVERT)
- logPut(c);
- }
-
- /*
- ** void moveCursor(int action, register int num)
- *
- * move cursor relatively
- */
- void moveCursor(action, num)
- int action;
- register int num;
- {
- wrapPending = NO;
- if (num == 0)
- num++;
- switch (action) {
- case UP:
- if (cursorY > bottomLine)
- cursorY = bottomLine;
- else if (cursorY >= upScrRegion && cursorY-num < upScrRegion)
- cursorY = upScrRegion;
- else if (cursorY - num < 0)
- cursorY = 0;
- else
- cursorY -= num;
- break;
- case DOWN:
- if (cursorY >= bottomLine)
- cursorY = bottomLine;
- else if (cursorY <= lowScrRegion && cursorY+num > lowScrRegion)
- cursorY = lowScrRegion;
- else if (cursorY + num > bottomLine)
- cursorY = bottomLine;
- else
- cursorY += num;
- break;
- case RIGHT:
- if (cursorX + num > LAST_COLUMN)
- cursorX = LAST_COLUMN;
- else
- cursorX += num;
- break;
- case LEFT:
- if (cursorX - num < 0)
- cursorX = 0;
- else
- cursorX -= num;
- break;
- }
- locate(cursorX, cursorY);
- }
-
- /*
- ** void scrlUp()
- *
- * scroll up current page
- */
- void scrlUp()
- {
- int tmp = cursorY;
-
- wrapPending = NO;
- cursorY = upScrRegion;
- #ifdef COPY_PASTE
- saveHist(cursorY, YES);
- #endif /* COPY_PASTE */
- deleteLine(1);
- cursorY = tmp;
- }
-
- /*
- ** void clearLine(from, to)
- *
- * clear lines from 'from' to 'to'
- */
- void clearLine(from, to)
- u_short from;
- register u_short to;
- {
- register int i;
- int tmp;
-
- wrapPending = NO;
- tmp = cursorY;
- for (i = from; i <= to; i++) {
- cursorY = i;
- if (softFont) {
- #ifdef SOFT_FONT
- if (cursor)
- cursorOnOff(NO);
- softFont = NO;
- clearColumn(0, MAX_COLUMN);
- softFont = YES;
- softFontClearLine(cursorY);
- if (cursor)
- cursorOnOff(YES);
- #endif /* SOFT_FONT */
- } else
- clearColumn(0, MAX_COLUMN);
- }
- cursorY = tmp;
- }
-
- /*
- ** void awMode(int mode)
- *
- * auto wrap mode
- */
- void awMode(mode)
- int mode;
- {
- autoWrap = mode;
- if (autoWrap == YES)
- wrapPending = NO;
- }
-
-
-