Debian Codegraph @

terps/tads/tads2/msdos/ossdosdj.c

raw symbols SCIP
1 /*
2 Name
3 ossdosdj.c - ossdos functions for DJGPP
4 Function
5
6 Notes
7
8 Modified
9 */
10
11 #include <dpmi.h>
12 #include <go32.h>
13 #include <sys/farptr.h>
14 #include <stdio.h>
15
16 /*
17 * BIOS video functions.
18 */
19 #define BIOSINT 0x10
20 /*
21 * BIOS video function numbers.
22 */
23 #define B_MOVECURSOR 2 /* Move cursor. */
24 #define B_UPSCROLL 6 /* Scroll window up. */
25 #define B_UPSCROLL_1 0x0601 /* Scroll window up 1 line. */
26 #define B_DOWNSCROLL 7 /* Scroll window down. */
27 #define B_DOWNSCROLL_1 0x0701 /* Scroll window down 1 line. */
28 #define B_CLEAR_REGION 0x0600 /* Clear region of screen. */
29 #define B_WRITECHAR 9 /* Write character & attribute at */
30 /* current position. */
31 #define B_TTYWRITE 0x0e /* Teletype-style write. */
32 #define B_GETMODE 0x0f /* Get video mode. */
33 #define B_SETPALETTE 0x10 /* Set palette registers. */
34 #define B_EGACGEN 0x11 /* EGA character generator. */
35 #define B_VCONFIG 0x12 /* Video subsystem configuration. */
36
37
38 /*
39 * Subfunctions for EGA character generator.
40 */
41 #define B_EGATEST 0x30
42
43 /*
44 * BIOS function to get equipment list.
45 */
46 #define BIOSEQUIP 0x11
47
48 /*
49 * Default number of rows in text modes.
50 */
51 #define DEF_ROW_MAX 24
52
53 /*
54 * Value returned by biosequip (in ax) to indicate a mono display.
55 */
56 #define EQUIP_MONO 0x30
57
58 /*
59 * Video modes.
60 */
61 #define BWT25X80 2 /* 25 x 80 black & white (CGA) text. */
62 #define CT25X80 3 /* 25 x 80 colour text. */
63 #define MT25X80 7 /* 25 x 80 monochrome (MDA) text. */
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; /* Screen dimensions. */
75 static char video_mode;
76 static char video_page;
77
78 extern int usebios;
79
80 /*
81 * Local copy of usebios because it gets overwritten by dbgu.c:dbguini()
82 */
83 static int bios_flag;
84
85 /* initialize console */
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; /* Do we have an EGA/VGA? */
94 __dpmi_int(BIOSINT, &regs);
95 if (regs.h.dl) {
96 ega = 1;
97 row_max = regs.h.dl; /* Yes: dl is number of rows - 1. */
98 }
99 else
100 row_max = DEF_ROW_MAX;
101 regs.h.ah = B_GETMODE;
102 __dpmi_int(BIOSINT, &regs);
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) { /* Mono text mode? */
109 __dpmi_int(BIOSEQUIP, &regs);
110 if ((regs.x.ax & EQUIP_MONO) == EQUIP_MONO)
111 /* Real mono system. */
112 scrbase = 0xb0000;
113 } else {
114 /* If graphics mode or no EGA/VGA */
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 /* uninitialize the console */
126 void oss_con_uninit(void)
127 {
128 /* nothing to do */
129 }
130
131 /*
132 * Scroll region down a line.
133 * This is equivalent to inserting a line at the top of the region.
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, &regs);
146 }
147
148 /*
149 * Scroll region up a line
150 * This is equivalent to deleting a line at the top of the region and pulling
151 * everything below it up.
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, &regs);
164 }
165
166 /*
167 * Clear the given region of the screen
168 */
169 void ossclr(int top, int left, int bottom, int right, int color)
170 {
171 __dpmi_regs regs;
172
173 /* if we're clearing an empty area, ignore it */
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, &regs);
184 }
185
186 /*
187 * Locate cursor at given line and column
188 * Line/column numbers start at zero (0)
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, &regs);
199 }
200
201 /*
202 * Return 1 if screen is monochrome, 0 otherwise
203 */
204 int ossmon(void)
205 {
206 return video_mode == MT25X80;
207 }
208
209 /*
210 * Display msg with color at coordinates (y, x)
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; /* count = 1 */
224 __dpmi_int(0x10, &regs);
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 * Return max screen size in *max_line and *max_column
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, &regs);
263 if (video_page == 1)
264 scrbase += 0x1000;
265 else
266 scrbase -= 0x1000;
267 return(ret);
268 }
269
270 /*
271 * is stdin at EOF?
272 */
273 int oss_eof_on_stdin()
274 {
275 return feof(stdin);
276 }