14 #include "inputfiles.h"
16 static int probe(FILE *file,
const char *fname, cbmcopy_message_cb msg_cb)
19 const char signatures[][32] =
21 "C64 tape image file\0\0\0\0\0\0\0\0\0\0\0\0\0",
22 "C64S tape file\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
23 "C64S tape image file\0\0\0\0\0\0\0\0\0\0\0\0"
30 unsigned char max_entries_l;
31 unsigned char max_entries_h;
32 unsigned char used_entries_l;
33 unsigned char used_entries_h;
41 msg_cb( sev_debug,
"checking for t64" );
43 if(fread( &t64header,
sizeof(t64header), 1, file) == 1)
45 for(i = 0; i <
sizeof(signatures) / 32; i++)
47 if(memcmp(signatures[i], t64header.sig, 32) == 0)
50 t64header.used_entries_l +
51 t64header.used_entries_h * 256;
52 msg_cb( sev_debug,
"found t64 signature '%s'", signatures[i] );
53 msg_cb( sev_debug,
"tape version %u.%u",
54 t64header.major, t64header.minor );
55 msg_cb( sev_debug,
"tape contains %d file%c",
56 used_entries, used_entries > 1 ?
's' :
'\0' );
66 static int read(FILE *file,
const char *fname,
int entry,
67 char *cbmname,
char *type,
68 unsigned char **data,
size_t *size,
69 cbmcopy_message_cb msg_cb)
73 unsigned char c64s_type;
74 unsigned char c1541_type;
75 unsigned char start_l;
76 unsigned char start_h;
79 unsigned char unused1[2];
80 unsigned char offset[4];
81 unsigned char unused2[4];
82 unsigned char name[16];
89 if(fseek( file, 0x40 + 32 * entry, SEEK_SET ) == 0 &&
90 fread( &t64entry,
sizeof(t64entry), 1, file ) == 1)
92 memcpy( cbmname, t64entry.name, 16 );
93 for( i = 15; i >= 0 && cbmname[i] == 0x20; i-- )
95 cbmname[i] = (char) 0xa0;
97 switch(t64entry.c1541_type)
117 msg_cb( sev_info,
"unknown 1541 file type, using default" );
121 for(offset = 0, i = 3; i >= 0; i--)
123 offset = offset * 0x100 + t64entry.offset[i];
125 msg_cb( sev_debug,
"data offset = %08lx", offset );
126 start = t64entry.start_l + 0x100 * t64entry.start_h;
127 end = t64entry.end_l + 0x100 * t64entry.end_h;
129 if(fseek(file, offset, SEEK_SET) == 0)
131 *size = 2 + (end - start);
132 *data = malloc(*size);
135 (*data)[0] = t64entry.start_l;
136 (*data)[1] = t64entry.start_h;
137 if(fread(&(*data)[2], (*size)-2, 1, file) == 1)
143 msg_cb( sev_warning,
"could not read file data" );
149 msg_cb( sev_warning,
"no memory" );
154 msg_cb( sev_warning,
"could not seek to file data" );
159 msg_cb( sev_warning,
"could not seek to directory entry" );
164 DECLARE_INPUT_READER(t64);
DLL interface for accessing the driver.