3 * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
5 * Copyright (C) 2001 tarzeau@space.ch
7 * Copyright (C) 2002 Florian Schulze - crow@icculus.org
9 * Portions of this code are from the MPEG software simulation group
10 * idct implementation. This code will be replaced with a new
11 * implementation soon.
13 * This file is part of Jump'n'Bump.
15 * Jump'n'Bump is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * Jump'n'Bump is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 int screen_height=256;
36 int bytes_per_pixel=1;
37 int dirty_block_shift=4;
39 static int current_pal[256];
40 static SDL_Surface *jnb_surface;
41 static int fullscreen = 0;
42 static int vinited = 0;
43 static void *screen_buffer[2];
44 static int drawing_enable = 0;
45 static void *background = NULL;
46 static int background_drawn;
47 static void *mask = NULL;
48 static int dirty_blocks[2][25*16*2];
50 void *get_vgaptr(int page, int x, int y)
52 assert(drawing_enable==1);
54 return (unsigned char *)screen_buffer[page] + (y*screen_pitch)+(x*bytes_per_pixel);
58 void set_scaling(int scale)
66 screen_pitch=screen_width*bytes_per_pixel;
73 screen_pitch=screen_width*bytes_per_pixel;
77 void open_screen(void)
83 lval = SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_AUDIO);
85 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
93 flags = SDL_SWSURFACE;
95 flags |= SDL_FULLSCREEN;
96 jnb_surface = SDL_SetVideoMode(screen_width, screen_height, bpp, flags);
99 fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
107 memset(current_pal, 0, sizeof(current_pal));
108 memset(dirty_blocks, 0, sizeof(dirty_blocks));
110 screen_buffer[0]=malloc(screen_width*screen_height*bytes_per_pixel);
111 screen_buffer[1]=malloc(screen_width*screen_height*bytes_per_pixel);
114 dirty_blocks[0]=malloc(sizeof(int)*25*16+1000);
115 dirty_blocks[1]=malloc(sizeof(int)*25*16+1000);
128 if (SDL_WM_ToggleFullScreen(jnb_surface))
133 void wait_vrt(int mix)
139 void clear_page(int page, int color)
143 assert(drawing_enable==1);
145 for (i=0; i<(25*16); i++)
146 dirty_blocks[page][i] = 1;
148 if (bytes_per_pixel==1) {
149 unsigned char *buf = get_vgaptr(page, 0, 0);
151 for (i=0; i<screen_height; i++)
152 for (j=0; j<screen_width; j++)
154 } else if (bytes_per_pixel==2) {
155 unsigned short *buf = get_vgaptr(page, 0, 0);
157 for (i=0; i<screen_height; i++)
158 for (j=0; j<screen_width; j++)
161 unsigned int *buf = get_vgaptr(page, 0, 0);
163 for (i=0; i<screen_height; i++)
164 for (j=0; j<screen_width; j++)
170 void clear_lines(int page, int y, int count, int color)
174 assert(drawing_enable==1);
181 if (bytes_per_pixel==1) {
182 for (i=0; i<count; i++) {
183 if ((i+y)<screen_height) {
184 unsigned char *buf = get_vgaptr(page, 0, i+y);
185 for (j=0; j<screen_width; j++)
189 } else if (bytes_per_pixel==2) {
190 for (i=0; i<count; i++) {
191 if ((i+y)<screen_height) {
192 unsigned short *buf = get_vgaptr(page, 0, i+y);
193 for (j=0; j<screen_width; j++)
198 for (i=0; i<count; i++) {
199 if ((i+y)<screen_height) {
200 unsigned int *buf = get_vgaptr(page, 0, i+y);
201 for (j=0; j<screen_width; j++)
206 count = ((y+count)>>dirty_block_shift) - (y>>dirty_block_shift) + 1;
207 y >>= dirty_block_shift;
208 for (i=0; i<count; i++)
210 dirty_blocks[page][(y+i)*25+j] = 1;
214 int get_color(int color, char pal[768])
218 return SDL_MapRGB(jnb_surface->format, (Uint8)(pal[color*3+0]<<2), (Uint8)(pal[color*3+1]<<2), (Uint8)(pal[color*3+2]<<2));
222 int get_pixel(int page, int x, int y)
224 assert(drawing_enable==1);
231 assert(x<screen_width);
232 assert(y<screen_height);
234 if (bytes_per_pixel==1)
235 return *(unsigned char *)get_vgaptr(page, x, y);
236 else if (bytes_per_pixel==2)
237 return *(unsigned short *)get_vgaptr(page, x, y);
239 return *(unsigned int *)get_vgaptr(page, x, y);
243 void set_pixel(int page, int x, int y, int color)
245 assert(drawing_enable==1);
252 assert(x<screen_width);
253 assert(y<screen_height);
255 dirty_blocks[page][(y>>dirty_block_shift)*25+(x>>dirty_block_shift)] = 1;
257 if (bytes_per_pixel==1)
258 *(unsigned char *)get_vgaptr(page, x, y) = color;
259 else if (bytes_per_pixel==2)
260 *(unsigned short *)get_vgaptr(page, x, y) = color;
262 *(unsigned int *)get_vgaptr(page, x, y) = color;
266 static unsigned int colorMask = 0xF7DEF7DE;
267 static unsigned int lowPixelMask = 0x08210821;
268 static unsigned int qcolorMask = 0xE79CE79C;
269 static unsigned int qlowpixelMask = 0x18631863;
270 static unsigned int redblueMask = 0xF81F;
271 static unsigned int greenMask = 0x7E0;
273 int Init_2xSaI (unsigned int BitFormat)
275 if (BitFormat == 565)
277 colorMask = 0xF7DEF7DE;
278 lowPixelMask = 0x08210821;
279 qcolorMask = 0xE79CE79C;
280 qlowpixelMask = 0x18631863;
281 redblueMask = 0xF81F;
284 else if (BitFormat == 555)
286 colorMask = 0x7BDE7BDE;
287 lowPixelMask = 0x04210421;
288 qcolorMask = 0x739C739C;
289 qlowpixelMask = 0x0C630C63;
290 redblueMask = 0x7C1F;
299 Init_2xSaIMMX (BitFormat);
306 void Scale2x (unsigned char *src, unsigned int src_pitch, int src_bytes_per_pixel,
307 unsigned char *dst, unsigned int dst_pitch, int dst_bytes_per_pixel,
308 int width, int height, int pal[256])
310 #define GET_COLOR(x) (pal[(x)])
313 unsigned char *src_line;
314 unsigned char *dst_line[2];
318 dst_line[1] = dst + dst_pitch;
319 for (y=0; y<height; y++) {
320 for (x=0; x<width; x++) {
323 if (src_bytes_per_pixel == 1) {
324 color = GET_COLOR(*(((unsigned char*)src_line) + x));
325 } else if (src_bytes_per_pixel == 2) {
326 color = *(((unsigned short*)src_line) + x);
328 color = *(((unsigned int*)src_line) + x);
331 if (dst_bytes_per_pixel == 2) {
332 *((unsigned long *) (&dst_line[0][x * 4])) = color | (color << 16);
333 *((unsigned long *) (&dst_line[1][x * 4])) = color | (color << 16);
335 *((unsigned long *) (&dst_line[0][x * 8])) = color;
336 *((unsigned long *) (&dst_line[0][x * 8 + 4])) = color;
337 *((unsigned long *) (&dst_line[1][x * 8])) = color;
338 *((unsigned long *) (&dst_line[1][x * 8 + 4])) = color;
342 src_line += src_pitch;
344 if (y < height - 1) {
345 dst_line[0] += dst_pitch * 2;
346 dst_line[1] += dst_pitch * 2;
352 void Super2xSaI (unsigned char *src, unsigned int src_pitch, int src_bytes_per_pixel,
353 unsigned char *dst, unsigned int dst_pitch, int dst_bytes_per_pixel,
354 int width, int height, int pal[256])
356 #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
358 #define INTERPOLATE(A, B) (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask))
360 #define Q_INTERPOLATE(A, B, C, D) ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2) \
361 + ((((A & qlowpixelMask) + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask)) >> 2) & qlowpixelMask)
363 #define GET_COLOR(x) (pal[(x)])
365 unsigned char *src_line[4];
366 unsigned char *dst_line[2];
368 unsigned long color[16];
370 if ( (width<2) || (height<2) ) {
371 Scale2x(src, src_pitch, src_bytes_per_pixel, dst, dst_pitch, dst_bytes_per_pixel, width, height, pal);
375 /* Point to the first 3 lines. */
378 src_line[2] = src + src_pitch;
379 src_line[3] = src + (src_pitch * 2);
382 dst_line[1] = dst + dst_pitch;
386 if (src_bytes_per_pixel == 1) {
389 color[0] = GET_COLOR(*sbp); color[1] = color[0]; color[2] = color[0]; color[3] = color[0];
390 color[4] = color[0]; color[5] = color[0]; color[6] = GET_COLOR(*(sbp + 1)); color[7] = GET_COLOR(*(sbp + 2));
392 color[8] = GET_COLOR(*sbp); color[9] = color[8]; color[10] = GET_COLOR(*(sbp + 1)); color[11] = GET_COLOR(*(sbp + 2));
394 color[12] = GET_COLOR(*sbp); color[13] = color[12]; color[14] = GET_COLOR(*(sbp + 1)); color[15] = GET_COLOR(*(sbp + 2));
395 } else if (src_bytes_per_pixel == 2) {
397 sbp = (unsigned short*)src_line[0];
398 color[0] = *sbp; color[1] = color[0]; color[2] = color[0]; color[3] = color[0];
399 color[4] = color[0]; color[5] = color[0]; color[6] = *(sbp + 1); color[7] = *(sbp + 2);
400 sbp = (unsigned short*)src_line[2];
401 color[8] = *sbp; color[9] = color[8]; color[10] = *(sbp + 1); color[11] = *(sbp + 2);
402 sbp = (unsigned short*)src_line[3];
403 color[12] = *sbp; color[13] = color[12]; color[14] = *(sbp + 1); color[15] = *(sbp + 2);
406 lbp = (unsigned long*)src_line[0];
407 color[0] = *lbp; color[1] = color[0]; color[2] = color[0]; color[3] = color[0];
408 color[4] = color[0]; color[5] = color[0]; color[6] = *(lbp + 1); color[7] = *(lbp + 2);
409 lbp = (unsigned long*)src_line[2];
410 color[8] = *lbp; color[9] = color[8]; color[10] = *(lbp + 1); color[11] = *(lbp + 2);
411 lbp = (unsigned long*)src_line[3];
412 color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2);
415 for (y = 0; y < height; y++) {
417 /* Todo: x = width - 2, x = width - 1 */
419 for (x = 0; x < width; x++) {
420 unsigned long product1a, product1b, product2a, product2b;
422 //--------------------------------------- B0 B1 B2 B3 0 1 2 3
423 // 4 5* 6 S2 -> 4 5* 6 7
424 // 1 2 3 S1 8 9 10 11
425 // A0 A1 A2 A3 12 13 14 15
426 //--------------------------------------
427 if (color[9] == color[6] && color[5] != color[10]) {
428 product2b = color[9];
429 product1b = product2b;
431 else if (color[5] == color[10] && color[9] != color[6]) {
432 product2b = color[5];
433 product1b = product2b;
435 else if (color[5] == color[10] && color[9] == color[6]) {
438 r += GET_RESULT(color[6], color[5], color[8], color[13]);
439 r += GET_RESULT(color[6], color[5], color[4], color[1]);
440 r += GET_RESULT(color[6], color[5], color[14], color[11]);
441 r += GET_RESULT(color[6], color[5], color[2], color[7]);
444 product1b = color[6];
446 product1b = color[5];
448 product1b = INTERPOLATE(color[5], color[6]);
450 product2b = product1b;
454 if (color[6] == color[10] && color[10] == color[13] && color[9] != color[14] && color[10] != color[12])
455 product2b = Q_INTERPOLATE(color[10], color[10], color[10], color[9]);
456 else if (color[5] == color[9] && color[9] == color[14] && color[13] != color[10] && color[9] != color[15])
457 product2b = Q_INTERPOLATE(color[9], color[9], color[9], color[10]);
459 product2b = INTERPOLATE(color[9], color[10]);
461 if (color[6] == color[10] && color[6] == color[1] && color[5] != color[2] && color[6] != color[0])
462 product1b = Q_INTERPOLATE(color[6], color[6], color[6], color[5]);
463 else if (color[5] == color[9] && color[5] == color[2] && color[1] != color[6] && color[5] != color[3])
464 product1b = Q_INTERPOLATE(color[6], color[5], color[5], color[5]);
466 product1b = INTERPOLATE(color[5], color[6]);
469 if (color[5] == color[10] && color[9] != color[6] && color[4] == color[5] && color[5] != color[14])
470 product2a = INTERPOLATE(color[9], color[5]);
471 else if (color[5] == color[8] && color[6] == color[5] && color[4] != color[9] && color[5] != color[12])
472 product2a = INTERPOLATE(color[9], color[5]);
474 product2a = color[9];
476 if (color[9] == color[6] && color[5] != color[10] && color[8] == color[9] && color[9] != color[2])
477 product1a = INTERPOLATE(color[9], color[5]);
478 else if (color[4] == color[9] && color[10] == color[9] && color[8] != color[5] && color[9] != color[0])
479 product1a = INTERPOLATE(color[9], color[5]);
481 product1a = color[5];
483 if (dst_bytes_per_pixel == 2) {
484 *((unsigned long *) (&dst_line[0][x * 4])) = product1a | (product1b << 16);
485 *((unsigned long *) (&dst_line[1][x * 4])) = product2a | (product2b << 16);
487 *((unsigned long *) (&dst_line[0][x * 8])) = product1a;
488 *((unsigned long *) (&dst_line[0][x * 8 + 4])) = product1b;
489 *((unsigned long *) (&dst_line[1][x * 8])) = product2a;
490 *((unsigned long *) (&dst_line[1][x * 8 + 4])) = product2b;
493 /* Move color matrix forward */
494 color[0] = color[1]; color[4] = color[5]; color[8] = color[9]; color[12] = color[13];
495 color[1] = color[2]; color[5] = color[6]; color[9] = color[10]; color[13] = color[14];
496 color[2] = color[3]; color[6] = color[7]; color[10] = color[11]; color[14] = color[15];
500 if (src_bytes_per_pixel == 1) {
501 color[3] = GET_COLOR(*(((unsigned char*)src_line[0]) + x));
502 color[7] = GET_COLOR(*(((unsigned char*)src_line[1]) + x));
503 color[11] = GET_COLOR(*(((unsigned char*)src_line[2]) + x));
504 color[15] = GET_COLOR(*(((unsigned char*)src_line[3]) + x));
505 } else if (src_bytes_per_pixel == 2) {
506 color[3] = *(((unsigned short*)src_line[0]) + x);
507 color[7] = *(((unsigned short*)src_line[1]) + x);
508 color[11] = *(((unsigned short*)src_line[2]) + x);
509 color[15] = *(((unsigned short*)src_line[3]) + x);
511 color[3] = *(((unsigned long*)src_line[0]) + x);
512 color[7] = *(((unsigned long*)src_line[1]) + x);
513 color[11] = *(((unsigned long*)src_line[2]) + x);
514 color[15] = *(((unsigned long*)src_line[3]) + x);
520 /* We're done with one line, so we shift the source lines up */
521 src_line[0] = src_line[1];
522 src_line[1] = src_line[2];
523 src_line[2] = src_line[3];
527 src_line[3] = src_line[2];
529 src_line[3] = src_line[2] + src_pitch;
531 /* Then shift the color matrix up */
532 if (src_bytes_per_pixel == 1) {
535 color[0] = GET_COLOR(*sbp); color[1] = color[0]; color[2] = GET_COLOR(*(sbp + 1)); color[3] = GET_COLOR(*(sbp + 2));
537 color[4] = GET_COLOR(*sbp); color[5] = color[4]; color[6] = GET_COLOR(*(sbp + 1)); color[7] = GET_COLOR(*(sbp + 2));
539 color[8] = GET_COLOR(*sbp); color[9] = color[8]; color[10] = GET_COLOR(*(sbp + 1)); color[11] = GET_COLOR(*(sbp + 2));
541 color[12] = GET_COLOR(*sbp); color[13] = color[12]; color[14] = GET_COLOR(*(sbp + 1)); color[15] = GET_COLOR(*(sbp + 2));
542 } else if (src_bytes_per_pixel == 2) {
544 sbp = (unsigned short*)src_line[0];
545 color[0] = *sbp; color[1] = color[0]; color[2] = *(sbp + 1); color[3] = *(sbp + 2);
546 sbp = (unsigned short*)src_line[1];
547 color[4] = *sbp; color[5] = color[4]; color[6] = *(sbp + 1); color[7] = *(sbp + 2);
548 sbp = (unsigned short*)src_line[2];
549 color[8] = *sbp; color[9] = color[9]; color[10] = *(sbp + 1); color[11] = *(sbp + 2);
550 sbp = (unsigned short*)src_line[3];
551 color[12] = *sbp; color[13] = color[12]; color[14] = *(sbp + 1); color[15] = *(sbp + 2);
554 lbp = (unsigned long*)src_line[0];
555 color[0] = *lbp; color[1] = color[0]; color[2] = *(lbp + 1); color[3] = *(lbp + 2);
556 lbp = (unsigned long*)src_line[1];
557 color[4] = *lbp; color[5] = color[4]; color[6] = *(lbp + 1); color[7] = *(lbp + 2);
558 lbp = (unsigned long*)src_line[2];
559 color[8] = *lbp; color[9] = color[9]; color[10] = *(lbp + 1); color[11] = *(lbp + 2);
560 lbp = (unsigned long*)src_line[3];
561 color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2);
564 if (y < height - 1) {
565 dst_line[0] += dst_pitch * 2;
566 dst_line[1] += dst_pitch * 2;
572 void flippage(int page)
578 assert(drawing_enable==0);
580 SDL_LockSurface(jnb_surface);
581 if (!jnb_surface->pixels) {
583 for (x=0; x<(25*16); x++) {
584 dirty_blocks[0][x] = 1;
585 dirty_blocks[1][x] = 1;
591 dest=(unsigned char *)jnb_surface->pixels;
592 src=screen_buffer[page];
593 Super2xSaI(src, JNB_WIDTH, 1, dest, jnb_surface->pitch, 2, JNB_WIDTH, JNB_HEIGHT, current_pal);
595 dest=(unsigned char *)jnb_surface->pixels;
596 src=screen_buffer[page];
597 for (y=0; y<screen_height; y++) {
598 //memset(&dest[y*jnb_surface->pitch],0,JNB_SURFACE_WIDTH*bytes_per_pixel);
599 for (x=0; x<25; x++) {
605 while ( (test_x<25) && (dirty_blocks[page][(y>>dirty_block_shift)*25+test_x]) ) {
610 memcpy( &dest[y*jnb_surface->pitch+(x<<dirty_block_shift)*bytes_per_pixel],
611 &src[y*screen_pitch+((x<<dirty_block_shift)*bytes_per_pixel)],
612 ((16<<dirty_block_shift)>>4)*bytes_per_pixel*count);
613 //*((pixel_t *)(&dest[(y>>dirty_block_shift)*jnb_surface->pitch+x*bytes_per_pixel]))=0xe0e0;
618 memset(&dirty_blocks[page], 0, sizeof(int)*25*16);
620 SDL_UnlockSurface(jnb_surface);
621 SDL_Flip(jnb_surface);
625 void draw_begin(void)
627 assert(drawing_enable==0);
630 if (background_drawn == 0) {
632 put_block(0, 0, 0, JNB_WIDTH, JNB_HEIGHT, background);
633 put_block(1, 0, 0, JNB_WIDTH, JNB_HEIGHT, background);
634 //put_block(0, 0, 0, rabbit_gobs.width[1], rabbit_gobs.height[1], rabbit_gobs.data[1]);
635 //put_block(1, 0, 0, rabbit_gobs.width[1], rabbit_gobs.height[1], rabbit_gobs.data[1]);
640 background_drawn = 1;
647 assert(drawing_enable==1);
653 void setpalette(int index, int count, char *palette)
655 SDL_Color colors[256];
658 assert(drawing_enable==0);
660 for (i = 0; i < count; i++) {
661 colors[i+index].r = palette[i * 3 + 0] << 2;
662 colors[i+index].g = palette[i * 3 + 1] << 2;
663 colors[i+index].b = palette[i * 3 + 2] << 2;
664 current_pal[i+index] = SDL_MapRGB(jnb_surface->format, colors[i+index].r, colors[i+index].g, colors[i+index].b);
667 SDL_SetColors(jnb_surface, &colors[index], index, count);
671 void fillpalette(int red, int green, int blue)
673 SDL_Color colors[256];
676 assert(drawing_enable==0);
678 for (i = 0; i < 256; i++) {
679 colors[i].r = red << 2;
680 colors[i].g = green << 2;
681 colors[i].b = blue << 2;
682 current_pal[i] = SDL_MapRGB(jnb_surface->format, colors[i].r, colors[i].g, colors[i].b);
685 SDL_SetColors(jnb_surface, colors, 0, 256);
689 void get_block(int page, int x, int y, int width, int height, void *buffer)
691 unsigned char *buffer_ptr, *vga_ptr;
694 assert(drawing_enable==1);
707 if (y + height >= screen_height)
708 height = screen_height - y;
709 if (x + width >= screen_width)
710 width = screen_width - x;
716 vga_ptr = get_vgaptr(page, x, y);
718 for (h = 0; h < height; h++) {
719 memcpy(buffer_ptr, vga_ptr, width * bytes_per_pixel);
720 vga_ptr += screen_pitch;
721 buffer_ptr += width * bytes_per_pixel;
727 void put_block(int page, int x, int y, int width, int height, void *buffer)
730 unsigned char *vga_ptr, *buffer_ptr;
732 assert(drawing_enable==1);
745 if (y + height >= screen_height)
746 height = screen_height - y;
747 if (x + width >= screen_width)
748 width = screen_width - x;
754 vga_ptr = get_vgaptr(page, x, y);
756 for (h = 0; h < height; h++) {
757 memcpy(vga_ptr, buffer_ptr, width * bytes_per_pixel);
758 vga_ptr += screen_pitch;
759 buffer_ptr += width * bytes_per_pixel;
761 width = ((x+width)>>dirty_block_shift) - (x>>dirty_block_shift) + 1;
762 height = ((y+height)>>dirty_block_shift) - (y>>dirty_block_shift) + 1;
763 x >>= dirty_block_shift;
764 y >>= dirty_block_shift;
766 for (h=0; h<height; h++)
767 dirty_blocks[page][(y+h)*25+(x+width)] = 1;
771 void put_text(int page, int x, int y, char *text, int align)
779 assert(drawing_enable==1);
781 if (text == NULL || strlen(text) == 0)
783 if (font_gobs.num_images == 0)
788 while (text[c1] != 0) {
795 if (t1 >= 33 && t1 <= 34)
798 else if (t1 >= 39 && t1 <= 41)
801 else if (t1 >= 44 && t1 <= 59)
804 else if (t1 >= 64 && t1 <= 90)
807 else if (t1 >= 97 && t1 <= 122)
833 width += pob_width(image, &font_gobs) + 1;
844 cur_x = x - width / 2;
847 cur_x = 0; /* this should cause error? -Chuck */
852 while (text[c1] != 0) {
859 if (t1 >= 33 && t1 <= 34)
862 else if (t1 >= 39 && t1 <= 41)
865 else if (t1 >= 44 && t1 <= 59)
868 else if (t1 >= 64 && t1 <= 90)
871 else if (t1 >= 97 && t1 <= 122)
897 put_pob(page, cur_x, y, image, &font_gobs, 1, mask_pic);
898 cur_x += pob_width(image, &font_gobs) + 1;
903 void put_pob(int page, int x, int y, int image, gob_t *gob, int use_mask, void *mask_pic)
908 int draw_width, draw_height;
911 assert(drawing_enable==1);
914 assert(image<gob->num_images);
919 width = draw_width = gob->width[image]*2;
920 height = draw_height = gob->height[image]*2;
921 x -= gob->hs_x[image]*2;
922 y -= gob->hs_y[image]*2;
924 width = draw_width = gob->width[image];
925 height = draw_height = gob->height[image];
926 x -= gob->hs_x[image];
927 y -= gob->hs_y[image];
930 if ((x + width) <= 0 || x >= screen_width)
932 if ((y + height) <= 0 || y >= screen_height)
942 if ((x + width) > screen_width)
943 draw_width -= x + width - screen_width;
949 if ((y + height) > screen_height)
950 draw_height -= y + height - screen_height;
953 if (bytes_per_pixel==1) {
954 unsigned char *vga_ptr;
955 unsigned char *pob_ptr;
956 unsigned char *mask_ptr;
958 vga_ptr = get_vgaptr(page, x, y);
959 pob_ptr = ((unsigned char *)gob->data[image]) + ((pob_y * width) + pob_x);
960 mask_ptr = ((unsigned char *)mask) + ((y * screen_pitch) + (x*bytes_per_pixel));
961 for (c1 = 0; c1 < draw_height; c1++) {
962 for (c2 = 0; c2 < draw_width; c2++) {
964 if (use_mask == 0 || (use_mask == 1 && colour == 0)) {
974 pob_ptr += width - c2;
975 vga_ptr += (screen_width - c2);
976 mask_ptr += (screen_width - c2);
978 } else if (bytes_per_pixel==2) {
979 unsigned short *vga_ptr;
980 unsigned short *pob_ptr;
981 unsigned short *mask_ptr;
983 vga_ptr = get_vgaptr(page, x, y);
984 pob_ptr = (unsigned short *)(((unsigned char *)gob->data[image]) + ((pob_y * width) + pob_x));
985 mask_ptr = (unsigned short *)(((unsigned char *)mask) + ((y * screen_pitch) + (x*bytes_per_pixel)));
986 for (c1 = 0; c1 < draw_height; c1++) {
987 for (c2 = 0; c2 < draw_width; c2++) {
989 if (use_mask == 0 || (use_mask == 1 && colour == 0)) {
999 pob_ptr += width - c2;
1000 vga_ptr += (screen_width - c2);
1001 mask_ptr += (screen_width - c2);
1004 unsigned int *vga_ptr;
1005 unsigned int *pob_ptr;
1006 unsigned int *mask_ptr;
1008 vga_ptr = get_vgaptr(page, x, y);
1009 pob_ptr = (unsigned int *)(((unsigned char *)gob->data[image]) + ((pob_y * width) + pob_x));
1010 mask_ptr = (unsigned int *)(((unsigned char *)mask) + ((y * screen_pitch) + (x*bytes_per_pixel)));
1011 for (c1 = 0; c1 < draw_height; c1++) {
1012 for (c2 = 0; c2 < draw_width; c2++) {
1014 if (use_mask == 0 || (use_mask == 1 && colour == 0)) {
1024 pob_ptr += width - c2;
1025 vga_ptr += (screen_width - c2);
1026 mask_ptr += (screen_width - c2);
1029 draw_width = ((x+draw_width)>>dirty_block_shift) - (x>>dirty_block_shift) + 1;
1030 draw_height = ((y+draw_height)>>dirty_block_shift) - (y>>dirty_block_shift) + 1;
1031 x >>= dirty_block_shift;
1032 y >>= dirty_block_shift;
1033 while (draw_width--)
1034 for (c1=0; c1<draw_height; c1++)
1035 dirty_blocks[page][(y+c1)*25+(x+draw_width)] = 1;
1039 int pob_width(int image, gob_t *gob)
1043 assert(image<gob->num_images);
1044 return gob->width[image];
1048 int pob_height(int image, gob_t *gob)
1052 assert(image<gob->num_images);
1053 return gob->height[image];
1057 int pob_hs_x(int image, gob_t *gob)
1061 assert(image<gob->num_images);
1062 return gob->hs_x[image];
1066 int pob_hs_y(int image, gob_t *gob)
1070 assert(image<gob->num_images);
1071 return gob->hs_y[image];
1075 int read_pcx(FILE * handle, char *buffer, int buf_len, char *pal)
1081 fseek(handle, 128, SEEK_CUR);
1083 while (ofs1 < buf_len) {
1085 if ((a & 0xc0) == 0xc0) {
1088 for (c1 = 0; c1 < a && ofs1 < buf_len; c1++)
1089 buffer[ofs1++] = (char) b;
1091 buffer[ofs1++] = (char) a;
1094 fseek(handle, 1, SEEK_CUR);
1095 for (c1 = 0; c1 < 768; c1++)
1096 pal[c1] = fgetc(handle) >> 2;
1103 void register_background(char *pixels, char pal[768])
1109 background_drawn = 0;
1117 for (i=0; i<256; i++)
1118 int_pal[i] = SDL_MapRGB(jnb_surface->format, (Uint8)(pal[i*3+0]<<2), (Uint8)(pal[i*3+1]<<2), (Uint8)(pal[i*3+2]<<2));
1119 background = malloc(screen_pitch*screen_height);
1121 Super2xSaI(pixels, JNB_WIDTH, 1, (unsigned char *)background, screen_pitch, bytes_per_pixel, JNB_WIDTH, JNB_HEIGHT, int_pal);
1123 background = malloc(JNB_WIDTH*JNB_HEIGHT);
1125 memcpy(background, pixels, JNB_WIDTH*JNB_HEIGHT);
1129 int register_gob(FILE *handle, gob_t *gob, int len)
1131 unsigned char *gob_data;
1134 gob_data = malloc(len);
1135 fread(gob_data, 1, len, handle);
1137 gob->num_images = *(short *)(&gob_data[0]);
1139 gob->width = malloc(gob->num_images*sizeof(int));
1140 gob->height = malloc(gob->num_images*sizeof(int));
1141 gob->hs_x = malloc(gob->num_images*sizeof(int));
1142 gob->hs_y = malloc(gob->num_images*sizeof(int));
1143 gob->data = malloc(gob->num_images*sizeof(void *));
1144 gob->orig_data = malloc(gob->num_images*sizeof(void *));
1145 for (i=0; i<gob->num_images; i++) {
1149 offset = *(int *)(&gob_data[i*4+2]);
1151 gob->width[i] = *(short *)(&gob_data[offset]); offset += 2;
1152 gob->height[i] = *(short *)(&gob_data[offset]); offset += 2;
1153 gob->hs_x[i] = *(short *)(&gob_data[offset]); offset += 2;
1154 gob->hs_y[i] = *(short *)(&gob_data[offset]); offset += 2;
1156 image_size = gob->width[i] * gob->height[i];
1157 gob->orig_data[i] = malloc(image_size);
1158 memcpy(gob->orig_data[i], &gob_data[offset], image_size);
1160 image_size = gob->width[i] * gob->height[i] * 4 * bytes_per_pixel;
1161 gob->data[i] = malloc(image_size);
1163 gob->data[i] = (unsigned short *)gob->orig_data[i];
1171 void recalculate_gob(gob_t *gob, char pal[768])
1179 for (i=1; i<256; i++) {
1180 int_pal[i] = SDL_MapRGB(jnb_surface->format, (Uint8)(pal[i*3+0]<<2), (Uint8)(pal[i*3+1]<<2), (Uint8)(pal[i*3+2]<<2));
1181 if (int_pal[i] == 0)
1182 int_pal[i] = SDL_MapRGB(jnb_surface->format, 8, 8, 8);
1186 for (i=0; i<gob->num_images; i++) {
1187 Super2xSaI(gob->orig_data[i], gob->width[i], 1, (unsigned char *)gob->data[i], gob->width[i]*2*bytes_per_pixel, bytes_per_pixel, gob->width[i], gob->height[i], int_pal);
1191 void register_mask(char *pixels)
1203 for (i=1; i<256; i++)
1204 int_pal[i] = 0xffffffff;
1205 mask = malloc(screen_pitch*screen_height);
1207 Scale2x(pixels, JNB_WIDTH, 1, (unsigned char *)mask, screen_pitch, bytes_per_pixel, JNB_WIDTH, JNB_HEIGHT, int_pal);
1209 mask = malloc(JNB_WIDTH*JNB_HEIGHT);
1211 memcpy(mask, pixels, JNB_WIDTH*JNB_HEIGHT);