-
Notifications
You must be signed in to change notification settings - Fork 0
/
low.c
87 lines (67 loc) · 1.32 KB
/
low.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
81
82
83
84
85
86
87
/*****************************************
Mroczna Harmonia
low.c Low level routines to access hardware
(C) 2001, 2023 M. Feliks
*****************************************/
#include <dos.h>
#include <i86.h>
#include <conio.h>
#include <string.h> // for memset
static unsigned char default_palette[768];
int is_key_pressed()
{
return kbhit() ? 1 : 0;
}
char get_key_code()
{
return getch();
}
void set_mode13h()
{
union REGS regs;
regs.w.ax = 0x13;
int86(0x10, ®s, ®s);
dump_palette(default_palette);
}
void unset_mode13h()
{
union REGS regs;
regs.w.ax = 0x3;
int86(0x10, ®s, ®s);
}
void copy_buffer(unsigned char* buffer)
{
unsigned char far* ptr_vidmem = (unsigned char far *)0xA0000000L;
memcpy(ptr_vidmem, 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* my_pal)
{
int i;
outp(0x03c8, 0);
for (i = 0; i < 768; i++) {
outp(0x03c9, my_pal[i]);
}
}
void dump_palette(unsigned char* my_pal)
{
int i;
outp(0x03c7, 0);
for (i = 0; i < 768; i++) {
my_pal[i] = inp(0x03c9);
}
}
void reset_palette()
{
set_palette(default_palette);
}