3 * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
5 * Copyright (C) 2002 Florian Schulze - crow@icculus.org
7 * Portions of this code are from the MPEG software simulation group
8 * idct implementation. This code will be replaced with a new
11 * This file is part of Jump'n'Bump.
13 * Jump'n'Bump is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * Jump'n'Bump is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 void open_screen(void)
37 __dpmi_int(0x10, ®s);
39 outportw(0x3c4, 0x0604);
40 outportw(0x3c4, 0x0100);
41 outportb(0x3c2, 0xe7);
42 outportw(0x3c4, 0x0300);
44 outportb(0x3d4, 0x11);
45 outportb(0x3d5, inportb(0x3d5) & 0x7f);
47 outportw(0x3d4, 0x7100);
48 outportw(0x3d4, 0x6301);
49 outportw(0x3d4, 0x6402);
50 outportw(0x3d4, 0x9203);
51 outportw(0x3d4, 0x6604);
52 outportw(0x3d4, 0x8205);
53 outportw(0x3d4, 0x2b06);
54 outportw(0x3d4, 0xb207);
55 outportw(0x3d4, 0x0008);
56 outportw(0x3d4, 0x6109);
57 outportw(0x3d4, 0x1310);
58 outportw(0x3d4, 0xac11);
59 outportw(0x3d4, 0xff12);
60 outportw(0x3d4, 0x3213);
61 outportw(0x3d4, 0x0014);
62 outportw(0x3d4, 0x0715);
63 outportw(0x3d4, 0x1a16);
64 outportw(0x3d4, 0xe317);
66 outportw(0x3d4, 0x3213);
68 ptr1 = (char *) (0xa0000 + __djgpp_conventional_base);
69 outportw(0x3c4, 0x0f02);
70 memset(ptr1, 0, 65535);
75 void wait_vrt(int mix)
78 while ((inportb(0x3da) & 8) == 0)
80 while ((inportb(0x3da) & 8) == 8)
83 while ((inportb(0x3da) & 8) == 0);
84 while ((inportb(0x3da) & 8) == 8);
88 void clear_page(int page, int color)
90 outportw(0x3c4, 0x0f02);
91 memset((char *) (0xa0000 - __djgpp_base_address), 0, 32768);
94 void clear_lines(int page, int y, int count, int color)
98 outportw(0x3c4, 0x0f02);
99 for (i=0; i<count; i++)
101 memset((char *) (0xa0000 + (i+y) * 100 + __djgpp_conventional_base), 0, 100);
104 int get_pixel(int page, int x, int y)
106 outportw(0x3ce, (((x) & 3) << 8) + 0x04);
107 //outportw(0x3c4, ((1 << ((x) & 3)) << 8) + 0x02);
108 return *(char *) (0xa0000 + (y * 100 + (x >> 2)) + ((long) page << 15) - __djgpp_base_address);
111 void set_pixel(int page, int x, int y, int color)
113 //outportw(0x3ce, (((x) & 3) << 8) + 0x04);
114 outportw(0x3c4, ((1 << ((x) & 3)) << 8) + 0x02);
115 *(char *) (0xa0000 + (y * 100 + (x >> 2)) + ((long) page << 15) - __djgpp_base_address) = color;
118 void flippage(int page)
120 outportw(0x3d4, (page << 23) + 0x0d);
121 outportw(0x3d4, ((page << 15) & 0xff00) + 0x0c);
125 void get_block(char page, short x, short y, short width, short height, char *buffer)
128 char *buffer_ptr, *vga_ptr;
130 for (c3 = 0; c3 < 4; c3++) {
131 outportw(0x3ce, (((x + c3) & 3) << 8) + 0x04);
132 for (c1 = 0; (c1 + c3) < width; c1 += 4) {
133 buffer_ptr = &buffer[(c1 + c3) * height];
134 vga_ptr = (char *) (0xa0000 + ((long) page << 15) + (long) y * 100 + ((x + c1 + c3) >> 2) + __djgpp_conventional_base);
135 for (c2 = 0; c2 < height; c2++) {
136 *buffer_ptr = *vga_ptr;
147 void put_block(char page, short x, short y, short width, short height, char *buffer)
150 char *vga_ptr, *buffer_ptr;
152 for (c3 = 0; c3 < 4; c3++) {
153 outportw(0x3c4, ((1 << ((x + c3) & 3)) << 8) + 0x02);
154 for (c1 = 0; (c1 + c3) < width; c1 += 4) {
155 vga_ptr = (char *) (0xa0000 + ((long) page << 15) + (long) y * 100 + ((x + c1 + c3) >> 2) + __djgpp_conventional_base);
156 buffer_ptr = &buffer[(c1 + c3) * height];
157 for (c2 = 0; c2 < height; c2++) {
158 *vga_ptr = *buffer_ptr;
168 void put_text(char page, int x, int y, char *text, char align)
176 if (text == NULL || strlen(text) == 0)
178 if (font_gobs == NULL)
183 while (text[c1] != 0) {
190 if (t1 >= 33 && t1 <= 34)
192 else if (t1 >= 39 && t1 <= 41)
194 else if (t1 >= 44 && t1 <= 59)
196 else if (t1 >= 64 && t1 <= 90)
198 else if (t1 >= 97 && t1 <= 122)
216 width += pob_width(image, font_gobs) + 1;
227 cur_x = x - width / 2;
231 while (text[c1] != 0) {
238 if (t1 >= 33 && t1 <= 34)
240 else if (t1 >= 39 && t1 <= 41)
242 else if (t1 >= 44 && t1 <= 59)
244 else if (t1 >= 64 && t1 <= 90)
246 else if (t1 >= 97 && t1 <= 122)
264 put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic);
265 cur_x += pob_width(image, font_gobs) + 1;
271 void put_pob(char page, short x, short y, short image, char *pob_data, char mask, char *mask_pic)
275 char *pob_ptr, *vga_ptr, *mask_ptr;
277 long draw_width, draw_height;
280 if (image < 0 || image >= *(short *) (pob_data))
283 pob_offset = *(long *) (pob_data + image * 4 + 2);
285 width = draw_width = *(short *) (pob_data + pob_offset);
286 height = draw_height = *(short *) (pob_data + pob_offset + 2);
287 x -= *(short *) (pob_data + pob_offset + 4);
288 y -= *(short *) (pob_data + pob_offset + 6);
292 if ((x + width) <= 0 || x >= 400)
294 if ((y + height) <= 0 || y >= 256)
301 if ((x + width) > 400)
302 draw_width -= x + width - 400;
304 pob_offset += -y * width;
308 if ((y + height) > 256)
309 draw_height -= y + height - 256;
311 for (c3 = 0; c3 < 4; c3++) {
312 outportw(0x3c4, ((1 << ((x + c3) & 3)) << 8) + 0x02);
313 pob_ptr = &pob_data[pob_offset + c3];
314 vga_ptr = (char *) (0xa0000 + (long) (page << 15) + (long) y * 100L + ((x + c3) >> 2) + __djgpp_conventional_base);
315 mask_ptr = (char *) (mask_pic + (long) y * 400L + x + c3);
316 for (c1 = 0; c1 < draw_height; c1++) {
317 for (c2 = c3; c2 < draw_width; c2 += 4) {
319 if (mask == 0 || (mask == 1 && colour == 0)) {
328 pob_ptr += width - c2 + c3;
329 vga_ptr += (400 - c2 + c3) >> 2;
330 mask_ptr += 400 - c2 + c3;
337 char pob_col(short x1, short y1, short image1, char *pob_data1, short x2, short y2, short image2, char *pob_data2)
340 long pob_offset1, pob_offset2;
341 short width1, width2;
342 short height1, height2;
343 short check_width, check_height;
344 char *pob_ptr1, *pob_ptr2;
346 pob_offset1 = *(long *) (pob_data1 + image1 * 4 + 2);
347 width1 = *(short *) (pob_data1 + pob_offset1);
348 height1 = *(short *) (pob_data1 + pob_offset1 + 2);
349 x1 -= *(short *) (pob_data1 + pob_offset1 + 4);
350 y1 -= *(short *) (pob_data1 + pob_offset1 + 6);
353 pob_offset2 = *(long *) (pob_data2 + image2 * 4 + 2);
354 width2 = *(short *) (pob_data2 + pob_offset2);
355 height2 = *(short *) (pob_data2 + pob_offset2 + 2);
356 x2 -= *(short *) (pob_data2 + pob_offset2 + 4);
357 y2 -= *(short *) (pob_data2 + pob_offset2 + 6);
361 if ((x1 + width1) <= x2)
363 else if ((x1 + width1) <= (x2 + width2)) {
364 pob_offset1 += x2 - x1;
365 check_width = x1 + width1 - x2;
367 pob_offset1 += x2 - x1;
368 check_width = width2;
371 if ((x2 + width2) <= x1)
373 else if ((x2 + width2) <= (x1 + width1)) {
374 pob_offset2 += x1 - x2;
375 check_width = x2 + width2 - x1;
377 pob_offset2 += x1 - x2;
378 check_width = width1;
382 if ((y1 + height1) <= y2)
384 else if ((y1 + height1) <= (y2 + height2)) {
385 pob_offset1 += (y2 - y1) * width1;
386 check_height = y1 + height1 - y2;
388 pob_offset1 += (y2 - y1) * width1;
389 check_height = height2;
392 if ((y2 + height2) <= y1)
394 else if ((y2 + height2) <= (y1 + height1)) {
395 pob_offset2 += (y1 - y2) * width2;
396 check_height = y2 + height2 - y1;
398 pob_offset2 += (y1 - y2) * width2;
399 check_height = height1;
403 pob_ptr1 = (char *) (pob_data1 + pob_offset1);
404 pob_ptr2 = (char *) (pob_data2 + pob_offset2);
405 for (c1 = 0; c1 < check_height; c1++) {
406 for (c2 = 0; c2 < check_width; c2++) {
407 if (*pob_ptr1 != 0 && *pob_ptr2 != 0)
412 pob_ptr1 += width1 - check_width;
413 pob_ptr2 += width2 - check_width;
421 short pob_width(short image, char *pob_data)
423 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2));
427 short pob_height(short image, char *pob_data)
429 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 2);
433 short pob_hs_x(short image, char *pob_data)
435 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 4);
439 short pob_hs_y(short image, char *pob_data)
441 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 6);
445 char read_pcx(FILE * handle, char *buffer, long buf_len, char *pal)
452 fseek(handle, 128, SEEK_CUR);
456 while (ofs1 < buf_len) {
458 if ((a & 0xc0) == 0xc0) {
461 for (c1 = 0; c1 < a; c1++)
468 fseek(handle, 1, SEEK_CUR);
469 for (c1 = 0; c1 < 768; c1++)
470 pal[c1] = fgetc(handle) >> 2;