diff --git a/src/cargador.c b/src/cargador.c index 3d8e35e..f43970d 100644 --- a/src/cargador.c +++ b/src/cargador.c @@ -786,7 +786,7 @@ void load_snap(struct z80snapshot *snap) { } } -int extract_screen_sna (char *screen, FILE * fichero) { +int extract_screen_sna (char *screen_memory, FILE * fichero) { unsigned char *tempo; unsigned char *tempo2; @@ -814,19 +814,19 @@ int extract_screen_sna (char *screen, FILE * fichero) { if (type==0) { //48k - memcpy(screen,tempo+27,6912); + memcpy(screen_memory,tempo+27,6912); } else { //128k v1=tempo2[2]; //printf("v1= %d\n",(int) v1); - if ((v1&8)==0) memcpy(screen,tempo+27,6912); //screen in bank 5 + if ((v1&8)==0) memcpy(screen_memory,tempo+27,6912); //screen in bank 5 else //Screen in bank 7 { v1&=0x07; - if (v1==7) memcpy(screen,tempo+27+49152,6912); //screen in bank 7 paged-in + if (v1==7) memcpy(screen_memory,tempo+27+49152,6912); //screen in bank 7 paged-in else - memcpy(screen,tempo2+4+16384*4,6912); //Screen in bank 7 not paged-in + memcpy(screen_memory,tempo2+4+16384*4,6912); //Screen in bank 7 not paged-in } } @@ -835,7 +835,7 @@ int extract_screen_sna (char *screen, FILE * fichero) { return 0; } -int extract_screen_z80 (char *screen, FILE * fichero) { +int extract_screen_z80 (char *screen_memory, FILE * fichero) { unsigned char tempo[30],tempo2[56],type,compressed,pager, byte_read[3]; unsigned char *memo; @@ -930,7 +930,7 @@ int extract_screen_z80 (char *screen, FILE * fichero) { fread(memo,6912,1,fichero); else uncompress_z80(fichero,6912,memo); - memcpy(screen, memo,6912); + memcpy(screen_memory, memo,6912); break; } if(longitud2==0xFFFF) longitud2 =16384; // uncompressed raw data @@ -951,7 +951,7 @@ int extract_screen_z80 (char *screen, FILE * fichero) { fread(memo,6912,1,fichero); else uncompress_z80(fichero,6912,memo); - memcpy(screen, memo,6912); + memcpy(screen_memory, memo,6912); break; } if(longitud2==0xFFFF) longitud2 =16384; // uncompressed raw data @@ -967,12 +967,12 @@ int extract_screen_z80 (char *screen, FILE * fichero) { // we uncompress first the data uncompress_z80(fichero,6912,memo); //uncompress only the screen - memcpy(screen,memo,6912); + memcpy(screen_memory,memo,6912); } else { // 48k uncompressed z80 loader - fread(screen,6912,1,fichero); + fread(screen_memory,6912,1,fichero); } } diff --git a/src/cargador.h b/src/cargador.h index a3b8f93..5eff4bb 100644 --- a/src/cargador.h +++ b/src/cargador.h @@ -43,5 +43,5 @@ int load_z80(char *); int load_sna(char *); void load_snap(struct z80snapshot *); void uncompress_z80(FILE *,int,unsigned char *); -int extract_screen_sna (char *screen, FILE * fichero); -int extract_screen_z80 (char *screen, FILE * fichero); +int extract_screen_sna (char *screen_memory, FILE * fichero); +int extract_screen_z80 (char *screen_memory, FILE * fichero); diff --git a/src/computer.c b/src/computer.c index e77dba3..e88b110 100644 --- a/src/computer.c +++ b/src/computer.c @@ -1892,6 +1892,7 @@ void ResetComputer () { ordenador.recording_rzx=0; //ordenador.playing_rzx=0; ordenador.icount=0; + ordenador.extract_screen_rzx = 0; currah_microspeech_reset(); } diff --git a/src/computer.h b/src/computer.h index aefaa8c..a496002 100644 --- a/src/computer.h +++ b/src/computer.h @@ -214,6 +214,7 @@ struct computer { unsigned short int icount; unsigned int total_frames_rzx; unsigned int frames_count_rzx; + unsigned char extract_screen_rzx; // Microdrive global variables FILE *mdr_file; // Current microdrive file diff --git a/src/gui_sdl.c b/src/gui_sdl.c index e8aeb2b..5f14c46 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -1967,6 +1967,8 @@ static int do_rzx(int which) { case 0: // Record ordenador.playing_rzx=0; + ordenador.recording_rzx=0; + rzx_close(); ordenador.icount = 0; retorno2=save_rzx(); if (retorno2) break; //Error @@ -1978,7 +1980,9 @@ static int do_rzx(int which) retorno = -2; break; case 1: // Play + ordenador.playing_rzx=0; ordenador.recording_rzx=0; + rzx_close(); ordenador.icount = 0; ordenador.total_frames_rzx=0; ordenador.frames_count_rzx=1; diff --git a/src/menu_sdl.c b/src/menu_sdl.c index 7479b63..1dae723 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -517,12 +517,43 @@ void print_font(SDL_Surface *screen, int r, int g, int b, SDL_FreeSurface(font_surf); } -int extract_screen_rzx (char *screen, FILE * fichero) +int extract_screen_rzx (char *screen_memory, char *filename) { - return -1; + int retorno=0; + FILE *fichero; + + ordenador.extract_screen_rzx = 1; + + if (rzx_playback(filename)) return -1; + + ordenador.total_frames_rzx = 0; + + ordenador.extract_screen_rzx = 0; + + fichero=fopen(extracted_rzx_file,"rb"); + if (!fichero) retorno=-2; + else + { + if (ext_matches(extracted_rzx_file, ".z80")|ext_matches(extracted_rzx_file, ".Z80")) + retorno = extract_screen_z80(screen_memory, fichero); + else if (ext_matches(extracted_rzx_file, ".sna")|ext_matches(extracted_rzx_file, ".SNA")) + retorno = extract_screen_sna(screen_memory, fichero); + else + {printf("Not supported snap format\n");retorno=-1;} + } + + fclose(fichero); + + if (retorno) printf("Load snapshot error %d\n", retorno); + + unlink(extracted_rzx_file); + + rzx_close(); + + return retorno; } -int extract_screen(char* screen, const char* name) +int extract_screen(char* screen_memory, const char* name) { FILE *fichero; char filename[MAX_PATH_LENGTH]; @@ -539,7 +570,7 @@ int extract_screen(char* screen, const char* name) fichero=fopen(filename,"rb"); if (!fichero) return -1; } - retorno = extract_screen_tap(screen, fichero); + retorno = extract_screen_tap(screen_memory, fichero); fclose(fichero); return retorno; } @@ -557,7 +588,7 @@ int extract_screen(char* screen, const char* name) fread(char_id,10,1,fichero); // read the (maybe) TZX header if((strncmp(char_id,"ZXTape!",7)) || (char_id[7]!=0x1A) || (char_id[8]!=1)) {fclose(fichero);retorno = -1;}; - retorno = extract_screen_tzx(screen, fichero); + retorno = extract_screen_tzx(screen_memory, fichero); fclose(fichero); return retorno; } @@ -572,8 +603,8 @@ int extract_screen(char* screen, const char* name) fichero=fopen(filename,"rb"); if (!fichero) return -1; } - if (ext_matches(name, ".z80")||ext_matches(name, ".Z80")) retorno = extract_screen_z80(screen, fichero); - else retorno = extract_screen_sna(screen, fichero); + if (ext_matches(name, ".z80")||ext_matches(name, ".Z80")) retorno = extract_screen_z80(screen_memory, fichero); + else retorno = extract_screen_sna(screen_memory, fichero); fclose(fichero); return retorno; } @@ -581,15 +612,9 @@ int extract_screen(char* screen, const char* name) if ((ext_matches(name, ".rzx")||ext_matches(name, ".RZX"))) { sprintf(filename,"%s/%s",load_path_rzx, name); - fichero=fopen(filename,"rb"); - if (!fichero) //Try in the tmp zip directory - { - sprintf(filename,"%s/%s",path_tmp, name); - fichero=fopen(filename,"rb"); - if (!fichero) return -1; - } - retorno = extract_screen_rzx(screen, fichero); - fclose(fichero); + + retorno = extract_screen_rzx(screen_memory, filename); + return retorno; } @@ -599,7 +624,7 @@ int extract_screen(char* screen, const char* name) void draw_scr_file(int x,int y, const char *selected_file, int which) { FILE *fichero; - char screen [6912]; + char screen_memory [6912]; unsigned int *p_translt, *p_translt2; unsigned char attribute, ink, paper, mask, octect; int loop_x, loop_y,bucle,valor,*p, length; @@ -634,7 +659,7 @@ void draw_scr_file(int x,int y, const char *selected_file, int which) strcpy(name, "rzxtemp."); strcat(name, ext); - if (extract_screen(screen, name)) return; //error + if (extract_screen(screen_memory, name)) return; //error sprintf(filename, "%s/%s", load_path_snaps, name); unlink(filename); @@ -667,7 +692,7 @@ void draw_scr_file(int x,int y, const char *selected_file, int which) if (!fichero) return; - if (fread(screen,1,6912,fichero)!=6912) {fclose(fichero);return;} + if (fread(screen_memory,1,6912,fichero)!=6912) {fclose(fichero);return;} fclose(fichero); } else //first SCR @@ -675,10 +700,10 @@ void draw_scr_file(int x,int y, const char *selected_file, int which) fichero=fopen(filename,"rb"); if (!fichero) - {if (extract_screen(screen, selected_file)) return;} + {if (extract_screen(screen_memory, selected_file)) return;} else { - if (fread(screen,1,6912,fichero)!=6912) {fclose(fichero);return;} + if (fread(screen_memory,1,6912,fichero)!=6912) {fclose(fichero);return;} fclose(fichero); } } @@ -691,12 +716,12 @@ void draw_scr_file(int x,int y, const char *selected_file, int which) for(loop_x=0; loop_x<32; loop_x++) { - attribute = screen[(*p_translt2)-147456]; // attribute + attribute = screen_memory[(*p_translt2)-147456]; // attribute ink = attribute & 0x07; // ink colour paper = (attribute >> 3) & 0x07; // paper colour - octect = screen[(*p_translt)-147456]; // bitmap + octect = screen_memory[(*p_translt)-147456]; // bitmap mask = 0x80; for (bucle = 0; bucle < 8; bucle++) diff --git a/src/rzx_init.c b/src/rzx_init.c index 5ae31f6..9369694 100644 --- a/src/rzx_init.c +++ b/src/rzx_init.c @@ -42,6 +42,7 @@ RZX_EMULINFO emul_info; rzx_u32 tstates; int snapshot_counter; RZX_browser rzx_browser_list[MAX_RZX_BROWSER_ITEM+1]; +char extracted_rzx_file[MAX_PATH_LENGTH]; void find_name (char *name, char *filename) { @@ -62,7 +63,6 @@ void find_name (char *name, char *filename) rzx_u32 rzx_callback(int msg, void *par) { int retorno; - char name[MAX_PATH_LENGTH]; switch(msg) { @@ -81,14 +81,22 @@ rzx_u32 rzx_callback(int msg, void *par) (int)((RZX_SNAPINFO*)par)->length, (((RZX_SNAPINFO*)par)->options&RZX_EXTERNAL)?"external":"embedded", (((RZX_SNAPINFO*)par)->options&RZX_COMPRESSED)?"compressed":"uncompressed"); - if (((RZX_SNAPINFO*)par)->options&RZX_EXTERNAL) find_name(name,((RZX_SNAPINFO*)par)->filename); - else strncpy (name, ((RZX_SNAPINFO*)par)->filename,80); - if (ext_matches(name, ".z80")|ext_matches(name, ".Z80")) - retorno = load_z80(name); - else if (ext_matches(name, ".sna")|ext_matches(name, ".SNA")) - retorno = load_sna(name); + if (((RZX_SNAPINFO*)par)->options&RZX_EXTERNAL) find_name(extracted_rzx_file,((RZX_SNAPINFO*)par)->filename); + else strncpy (extracted_rzx_file, ((RZX_SNAPINFO*)par)->filename,80); + + if (ordenador.extract_screen_rzx) + { + ((RZX_SNAPINFO*)par)->options&=~RZX_REMOVE; //We do not want the file removed + } else - {printf("> Not supported snap format\n");retorno=-1;} + { + if (ext_matches(extracted_rzx_file, ".z80")|ext_matches(extracted_rzx_file, ".Z80")) + retorno = load_z80(extracted_rzx_file); + else if (ext_matches(extracted_rzx_file, ".sna")|ext_matches(extracted_rzx_file, ".SNA")) + retorno = load_sna(extracted_rzx_file); + else + {printf("> Not supported snap format\n");retorno=-1;} + } if (retorno) { printf("> Load snapshot error %d\n", retorno); diff --git a/src/rzx_init.h b/src/rzx_init.h index 0296b3a..4788009 100644 --- a/src/rzx_init.h +++ b/src/rzx_init.h @@ -27,4 +27,5 @@ typedef struct } RZX_browser; -extern RZX_browser rzx_browser_list[MAX_RZX_BROWSER_ITEM+1]; \ No newline at end of file +extern RZX_browser rzx_browser_list[MAX_RZX_BROWSER_ITEM+1]; +extern char extracted_rzx_file[MAX_PATH_LENGTH]; \ No newline at end of file diff --git a/src/tape_browser.c b/src/tape_browser.c index e28310c..4f337df 100644 --- a/src/tape_browser.c +++ b/src/tape_browser.c @@ -612,7 +612,7 @@ void save_scr_browser(unsigned char* zx_screen) } */ -int extract_screen_tap (char *screen, FILE * fichero) { +int extract_screen_tap (char *screen_memory, FILE * fichero) { unsigned int longitud; unsigned char value[65536], empty, flag_byte; @@ -642,7 +642,7 @@ int extract_screen_tap (char *screen, FILE * fichero) { { retval=fread (value, 1, longitud-1, fichero); if (retval!=(longitud-1)) {retorno=1;break;} - if ((longitud==6914) || (longitud==49154)) {memcpy(screen, value+1, 6912);rewind_tape (fichero,1);return 0;} + if ((longitud==6914) || (longitud==49154)) {memcpy(screen_memory, value+1, 6912);rewind_tape (fichero,1);return 0;} } } else @@ -656,7 +656,7 @@ int extract_screen_tap (char *screen, FILE * fichero) { { retval=fread (value, 1, longitud-1, fichero); if (retval!=(longitud-1)) {retorno=1;break;} - if ((longitud==6914) || (longitud==49154)) {memcpy(screen, value+1, 6912);rewind_tape (fichero,1);return 0;} + if ((longitud==6914) || (longitud==49154)) {memcpy(screen_memory, value+1, 6912);rewind_tape (fichero,1);return 0;} } break; default: //Custom data @@ -664,7 +664,7 @@ int extract_screen_tap (char *screen, FILE * fichero) { { retval=fread (value, 1, longitud-1, fichero); if (retval!=(longitud-1)) {retorno=1;break;} - if ((longitud==6914) || (longitud==49154)) {memcpy(screen, value+1, 6912);rewind_tape (fichero,1);return 0;} + if ((longitud==6914) || (longitud==49154)) {memcpy(screen_memory, value+1, 6912);rewind_tape (fichero,1);return 0;} } break; } @@ -674,7 +674,7 @@ rewind_tape (fichero,1); return -1; } -int extract_screen_tzx (char *screen, FILE * fichero) +int extract_screen_tzx (char *screen_memory, FILE * fichero) { unsigned int longitud, bucle, byte_position, retorno; @@ -721,7 +721,7 @@ int extract_screen_tzx (char *screen, FILE * fichero) { retval=fread (value, 1, longitud-1, fichero); if (retval!=(longitud-1)) {retorno=1;break;} - if ((longitud==6914) || (longitud==49154)) {memcpy(screen, value+1, 6912);rewind_tape (fichero,1);return 0;} + if ((longitud==6914) || (longitud==49154)) {memcpy(screen_memory, value+1, 6912);rewind_tape (fichero,1);return 0;} } } else @@ -735,7 +735,7 @@ int extract_screen_tzx (char *screen, FILE * fichero) { retval=fread (value, 1, longitud-1, fichero); if (retval!=(longitud-1)) {retorno=1;break;} - if ((longitud==6914) || (longitud==49154)) {memcpy(screen, value+1, 6912);rewind_tape (fichero,1);return 0;} + if ((longitud==6914) || (longitud==49154)) {memcpy(screen_memory, value+1, 6912);rewind_tape (fichero,1);return 0;} } break; default: //Custom data @@ -743,7 +743,7 @@ int extract_screen_tzx (char *screen, FILE * fichero) { retval=fread (value, 1, longitud-1, fichero); if (retval!=(longitud-1)) {retorno=1;break;} - if ((longitud==6914) || (longitud==49154)) {memcpy(screen, value+1, 6912);rewind_tape (fichero,1);return 0;} + if ((longitud==6914) || (longitud==49154)) {memcpy(screen_memory, value+1, 6912);rewind_tape (fichero,1);return 0;} } break; } @@ -787,9 +787,9 @@ int extract_screen_tzx (char *screen, FILE * fichero) else for(bucle=0;bucle