From f496d9f1b7afa1eb960d49e2aa099ee6a45846fa Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Fri, 27 Mar 2015 09:24:14 +0000 Subject: [PATCH] Improved RZX compatibility with the other emulator, fixed bug in rzx edit (file truncate) --- src/emulator.c | 3 +-- src/gui_sdl.c | 10 ++++++---- src/rzx_lib/rzx.c | 18 +++++++++++++++++- src/rzx_lib/rzx.h | 1 + 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index ef063c3..5418b46 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -1835,8 +1835,7 @@ int main(int argc,char *argv[]) if ((ordenador.precision==0)||(jump_frames>0)) ordenador.interr=0; if (ordenador.recording_rzx) { - if (ordenador.icount == 0xFFFF) ordenador.icount=0; - else if (test_IFF1(&procesador)||(ordenador.icount>10)) {rzx_update(&ordenador.icount);ordenador.icount=0;} + if (test_IFF1(&procesador)||(ordenador.icount>10)) {rzx_update(&ordenador.icount);ordenador.icount=0;} } } } diff --git a/src/gui_sdl.c b/src/gui_sdl.c index cc2ec25..a531a99 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -2019,9 +2019,7 @@ static int do_rzx(int which) ordenador.frames_count_rzx=1; retorno2 = load_rzx(0); if (retorno2) break; //Error or no file - retorno2 = rzx_update(&ordenador.maxicount); //The first frame does not generate interrupt - if (retorno2 == RZX_FINISHED) {printf("RZX: Playing finished at fisrt frame\n"); break;} - //ordenador.cicles_counter=32; //to avoid the interrupt at first frame + ordenador.maxicount = 0; //Force rzx_update and interrupt ordenador.playing_rzx = 1; retorno = -2; //Come back to the menu break; @@ -2035,7 +2033,7 @@ static int do_rzx(int which) case 3: //Add Bookmark if (!ordenador.recording_rzx) break; rzx_update(&ordenador.icount); - ordenador.icount=0xFFFF; //to avoid a new rzx_update + ordenador.icount=0; save_z80("temp.z80",1); if (rzx_add_snapshot("temp.z80", RZX_COMPRESSED)==RZX_OK) {printf("RZX: Added snapshot\n");msgInfo("Added Bookmark", 3000, NULL);} else {printf("RZX: Impossible to add snapshot\n"); break;} @@ -2044,7 +2042,11 @@ static int do_rzx(int which) break; case 4: //browser if (!ordenador.playing_rzx&&!ordenador.recording_rzx) break; + if (ordenador.recording_rzx) rzx_update(&ordenador.icount); //Discard the records + ordenador.icount = 0; + rzx_reset(); //Reset internal library variables rzx_browser(); + if (ordenador.playing_rzx) ordenador.maxicount = 0; //Force rzx_update and interrupt retorno = -2; break; case 5: //edit diff --git a/src/rzx_lib/rzx.c b/src/rzx_lib/rzx.c index e8b8ff2..2ddc592 100644 --- a/src/rzx_lib/rzx.c +++ b/src/rzx_lib/rzx.c @@ -719,6 +719,9 @@ int rzx_edit(const char *filename) void rzx_close(void) { + long fpos; + int fd; + switch(rzx.mode) { case RZX_PLAYBACK: @@ -728,7 +731,14 @@ void rzx_close(void) break; case RZX_RECORD: /* is there an IRB to close? */ - if(rzx_status&RZX_IRB) rzx_close_irb(); + if(rzx_status&RZX_IRB) rzx_close_irb(); + if (rzxfile!=NULL) + { + fflush(rzxfile); + fpos=ftell(rzxfile); + fd=fileno(rzxfile); + ftruncate(fd, fpos); + } break; default: break; @@ -757,6 +767,12 @@ void rzx_close(void) } } +void rzx_reset() +{ + INmax=0; + INcount=0; + INold=0xFFFF; +} int rzx_update(rzx_u16 *icount) { diff --git a/src/rzx_lib/rzx.h b/src/rzx_lib/rzx.h index ee78a07..6fae97d 100644 --- a/src/rzx_lib/rzx.h +++ b/src/rzx_lib/rzx.h @@ -143,6 +143,7 @@ int rzx_add_comment(const char *text, const rzx_u32 flags); void rzx_set_file_position(unsigned int rzx_position); int rzx_extract_snapshot(unsigned int position, char *path, char *ext, int restore_position); int rzx_edit(const char *filename); +void rzx_reset(void); #ifdef RZX_DEBUG extern rzx_u16 INcount;