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 char *get_vgaptr(int page, int x, int y)
13 return &screen_buffer[JNB_WIDTH*JNB_HEIGHT+((y * JNB_WIDTH) + x)];
15 return &screen_buffer[(y * JNB_WIDTH) + x];
19 void open_screen(void)
23 lval = SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_AUDIO);
25 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
30 jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE | SDL_FULLSCREEN);
32 jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE);
34 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
52 if (SDL_WM_ToggleFullScreen(jnb_surface))
57 void wait_vrt(int mix)
63 void clear_page(int page, int color)
65 memset((void *) get_vgaptr(page, 0, 0), color, JNB_WIDTH * JNB_HEIGHT);
69 void clear_lines(int page, int y, int count, int color)
73 for (i=0; i<count; i++)
75 memset((void *) get_vgaptr(page, 0, i+y), color, JNB_WIDTH);
79 int get_pixel(int page, int x, int y)
81 return *(char *) get_vgaptr(page, x, y);
85 void set_pixel(int page, int x, int y, int color)
87 *(char *) get_vgaptr(page, x, y) = color;
91 void flippage(int page)
98 SDL_LockSurface(jnb_surface);
99 dest=(char *)jnb_surface->pixels;
101 src=&screen_buffer[JNB_WIDTH*JNB_HEIGHT];
103 src=&screen_buffer[0];
104 w=(jnb_surface->clip_rect.w>JNB_WIDTH)?(JNB_WIDTH):(jnb_surface->clip_rect.w);
105 h=(jnb_surface->clip_rect.h>JNB_HEIGHT)?(JNB_HEIGHT):(jnb_surface->clip_rect.h);
109 dest+=jnb_surface->pitch;
112 SDL_UnlockSurface(jnb_surface);
113 SDL_Flip(jnb_surface);
117 void setpalette(int index, int count, char *palette)
119 SDL_Color colors[256];
122 for (i = 0; i < count; i++) {
123 colors[i].r = palette[i * 3 + 0] << 2;
124 colors[i].g = palette[i * 3 + 1] << 2;
125 colors[i].b = palette[i * 3 + 2] << 2;
127 SDL_SetColors(jnb_surface, colors, index, count);
131 void fillpalette(int red, int green, int blue)
133 SDL_Color colors[256];
136 for (i = 0; i < 256; i++) {
137 colors[i].r = red << 2;
138 colors[i].g = green << 2;
139 colors[i].b = blue << 2;
141 SDL_SetColors(jnb_surface, colors, 0, 256);
145 void get_block(int page, int x, int y, int width, int height, char *buffer)
148 char *buffer_ptr, *vga_ptr;
154 if (y + height >= JNB_HEIGHT)
155 height = JNB_HEIGHT - y;
156 if (x + width >= JNB_WIDTH)
157 width = JNB_WIDTH - x;
159 for (h = 0; h < height; h++) {
160 buffer_ptr = &buffer[h * width];
162 vga_ptr = get_vgaptr(page, x, h + y);
164 for (w = 0; w < width; w++) {
176 void put_block(int page, int x, int y, int width, int height, char *buffer)
179 char *vga_ptr, *buffer_ptr;
185 if (y + height >= JNB_HEIGHT)
186 height = JNB_HEIGHT - y;
187 if (x + width >= JNB_WIDTH)
188 width = JNB_WIDTH - x;
190 for (h = 0; h < height; h++) {
191 vga_ptr = get_vgaptr(page, x, y + h);
193 buffer_ptr = &buffer[h * width];
194 for (w = 0; w < width; w++) {
195 *vga_ptr = *buffer_ptr;
203 void put_text(int page, int x, int y, char *text, int align)
211 if (text == NULL || strlen(text) == 0)
213 if (font_gobs == NULL)
218 while (text[c1] != 0) {
225 if (t1 >= 33 && t1 <= 34)
228 else if (t1 >= 39 && t1 <= 41)
231 else if (t1 >= 44 && t1 <= 59)
234 else if (t1 >= 64 && t1 <= 90)
237 else if (t1 >= 97 && t1 <= 122)
263 width += pob_width(image, font_gobs) + 1;
274 cur_x = x - width / 2;
277 cur_x = 0; /* this should cause error? -Chuck */
282 while (text[c1] != 0) {
289 if (t1 >= 33 && t1 <= 34)
292 else if (t1 >= 39 && t1 <= 41)
295 else if (t1 >= 44 && t1 <= 59)
298 else if (t1 >= 64 && t1 <= 90)
301 else if (t1 >= 97 && t1 <= 122)
327 put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic);
328 cur_x += pob_width(image, font_gobs) + 1;
333 void put_pob(int page, int x, int y, int image, char *pob_data, int mask, char *mask_pic)
337 char *pob_ptr, *vga_ptr, *mask_ptr;
339 long draw_width, draw_height;
342 if (image < 0 || image >= *(short *) (pob_data))
345 vga_ptr = get_vgaptr(page, 0, 0);
346 pob_offset = *(unsigned long *) (pob_data + (image * 4) + 2);
347 width = draw_width = *(short *) (pob_data + pob_offset);
348 height = draw_height = *(short *) (pob_data + pob_offset + 2);
349 x -= *(short *) (pob_data + pob_offset + 4);
350 y -= *(short *) (pob_data + pob_offset + 6);
352 if ((x + width) <= 0 || x >= 400)
354 if ((y + height) <= 0 || y >= 256)
361 if ((x + width) > 400)
362 draw_width -= x + width - 400;
364 pob_offset += -y * width;
368 if ((y + height) > 256)
369 draw_height -= y + height - 256;
371 pob_ptr = &pob_data[pob_offset];
374 vga_ptr = get_vgaptr(page, x, y);
375 mask_ptr = (char *) (mask_pic + (y * 400) + x);
376 for (c1 = 0; c1 < draw_height; c1++) {
377 for (c2 = 0; c2 < draw_width; c2++) {
379 if (mask == 0 || (mask == 1 && colour == 0)) {
388 pob_ptr += width - c2;
389 vga_ptr += (400 - c2);
390 mask_ptr += (400 - c2);
395 int pob_col(int x1, int y1, int image1, char *pob_data1, int x2, int y2, int image2, char *pob_data2)
398 long pob_offset1, pob_offset2;
399 short width1, width2;
400 short height1, height2;
401 short check_width, check_height;
402 char *pob_ptr1, *pob_ptr2;
404 pob_offset1 = *(long *) (pob_data1 + image1 * 4 + 2);
405 width1 = *(short *) (pob_data1 + pob_offset1);
406 height1 = *(short *) (pob_data1 + pob_offset1 + 2);
407 x1 -= *(short *) (pob_data1 + pob_offset1 + 4);
408 y1 -= *(short *) (pob_data1 + pob_offset1 + 6);
410 pob_offset2 = *(long *) (pob_data2 + image2 * 4 + 2);
411 width2 = *(short *) (pob_data2 + pob_offset2);
412 height2 = *(short *) (pob_data2 + pob_offset2 + 2);
413 x2 -= *(short *) (pob_data2 + pob_offset2 + 4);
414 y2 -= *(short *) (pob_data2 + pob_offset2 + 6);
418 if ((x1 + width1) <= x2)
421 else if ((x1 + width1) <= (x2 + width2)) {
422 pob_offset1 += x2 - x1;
423 check_width = x1 + width1 - x2;
427 pob_offset1 += x2 - x1;
428 check_width = width2;
433 if ((x2 + width2) <= x1)
436 else if ((x2 + width2) <= (x1 + width1)) {
437 pob_offset2 += x1 - x2;
438 check_width = x2 + width2 - x1;
442 pob_offset2 += x1 - x2;
443 check_width = width1;
447 if ((y1 + height1) <= y2)
450 else if ((y1 + height1) <= (y2 + height2)) {
451 pob_offset1 += (y2 - y1) * width1;
452 check_height = y1 + height1 - y2;
456 pob_offset1 += (y2 - y1) * width1;
457 check_height = height2;
462 if ((y2 + height2) <= y1)
465 else if ((y2 + height2) <= (y1 + height1)) {
466 pob_offset2 += (y1 - y2) * width2;
467 check_height = y2 + height2 - y1;
471 pob_offset2 += (y1 - y2) * width2;
472 check_height = height1;
475 pob_ptr1 = (char *) (pob_data1 + pob_offset1);
476 pob_ptr2 = (char *) (pob_data2 + pob_offset2);
477 for (c1 = 0; c1 < check_height; c1++) {
478 for (c2 = 0; c2 < check_width; c2++) {
479 if (*pob_ptr1 != 0 && *pob_ptr2 != 0)
484 pob_ptr1 += width1 - check_width;
485 pob_ptr2 += width2 - check_width;
491 int pob_width(int image, char *pob_data)
493 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2));
497 int pob_height(int image, char *pob_data)
499 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 2);
503 int pob_hs_x(int image, char *pob_data)
505 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 4);
509 int pob_hs_y(int image, char *pob_data)
511 return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 6);
515 int read_pcx(FILE * handle, char *buffer, int buf_len, char *pal)
521 fseek(handle, 128, SEEK_CUR);
523 while (ofs1 < buf_len) {
525 if ((a & 0xc0) == 0xc0) {
528 for (c1 = 0; c1 < a && ofs1 < buf_len; c1++)
529 buffer[ofs1++] = (char) b;
531 buffer[ofs1++] = (char) a;
534 fseek(handle, 1, SEEK_CUR);
535 for (c1 = 0; c1 < 768; c1++)
536 pal[c1] = fgetc(handle) >> 2;
544 int filelength(int handle)
548 if (fstat(handle, &buf) == -1) {
549 perror("filelength");