summaryrefslogtreecommitdiff
path: root/util/vgabios/int10.c
blob: 21ba7fbfa7f593f63ea95a7b4a643c5eb0de9744 (plain)
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#include <stdio.h>
#include <stdtypes.h>
#include "testbios.h"

extern int verbose;


#ifndef _PC
/*
 * This is derived from a number of PC system BIOS'es.  The intent here is to
 * provide very primitive video support, before an EGA/VGA BIOS installs its
 * own interrupt vector.  Here, "Ignored" calls should remain so.  "Not
 * Implemented" denotes functionality that can be implemented should the need
 * arise.  What are "Not Implemented" throughout are video memory accesses.
 * Also, very little input validity checking is done here.
 */
int int42_handler(void)
{
#if 0
	if (verbose && X86_AH != 0x0e) {
		printf("int%x\n", current->num);
		x86emu_dump_xregs();
	}

	switch (X86_AH) {
	case 0x00:
		/* Set Video Mode                                     */
		/* Enter:  AL = video mode number                     */
		/* Leave:  Nothing                                    */
		/* Implemented (except for clearing the screen)       */
		{		/* Localise */
			int i;
			u16 ioport, int1d, regvals, tmp;
			u8 mode, cgamode, cgacolour;

			/*
			 * Ignore all mode numbers but 0x00-0x13.  Some systems also ignore
			 * 0x0B and 0x0C, but don't do that here.
			 */
			if (X86_AL > 0x13)
				break;

			/*
			 * You didn't think that was really the mode set, did you?  There
			 * are only so many slots in the video parameter table...
			 */
			mode = X86_AL;
			ioport = 0x03D4;
			switch (MEM_RB(0x0410) & 0x30) {
			case 0x30:	/* MDA */
				mode = 0x07;	/* Force mode to 0x07 */
				ioport = 0x03B4;
				break;
			case 0x10:	/* CGA 40x25 */
				if (mode >= 0x07)
					mode = 0x01;
				break;
			case 0x20:	/* CGA 80x25 (MCGA?) */
				if (mode >= 0x07)
					mode = 0x03;
				break;
			case 0x00:	/* EGA/VGA */
				if (mode >= 0x07)	/* Don't try MDA timings */
					mode = 0x01;	/* !?!?! */
				break;
			}

			/* Locate data in video parameter table */
			int1d = MEM_RW(0x1d << 2);
			regvals = ((mode >> 1) << 4) + int1d;
			cgacolour = 0x30;
			if (mode == 0x06) {
				regvals -= 0x10;
				cgacolour = 0x3F;
			}

	    /** Update BIOS Data Area **/

			/* Video mode */
			MEM_WB(0x0449, mode);

			/* Columns */
			tmp = MEM_RB(mode + int1d + 0x48);
			MEM_WW(0x044A, tmp);

			/* Page length */
			tmp = MEM_RW((mode & 0x06) + int1d + 0x40);
			MEM_WW(0x044C, tmp);

			/* Start Address */
			MEM_WW(0x044E, 0);

			/* Cursor positions, one for each display page */
			for (i = 0x0450; i < 0x0460; i += 2)
				MEM_WW(i, 0);

			/* Cursor start & end scanlines */
			tmp = MEM_RB(regvals + 0x0B);
			MEM_WB(0x0460, tmp);
			tmp = MEM_RB(regvals + 0x0A);
			MEM_WB(0x0461, tmp);

			/* Current display page number */
			MEM_WB(0x0462, 0);

			/* CRTC I/O address */
			MEM_WW(0x0463, ioport);

			/* CGA Mode register value */
			cgamode = MEM_RB(mode + int1d + 0x50);
			MEM_WB(0x0465, cgamode);

			/* CGA Colour register value */
			MEM_WB(0x0466, cgacolour);

			/* Rows */
			MEM_WB(0x0484, (25 - 1));

			/* Programme the mode */
			outb(ioport + 4, cgamode & 0x37);	/* Turn off screen */
			for (i = 0; i < 0x10; i++) {
				tmp = MEM_RB(regvals + i);
				outb(ioport, i);
				outb(ioport + 1, tmp);
			}
			outb(ioport + 5, cgacolour);	/* Select colour mode */
			outb(ioport + 4, cgamode);	/* Turn on screen */
		}
		break;

	case 0x01:
		/* Set Cursor Type                                    */
		/* Enter:  CH = starting line for cursor              */
		/*         CL = ending line for cursor                */
		/* Leave:  Nothing                                    */
		/* Implemented                                        */
		{		/* Localise */
			u16 ioport = MEM_RW(0x0463);

			MEM_WB(0x0460, X86_CL);
			MEM_WB(0x0461, X86_CH);

			outb(ioport, 0x0A);
			outb(ioport + 1, X86_CH);
			outb(ioport, 0x0B);
			outb(ioport + 1, X86_CL);
		}
		break;

	case 0x02:
		/* Set Cursor Position                                */
		/* Enter:  BH = display page number                   */
		/*         DH = row                                   */
		/*         DL = column                                */
		/* Leave:  Nothing                                    */
		/* Implemented                                        */
		{		/* Localise */
			u16 offset, ioport;

			MEM_WB((X86_BH << 1) + 0x0450, X86_DL);
			MEM_WB((X86_BH << 1) + 0x0451, X86_DH);

			if (X86_BH != MEM_RB(0x0462))
				break;

			offset = (X86_DH * MEM_RW(0x044A)) + X86_DL;
			offset += MEM_RW(0x044E) << 1;

			ioport = MEM_RW(0x0463);
			outb(ioport, 0x0E);
			outb(ioport + 1, offset >> 8);
			outb(ioport, 0x0F);
			outb(ioport + 1, offset & 0xFF);
		}
		break;

	case 0x03:
		/* Get Cursor Position                                */
		/* Enter:  BH = display page number                   */
		/* Leave:  CH = starting line for cursor              */
		/*         CL = ending line for cursor                */
		/*         DH = row                                   */
		/*         DL = column                                */
		/* Implemented                                        */
		{		/* Localise */
			X86_CL = MEM_RB(0x0460);
			X86_CH = MEM_RB(0x0461);
			X86_DL = MEM_RB((X86_BH << 1) + 0x0450);
			X86_DH = MEM_RB((X86_BH << 1) + 0x0451);
		}
		break;

	case 0x04:
		/* Get Light Pen Position                             */
		/* Enter:  Nothing                                    */
		/* Leave:  AH = 0x01 (down/triggered) or 0x00 (not)   */
		/*         BX = pixel column                          */
		/*         CX = pixel row                             */
		/*         DH = character row                         */
		/*         DL = character column                      */
		/* Not Implemented                                    */
		{		/* Localise */
			printf("int%x - Get Light Pen Position. "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();
			X86_AH = X86_BX = X86_CX = X86_DX = 0;
		}
		break;

	case 0x05:
		/* Set Display Page                                   */
		/* Enter:  AL = display page number                   */
		/* Leave:  Nothing                                    */
		/* Implemented                                        */
		{		/* Localise */
			u16 start, ioport = MEM_RW(0x0463);
			u8 x, y;

			/* Calculate new start address */
			MEM_WB(0x0462, X86_AL);
			start = X86_AL * MEM_RW(0x044C);
			MEM_WW(0x044E, start);
			start <<= 1;

			/* Update start address */
			outb(ioport, 0x0C);
			outb(ioport + 1, start >> 8);
			outb(ioport, 0x0D);
			outb(ioport + 1, start & 0xFF);

			/* Switch cursor position */
			y = MEM_RB((X86_AL << 1) + 0x0450);
			x = MEM_RB((X86_AL << 1) + 0x0451);
			start += (y * MEM_RW(0x044A)) + x;

			/* Update cursor position */
			outb(ioport, 0x0E);
			outb(ioport + 1, start >> 8);
			outb(ioport, 0x0F);
			outb(ioport + 1, start & 0xFF);
		}
		break;

	case 0x06:
		/* Initialise or Scroll Window Up                     */
		/* Enter:  AL = lines to scroll up                    */
		/*         BH = attribute for blank                   */
		/*         CH = upper y of window                     */
		/*         CL = left x of window                      */
		/*         DH = lower y of window                     */
		/*         DL = right x of window                     */
		/* Leave:  Nothing                                    */
		/* Not Implemented                                    */
		{		/* Localise */
			printf("int%x: Initialise or Scroll Window Up - "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();
		}
		break;

	case 0x07:
		/* Initialise or Scroll Window Down                   */
		/* Enter:  AL = lines to scroll down                  */
		/*         BH = attribute for blank                   */
		/*         CH = upper y of window                     */
		/*         CL = left x of window                      */
		/*         DH = lower y of window                     */
		/*         DL = right x of window                     */
		/* Leave:  Nothing                                    */
		/* Not Implemented                                    */
		{		/* Localise */
			printf("int%x: Initialise or Scroll Window Down - "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();

		}
		break;

	case 0x08:
		/* Read Character and Attribute at Cursor             */
		/* Enter:  BH = display page number                   */
		/* Leave:  AH = attribute                             */
		/*         AL = character                             */
		/* Not Implemented                                    */
		{		/* Localise */
			printf
			    ("int%x: Read Character and Attribute at Cursor - "
			     "Function not implemented.\n", current->num);
			x86emu_dump_xregs();

			X86_AX = 0;
		}
		break;

	case 0x09:
		/* Write Character and Attribute at Cursor            */
		/* Enter:  AL = character                             */
		/*         BH = display page number                   */
		/*         BL = attribute (text) or colour (graphics) */
		/*         CX = replication count                     */
		/* Leave:  Nothing                                    */
		/* Not Implemented                                    */
		{		/* Localise */
			printf
			    ("int%x: Write Character and Attribute at Cursor - "
			     "Function not implemented.\n", current->num);
			x86emu_dump_xregs();

		}
		break;

	case 0x0a:
		/* Write Character at Cursor                          */
		/* Enter:  AL = character                             */
		/*         BH = display page number                   */
		/*         BL = colour                                */
		/*         CX = replication count                     */
		/* Leave:  Nothing                                    */
		/* Not Implemented                                    */
		{		/* Localise */
			printf("int%x: Write Character at Cursor - "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();

		}
		break;

	case 0x0b:
		/* Set Palette, Background or Border                  */
		/* Enter:  BH = 0x00 or 0x01                          */
		/*         BL = colour or palette (respectively)      */
		/* Leave:  Nothing                                    */
		/* Implemented                                        */
		{		/* Localise */
			u16 ioport = MEM_RW(0x0463) + 5;
			u8 cgacolour = MEM_RB(0x0466);

			if (X86_BH) {
				cgacolour &= 0xDF;
				cgacolour |= (X86_BL & 0x01) << 5;
			} else {
				cgacolour &= 0xE0;
				cgacolour |= X86_BL & 0x1F;
			}

			MEM_WB(0x0466, cgacolour);
			outb(ioport, cgacolour);
		}
		break;

	case 0x0c:
		/* Write Graphics Pixel                               */
		/* Enter:  AL = pixel value                           */
		/*         BH = display page number                   */
		/*         CX = column                                */
		/*         DX = row                                   */
		/* Leave:  Nothing                                    */
		/* Not Implemented                                    */
		{		/* Localise */
			printf("int%x: Write Graphics Pixel - "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();

		}
		break;

	case 0x0d:
		/* Read Graphics Pixel                                */
		/* Enter:  BH = display page number                   */
		/*         CX = column                                */
		/*         DX = row                                   */
		/* Leave:  AL = pixel value                           */
		/* Not Implemented                                    */
		{		/* Localise */
			printf("int%x: Write Graphics Pixel - "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();

			X86_AL = 0;

		}
		break;

	case 0x0e:
		/* Write Character in Teletype Mode                   */
		/* Enter:  AL = character                             */
		/*         BH = display page number                   */
		/*         BL = foreground colour                     */
		/* Leave:  Nothing                                    */
		/* Not Implemented                                    */
		/* WARNING:  Emulation of BEL characters will require */
		/*           emulation of RTC and PC speaker I/O.     */
		/*           Also, this recurses through int 0x10     */
		/*           which might or might not have been       */
		/*           installed yet.                           */
		{		/* Localise */
#ifdef PARANOID
			printf("int%x: Write Character in Teletype Mode - "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();
#endif
			printf("%c", X86_AL);
		}
		break;

	case 0x0f:
		/* Get Video Mode                                     */
		/* Enter:  Nothing                                    */
		/* Leave:  AH = number of columns                     */
		/*         AL = video mode number                     */
		/*         BH = display page number                   */
		/* Implemented                                        */
		{		/* Localise */
			X86_AH = MEM_RW(0x044A);
			X86_AL = MEM_RB(0x0449);
			X86_BH = MEM_RB(0x0462);
		}
		break;

	case 0x10:
		/* Colour Control (subfunction in AL)                 */
		/* Enter:  Various                                    */
		/* Leave:  Various                                    */
		/* Ignored                                            */
		break;

	case 0x11:
		/* Font Control (subfunction in AL)                   */
		/* Enter:  Various                                    */
		/* Leave:  Various                                    */
		/* Ignored                                            */
		break;

	case 0x12:
		/* Miscellaneous (subfunction in BL)                  */
		/* Enter:  Various                                    */
		/* Leave:  Various                                    */
		/* Ignored.  Previous code here optionally allowed    */
		/* the enabling and disabling of VGA, but no system   */
		/* BIOS I've come across actually implements it.      */
		break;

	case 0x13:
		/* Write String in Teletype Mode                      */
		/* Enter:  AL = write mode                            */
		/*         BL = attribute (if (AL & 0x02) == 0)       */
		/*         CX = string length                         */
		/*         DH = row                                   */
		/*         DL = column                                */
		/*         ES:BP = string segment:offset              */
		/* Leave:  Nothing                                    */
		/* Not Implemented                                    */
		/* WARNING:  Emulation of BEL characters will require */
		/*           emulation of RTC and PC speaker I/O.     */
		/*           Also, this recurses through int 0x10     */
		/*           which might or might not have been       */
		/*           installed yet.                           */
		{		/* Localise */
			printf("int%x: Write String in Teletype Mode - "
			       "Function not implemented.\n", current->num);
			x86emu_dump_xregs();

		}
		break;

	default:
		/* Various extensions                                 */
		/* Enter:  Various                                    */
		/* Leave:  Various                                    */
		/* Ignored                                            */
		break;
	}
#endif
	return 1;
}
#endif