Tzx fast load for custom data, stop resets tape countdown, fixed tester file

This commit is contained in:
fabio.olimpieri 2013-02-24 08:04:20 +00:00
parent 526d10d6b4
commit 5176c41c71
8 changed files with 76 additions and 12 deletions

View File

@ -121,6 +121,7 @@ void computer_init () { //Called only on start-up
ordenador.rewind_on_reset = 1; //Rewound on reset by default ordenador.rewind_on_reset = 1; //Rewound on reset by default
ordenador.pause_instant_load = 0; ordenador.pause_instant_load = 0;
ordenador.tape_current_mode = TAP_TRASH; ordenador.tape_current_mode = TAP_TRASH;
ordenador.next_block= NOBLOCK;
ordenador.tap_file = NULL; ordenador.tap_file = NULL;
ordenador.osd_text[0] = 0; ordenador.osd_text[0] = 0;
@ -1243,6 +1244,7 @@ inline void read_keyboard () {
case SDLK_F5: // STOP tape case SDLK_F5: // STOP tape
//if ((ordenador.tape_fast_load == 0)) //if ((ordenador.tape_fast_load == 0))
ordenador.pause = 1; ordenador.pause = 1;
ordenador.tape_start_countdwn=0;
break; break;
case SDLK_F6: // PLAY tape case SDLK_F6: // PLAY tape

View File

@ -34,6 +34,7 @@ extern char salir;
enum tapmodes {TAP_GUIDE, TAP_DATA, TAP_PAUSE, TAP_TRASH, TAP_STOP, TAP_PAUSE2, TZX_PURE_TONE, 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}; TZX_SEQ_PULSES, TAP_FINAL_BIT, TAP_PAUSE3};
enum taptypes {TAP_TAP, TAP_TZX}; enum taptypes {TAP_TAP, TAP_TZX};
enum block_type {NOBLOCK, PROG, VAR, DATA};
int countdown_buffer; int countdown_buffer;
@ -165,6 +166,7 @@ struct computer {
// tape global variables // tape global variables
enum tapmodes tape_current_mode; enum tapmodes tape_current_mode;
enum block_type next_block;
unsigned char pause; // 1=tape stop unsigned char pause; // 1=tape stop
enum taptypes tape_file_type; enum taptypes tape_file_type;
unsigned int tape_counter0; unsigned int tape_counter0;

View File

@ -1543,7 +1543,7 @@ int main(int argc,char *argv[]) {
PC=procesador.PC; 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 */ FAST_LOAD is 1, we must load the block in memory and return */
if((!ordenador.mdr_paged)&&(PC==0x056c) && (ordenador.tape_fast_load==1)) { 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.pause_fastload_countdwn==0)
{ {
if (ordenador.tape_file_type==TAP_TAP) fastload_block_tap(ordenador.tap_file); 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 { else {

View File

@ -251,6 +251,7 @@ static void insert_tape()
ordenador.tape_current_bit=0; ordenador.tape_current_bit=0;
ordenador.tape_current_mode=TAP_TRASH; ordenador.tape_current_mode=TAP_TRASH;
ordenador.next_block= NOBLOCK;
if(ordenador.tap_file!=NULL) { if(ordenador.tap_file!=NULL) {
fclose(ordenador.tap_file); fclose(ordenador.tap_file);
@ -440,10 +441,12 @@ static int manage_tape(int which)
case 3: //Stop case 3: //Stop
//if (ordenador.tape_fast_load == 0) //if (ordenador.tape_fast_load == 0)
ordenador.pause = 1; ordenador.pause = 1;
ordenador.tape_start_countdwn=0;
retorno=-1; retorno=-1;
break; break;
case 4: //Rewind case 4: //Rewind
ordenador.pause=1; ordenador.pause=1;
ordenador.tape_start_countdwn=0;
if(ordenador.tap_file!=NULL) { if(ordenador.tap_file!=NULL) {
ordenador.tape_current_mode=TAP_TRASH; ordenador.tape_current_mode=TAP_TRASH;
rewind_tape(ordenador.tap_file,1); rewind_tape(ordenador.tap_file,1);

View File

@ -435,7 +435,7 @@ void menu_print_font(SDL_Surface *screen, int r, int g, int b,
lenght = strlen(buf); lenght = strlen(buf);
if (lenght>max_string) 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 */ /* Fixup multi-menu option look */

View File

@ -638,6 +638,7 @@ void taps_menu() {
case SDLK_2: case SDLK_2:
fin=0; fin=0;
ordenador.pause=1; ordenador.pause=1;
ordenador.tape_start_countdwn=0;
if(ordenador.tap_file!=NULL) { if(ordenador.tap_file!=NULL) {
ordenador.tape_current_mode=TAP_TRASH; ordenador.tape_current_mode=TAP_TRASH;
rewind_tape(ordenador.tap_file,1); rewind_tape(ordenador.tap_file,1);
@ -647,6 +648,7 @@ void taps_menu() {
break; break;
case SDLK_3: case SDLK_3:
ordenador.pause=1; ordenador.pause=1;
ordenador.tape_start_countdwn=0;
ordenador.tape_fast_load=1-ordenador.tape_fast_load; ordenador.tape_fast_load=1-ordenador.tape_fast_load;
if(ordenador.tap_file!=NULL) { if(ordenador.tap_file!=NULL) {
ordenador.tape_current_mode=TAP_TRASH; ordenador.tape_current_mode=TAP_TRASH;
@ -692,6 +694,7 @@ void select_tapfile() {
ordenador.tape_current_bit=0; ordenador.tape_current_bit=0;
ordenador.tape_current_mode=TAP_TRASH; ordenador.tape_current_mode=TAP_TRASH;
ordenador.next_block= NOBLOCK;
if(ordenador.tap_file!=NULL) { if(ordenador.tap_file!=NULL) {
fclose(ordenador.tap_file); fclose(ordenador.tap_file);

View File

@ -432,6 +432,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) {
retval=fread(&value,1,1,fichero); retval=fread(&value,1,1,fichero);
if(ordenador.mode128k==0) { if(ordenador.mode128k==0) {
ordenador.pause = 1; ordenador.pause = 1;
ordenador.tape_start_countdwn=0;
return; return;
} }
break; break;
@ -534,6 +535,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) {
switch (ordenador.tape_current_mode) { switch (ordenador.tape_current_mode) {
case TAP_FINAL_BIT: case TAP_FINAL_BIT:
ordenador.tape_current_mode = TAP_TRASH; ordenador.tape_current_mode = TAP_TRASH;
ordenador.next_block= NOBLOCK;
break; break;
case TAP_GUIDE: // guide tone case TAP_GUIDE: // guide tone
if (ordenador.tape_counter_rep) { // still into 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 { } else {
ordenador.tape_counter_rep = 0; ordenador.tape_counter_rep = 0;
ordenador.tape_current_mode = TAP_TRASH; // read new block ordenador.tape_current_mode = TAP_TRASH; // read new block
ordenador.next_block= NOBLOCK;
} }
break; break;
case TAP_PAUSE2: // pause and stop case TAP_PAUSE2: // pause and stop
@ -615,6 +618,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) {
} else { } else {
ordenador.tape_counter_rep = 0; ordenador.tape_counter_rep = 0;
ordenador.tape_current_mode = TAP_TRASH; // read new block ordenador.tape_current_mode = TAP_TRASH; // read new block
ordenador.next_block= NOBLOCK;
ordenador.pause = 1; ordenador.pause = 1;
} }
break; break;
@ -626,6 +630,7 @@ inline void tape_read_tzx (FILE * fichero, int tstados) {
ordenador.tape_counter1 = 0; // new pulse ordenador.tape_counter1 = 0; // new pulse
} else } else
ordenador.tape_current_mode = TAP_TRASH; // next ID ordenador.tape_current_mode = TAP_TRASH; // next ID
ordenador.next_block= NOBLOCK;
break; break;
case TZX_SEQ_PULSES: case TZX_SEQ_PULSES:
ordenador.tape_current_bit = 1 - ordenador.tape_current_bit; // invert current bit 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; ordenador.tape_counter1 = 0;
} else } else
ordenador.tape_current_mode = TAP_TRASH; // next ID ordenador.tape_current_mode = TAP_TRASH; // next ID
ordenador.next_block= NOBLOCK;
break; break;
case TAP_STOP: case TAP_STOP:
ordenador.tape_current_bit = 0; ordenador.tape_current_bit = 0;
ordenador.tape_current_mode = TAP_TRASH; // initialize ordenador.tape_current_mode = TAP_TRASH; // initialize
ordenador.next_block= NOBLOCK;
ordenador.pause = 1; // pause it ordenador.pause = 1; // pause it
break; break;
default: default:
@ -659,7 +666,9 @@ void rewind_tape(FILE *fichero,unsigned char pause) {
if(ordenador.tape_file_type==TAP_TZX) if(ordenador.tape_file_type==TAP_TZX)
for(thebucle=0;thebucle<10;thebucle++) for(thebucle=0;thebucle<10;thebucle++)
retval=fread(&value,1,1,ordenador.tap_file); // jump over the header retval=fread(&value,1,1,ordenador.tap_file); // jump over the header
ordenador.next_block= NOBLOCK;
ordenador.pause=pause; ordenador.pause=pause;
if (pause) ordenador.tape_start_countdwn=0; //Stop tape play countdown
} }
unsigned char file_empty(FILE *fichero) { 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 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; int retval, retval2;
//ordenador.other_ret = 1; // next instruction must be RET //ordenador.other_ret = 1; // next instruction must be RET
@ -953,8 +962,38 @@ void fastload_block_tzx (FILE * fichero) {
return; return;
} }
longitud = ((unsigned int) value[0]) + 256 * ((unsigned int) value[1]); 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; break;
case 0x11: // turbo case 0x11: // turbo
retval=fread(value,1,0x0F, fichero); retval=fread(value,1,0x0F, fichero);
retval=fread (value, 1,3 ,fichero); // read length of current block retval=fread (value, 1,3 ,fichero); // read length of current block
@ -989,7 +1028,7 @@ void fastload_block_tzx (FILE * fichero) {
case 0x20: // pause case 0x20: // pause
retval=fread(value,1,2,fichero); retval=fread(value,1,2,fichero);
if (retval!=2) {procesador.Rm.br.F &= (~F_C);return;} 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; break;
case 0x21: // group start case 0x21: // group start
@ -1020,6 +1059,7 @@ void fastload_block_tzx (FILE * fichero) {
retval=fread(value,1,4,fichero); retval=fread(value,1,4,fichero);
if(ordenador.mode128k==0) { if(ordenador.mode128k==0) {
ordenador.pause = 1; ordenador.pause = 1;
ordenador.tape_start_countdwn=0;
return; return;
} }
break; break;
@ -1168,7 +1208,6 @@ void fastload_block_tzx (FILE * fichero) {
retval=fread (&blockid, 1, 1, fichero); //Read next id block retval=fread (&blockid, 1, 1, fichero); //Read next id block
if (!feof(fichero)) if (!feof(fichero))
{ {
if (blockid==0x10) if (blockid==0x10)
@ -1177,22 +1216,26 @@ void fastload_block_tzx (FILE * fichero) {
if (retval==5) if (retval==5)
if ((value[4]!=0x0)&&(value[4]!=0xFF)) blockid=0x1; //custom data 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]==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) if (blockid!=0x10)
{ {
//Anticipate auto ultra fast mode //Anticipate auto ultra fast mode
if ((ordenador.turbo_state!= 1)&&(ordenador.turbo==1)) if ((ordenador.turbo_state!= 1)&&(ordenador.turbo==1))
{ {
update_frequency(10000000); update_frequency(11000000);
jump_frames=7; jump_frames=7;
ordenador.turbo_state=4; 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) 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 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+1; else ordenador.pause_fastload_countdwn=((unsigned int)pause[0]+256*(unsigned int)pause[1])/60;
} }
fseek(fichero, byte_position, SEEK_SET); fseek(fichero, byte_position, SEEK_SET);

View File

@ -237,6 +237,13 @@ byte Z80free_Rd (register word Addr) {
return ((byte)memory[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) { void Z80free_Wr (register word Addr, register byte Value) {
memory[Addr]=(unsigned char) Value; memory[Addr]=(unsigned char) Value;