| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#include <dpmi.h> |
| 12 |
#include <go32.h> |
| 13 |
#include <sys/farptr.h> |
| 14 |
#include <stdio.h> |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#define BIOSINT 0x10 |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#define B_MOVECURSOR 2 |
| 24 |
#define B_UPSCROLL 6 |
| 25 |
#define B_UPSCROLL_1 0x0601 |
| 26 |
#define B_DOWNSCROLL 7 |
| 27 |
#define B_DOWNSCROLL_1 0x0701 |
| 28 |
#define B_CLEAR_REGION 0x0600 |
| 29 |
#define B_WRITECHAR 9 |
| 30 |
|
| 31 |
#define B_TTYWRITE 0x0e |
| 32 |
#define B_GETMODE 0x0f |
| 33 |
#define B_SETPALETTE 0x10 |
| 34 |
#define B_EGACGEN 0x11 |
| 35 |
#define B_VCONFIG 0x12 |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
#define B_EGATEST 0x30 |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
#define BIOSEQUIP 0x11 |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
#define DEF_ROW_MAX 24 |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#define EQUIP_MONO 0x30 |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#define BWT25X80 2 |
| 62 |
#define CT25X80 3 |
| 63 |
#define MT25X80 7 |
| 64 |
|
| 65 |
union vcell { |
| 66 |
struct { |
| 67 |
char vchar; |
| 68 |
unsigned char vattr; |
| 69 |
} ca; |
| 70 |
unsigned short s; |
| 71 |
}; |
| 72 |
|
| 73 |
unsigned long scrbase; |
| 74 |
static char col_max, row_max; |
| 75 |
static char video_mode; |
| 76 |
static char video_page; |
| 77 |
|
| 78 |
extern int usebios; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
static int bios_flag; |
| 84 |
|
| 85 |
|
| 86 |
void oss_con_init(void) |
| 87 |
{ |
| 88 |
int ega = 0; |
| 89 |
__dpmi_regs regs; |
| 90 |
|
| 91 |
regs.x.bx = regs.x.dx = 0; |
| 92 |
regs.h.ah = B_EGACGEN; |
| 93 |
regs.h.al = B_EGATEST; |
| 94 |
__dpmi_int(BIOSINT, ®s); |
| 95 |
if (regs.h.dl) { |
| 96 |
ega = 1; |
| 97 |
row_max = regs.h.dl; |
| 98 |
} |
| 99 |
else |
| 100 |
row_max = DEF_ROW_MAX; |
| 101 |
regs.h.ah = B_GETMODE; |
| 102 |
__dpmi_int(BIOSINT, ®s); |
| 103 |
col_max = regs.h.ah - 1; |
| 104 |
video_mode = regs.h.al; |
| 105 |
video_page = regs.h.bh; |
| 106 |
bios_flag = usebios; |
| 107 |
if (bios_flag) return; |
| 108 |
if (video_mode == MT25X80) { |
| 109 |
__dpmi_int(BIOSEQUIP, ®s); |
| 110 |
if ((regs.x.ax & EQUIP_MONO) == EQUIP_MONO) |
| 111 |
|
| 112 |
scrbase = 0xb0000; |
| 113 |
} else { |
| 114 |
|
| 115 |
if (video_mode > CT25X80 || !ega) { |
| 116 |
bios_flag = 1; |
| 117 |
return; |
| 118 |
} |
| 119 |
scrbase = 0xb8000; |
| 120 |
} |
| 121 |
if (video_page == 1) |
| 122 |
scrbase += 0x1000; |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
void oss_con_uninit(void) |
| 127 |
{ |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
void ossscu(int top, int left, int bottom, int right, int blank_color) |
| 136 |
{ |
| 137 |
__dpmi_regs regs; |
| 138 |
|
| 139 |
regs.h.ch = top; |
| 140 |
regs.h.cl = left; |
| 141 |
regs.h.dh = bottom; |
| 142 |
regs.h.dl = right; |
| 143 |
regs.h.bh = blank_color; |
| 144 |
regs.x.ax = B_DOWNSCROLL_1; |
| 145 |
__dpmi_int(BIOSINT, ®s); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
void ossscr(int top, int left, int bottom, int right, int blank_color) |
| 154 |
{ |
| 155 |
__dpmi_regs regs; |
| 156 |
|
| 157 |
regs.h.ch = top; |
| 158 |
regs.h.cl = left; |
| 159 |
regs.h.dh = bottom; |
| 160 |
regs.h.dl = right; |
| 161 |
regs.h.bh = blank_color; |
| 162 |
regs.x.ax = B_UPSCROLL_1; |
| 163 |
__dpmi_int(BIOSINT, ®s); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
void ossclr(int top, int left, int bottom, int right, int color) |
| 170 |
{ |
| 171 |
__dpmi_regs regs; |
| 172 |
|
| 173 |
|
| 174 |
if (top > bottom || left > right) |
| 175 |
return; |
| 176 |
|
| 177 |
regs.h.ch = top; |
| 178 |
regs.h.cl = left; |
| 179 |
regs.h.dh = bottom; |
| 180 |
regs.h.dl = right; |
| 181 |
regs.h.bh = color; |
| 182 |
regs.x.ax = B_CLEAR_REGION; |
| 183 |
__dpmi_int(BIOSINT, ®s); |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
void ossloc(int row, int column) |
| 191 |
{ |
| 192 |
__dpmi_regs regs; |
| 193 |
|
| 194 |
regs.h.dh = row; |
| 195 |
regs.h.dl = column; |
| 196 |
regs.h.bh = video_page; |
| 197 |
regs.h.ah = B_MOVECURSOR; |
| 198 |
__dpmi_int(BIOSINT, ®s); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
int ossmon(void) |
| 205 |
{ |
| 206 |
return video_mode == MT25X80; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
void ossdsp(int y, int x, int color, char *s) |
| 213 |
{ |
| 214 |
if (bios_flag) { |
| 215 |
__dpmi_regs regs; |
| 216 |
|
| 217 |
while (*s) { |
| 218 |
ossloc(y, x++); |
| 219 |
regs.h.ah = B_WRITECHAR; |
| 220 |
regs.h.al = *s++; |
| 221 |
regs.h.bh = video_page; |
| 222 |
regs.h.bl = color; |
| 223 |
regs.x.cx = 1; |
| 224 |
__dpmi_int(0x10, ®s); |
| 225 |
} |
| 226 |
} else { |
| 227 |
union vcell vc; |
| 228 |
unsigned long vp; |
| 229 |
char *p = s; |
| 230 |
|
| 231 |
vp = scrbase + ((y * 80 + x) << 1); |
| 232 |
vc.ca.vattr = color; |
| 233 |
_farsetsel(_go32_conventional_mem_selector()); |
| 234 |
while (*p) { |
| 235 |
vc.ca.vchar = *p++; |
| 236 |
_farnspokew(vp, vc.s); |
| 237 |
vp += 2; |
| 238 |
} |
| 239 |
ossloc(y, x + (p - s - (*s ? 1 : 0))); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
void ossgmx(int *max_line, int *max_column) |
| 247 |
{ |
| 248 |
*max_line = row_max; |
| 249 |
*max_column = col_max; |
| 250 |
} |
| 251 |
|
| 252 |
int ossvpg(char pg) |
| 253 |
{ |
| 254 |
int ret; |
| 255 |
__dpmi_regs regs; |
| 256 |
|
| 257 |
if (pg == video_page) return(video_page); |
| 258 |
ret = video_page; |
| 259 |
video_page = pg; |
| 260 |
regs.h.ah = 5; |
| 261 |
regs.h.al = pg; |
| 262 |
__dpmi_int(BIOSINT, ®s); |
| 263 |
if (video_page == 1) |
| 264 |
scrbase += 0x1000; |
| 265 |
else |
| 266 |
scrbase -= 0x1000; |
| 267 |
return(ret); |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
int oss_eof_on_stdin() |
| 274 |
{ |
| 275 |
return feof(stdin); |
| 276 |
} |