diff --git a/include/data.h b/include/data.h index b32e34a..78e8a72 100644 --- a/include/data.h +++ b/include/data.h @@ -20,8 +20,8 @@ typedef void *data_file_t; -extern void data_setpath(char *); -extern void data_closepath(); +extern int data_setpath(char *); +extern void data_closepath(void); extern data_file_t *data_file_open(char *); extern int data_file_seek(data_file_t *file, long offset, int origin); diff --git a/include/system.h b/include/system.h index 17b00e3..6c1e1e4 100644 --- a/include/system.h +++ b/include/system.h @@ -61,7 +61,6 @@ typedef signed int S32; /* 32 bits signed */ */ extern void sys_init(int, char **); extern void sys_shutdown(void); -extern void sys_panic(char *, ...); extern U32 sys_gettime(void); /* diff --git a/libretro/core/cmdline.c b/libretro/core/cmdline.c index e1f47f1..49d714d 100644 --- a/libretro/core/cmdline.c +++ b/libretro/core/cmdline.c @@ -85,33 +85,21 @@ static void parse_cmdline(const char *argv) int pre_main(const char *argv) { int i; - bool Only1Arg; parse_cmdline(argv); - Only1Arg = (strcmp(ARGUV[0],"skelsdl") == 0) ? 1: 0; - for (i = 0; i<64; i++) xargv_cmd[i] = NULL; - if(Only1Arg) - { - Add_Option("skelsdl"); - Add_Option(RPATH/*ARGUV[0]*/); - } - else - { // Pass all cmdline args - for(i = 0; i < ARGUC; i++) - Add_Option(ARGUV[i]); - } + /* Pass all cmdline args */ + for(i = 0; i < ARGUC; i++) + Add_Option(ARGUV[i]); for (i = 0; i < PARAMCOUNT; i++) - { xargv_cmd[i] = (char*)(XARGV[i]); - printf("%2d %s\n",i,XARGV[i]); - } - skel_main(PARAMCOUNT,( char **)xargv_cmd); + if (skel_main(PARAMCOUNT,( char **)xargv_cmd) == -1) + return -1; xargv_cmd[PARAMCOUNT - 2] = NULL; diff --git a/libretro/core/libretro-core.c b/libretro/core/libretro-core.c index 4ec1e4a..78f2251 100644 --- a/libretro/core/libretro-core.c +++ b/libretro/core/libretro-core.c @@ -22,19 +22,25 @@ SDL_Surface *sdlscrn; void SDL_Uninit(void) { - if(sdlscrn->format->palette->colors) - free(sdlscrn->format->palette->colors); + if (sdlscrn) + { - if(sdlscrn->format->palette) - free(sdlscrn->format->palette); - if(sdlscrn->format) - free(sdlscrn->format); + if(sdlscrn->format) + { + if(sdlscrn->format->palette) + { + if(sdlscrn->format->palette->colors) + free(sdlscrn->format->palette->colors); + free(sdlscrn->format->palette); + } + free(sdlscrn->format); + } - if(sdlscrn->pixels) - sdlscrn->pixels=NULL; + if(sdlscrn->pixels) + sdlscrn->pixels=NULL; - if(sdlscrn) free(sdlscrn); + } } const char *retro_save_directory; @@ -68,15 +74,10 @@ void retro_set_environment(retro_environment_t cb) static void update_variables(void) { + /* TODO/FIXME - add core options? */ } -static void retro_wrap_emulator(void) -{ -} - -void retro_reset(void) -{ -} +void retro_reset(void) { } void StartTicks(void); @@ -93,22 +94,25 @@ void retro_init(void) StartTicks(); - // if defined, use the system directory - if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) && system_dir) + /* if defined, use the system directory */ + if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) + && system_dir) retro_system_directory=system_dir; - // if defined, use the system directory - if (environ_cb(RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY, &content_dir) && content_dir) + /* if defined, use the system directory */ + if (environ_cb(RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY, &content_dir) + && content_dir) retro_content_directory=content_dir; - // If save directory is defined use it, otherwise use system directory - if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_dir) && save_dir) + /* If save directory is defined use it, otherwise use system directory */ + if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_dir) + && save_dir) retro_save_directory = *save_dir ? save_dir : retro_system_directory; else // make retro_save_directory the same in case RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY is not implemented by the frontend retro_save_directory=retro_system_directory; - if(retro_system_directory==NULL) + if (!retro_system_directory) sprintf(RETRO_DIR, "%s\0","."); else sprintf(RETRO_DIR, "%s\0", retro_system_directory); @@ -137,11 +141,7 @@ unsigned retro_api_version(void) return RETRO_API_VERSION; } -void retro_set_controller_port_device(unsigned port, unsigned device) -{ - (void)port; - (void)device; -} +void retro_set_controller_port_device(unsigned port, unsigned device) { } void retro_get_system_info(struct retro_system_info *info) { @@ -155,7 +155,8 @@ void retro_get_system_info(struct retro_system_info *info) void retro_get_system_av_info(struct retro_system_av_info *info) { - struct retro_game_geometry geom = { retrow, retroh, retrow, retrow,4.0 / 3.0 }; + struct retro_game_geometry geom = { retrow, retroh, retrow, retrow, + 4.0 / 3.0 }; struct retro_system_timing timing = { 25.0, 22050.0 }; info->geometry = geom; @@ -184,7 +185,8 @@ void retro_run(void) { bool updated = false; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) + && updated) update_variables(); Retro_PollEvent(); @@ -212,8 +214,9 @@ bool retro_load_game(const struct retro_game_info *info) sprintf(RPATH,"\"xrick\" \"-data\" \"%s\"\0", info->path); else sprintf(RPATH,"\"xrick\" \"-data\" \"%s/data.zip\"\0", retro_system_directory); - pre_main(RPATH); - game_run(); + if (pre_main(RPATH) == -1) + return false; + game_run(); return true; } @@ -222,9 +225,9 @@ void freedata(void); void retro_unload_game(void) { - freedata(); /* free cached data */ - data_closepath(); - sys_shutdown(); + freedata(); /* free cached data */ + data_closepath(); + sys_shutdown(); } unsigned retro_get_region(void) @@ -257,13 +260,11 @@ bool retro_unserialize(const void *data_, size_t size) void *retro_get_memory_data(unsigned id) { - (void)id; return NULL; } size_t retro_get_memory_size(unsigned id) { - (void)id; return 0; } diff --git a/src/data.c b/src/data.c index c81c59f..30dcaad 100644 --- a/src/data.c +++ b/src/data.c @@ -84,11 +84,11 @@ static char *str_slash(char *s) /* * */ -void data_setpath(char *name) +int data_setpath(char *name) { - unzFile zip; + unzFile zip; - if (str_zipext(name)) + if (str_zipext(name)) { /* path has .zip extension */ char *n = str_slash(str_dup(name)); @@ -96,13 +96,11 @@ void data_setpath(char *name) if (!zip) { free(n); - sys_panic("(data) can not open data"); - } - else - { - path.zip = zip; - path.name = n; + return -1; } + + path.zip = zip; + path.name = n; } else { @@ -111,6 +109,8 @@ void data_setpath(char *name) path.zip = NULL; path.name = str_dup(name); } + + return 0; } /* diff --git a/src/maps.c b/src/maps.c index 8f707f2..8b4c36e 100644 --- a/src/maps.c +++ b/src/maps.c @@ -152,8 +152,6 @@ map_chain(void) * found, then panic */ for (c = map_submaps[game_submap].connect; ; c++) { - if (map_connect[c].dir == 0xff) - sys_panic("(map_chain) can not find connector\n"); if (map_connect[c].dir != game_dir) continue; t = (ent_ents[1].y >> 3) + map_frow - map_connect[c].rowout; if (t < 3) break; diff --git a/src/system.c b/src/system.c index a2f30d8..8e71df7 100644 --- a/src/system.c +++ b/src/system.c @@ -11,32 +11,12 @@ * You must not remove this notice, or any other, from this software. */ -#include /* args for sys_panic */ #include /* printf */ #include #include #include "system.h" -/* - * Panic - */ -void -sys_panic(char *err, ...) -{ - va_list argptr; - char s[1024]; - - /* prepare message */ - va_start(argptr, err); - vsprintf(s, err, argptr); - va_end(argptr); - - /* print message and die */ - printf("%s\npanic!\n", s); - exit(1); -} - /* forward declaration */ extern long GetTicks(void); diff --git a/src/util.c b/src/util.c index 0b83f8d..b8700a2 100644 --- a/src/util.c +++ b/src/util.c @@ -31,16 +31,14 @@ * x,y: coordinates to test. * ret: TRUE/(x,y) is within e's space, FALSE/not. */ -U8 -u_fboxtest(U8 e, S16 x, S16 y) +U8 u_fboxtest(U8 e, S16 x, S16 y) { if (ent_ents[e].x >= x || ent_ents[e].x + ent_ents[e].w < x || ent_ents[e].y >= y || ent_ents[e].y + ent_ents[e].h < y) return FALSE; - else - return TRUE; + return TRUE; } @@ -55,24 +53,22 @@ u_fboxtest(U8 e, S16 x, S16 y) * e2: entity to test (corresponds to SI in asm code). * ret: TRUE/intersect, FALSE/not. */ -U8 -u_boxtest(U8 e1, U8 e2) +U8 u_boxtest(U8 e1, U8 e2) { - /* rick is special (may be crawling) */ - if (e1 == E_RICK_NO) - return e_rick_boxtest(e2); + /* rick is special (may be crawling) */ + if (e1 == E_RICK_NO) + return e_rick_boxtest(e2); - /* - * entity 1: x+0x05 to x+0x011, y to y+0x14 - * entity 2: x to x+ .w, y to y+ .h - */ - if (ent_ents[e1].x + 0x11 < ent_ents[e2].x || - ent_ents[e1].x + 0x05 > ent_ents[e2].x + ent_ents[e2].w || - ent_ents[e1].y + 0x14 < ent_ents[e2].y || - ent_ents[e1].y > ent_ents[e2].y + ent_ents[e2].h - 1) - return FALSE; - else - return TRUE; + /* + * entity 1: x+0x05 to x+0x011, y to y+0x14 + * entity 2: x to x+ .w, y to y+ .h + */ + if (ent_ents[e1].x + 0x11 < ent_ents[e2].x || + ent_ents[e1].x + 0x05 > ent_ents[e2].x + ent_ents[e2].w || + ent_ents[e1].y + 0x14 < ent_ents[e2].y || + ent_ents[e1].y > ent_ents[e2].y + ent_ents[e2].h - 1) + return FALSE; + return TRUE; } @@ -86,8 +82,7 @@ u_boxtest(U8 e1, U8 e2) * rc0: anything CHANGED to the environment flag for crawling (6DBA) * rc1: anything CHANGED to the environment flag (6DAD) */ -void -u_envtest(S16 x, S16 y, U8 crawl, U8 *rc0, U8 *rc1) +void u_envtest(S16 x, S16 y, U8 crawl, U8 *rc0, U8 *rc1) { U8 i, xx; @@ -188,21 +183,17 @@ u_envtest(S16 x, S16 y, U8 crawl, U8 *rc0, U8 *rc1) * ASM 126F * return: FALSE if not in box, TRUE if in box. */ -U8 -u_trigbox(U8 e, S16 x, S16 y) +U8 u_trigbox(U8 e, S16 x, S16 y) { - U16 xmax, ymax; + U16 xmax = ent_ents[e].trig_x + (ent_entdata[ent_ents[e].n & 0x7F].trig_w << 3); + U16 ymax = ent_ents[e].trig_y + (ent_entdata[ent_ents[e].n & 0x7F].trig_h << 3); - xmax = ent_ents[e].trig_x + (ent_entdata[ent_ents[e].n & 0x7F].trig_w << 3); - ymax = ent_ents[e].trig_y + (ent_entdata[ent_ents[e].n & 0x7F].trig_h << 3); + if (xmax > 0xFF) xmax = 0xFF; - if (xmax > 0xFF) xmax = 0xFF; - - if (x <= ent_ents[e].trig_x || x > xmax || - y <= ent_ents[e].trig_y || y > ymax) - return FALSE; - else - return TRUE; + if (x <= ent_ents[e].trig_x || x > xmax || + y <= ent_ents[e].trig_y || y > ymax) + return FALSE; + return TRUE; } diff --git a/src/xrick.c b/src/xrick.c index 4672033..a5c70e8 100644 --- a/src/xrick.c +++ b/src/xrick.c @@ -14,18 +14,13 @@ #include "system.h" #include "game.h" -/* - * main - */ -int -skel_main(int argc, char *argv[]) +/* main */ +int skel_main(int argc, char *argv[]) { sys_init(argc, argv); if (sysarg_args_data) - data_setpath(sysarg_args_data); - else - data_setpath("data.zip"); - return 0; + return data_setpath(sysarg_args_data); + return data_setpath("data.zip"); } /* eof */