Added RZX snapshot preview

This commit is contained in:
fabio.olimpieri 2015-03-17 14:52:53 +00:00
parent 8e988a0240
commit 951654101f
10 changed files with 97 additions and 57 deletions

View File

@ -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 *tempo;
unsigned char *tempo2; unsigned char *tempo2;
@ -814,19 +814,19 @@ int extract_screen_sna (char *screen, FILE * fichero) {
if (type==0) { //48k if (type==0) { //48k
memcpy(screen,tempo+27,6912); memcpy(screen_memory,tempo+27,6912);
} else { //128k } else { //128k
v1=tempo2[2]; v1=tempo2[2];
//printf("v1= %d\n",(int) v1); //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 else //Screen in bank 7
{ {
v1&=0x07; 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 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; 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 tempo[30],tempo2[56],type,compressed,pager, byte_read[3];
unsigned char *memo; unsigned char *memo;
@ -930,7 +930,7 @@ int extract_screen_z80 (char *screen, FILE * fichero) {
fread(memo,6912,1,fichero); fread(memo,6912,1,fichero);
else else
uncompress_z80(fichero,6912,memo); uncompress_z80(fichero,6912,memo);
memcpy(screen, memo,6912); memcpy(screen_memory, memo,6912);
break; break;
} }
if(longitud2==0xFFFF) longitud2 =16384; // uncompressed raw data 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); fread(memo,6912,1,fichero);
else else
uncompress_z80(fichero,6912,memo); uncompress_z80(fichero,6912,memo);
memcpy(screen, memo,6912); memcpy(screen_memory, memo,6912);
break; break;
} }
if(longitud2==0xFFFF) longitud2 =16384; // uncompressed raw data 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 // we uncompress first the data
uncompress_z80(fichero,6912,memo); //uncompress only the screen uncompress_z80(fichero,6912,memo); //uncompress only the screen
memcpy(screen,memo,6912); memcpy(screen_memory,memo,6912);
} else { } else {
// 48k uncompressed z80 loader // 48k uncompressed z80 loader
fread(screen,6912,1,fichero); fread(screen_memory,6912,1,fichero);
} }
} }

View File

@ -43,5 +43,5 @@ int load_z80(char *);
int load_sna(char *); int load_sna(char *);
void load_snap(struct z80snapshot *); void load_snap(struct z80snapshot *);
void uncompress_z80(FILE *,int,unsigned char *); void uncompress_z80(FILE *,int,unsigned char *);
int extract_screen_sna (char *screen, FILE * fichero); int extract_screen_sna (char *screen_memory, FILE * fichero);
int extract_screen_z80 (char *screen, FILE * fichero); int extract_screen_z80 (char *screen_memory, FILE * fichero);

View File

@ -1892,6 +1892,7 @@ void ResetComputer () {
ordenador.recording_rzx=0; ordenador.recording_rzx=0;
//ordenador.playing_rzx=0; //ordenador.playing_rzx=0;
ordenador.icount=0; ordenador.icount=0;
ordenador.extract_screen_rzx = 0;
currah_microspeech_reset(); currah_microspeech_reset();
} }

View File

@ -214,6 +214,7 @@ struct computer {
unsigned short int icount; unsigned short int icount;
unsigned int total_frames_rzx; unsigned int total_frames_rzx;
unsigned int frames_count_rzx; unsigned int frames_count_rzx;
unsigned char extract_screen_rzx;
// Microdrive global variables // Microdrive global variables
FILE *mdr_file; // Current microdrive file FILE *mdr_file; // Current microdrive file

View File

@ -1967,6 +1967,8 @@ static int do_rzx(int which)
{ {
case 0: // Record case 0: // Record
ordenador.playing_rzx=0; ordenador.playing_rzx=0;
ordenador.recording_rzx=0;
rzx_close();
ordenador.icount = 0; ordenador.icount = 0;
retorno2=save_rzx(); retorno2=save_rzx();
if (retorno2) break; //Error if (retorno2) break; //Error
@ -1978,7 +1980,9 @@ static int do_rzx(int which)
retorno = -2; retorno = -2;
break; break;
case 1: // Play case 1: // Play
ordenador.playing_rzx=0;
ordenador.recording_rzx=0; ordenador.recording_rzx=0;
rzx_close();
ordenador.icount = 0; ordenador.icount = 0;
ordenador.total_frames_rzx=0; ordenador.total_frames_rzx=0;
ordenador.frames_count_rzx=1; ordenador.frames_count_rzx=1;

View File

@ -517,12 +517,43 @@ void print_font(SDL_Surface *screen, int r, int g, int b,
SDL_FreeSurface(font_surf); 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; FILE *fichero;
char filename[MAX_PATH_LENGTH]; char filename[MAX_PATH_LENGTH];
@ -539,7 +570,7 @@ int extract_screen(char* screen, const char* name)
fichero=fopen(filename,"rb"); fichero=fopen(filename,"rb");
if (!fichero) return -1; if (!fichero) return -1;
} }
retorno = extract_screen_tap(screen, fichero); retorno = extract_screen_tap(screen_memory, fichero);
fclose(fichero); fclose(fichero);
return retorno; 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 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)) if((strncmp(char_id,"ZXTape!",7)) || (char_id[7]!=0x1A) || (char_id[8]!=1))
{fclose(fichero);retorno = -1;}; {fclose(fichero);retorno = -1;};
retorno = extract_screen_tzx(screen, fichero); retorno = extract_screen_tzx(screen_memory, fichero);
fclose(fichero); fclose(fichero);
return retorno; return retorno;
} }
@ -572,8 +603,8 @@ int extract_screen(char* screen, const char* name)
fichero=fopen(filename,"rb"); fichero=fopen(filename,"rb");
if (!fichero) return -1; if (!fichero) return -1;
} }
if (ext_matches(name, ".z80")||ext_matches(name, ".Z80")) retorno = extract_screen_z80(screen, fichero); if (ext_matches(name, ".z80")||ext_matches(name, ".Z80")) retorno = extract_screen_z80(screen_memory, fichero);
else retorno = extract_screen_sna(screen, fichero); else retorno = extract_screen_sna(screen_memory, fichero);
fclose(fichero); fclose(fichero);
return retorno; return retorno;
} }
@ -581,15 +612,9 @@ int extract_screen(char* screen, const char* name)
if ((ext_matches(name, ".rzx")||ext_matches(name, ".RZX"))) if ((ext_matches(name, ".rzx")||ext_matches(name, ".RZX")))
{ {
sprintf(filename,"%s/%s",load_path_rzx, name); sprintf(filename,"%s/%s",load_path_rzx, name);
fichero=fopen(filename,"rb");
if (!fichero) //Try in the tmp zip directory retorno = extract_screen_rzx(screen_memory, filename);
{
sprintf(filename,"%s/%s",path_tmp, name);
fichero=fopen(filename,"rb");
if (!fichero) return -1;
}
retorno = extract_screen_rzx(screen, fichero);
fclose(fichero);
return retorno; 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) void draw_scr_file(int x,int y, const char *selected_file, int which)
{ {
FILE *fichero; FILE *fichero;
char screen [6912]; char screen_memory [6912];
unsigned int *p_translt, *p_translt2; unsigned int *p_translt, *p_translt2;
unsigned char attribute, ink, paper, mask, octect; unsigned char attribute, ink, paper, mask, octect;
int loop_x, loop_y,bucle,valor,*p, length; 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."); strcpy(name, "rzxtemp.");
strcat(name, ext); 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); sprintf(filename, "%s/%s", load_path_snaps, name);
unlink(filename); unlink(filename);
@ -667,7 +692,7 @@ void draw_scr_file(int x,int y, const char *selected_file, int which)
if (!fichero) return; 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); fclose(fichero);
} }
else //first SCR 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"); fichero=fopen(filename,"rb");
if (!fichero) if (!fichero)
{if (extract_screen(screen, selected_file)) return;} {if (extract_screen(screen_memory, selected_file)) return;}
else else
{ {
if (fread(screen,1,6912,fichero)!=6912) {fclose(fichero);return;} if (fread(screen_memory,1,6912,fichero)!=6912) {fclose(fichero);return;}
fclose(fichero); 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++) 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 ink = attribute & 0x07; // ink colour
paper = (attribute >> 3) & 0x07; // paper colour paper = (attribute >> 3) & 0x07; // paper colour
octect = screen[(*p_translt)-147456]; // bitmap octect = screen_memory[(*p_translt)-147456]; // bitmap
mask = 0x80; mask = 0x80;
for (bucle = 0; bucle < 8; bucle++) for (bucle = 0; bucle < 8; bucle++)

View File

@ -42,6 +42,7 @@ RZX_EMULINFO emul_info;
rzx_u32 tstates; rzx_u32 tstates;
int snapshot_counter; int snapshot_counter;
RZX_browser rzx_browser_list[MAX_RZX_BROWSER_ITEM+1]; RZX_browser rzx_browser_list[MAX_RZX_BROWSER_ITEM+1];
char extracted_rzx_file[MAX_PATH_LENGTH];
void find_name (char *name, char *filename) 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) rzx_u32 rzx_callback(int msg, void *par)
{ {
int retorno; int retorno;
char name[MAX_PATH_LENGTH];
switch(msg) switch(msg)
{ {
@ -81,14 +81,22 @@ rzx_u32 rzx_callback(int msg, void *par)
(int)((RZX_SNAPINFO*)par)->length, (int)((RZX_SNAPINFO*)par)->length,
(((RZX_SNAPINFO*)par)->options&RZX_EXTERNAL)?"external":"embedded", (((RZX_SNAPINFO*)par)->options&RZX_EXTERNAL)?"external":"embedded",
(((RZX_SNAPINFO*)par)->options&RZX_COMPRESSED)?"compressed":"uncompressed"); (((RZX_SNAPINFO*)par)->options&RZX_COMPRESSED)?"compressed":"uncompressed");
if (((RZX_SNAPINFO*)par)->options&RZX_EXTERNAL) find_name(name,((RZX_SNAPINFO*)par)->filename); if (((RZX_SNAPINFO*)par)->options&RZX_EXTERNAL) find_name(extracted_rzx_file,((RZX_SNAPINFO*)par)->filename);
else strncpy (name, ((RZX_SNAPINFO*)par)->filename,80); else strncpy (extracted_rzx_file, ((RZX_SNAPINFO*)par)->filename,80);
if (ext_matches(name, ".z80")|ext_matches(name, ".Z80"))
retorno = load_z80(name); if (ordenador.extract_screen_rzx)
else if (ext_matches(name, ".sna")|ext_matches(name, ".SNA")) {
retorno = load_sna(name); ((RZX_SNAPINFO*)par)->options&=~RZX_REMOVE; //We do not want the file removed
}
else 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) if (retorno)
{ {
printf("> Load snapshot error %d\n", retorno); printf("> Load snapshot error %d\n", retorno);

View File

@ -27,4 +27,5 @@ typedef struct
} RZX_browser; } RZX_browser;
extern RZX_browser rzx_browser_list[MAX_RZX_BROWSER_ITEM+1]; extern RZX_browser rzx_browser_list[MAX_RZX_BROWSER_ITEM+1];
extern char extracted_rzx_file[MAX_PATH_LENGTH];

View File

@ -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 int longitud;
unsigned char value[65536], empty, flag_byte; 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); retval=fread (value, 1, longitud-1, fichero);
if (retval!=(longitud-1)) {retorno=1;break;} 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 else
@ -656,7 +656,7 @@ int extract_screen_tap (char *screen, FILE * fichero) {
{ {
retval=fread (value, 1, longitud-1, fichero); retval=fread (value, 1, longitud-1, fichero);
if (retval!=(longitud-1)) {retorno=1;break;} 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; break;
default: //Custom data default: //Custom data
@ -664,7 +664,7 @@ int extract_screen_tap (char *screen, FILE * fichero) {
{ {
retval=fread (value, 1, longitud-1, fichero); retval=fread (value, 1, longitud-1, fichero);
if (retval!=(longitud-1)) {retorno=1;break;} 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; break;
} }
@ -674,7 +674,7 @@ rewind_tape (fichero,1);
return -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; 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); retval=fread (value, 1, longitud-1, fichero);
if (retval!=(longitud-1)) {retorno=1;break;} 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 else
@ -735,7 +735,7 @@ int extract_screen_tzx (char *screen, FILE * fichero)
{ {
retval=fread (value, 1, longitud-1, fichero); retval=fread (value, 1, longitud-1, fichero);
if (retval!=(longitud-1)) {retorno=1;break;} 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; break;
default: //Custom data default: //Custom data
@ -743,7 +743,7 @@ int extract_screen_tzx (char *screen, FILE * fichero)
{ {
retval=fread (value, 1, longitud-1, fichero); retval=fread (value, 1, longitud-1, fichero);
if (retval!=(longitud-1)) {retorno=1;break;} 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; break;
} }
@ -787,9 +787,9 @@ int extract_screen_tzx (char *screen, FILE * fichero)
else else
for(bucle=0;bucle<longitud;bucle++) for(bucle=0;bucle<longitud;bucle++)
fread(value,1,1, fichero); fread(value,1,1, fichero);
//if (longitud==6144) {memcpy(screen, value, 6144);found_screen=1;} //if (longitud==6144) {memcpy(screen_memory, value, 6144);found_screen=1;}
//if ((longitud==768) && (found_screen)) {memcpy(screen+6144, value, 768);rewind_tape (fichero,1);return 0;} //if ((longitud==768) && (found_screen)) {memcpy(screen_memory+6144, value, 768);rewind_tape (fichero,1);return 0;}
//if (longitud==6912) {memcpy(screen, value, 6912);rewind_tape (fichero,1);return 0;} //if (longitud==6912) {memcpy(screen_memory, value, 6912);rewind_tape (fichero,1);return 0;}
break; break;
case 0x20: // pause case 0x20: // pause

View File

@ -43,6 +43,6 @@ int select_block(FILE * fichero);
int jump_to_block(FILE * fichero, int blocks_to_jump); int jump_to_block(FILE * fichero, int blocks_to_jump);
void free_browser(); void free_browser();
//void save_scr_browser(unsigned char* zx_screen); //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);
int extract_screen_tzx (char *screen, FILE * fichero); int extract_screen_tzx (char *screen_memory, FILE * fichero);
#endif #endif