1
1
/* scl2trd.c: Convert .SCL disk images to .TRD disk images
2
2
Copyright (c) 2002-2007 Dmitry Sanarin, Philip Kendall and Fredrick Meunier
4
$Id: scl2trd.c 2891 2007-05-26 19:42:40Z zubzero $
4
$Id: scl2trd.c 4889 2013-02-18 23:15:03Z sbaldovi $
6
6
This program is free software; you can redistribute it and/or modify
7
7
it under the terms of the GNU General Public License as published by
147
148
TRDh = malloc(4096);
148
read(TRD, TRDh, 4096);
149
bytes_read = read(TRD, TRDh, 4096);
150
if (bytes_read < 4096) {
151
printf("Error - cannot read TRD header from %s\n", newname);
150
157
tmp = (char *) TRDh + 0x8E5;
151
trd_free = (unsigned int *) tmp;
152
158
trd_files = (unsigned char *) TRDh + 0x8E4;
153
159
trd_fsec = (unsigned char *) TRDh + 0x8E1;
154
160
trd_ftrk = (unsigned char *) TRDh + 0x8E2;
156
162
if ((SCL = open(oldname, O_RDONLY | O_BINARY)) == -1) {
157
163
printf("Can't open SCL file %s.\n", oldname);
163
read(SCL, &signature, 8);
167
bytes_read = read(SCL, &signature, 8);
168
if (bytes_read < 8) {
169
printf("Error - cannot read signature from SCL file %s\n", oldname);
165
173
if (strncasecmp(signature, "SINCLAIR", 8)) {
166
174
printf("Wrong signature=%s. \n", signature);
172
read(SCL, &blocks, 1);
174
for (x = 0; x < blocks; x++)
175
read(SCL, &(headers[x][0]), 14);
178
bytes_read = read(SCL, &blocks, 1);
179
if (bytes_read < 1) {
180
printf("Error - cannot read number of files in SCL file %s\n", oldname);
184
for (x = 0; x < blocks; x++) {
185
bytes_read = read(SCL, &(headers[x][0]), 14);
186
if (bytes_read < 14) {
187
printf("Error - cannot read header %d from SCL file %s\n", x, oldname);
177
192
for (x = 0; x < blocks; x++) {
178
193
size = headers[x][13];
202
217
lseek(TRD, fptr, SEEK_SET);
204
219
while (left > 32000) {
205
read(SCL, tmpscl, 32000);
206
write(TRD, tmpscl, 32000);
210
read(SCL, tmpscl, left);
211
write(TRD, tmpscl, left);
220
bytes_read = read(SCL, tmpscl, 32000);
221
if (bytes_read <= 0) {
222
printf("Error - reading file %d from SCL %s\n", x, oldname);
226
bytes_written = write(TRD, tmpscl, bytes_read);
227
if (bytes_written < bytes_read) {
228
printf("Error - writing to TRD file %s\n", newname);
236
bytes_read = read(SCL, tmpscl, left);
237
if (bytes_read < (ssize_t)left) {
238
printf("Error - reading file %d from SCL %s\n", x, oldname);
242
bytes_written = write(TRD, tmpscl, bytes_read);
243
if (bytes_written < bytes_read) {
244
printf("Error - writing to TRD file %s\n", newname);
234
270
lseek(TRD, 0L, SEEK_SET);
235
write(TRD, TRDh, 4096);
271
bytes_written = write(TRD, TRDh, 4096);
272
if (bytes_written < 4096) {
273
printf("Error - writing header to TRD file %s\n", newname);
241
287
parse_options(int argc, char **argv, struct options * options)
243
289
/* Defined by getopt */
245
290
extern int optind;