From 5176c41c715c87b5478e56703ab362706ba66281 Mon Sep 17 00:00:00 2001 From: "fabio.olimpieri" Date: Sun, 24 Feb 2013 08:04:20 +0000 Subject: [PATCH] Tzx fast load for custom data, stop resets tape countdown, fixed tester file --- src/computer.c | 2 ++ src/computer.h | 2 ++ src/emulator.c | 8 +++-- src/gui_sdl.c | 3 ++ src/menu_sdl.c | 2 +- src/menus.c | 3 ++ src/tape.c | 61 ++++++++++++++++++++++++++++++------ src/z80free/z80free_tester.c | 7 +++++ 8 files changed, 76 insertions(+), 12 deletions(-) diff --git a/src/computer.c b/src/computer.c index 1f810f8..348b6f3 100644 --- a/src/computer.c +++ b/src/computer.c @@ -121,6 +121,7 @@ void computer_init () { //Called only on start-up ordenador.rewind_on_reset = 1; //Rewound on reset by default ordenador.pause_instant_load = 0; ordenador.tape_current_mode = TAP_TRASH; + ordenador.next_block= NOBLOCK; ordenador.tap_file = NULL; ordenador.osd_text[0] = 0; @@ -1243,6 +1244,7 @@ inline void read_keyboard () { case SDLK_F5: // STOP tape //if ((ordenador.tape_fast_load == 0)) ordenador.pause = 1; + ordenador.tape_start_countdwn=0; break; case SDLK_F6: // PLAY tape diff --git a/src/computer.h b/src/computer.h index fb5c217..071602c 100644 --- a/src/computer.h +++ b/src/computer.h @@ -34,6 +34,7 @@ extern char salir; enum tapmodes {TAP_GUIDE, TAP_DATA, TAP_PAUSE, TAP_TRASH, TAP_STOP, TAP_PAUSE2, TZX_PURE_TONE, TZX_SEQ_PULSES, TAP_FINAL_BIT, TAP_PAUSE3}; enum taptypes {TAP_TAP, TAP_TZX}; +enum block_type {NOBLOCK, PROG, VAR, DATA}; int countdown_buffer; @@ -165,6 +166,7 @@ struct computer { // tape global variables enum tapmodes tape_current_mode; + enum block_type next_block; unsigned char pause; // 1=tape stop enum taptypes tape_file_type; unsigned int tape_counter0; diff --git a/src/emulator.c b/src/emulator.c index 2190fb8..d86e199 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -1543,7 +1543,7 @@ int main(int argc,char *argv[]) { PC=procesador.PC; - /* if PC is 0x0556, a call to LD_BYTES has been made, so if + /* if PC is 0x056c, a call to LD_BYTES has been made, so if FAST_LOAD is 1, we must load the block in memory and return */ if((!ordenador.mdr_paged)&&(PC==0x056c) && (ordenador.tape_fast_load==1)) { @@ -1552,7 +1552,11 @@ int main(int argc,char *argv[]) { if (ordenador.pause_fastload_countdwn==0) { if (ordenador.tape_file_type==TAP_TAP) fastload_block_tap(ordenador.tap_file); - else fastload_block_tzx(ordenador.tap_file); + else + { + ordenador.tape_start_countdwn=0; //Stop tape play countdown + if (ordenador.pause ==1) fastload_block_tzx(ordenador.tap_file); + } } } else { diff --git a/src/gui_sdl.c b/src/gui_sdl.c index 21b5c16..51cfa89 100644 --- a/src/gui_sdl.c +++ b/src/gui_sdl.c @@ -251,6 +251,7 @@ static void insert_tape() ordenador.tape_current_bit=0; ordenador.tape_current_mode=TAP_TRASH; + ordenador.next_block= NOBLOCK; if(ordenador.tap_file!=NULL) { fclose(ordenador.tap_file); @@ -440,10 +441,12 @@ static int manage_tape(int which) case 3: //Stop //if (ordenador.tape_fast_load == 0) ordenador.pause = 1; + ordenador.tape_start_countdwn=0; retorno=-1; break; case 4: //Rewind ordenador.pause=1; + ordenador.tape_start_countdwn=0; if(ordenador.tap_file!=NULL) { ordenador.tape_current_mode=TAP_TRASH; rewind_tape(ordenador.tap_file,1); diff --git a/src/menu_sdl.c b/src/menu_sdl.c index 0355551..43ff7e6 100644 --- a/src/menu_sdl.c +++ b/src/menu_sdl.c @@ -435,7 +435,7 @@ void menu_print_font(SDL_Surface *screen, int r, int g, int b, lenght = strlen(buf); if (lenght>max_string) { - strcpy (buf + max_string-4, buf + lenght-4); + strcpy (buf + max_string-8, buf + lenght-8); } } /* Fixup multi-menu option look */ diff --git a/src/menus.c b/src/menus.c index a3a9c98..d9e05c8 100644 --- a/src/menus.c +++ b/src/menus.c @@ -638,6 +638,7 @@ void taps_menu() { case SDLK_2: fin=0; ordenador.pause=1; + ordenador.tape_start_countdwn=0; if(ordenador.tap_file!=NULL) { ordenador.tape_current_mode=TAP_TRASH; rewind_tape(ordenador.tap_file,1); @@ -647,6 +648,7 @@ void taps_menu() { break; case SDLK_3: ordenador.pause=1; + ordenador.tape_start_countdwn=0; ordenador.tape_fast_load=1-ordenador.tape_fast_load; if(ordenador.tap_file!=NULL) { ordenador.tape_current_mode=TAP_TRASH; @@ -692,6 +694,7 @@ void select_tapfile() { ordenador.tape_current_bit=0; ordenador.tape_current_mode=TAP_TRASH; + ordenador.next_block= NOBLOCK; if(ordenador.tap_file!=NULL) { fclose(ordenador.tap_file); diff --git a/src/tape.c b/src/tape.c index 5111cb2..2b7104f 100644 --- a/src/tape.c +++ b/src/tape.c @@ -432,6 +432,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) { retval=fread(&value,1,1,fichero); if(ordenador.mode128k==0) { ordenador.pause = 1; + ordenador.tape_start_countdwn=0; return; } break; @@ -534,6 +535,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) { switch (ordenador.tape_current_mode) { case TAP_FINAL_BIT: ordenador.tape_current_mode = TAP_TRASH; + ordenador.next_block= NOBLOCK; break; case TAP_GUIDE: // guide tone if (ordenador.tape_counter_rep) { // still into guide tone @@ -605,6 +607,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) { } else { ordenador.tape_counter_rep = 0; ordenador.tape_current_mode = TAP_TRASH; // read new block + ordenador.next_block= NOBLOCK; } break; case TAP_PAUSE2: // pause and stop @@ -615,6 +618,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) { } else { ordenador.tape_counter_rep = 0; ordenador.tape_current_mode = TAP_TRASH; // read new block + ordenador.next_block= NOBLOCK; ordenador.pause = 1; } break; @@ -626,6 +630,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) { ordenador.tape_counter1 = 0; // new pulse } else ordenador.tape_current_mode = TAP_TRASH; // next ID + ordenador.next_block= NOBLOCK; break; case TZX_SEQ_PULSES: ordenador.tape_current_bit = 1 - ordenador.tape_current_bit; // invert current bit @@ -637,11 +642,13 @@ inline void tape_read_tzx (FILE * fichero, int tstados) { ordenador.tape_counter1 = 0; } else ordenador.tape_current_mode = TAP_TRASH; // next ID + ordenador.next_block= NOBLOCK; break; case TAP_STOP: ordenador.tape_current_bit = 0; ordenador.tape_current_mode = TAP_TRASH; // initialize + ordenador.next_block= NOBLOCK; ordenador.pause = 1; // pause it break; default: @@ -659,7 +666,9 @@ void rewind_tape(FILE *fichero,unsigned char pause) { if(ordenador.tape_file_type==TAP_TZX) for(thebucle=0;thebucle<10;thebucle++) retval=fread(&value,1,1,ordenador.tap_file); // jump over the header + ordenador.next_block= NOBLOCK; ordenador.pause=pause; + if (pause) ordenador.tape_start_countdwn=0; //Stop tape play countdown } unsigned char file_empty(FILE *fichero) { @@ -897,7 +906,7 @@ void fastload_block_tzx (FILE * fichero) { */ unsigned int longitud, len, bucle, number_bytes, byte_position; - unsigned char value[65536], empty, blockid, parity, pause[2]; + unsigned char value[65536], empty, blockid, parity, pause[2],flag_byte; int retval, retval2; //ordenador.other_ret = 1; // next instruction must be RET @@ -933,7 +942,7 @@ void fastload_block_tzx (FILE * fichero) { do { retval=fread (&blockid, 1, 1, fichero); //Read id block if (feof (fichero)) // end of file? - { + { sprintf (ordenador.osd_text, "Rewind tape"); ordenador.osd_time = 100; rewind_tape(fichero, 1); @@ -953,8 +962,38 @@ void fastload_block_tzx (FILE * fichero) { return; } longitud = ((unsigned int) value[0]) + 256 * ((unsigned int) value[1]); + byte_position=ftell(fichero); + retval=fread (&flag_byte, 1, 1, fichero); + if (retval!=1) {procesador.Rm.br.F &= (~F_C);return;} + switch(flag_byte) + { + case 0x00: //header + retval=fread (value, 1, 17, fichero); + if (retval!=17) {procesador.Rm.br.F &= (~F_C);return;} + switch(value[0] ) //Type + { + case 0x00: + ordenador.next_block=PROG; + break; + case 0X01: + case 0X02: + case 0X03: + ordenador.next_block=DATA; + break; + default: //?? + ordenador.next_block=NOBLOCK; + break; + } break; - + case 0xFF: //data + ordenador.next_block=NOBLOCK; + break; + default: //Custom data + ordenador.next_block=NOBLOCK; + break; + } + fseek(fichero, byte_position, SEEK_SET); + break; case 0x11: // turbo retval=fread(value,1,0x0F, fichero); retval=fread (value, 1,3 ,fichero); // read length of current block @@ -989,7 +1028,7 @@ void fastload_block_tzx (FILE * fichero) { case 0x20: // pause retval=fread(value,1,2,fichero); if (retval!=2) {procesador.Rm.br.F &= (~F_C);return;} - if (!value[0]&&!value[1]) {procesador.Rm.br.F &= (~F_C);return;} //stop the tape + if (!value[0]&&!value[1]) {return;} //stop the tape break; case 0x21: // group start @@ -1020,6 +1059,7 @@ void fastload_block_tzx (FILE * fichero) { retval=fread(value,1,4,fichero); if(ordenador.mode128k==0) { ordenador.pause = 1; + ordenador.tape_start_countdwn=0; return; } break; @@ -1168,7 +1208,6 @@ void fastload_block_tzx (FILE * fichero) { retval=fread (&blockid, 1, 1, fichero); //Read next id block - if (!feof(fichero)) { if (blockid==0x10) @@ -1177,22 +1216,26 @@ void fastload_block_tzx (FILE * fichero) { if (retval==5) if ((value[4]!=0x0)&&(value[4]!=0xFF)) blockid=0x1; //custom data if ((value[4]==0x0)&&((value[2]+value[3]*256)!=0x13)) blockid=0x1; //custom data + if ((value[4]==0xFF)&&(ordenador.next_block==NOBLOCK)) blockid=0x2; //standard data + //printf("TZX: ID_fast2: %X en %d\n",blockid,byte_position+1); + //printf("TZX: next block: %X \n",ordenador.next_block); } if (blockid!=0x10) { //Anticipate auto ultra fast mode if ((ordenador.turbo_state!= 1)&&(ordenador.turbo==1)) { - update_frequency(10000000); + update_frequency(11000000); jump_frames=7; ordenador.turbo_state=4; } - ordenador.tape_start_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/20+1; //autoplay countdown + ordenador.tape_start_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/20+1; //autoplay countdown + if (ordenador.tape_start_countdwn<10) ordenador.tape_start_countdwn=10; //in case the pause is too short } else if (ordenador.pause_instant_load) { - if (ordenador.turbo==0) ordenador.pause_fastload_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/20+1; //tzx pause - else ordenador.pause_fastload_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/60+1; + if (ordenador.turbo==0) ordenador.pause_fastload_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/20; //tzx pause + else ordenador.pause_fastload_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/60; } fseek(fichero, byte_position, SEEK_SET); diff --git a/src/z80free/z80free_tester.c b/src/z80free/z80free_tester.c index 318e680..9326c9a 100644 --- a/src/z80free/z80free_tester.c +++ b/src/z80free/z80free_tester.c @@ -237,6 +237,13 @@ byte Z80free_Rd (register word Addr) { return ((byte)memory[Addr]); } + +byte Z80free_Rd_fetch (register word Addr) { + + return ((byte)memory[Addr]); + +} + void Z80free_Wr (register word Addr, register byte Value) { memory[Addr]=(unsigned char) Value;