4 static SDL_Surface *jnb_surface, *jnb_surface_page1;
5 static int fullscreen = 0;
6 static int vinited = 0;
12 lval = SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_AUDIO);
14 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
18 jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_HWSURFACE | SDL_DOUBLEBUF);
20 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
24 jnb_surface_page1 = SDL_CreateRGBSurface(SDL_HWSURFACE, JNB_WIDTH, JNB_HEIGHT, JNB_BPP, 0, 0, 0, 0);
25 if (!jnb_surface_page1) {
26 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
33 lval = SDL_WM_ToggleFullScreen(jnb_surface);
35 fprintf(stderr, "SDL WARNING: %s\n", SDL_GetError());
51 if (SDL_WM_ToggleFullScreen(jnb_surface))
60 void flippage(long page)
64 which = (page == 1) ? jnb_surface_page1 : jnb_surface;
66 SDL_UpdateRect(which, 0, 0, 0, 0);
69 char *get_vgaptr(long page, long x, long y)
73 which = (page == 1) ? jnb_surface_page1 : jnb_surface;
75 return (char *) &(((char *) which->pixels)[(y * JNB_WIDTH) + x]);
78 void setpalette(int index, int count, char *palette)
80 SDL_Color colors[256];
83 for (i = 0; i < count; i++) {
84 colors[i].r = palette[i * 3 + 0] << 2;
85 colors[i].g = palette[i * 3 + 1] << 2;
86 colors[i].b = palette[i * 3 + 2] << 2;
88 SDL_SetColors(jnb_surface, colors, index, count);
89 SDL_SetColors(jnb_surface_page1, colors, index, count);
92 void fillpalette(int red, int green, int blue)
94 SDL_Color colors[256];
97 for (i = 0; i < 256; i++) {
98 colors[i].r = red << 2;
99 colors[i].g = green << 2;
100 colors[i].b = blue << 2;
102 SDL_SetColors(jnb_surface, colors, 0, 256);
103 SDL_SetColors(jnb_surface_page1, colors, 0, 256);
106 void get_block(char page, long x, long y, long width, long height, char *buffer)
109 char *buffer_ptr, *vga_ptr;
115 if (y + height >= JNB_HEIGHT)
116 height = JNB_HEIGHT - y;
117 if (x + width >= JNB_WIDTH)
118 width = JNB_WIDTH - x;
120 for (h = 0; h < height; h++) {
121 buffer_ptr = &buffer[h * width];
123 vga_ptr = get_vgaptr(page, x, h + y);
125 for (w = 0; w < width; w++) {
136 void put_block(char page, long x, long y, long width, long height, char *buffer)
139 char *vga_ptr, *buffer_ptr;
145 if (y + height >= JNB_HEIGHT)
146 height = JNB_HEIGHT - y;
147 if (x + width >= JNB_WIDTH)
148 width = JNB_WIDTH - x;
150 for (h = 0; h < height; h++) {
151 vga_ptr = get_vgaptr(page, x, y + h);
153 buffer_ptr = &buffer[h * width];
154 for (w = 0; w < width; w++) {
155 *vga_ptr = *buffer_ptr;
162 void put_text(char page, int x, int y, char *text, char align)
170 if (text == NULL || strlen(text) == 0)
172 if (font_gobs == NULL)
177 while (text[c1] != 0) {
184 if (t1 >= 33 && t1 <= 34)
187 else if (t1 >= 39 && t1 <= 41)
190 else if (t1 >= 44 && t1 <= 59)
193 else if (t1 >= 64 && t1 <= 90)
196 else if (t1 >= 97 && t1 <= 122)
221 width += pob_width(image, font_gobs) + 1;
232 cur_x = x - width / 2;
235 cur_x = 0; /* this should cause error? -Chuck */
240 while (text[c1] != 0) {
247 if (t1 >= 33 && t1 <= 34)
250 else if (t1 >= 39 && t1 <= 41)
253 else if (t1 >= 44 && t1 <= 59)
256 else if (t1 >= 64 && t1 <= 90)
259 else if (t1 >= 97 && t1 <= 122)
265 else if (t1 == '
\84')
268 else if (t1 == '
\86')
271 else if (t1 == '
\8e')
274 else if (t1 == '
\8f')
277 else if (t1 == '
\94')
280 else if (t1 == '
\99')
285 put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic);
286 cur_x += pob_width(image, font_gobs) + 1;
290 void put_pob(char page, short x, short y, short image, char *pob_data, char mask, char *mask_pic)
294 char *pob_ptr, *vga_ptr, *mask_ptr;
296 long draw_width, draw_height;
299 if (image < 0 || image >= *(short *) (pob_data))
302 vga_ptr = get_vgaptr(page, 0, 0);
303 pob_offset = *(unsigned long *) (pob_data + (image * 4) + 2);
304 width = draw_width = *(short *) (pob_data + pob_offset);
305 height = draw_height = *(short *) (pob_data + pob_offset + 2);
306 x -= *(short *) (pob_data + pob_offset + 4);
307 y -= *(short *) (pob_data + pob_offset + 6);
309 if ((x + width) <= 0 || x >= 400)
311 if ((y + height) <= 0 || y >= 256)
318 if ((x + width) > 400)
319 draw_width -= x + width - 400;
321 pob_offset += -y * width;
325 if ((y + height) > 256)
326 draw_height -= y + height - 256;
328 pob_ptr = &pob_data[pob_offset];
332 vga_ptr = (char *) (0xa0000 + (long) (page << 15) + (long) y * 100L + ((x + c3) >> 2) + __djgpp_conventional_base);
334 vga_ptr = get_vgaptr(page, x, y);
336 mask_ptr = (char *) (mask_pic + (y * 400) + x);
337 for (c1 = 0; c1 < draw_height; c1++) {
338 for (c2 = 0; c2 < draw_width; c2++) {
340 if (mask == 0 || (mask == 1 && colour == 0)) {
349 pob_ptr += width - c2;
350 vga_ptr += (400 - c2);
351 mask_ptr += (400 - c2);
355 char pob_col(short x1, short y1, short image1, char *pob_data1, short x2, short y2, short image2, char *pob_data2)
358 long pob_offset1, pob_offset2;
359 short width1, width2;
360 short height1, height2;
361 short check_width, check_height;
362 char *pob_ptr1, *pob_ptr2;
364 pob_offset1 = *(long *) (pob_data1 + image1 * 4 + 2);
365 width1 = *(short *) (pob_data1 + pob_offset1);
366 height1 = *(short *) (pob_data1 + pob_offset1 + 2);
367 x1 -= *(short *) (pob_data1 + pob_offset1 + 4);
368 y1 -= *(short *) (pob_data1 + pob_offset1 + 6);
370 pob_offset2 = *(long *) (pob_data2 + image2 * 4 + 2);
371 width2 = *(short *) (pob_data2 + pob_offset2);
372 height2 = *(short *) (pob_data2 + pob_offset2 + 2);
373 x2 -= *(short *) (pob_data2 + pob_offset2 + 4);
374 y2 -= *(short *) (pob_data2 + pob_offset2 + 6);
378 if ((x1 + width1) <= x2)
381 else if ((x1 + width1) <= (x2 + width2)) {
382 pob_offset1 += x2 - x1;
383 check_width = x1 + width1 - x2;
387 pob_offset1 += x2 - x1;
388 check_width = width2;
393 if ((x2 + width2) <= x1)
396 else if ((x2 + width2) <= (x1 + width1)) {
397 pob_offset2 += x1 - x2;
398 check_width = x2 + width2 - x1;
402 pob_offset2 += x1 - x2;
403 check_width = width1;
407 if ((y1 + height1) <= y2)
410 else if ((y1 + height1) <= (y2 + height2)) {
411 pob_offset1 += (y2 - y1) * width1;
412 check_height = y1 + height1 - y2;
416 pob_offset1 += (y2 - y1) * width1;
417 check_height = height2;
422 if ((y2 + height2) <= y1)
425 else if ((y2 + height2) <= (y1 + height1)) {
426 pob_offset2 += (y1 - y2) * width2;
427 check_height = y2 + height2 - y1;
431 pob_offset2 += (y1 - y2) * width2;
432 check_height = height1;
435 pob_ptr1 = (char *) (pob_data1 + pob_offset1);
436 pob_ptr2 = (char *) (pob_data2 + pob_offset2);
437 for (c1 = 0; c1 < check_height; c1++) {
438 for (c2 = 0; c2 < check_width; c2++) {
439 if (*pob_ptr1 != 0 && *pob_ptr2 != 0)
444 pob_ptr1 += width1 - check_width;
445 pob_ptr2 += width2 - check_width;
450 short pob_width(short image, char *pob_data)
452 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2));
455 short pob_height(short image, char *pob_data)
457 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 2);
460 short pob_hs_x(short image, char *pob_data)
462 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 4);
465 short pob_hs_y(short image, char *pob_data)
467 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 6);
470 char read_pcx(FILE * handle, char *buffer, long buf_len, char *pal)
476 fseek(handle, 128, SEEK_CUR);
478 while (ofs1 < buf_len) {
480 if ((a & 0xc0) == 0xc0) {
483 for (c1 = 0; c1 < a && ofs1 < buf_len; c1++)
484 buffer[ofs1++] = (char) b;
486 buffer[ofs1++] = (char) a;
489 fseek(handle, 1, SEEK_CUR);
490 for (c1 = 0; c1 < 768; c1++)
491 pal[c1] = fgetc(handle) >> 2;
498 long filelength(int handle)
502 if (fstat(handle, &buf) == -1) {
503 perror("filelength");