-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlow.c
125 lines (100 loc) · 2.26 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
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
/*****************************************
NAAGTRO version 2
low.c Low-level access to hardware
(C) March 5, 2023 M. Feliks
*****************************************/
#include <dos.h>
#include <dpmi.h>
#include <mem.h>
#include <sys/nearptr.h>
#include <string.h> // for memset
#include <conio.h>
int is_key_pressed()
{
return kbhit() ? 1 : 0;
}
char get_key_code()
{
return getch();
}
void set_mode13h()
{
__dpmi_regs r;
memset(&r, 0, sizeof(__dpmi_regs));
r.x.ax = 0x13;
__dpmi_int(0x10, &r);
__djgpp_nearptr_enable();
}
void unset_mode13h()
{
__dpmi_regs r;
memset(&r, 0, sizeof(__dpmi_regs));
r.x.ax = 0x03;
__dpmi_int(0x10, &r);
__djgpp_nearptr_disable();
}
void copy_buffer(unsigned char* frame_buffer)
{
unsigned char* ptr_vidmem;
ptr_vidmem = (unsigned char*)0x0a0000 + __djgpp_conventional_base;
memcpy(ptr_vidmem, frame_buffer, 64000);
}
void screen_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 load_palette(unsigned char* palette)
{
int i;
outp(0x03c7, 0);
for (i = 0; i < 768; i++) {
palette[i] = inp(0x03c9);
}
}
void do_blur(unsigned char* frame_buffer, int width, int height)
{
int i;
int color;
unsigned char* pbf = frame_buffer;
for (i = 0; i < width; i++) {
*pbf = 0;
pbf++;
}
for (i = 0; i < width * (height - 2); i++) {
color = *(pbf - 1);
color += *(pbf + 1);
color += *(pbf - width);
color += *(pbf + width);
color >>= 2;
*pbf = (unsigned char)color;
pbf++;
}
for (i = 0; i < width; i++) {
*pbf = 0;
pbf++;
}
}
void do_segment_blur(unsigned char* frame_buffer, int width)
{
int i;
int color;
for (i = 0; i <= 0xffff; i++) {
color = *(frame_buffer + ((i - 1) & 0xffff));
color += *(frame_buffer + ((i + 1) & 0xffff));
color += *(frame_buffer + ((i - width) & 0xffff));
color += *(frame_buffer + ((i + width) & 0xffff));
color >>= 2;
*(frame_buffer + i) = (unsigned char)color;
}
}