From c2a335e1fa9715bae929a4718608023b59a46637 Mon Sep 17 00:00:00 2001 From: Florian Schulze Date: Thu, 21 Feb 2002 04:15:40 +0000 Subject: [PATCH] More cleanups. More separation of drawing and gameing logic. Scaler mostly working, just palette changes aren't possible. --- dos/input.c | 2 +- fireworks.c | 29 +-- globals.h | 72 +++++-- main.c | 165 ++++++++------- menu.c | 22 +- sdl/gfx.c | 569 +++++++++++++++++++++++++++++++--------------------- sdl/input.c | 2 +- sdl/sound.c | 2 +- 8 files changed, 510 insertions(+), 353 deletions(-) diff --git a/dos/input.c b/dos/input.c index 645db5c..0ab68b2 100644 --- a/dos/input.c +++ b/dos/input.c @@ -89,7 +89,7 @@ void read_joy(void) } -int calib_joy(char type) +int calib_joy(int type) { int c1; int x, y; diff --git a/fireworks.c b/fireworks.c index fc0e0d7..39cfba1 100644 --- a/fireworks.c +++ b/fireworks.c @@ -9,7 +9,7 @@ void fireworks(void) int s1, s2, s3; char pal[768]; struct { - char used, direction, colour; + int used, direction, colour; int x, y; int x_add, y_add; int timer; @@ -18,10 +18,11 @@ void fireworks(void) struct { int x, y; int old_x, old_y; - char col, back[2]; + int col; + pixel_t back[2]; } stars[300]; - register_background(NULL); + register_background(NULL, NULL); if ((handle = dat_open("level.pcx", datfile_name, "rb")) == 0) { strcpy(main_info.error_str, "Error loading 'level.pcx', aborting...\n"); @@ -31,6 +32,10 @@ void fireworks(void) fclose(handle); memset(mask_pic, 0, 102400); + register_mask(mask_pic); + + recalculate_gob(&rabbit_gobs, pal); + recalculate_gob(&object_gobs, pal); memset(ban_map, 0, sizeof(ban_map)); @@ -39,8 +44,8 @@ void fireworks(void) draw_begin(); for (c2 = 193; c2 < 256; c2++) { - clear_lines(0, c2, 1, (c2 - 192) >> 2); - clear_lines(1, c2, 1, (c2 - 192) >> 2); + clear_lines(0, c2, 1, get_color((c2 - 192) >> 2, pal)); + clear_lines(1, c2, 1, get_color((c2 - 192) >> 2, pal)); } draw_end(); @@ -51,7 +56,7 @@ void fireworks(void) rabbits[c1].used = 0; rabbits[0].used = 1; - rabbits[0].colour = (char)rnd(4); + rabbits[0].colour = rnd(4); rabbits[0].x = (int) (150 + rnd(100)) << 16; rabbits[0].y = 256 << 16; rabbits[0].x_add = ((int) rnd(65535) << 1) - 65536; @@ -95,9 +100,9 @@ void fireworks(void) stars[c1].old_y = stars[c1].y; stars[c1].y -= (int) (31 - stars[c1].col) * 16384; if ((stars[c1].y >> 16) < 0) - stars[c1].y += 256 << 16; - if ((stars[c1].y >> 16) >= 256) - stars[c1].y -= 256 << 16; + stars[c1].y += JNB_HEIGHT << 16; + if ((stars[c1].y >> 16) >= JNB_HEIGHT) + stars[c1].y -= JNB_HEIGHT << 16; } for (c1 = 0, c2 = 0; c1 < 20; c1++) { @@ -108,7 +113,7 @@ void fireworks(void) for (c1 = 0; c1 < 20; c1++) { if (rabbits[c1].used == 0) { rabbits[c1].used = 1; - rabbits[c1].colour = (char)rnd(4); + rabbits[c1].colour = rnd(4); rabbits[c1].x = (int) (150 + rnd(100)) << 16; rabbits[c1].y = 256 << 16; rabbits[c1].x_add = ((int) rnd(65535) << 1) - 65536; @@ -171,7 +176,7 @@ void fireworks(void) } rabbits[c1].image = player_anims[rabbits[c1].anim].frame[rabbits[c1].frame].image + rabbits[c1].colour * 18 + rabbits[c1].direction * 9; if (rabbits[c1].used == 1) - add_pob(main_info.draw_page, rabbits[c1].x >> 16, rabbits[c1].y >> 16, rabbits[c1].image, rabbit_gobs); + add_pob(main_info.draw_page, rabbits[c1].x >> 16, rabbits[c1].y >> 16, rabbits[c1].image, &rabbit_gobs); } } @@ -183,7 +188,7 @@ void fireworks(void) for (c1 = 0; c1 < 300; c1++) { stars[c1].back[main_info.draw_page] = get_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16); - set_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16, stars[c1].col); + set_pixel(main_info.draw_page, stars[c1].x >> 16, stars[c1].y >> 16, get_color(stars[c1].col, pal)); } dj_mix(); diff --git a/globals.h b/globals.h index fba5f06..8d57775 100644 --- a/globals.h +++ b/globals.h @@ -37,6 +37,24 @@ #define JNB_WIDTH 400 #define JNB_HEIGHT 256 +#ifndef SCALE_UP +#define SCALE_UP2 +#endif + +#if (defined(SCALE_UP) || defined(SCALE_UP2)) +#define JNB_BPP 16 +#define JNB_BYTESPP 2 +#define JNB_SURFACE_WIDTH (JNB_WIDTH*2) +#define JNB_SURFACE_HEIGHT (JNB_HEIGHT*2) +typedef unsigned short pixel_t; +#else +#define JNB_BPP 8 +#define JNB_BYTESPP 1 +#define JNB_SURFACE_WIDTH JNB_WIDTH +#define JNB_SURFACE_HEIGHT JNB_HEIGHT +typedef unsigned char pixel_t; +#endif + #ifndef USE_SDL #define KEY_PL1_LEFT 0xcb #define KEY_PL1_RIGHT 0xcd @@ -108,6 +126,15 @@ #define BAN_ICE 3 #define BAN_SPRING 4 +typedef struct { + int num_images; + int *width; + int *height; + int *hs_x; + int *hs_y; + pixel_t **data; + unsigned char **orig_data; +} gob_t; struct { int joy_enabled, mouse_enabled; @@ -119,11 +146,11 @@ struct { struct { int x, y; int image; - char *pob_data; + gob_t *pob_data; int back_buf_ofs; } pobs[NUM_POBS]; } page_info[2]; - char *pob_backbuf[2]; + pixel_t pob_backbuf[2][JNB_SURFACE_WIDTH*JNB_SURFACE_HEIGHT]; } main_info; struct { @@ -133,7 +160,7 @@ struct { int bumped[4]; int x, y; int x_add, y_add; - char direction, jump_ready, jump_abort, in_water; + int direction, jump_ready, jump_abort, in_water; int anim, frame, frame_tick, image; } player[4]; @@ -175,8 +202,10 @@ char datfile_name[2048]; char *background_pic; char *mask_pic; -char *rabbit_gobs; -char *font_gobs; +extern gob_t rabbit_gobs; +extern gob_t font_gobs; +extern gob_t object_gobs; +extern gob_t number_gobs; /* fireworks.c */ @@ -191,12 +220,12 @@ void position_player(int player_num); void fireworks(void); void add_object(int type, int x, int y, int x_add, int y_add, int anim, int frame); void update_objects(void); -int add_pob(int page, int x, int y, int image, char *pob_data); +int add_pob(int page, int x, int y, int image, gob_t *pob_data); void draw_flies(int page); void draw_pobs(int page); void redraw_flies_background(int page); void redraw_pob_backgrounds(int page); -int add_leftovers(int page, int x, int y, int image, char *pob_data); +int add_leftovers(int page, int x, int y, int image, gob_t *pob_data); void draw_leftovers(int page); int init_level(int level, char *pal); void deinit_level(void); @@ -213,7 +242,7 @@ void write_calib_data(void); void update_player_actions(void); void init_inputs(void); -int calib_joy(char type); +int calib_joy(int type); /* menu.c */ @@ -231,27 +260,30 @@ void draw_end(void); void flippage(int page); void draw_begin(void); void draw_end(void); -void clear_lines(int page, int y, int count, int color); -int get_pixel(int page, int x, int y); -void set_pixel(int page, int x, int y, int color); +void clear_lines(int page, int y, int count, pixel_t color); +pixel_t get_color(int color, char pal[768]); +pixel_t get_pixel(int page, int x, int y); +void set_pixel(int page, int x, int y, pixel_t color); void setpalette(int index, int count, char *palette); void fillpalette(int red, int green, int blue); #ifdef DOS void get_block(char page, short x, short y, short width, short height, char *buffer); void put_block(char page, short x, short y, short width, short height, char *buffer); #else -void get_block(int page, int x, int y, int width, int height, char *buffer); -void put_block(int page, int x, int y, int width, int height, char *buffer); +void get_block(int page, int x, int y, int width, int height, pixel_t *buffer); +void put_block(int page, int x, int y, int width, int height, pixel_t *buffer); #endif void put_text(int page, int x, int y, char *text, int align); -void put_pob(int page, int x, int y, int image, char *pob_data, int mask, char *mask_pic); -int pob_col(int x1, int y1, int image1, char *pob_data1, int x2, int y2, int image2, char *pob_data2); -int pob_width(int image, char *pob_data); -int pob_height(int image, char *pob_data); -int pob_hs_x(int image, char *pob_data); -int pob_hs_y(int image, char *pob_data); +void put_pob(int page, int x, int y, int image, gob_t *gob, int mask, unsigned char *mask_pic); +int pob_width(int image, gob_t *gob); +int pob_height(int image, gob_t *gob); +int pob_hs_x(int image, gob_t *gob); +int pob_hs_y(int image, gob_t *gob); int read_pcx(FILE * handle, char *buffer, int buf_len, char *pal); -void register_background(char *pixels); +void register_background(char *pixels, char pal[768]); +int register_gob(FILE *handle, gob_t *gob, int len); +void recalculate_gob(gob_t *gob, char pal[768]); +void register_mask(char *pixels); /* gfx.c */ diff --git a/main.c b/main.c index 90edcdc..3dfb537 100644 --- a/main.c +++ b/main.c @@ -4,8 +4,10 @@ #define M_PI 3.14159265358979323846 #endif -char *object_gobs; -char *number_gobs; +gob_t rabbit_gobs = { 0 }; +gob_t font_gobs = { 0 }; +gob_t object_gobs = { 0 }; +gob_t number_gobs = { 0 }; unsigned int ban_map[17][22] = { {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, @@ -153,7 +155,8 @@ struct { struct { int x, y; int old_x, old_y; - char back[2], back_defined[2]; + pixel_t back[2]; + int back_defined[2]; } flies[NUM_FLIES]; struct { @@ -162,12 +165,12 @@ struct { struct { int x, y; int image; - char *pob_data; + gob_t *pob_data; } pobs[NUM_LEFTOVERS]; } page[2]; } leftovers; -char pogostick, bunnies_in_space, jetpack, lord_of_the_flies, blood_is_thicker_than_water; +int pogostick, bunnies_in_space, jetpack, lord_of_the_flies, blood_is_thicker_than_water; int main(int argc, char *argv[]) { @@ -176,9 +179,8 @@ int main(int argc, char *argv[]) int l1; int s1, s2, s3, s4; int closest_player = 0, dist, cur_dist; - char end_loop_flag, fade_flag; - char mod_vol, sfx_vol, mod_fade_direction; - char *ptr1 = (char *) NULL; + int end_loop_flag, fade_flag; + int mod_vol, sfx_vol, mod_fade_direction; char str1[100]; char pal[768]; char cur_pal[768]; @@ -207,8 +209,13 @@ int main(int argc, char *argv[]) memset(cur_pal, 0, 768); setpalette(0, 256, cur_pal); + recalculate_gob(&rabbit_gobs, pal); + recalculate_gob(&font_gobs, pal); + recalculate_gob(&object_gobs, pal); + recalculate_gob(&number_gobs, pal); + flippage(1); - register_background(background_pic); + register_background(background_pic, pal); flippage(0); s1 = rnd(250) + 50; @@ -227,8 +234,8 @@ int main(int argc, char *argv[]) mod_vol = sfx_vol = 10; mod_fade_direction = 1; dj_ready_mod(MOD_GAME); - dj_set_mod_volume(mod_vol); - dj_set_sfx_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); + dj_set_sfx_volume((char)mod_vol); dj_start_mod(); dj_play_sfx(SFX_FLY, SFX_FLY_FREQ, 0, 0, 0, 4); dj_set_nosound(0); @@ -375,10 +382,10 @@ int main(int argc, char *argv[]) player[c1].bumps++; player[c1].bumped[c2]++; s1 = player[c1].bumps % 100; - add_leftovers(0, 360, 34 + c1 * 64, s1 / 10, number_gobs); - add_leftovers(1, 360, 34 + c1 * 64, s1 / 10, number_gobs); - add_leftovers(0, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, number_gobs); - add_leftovers(1, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, number_gobs); + add_leftovers(0, 360, 34 + c1 * 64, s1 / 10, &number_gobs); + add_leftovers(1, 360, 34 + c1 * 64, s1 / 10, &number_gobs); + add_leftovers(0, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, &number_gobs); + add_leftovers(1, 376, 34 + c1 * 64, s1 - (s1 / 10) * 10, &number_gobs); } } else { if (player[c2].y_add < 0) @@ -412,10 +419,10 @@ int main(int argc, char *argv[]) player[c2].bumps++; player[c2].bumped[c1]++; s1 = player[c2].bumps % 100; - add_leftovers(0, 360, 34 + c2 * 64, s1 / 10, number_gobs); - add_leftovers(1, 360, 34 + c2 * 64, s1 / 10, number_gobs); - add_leftovers(0, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, number_gobs); - add_leftovers(1, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, number_gobs); + add_leftovers(0, 360, 34 + c2 * 64, s1 / 10, &number_gobs); + add_leftovers(1, 360, 34 + c2 * 64, s1 / 10, &number_gobs); + add_leftovers(0, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, &number_gobs); + add_leftovers(1, 376, 34 + c2 * 64, s1 - (s1 / 10) * 10, &number_gobs); } } else { if (player[c1].y_add < 0) @@ -575,7 +582,7 @@ int main(int argc, char *argv[]) main_info.page_info[main_info.draw_page].pobs[s1].x = player[c1].x >> 16; main_info.page_info[main_info.draw_page].pobs[s1].y = player[c1].y >> 16; main_info.page_info[main_info.draw_page].pobs[s1].image = player[c1].image + c1 * 18; - main_info.page_info[main_info.draw_page].pobs[s1].pob_data = rabbit_gobs; + main_info.page_info[main_info.draw_page].pobs[s1].pob_data = &rabbit_gobs; s1++; } } @@ -593,24 +600,24 @@ int main(int argc, char *argv[]) if (mod_fade_direction == 1) { if (mod_vol < 30) { mod_vol++; - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); } } else { if (mod_vol > 0) { mod_vol--; - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); } } if (mod_fade_direction == 1) { if (sfx_vol < 64) { sfx_vol++; - dj_set_sfx_volume(sfx_vol); + dj_set_sfx_volume((char)sfx_vol); } } else { if (sfx_vol > 0) { sfx_vol--; - dj_set_sfx_volume(sfx_vol); + dj_set_sfx_volume((char)sfx_vol); } } @@ -659,8 +666,10 @@ int main(int argc, char *argv[]) deinit_level(); memset(mask_pic, 0, 102400L); + register_mask(mask_pic); - register_background(NULL); + recalculate_gob(&font_gobs, pal); + register_background(NULL, NULL); draw_begin(); @@ -707,14 +716,14 @@ int main(int argc, char *argv[]) mod_vol = 0; dj_ready_mod(MOD_SCORES); - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); dj_start_mod(); dj_set_nosound(0); while (key_pressed(1) == 0) { if (mod_vol < 35) mod_vol++; - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); for (c1 = 0; c1 < 768; c1++) { if (cur_pal[c1] < pal[c1]) cur_pal[c1]++; @@ -734,7 +743,7 @@ int main(int argc, char *argv[]) while (mod_vol > 0) { mod_vol--; - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); for (c1 = 0; c1 < 768; c1++) { if (cur_pal[c1] > pal[c1]) cur_pal[c1]--; @@ -1241,7 +1250,7 @@ void update_objects(void) } } if (objects[c1].used == 1) - add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs); + add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, &object_gobs); break; case OBJ_SPLASH: objects[c1].ticks--; @@ -1255,7 +1264,7 @@ void update_objects(void) } } if (objects[c1].used == 1) - add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs); + add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, &object_gobs); break; case OBJ_SMOKE: objects[c1].x += objects[c1].x_add; @@ -1271,7 +1280,7 @@ void update_objects(void) } } if (objects[c1].used == 1) - add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs); + add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, &object_gobs); break; case OBJ_YEL_BUTFLY: case OBJ_PINK_BUTFLY: @@ -1369,7 +1378,7 @@ void update_objects(void) } } if (objects[c1].used == 1) - add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs); + add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, &object_gobs); break; case OBJ_FUR: if (rnd(100) < 30) @@ -1447,7 +1456,7 @@ void update_objects(void) s1 = 0; if (s1 > 7) s1 = 7; - add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame + s1, object_gobs); + add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame + s1, &object_gobs); } break; case OBJ_FLESH: @@ -1512,8 +1521,8 @@ void update_objects(void) } else { if (rnd(100) < 10) { s1 = rnd(4) - 2; - add_leftovers(0, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, object_gobs); - add_leftovers(1, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, object_gobs); + add_leftovers(0, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, &object_gobs); + add_leftovers(1, objects[c1].x >> 16, (objects[c1].y >> 16) + s1, objects[c1].frame, &object_gobs); } objects[c1].used = 0; } @@ -1531,7 +1540,7 @@ void update_objects(void) if (objects[c1].x_add > 0 && objects[c1].x_add < 16384) objects[c1].x_add = 16384; if (objects[c1].used == 1) - add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame, object_gobs); + add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].frame, &object_gobs); break; case OBJ_FLESH_TRACE: objects[c1].ticks--; @@ -1545,7 +1554,7 @@ void update_objects(void) } } if (objects[c1].used == 1) - add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, object_gobs); + add_pob(main_info.draw_page, objects[c1].x >> 16, objects[c1].y >> 16, objects[c1].image, &object_gobs); break; } } @@ -1554,7 +1563,7 @@ void update_objects(void) } -int add_pob(int page, int x, int y, int image, char *pob_data) +int add_pob(int page, int x, int y, int image, gob_t *pob_data) { if (main_info.page_info[page].num_pobs >= NUM_POBS) @@ -1592,8 +1601,12 @@ void draw_pobs(int page) for (c1 = main_info.page_info[page].num_pobs - 1; c1 >= 0; c1--) { main_info.page_info[page].pobs[c1].back_buf_ofs = back_buf_ofs; - get_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), (char *) (main_info.pob_backbuf[page] + back_buf_ofs)); + get_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), &main_info.pob_backbuf[page][back_buf_ofs]); +#ifdef SCALE_UP2 + back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * 4 * JNB_BYTESPP; +#else back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data); +#endif put_pob(page, main_info.page_info[page].pobs[c1].x, main_info.page_info[page].pobs[c1].y, main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data, 1, mask_pic); } @@ -1616,12 +1629,12 @@ void redraw_pob_backgrounds(int page) int c1; for (c1 = 0; c1 < main_info.page_info[page].num_pobs; c1++) - put_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), (char *) (main_info.pob_backbuf[page] + main_info.page_info[page].pobs[c1].back_buf_ofs)); + put_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), &main_info.pob_backbuf[page][main_info.page_info[page].pobs[c1].back_buf_ofs]); } -int add_leftovers(int page, int x, int y, int image, char *pob_data) +int add_leftovers(int page, int x, int y, int image, gob_t *pob_data) { if (leftovers.page[page].num_pobs >= NUM_LEFTOVERS) @@ -1674,6 +1687,7 @@ int init_level(int level, char *pal) return 1; } fclose(handle); + register_mask(mask_pic); for (c1 = 0; c1 < 4; c1++) { if (player[c1].enabled == 1) { @@ -1745,8 +1759,8 @@ int init_program(int argc, char *argv[], char *pal) { FILE *handle = (FILE *) NULL; int c1 = 0, c2 = 0; - char load_flag = 0; - char force2, force3; + int load_flag = 0; + int force2, force3; sfx_data fly; int player_anim_data[] = { 1, 0, 0, 0x7fff, 0, 0, 0, 0, 0, 0, @@ -1815,63 +1829,58 @@ int init_program(int argc, char *argv[], char *pal) } } - if ((background_pic = malloc(102400)) == NULL) - return 1; - if ((mask_pic = malloc(102400)) == NULL) + if ((handle = dat_open("menu.pcx", datfile_name, "rb")) == 0) { + strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n"); return 1; - memset(mask_pic, 0, 102400); - - main_info.pob_backbuf[0] = malloc(65535); - main_info.pob_backbuf[1] = malloc(65535); - if (main_info.pob_backbuf[0] == 0 || main_info.pob_backbuf[1] == 0) + } + if (read_pcx(handle, background_pic, 102400L, pal) != 0) { + strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n"); return 1; + } + fclose(handle); if ((handle = dat_open("rabbit.gob", datfile_name, "rb")) == 0) { strcpy(main_info.error_str, "Error loading 'rabbit.gob', aborting...\n"); return 1; } - if ((rabbit_gobs = malloc(dat_filelen("rabbit.gob", datfile_name))) == 0) { - strcpy(main_info.error_str, "Not enough memory, aborting...\n"); + if (register_gob(handle, &rabbit_gobs, dat_filelen("rabbit.gob", datfile_name))) { + /* error */ fclose(handle); return 1; } - fread(rabbit_gobs, 1, dat_filelen("rabbit.gob", datfile_name), handle); fclose(handle); if ((handle = dat_open("objects.gob", datfile_name, "rb")) == 0) { strcpy(main_info.error_str, "Error loading 'objects.gob', aborting...\n"); return 1; } - if ((object_gobs = malloc(dat_filelen("objects.gob", datfile_name))) == 0) { - strcpy(main_info.error_str, "Not enough memory, aborting...\n"); + if (register_gob(handle, &object_gobs, dat_filelen("objects.gob", datfile_name))) { + /* error */ fclose(handle); return 1; } - fread(object_gobs, 1, dat_filelen("objects.gob", datfile_name), handle); fclose(handle); if ((handle = dat_open("font.gob", datfile_name, "rb")) == 0) { strcpy(main_info.error_str, "Error loading 'font.gob', aborting...\n"); return 1; } - if ((font_gobs = malloc(dat_filelen("font.gob", datfile_name))) == 0) { - strcpy(main_info.error_str, "Not enough memory, aborting...\n"); + if (register_gob(handle, &font_gobs, dat_filelen("font.gob", datfile_name))) { + /* error */ fclose(handle); return 1; } - fread(font_gobs, 1, dat_filelen("font.gob", datfile_name), handle); fclose(handle); if ((handle = dat_open("numbers.gob", datfile_name, "rb")) == 0) { strcpy(main_info.error_str, "Error loading 'numbers.gob', aborting...\n"); return 1; } - if ((number_gobs = malloc(dat_filelen("numbers.gob", datfile_name))) == 0) { - strcpy(main_info.error_str, "Not enough memory, aborting...\n"); + if (register_gob(handle, &number_gobs, dat_filelen("numbers.gob", datfile_name))) { + /* error */ fclose(handle); return 1; } - fread(number_gobs, 1, dat_filelen("numbers.gob", datfile_name), handle); fclose(handle); if (read_level() != 0) { @@ -1881,6 +1890,7 @@ int init_program(int argc, char *argv[], char *pal) } dj_init(); + if (main_info.no_sound == 0) { dj_autodetect_sd(); dj_set_mixing_freq(20000); @@ -1981,15 +1991,12 @@ int init_program(int argc, char *argv[], char *pal) dj_set_sfx_settings(SFX_FLY, &fly); } - if ((handle = dat_open("menu.pcx", datfile_name, "rb")) == 0) { - strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n"); + if ((background_pic = malloc(102400)) == NULL) return 1; - } - if (read_pcx(handle, background_pic, 102400L, pal) != 0) { - strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n"); + if ((mask_pic = malloc(102400)) == NULL) return 1; - } - fclose(handle); + memset(mask_pic, 0, 102400); + register_mask(mask_pic); setpalette(0, 256, pal); @@ -2006,7 +2013,8 @@ int init_program(int argc, char *argv[], char *pal) if (calib_joy(0) != 0) load_flag = 1; else { - register_background(NULL); + recalculate_gob(&font_gobs, pal); + register_background(NULL, NULL); main_info.view_page = 1; flippage(1); @@ -2022,7 +2030,8 @@ int init_program(int argc, char *argv[], char *pal) if (calib_joy(1) != 0) load_flag = 1; else { - register_background(NULL); + recalculate_gob(&font_gobs, pal); + register_background(NULL, NULL); flippage(0); wait_vrt(0); @@ -2082,18 +2091,6 @@ void deinit_program(void) dj_free_sfx(SFX_SPLASH); dj_deinit(); - if (rabbit_gobs != 0) - free(rabbit_gobs); - if (object_gobs != 0) - free(object_gobs); - if (number_gobs != 0) - free(number_gobs); - - if (main_info.pob_backbuf[0] != 0) - free(main_info.pob_backbuf[0]); - if (main_info.pob_backbuf[1] != 0) - free(main_info.pob_backbuf[1]); - if (background_pic != 0) free(background_pic); if (mask_pic != 0) diff --git a/menu.c b/menu.c index 35f16be..e021b4e 100644 --- a/menu.c +++ b/menu.c @@ -38,9 +38,9 @@ char *message[] = { int menu(void) { int c1; - char esc_pressed; - char end_loop_flag, new_game_flag, fade_flag; - char mod_vol = 0, mod_fade_direction = 0; + int esc_pressed; + int end_loop_flag, new_game_flag, fade_flag; + int mod_vol = 0, mod_fade_direction = 0; int cur_message; int fade_dir, fade_count, fade_tick; char fade_pal[48]; @@ -51,7 +51,7 @@ int menu(void) mod_vol = 0; mod_fade_direction = 1; dj_ready_mod(MOD_MENU); - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); dj_set_sfx_volume(64); dj_start_mod(); dj_set_nosound(0); @@ -396,7 +396,7 @@ int menu(void) main_info.page_info[main_info.draw_page].num_pobs = 0; for (c1 = 3; c1 >= 0; c1--) - add_pob(main_info.draw_page, player[c1].x >> 16, player[c1].y >> 16, player[c1].image + c1 * 18, rabbit_gobs); + add_pob(main_info.draw_page, player[c1].x >> 16, player[c1].y >> 16, player[c1].image + c1 * 18, &rabbit_gobs); update_objects(); @@ -409,12 +409,12 @@ int menu(void) if (mod_fade_direction == 1) { if (mod_vol < 35) { mod_vol++; - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); } } else { if (mod_vol > 0) { mod_vol--; - dj_set_mod_volume(mod_vol); + dj_set_mod_volume((char)mod_vol); } } @@ -533,7 +533,11 @@ int menu_init(void) fclose(handle); memset(menu_cur_pal, 0, 768); - register_background(background_pic); + recalculate_gob(&rabbit_gobs, menu_pal); + recalculate_gob(&font_gobs, menu_pal); + recalculate_gob(&object_gobs, menu_pal); + register_background(background_pic, menu_pal); + register_mask(mask_pic); for (c1 = 0; c1 < 4; c1++) { player[c1].enabled = 0; @@ -541,7 +545,7 @@ int menu_init(void) player[c1].y = (160L + c1 * 2) << 16; player[c1].x_add = 0; player[c1].y_add = 0; - player[c1].direction = (char)rnd(2); + player[c1].direction = rnd(2); player[c1].jump_ready = 1; player[c1].anim = 0; player[c1].frame = 0; diff --git a/sdl/gfx.c b/sdl/gfx.c index 0ba83e8..f926e50 100644 --- a/sdl/gfx.c +++ b/sdl/gfx.c @@ -1,25 +1,20 @@ #include "globals.h" -#define SCALE_UP -#define JNB_BPP 8 static int current_pal[256]; static SDL_Surface *jnb_surface; static int fullscreen = 0; static int vinited = 0; -static unsigned char screen_buffer[2][JNB_WIDTH*JNB_HEIGHT]; +static pixel_t screen_buffer[2][JNB_SURFACE_WIDTH*JNB_SURFACE_HEIGHT]; static int drawing_enable = 0; -static char *background; +static pixel_t *background = NULL; static int background_drawn; +static pixel_t *mask = NULL; -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; - -char *get_vgaptr(int page, int x, int y) +pixel_t *get_vgaptr(int page, int x, int y) { assert(drawing_enable==1); - return &screen_buffer[page][y*JNB_WIDTH+x]; + return &screen_buffer[page][y*JNB_SURFACE_WIDTH+x]; } @@ -33,17 +28,11 @@ void open_screen(void) exit(EXIT_FAILURE); } -#ifdef SCALE_UP - if (fullscreen) - jnb_surface = SDL_SetVideoMode(JNB_WIDTH*2, JNB_HEIGHT*2, 16, SDL_SWSURFACE | SDL_FULLSCREEN); - else - jnb_surface = SDL_SetVideoMode(JNB_WIDTH*2, JNB_HEIGHT*2, 16, SDL_SWSURFACE); -#else if (fullscreen) - jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE | SDL_FULLSCREEN); + jnb_surface = SDL_SetVideoMode(JNB_SURFACE_WIDTH, JNB_SURFACE_HEIGHT, JNB_BPP, SDL_SWSURFACE | SDL_FULLSCREEN); else - jnb_surface = SDL_SetVideoMode(JNB_WIDTH, JNB_HEIGHT, JNB_BPP, SDL_SWSURFACE); -#endif + jnb_surface = SDL_SetVideoMode(JNB_SURFACE_WIDTH, JNB_SURFACE_HEIGHT, JNB_BPP, SDL_SWSURFACE); + if (!jnb_surface) { fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError()); exit(EXIT_FAILURE); @@ -78,48 +67,80 @@ void wait_vrt(int mix) void clear_page(int page, int color) { + int i,j; + pixel_t *buf = get_vgaptr(page, 0, 0); + assert(drawing_enable==1); - memset((void *) get_vgaptr(page, 0, 0), color, JNB_WIDTH * JNB_HEIGHT); + for (i=0; iformat, (Uint8)(pal[color*3+0]<<2), (Uint8)(pal[color*3+1]<<2), (Uint8)(pal[color*3+2]<<2)); } -int get_pixel(int page, int x, int y) +pixel_t get_pixel(int page, int x, int y) { assert(drawing_enable==1); +#ifdef SCALE_UP2 + x *= 2; + y *= 2; +#endif + assert(x> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask)) @@ -159,13 +184,8 @@ int Init_2xSaI (uint32 BitFormat) #define Q_INTERPOLATE(A, B, C, D) ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2) \ + ((((A & qlowpixelMask) + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask)) >> 2) & qlowpixelMask) -#define GET_COLOR(x) (current_pal[(x)]) - +#define GET_COLOR(x) (pal[(x)]) -void Super2xSaI2 (uint8 *src, uint32 src_pitch, int src_bytes_per_pixel, - uint8 *dst, uint32 dst_pitch, int dst_bytes_per_pixel, - int width, int height) -{ unsigned char *src_line[4]; unsigned char *dst_line[2]; int x, y; @@ -368,27 +388,72 @@ void Super2xSaI2 (uint8 *src, uint32 src_pitch, int src_bytes_per_pixel, } +void Scale2x (unsigned char *src, unsigned int src_pitch, int src_bytes_per_pixel, + unsigned char *dst, unsigned int dst_pitch, int dst_bytes_per_pixel, + int width, int height, int pal[256]) +{ +#define GET_COLOR(x) (pal[(x)]) + + int x,y; + unsigned char *src_line; + unsigned char *dst_line[2]; + + src_line = src; + dst_line[0] = dst; + dst_line[1] = dst + dst_pitch; + for (y=0; ypixels; + dest=(unsigned char *)jnb_surface->pixels; src=screen_buffer[page]; #ifdef SCALE_UP - Super2xSaI2(src, JNB_WIDTH, 1, dest, jnb_surface->pitch, 2, JNB_WIDTH, JNB_HEIGHT); + Super2xSaI(src, JNB_WIDTH, 1, dest, jnb_surface->pitch, 2, JNB_WIDTH, JNB_HEIGHT, current_pal); #else - w=(jnb_surface->clip_rect.w>JNB_WIDTH)?(JNB_WIDTH):(jnb_surface->clip_rect.w); - h=(jnb_surface->clip_rect.h>JNB_HEIGHT)?(JNB_HEIGHT):(jnb_surface->clip_rect.h); + w=(jnb_surface->clip_rect.w>JNB_SURFACE_WIDTH)?(JNB_SURFACE_WIDTH):(jnb_surface->clip_rect.w); + h=(jnb_surface->clip_rect.h>JNB_SURFACE_HEIGHT)?(JNB_SURFACE_HEIGHT):(jnb_surface->clip_rect.h); for (; h>0; h--) { - memcpy(dest,src,w); + memcpy(dest,src,w*JNB_BYTESPP); dest+=jnb_surface->pitch; - src+=JNB_WIDTH; + src+=JNB_SURFACE_WIDTH; } #endif SDL_UnlockSurface(jnb_surface); @@ -405,6 +470,8 @@ void draw_begin(void) if (background) { put_block(0, 0, 0, JNB_WIDTH, JNB_HEIGHT, background); put_block(1, 0, 0, JNB_WIDTH, JNB_HEIGHT, background); + //put_block(0, 0, 0, rabbit_gobs.width[1], rabbit_gobs.height[1], rabbit_gobs.data[1]); + //put_block(1, 0, 0, rabbit_gobs.width[1], rabbit_gobs.height[1], rabbit_gobs.data[1]); } else { clear_page(0, 0); clear_page(1, 0); @@ -460,64 +527,77 @@ void fillpalette(int red, int green, int blue) } -void get_block(int page, int x, int y, int width, int height, char *buffer) +void get_block(int page, int x, int y, int width, int height, pixel_t *buffer) { - short w, h; - char *buffer_ptr, *vga_ptr; + int h; + pixel_t *buffer_ptr, *vga_ptr; assert(drawing_enable==1); +#ifdef SCALE_UP2 + x *= 2; + y *= 2; + width *= 2; + height *= 2; +#endif + if (x < 0) x = 0; if (y < 0) y = 0; - if (y + height >= JNB_HEIGHT) - height = JNB_HEIGHT - y; - if (x + width >= JNB_WIDTH) - width = JNB_WIDTH - x; + if (y + height >= JNB_SURFACE_HEIGHT) + height = JNB_SURFACE_HEIGHT - y; + if (x + width >= JNB_SURFACE_WIDTH) + width = JNB_SURFACE_WIDTH - x; + if (width<=0) + return; + if(height<=0) + return; + vga_ptr = get_vgaptr(page, x, y); + buffer_ptr = buffer; for (h = 0; h < height; h++) { - buffer_ptr = &buffer[h * width]; - - vga_ptr = get_vgaptr(page, x, h + y); - - for (w = 0; w < width; w++) { - unsigned char ch; - ch = *vga_ptr; - *buffer_ptr = ch; - buffer_ptr++; - vga_ptr++; - } + memcpy(buffer_ptr, vga_ptr, width * JNB_BYTESPP); + vga_ptr += JNB_SURFACE_WIDTH; + buffer_ptr += width; } } -void put_block(int page, int x, int y, int width, int height, char *buffer) +void put_block(int page, int x, int y, int width, int height, pixel_t *buffer) { - short w, h; - char *vga_ptr, *buffer_ptr; + int h; + pixel_t *vga_ptr, *buffer_ptr; assert(drawing_enable==1); +#ifdef SCALE_UP2 + x *= 2; + y *= 2; + width *= 2; + height *= 2; +#endif + if (x < 0) x = 0; if (y < 0) y = 0; - if (y + height >= JNB_HEIGHT) - height = JNB_HEIGHT - y; - if (x + width >= JNB_WIDTH) - width = JNB_WIDTH - x; + if (y + height >= JNB_SURFACE_HEIGHT) + height = JNB_SURFACE_HEIGHT - y; + if (x + width >= JNB_SURFACE_WIDTH) + width = JNB_SURFACE_WIDTH - x; + if (width<=0) + return; + if(height<=0) + return; + vga_ptr = get_vgaptr(page, x, y); + buffer_ptr = buffer; for (h = 0; h < height; h++) { - vga_ptr = get_vgaptr(page, x, y + h); - - buffer_ptr = &buffer[h * width]; - for (w = 0; w < width; w++) { - *vga_ptr = *buffer_ptr; - vga_ptr++; - buffer_ptr++; - } + memcpy(vga_ptr, buffer_ptr, width * JNB_BYTESPP); + vga_ptr += JNB_SURFACE_WIDTH; + buffer_ptr += width; } } @@ -534,7 +614,7 @@ void put_text(int page, int x, int y, char *text, int align) if (text == NULL || strlen(text) == 0) return; - if (font_gobs == NULL) + if (font_gobs.num_images == 0) return; width = 0; @@ -584,7 +664,7 @@ void put_text(int page, int x, int y, char *text, int align) else continue; - width += pob_width(image, font_gobs) + 1; + width += pob_width(image, &font_gobs) + 1; } switch (align) { @@ -648,193 +728,120 @@ void put_text(int page, int x, int y, char *text, int align) else continue; - put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic); - cur_x += pob_width(image, font_gobs) + 1; + put_pob(page, cur_x, y, image, &font_gobs, 1, mask_pic); + cur_x += pob_width(image, &font_gobs) + 1; } } -void put_pob(int page, int x, int y, int image, char *pob_data, int mask, char *mask_pic) +void put_pob(int page, int x, int y, int image, gob_t *gob, int use_mask, unsigned char *mask_pic) { - long c1, c2; - long pob_offset; - char *pob_ptr, *vga_ptr, *mask_ptr; - long width, height; - long draw_width, draw_height; - char colour; + int c1, c2; + int pob_offset; + pixel_t *pob_ptr; + pixel_t *vga_ptr; + pixel_t *mask_ptr; + int width, height; + int draw_width, draw_height; + int colour; assert(drawing_enable==1); + assert(gob); + assert(image>=0); + assert(imagenum_images); - if (image < 0 || image >= *(short *) (pob_data)) - return; +#ifdef SCALE_UP2 + x *= 2; + y *= 2; +#endif - vga_ptr = get_vgaptr(page, 0, 0); - pob_offset = *(unsigned long *) (pob_data + (image * 4) + 2); - width = draw_width = *(short *) (pob_data + pob_offset); - height = draw_height = *(short *) (pob_data + pob_offset + 2); - x -= *(short *) (pob_data + pob_offset + 4); - y -= *(short *) (pob_data + pob_offset + 6); - pob_offset += 8; - if ((x + width) <= 0 || x >= 400) +#ifdef SCALE_UP2 + width = draw_width = gob->width[image]*2; + height = draw_height = gob->height[image]*2; + x -= gob->hs_x[image]*2; + y -= gob->hs_y[image]*2; +#else + width = draw_width = gob->width[image]; + height = draw_height = gob->height[image]; + x -= gob->hs_x[image]; + y -= gob->hs_y[image]; +#endif + if ((x + width) <= 0 || x >= JNB_SURFACE_WIDTH) return; - if ((y + height) <= 0 || y >= 256) + if ((y + height) <= 0 || y >= JNB_SURFACE_HEIGHT) return; + pob_offset = 0; if (x < 0) { pob_offset -= x; draw_width += x; x = 0; } - if ((x + width) > 400) - draw_width -= x + width - 400; + if ((x + width) > JNB_SURFACE_WIDTH) + draw_width -= x + width - JNB_SURFACE_WIDTH; if (y < 0) { - pob_offset += -y * width; - draw_height -= -y; + pob_offset -= y * width; + draw_height += y; y = 0; } - if ((y + height) > 256) - draw_height -= y + height - 256; - - pob_ptr = &pob_data[pob_offset]; - + if ((y + height) > JNB_SURFACE_HEIGHT) + draw_height -= y + height - JNB_SURFACE_HEIGHT; + pob_ptr = &gob->data[image][pob_offset]; vga_ptr = get_vgaptr(page, x, y); - mask_ptr = (char *) (mask_pic + (y * 400) + x); + mask_ptr = &mask[(y * JNB_SURFACE_WIDTH) + x]; for (c1 = 0; c1 < draw_height; c1++) { for (c2 = 0; c2 < draw_width; c2++) { colour = *mask_ptr; - if (mask == 0 || (mask == 1 && colour == 0)) { + if (use_mask == 0 || (use_mask == 1 && colour == 0)) { colour = *pob_ptr; - if (colour != 0) + if (colour != 0) { *vga_ptr = colour; + } } - pob_ptr++; vga_ptr++; + pob_ptr++; mask_ptr++; } pob_ptr += width - c2; - vga_ptr += (400 - c2); - mask_ptr += (400 - c2); + vga_ptr += (JNB_SURFACE_WIDTH - c2); + mask_ptr += (JNB_SURFACE_WIDTH - c2); } } -int pob_col(int x1, int y1, int image1, char *pob_data1, int x2, int y2, int image2, char *pob_data2) -{ - short c1, c2; - long pob_offset1, pob_offset2; - short width1, width2; - short height1, height2; - short check_width, check_height; - char *pob_ptr1, *pob_ptr2; - - pob_offset1 = *(long *) (pob_data1 + image1 * 4 + 2); - width1 = *(short *) (pob_data1 + pob_offset1); - height1 = *(short *) (pob_data1 + pob_offset1 + 2); - x1 -= *(short *) (pob_data1 + pob_offset1 + 4); - y1 -= *(short *) (pob_data1 + pob_offset1 + 6); - pob_offset1 += 8; - pob_offset2 = *(long *) (pob_data2 + image2 * 4 + 2); - width2 = *(short *) (pob_data2 + pob_offset2); - height2 = *(short *) (pob_data2 + pob_offset2 + 2); - x2 -= *(short *) (pob_data2 + pob_offset2 + 4); - y2 -= *(short *) (pob_data2 + pob_offset2 + 6); - pob_offset2 += 8; - - if (x1 < x2) { - if ((x1 + width1) <= x2) - return 0; - - else if ((x1 + width1) <= (x2 + width2)) { - pob_offset1 += x2 - x1; - check_width = x1 + width1 - x2; - } - - else { - pob_offset1 += x2 - x1; - check_width = width2; - } - } - - else { - if ((x2 + width2) <= x1) - return 0; - - else if ((x2 + width2) <= (x1 + width1)) { - pob_offset2 += x1 - x2; - check_width = x2 + width2 - x1; - } - - else { - pob_offset2 += x1 - x2; - check_width = width1; - } - } - if (y1 < y2) { - if ((y1 + height1) <= y2) - return 0; - - else if ((y1 + height1) <= (y2 + height2)) { - pob_offset1 += (y2 - y1) * width1; - check_height = y1 + height1 - y2; - } - - else { - pob_offset1 += (y2 - y1) * width1; - check_height = height2; - } - } - - else { - if ((y2 + height2) <= y1) - return 0; - - else if ((y2 + height2) <= (y1 + height1)) { - pob_offset2 += (y1 - y2) * width2; - check_height = y2 + height2 - y1; - } - - else { - pob_offset2 += (y1 - y2) * width2; - check_height = height1; - } - } - pob_ptr1 = (char *) (pob_data1 + pob_offset1); - pob_ptr2 = (char *) (pob_data2 + pob_offset2); - for (c1 = 0; c1 < check_height; c1++) { - for (c2 = 0; c2 < check_width; c2++) { - if (*pob_ptr1 != 0 && *pob_ptr2 != 0) - return 1; - pob_ptr1++; - pob_ptr2++; - } - pob_ptr1 += width1 - check_width; - pob_ptr2 += width2 - check_width; - } - return 0; -} - - -int pob_width(int image, char *pob_data) +int pob_width(int image, gob_t *gob) { - return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2)); + assert(gob); + assert(image>=0); + assert(imagenum_images); + return gob->width[image]; } -int pob_height(int image, char *pob_data) +int pob_height(int image, gob_t *gob) { - return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 2); + assert(gob); + assert(image>=0); + assert(imagenum_images); + return gob->height[image]; } -int pob_hs_x(int image, char *pob_data) +int pob_hs_x(int image, gob_t *gob) { - return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 4); + assert(gob); + assert(image>=0); + assert(imagenum_images); + return gob->hs_x[image]; } -int pob_hs_y(int image, char *pob_data) +int pob_hs_y(int image, gob_t *gob) { - return *(short *) (pob_data + *(long *) (pob_data + image * 4 + 2) + 6); + assert(gob); + assert(image>=0); + assert(imagenum_images); + return gob->hs_y[image]; } @@ -866,8 +873,120 @@ int read_pcx(FILE * handle, char *buffer, int buf_len, char *pal) } -void register_background(char *pixels) +void register_background(char *pixels, char pal[768]) { - background = pixels; + if (background) { + free(background); + background = NULL; + } background_drawn = 0; + if (!pixels) + return; + assert(pal); +#ifdef SCALE_UP2 + { + int int_pal[256]; + int i; + + for (i=0; i<256; i++) + 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)); + background = malloc(JNB_SURFACE_WIDTH*JNB_SURFACE_HEIGHT*JNB_BYTESPP); + assert(background); + Super2xSaI(pixels, JNB_WIDTH, 1, (unsigned char *)background, JNB_SURFACE_WIDTH*JNB_BYTESPP, JNB_BYTESPP, JNB_WIDTH, JNB_HEIGHT, int_pal); + } +#else + background = malloc(JNB_WIDTH*JNB_HEIGHT); + assert(background); + memcpy(background, pixels, JNB_WIDTH*JNB_HEIGHT); +#endif +} + +int register_gob(FILE *handle, gob_t *gob, int len) +{ + unsigned char *gob_data; + int i; + + gob_data = malloc(len); + fread(gob_data, 1, len, handle); + + gob->num_images = *(short *)(&gob_data[0]); + + gob->width = malloc(gob->num_images*sizeof(int)); + gob->height = malloc(gob->num_images*sizeof(int)); + gob->hs_x = malloc(gob->num_images*sizeof(int)); + gob->hs_y = malloc(gob->num_images*sizeof(int)); + gob->data = malloc(gob->num_images*sizeof(pixel_t *)); + gob->orig_data = malloc(gob->num_images*sizeof(unsigned char *)); + for (i=0; inum_images; i++) { + int image_size; + int offset; + + offset = *(int *)(&gob_data[i*4+2]); + + gob->width[i] = *(short *)(&gob_data[offset]); offset += 2; + gob->height[i] = *(short *)(&gob_data[offset]); offset += 2; + gob->hs_x[i] = *(short *)(&gob_data[offset]); offset += 2; + gob->hs_y[i] = *(short *)(&gob_data[offset]); offset += 2; + + image_size = gob->width[i] * gob->height[i]; + gob->orig_data[i] = malloc(image_size); + memcpy(gob->orig_data[i], &gob_data[offset], image_size); +#ifdef SCALE_UP2 + image_size = gob->width[i] * gob->height[i] * 4 * JNB_BYTESPP; + gob->data[i] = malloc(image_size); +#else + gob->data[i] = gob->orig_data[i]; +#endif + } + free(gob_data); + return 0; +} + + +void recalculate_gob(gob_t *gob, char pal[768]) +{ +#ifdef SCALE_UP2 + int int_pal[256]; + int i; + + for (i=1; i<256; i++) { + 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)); + if (int_pal[i] == 0) + int_pal[i] = SDL_MapRGB(jnb_surface->format, 8, 8, 8); + } + int_pal[0] = 0; + + for (i=0; inum_images; i++) { + if ( (gob->width[i]>4) && (gob->height[i]>4) ) + Super2xSaI(gob->orig_data[i], gob->width[i], 1, (unsigned char *)gob->data[i], gob->width[i]*2*JNB_BYTESPP, JNB_BYTESPP, gob->width[i], gob->height[i], int_pal); + else + Scale2x(gob->orig_data[i], gob->width[i], 1, (unsigned char *)gob->data[i], gob->width[i]*2*JNB_BYTESPP, JNB_BYTESPP, gob->width[i], gob->height[i], int_pal); + } +#endif +} + +void register_mask(char *pixels) +{ + if (mask) { + free(mask); + mask = NULL; + } + assert(pixels); +#ifdef SCALE_UP2 + { + int int_pal[256]; + int i; + + int_pal[0] = 0; + for (i=1; i<256; i++) + int_pal[i] = 1; + mask = malloc(JNB_SURFACE_WIDTH*JNB_SURFACE_HEIGHT*JNB_BYTESPP); + assert(mask); + Scale2x(pixels, JNB_WIDTH, 1, (unsigned char *)mask, JNB_SURFACE_WIDTH*JNB_BYTESPP, JNB_BYTESPP, JNB_WIDTH, JNB_HEIGHT, int_pal); + } +#else + mask = malloc(JNB_WIDTH*JNB_HEIGHT); + assert(mask); + memcpy(mask, pixels, JNB_WIDTH*JNB_HEIGHT); +#endif } diff --git a/sdl/input.c b/sdl/input.c index dbb85c2..b205292 100644 --- a/sdl/input.c +++ b/sdl/input.c @@ -1,6 +1,6 @@ #include "globals.h" -int calib_joy(char type) +int calib_joy(int type) { return 1; } diff --git a/sdl/sound.c b/sdl/sound.c index d1f2c4b..7da8b2b 100644 --- a/sdl/sound.c +++ b/sdl/sound.c @@ -358,7 +358,7 @@ void dj_stop_sfx_channel(char channel_num) char dj_load_sfx(FILE * file_handle, char *filename, int file_length, char sfx_type, unsigned char sfx_num) { sounds[sfx_num].buf = malloc(file_length); - fread(sounds[sfx_num].buf, file_length, 1, file_handle); + fread(sounds[sfx_num].buf, 1, file_length, file_handle); sounds[sfx_num].length = file_length / 2; return 0; } -- 2.39.2