home *** CD-ROM | disk | FTP | other *** search
- /*
- * j3100.c: hterm screen driver for J-3100 series
- *
- * Author: Kaz.Tominaga@Titech/giken
- *
- * 1.1 89/11/01 Tominaga@titech/giken converted from ibmpc.c
- * 1.2 89/11/29 Halca.Hirano visible/audible/both bell mode
- * 1.3 90/06/21 Halca.Hirano
- * remove multiple page support by explicit page selection
- * support soft font
- * 1.4 90/07/05 Halca.Hirano
- * turn backlight off when text CRT off (called by screen saver)
- *
- * $Header: j3100.cv 1.8 90/07/05 08:37:26 hirano Exp $
- */
-
- #ifdef J3100
- #include "option.h"
- #include <stdio.h>
- #include "config.h"
- #include "hterm.h"
- #include "default.h"
- #include "global.h"
-
- /* the expression of cursor location in BIOS */
- #define B_CURSOR(x,y) (u_short)((((y) & 0xff) << 8) | ((x) & 0xff))
-
- /*
- * physical line number VRAM address convertion table
- * index = physical line number
- * contents = VRAM address
- */
- static u_short *ltopTab[MAX_LINE_25_MODE];
- /*
- * logical line number to VRAM address conversion function
- */
- #define ltop(y) (ltopTab[y])
-
- static u_short screenmode; /* screen mode */
- static u_short scrollmode; /* scroll mode */
- static u_short cursormode; /* cursor mode */
- static u_short cursorshape; /* cursor shape */
- static u_short syslinecount; /* system line count */
- static short vramSegmentSave; /* text move VRAM segment */
- static short backingStoreSeg; /* soft font backing store */
- static char FAR *backingStore; /* pointer to backing store */
-
- static void reverseScreen(void );
-
- /*
- ** void CRTInit(): initialize PC98 CRT
- *
- * called once just after hterm startup
- */
- void CRTInit()
- {
- register int i;
- register u_short *p;
-
- #ifdef SOFT_FONT
- /*
- * build line number conversion table
- */
- p = (u_short *)0;
- for (i = 0; i < MAX_LINE_25_MODE; i++) {
- /* physical line no to VRAM address convertion table */
- ltopTab[i] = p;
- p += MAX_COLUMN;
- }
-
- /*
- * allocate memory for VRAM backing store
- */
- backingStore = allocMem((long)MAX_CHAR*sizeof(short));
- if (backingStore == 0) {
- fprintf(stderr, msg_alloc, "backing store\n");
- exit(1);
- }
- backingStoreSeg = FP_SEG(backingStore);
- #endif
- vramSegmentSave = vramSegment = VRAM_MONO;
- gvramSegment = GVRAMSEG; /* but reset later */
-
- /* read screen mode */
- rg.h.ah = 0x0f;
- int86(VIDEOBIOS, &rg, &rg);
- screenmode = rg.h.al;
-
- /* read scroll mode */
- rg.x.ax = 0x8200;
- rg.h.bl = -1;
- int86(VIDEOBIOS, &rg, &rg);
- scrollmode = rg.h.al;
-
- /* read cursor mode */
- rg.x.ax = 0x8204;
- rg.h.bl = -1;
- int86(VIDEOBIOS, &rg, &rg);
- cursormode = rg.h.al;
-
- /* read cursor shape */
- rg.h.ah = 3;
- int86(VIDEOBIOS, &rg, &rg);
- cursorshape = rg.x.cx;
-
- /* get system line count */
- rg.x.ax = 0x0cff;
- int86(SYSTEMSUB, &rg, &rg);
- syslinecount = rg.h.al;
- }
-
- /*
- ** void CRTEnd()
- */
- void CRTEnd()
- {
- freeMem(backingStore);
- upScrRegion = 0;
- lowScrRegion = BOTTOM_LINE_25_MODE;
- #ifdef SOFT_FONT
- if (softFont) { /* erase graphic screen */
- clearCurrentPage();
- cursorOnOff(NO);
- softFont = NO;
- }
- #endif /* SOFT_FONT */
- restoreCRTMode();
- }
-
-
- /*
- ** void setCRTMode()
- *
- * set CRT mode
- */
- void setCRTMode()
- {
- short FAR *p;
- int i;
-
- /*
- * set CRT mode
- */
- #ifdef SOFT_FONT
- if (softFont) {
- /*
- * erase text cursor and text VRAM
- */
- softFont = NO;
- cursorOnOff(NO);
- clearCurrentPage();
- softFont = YES;
- /*
- * fake text VRAM dummy at vramBacking store
- */
- vramSegment = backingStoreSeg;
- /*
- * clear backing store
- */
- FP_SEG(p) = vramSegment;
- FP_OFF(p) = 0;
- for (i = MAX_CHAR; i > 0; --i)
- *p++ = (u_short)((eraseAttr<<8) | SPACE);
- /*
- * set GRAPHIC mode
- */
- rg.h.ah = 0; /* set video mode command */
- rg.h.al = 0x0074; /* mono 640x400(?) */
- int86(VIDEOBIOS, &rg, &rg);
- } else
- #endif /* SOFT_FONT */
- {
- vramSegment = vramSegmentSave;
- /*
- * set TEXT mode
- */
- /* set screen mode */
- rg.x.ax = 0x0074; /* graphics 25rows */
- int86(VIDEOBIOS, &rg, &rg);
-
- /* set scroll mode */
- rg.x.ax = 0x8200;
- rg.h.bl = 0; /* fast scroll mode */
- int86(VIDEOBIOS, &rg, &rg);
-
- /* set one system line for feps */
- rg.x.ax = 0x0c00;
- int86(SYSTEMSUB, &rg, &rg);
-
- /* cursor mode is set by setup */
- }
- }
-
- /*
- ** void restoreCRTMode()
- *
- * restore CRT mode to startup condition
- */
- void restoreCRTMode()
- {
- /* restore screen mode */
- rg.h.ah = 0;
- rg.h.al = screenmode;
- int86(VIDEOBIOS, &rg, &rg);
-
- /* restore scroll mode */
- rg.x.ax = 0x8200;
- rg.h.bl = scrollmode;
- int86(VIDEOBIOS, &rg, &rg);
-
- /* restore cursor mode */
- rg.x.ax = 0x8204;
- rg.h.bl = cursormode;
- int86(VIDEOBIOS, &rg, &rg);
-
- /* restore cursor shape */
- rg.h.ah = 1;
- rg.x.cx = cursorshape;
- int86(VIDEOBIOS, &rg, &rg);
-
- /* restore system line count */
- rg.h.ah = 0x0c;
- rg.h.al = syslinecount;
- int86(SYSTEMSUB, &rg, &rg);
- }
-
- /*
- ** locate(register int x, int y)
- *
- * set cursor on position (x,y)
- */
- void locate(x, y)
- register int x, y;
- {
- cursorX = x;
- cursorY = y;
- #ifdef SOFT_FONT
- if (softFont) {
- if (cursor)
- softFontLocate(x, y);
- } else
- #endif
- b_setCursor(B_CURSOR(x, y)); /* set cursor using bios */
- }
-
- #ifdef SOFT_FONT
- /*
- ** int isKanjiOnVRAM(x, y)
- *
- * return non zero if the character is kanji at current cursor position
- *
- */
- int isKanjiOnVRAM(x, y)
- int x;
- int y;
- {
- u_short FAR *p;
-
- FP_SEG(p) = vramSegment;
- FP_OFF(p) = (int)(ltop(y) + x);
- return(isSJIS1(*p & 0xff));
- }
- #endif /* SOFT_FONT */
-
- /*
- ** void cursorOnOff(int onOff)
- *
- * set cursor form; on/off, blinking/static, underline/block
- */
- void cursorOnOff(onOff)
- int onOff;
- {
- #ifdef SOFT_FONT
- if (softFont) {
- softCursorOnOff(onOff);
- } else
- #endif
- {
- rg.x.ax = 0x8204; /* set cursor mode */
- rg.h.bl = blinkCursor ? 0/*blink*/ : 1/*static*/;
- int86(VIDEOBIOS, &rg, &rg);
-
- rg.h.ah = 1; /* set cursor type service code */
- if (onOff == YES)
- rg.x.cx = blockCursor ? 0x010e/*block*/ : 0x0b0e/*underline*/;
- else
- rg.x.cx = 0x0f00; /* cursor off */
- int86(VIDEOBIOS, &rg, &rg);
- }
- }
-
- /*
- ** void putChar(register u_short c)
- *
- * put a charactor 'c' and attribute 'attrib' at (cursorX, cursorY)
- */
- void putChar(c)
- register u_short c;
- {
- u_short attr;
- u_short code;
- u_short FAR *p;
-
- #ifdef SOFT_FONT
- if (softFont) {
- /*
- * update backing store
- */
- FP_SEG(p) = vramSegment;
- FP_OFF(p) = (int)(ltop(cursorY) + cursorX);
- *p = (attrib << 8 | (u_char)c);
- } else
- #endif
- {
- /* attribute decoding */
- if (attrib & _REVER) {
- attr = _REVER_ATTR;
- } else if (attrib & _UNDER) {
- attr = _UNDER_ATTR;
- } else if (attrib & _HIGH && c != SPACE) {
- attr = _HIGH_ATTR;
- } else if (attrib & _BLINK && c != SPACE) {
- attr = _BLINK_ATTR;
- } else {
- attr = _NORMAL_ATTR;
- }
-
- code = (attr << 8) | (u_char)c;
- b_writeChar(code); /* put a char using bios */
- }
- }
-
- /*
- ** void insertLine(register u_short num)
- *
- * insert num lines at cursorY
- *
- * If cursorY is not in scroll region, ignore request
- * If num exceeds scroll region, strict num into scroll region
- *
- */
- void insertLine(num)
- register int num;
- {
- u_short savexy;
-
- /*
- * if cursor is out of scroll region or zero request, ignore request
- */
- if (cursorY < upScrRegion || cursorY > lowScrRegion || num == 0)
- return; /* ignore */
- /*
- * requested num must be in scroll region
- */
- if (lowScrRegion+1-cursorY < num)
- num = lowScrRegion+1-cursorY; /* out of scroll region */
-
- #ifdef SOFT_FONT
- if (softFont) {
- /*
- * update backing store then move GVRAM
- */
- if (cursor)
- cursorOnOff(NO);
- /* moveBackward(to, from, num, MOVE_ATTRIBUTE_TOO) */
- moveBackward(ltop(cursorY+num), ltop(cursorY),
- (lowScrRegion+1-cursorY-num) * MAX_COLUMN, YES);
- softFontInsertLine(num);
- if (cursor)
- cursorOnOff(YES);
- /*
- * clear created lines
- */
- clearLine(cursorY, cursorY+num-1);
- } else
- #endif
- {
- savexy = b_getCursor(); /* save cursor position */
- rg.h.ah = 7; /* scroll down bios */
- rg.h.al = num; /* scroll line */
- /* scroll region */
- rg.x.cx = B_CURSOR(0, cursorY);
- rg.x.dx = B_CURSOR(MAX_COLUMN-1, lowScrRegion);
- int86(VIDEOBIOS, &rg, &rg);
- b_setCursor(savexy); /* restore cursor position */
- }
- }
-
- /*
- ** void deleteLine(register u_short num)
- *
- * delete num lines at cursorY
- *
- * If cursorY is not in scroll region, ignore request
- * If num exceeds scroll region, strict num into scroll region
- *
- */
- void deleteLine(num)
- register int num;
- {
- u_short savexy;
-
- /*
- * if cursor is out of scroll region or zero request, ignore request
- */
- if (cursorY < upScrRegion || cursorY > lowScrRegion || num == 0)
- return; /* ignore */
- /*
- * requested num must be in scroll region
- */
- if (lowScrRegion+1-cursorY < num)
- num = lowScrRegion+1-cursorY; /* out of scroll region */
-
- #ifdef SOFT_FONT
- if (softFont) {
- /*
- * update backing store then move GVRAM
- */
- if (cursor)
- cursorOnOff(NO);
- /* moveForward(to, from, num, MOVE_ATTRIBUTE_TOO) */
- moveForward(ltop(cursorY), ltop(cursorY+num),
- (lowScrRegion+1-cursorY-num)*MAX_COLUMN, YES);
- softFontDeleteLine(num);
- if (cursor)
- cursorOnOff(YES);
- /*
- * clear created lines
- */
- clearLine(lowScrRegion-num+1, lowScrRegion);
- } else
- #endif
- {
- savexy = b_getCursor(); /* save cursor position */
- rg.h.ah = 6; /* scroll up bios */
- rg.h.al = num; /* scroll line */
- /* scroll region */
- rg.x.cx = B_CURSOR(0, cursorY);
- rg.x.dx = B_CURSOR(MAX_COLUMN-1, lowScrRegion);
- int86(VIDEOBIOS, &rg, &rg);
- b_setCursor(savexy); /* restore cursor position */
- }
- }
-
- /*
- ** void clearColumn(register u_shrot from, register u_short to)
- *
- * clear column 'from' to 'to'-1 on cursorY line,
- */
- void clearColumn(from, to)
- register u_short from, to;
- {
- int savexy;
-
- if (to > from) {
- #ifdef SOFT_FONT
- if (softFont) {
- if (cursor)
- cursorOnOff(NO);
- fillVRAM(ltop(cursorY)+from, to-from, SPACE, eraseAttr);
- softFontClearColumn(from, to);
- if (cursor)
- cursorOnOff(YES);
- } else
- #endif
- {
- savexy = b_getCursor(); /* save cursor position */
- rg.h.ah = 6; /* use scroll up bios to clear region */
- rg.h.al = 0; /* scroll line = 0 means 'clear' */
- /* scroll region */
- rg.x.cx = B_CURSOR(from, cursorY);
- rg.x.dx = B_CURSOR(to-1, cursorY);
- int86(VIDEOBIOS, &rg, &rg);
- b_setCursor(savexy); /* restore cursor position */
- }
- }
- }
-
- /*
- ** void clearCurrentPage()
- *
- * clear current page
- */
- void clearCurrentPage()
- {
- #ifdef SOFT_FONT
- if (softFont) {
- clearLine(0, BOTTOM_LINE_25_MODE);
- } else
- #endif
- {
- rg.h.ah = 6; /* use scroll up bios to clear region */
- rg.h.al = 0; /* scroll line = 0 means 'clear' */
- /* scroll region */
- rg.x.cx = B_CURSOR(0, 0);
- rg.x.dx = B_CURSOR(MAX_COLUMN-1, realBottomLine);
- int86(VIDEOBIOS, &rg, &rg);
- }
- }
-
- /*
- ** void insertChar(register int at, int n)
- *
- * insert n blank charactors at 'at' on cursorY line
- */
- void insertChar(at, n)
- register int at;
- register int n;
- {
- register int moveNum = MAX_COLUMN-at-n;
- u_short savexy;
-
- #ifdef SOFT_FONT
- if (softFont) {
- register u_short *src = ltop(cursorY)+at;
- if (cursor)
- cursorOnOff(NO);
- if (moveNum > 0)
- moveBackward(src+n, src, moveNum, YES);
- else
- n = MAX_COLUMN-at;
- fillVRAM(src, n, SPACE, eraseAttr);
- softFontInsertChar(at, n);
- if (cursor)
- cursorOnOff(YES);
- } else
- #endif
- {
- savexy = b_getCursor(); /* save cursor position */
- if (moveNum > 0)
- moveBackwardJ3(B_CURSOR(at+n, cursorY), B_CURSOR(at, cursorY), moveNum);
- else
- n = MAX_COLUMN-at;
- clearColumn(at, at+n);
-
- b_setCursor(savexy); /* restore cursor position */
- }
- }
-
- /*
- ** void deleteChar(register int at, register int n)
- *
- * delete 'n' characters at 'at' on cursorY line and make blank trailing 'n'
- * characters.
- */
- void deleteChar(at, n)
- register int at;
- register int n;
- {
- register int moveNum = MAX_COLUMN-at-n;
- u_short savexy;
-
- #ifdef SOFT_FONT
- if (softFont) {
- register u_short *src = ltop(cursorY)+at;
- if (cursor)
- cursorOnOff(NO);
- if (moveNum > 0)
- moveForward(src, src+n, moveNum, YES);
- else {
- n = MAX_COLUMN-at;
- moveNum = 0;
- }
- fillVRAM(src+moveNum, n, SPACE, eraseAttr);
- softFontDeleteChar(at, n);
- if (cursor)
- cursorOnOff(YES);
- } else
- #endif
- {
- savexy = b_getCursor(); /* save cursor position */
-
- if (moveNum > 0)
- moveForwardJ3(B_CURSOR(at, cursorY), B_CURSOR(at+n, cursorY), moveNum);
- else
- n = MAX_COLUMN-at;
- clearColumn(MAX_COLUMN-n, MAX_COLUMN);
-
- b_setCursor(savexy); /* restore cursor position */
- }
- }
-
- /*
- ** void saveLine(int y, register u_char FAR *buf)
- *
- * copy line y in VRAM into buffer
- * Kanji code is EUC in buffer.
- */
- void saveLine(y, buf)
- int y;
- register u_char FAR *buf;
- {
- #ifdef SOFT_FONT
- if (softFont) {
- register u_short c;
- short FAR *from;
- register u_char l;
- register int i;
-
- FP_SEG(from) = vramSegment;
- FP_OFF(from) = (int)ltop(y);
-
- for (i = 0; i < MAX_COLUMN; i++) {
- c = *from++;
- if (c & 0x80) { /* kanji */
- l = c;
- c = SJIStoJIS(l, *from++ & 0xff) | 0x8080;
- *buf++ = c >> 8;
- *buf++ = c;
- i++;
- } else
- *buf++ = c;
- }
- } else
- #endif /* SOFT_FONT */
- {
- register u_short c, c2, i;
- u_short savexy; /* bios expression */
-
- /* save current cursor position by bios call */
- savexy = b_getCursor();
-
- for (i = 0; i < MAX_COLUMN; i++) {
- c = b_readCharAt(B_CURSOR(i, y));
- if (c & 0x80) { /* kanji */
- /* Oops! hankaku-kana is not supported! */
- i++;
- c2 = b_readCharAt(B_CURSOR(i, y));
- c = SJIStoJIS(c, c2 & 0xff) | 0x8080;
- *buf++ = c >> 8;
- *buf++ = c;
- } else {
- *buf++ = c;
- }
- }
-
- /* restore cursor position by calling bios */
- b_setCursor(savexy);
- }
- }
-
- /*
- ** static void reverseScreen()
- *
- * reverse screen
- */
- static void reverseScreen()
- {
- #ifdef SOFT_FONT
- if (softFont)
- softFontReverseScreen();
- else
- #endif /* SOFT_FONT */
- v_reverseScreen();
- }
-
- /*
- ** void savePage(u_short buf[])
- *
- * save vram into save buffer 'buf' without code conversion
- */
- void savePage(buf)
- u_short *buf;
- {
- u_short savexy;
-
- #ifdef SOFT_FONT
- if (softFont)
- moveMemory(buf, getDSeg(), (u_short *)0, vramSegment, MAX_CHAR);
- else
- #endif
- {
- savexy = b_getCursor();
- saveVRAM(buf, getDSeg());
- b_setCursor(savexy);
- }
- }
-
- /*
- ** void restorePage(u_short buf)
- *
- * restore saved page into vram
- */
- void restorePage(buf)
- u_short *buf;
- {
- u_short savexy;
-
- #ifdef SOFT_FONT
- register u_short c;
- register u_char l;
- u_short *p;
- int cursorXSave = cursorX;
- int cursorYSave = cursorY;
-
- if (softFont) {
- moveMemory((u_short *)0, vramSegment, buf, getDSeg(), MAX_CHAR);
- softCursorOnOff(NO);
- p = buf; /* char pointer */
- for (cursorY = 0; cursorY <= realBottomLine; cursorY++) {
- for (cursorX = 0; cursorX < MAX_COLUMN; cursorX++) {
- c = *p++; /* get attribute and char */
- attrib = (c >> 8); /* attribute */
- c &= 0xff; /* strip attribute */
- if (c & 0x80) { /* kanji */
- l = c;
- c = SJIStoJIS(l, *p++ & 0xff);
- softFontPutChar(c);
- cursorX++;
- } else { /* ASCII */
- if (c < 0x20 || 0x7e < c) /* ignore kana */
- c = '?';
- softFontPutChar(c);
- }
- }
- }
- cursorX = cursorXSave;
- cursorY = cursorYSave;
- if (cursor)
- softCursorOnOff(YES);
- } else
- #endif /* SOFT_FONT */
- {
- savexy = b_getCursor();
- loadVRAM(buf, getDSeg());
- b_setCursor(savexy);
- }
- }
-
- /*
- ** void clearSavedPage(u_char buf[])
- *
- * clear saved page
- */
- void clearSavedPage(buf)
- u_short *buf;
- {
- register int i;
- register u_short *p;
-
- for (p = buf, i = MAX_CHAR; i > 0; --i)
- *p++ = (u_short)((eraseAttr<<8) | SPACE);
- }
-
- /*
- ** void click()
- *
- * generate click 'pi' sound
- */
- void click()
- {
- int i;
- u_char status;
-
- status = inp(ADDR_BUZZAR); /* read current status */
- outp(ADDR_BUZZAR, status | 0x3); /* buzzar on */
- for (i = 0; i < CLICK_BEEP; i++)
- nullFunction(); /* short wait */
- outp(ADDR_BUZZAR, status); /* buzzar off */
- }
-
- /*
- ** void bell()
- *
- * generate beep sound 'pii' with screen flush if required
- */
- void bell()
- {
- u_char status;
-
- /* check shift status for discarding beeps */
- rg.h.ah = 2;
- int86(KEY_BIOS, &rg, &rg);
- if ((rg.h.al & 0x03) == 0x03) return; /* both SHIFT are pressed */
-
- cursorOnOff(NO); /* for flashing screen */
- if (visibleBell == AUDIBLE_BELL || visibleBell == BOTH_AV_BELL) {
- status = inp(ADDR_BUZZAR); /* read current status */
- outp(ADDR_BUZZAR,status | 0x3); /* buzzar on */
- }
- timerValue = timerLoadValue;
- while (timerLoadValue - timerValue < BELL_BEEP) {
- nullFunction();
- if (visibleBell == VISIBLE_BELL || visibleBell == BOTH_AV_BELL) {
- reverseScreen();
- reverseScreen();
- }
- }
- cursorOnOff(cursor); /* redisplay cursor if required */
- if (visibleBell == AUDIBLE_BELL || visibleBell == BOTH_AV_BELL)
- outp(ADDR_BUZZAR, status); /* buzzar off */
- }
-
- /*
- ** void textCRTOnOff(int onOff)
- *
- * display text CRT or hide it
- *
- * actually Off means clearing of current page
- * backlight is turned off
- */
- void textCRTOnOff(onOff)
- int onOff;
- {
- if (onOff == NO) {
- clearCurrentPage();
- outp(0xe8, 0xb05a); /* back light off */
- } else
- outp(0xe8, 0xbf5a); /* back light on */
- }
-
- void setBorder(col)
- int col;
- {
- /* not supported */
- }
- #endif /* J3100 */
-