diff --git a/src/computer.c b/src/computer.c index d4f0bad..e77dba3 100644 --- a/src/computer.c +++ b/src/computer.c @@ -654,6 +654,8 @@ void set_memory_pointers () { void end_of_frame() { +static char rzx_message[24]; + if (ordenador.osd_time) { ordenador.osd_time--; if (ordenador.osd_time==0) { @@ -671,8 +673,12 @@ void end_of_frame() } } else if (ordenador.recording_rzx) print_string (ordenador.screenbuffer,"RZX Recording",-1, 450, 12, 0,ordenador.screen_width); - else if (ordenador.playing_rzx) print_string (ordenador.screenbuffer,"RZX Playing",-1, 450, 12, 0,ordenador.screen_width); - + else if (ordenador.playing_rzx) + { + if (ordenador.total_frames_rzx) sprintf(rzx_message, "RZX Playing %d%%", 100*ordenador.frames_count_rzx/ordenador.total_frames_rzx); + else strcpy (rzx_message, "RZX Playing"); + print_string (ordenador.screenbuffer,rzx_message,-1, 450, 12, 0,ordenador.screen_width); + } if (ordenador.tape_start_countdwn==1) ordenador.tape_stop=0; //Autoplay if ((ordenador.tape_start_countdwn>0)&&(ordenador.stop_tape_start_countdown ==0)) ordenador.tape_start_countdwn--; @@ -1881,10 +1887,10 @@ void ResetComputer () { ordenador.cicles_counter=0; ordenador.currline=0; ordenador.currpix=0; - ordenador.interr = 0; + ordenador.interr = 1; ordenador.recording_rzx=0; - ordenador.playing_rzx=0; + //ordenador.playing_rzx=0; ordenador.icount=0; currah_microspeech_reset(); @@ -2347,11 +2353,12 @@ inline byte Z80free_In_internal (register word Port) { static unsigned int temporal_io; static byte pines, pines_rzx; + static int error; if (ordenador.playing_rzx) { - pines_rzx = rzx_get_input(); - if (pines_rzx == RZX_SYNCLOST) + error = rzx_get_input(&pines_rzx); + if (error == RZX_SYNCLOST) { msgInfo("RZX sync lost", 4000, NULL); pines_rzx =0; diff --git a/src/computer.h b/src/computer.h index 862b447..aefaa8c 100644 --- a/src/computer.h +++ b/src/computer.h @@ -212,6 +212,8 @@ struct computer { unsigned char playing_rzx; unsigned short int maxicount; unsigned short int icount; + unsigned int total_frames_rzx; + unsigned int frames_count_rzx; // Microdrive global variables FILE *mdr_file; // Current microdrive file diff --git a/src/emulator.c b/src/emulator.c index 74c8783..2e0d131 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -1808,6 +1808,7 @@ int main(int argc,char *argv[]) } ordenador.icount = 0; + ordenador.frames_count_rzx++; error = rzx_update(&ordenador.maxicount); if (error == RZX_FINISHED) { @@ -1826,13 +1827,13 @@ int main(int argc,char *argv[]) if (!ordenador.precision) ordenador.currpix=64; if (curr_frames==jump_frames) end_of_frame(); else ordenador.cicles_counter=0; } - if (ordenador.cicles_counter<32) Z80free_INT(&procesador,bus_empty()); + //if (ordenador.cicles_counter<32) Z80free_INT(&procesador,bus_empty()); } else if(ordenador.interr==1) { Z80free_INT(&procesador,bus_empty()); if ((ordenador.precision==0)||(jump_frames>0)) ordenador.interr=0; - if (ordenador.recording_rzx) {rzx_update(&ordenador.icount);ordenador.icount=0;} + if (ordenador.recording_rzx) {if (ordenador.icount != 0xFFFF) rzx_update(&ordenador.icount);ordenador.icount=0;} } } diff --git a/src/gui_sdl.c b/src/gui_sdl.c index 319a347..932f535 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -212,7 +212,7 @@ static const char *tools_messages[] = { /*08*/ "Keyboard rumble", /*09*/ "^|on|off", /*10*/ "Recording (RZX)", - /*11*/ "^|Record|Play|Stop", + /*11*/ "^|Record|Play|Stop|Bookmark", /*12*/ "Load poke file", /*13*/ "Insert poke", /*14*/ "Help", @@ -1948,11 +1948,13 @@ static int do_rzx(int which) case 1: // Play ordenador.recording_rzx=0; ordenador.icount = 0; + ordenador.total_frames_rzx=0; + ordenador.frames_count_rzx=1; retorno2 = load_rzx(); if (retorno2) break; //Error or no file retorno2 = rzx_update(&ordenador.maxicount); 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.cicles_counter=32; //to avoid the interrupt at first frame ordenador.playing_rzx = 1; retorno = -2; //Come back to the menu break; @@ -1963,6 +1965,16 @@ static int do_rzx(int which) printf("RZX: Stop\n"); retorno = -2; break; + case 3: //Add Bookmark + if (!ordenador.recording_rzx) break; + rzx_update(&ordenador.icount); + ordenador.icount=0xFFFF; //to avoid a new rzx_update + 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;} + unlink("temp.z80"); + retorno = -2; + break; default: break; } diff --git a/src/rzx_init.c b/src/rzx_init.c index 3d2022a..eb3a56c 100644 --- a/src/rzx_init.c +++ b/src/rzx_init.c @@ -97,6 +97,7 @@ rzx_u32 rzx_callback(int msg, void *par) { /* fetch the IRB info if needed */ tstates=((RZX_IRBINFO*)par)->tstates; + ordenador.cicles_counter=tstates; printf("> IRB notify: tstates=%i, %s, %s\n",(int)tstates, ((RZX_IRBINFO*)par)->options&RZX_COMPRESSED?"compressed":"uncompressed", ((RZX_IRBINFO*)par)->options&RZX_PROTECTED?"protected":"not protected"); @@ -112,6 +113,11 @@ rzx_u32 rzx_callback(int msg, void *par) printf("> IRB notify: tstates=%i, %s\n",(int)ordenador.cicles_counter, ((RZX_IRBINFO*)par)->options&RZX_COMPRESSED?"compressed":"uncompressed"); } + else if(rzx.mode==RZX_SCAN) + { + ordenador.total_frames_rzx += ((RZX_IRBINFO*)par)->framecount; + printf("> IRB notify: Total frames to play %d\n", ordenador.total_frames_rzx); + } break; case RZXMSG_SECURITY: printf("> Security Information Block\n"); @@ -139,7 +145,7 @@ void init_rzx() printf("Init RZX library\n"); printf("Using RZX Library v%i.%02i build %i\n",(RZX_LIBRARY_VERSION&0xFF00)>>8,RZX_LIBRARY_VERSION&0xFF,RZX_LIBRARY_BUILD); - strcpy(emul_info.name,"RZX FBZX Wii"); + strcpy(emul_info.name,"RZX FBZX Wii "); emul_info.ver_major=FBZXVMAJ; emul_info.ver_minor=FBZXVMIN; emul_info.data=0; emul_info.length=0; diff --git a/src/rzx_lib/rzx.c b/src/rzx_lib/rzx.c index 3cda15c..f60a530 100644 --- a/src/rzx_lib/rzx.c +++ b/src/rzx_lib/rzx.c @@ -234,11 +234,18 @@ int rzx_scan() break; case RZXBLK_DATA: fread(block.buff,13,1,rzxfile); + #ifndef RZX_BIG_ENDIAN + rzx_irb.framecount=*((rzx_u32*)&block.buff[0]); + #else + rzx_irb.framecount=block.buff[0]+256*block.buff[1]+65536*block.buff[2]+16777216*block.buff[3]; + #endif + /* notify the emulator the frame count */ + emul_handler(RZXMSG_IRBNOTIFY,&rzx_irb); break; case RZXBLK_SEC_SIG: emul_handler(RZXMSG_SEC_SIG,NULL); break; - case RZXBLK_SNAP: + case RZXBLK_SNAP: break; default: emul_handler(RZXMSG_UNKNOWN,NULL); @@ -296,6 +303,7 @@ int rzx_seek_irb() FILE *snapfile; while(!done) { + fseek(rzxfile,block.start,SEEK_SET); if(fread(block.buff,5,1,rzxfile)<1) return RZX_FINISHED; block.type=block.buff[0]; #ifndef RZX_BIG_ENDIAN @@ -392,6 +400,7 @@ int rzx_seek_irb() } #endif /* all done */ + block.start+=block.length; return RZX_OK; break; case RZXBLK_SECURITY: @@ -406,7 +415,6 @@ int rzx_seek_irb() } /* seek the next block in the file */ block.start+=block.length; - fseek(rzxfile,block.start,SEEK_SET); } return RZX_OK; } @@ -462,6 +470,7 @@ int rzx_playback(const char *filename) rzx.ver_major=block.buff[4]; rzx.ver_minor=block.buff[5]; /* pre-scan the file to collect useful information and stats */ + rzx.mode=RZX_SCAN; if(rzx_scan()!=RZX_OK) { rzx_close(); @@ -539,7 +548,9 @@ void rzx_close(void) switch(rzx.mode) { case RZX_PLAYBACK: +#ifdef RZX_USE_COMPRESSION rzx_pclose(); +#endif break; case RZX_RECORD: /* is there an IRB to close? */ @@ -628,7 +639,7 @@ int rzx_update(rzx_u16 *icount) /* close if parameters are not valid */ if((!icount)&&(rzx_status&RZX_IRB)) { - rzx_close_irb(); + rzx_close_irb(); break; } /* need to start a new IRB? */ @@ -667,6 +678,8 @@ int rzx_update(rzx_u16 *icount) rzx_popen(fpos,"wb"); } #endif + INcount=0; + INold=0xFFFF; } /* prepare the frame data */ @@ -721,10 +734,11 @@ void rzx_store_input(rzx_u8 value) } -rzx_u8 rzx_get_input(void) +int rzx_get_input(rzx_u8 *input) { - if(INcount>=INmax) {printf("Too many inputs read\n"); return RZX_SYNCLOST;}; - return inputbuffer[INcount++]; + if(INcount>=INmax) {printf("Too many inputs read\n"); *input=0; return RZX_SYNCLOST;}; + *input = inputbuffer[INcount++]; + return RZX_OK; } int rzx_add_snapshot(const char *filename, const rzx_u32 flags) diff --git a/src/rzx_lib/rzx.h b/src/rzx_lib/rzx.h index a2c49c1..9d4f15c 100644 --- a/src/rzx_lib/rzx.h +++ b/src/rzx_lib/rzx.h @@ -32,8 +32,14 @@ typedef unsigned char rzx_u8; /* must be unsigned 8-bit */ typedef unsigned short int rzx_u16; /* must be unsigned 16-bit */ typedef unsigned long int rzx_u32; /* must be unsigned 32-bit */ +#ifdef GEKKO +#include +#endif + /* Uncomment the next line for Motorola-byte-order CPUs */ +#if BYTE_ORDER == BIG_ENDIAN #define RZX_BIG_ENDIAN +#endif /* Uncomment the next line to enable compression support */ #define RZX_USE_COMPRESSION @@ -57,6 +63,7 @@ typedef unsigned long int rzx_u32; /* must be unsigned 32-bit */ #define RZX_IDLE 0 #define RZX_PLAYBACK 1 #define RZX_RECORD 2 +#define RZX_SCAN 3 /* RZX callback messages */ @@ -124,7 +131,7 @@ int rzx_playback(const char *filename); void rzx_close(void); int rzx_update(rzx_u16 *icount); void rzx_store_input(rzx_u8 value); -rzx_u8 rzx_get_input(void); +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);