]> icculus.org git repositories - crow/jumpnbump.git/blob - dos/gfx.c
Initial revision
[crow/jumpnbump.git] / dos / gfx.c
1 #include "globals.h"
2
3
4 void open_screen(void) {
5         __dpmi_regs regs;
6   char *ptr1;
7
8         regs.x.ax = 0x13;
9   __dpmi_int(0x10, &regs);
10
11         outportw(0x3c4, 0x0604);
12         outportw(0x3c4, 0x0100);
13         outportb(0x3c2, 0xe7);
14         outportw(0x3c4, 0x0300);
15
16         outportb(0x3d4, 0x11);
17   outportb(0x3d5, inportb(0x3d5) & 0x7f);
18
19         outportw(0x3d4, 0x7100);
20         outportw(0x3d4, 0x6301);
21         outportw(0x3d4, 0x6402);
22   outportw(0x3d4, 0x9203);
23         outportw(0x3d4, 0x6604);
24         outportw(0x3d4, 0x8205);
25         outportw(0x3d4, 0x2b06);
26         outportw(0x3d4, 0xb207);
27   outportw(0x3d4, 0x0008);
28         outportw(0x3d4, 0x6109);
29         outportw(0x3d4, 0x1310);
30         outportw(0x3d4, 0xac11);
31         outportw(0x3d4, 0xff12);
32         outportw(0x3d4, 0x3213);
33         outportw(0x3d4, 0x0014);
34         outportw(0x3d4, 0x0715);
35         outportw(0x3d4, 0x1a16);
36         outportw(0x3d4, 0xe317);
37
38         outportw(0x3d4, 0x3213);
39
40   ptr1 = (char *)(0xa0000 + __djgpp_conventional_base);
41         outportw(0x3c4, 0x0f02);
42   memset(ptr1, 0, 65535);
43
44 }
45
46
47 void wait_vrt(void) {
48
49         while( (inportb(0x3da) & 8) == 0);
50   while( (inportb(0x3da) & 8) == 8);
51
52 }
53
54
55 /*void get_block(char page, short x, short y, short width, short height, char *buffer) {
56         short c1, c2, c3;
57         char *buffer_ptr, *vga_ptr;
58
59         for (c3 = 0; c3 < 4; c3++) {
60                 outportw(0x3ce, ( ( (x + c3) & 3) << 8) + 0x04);
61                 for (c1 = 0; (c1 + c3) < width; c1 += 4) {
62                         buffer_ptr = &buffer[(c1 + c3) * height];
63                         vga_ptr = (char *)(0xa0000 + ( (long)page << 15) + (long)y * 100 + ( (x + c1 + c3) >> 2) + __djgpp_conventional_base);
64                         for (c2 = 0; c2 < height; c2++) {
65                                 *buffer_ptr = *vga_ptr;
66                                 buffer_ptr++;
67                                 vga_ptr += 100;
68                         }
69                 }
70         }
71
72 }*/
73
74
75 /*void put_block(char page, short x, short y, short width, short height, char *buffer) {
76         short c1, c2, c3;
77         char *vga_ptr, *buffer_ptr;
78
79         for (c3 = 0; c3 < 4; c3++) {
80                 outportw(0x3c4, ( (1 << ( (x + c3) & 3) ) << 8) + 0x02);
81                 for (c1 = 0; (c1 + c3) < width; c1 += 4) {
82                         vga_ptr = (char *)(0xa0000 + ( (long)page << 15) + (long)y * 100 + ( (x + c1 + c3) >> 2) + __djgpp_conventional_base);
83                         buffer_ptr = &buffer[(c1 + c3) * height];
84                         for (c2 = 0; c2 < height; c2++) {
85                                 *vga_ptr = *buffer_ptr;
86                                 vga_ptr += 100;
87                                 buffer_ptr++;
88                         }
89                 }
90         }
91
92 }*/
93
94
95 void put_text(char page, int x, int y, char *text, char align) {
96         int c1;
97         int t1;
98         int width;
99         int cur_x;
100         int image;
101
102         if (text == NULL || strlen(text) == 0)
103                 return;
104         if (font_gobs == NULL)
105                 return;
106
107         width = 0;
108         c1 = 0;
109         while (text[c1] != 0) {
110                 t1 = text[c1];
111                 c1++;
112                 if (t1 == ' ') {
113                         width += 5;
114                         continue;
115                 }
116                 if (t1 >= 33 && t1 <= 34)
117                         image = t1 - 33;
118                 else if (t1 >= 39 && t1 <= 41)
119                         image = t1 - 37;
120                 else if (t1 >= 44 && t1 <= 59)
121                         image = t1 - 39;
122                 else if (t1 >= 64 && t1 <= 90)
123                         image = t1 - 43;
124                 else if (t1 >= 97 && t1 <= 122)
125                         image = t1 - 49;
126                 else if (t1 == '~')
127                         image = 74;
128                 else if (t1 == '\84')
129                         image = 75;
130                 else if (t1 == '\86')
131                         image = 76;
132                 else if (t1 == '\8e')
133                         image = 77;
134                 else if (t1 == '\8f')
135                         image = 78;
136                 else if (t1 == '\94')
137                         image = 79;
138                 else if (t1 == '\99')
139                         image = 80;
140                 else
141                         continue;
142                 width += pob_width(image, font_gobs) + 1;
143         }
144
145         switch (align) {
146                 case 0:
147                         cur_x = x;
148                         break;
149                 case 1:
150                         cur_x = x - width;
151                         break;
152                 case 2:
153                         cur_x = x - width / 2;
154                         break;
155         }
156         c1 = 0;
157         while (text[c1] != 0) {
158                 t1 = text[c1];
159                 c1++;
160                 if (t1 == ' ') {
161                         cur_x += 5;
162                         continue;
163                 }
164                 if (t1 >= 33 && t1 <= 34)
165                         image = t1 - 33;
166                 else if (t1 >= 39 && t1 <= 41)
167                         image = t1 - 37;
168                 else if (t1 >= 44 && t1 <= 59)
169                         image = t1 - 39;
170                 else if (t1 >= 64 && t1 <= 90)
171                         image = t1 - 43;
172                 else if (t1 >= 97 && t1 <= 122)
173                         image = t1 - 49;
174                 else if (t1 == '~')
175                         image = 74;
176                 else if (t1 == '\84')
177                         image = 75;
178                 else if (t1 == '\86')
179                         image = 76;
180                 else if (t1 == '\8e')
181                         image = 77;
182                 else if (t1 == '\8f')
183                         image = 78;
184                 else if (t1 == '\94')
185                         image = 79;
186                 else if (t1 == '\99')
187                         image = 80;
188                 else
189                         continue;
190                 put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic);
191                 cur_x += pob_width(image, font_gobs) + 1;
192         }
193
194 }
195
196
197 void put_pob(char page, short x, short y, short image, char *pob_data, char mask, char *mask_pic) {
198         long c1, c2, c3;
199         long pob_offset;
200         char *pob_ptr, *vga_ptr, *mask_ptr;
201         long width, height;
202   long draw_width, draw_height;
203         char colour;
204
205         if (image < 0 || image >= *(short *)(pob_data) )
206                 return;
207
208         pob_offset = *(long *)(pob_data + image * 4 + 2);
209
210         width = draw_width = *(short *)(pob_data + pob_offset);
211         height = draw_height = *(short *)(pob_data + pob_offset + 2);
212         x -= *(short *)(pob_data + pob_offset + 4);
213         y -= *(short *)(pob_data + pob_offset + 6);
214
215         pob_offset += 8;
216
217   if ( (x + width) <= 0 || x >= 400)
218     return;
219   if ( (y + height) <= 0 || y >= 256)
220     return;
221   if (x < 0) {
222     pob_offset -= x;
223     draw_width += x;
224     x = 0;
225   }
226   if ( (x + width) > 400)
227     draw_width -= x + width - 400;
228   if (y < 0) {
229     pob_offset += -y * width;
230     draw_height -= -y;
231     y = 0;
232   }
233   if ( (y + height) > 256)
234     draw_height -= y + height - 256;
235
236         for (c3 = 0; c3 < 4; c3++) {
237                 outportw(0x3c4, ( (1 << ( (x + c3) & 3) ) << 8) + 0x02);
238                 pob_ptr = &pob_data[pob_offset + c3];
239                 vga_ptr = (char *)(0xa0000 + (long)(page << 15) + (long)y * 100L + ( (x + c3) >> 2) + __djgpp_conventional_base);
240                 mask_ptr = (char *)(mask_pic + (long)y * 400L + x + c3);
241                 for (c1 = 0; c1 < draw_height; c1++) {
242                         for (c2 = c3; c2 < draw_width; c2 += 4) {
243         colour = *mask_ptr;
244         if (mask == 0 || (mask == 1 && colour == 0) ) {
245                                         colour = *pob_ptr;
246                                         if (colour != 0)
247                                                 *vga_ptr = colour;
248         }
249                                 pob_ptr += 4;
250                                 vga_ptr++;
251                                 mask_ptr += 4;
252                         }
253       pob_ptr += width - c2 + c3;
254       vga_ptr += (400 - c2 + c3) >> 2;
255       mask_ptr += 400 - c2 + c3;
256                 }
257         }
258
259 }
260
261
262 char pob_col(short x1, short y1, short image1, char *pob_data1, short x2, short y2, short image2, char *pob_data2) {
263         short c1, c2;
264         long pob_offset1, pob_offset2;
265         short width1, width2;
266         short height1, height2;
267   short check_width, check_height;
268         char *pob_ptr1, *pob_ptr2;
269
270         pob_offset1 = *(long *)(pob_data1 + image1 * 4 + 2);
271         width1 = *(short *)(pob_data1 + pob_offset1);
272         height1 = *(short *)(pob_data1 + pob_offset1 + 2);
273         x1 -= *(short *)(pob_data1 + pob_offset1 + 4);
274         y1 -= *(short *)(pob_data1 + pob_offset1 + 6);
275         pob_offset1 += 8;
276
277         pob_offset2 = *(long *)(pob_data2 + image2 * 4 + 2);
278         width2 = *(short *)(pob_data2 + pob_offset2);
279         height2 = *(short *)(pob_data2 + pob_offset2 + 2);
280         x2 -= *(short *)(pob_data2 + pob_offset2 + 4);
281         y2 -= *(short *)(pob_data2 + pob_offset2 + 6);
282         pob_offset2 += 8;
283
284   if (x1 < x2) {
285         if ( (x1 + width1) <= x2)
286                         return 0;
287     else if ( (x1 + width1) <= (x2 + width2) ) {
288         pob_offset1 += x2 - x1;
289         check_width = x1 + width1 - x2;
290     }
291     else {
292         pob_offset1 += x2 - x1;
293       check_width = width2;
294     }
295   }
296   else {
297         if ( (x2 + width2) <= x1)
298                         return 0;
299     else if ( (x2 + width2) <= (x1 + width1) ) {
300         pob_offset2 += x1 - x2;
301         check_width = x2 + width2 - x1;
302     }
303     else {
304         pob_offset2 += x1 - x2;
305       check_width = width1;
306     }
307   }
308   if (y1 < y2) {
309         if ( (y1 + height1) <= y2)
310                         return 0;
311     else if ( (y1 + height1) <= (y2 + height2) ) {
312         pob_offset1 += (y2 - y1) * width1;
313         check_height = y1 + height1 - y2;
314     }
315     else {
316         pob_offset1 += (y2 - y1) * width1;
317       check_height = height2;
318     }
319   }
320   else {
321         if ( (y2 + height2) <= y1)
322                         return 0;
323     else if ( (y2 + height2) <= (y1 + height1) ) {
324         pob_offset2 += (y1 - y2) * width2;
325         check_height = y2 + height2 - y1;
326     }
327     else {
328         pob_offset2 += (y1 - y2) * width2;
329       check_height = height1;
330     }
331   }
332
333   pob_ptr1 = (char *)(pob_data1 + pob_offset1);
334   pob_ptr2 = (char *)(pob_data2 + pob_offset2);
335   for (c1 = 0; c1 < check_height; c1++) {
336           for (c2 = 0; c2 < check_width; c2++) {
337         if (*pob_ptr1 != 0 && *pob_ptr2 != 0)
338         return 1;
339       pob_ptr1++;
340       pob_ptr2++;
341         }
342     pob_ptr1 += width1 - check_width;
343     pob_ptr2 += width2 - check_width;
344   }
345
346   return 0;
347
348 }
349
350
351 short pob_width(short image, char *pob_data) {
352         return *(short *)(pob_data + *(long *)(pob_data + image * 4 + 2) );
353 }
354
355
356 short pob_height(short image, char *pob_data) {
357         return *(short *)(pob_data + *(long *)(pob_data + image * 4 + 2) + 2);
358 }
359
360
361 short pob_hs_x(short image, char *pob_data) {
362         return *(short *)(pob_data + *(long *)(pob_data + image * 4 + 2) + 4);
363 }
364
365
366 short pob_hs_y(short image, char *pob_data) {
367         return *(short *)(pob_data + *(long *)(pob_data + image * 4 + 2) + 6);
368 }
369
370
371 char read_pcx(FILE *handle, char *buffer, long buf_len, char *pal) {
372         short c1;
373         short a, b;
374         long ofs1;
375
376         if (buffer != 0) {
377                 fseek(handle, 128, SEEK_CUR);
378
379                 ofs1 = 0;
380
381                 while (ofs1 < buf_len) {
382                         a = fgetc(handle);
383                         if ( (a & 0xc0) == 0xc0) {
384                                 b = fgetc(handle);
385                                 a &= 0x3f;
386                                 for (c1 = 0; c1 < a; c1++)
387                                         buffer[ofs1++] = b;
388                         }
389                         else
390                                 buffer[ofs1++] = a;
391                 }
392
393                 if (pal != 0) {
394                         fseek(handle, 1, SEEK_CUR);
395                         for (c1 = 0; c1 < 768; c1++)
396                                 pal[c1] = fgetc(handle) >> 2;
397                 }
398
399         }
400
401         fclose(handle);
402         return 0;
403 }