-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvga13h.c
80 lines (60 loc) · 1.2 KB
/
vga13h.c
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
#include <i86.h>
#include <conio.h>
#include <string.h> // for memset
#include "vga13h.h"
#ifdef __386__
#define DO_INT(i, r_in, r_out) int386(i, r_in, r_out)
#define VGA_MEMORY 0xA0000
#else
#define DO_INT(i, r_in, r_out) int86(i, r_in, r_out)
#define VGA_MEMORY 0xA0000000L
#endif
static unsigned char default_palette[768];
void set_mode13h()
{
union REGS regs;
regs.w.ax = 0x13;
DO_INT(0x10, ®s, ®s);
dump_palette(default_palette);
}
void unset_mode13h()
{
union REGS regs;
regs.w.ax = 0x3;
DO_INT(0x10, ®s, ®s);
}
void copy_buffer(unsigned char* buffer)
{
memcpy((unsigned char *)VGA_MEMORY, buffer, 64000);
}
void clear_buffer(unsigned char* buffer)
{
memset(buffer, 0, 64000);
}
void retrace()
{
while (!(inp(0x03da) & 8))
;
while ((inp(0x03da) & 8))
;
}
void set_palette(unsigned char* palette)
{
int i;
outp(0x03c8, 0);
for (i = 0; i < 768; i++) {
outp(0x03c9, palette[i]);
}
}
void dump_palette(unsigned char* palette)
{
int i;
outp(0x03c7, 0);
for (i = 0; i < 768; i++) {
palette[i] = inp(0x03c9);
}
}
void reset_palette()
{
set_palette(default_palette);
}