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];
10 void open_screen(void)
14 lval = SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_AUDIO);
16 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
21 jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE | SDL_FULLSCREEN);
23 jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE);
25 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
43 if (SDL_WM_ToggleFullScreen(jnb_surface))
48 void wait_vrt(int mix)
54 void clear_page(int page, int color)
56 memset((void *) get_vgaptr(page, 0, 0), color, JNB_WIDTH * JNB_HEIGHT);
60 void clear_lines(int page, int y, int count, int color)
64 for (i=0; i<count; i++)
66 memset((void *) get_vgaptr(page, 0, i+y), color, JNB_WIDTH);
70 void flippage(int page)
77 SDL_LockSurface(jnb_surface);
78 dest=(char *)jnb_surface->pixels;
80 src=&screen_buffer[JNB_WIDTH*JNB_HEIGHT];
82 src=&screen_buffer[0];
83 w=(jnb_surface->clip_rect.w>JNB_WIDTH)?(JNB_WIDTH):(jnb_surface->clip_rect.w);
84 h=(jnb_surface->clip_rect.h>JNB_HEIGHT)?(JNB_HEIGHT):(jnb_surface->clip_rect.h);
88 dest+=jnb_surface->pitch;
91 SDL_UnlockSurface(jnb_surface);
92 SDL_Flip(jnb_surface);
96 char *get_vgaptr(int page, int x, int y)
99 return &screen_buffer[JNB_WIDTH*JNB_HEIGHT+((y * JNB_WIDTH) + x)];
101 return &screen_buffer[(y * JNB_WIDTH) + x];
105 void setpalette(int index, int count, char *palette)
107 SDL_Color colors[256];
110 for (i = 0; i < count; i++) {
111 colors[i].r = palette[i * 3 + 0] << 2;
112 colors[i].g = palette[i * 3 + 1] << 2;
113 colors[i].b = palette[i * 3 + 2] << 2;
115 SDL_SetColors(jnb_surface, colors, index, count);
119 void fillpalette(int red, int green, int blue)
121 SDL_Color colors[256];
124 for (i = 0; i < 256; i++) {
125 colors[i].r = red << 2;
126 colors[i].g = green << 2;
127 colors[i].b = blue << 2;
129 SDL_SetColors(jnb_surface, colors, 0, 256);
133 void get_block(int page, int x, int y, int width, int height, char *buffer)
136 char *buffer_ptr, *vga_ptr;
142 if (y + height >= JNB_HEIGHT)
143 height = JNB_HEIGHT - y;
144 if (x + width >= JNB_WIDTH)
145 width = JNB_WIDTH - x;
147 for (h = 0; h < height; h++) {
148 buffer_ptr = &buffer[h * width];
150 vga_ptr = get_vgaptr(page, x, h + y);
152 for (w = 0; w < width; w++) {
164 void put_block(int page, int x, int y, int width, int height, char *buffer)
167 char *vga_ptr, *buffer_ptr;
173 if (y + height >= JNB_HEIGHT)
174 height = JNB_HEIGHT - y;
175 if (x + width >= JNB_WIDTH)
176 width = JNB_WIDTH - x;
178 for (h = 0; h < height; h++) {
179 vga_ptr = get_vgaptr(page, x, y + h);
181 buffer_ptr = &buffer[h * width];
182 for (w = 0; w < width; w++) {
183 *vga_ptr = *buffer_ptr;
191 void put_text(int page, int x, int y, char *text, int align)
199 if (text == NULL || strlen(text) == 0)
201 if (font_gobs == NULL)
206 while (text[c1] != 0) {
213 if (t1 >= 33 && t1 <= 34)
216 else if (t1 >= 39 && t1 <= 41)
219 else if (t1 >= 44 && t1 <= 59)
222 else if (t1 >= 64 && t1 <= 90)
225 else if (t1 >= 97 && t1 <= 122)
251 width += pob_width(image, font_gobs) + 1;
262 cur_x = x - width / 2;
265 cur_x = 0; /* this should cause error? -Chuck */
270 while (text[c1] != 0) {
277 if (t1 >= 33 && t1 <= 34)
280 else if (t1 >= 39 && t1 <= 41)
283 else if (t1 >= 44 && t1 <= 59)
286 else if (t1 >= 64 && t1 <= 90)
289 else if (t1 >= 97 && t1 <= 122)
315 put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic);
316 cur_x += pob_width(image, font_gobs) + 1;
321 void put_pob(int page, int x, int y, int image, char *pob_data, int mask, char *mask_pic)
325 char *pob_ptr, *vga_ptr, *mask_ptr;
327 long draw_width, draw_height;
330 if (image < 0 || image >= *(short *) (pob_data))
333 vga_ptr = get_vgaptr(page, 0, 0);
334 pob_offset = *(unsigned long *) (pob_data + (image * 4) + 2);
335 width = draw_width = *(short *) (pob_data + pob_offset);
336 height = draw_height = *(short *) (pob_data + pob_offset + 2);
337 x -= *(short *) (pob_data + pob_offset + 4);
338 y -= *(short *) (pob_data + pob_offset + 6);
340 if ((x + width) <= 0 || x >= 400)
342 if ((y + height) <= 0 || y >= 256)
349 if ((x + width) > 400)
350 draw_width -= x + width - 400;
352 pob_offset += -y * width;
356 if ((y + height) > 256)
357 draw_height -= y + height - 256;
359 pob_ptr = &pob_data[pob_offset];
363 vga_ptr = (char *) (0xa0000 + (long) (page << 15) + (long) y * 100L + ((x + c3) >> 2) + __djgpp_conventional_base);
365 vga_ptr = get_vgaptr(page, x, y);
367 mask_ptr = (char *) (mask_pic + (y * 400) + x);
368 for (c1 = 0; c1 < draw_height; c1++) {
369 for (c2 = 0; c2 < draw_width; c2++) {
371 if (mask == 0 || (mask == 1 && colour == 0)) {
380 pob_ptr += width - c2;
381 vga_ptr += (400 - c2);
382 mask_ptr += (400 - c2);
387 int pob_col(int x1, int y1, int image1, char *pob_data1, int x2, int y2, int image2, char *pob_data2)
390 long pob_offset1, pob_offset2;
391 short width1, width2;
392 short height1, height2;
393 short check_width, check_height;
394 char *pob_ptr1, *pob_ptr2;
396 pob_offset1 = *(long *) (pob_data1 + image1 * 4 + 2);
397 width1 = *(short *) (pob_data1 + pob_offset1);
398 height1 = *(short *) (pob_data1 + pob_offset1 + 2);
399 x1 -= *(short *) (pob_data1 + pob_offset1 + 4);
400 y1 -= *(short *) (pob_data1 + pob_offset1 + 6);
402 pob_offset2 = *(long *) (pob_data2 + image2 * 4 + 2);
403 width2 = *(short *) (pob_data2 + pob_offset2);
404 height2 = *(short *) (pob_data2 + pob_offset2 + 2);
405 x2 -= *(short *) (pob_data2 + pob_offset2 + 4);
406 y2 -= *(short *) (pob_data2 + pob_offset2 + 6);
410 if ((x1 + width1) <= x2)
413 else if ((x1 + width1) <= (x2 + width2)) {
414 pob_offset1 += x2 - x1;
415 check_width = x1 + width1 - x2;
419 pob_offset1 += x2 - x1;
420 check_width = width2;
425 if ((x2 + width2) <= x1)
428 else if ((x2 + width2) <= (x1 + width1)) {
429 pob_offset2 += x1 - x2;
430 check_width = x2 + width2 - x1;
434 pob_offset2 += x1 - x2;
435 check_width = width1;
439 if ((y1 + height1) <= y2)
442 else if ((y1 + height1) <= (y2 + height2)) {
443 pob_offset1 += (y2 - y1) * width1;
444 check_height = y1 + height1 - y2;
448 pob_offset1 += (y2 - y1) * width1;
449 check_height = height2;
454 if ((y2 + height2) <= y1)
457 else if ((y2 + height2) <= (y1 + height1)) {
458 pob_offset2 += (y1 - y2) * width2;
459 check_height = y2 + height2 - y1;
463 pob_offset2 += (y1 - y2) * width2;
464 check_height = height1;
467 pob_ptr1 = (char *) (pob_data1 + pob_offset1);
468 pob_ptr2 = (char *) (pob_data2 + pob_offset2);
469 for (c1 = 0; c1 < check_height; c1++) {
470 for (c2 = 0; c2 < check_width; c2++) {
471 if (*pob_ptr1 != 0 && *pob_ptr2 != 0)
476 pob_ptr1 += width1 - check_width;
477 pob_ptr2 += width2 - check_width;
483 int pob_width(int image, char *pob_data)
485 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2));
489 int pob_height(int image, char *pob_data)
491 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 2);
495 int pob_hs_x(int image, char *pob_data)
497 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 4);
501 int pob_hs_y(int image, char *pob_data)
503 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 6);
507 int read_pcx(FILE * handle, char *buffer, int buf_len, char *pal)
513 fseek(handle, 128, SEEK_CUR);
515 while (ofs1 < buf_len) {
517 if ((a & 0xc0) == 0xc0) {
520 for (c1 = 0; c1 < a && ofs1 < buf_len; c1++)
521 buffer[ofs1++] = (char) b;
523 buffer[ofs1++] = (char) a;
526 fseek(handle, 1, SEEK_CUR);
527 for (c1 = 0; c1 < 768; c1++)
528 pal[c1] = fgetc(handle) >> 2;
536 int filelength(int handle)
540 if (fstat(handle, &buf) == -1) {
541 perror("filelength");