From 7538a0da0768c74d646aeb7716e4a19db712a7e6 Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Wed, 18 Mar 2015 12:57:14 +0000 Subject: [PATCH] Fixed bug in rzx snapshot extract, changed rzx function names --- src/gui_sdl.c | 2 +- src/menu_sdl.c | 2 +- src/rzx_lib/rzx.c | 39 +++++++++++++++++++++++++++++++++++---- src/rzx_lib/rzx.h | 4 ++-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/gui_sdl.c b/src/gui_sdl.c index 5f14c46..314c369 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -1953,7 +1953,7 @@ static void rzx_browser() ordenador.frames_count_rzx=rzx_browser_list[block_n_int].frames_count; - set_rzxfile_position(rzx_position); + rzx_set_file_position(rzx_position); free((void*)row_selected); } diff --git a/src/menu_sdl.c b/src/menu_sdl.c index 1dae723..0c86237 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -654,7 +654,7 @@ void draw_scr_file(int x,int y, const char *selected_file, int which) rzx_position=rzx_browser_list[block_n_int].position; - if (extract_snapshot(rzx_position, load_path_snaps, ext)) return; //error + if (rzx_extract_snapshot(rzx_position, load_path_snaps, ext)) return; //error strcpy(name, "rzxtemp."); strcat(name, ext); diff --git a/src/rzx_lib/rzx.c b/src/rzx_lib/rzx.c index 6a1bf33..d21f82c 100644 --- a/src/rzx_lib/rzx.c +++ b/src/rzx_lib/rzx.c @@ -86,6 +86,29 @@ static rzx_u8 *zbuf=0; static int zmode=0; static rzx_u32 packed_bytes=0; +static z_stream zs_temp; +static rzx_u8 *zbuf_temp=0; +static int zmode_temp=0; +static rzx_u32 packed_bytes_temp=0; + +void rzx_swap_variables() +{ + zs_temp=zs; + zbuf_temp=zbuf; + zmode_temp=zmode; + packed_bytes_temp=packed_bytes; + +} + +void rzx_swap_variables_revert() +{ + zs=zs_temp; + zbuf=zbuf_temp; + zmode=zmode_temp; + packed_bytes=packed_bytes_temp; + +} + unsigned int last_snapshot_position; int rzx_pwrite(rzx_u8 *buffer, int len) @@ -271,7 +294,7 @@ int rzx_scan() return ret; } -void set_rzxfile_position(unsigned int rzx_position) +void rzx_set_file_position(unsigned int rzx_position) { block.start = rzx_position; @@ -281,12 +304,16 @@ void set_rzxfile_position(unsigned int rzx_position) #endif } -int extract_snapshot(unsigned int position, char *path, char *ext) +int rzx_extract_snapshot(unsigned int position, char *path, char *ext) { int done=0, ret=0; int old_position, fpos; FILE *snapfile; +#ifdef RZX_USE_COMPRESSION +rzx_swap_variables(); +#endif + old_position=ftell(rzxfile); fseek(rzxfile,position,SEEK_SET); @@ -338,8 +365,12 @@ old_position=ftell(rzxfile); } else ret=-1; - fseek(rzxfile,old_position,SEEK_SET); - return ret; + fseek(rzxfile,old_position,SEEK_SET); + +#ifdef RZX_USE_COMPRESSION +rzx_swap_variables_revert(); +#endif +return ret; } void rzx_close_irb() diff --git a/src/rzx_lib/rzx.h b/src/rzx_lib/rzx.h index 2095c0a..a68b161 100644 --- a/src/rzx_lib/rzx.h +++ b/src/rzx_lib/rzx.h @@ -138,8 +138,8 @@ int rzx_get_input(rzx_u8 *input); int rzx_add_snapshot(const char *filename, const rzx_u32 flags); int rzx_add_comment(const char *text, const rzx_u32 flags); -void set_rzxfile_position(unsigned int rzx_position); -int extract_snapshot(unsigned int position, char *path, char *ext); +void rzx_set_file_position(unsigned int rzx_position); +int rzx_extract_snapshot(unsigned int position, char *path, char *ext); #ifdef RZX_DEBUG extern rzx_u16 INcount;