// read tape info from tape file
int get_tape_info( char *filename)
{
FILE *fp;
int t;
unsigned char c;
fp=fopen(filename,"r");
if (fp) {
t=0;
// skip until zeroes found
do {
c=fgetc(fp);
t++;
} while (c);
// skip zeroes until SOH found (0x01)
do {
c=fgetc(fp);
} while (c==0);
if (c != 0x01) {
//printf("no SOH found\n\r");
fclose(fp);
return -1;
}
// read header
if (t>1) {
printf("%d garbage bytes found at start of file\n\r",t-1);
tape_info.skip_length=219+t-1;
} else {
tape_info.skip_length=219;
}
// start with short filename (5 chars)
for (t=0; t<5; t++) {
tape_info.short_name[t]=fgetc(fp);
}
tape_info.short_name[5]=0;
// file header ID (1 char)
tape_info.header_id=fgetc(fp);
//printf("File header ID: $%02x\n\r",header_id);
// file type (if bit 7 is set file can not be auto executed after load)
tape_info.file_type=fgetc(fp);
//printf("File type: $%02x\n\r",file_type);
if (tape_info.file_type & 0x80) tape_info.auto_run='A';
else tape_info.auto_run=' ';
// length of file (2 bytes, L/H)
c=fgetc(fp);
tape_info.file_size=c;
c=fgetc(fp);
tape_info.file_size |= (c<<8);
//printf("File length: %d ($%04x)\n\r",file_size,file_size);
// loading address (2 bytes, L/H)
c=fgetc(fp);
tape_info.load_address=c;
c=fgetc(fp);
tape_info.load_address |= (c<<8);
//printf("Load address: $%04x\n\r",load_address);
// go address (2 bytes, L/H)
c=fgetc(fp);
tape_info.go_address=c;
c=fgetc(fp);
tape_info.go_address |= (c<<8);
//printf("Go address: $%04x\n\r",go_address
fclose(fp);
return 0;
} else {
return -1;
}
}