-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfx.c
186 lines (145 loc) · 3.11 KB
/
gfx.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
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
/*****************************************
Mroczna Harmonia
gfx.c xxxxxxxxxxxx
(C) 2001, 2023 M. Feliks
*****************************************/
#include <dos.h>
#include <string.h> // for memset
#include "globals.h"
unsigned char palette[768];
void tryb_graf()
{
_AX = 0x13;
geninterrupt(0x10);
}
void tryb_text()
{
_AX = 0x3;
geninterrupt(0x10);
}
void kopiuj_bufor()
{
unsigned char far* ptr_vidmem = (unsigned char far *)0xA0000000L;
memcpy(ptr_vidmem, bufor, 64000);
}
void czysc_bufor()
{
unsigned char far* ptr_vidmem = (unsigned char far *)0xA0000000L;
memset(bufor, 0, 64000);
}
void retrace()
{
while (!(inportb(0x03da) & 8))
;
while ((inportb(0x03da) & 8))
;
}
void set_palette(unsigned char* my_pal)
{
int i;
outportb(0x03c8, 0);
for (i = 0; i < 768; i++) {
outportb(0x03c9, my_pal[i]);
}
}
void dump_palette(unsigned char* my_pal)
{
int i;
outportb(0x03c7, 0);
for (i = 0; i < 768; i++) {
my_pal[i] = inportb(0x03c9);
}
}
// end of low-level code
void pasek(int x, int y, unsigned char kolor)
{
int i;
unsigned char* bptr = bufor + x + y * 320;
for (i = 0; i < 8; i++, bptr++) {
*bptr = kolor;
}
}
void pixel(int x, int y, unsigned char color)
{
if (x >= 0 && x <= 319 && y >= 0 && y <= 199) {
*(bufor + x + y * 320) = color;
}
}
void draw_sprite(unsigned char* sprite, int x, int y, int width, int height, unsigned char* where)
{
int i, j;
unsigned char* sprptr = sprite;
unsigned char* bptr = where + x + y * 320;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++, sprptr++, bptr++) {
if (*sprptr != 0) {
*bptr = *sprptr;
}
}
bptr += 320 - width;
}
}
void save_pal(void)
{
dump_palette(palette);
}
void renew_pal(void)
{
set_palette(palette);
}
void paleta_inicjuj(void)
{
int i;
unsigned char my_pal[768], *ptr;
dump_palette(my_pal);
ptr = my_pal + 100 * 3;
for (i = 0; i < 64; i++) {
*(ptr++) = 0;
*(ptr++) = 0;
*(ptr++) = i;
}
for (i = 0; i < 64; i++) {
*(ptr++) = i;
*(ptr++) = 0;
*(ptr++) = 0;
}
set_palette(my_pal);
}
void flash(void)
{
int i, j;
unsigned char my_pal[768], dest_pal[768], *srcp, *destp;
dump_palette(dest_pal);
memset(my_pal, 63, 768);
set_palette(my_pal);
for (i = 0; i < 64; i++) {
srcp = my_pal;
destp = dest_pal;
for (j = 0; j < 768; j++) {
if ((*srcp) > (*destp)) {
(*srcp)--;
}
srcp++;
destp++;
}
set_palette(my_pal);
retrace();
}
}
void fade_down(void)
{
int i, j;
unsigned char my_pal[768], *srcp;
dump_palette(my_pal);
for (j = 0; j < 64; j++) {
srcp = my_pal;
for (j = 0; j < 768; j++) {
if ((*srcp) > 0) {
(*srcp)--;
}
srcp++;
}
set_palette(my_pal);
retrace();
}
}