home *** CD-ROM | disk | FTP | other *** search
- /* os2.c */
-
- /*
- * Author:
- * Greg Roelofs (roe2@midway.uchicago.edu). Based on Guntram Blohm's
- * pc.c; MSC 6.0 headers; and PC Magazine Environments columns, 22 Dec
- * 1987 and 15 Nov 1988.
- *
- * This file implements the OS/2 VIO interface.
- * Most recent revisions: 4 Jun 92
- */
-
- #if OS2
-
- #define INCL_NOPM
- #define INCL_DOS
- #define INCL_KBD
- #define INCL_VIO
- #include <os2.h>
-
- #define GOT_OS2_H
-
- #include "config.h"
- #include "vi.h"
-
- #ifndef MAX
- # define MAX(a,b) ((a) > (b)? (a) : (b))
- #endif
-
- /* vmode contains the screen attribute index and is set by attrset
- * (stupid name, sigh...) */
- int vmode;
-
- /* The following array contains attribute definitions for color/monochrome
- * attributes. The variable "screen" selects one of the sets. Maybe some-
- * one will put them into elvis options one day.
- */
- static int screen;
- static char attr[2][8] =
- { /* :se: :so: :VB: :ul: :as: popup visible quit */
- /*{0x1f, 0x1d, 0x1e, 0x1a, 0x1c, 0x2f, 0x3f, 0x07},*/ /* color */
- {0x02, 0x0c, 0x0a, 0x01, 0x09, 0x17, 0x20, 0x02}, /* color */
- {0x07, 0x70, 0x0f, 0x01, 0x0f, 0x70, 0x70, 0x07}, /* mono */
- };
-
- static USHORT row, col; /* static for addressing efficiency */
- static VIOMODEINFO viomi_init;
- static VIOCURSORINFO vioci_init;
- #if !FASTPUT
- static ansi_flag = FALSE;
- #endif
-
-
- int biosquit()
- {
- vmode = 7; /* "quit" attribute */
- v_ce();
- }
-
-
- /* this function changes the table of attribute bytes used during BIOS output */
- int bioscolor(mode, attrbyte)
- int mode; /* e.g., A_NORMAL */
- int attrbyte; /* color code, as a PC attribute byte */
- {
- attr[0][mode] = attrbyte;
- return 0;
- }
-
-
- /* one routine to set (or clear) raw mode on both stdin and stdout */
- void raw_set_stdio(rawstate)
- int rawstate; /* TRUE -> set raw mode; FALSE -> clear raw mode */
- {
- if (rawstate) {
- setmode(0, O_BINARY);
- setmode(1, O_BINARY); /* GRR: may need to trap ^C here */
- } else {
- setmode(0, O_TEXT);
- setmode(1, O_TEXT);
- }
- }
-
-
-
-
-
-
- /* cursor up: determine current position, decrement row, set position */
- void v_up()
- {
- VioGetCurPos(&row, &col, 0);
- --row;
- VioSetCurPos(MAX(row,0), col, 0);
- }
-
- #ifndef NO_CURSORSHAPE
-
- /* cursor big: set begin scan to end scan - 4 */
- void v_cb()
- {
- VIOCURSORINFO vioci = vioci_init;
-
- vioci.yStart = vioci.cEnd - 4; /* cEnd never changes */
- VioSetCurType(&vioci, 0);
- }
-
- /* cursor small: set begin scan to end scan - 1 */
- void v_cs()
- {
- VIOCURSORINFO vioci = vioci_init;
-
- vioci.yStart = vioci.cEnd - 1; /* cEnd never changes */
- VioSetCurType(&vioci, 0);
- }
-
- #endif /* !NO_CURSORSHAPE */
-
- /* clear to end: get cursor position and emit the aproppriate number
- * of spaces, without moving cursor */
- void v_ce()
- {
- CHAR cell[3] = {' ', (CHAR)attr[screen][vmode], '\0'};
- USHORT count;
-
- VioGetCurPos(&row, &col, 0);
- count = COLS - col;
- VioWrtNCell(cell, count, row, col, 0);
- }
-
- /* clear screen: clear all and set cursor home */
- void v_cl()
- {
- CHAR cell[3] = {' ', (CHAR)attr[screen][vmode], '\0'};
-
- VioScrollUp(0, 0, -1, -1, -1, cell, 0);
- VioSetCurPos(0, 0, 0);
- }
-
- /* clear to bottom: get position, clear to eol, clear next line to end */
- void v_cd()
- {
- CHAR cell[3] = {' ', (CHAR)attr[screen][vmode], '\0'};
- USHORT count;
-
- VioGetCurPos(&row, &col, 0);
- count = COLS - col;
- VioWrtNCell(cell, count, row, col, 0);
- VioScrollUp(row+1, 0, -1, -1, -1, cell, 0);
- /* VioScrollUp(row+1, 0, LINES-1, COLS-1, -1, cell, 0); */
- }
-
- /* add line: scroll rest of screen down */
- void v_al()
- {
- CHAR cell[3] = {' ', (CHAR)attr[screen][vmode], '\0'};
-
- VioGetCurPos(&row, &col, 0);
- VioScrollDn(row, 0, -1, -1, 1, cell, 0);
- }
-
- /* delete line: scroll rest up */
- void v_dl()
- {
- CHAR cell[3] = {' ', (CHAR)attr[screen][vmode], '\0'};
-
- VioGetCurPos(&row, &col, 0);
- VioScrollUp(row, 0, -1, -1, 1, cell, 0);
- }
-
- /* scroll reverse: scroll whole screen */
- void v_sr()
- {
- CHAR cell[3] = {' ', (CHAR)attr[screen][vmode], '\0'};
-
- VioScrollDn(0, 0, -1, -1, 1, cell, 0);
- }
-
- /* void v_move(x,y) VioSetCurPos() call put directly in curses move() macro */
-
-
- /* put character (under DOS, set attribute first, then execute char--to do
- * so under OS/2 requires several more function calls and is more than twice
- * as slow, so allow choice with FASTPUT); also remember if current line has
- * changed */
- int v_put(ch)
- int ch;
- {
- CHAR cell[3] = {' ', (CHAR)attr[screen][vmode], '\0'};
-
- *cell = (CHAR) (ch &= 0xff);
- #if FASTPUT
- VioWrtTTY(cell, 1, 0); /* only using char, not attribute */
- if (ch == '\n')
- exwrote = TRUE;
- #else /* !FASTPUT */
- VioGetCurPos(&row, &col, 0);
- if (ch >= ' ')
- VioWrtNCell(cell, 1, row, col, 0); /* write attributes */
- VioWrtTTY(cell, 1, 0); /* move cursor */
- if (ch == '\n')
- {
- exwrote = TRUE;
- /* video(0xe0d, (int *)0, (int *)0); */ /* GRR: necessary? */
- }
- #endif /* ?FASTPUT */
- return ch;
- }
-
-
- /* determine size of screen and set of attributes to use, and store
- * initial state */
- void v_vio_init(pRows, pCols)
- int *pRows, *pCols;
- {
- CHAR cell[3];
- USHORT count = 2;
-
- viomi_init.cb = sizeof(viomi_init);
- VioGetMode(&viomi_init, 0);
- VioGetCurType(&vioci_init, 0);
-
- *pRows = viomi_init.row;
- *pCols = viomi_init.col;
- screen = (viomi_init.color == COLORS_16)? 0 : 1;
-
- /* get attribute of first character on last row and save for exit */
- VioReadCellStr(cell, &count, viomi_init.row-1, 0, 0);
- if (count > 0)
- attr[0][7] = cell[1]; /* "quit" attribute */
-
- #if !FASTPUT /* if we're going to spend time writing attributes,
- * make sure it's not wasted... */
- VioGetAnsi(&count, 0);
- if (count == ANSI_ON) {
- VioSetAnsi(ANSI_OFF, 0);
- ansi_flag = TRUE;
- }
- #endif /* !FASTPUT */
- }
-
- /* restore initial video state, at least partially */
- void v_vio_restore()
- {
- #if !FASTPUT
- if (ansi_flag)
- VioSetAnsi(ANSI_ON, 0);
- #endif /* !FASTPUT */
- }
-
- /* this function returns the DOS time as a 32-bit long int representing
- * hundredths of a second since midnight */
- static long dostime()
- {
- DATETIME dt;
-
- DosGetDateTime(&dt);
- return (((dt.hours*60L) + dt.minutes)*60L + dt.seconds)*100L +
- dt.hundredths;
- }
-
-
- /*ARGSUSED*/
- /* This function implements a raw read from the keyboard, with timeout. */
- int ttyread(buf, len, time)
- char *buf; /* where to store the keystrokes */
- int len; /* maximum number of characters to get -- ignored */
- int time; /* maximum time to wait, in 1/9th second increments */
- {
- long stop;
-
- /* are we going to time out? */
- if (time != 0)
- {
- /* compute the time when we'll give up */
- stop = dostime() + time * 10L;
-
- /* wait for either keystroke or timeout */
- while (!kbhit())
- if (dostime() > stop) /* couldn't read any chars */
- return 0; /* before timeout */
- }
-
- /* get a keystroke */
- *buf = getch();
- if (*buf == 0) /* function key? */
- {
- buf[0] = '#';
- buf[1] = getch();
- return 2;
- }
- else
- return 1;
- }
-
- int sleep(seconds)
- unsigned seconds;
- {
- DosSleep((ULONG)seconds);
- return 0;
- }
-
- #endif /* OS2 */
-