1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
/*
*
* MS-DOS terminal I/O. TTYIO.C
*/
#include "def.h"
#ifdef MSDOS
void ttopen ();
void ttclose (); /* stub */
int ttputc ();
void putline ();
void ttflush (); /* stub */
int ttkeyready ();
int ttgetc ();
void ttraw ();
void ttcooked ();
void set_crt_type ();
#include "dos.h"
int slot;
int scr_type;
#define SCREEN_PORT (video_port)
static int video_port =
{
0x1010
};
extern bool wang_pc;
extern bool ibm_pc;
int nrow; /* Terminal size, rows. */
int ncol; /* Terminal size, columns. */
int last_key;
uchar attr = 0x0f; /* saved color attribute, default
* white on black */
/*
* Initialization.
* for MS-DOS.
*/
void
ttopen ()
{
uchar *ptr;
uchar data[64];
if (wang_pc && !ibm_pc)
set_crt_type ();
nrow = NROW;
ncol = NCOL;
if (ibm_pc)
{
union REGS inregs, outregs;
struct SREGS segs;
int i;
for (i = 0; i < 64; i++)
data[i] = 0;
ptr = data;
inregs.h.ah = 0x1b;
inregs.h.al = 0;
inregs.x.bx = 0;
inregs.x.di = (int) data;
#ifdef FP_SEG /* this is for MSC 5.1 */
segs.es = FP_SEG (ptr);
#else /* this is for MSC 6.0 or 7.0 */
segs.es = _FP_SEG (ptr);
#endif
int86x (0x10, &inregs, &outregs, &segs); /* get number of rows */
/* if that failed then use the default */
if ((outregs.h.al != 0x1b) || (data[0x22] == 0))
return;
nrow = data[0x22];
/* get current attributes */
inregs.h.ah = 0x8;
inregs.h.al = 0;
inregs.h.bh = 0;
int86 (0x10, &inregs, &outregs);
attr = outregs.h.ah & 0x7f; /* don't want blink */
}
}
void
ttclose ()
{
}
void
ttflush ()
{
}
/*
* Write character.
*/
int
ttputc (c)
int c;
{
bdos (6, c, 0);
return c;
}
void
putline (row, startcol, stringsize, string)
int row, startcol, stringsize;
char *string;
{
extern int tthue;
unsigned short *screen;
int x, attribute;
char c_row, c_col, i;
union REGS regs;
if (ibm_pc)
{
c_row = row - 1;
c_col = startcol - 1;
for (i = 0; i < stringsize; i++)
{
regs.h.ah = 2;
regs.h.dh = c_row;
regs.h.dl = c_col;
regs.h.bh = 0;
int86 (0x10, ®s, ®s); /* set cursor position */
if (tthue == CTEXT)
regs.h.bl = attr;
if (tthue == CMODE)
regs.h.bl = ((0x70 & attr) >> 4) | ((0x07 & attr) << 4);
regs.h.ah = 9;
regs.h.bh = 0;
regs.h.al = string[i];
regs.x.cx = 1;
int86 (0x10, ®s, ®s); /* set cursor position */
c_col++;
}
}
else if (wang_pc)
{
if (tthue == CTEXT)
attribute = 0x00;
else
attribute = 0x02;
x = stringsize;
screen = (unsigned short *) WANG_CHARACTER_SCREEN;
screen += ((row - 1) * 80) + startcol - 1;
outp (SCREEN_PORT, 01);
while (x--)
{
*screen = (*string++ << 8) | attribute;
screen++;
}
outp (SCREEN_PORT, 00);
}
}
/*
* return with a TRUE if key was struck.
*/
int
ttkeyready ()
{
int cnt;
if (last_key != 0)
return (1);
last_key = bdos (6, 0xff, 0);
last_key &= 0xff;
if (last_key == 0)
return (0);
else
return (1);
}
/*
* Read character.
*/
int
ttgetc ()
{
int c;
if (last_key != 0)
{
c = last_key;
last_key = 0;
return (c);
}
ttcooked ();
c = (bdos (7, 0, 0) & 0xFF);
ttraw ();
return (c);
}
/* disable nasty cntrl-c during disk io!
*/
void
ttraw ()
{
union REGS inregs, outregs;
inregs.h.al = 1;
inregs.h.ah = 0x33;
inregs.h.dl = 0;
intdos (&inregs, &outregs);
/*
cntrlcoff();
*/
}
/* re enable cntrl-c for keyboard
*/
void
ttcooked ()
{
union REGS inregs, outregs;
inregs.h.al = 1;
inregs.h.ah = 0x33;
intdos (&inregs, &outregs);
inregs.h.dl = 1;
/*
cntrlcon();
*/
}
/* switch physical monitors
*/
static char str[] =
{
0x1b, '/', 1, 's'
};
void
set_crt_type ()
{
char active_screen;
active_screen = getscreenstate ();
slot = active_screen & 0x0f;
scr_type = (active_screen & 0x70) >> 4;
video_port = 0x1010 | (slot << 8);
}
#endif
|