-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathega.cpp
356 lines (315 loc) · 6.16 KB
/
ega.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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "image.h"
#include "types.h"
#include "memory.h"
#include "ega.h"
#ifdef __GNUC__
#include <iostream>
using namespace std;
#endif
/* mode, width, height, bytes_per_line, base_addr, bpp, Bpp, colors, vsync_reg, scale */
const adapter::video_mode ega::video_modes[] = {
{TEXT,80,25,80,0xb800,1,8,0xF,0x3da,0},
{EGAMONO,640,350,80,0xa000,1,1,0x1,0x3da,0},
{EGAHI,640,350,320,0xa000,4,1,0xF,0x3da,0},
{EGALO,320,200,160,0xa000,4,1,0xF,0x3da,2},
{X16,160,100,160,0xb800,1,8,0xF,0x3da,4}
};
ega::ega(void)
{
_savedvmode = getmode();
}
ega::~ega(void)
{
setmode(_savedvmode);
}
bool ega::setup(void)
{
for (unsigned long int i=0;i<sizeof(video_modes);i++) {
if (video_modes[i].mode == _vmode) {
_row_bytes = video_modes[i].bytes;
_width = video_modes[i].x;
_height = video_modes[i].y;
bpp = video_modes[i].bpp;
Bpp = 8/bpp;
planes = video_modes[i].planes;
colors = video_modes[i].colors;
SR = video_modes[i].sr;
buf_size = _row_bytes*_height;
#ifdef __BORLANDC__
_buffer = (unsigned char far *) MK_FP(video_modes[i].fp,0);
screen.size(_width,_height);
#endif
return true;
}
}
return false;
}
void ega::setmode(Mode mode)
{
#ifdef __BORLANDC__
_AL=(unsigned char) mode;
_AH=0;
geninterrupt(0x10);
#endif
}
bool ega::graphmode(Mode mode)
{
switch (mode) {
case TEXT:
return textmode();
case X16:
setpalette(palette::TEXT_PAL);
return x16mode();
case EGALO:
case EGAHI:
setpalette(palette::TEXT_PAL);
break;
case EGAMONO:
setpalette(palette::BW_PAL);
break;
case CGALO1:
case CGALO2:
case CGAHI:
case COMPAQ:
case HERC:
case BWTEXT:
case PCJRLO:
case PCJRMED:
case PCJRHI:
case EGAMED:
case VGAMONO:
case VGAHI:
case VGALO:
case SVGA:
case XGA:
case HD:
case FHD:
case UNDEF:
return false;
}
_vmode=mode;
setmode(_vmode);
return setup();
}
bool ega::textmode(void)
{
#ifdef __BORLANDC__
_AL=0x03;
_AH=0;
geninterrupt(0x10);
return setup();
#else
return true;
#endif
}
bool ega::x16mode(void)
{
#ifdef __BORLANDC__
unsigned char status;
unsigned char switches;
_AL=(unsigned char) TEXT;
_AH=0;
geninterrupt(0x10);
_AH=0x12;
_AL=0;
_BL=0x10;
geninterrupt(0x10); /* get EGA switch settings */
switches = _CL;
_AL=0x03;
_AH=0x10;
_BL=0;
geninterrupt(0x10); /* turn off blink via EGA BIOS */
/* EGA hires mode is 640x350 with a 9x14 character cell. The pixel aspect
ratio is 1:1.37, so if we make the blocks 3 scans tall you get a square
pixel at 160x100, but some of the scan lines are not used (50) */
if (
switches == 0x09 || /* EGA Hires monitor attached, 9x14 */
switches == 0xB /* EGA with Monochrome monitor, 9x14 */
) {
write_crtc(CRTCb,0x09,0x02);
} else { /* Must be CGA 8x8 on EGA card */
write_crtc(CRTCb,0x09,0x01);
}
_vmode=X16;
return setup();
#else
return true;
#endif
}
void ega::write_crtc(unsigned int port, unsigned char reg, unsigned char val)
{
#ifdef __BORLANDC__
outportb(port, reg);
outportb(port+1,val);
#endif
}
adapter::Mode ega::getmode(void)
{
#ifdef __BORLANDC__
_AX=0x0f00;
geninterrupt(0x10);
_vmode=(Mode)_AL;
return (_vmode);
#else
return _vmode;
#endif
}
void ega::cls(void)
{
screen.clear();
update();
}
void ega::update(void)
{
vsync();
translate(screen._buffer);
}
void ega::translate(ptr_t src)
{
#ifdef __BORLANDC__
switch (_vmode) {
case TEXT:
_CX=buf_size>>1;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
_DS=_BX;
_AX=FP_SEG(_buffer);
_ES=_AX;
xlate:
asm {
lodsw // 5
mov bx, ax
shl ax,8
mov al,0xDB
stosw
mov ax, bx
mov al,0xDB
stosw
loop xlate // 15
} // 44
break;
case X16:
#ifdef i86
_CX=buf_size>>1;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
_DS=_BX;
_AX=FP_SEG(_buffer);
_ES=_AX;
xlate16:
asm {
lodsw // 5
shl al, 4 // 3
or ah, al // 2
mov al, 0xde // 2
stosw // 4
loop xlate16 // 15
} // 44
#else
_CX=buf_size>>2;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
_DS=_BX;
_AX=FP_SEG(_buffer);
_ES=_AX;
xlate32:
asm {
lodsd // 5
//and eax, 0x0F0F0F0F // 2
shl al, 4 // 3
or ah, al // 2
mov al, 0xde // 2
ror eax, 16 // 3
shl al, 4 // 3
or ah, al // 2
mov al, 0xde // 2
rol eax, 16 // 3
stosd // 4
loop xlate32 // 15
} // 44
#endif
break;
case EGALO:
_CX=buf_size<<1;
_DI=FP_OFF(_buffer);
_SI=FP_OFF(src);
_BX=FP_SEG(src);
_DS=_BX;
_AX=FP_SEG(_buffer);
_ES=_AX;
asm { // setup write mode 2
mov dx, GDCi
mov al, 5
out dx, al
inc dx
mov al, 0x02
out dx, al
mov dx, SCi
mov al, 2
out dx, al
mov al, 0x0F
inc dx
out dx, al
mov dx, GDCi
mov al, 3
out dx, al
inc dx
mov al, 0
out dx, al
mov dx, GDCi
mov al, 8
out dx, al // select bit mask register
inc dx
mov al, 0x80
}
xlatelo:
asm{
out dx, al // mask current pixel bit
mov ah,al
mov al,es:[di]
lodsb
stosb
mov al,ah
ror al, 1 // shift mask right 1 bit/pixel
jc incdi
dec di
}
incdi:
asm {
loop xlatelo
} // 44
break;
}
#endif
}
void ega::vsync(void)
{
#ifdef __BORLANDC__
unsigned char p;
do {
p=inportb(SR);
} while (p & 8);
do {
p=inportb(SR);
} while (!(p & 8));
#endif
}
bool ega::setpalette(palette::pal_type pal)
{
// TODO
_cur_palette = pal;
return true;
}
bool ega::setpalette(palette::pal_t *pal, int palette_entries)
{
// TODO
return true;
}