-
Notifications
You must be signed in to change notification settings - Fork 9
/
d_video.cpp
406 lines (364 loc) · 8.83 KB
/
d_video.cpp
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/***************************************************************
BayCom(R) Packet-Radio fuer IBM PC
OpenBCM-Mailbox
------------------
DOS-Video-Routinen
------------------
Copyright (c) Florian Radlherr
Taubenbergstr. 32
83627 Warngau
Alle Rechte vorbehalten / All Rights reserved
***************************************************************/
#include "baycom.h"
/*---------------------------------------------------------------------------*/
video far *vram=NULL;
unsigned short vseg=0xb800;
unsigned bildzeilen=25;
unsigned bildspalten=80;
unsigned monochrome=0;
int novideo=0;
int cgadisp=0;
int monodisp=0;
char *vorne; // fuer jeden Bildpunkt, welches Fenster sichtbar ist
int wa = 0; // aktuell aktives Fenster
int video_off=0;
time_t video_timer=0;
static int vramcolor=1;
static unsigned doscursor;
static unsigned dossize;
#ifdef __HWSCREEN__
static struct text_info dosbildschirm;
#endif
static int vgabildaktiv=0;
/*---------------------------------------------------------------------------*/
static void near settextinfo (struct text_info *mode)
//*************************************************************************
//
// Momentanen Textmodus setzen
//
//*************************************************************************
{
#ifdef __HWSCREEN__
textattr(mode->attribute);
textmode(mode->currmode);
gotoxy(mode->curx,mode->cury);
#endif
}
/*---------------------------------------------------------------------------*/
static void near egalines (void)
//*************************************************************************
//
// Umschalten auf 43/50 Zeilenmodus bei EGA/VGA
//
//*************************************************************************
{
#ifdef __HWSCREEN__
_AX=3;
geninterrupt(0x10);
_BX=0;
_AL=18;
_AH=17;
geninterrupt(0x10);
_BX=32;
_AL=0;
_AH=32;
geninterrupt(0x10);
#endif
}
/*---------------------------------------------------------------------------*/
static int near setmaxlines (void)
//*************************************************************************
//
// Setzt den Bildschirm auf einen 8x8-Zeichensatz
//
//*************************************************************************
{
#ifdef __HWSCREEN__
union REGS rg;
if (ad_peekb(0x40, 0x84) == 24)
{
rg.x.ax = 0x1200; // Test, ob EGA vorhanden
rg.x.bx = 0xff10;
ad_int(0x10, &rg, &rg); // wenn EGA, bh=0-1 und bl=0-3
if (! (rg.x.bx & 0xfefc))
egalines();
}
return ad_peekb(0x40, 0x84)+1;
#else
return 25;
#endif
}
/*---------------------------------------------------------------------------*/
void video_close (void)
//*************************************************************************
//
// DOS-Bildschirm wiederherstellen
//
//*************************************************************************
{
#ifdef __HWSCREEN__
video *dossave;
int ok = 0;
handle fh;
if (vgabildaktiv && ! novideo)
{
settextinfo(&dosbildschirm);
dossave = (video *) t_malloc(dossize, "dosv");
if (dossave)
{
fh = _open(VIDNAME, O_RDONLY | O_BINARY);
if (fh != EOF)
{
if (_read(fh, dossave, dossize) == dossize)
{
copyToLow(vseg, 0, dossave, dossize);
ok = 1;
}
_close(fh);
}
t_free(dossave);
}
unlink(VIDNAME);
if (! ok)
clrscr();
_CX = doscursor;
_AX = 0x100;
geninterrupt(0x10);
}
#endif
vgabildaktiv = 0;
}
/*---------------------------------------------------------------------------*/
void dosabspeichern (int platz)
//*************************************************************************
//
// Speichert das die momentane Umgebung des DOS-Bildschirmes ab
//
//*************************************************************************
{
#ifdef __HWSCREEN__
handle fh;
video *dossave;
if (! novideo)
{
if (! vgabildaktiv)
{
gettextinfo(&dosbildschirm);
dossize = ad_peek(0x40, 0x4c);
if (platz)
dossave = (video *) t_malloc(dossize, "doss");
if (dossave)
{
copyFromLow(dossave, vseg, 0, dossize);
fh = _creat(VIDNAME, 0);
if (fh != EOF)
{
_write(fh, dossave, dossize);
_close(fh);
}
t_free(dossave);
}
doscursor = ad_peek(0x40, 0x60);
if (vramcolor && ! cgadisp)
bildzeilen = setmaxlines();
else
bildzeilen = ad_peekb(0x40,0x84)+1;
bildspalten = ad_peekb(0x40,0x4a);
if ((bildspalten<40) || (bildspalten>200)) // Plausi-Check
bildspalten = 80;
if ((bildzeilen<10) || (bildzeilen>100))
bildzeilen = 25;
_setcursortype(_SOLIDCURSOR);
putchar(0); // Cursor initialisieren
mausinit(bildzeilen-1, bildspalten-1);
}
vgabildaktiv=1;
}
else
video_off=1;
#endif
}
/*---------------------------------------------------------------------------*/
void video_open (void)
//*************************************************************************
//
// Stellt den Videomodus fest und schaltet ggf auf anderen Modus um
//
//*************************************************************************
{
#ifdef __HWSCREEN__
int i;
static int firstcall=1;
if (novideo)
{
video_off = 1;
vorne = (char *) t_malloc(bildzeilen*bildspalten, "*vsi");
for (i=0; i < (bildzeilen*bildspalten); i++)
vorne[i] = 0;
vram = (video *) t_malloc(bildzeilen*bildspalten*2, "*ssi");
vseg = FP_SEG(vram);
return;
}
gettextinfo(&dosbildschirm);
#ifdef __DPMI32__
_AH=0x0f;
geninterrupt(0x10);
if (_AL == 7)
{
vseg = 0xb000;
dosbildschirm.currmode = MONO;
}
else
vseg = 0xb800;
vram = (video *) t_malloc(20000, "*vid");
#else
if (dosbildschirm.currmode == MONO)
{
vram = (video far *) MK_FP(0xb000, 0);
vramcolor = 0;
vseg = 0xb000;
}
else
{
vram = (video far *) MK_FP(0xb800, 0);
vseg = 0xb800;
}
#endif
dosabspeichern(1);
if (firstcall)
{
firstcall = 0;
if ((dosbildschirm.currmode == MONO)
||(dosbildschirm.currmode == BW80) || monodisp)
monochrome = 1;
set_color();
vorne = (char *) t_malloc(bildzeilen*bildspalten, "*vor");
for (i=0; i < (bildzeilen*bildspalten); i++)
vorne[i]=0;
}
#endif
}
/*---------------------------------------------------------------------------*/
void video_setcursor (unsigned x, unsigned y)
{
#ifdef __HWSCREEN__
if (! video_off)
{
_DH=y;
_DL=x;
_BH=0;
_AH=2;
geninterrupt(0x10);
}
#endif
}
/*---------------------------------------------------------------------------*/
void video_putc (int x, int y, unsigned attr, unsigned c)
{
if (video_off)
return;
int index = x+bildspalten*y;
if (vorne[index] == wa)
{
vram[index] = c | (attr << 8);
#ifdef __DPMI32__
ad_poke(vseg, index << 1, c | attr << 8);
#endif
}
}
/*---------------------------------------------------------------------------*/
void video_puts (int x, int y, unsigned attr, char *s)
{
if (video_off)
return;
int index = x+bildspalten*y;
attr <<= 8;
while (*s)
{
if (vorne[index] == wa)
{
vram[index] = (*s) | attr;
#ifdef __DPMI32__
ad_poke(vseg, index << 1, (*s) | attr);
#endif
}
index++;
s++;
}
}
/*---------------------------------------------------------------------------*/
void wclear (int col)
{
int i, j;
int xmax;
int ymax = e->ylen-1+e->y;
int line;
video blank = ' ' | (col << 8);
if (video_off)
return;
e->wpos = 0;
for (j = e->y; j <= ymax; j++)
{
line = bildspalten*j;
xmax = e->xlen-1+e->x+line;
for (i = e->x+line; i <= xmax; i++)
{
if (vorne[i] == wa)
{
vram[i] = blank;
#ifdef __DPMI32__
ad_poke(vseg, i << 1, blank);
#endif
}
}
}
}
/*---------------------------------------------------------------------------*/
void video_update (void)
{
#ifdef __DPMI32__
if (! video_off)
{
copyToLow(vseg, 0, vram, bildzeilen * bildspalten * 2);
}
#endif
}
/*---------------------------------------------------------------------------*/
void video_switchon (void)
{
if (novideo)
return;
if (video_off)
{
video_off = 0;
allupdate++;
}
video_timer = ad_time()+m.crtsave*60;
}
/*---------------------------------------------------------------------------*/
void video_checkoff (int force)
{
if (novideo)
{
video_off = 1;
return;
}
if (video_timer == 0)
{
if (m.crtsave)
video_switchon();
else
return;
}
if (force || (ad_time() > video_timer && video_timer))
{
if(! video_off && m.crtsave)
{
video_setcursor(255, 255);
memset(vram, 0, bildzeilen * bildspalten*2);
video_update();
video_off = 1;
}
}
}
/*---------------------------------------------------------------------------*/