4 static SDL_Surface *jnb_surface;
5 static int fullscreen = 0;
6 static int vinited = 0;
7 static unsigned char screen_buffer[JNB_WIDTH*JNB_HEIGHT*2];
13 lval = SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_AUDIO);
15 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
20 jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE | SDL_FULLSCREEN);
22 jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE);
24 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
41 if (SDL_WM_ToggleFullScreen(jnb_surface))
50 void flippage(int page)
57 SDL_LockSurface(jnb_surface);
58 dest=(char *)jnb_surface->pixels;
60 src=&screen_buffer[JNB_WIDTH*JNB_HEIGHT];
62 src=&screen_buffer[0];
63 w=(jnb_surface->clip_rect.w>JNB_WIDTH)?(JNB_WIDTH):(jnb_surface->clip_rect.w);
64 h=(jnb_surface->clip_rect.h>JNB_HEIGHT)?(JNB_HEIGHT):(jnb_surface->clip_rect.h);
68 dest+=jnb_surface->pitch;
71 SDL_UnlockSurface(jnb_surface);
72 SDL_Flip(jnb_surface);
75 char *get_vgaptr(int page, int x, int y)
78 return &screen_buffer[JNB_WIDTH*JNB_HEIGHT+((y * JNB_WIDTH) + x)];
80 return &screen_buffer[(y * JNB_WIDTH) + x];
83 void setpalette(int index, int count, char *palette)
85 SDL_Color colors[256];
88 for (i = 0; i < count; i++) {
89 colors[i].r = palette[i * 3 + 0] << 2;
90 colors[i].g = palette[i * 3 + 1] << 2;
91 colors[i].b = palette[i * 3 + 2] << 2;
93 SDL_SetColors(jnb_surface, colors, index, count);
96 void fillpalette(int red, int green, int blue)
98 SDL_Color colors[256];
101 for (i = 0; i < 256; i++) {
102 colors[i].r = red << 2;
103 colors[i].g = green << 2;
104 colors[i].b = blue << 2;
106 SDL_SetColors(jnb_surface, colors, 0, 256);
109 void get_block(int page, int x, int y, int width, int height, char *buffer)
112 char *buffer_ptr, *vga_ptr;
118 if (y + height >= JNB_HEIGHT)
119 height = JNB_HEIGHT - y;
120 if (x + width >= JNB_WIDTH)
121 width = JNB_WIDTH - x;
123 for (h = 0; h < height; h++) {
124 buffer_ptr = &buffer[h * width];
126 vga_ptr = get_vgaptr(page, x, h + y);
128 for (w = 0; w < width; w++) {
139 void put_block(int page, int x, int y, int width, int height, char *buffer)
142 char *vga_ptr, *buffer_ptr;
148 if (y + height >= JNB_HEIGHT)
149 height = JNB_HEIGHT - y;
150 if (x + width >= JNB_WIDTH)
151 width = JNB_WIDTH - x;
153 for (h = 0; h < height; h++) {
154 vga_ptr = get_vgaptr(page, x, y + h);
156 buffer_ptr = &buffer[h * width];
157 for (w = 0; w < width; w++) {
158 *vga_ptr = *buffer_ptr;
165 void put_text(int page, int x, int y, char *text, int align)
173 if (text == NULL || strlen(text) == 0)
175 if (font_gobs == NULL)
180 while (text[c1] != 0) {
187 if (t1 >= 33 && t1 <= 34)
190 else if (t1 >= 39 && t1 <= 41)
193 else if (t1 >= 44 && t1 <= 59)
196 else if (t1 >= 64 && t1 <= 90)
199 else if (t1 >= 97 && t1 <= 122)
224 width += pob_width(image, font_gobs) + 1;
235 cur_x = x - width / 2;
238 cur_x = 0; /* this should cause error? -Chuck */
243 while (text[c1] != 0) {
250 if (t1 >= 33 && t1 <= 34)
253 else if (t1 >= 39 && t1 <= 41)
256 else if (t1 >= 44 && t1 <= 59)
259 else if (t1 >= 64 && t1 <= 90)
262 else if (t1 >= 97 && t1 <= 122)
268 else if (t1 == '
\84')
271 else if (t1 == '
\86')
274 else if (t1 == '
\8e')
277 else if (t1 == '
\8f')
280 else if (t1 == '
\94')
283 else if (t1 == '
\99')
288 put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic);
289 cur_x += pob_width(image, font_gobs) + 1;
293 void put_pob(int page, int x, int y, int image, char *pob_data, int mask, char *mask_pic)
297 char *pob_ptr, *vga_ptr, *mask_ptr;
299 long draw_width, draw_height;
302 if (image < 0 || image >= *(short *) (pob_data))
305 vga_ptr = get_vgaptr(page, 0, 0);
306 pob_offset = *(unsigned long *) (pob_data + (image * 4) + 2);
307 width = draw_width = *(short *) (pob_data + pob_offset);
308 height = draw_height = *(short *) (pob_data + pob_offset + 2);
309 x -= *(short *) (pob_data + pob_offset + 4);
310 y -= *(short *) (pob_data + pob_offset + 6);
312 if ((x + width) <= 0 || x >= 400)
314 if ((y + height) <= 0 || y >= 256)
321 if ((x + width) > 400)
322 draw_width -= x + width - 400;
324 pob_offset += -y * width;
328 if ((y + height) > 256)
329 draw_height -= y + height - 256;
331 pob_ptr = &pob_data[pob_offset];
335 vga_ptr = (char *) (0xa0000 + (long) (page << 15) + (long) y * 100L + ((x + c3) >> 2) + __djgpp_conventional_base);
337 vga_ptr = get_vgaptr(page, x, y);
339 mask_ptr = (char *) (mask_pic + (y * 400) + x);
340 for (c1 = 0; c1 < draw_height; c1++) {
341 for (c2 = 0; c2 < draw_width; c2++) {
343 if (mask == 0 || (mask == 1 && colour == 0)) {
352 pob_ptr += width - c2;
353 vga_ptr += (400 - c2);
354 mask_ptr += (400 - c2);
358 int pob_col(int x1, int y1, int image1, char *pob_data1, int x2, int y2, int image2, char *pob_data2)
361 long pob_offset1, pob_offset2;
362 short width1, width2;
363 short height1, height2;
364 short check_width, check_height;
365 char *pob_ptr1, *pob_ptr2;
367 pob_offset1 = *(long *) (pob_data1 + image1 * 4 + 2);
368 width1 = *(short *) (pob_data1 + pob_offset1);
369 height1 = *(short *) (pob_data1 + pob_offset1 + 2);
370 x1 -= *(short *) (pob_data1 + pob_offset1 + 4);
371 y1 -= *(short *) (pob_data1 + pob_offset1 + 6);
373 pob_offset2 = *(long *) (pob_data2 + image2 * 4 + 2);
374 width2 = *(short *) (pob_data2 + pob_offset2);
375 height2 = *(short *) (pob_data2 + pob_offset2 + 2);
376 x2 -= *(short *) (pob_data2 + pob_offset2 + 4);
377 y2 -= *(short *) (pob_data2 + pob_offset2 + 6);
381 if ((x1 + width1) <= x2)
384 else if ((x1 + width1) <= (x2 + width2)) {
385 pob_offset1 += x2 - x1;
386 check_width = x1 + width1 - x2;
390 pob_offset1 += x2 - x1;
391 check_width = width2;
396 if ((x2 + width2) <= x1)
399 else if ((x2 + width2) <= (x1 + width1)) {
400 pob_offset2 += x1 - x2;
401 check_width = x2 + width2 - x1;
405 pob_offset2 += x1 - x2;
406 check_width = width1;
410 if ((y1 + height1) <= y2)
413 else if ((y1 + height1) <= (y2 + height2)) {
414 pob_offset1 += (y2 - y1) * width1;
415 check_height = y1 + height1 - y2;
419 pob_offset1 += (y2 - y1) * width1;
420 check_height = height2;
425 if ((y2 + height2) <= y1)
428 else if ((y2 + height2) <= (y1 + height1)) {
429 pob_offset2 += (y1 - y2) * width2;
430 check_height = y2 + height2 - y1;
434 pob_offset2 += (y1 - y2) * width2;
435 check_height = height1;
438 pob_ptr1 = (char *) (pob_data1 + pob_offset1);
439 pob_ptr2 = (char *) (pob_data2 + pob_offset2);
440 for (c1 = 0; c1 < check_height; c1++) {
441 for (c2 = 0; c2 < check_width; c2++) {
442 if (*pob_ptr1 != 0 && *pob_ptr2 != 0)
447 pob_ptr1 += width1 - check_width;
448 pob_ptr2 += width2 - check_width;
453 int pob_width(int image, char *pob_data)
455 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2));
458 int pob_height(int image, char *pob_data)
460 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 2);
463 int pob_hs_x(int image, char *pob_data)
465 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 4);
468 int pob_hs_y(int image, char *pob_data)
470 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 6);
473 int read_pcx(FILE * handle, char *buffer, int buf_len, char *pal)
479 fseek(handle, 128, SEEK_CUR);
481 while (ofs1 < buf_len) {
483 if ((a & 0xc0) == 0xc0) {
486 for (c1 = 0; c1 < a && ofs1 < buf_len; c1++)
487 buffer[ofs1++] = (char) b;
489 buffer[ofs1++] = (char) a;
492 fseek(handle, 1, SEEK_CUR);
493 for (c1 = 0; c1 < 768; c1++)
494 pal[c1] = fgetc(handle) >> 2;
501 int filelength(int handle)
505 if (fstat(handle, &buf) == -1) {
506 perror("filelength");