From 434e7f96cee408bb79cfd56bfcdff527223d74e6 Mon Sep 17 00:00:00 2001 From: Björn Esser Date: Jun 21 2019 20:48:17 +0000 Subject: Initial import (#1722942) --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..601d543 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/cc1541-*.tar.bz2 +/cc1541-*.tar.gz diff --git a/0001-Added-B-switch-to-specify-DIR-block-size.-Also-made-.patch b/0001-Added-B-switch-to-specify-DIR-block-size.-Also-made-.patch new file mode 100644 index 0000000..e819eee --- /dev/null +++ b/0001-Added-B-switch-to-specify-DIR-block-size.-Also-made-.patch @@ -0,0 +1,214 @@ +From c84df7b7e4528911bf286ce5e40ffe72afacd013 Mon Sep 17 00:00:00 2001 +From: Claus +Date: Mon, 14 Jan 2019 18:49:00 +0100 +Subject: [PATCH 01/30] Added -B switch to specify DIR block size. Also made + the actual block size the default for loop files (was always 0 before). + +--- + cc1541.c | 43 +++++++++++++++++++++++--------- + test_cc1541/test_cc1541.c | 52 +++++++++++++++++++++++++++++++++++++++ + 2 files changed, 84 insertions(+), 11 deletions(-) + +diff --git a/cc1541.c b/cc1541.c +index 8bf507f..1e45275 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -71,6 +71,7 @@ typedef struct + int track; + int sector; + int nrSectors; ++ int nrSectorsShown; + int mode; + } imagefile; + +@@ -97,7 +98,7 @@ void + usage() + { + printf("\n*** This is cc1541 version " VERSION " built on " __DATE__ " ***\n\n"); +- printf("Usage: cc1541 -niFSsfeErbcwlxtdu45q image.[d64|g64|d71]\n\n"); ++ printf("Usage: cc1541 -niFSsfeErbcwlBxtdu45q image.[d64|g64|d71]\n\n"); + printf("-n diskname Disk name, default='DEFAULT'.\n"); + printf("-i id Disk ID, default='LODIS'.\n"); + printf("-F Next file first sector on a new track (default=3).\n"); +@@ -124,6 +125,8 @@ usage() + printf(" local name is used. After file written, the filename is unset.\n"); + printf("-l filename Write loop file (an additional dir entry) to existing file to\n"); + printf(" disk, set filename with -f.\n"); ++ printf("-B numblocks Write the given value as file size in blocks to the directory for\n"); ++ printf(" the next file.\n"); + printf("-x Don't split files over dirtrack hole (default split files).\n"); + printf("-t Use dirtrack to also store files (makes -x useless) (default no).\n"); + printf("-d track Maintain a shadow directory (copy of the actual directory).\n"); +@@ -558,7 +561,7 @@ wipe_file(image_type type, unsigned char* image, unsigned int track, unsigned in + } + + static int +-find_file(image_type type, unsigned char* image, char* filename, unsigned char *track, unsigned char *sector) ++find_file(image_type type, unsigned char* image, char* filename, unsigned char *track, unsigned char *sector, unsigned int *numblocks) + { + int direntryindex = 0; + +@@ -575,7 +578,7 @@ find_file(image_type type, unsigned char* image, char* filename, unsigned char * + if (dirstrcmp((char *) image + dirblock + entryOffset + FILENAMEOFFSET, filename) == 0) { + *track = image[dirblock + entryOffset + FILETRACKOFFSET]; + *sector = image[dirblock + entryOffset + FILESECTOROFFSET]; +- ++ *numblocks = image[dirblock + entryOffset + FILEBLOCKSLOOFFSET] + 256*image[dirblock + entryOffset + FILEBLOCKSHIOFFSET]; + return direntryindex; + } + break; +@@ -852,7 +855,7 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + + if (file->mode & MODE_LOOPFILE) { + /* find loopfile source files */ +- int direntryindex = find_file(type, image, file->localname, &track, §or); ++ int direntryindex = find_file(type, image, file->localname, &track, §or, &file->nrSectors); + if (direntryindex >= 0) { + file->track = track; + file->sector = sector; +@@ -862,16 +865,19 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + image[entryOffset + FILETRACKOFFSET] = file->track; + image[entryOffset + FILESECTOROFFSET] = file->sector; + +- image[entryOffset + FILEBLOCKSLOOFFSET] = 0; +- image[entryOffset + FILEBLOCKSHIOFFSET] = 0; ++ if (file->nrSectorsShown == -1) { ++ file->nrSectorsShown = file->nrSectors; ++ } ++ image[entryOffset + FILEBLOCKSLOOFFSET] = file->nrSectorsShown % 256; ++ image[entryOffset + FILEBLOCKSHIOFFSET] = file->nrSectorsShown / 256; + + if (shadowdirtrack > 0) { + entryOffset = linear_sector(type, shadowdirtrack, file->direntrysector) * BLOCKSIZE + file->direntryoffset; + image[entryOffset + FILETRACKOFFSET] = file->track; + image[entryOffset + FILESECTOROFFSET] = file->sector; + +- image[entryOffset + FILEBLOCKSLOOFFSET] = 0; +- image[entryOffset + FILEBLOCKSHIOFFSET] = 0; ++ image[entryOffset + FILEBLOCKSLOOFFSET] = file->nrSectors; ++ image[entryOffset + FILEBLOCKSHIOFFSET] = file->nrSectors; + } + + continue; +@@ -1155,8 +1161,11 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + image[entryOffset + FILETRACKOFFSET] = file->track; + image[entryOffset + FILESECTOROFFSET] = file->sector; + +- image[entryOffset + FILEBLOCKSLOOFFSET] = file->nrSectors & 255; +- image[entryOffset + FILEBLOCKSHIOFFSET] = file->nrSectors >> 8; ++ if (file->nrSectorsShown < 0) { ++ file->nrSectorsShown = file->nrSectors; ++ } ++ image[entryOffset + FILEBLOCKSLOOFFSET] = file->nrSectorsShown & 255; ++ image[entryOffset + FILEBLOCKSHIOFFSET] = file->nrSectorsShown >> 8; + + if (shadowdirtrack > 0) { + entryOffset = linear_sector(type, shadowdirtrack, file->direntrysector) * BLOCKSIZE + file->direntryoffset; +@@ -1372,6 +1381,7 @@ main(int argc, char* argv[]) + int sectorInterleave = 0; + int dir_sector_interleave = 3; + int numdirblocks = 2; ++ int nrSectorsShown = -1; + char* filename = NULL; + int set_header = 0; + +@@ -1468,6 +1478,7 @@ main(int argc, char* argv[]) + files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; + files[nrFiles].first_sector_new_track = first_sector_new_track; + files[nrFiles].nrSectors = 0; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; + nrFiles++; + } else { + fprintf(stderr, "File '%s' (%d) not found\n", argv[j + 1], nrFiles + 1); +@@ -1477,6 +1488,7 @@ main(int argc, char* argv[]) + filename = NULL; + first_sector_new_track = default_first_sector_new_track; + sectorInterleave = 0; ++ nrSectorsShown = -1; + j++; + } else if (strcmp(argv[j], "-x") == 0) { + dirtracksplit = 0; +@@ -1492,7 +1504,16 @@ main(int argc, char* argv[]) + printf("Error parsing argument for -u\n"); + return -1; + } +- } else if (strcmp(argv[j], "-4") == 0) { ++ } else if (strcmp(argv[j], "-B") == 0) { ++ if ((argc < j + 2) || !sscanf(argv[++j], "%d", &nrSectorsShown)) { ++ printf("Error parsing argument for -B\n"); ++ return -1; ++ } ++ if (nrSectorsShown < 0 || nrSectorsShown > 65535) { ++ printf("Argument must be between 0 and 65535 for -B\n"); ++ return -1; ++ } ++ } else if (strcmp(argv[j], "-4") == 0) { + type = IMAGE_D64_EXTENDED_SPEED_DOS; + } else if (strcmp(argv[j], "-5") == 0) { + type = IMAGE_D64_EXTENDED_DOLPHIN_DOS; +diff --git a/test_cc1541/test_cc1541.c b/test_cc1541/test_cc1541.c +index c6b6a93..f541add 100644 +--- a/test_cc1541/test_cc1541.c ++++ b/test_cc1541/test_cc1541.c +@@ -557,6 +557,58 @@ main(int argc, char* argv[]) { + remove("1.prg"); + remove("2.prg"); + ++ description = "File should have DIR block size 0 for -B"; ++ test++; ++ create_value_file("1.prg", 3 * 254, 1); ++ if (run_binary_cleanup(binary, "-B 0 -w 1.prg", "image.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } ++ else if (image[track_offset[17] + 256 + 30] == 0 && image[track_offset[17] + 256 + 31] == 0) { ++ passed++; ++ } ++ else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); ++ ++ description = "File should have DIR block size 65535 for -B"; ++ test++; ++ create_value_file("1.prg", 3 * 254, 1); ++ if (run_binary_cleanup(binary, "-B 65535 -w 1.prg", "image.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } ++ else if (image[track_offset[17] + 256 + 30] == (char)255 && image[track_offset[17] + 256 + 31] == (char)255) { ++ passed++; ++ } ++ else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); ++ ++ description = "Loop file should have actual DIR block size per default"; ++ test++; ++ create_value_file("1.prg", 258 * 254, 1); ++ if (run_binary_cleanup(binary, "-w 1.prg -f LOOP.PRG -l 1.PRG", "image.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } else if (image[track_offset[17] + 256 + 32 + 30] == 2 && image[track_offset[17] + 256 + 32 + 31] == 1) { ++ passed++; ++ } else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); ++ ++ description = "Loop file should have DIR block size 258 for -B"; ++ test++; ++ create_value_file("1.prg", 39 * 254, 1); ++ if (run_binary/*_cleanup*/(binary, "-w 1.prg -f LOOP.PRG -B 258 -l 1.PRG", "image.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } else if (image[track_offset[17] + 256 + 32 + 30] == 2 && image[track_offset[17] + 256 + 32 + 31] == 1) { ++ passed++; ++ } else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); ++ + /* clean up */ + if (image != NULL) { + free(image); +-- +2.21.0 + diff --git a/0002-Tabs-to-spaces.patch b/0002-Tabs-to-spaces.patch new file mode 100644 index 0000000..90fcb05 --- /dev/null +++ b/0002-Tabs-to-spaces.patch @@ -0,0 +1,162 @@ +From 696bfc0817797e76888454a29d94317f9e273f4c Mon Sep 17 00:00:00 2001 +From: Claus +Date: Mon, 14 Jan 2019 18:56:31 +0100 +Subject: [PATCH 02/30] Tabs to spaces. + +--- + cc1541.c | 38 +++++++++++++-------------- + test_cc1541/test_cc1541.c | 54 +++++++++++++++++++-------------------- + 2 files changed, 46 insertions(+), 46 deletions(-) + +diff --git a/cc1541.c b/cc1541.c +index 1e45275..9cd5d68 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -126,7 +126,7 @@ usage() + printf("-l filename Write loop file (an additional dir entry) to existing file to\n"); + printf(" disk, set filename with -f.\n"); + printf("-B numblocks Write the given value as file size in blocks to the directory for\n"); +- printf(" the next file.\n"); ++ printf(" the next file.\n"); + printf("-x Don't split files over dirtrack hole (default split files).\n"); + printf("-t Use dirtrack to also store files (makes -x useless) (default no).\n"); + printf("-d track Maintain a shadow directory (copy of the actual directory).\n"); +@@ -578,7 +578,7 @@ find_file(image_type type, unsigned char* image, char* filename, unsigned char * + if (dirstrcmp((char *) image + dirblock + entryOffset + FILENAMEOFFSET, filename) == 0) { + *track = image[dirblock + entryOffset + FILETRACKOFFSET]; + *sector = image[dirblock + entryOffset + FILESECTOROFFSET]; +- *numblocks = image[dirblock + entryOffset + FILEBLOCKSLOOFFSET] + 256*image[dirblock + entryOffset + FILEBLOCKSHIOFFSET]; ++ *numblocks = image[dirblock + entryOffset + FILEBLOCKSLOOFFSET] + 256*image[dirblock + entryOffset + FILEBLOCKSHIOFFSET]; + return direntryindex; + } + break; +@@ -865,9 +865,9 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + image[entryOffset + FILETRACKOFFSET] = file->track; + image[entryOffset + FILESECTOROFFSET] = file->sector; + +- if (file->nrSectorsShown == -1) { +- file->nrSectorsShown = file->nrSectors; +- } ++ if (file->nrSectorsShown == -1) { ++ file->nrSectorsShown = file->nrSectors; ++ } + image[entryOffset + FILEBLOCKSLOOFFSET] = file->nrSectorsShown % 256; + image[entryOffset + FILEBLOCKSHIOFFSET] = file->nrSectorsShown / 256; + +@@ -1161,9 +1161,9 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + image[entryOffset + FILETRACKOFFSET] = file->track; + image[entryOffset + FILESECTOROFFSET] = file->sector; + +- if (file->nrSectorsShown < 0) { +- file->nrSectorsShown = file->nrSectors; +- } ++ if (file->nrSectorsShown < 0) { ++ file->nrSectorsShown = file->nrSectors; ++ } + image[entryOffset + FILEBLOCKSLOOFFSET] = file->nrSectorsShown & 255; + image[entryOffset + FILEBLOCKSHIOFFSET] = file->nrSectorsShown >> 8; + +@@ -1478,7 +1478,7 @@ main(int argc, char* argv[]) + files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; + files[nrFiles].first_sector_new_track = first_sector_new_track; + files[nrFiles].nrSectors = 0; +- files[nrFiles].nrSectorsShown = nrSectorsShown; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; + nrFiles++; + } else { + fprintf(stderr, "File '%s' (%d) not found\n", argv[j + 1], nrFiles + 1); +@@ -1504,16 +1504,16 @@ main(int argc, char* argv[]) + printf("Error parsing argument for -u\n"); + return -1; + } +- } else if (strcmp(argv[j], "-B") == 0) { +- if ((argc < j + 2) || !sscanf(argv[++j], "%d", &nrSectorsShown)) { +- printf("Error parsing argument for -B\n"); +- return -1; +- } +- if (nrSectorsShown < 0 || nrSectorsShown > 65535) { +- printf("Argument must be between 0 and 65535 for -B\n"); +- return -1; +- } +- } else if (strcmp(argv[j], "-4") == 0) { ++ } else if (strcmp(argv[j], "-B") == 0) { ++ if ((argc < j + 2) || !sscanf(argv[++j], "%d", &nrSectorsShown)) { ++ printf("Error parsing argument for -B\n"); ++ return -1; ++ } ++ if (nrSectorsShown < 0 || nrSectorsShown > 65535) { ++ printf("Argument must be between 0 and 65535 for -B\n"); ++ return -1; ++ } ++ } else if (strcmp(argv[j], "-4") == 0) { + type = IMAGE_D64_EXTENDED_SPEED_DOS; + } else if (strcmp(argv[j], "-5") == 0) { + type = IMAGE_D64_EXTENDED_DOLPHIN_DOS; +diff --git a/test_cc1541/test_cc1541.c b/test_cc1541/test_cc1541.c +index f541add..8941110 100644 +--- a/test_cc1541/test_cc1541.c ++++ b/test_cc1541/test_cc1541.c +@@ -557,33 +557,33 @@ main(int argc, char* argv[]) { + remove("1.prg"); + remove("2.prg"); + +- description = "File should have DIR block size 0 for -B"; +- test++; +- create_value_file("1.prg", 3 * 254, 1); +- if (run_binary_cleanup(binary, "-B 0 -w 1.prg", "image.d64", &image, &size) != NO_ERROR) { +- printf("UNRESOLVED: %s\n", description); +- } +- else if (image[track_offset[17] + 256 + 30] == 0 && image[track_offset[17] + 256 + 31] == 0) { +- passed++; +- } +- else { +- printf("FAIL: %s\n", description); +- } +- remove("1.prg"); +- +- description = "File should have DIR block size 65535 for -B"; +- test++; +- create_value_file("1.prg", 3 * 254, 1); +- if (run_binary_cleanup(binary, "-B 65535 -w 1.prg", "image.d64", &image, &size) != NO_ERROR) { +- printf("UNRESOLVED: %s\n", description); +- } +- else if (image[track_offset[17] + 256 + 30] == (char)255 && image[track_offset[17] + 256 + 31] == (char)255) { +- passed++; +- } +- else { +- printf("FAIL: %s\n", description); +- } +- remove("1.prg"); ++ description = "File should have DIR block size 0 for -B"; ++ test++; ++ create_value_file("1.prg", 3 * 254, 1); ++ if (run_binary_cleanup(binary, "-B 0 -w 1.prg", "image.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } ++ else if (image[track_offset[17] + 256 + 30] == 0 && image[track_offset[17] + 256 + 31] == 0) { ++ passed++; ++ } ++ else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); ++ ++ description = "File should have DIR block size 65535 for -B"; ++ test++; ++ create_value_file("1.prg", 3 * 254, 1); ++ if (run_binary_cleanup(binary, "-B 65535 -w 1.prg", "image.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } ++ else if (image[track_offset[17] + 256 + 30] == (char)255 && image[track_offset[17] + 256 + 31] == (char)255) { ++ passed++; ++ } ++ else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); + + description = "Loop file should have actual DIR block size per default"; + test++; +-- +2.21.0 + diff --git a/0004-Add-make-target-to-run-tests.patch b/0004-Add-make-target-to-run-tests.patch new file mode 100644 index 0000000..eeb2701 --- /dev/null +++ b/0004-Add-make-target-to-run-tests.patch @@ -0,0 +1,25 @@ +From 64c0c144e90e41d609bc9f4e880809b9677e7540 Mon Sep 17 00:00:00 2001 +From: Claus +Date: Mon, 21 Jan 2019 09:42:59 +0100 +Subject: [PATCH 04/30] Add make target to run tests. + +--- + test_cc1541/Makefile | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/test_cc1541/Makefile b/test_cc1541/Makefile +index 4ab0c49..04c3680 100644 +--- a/test_cc1541/Makefile ++++ b/test_cc1541/Makefile +@@ -4,5 +4,8 @@ test_cc1541: test_cc1541.o + %.o: %.c + gcc -std=c99 -c $< + ++test: test_cc1541 ++ ./test_cc1541 ../cc1541 ++ + clean: + rm -rf *.o test_cc1541 *~ +-- +2.21.0 + diff --git a/0006-Added-L-switch-to-reference-loop-files-by-index.patch b/0006-Added-L-switch-to-reference-loop-files-by-index.patch new file mode 100644 index 0000000..0c5ecf9 --- /dev/null +++ b/0006-Added-L-switch-to-reference-loop-files-by-index.patch @@ -0,0 +1,233 @@ +From 962d56ce127bda6285812af5f25abebd85896bb1 Mon Sep 17 00:00:00 2001 +From: Claus +Date: Sun, 3 Feb 2019 20:26:43 +0100 +Subject: [PATCH 06/30] Added -L switch to reference loop files by index + +--- + cc1541.c | 109 +++++++++++++++++++++++++------------- + test_cc1541/test_cc1541.c | 22 ++++++-- + 2 files changed, 91 insertions(+), 40 deletions(-) + +diff --git a/cc1541.c b/cc1541.c +index 9cd5d68..84a1df3 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -63,6 +63,7 @@ typedef struct + { + char* localname; + char filename[FILENAMEMAXSIZE]; ++ int loopindex; + int direntryindex; + int direntrysector; + int direntryoffset; +@@ -98,7 +99,7 @@ void + usage() + { + printf("\n*** This is cc1541 version " VERSION " built on " __DATE__ " ***\n\n"); +- printf("Usage: cc1541 -niFSsfeErbcwlBxtdu45q image.[d64|g64|d71]\n\n"); ++ printf("Usage: cc1541 -niFSsfeErbcwLlBxtdu45q image.[d64|g64|d71]\n\n"); + printf("-n diskname Disk name, default='DEFAULT'.\n"); + printf("-i id Disk ID, default='LODIS'.\n"); + printf("-F Next file first sector on a new track (default=3).\n"); +@@ -123,6 +124,8 @@ usage() + printf("-c Save next file cluster-optimized (d71 only).\n"); + printf("-w localname Write local file to disk, if filename is not set then the\n"); + printf(" local name is used. After file written, the filename is unset.\n"); ++ printf("-L fileindex Write loop file (an additional dir entry) to previous file given\n"); ++ printf(" in commandline (first file has index 1), set filename with -f.\n"); + printf("-l filename Write loop file (an additional dir entry) to existing file to\n"); + printf(" disk, set filename with -f.\n"); + printf("-B numblocks Write the given value as file size in blocks to the directory for\n"); +@@ -561,7 +564,7 @@ wipe_file(image_type type, unsigned char* image, unsigned int track, unsigned in + } + + static int +-find_file(image_type type, unsigned char* image, char* filename, unsigned char *track, unsigned char *sector, unsigned int *numblocks) ++find_file(image_type type, unsigned char* image, char* filename, unsigned char *track, unsigned char *sector, int *numblocks) + { + int direntryindex = 0; + +@@ -704,13 +707,6 @@ create_dir_entries(image_type type, unsigned char* image, imagefile* files, int + } + } while (!found); + +- if (shadowdirtrack > 0) { +- if (memcmp(image + dirblock + 1, image + shadowdirblock + 1, BLOCKSIZE - 1) != 0) { +- fprintf(stderr, "Dir vs shadow dir mismatch\n"); +- exit(-1); +- } +- } +- + /* set filetype */ + image[dirblock + entryOffset + FILETYPEOFFSET] = FILETYPE_PRG; + +@@ -1382,6 +1378,7 @@ main(int argc, char* argv[]) + int dir_sector_interleave = 3; + int numdirblocks = 2; + int nrSectorsShown = -1; ++ int loopindex; + char* filename = NULL; + int set_header = 0; + +@@ -1452,44 +1449,84 @@ main(int argc, char* argv[]) + files[nrFiles].mode = (files[nrFiles].mode & ~MODE_BEGINNING_SECTOR_MASK) | (i + 1); + } else if (strcmp(argv[j], "-c") == 0) { + files[nrFiles].mode |= MODE_SAVECLUSTEROPTIMIZED; +- } else if (strcmp(argv[j], "-w") == 0 || strcmp(argv[j], "-l") == 0) { ++ } else if (strcmp(argv[j], "-w") == 0) { + if (argc < j + 2) { +- printf("Error parsing argument for -w or -l\n"); ++ printf("Error parsing argument for -w\n"); + return -1; + } + struct stat st; +- int loop_file = !strcmp(argv[j], "-l"); +- if (loop_file) { +- files[nrFiles].mode |= MODE_LOOPFILE; +- } +- int file_exists = loop_file ? 1 /* will be checked later */ +- : (stat(argv[j + 1], &st) == 0); +- if (file_exists) { +- files[nrFiles].localname = argv[j + 1]; +- +- if (filename == NULL) { +- strncpy(files[nrFiles].filename, files[nrFiles].localname, FILENAMEMAXSIZE); +- ascii2petscii(files[nrFiles].filename); +- } else { +- evalhexescape(filename); +- strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); +- } +- +- files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; +- files[nrFiles].first_sector_new_track = first_sector_new_track; +- files[nrFiles].nrSectors = 0; +- files[nrFiles].nrSectorsShown = nrSectorsShown; +- nrFiles++; +- } else { ++ if (stat(argv[j + 1], &st) != 0) { + fprintf(stderr, "File '%s' (%d) not found\n", argv[j + 1], nrFiles + 1); + exit(-1); + } +- +- filename = NULL; ++ files[nrFiles].localname = argv[j + 1]; ++ if (filename == NULL) { ++ strncpy(files[nrFiles].filename, files[nrFiles].localname, FILENAMEMAXSIZE); ++ ascii2petscii(files[nrFiles].filename); ++ } else { ++ evalhexescape(filename); ++ strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); ++ } ++ files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; ++ files[nrFiles].first_sector_new_track = first_sector_new_track; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; + first_sector_new_track = default_first_sector_new_track; ++ filename = NULL; + sectorInterleave = 0; + nrSectorsShown = -1; ++ nrFiles++; + j++; ++ } else if (strcmp(argv[j], "-l") == 0) { ++ if (argc < j + 2) { ++ printf("Error parsing argument for -l\n"); ++ return -1; ++ } ++ if (filename == NULL) { ++ printf("Loop files require a filename set with -f\n"); ++ return -1; ++ } ++ files[nrFiles].mode |= MODE_LOOPFILE; ++ files[nrFiles].localname = argv[j + 1]; ++ evalhexescape(filename); ++ strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); ++ files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; ++ files[nrFiles].first_sector_new_track = first_sector_new_track; ++ first_sector_new_track = default_first_sector_new_track; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; ++ filename = NULL; ++ sectorInterleave = 0; ++ nrSectorsShown = -1; ++ nrFiles++; ++ j++; ++ } else if (strcmp(argv[j], "-L") == 0) { ++ if ((argc < j + 2) || !sscanf(argv[++j], "%d", &loopindex)) { ++ printf("Error parsing argument for -L\n"); ++ return -1; ++ } ++ if (loopindex >= nrFiles) { ++ printf("Argument must be lower than current file index for -L\n"); ++ return -1; ++ } ++ if (loopindex < 1) { ++ printf("Argument must be greater or equal to 1 for -L\n"); ++ return -1; ++ } ++ if (filename == NULL) { ++ printf("Loop files require a filename set with -f\n"); ++ return -1; ++ } ++ files[nrFiles].mode |= MODE_LOOPFILE; ++ evalhexescape(filename); ++ strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); ++ files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; ++ files[nrFiles].first_sector_new_track = first_sector_new_track; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; ++ first_sector_new_track = default_first_sector_new_track; ++ filename = NULL; ++ sectorInterleave = 0; ++ nrSectorsShown = -1; ++ nrFiles++; ++ j++; + } else if (strcmp(argv[j], "-x") == 0) { + dirtracksplit = 0; + } else if (strcmp(argv[j], "-t") == 0) { +diff --git a/test_cc1541/test_cc1541.c b/test_cc1541/test_cc1541.c +index 8941110..c859242 100644 +--- a/test_cc1541/test_cc1541.c ++++ b/test_cc1541/test_cc1541.c +@@ -547,9 +547,9 @@ main(int argc, char* argv[]) { + create_value_file("2.prg", 5 * 254, 2); + if (run_binary_cleanup(binary, "-d 23 -w 1.prg -w 2.prg", "image.d64", &image, &size) != NO_ERROR) { + printf("UNRESOLVED: %s\n", description); +- } else if (memcmp(&image[track_offset[17]+2], &image[track_offset[22]+2], 254) == 0 && +- memcmp(&image[track_offset[17] + 2] + 256, &image[track_offset[22] + 2] + 256, 254) == 0) +- { /* leave out next dir block t/s */ ++ } else if (memcmp(&image[track_offset[17] + 1], &image[track_offset[22] + 1], 255) == 0 && ++ memcmp(&image[track_offset[17] + 256 + 1], &image[track_offset[22] + 256 + 1], 255) == 0) ++ { /* leave out next dir block track */ + passed++; + } else { + printf("FAIL: %s\n", description); +@@ -600,7 +600,7 @@ main(int argc, char* argv[]) { + description = "Loop file should have DIR block size 258 for -B"; + test++; + create_value_file("1.prg", 39 * 254, 1); +- if (run_binary/*_cleanup*/(binary, "-w 1.prg -f LOOP.PRG -B 258 -l 1.PRG", "image.d64", &image, &size) != NO_ERROR) { ++ if (run_binary_cleanup(binary, "-w 1.prg -f LOOP.PRG -B 258 -l 1.PRG", "image.d64", &image, &size) != NO_ERROR) { + printf("UNRESOLVED: %s\n", description); + } else if (image[track_offset[17] + 256 + 32 + 30] == 2 && image[track_offset[17] + 256 + 32 + 31] == 1) { + passed++; +@@ -609,6 +609,20 @@ main(int argc, char* argv[]) { + } + remove("1.prg"); + ++ description = "File should have DIR block size 258 for -B, but actual block size in shadow dir for -d"; ++ test++; ++ create_value_file("1.prg", 3 * 254, 1); ++ if (run_binary/*_cleanup*/(binary, "-B 258 -d 23 -w 1.prg", "image_d23.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } ++ else if (image[track_offset[17] + 256 + 30] == 258%256 && image[track_offset[17] + 256 + 31] == 258/256 && image[track_offset[22] + 256 + 30] == 3 && image[track_offset[22] + 256 + 31] == 0) { ++ passed++; ++ } ++ else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); ++ + /* clean up */ + if (image != NULL) { + free(image); +-- +2.21.0 + diff --git a/0011-Resolve-strange-deviating-versions.patch b/0011-Resolve-strange-deviating-versions.patch new file mode 100644 index 0000000..ddfd06c --- /dev/null +++ b/0011-Resolve-strange-deviating-versions.patch @@ -0,0 +1,172 @@ +From e689c3ca9b9817a37b3d96c712d4074e29f8712d Mon Sep 17 00:00:00 2001 +From: Claus +Date: Mon, 4 Feb 2019 10:15:52 +0100 +Subject: [PATCH 11/30] Resolve strange deviating versions. + +--- + cc1541.c | 44 ++++++++++++++++++++++----------------- + test_cc1541/test_cc1541.c | 18 +++++++++++++--- + 2 files changed, 40 insertions(+), 22 deletions(-) + +diff --git a/cc1541.c b/cc1541.c +index 84a1df3..c8da428 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -124,8 +124,8 @@ usage() + printf("-c Save next file cluster-optimized (d71 only).\n"); + printf("-w localname Write local file to disk, if filename is not set then the\n"); + printf(" local name is used. After file written, the filename is unset.\n"); +- printf("-L fileindex Write loop file (an additional dir entry) to previous file given\n"); +- printf(" in commandline (first file has index 1), set filename with -f.\n"); ++ printf("-L fileindex Write loop file (an additional dir entry) to entry in directory\n"); ++ printf(" with given index (first file has index 1), set filename with -f.\n"); + printf("-l filename Write loop file (an additional dir entry) to existing file to\n"); + printf(" disk, set filename with -f.\n"); + printf("-B numblocks Write the given value as file size in blocks to the directory for\n"); +@@ -850,8 +850,20 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + imagefile *file = &(files[i]); + + if (file->mode & MODE_LOOPFILE) { +- /* find loopfile source files */ +- int direntryindex = find_file(type, image, file->localname, &track, §or, &file->nrSectors); ++ ++ ++ int direntryindex = file->loopindex; ++ track = files[file->loopindex].track; ++ sector = files[file->loopindex].sector; ++ file->nrSectors = files[file->loopindex].nrSectors; ++ ++ if (file->localname != NULL) { ++ /* find loopfile source file */ ++ direntryindex = find_file(type, image, file->localname, &track, §or, &file->nrSectors); ++ } else if(direntryindex >= file->direntryindex) { ++ fprintf(stderr, "Loop file index %d (%d) not found\n", file->loopindex, i + 1); ++ exit(-1); ++ } + if (direntryindex >= 0) { + file->track = track; + file->sector = sector; +@@ -879,7 +891,6 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + continue; + } else { + fprintf(stderr, "Loop source file '%s' (%d) not found\n", file->localname, i + 1); +- + exit(-1); + } + } +@@ -1459,7 +1470,7 @@ main(int argc, char* argv[]) + fprintf(stderr, "File '%s' (%d) not found\n", argv[j + 1], nrFiles + 1); + exit(-1); + } +- files[nrFiles].localname = argv[j + 1]; ++ files[nrFiles].localname = argv[j + 1]; + if (filename == NULL) { + strncpy(files[nrFiles].filename, files[nrFiles].localname, FILENAMEMAXSIZE); + ascii2petscii(files[nrFiles].filename); +@@ -1469,7 +1480,7 @@ main(int argc, char* argv[]) + } + files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; + files[nrFiles].first_sector_new_track = first_sector_new_track; +- files[nrFiles].nrSectorsShown = nrSectorsShown; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; + first_sector_new_track = default_first_sector_new_track; + filename = NULL; + sectorInterleave = 0; +@@ -1486,27 +1497,23 @@ main(int argc, char* argv[]) + return -1; + } + files[nrFiles].mode |= MODE_LOOPFILE; +- files[nrFiles].localname = argv[j + 1]; ++ files[nrFiles].localname = argv[j + 1]; + evalhexescape(filename); + strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); + files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; + files[nrFiles].first_sector_new_track = first_sector_new_track; + first_sector_new_track = default_first_sector_new_track; +- files[nrFiles].nrSectorsShown = nrSectorsShown; +- filename = NULL; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; ++ filename = NULL; + sectorInterleave = 0; + nrSectorsShown = -1; + nrFiles++; +- j++; ++ j++; + } else if (strcmp(argv[j], "-L") == 0) { + if ((argc < j + 2) || !sscanf(argv[++j], "%d", &loopindex)) { + printf("Error parsing argument for -L\n"); + return -1; + } +- if (loopindex >= nrFiles) { +- printf("Argument must be lower than current file index for -L\n"); +- return -1; +- } + if (loopindex < 1) { + printf("Argument must be greater or equal to 1 for -L\n"); + return -1; +@@ -1517,16 +1524,15 @@ main(int argc, char* argv[]) + } + files[nrFiles].mode |= MODE_LOOPFILE; + evalhexescape(filename); +- strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); ++ strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); + files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; + files[nrFiles].first_sector_new_track = first_sector_new_track; +- files[nrFiles].nrSectorsShown = nrSectorsShown; +- first_sector_new_track = default_first_sector_new_track; ++ files[nrFiles].nrSectorsShown = nrSectorsShown; ++ first_sector_new_track = default_first_sector_new_track; + filename = NULL; + sectorInterleave = 0; + nrSectorsShown = -1; + nrFiles++; +- j++; + } else if (strcmp(argv[j], "-x") == 0) { + dirtracksplit = 0; + } else if (strcmp(argv[j], "-t") == 0) { +diff --git a/test_cc1541/test_cc1541.c b/test_cc1541/test_cc1541.c +index c859242..bbedf5f 100644 +--- a/test_cc1541/test_cc1541.c ++++ b/test_cc1541/test_cc1541.c +@@ -596,7 +596,7 @@ main(int argc, char* argv[]) { + printf("FAIL: %s\n", description); + } + remove("1.prg"); +- ++ + description = "Loop file should have DIR block size 258 for -B"; + test++; + create_value_file("1.prg", 39 * 254, 1); +@@ -612,7 +612,7 @@ main(int argc, char* argv[]) { + description = "File should have DIR block size 258 for -B, but actual block size in shadow dir for -d"; + test++; + create_value_file("1.prg", 3 * 254, 1); +- if (run_binary/*_cleanup*/(binary, "-B 258 -d 23 -w 1.prg", "image_d23.d64", &image, &size) != NO_ERROR) { ++ if (run_binary_cleanup(binary, "-B 258 -d 23 -w 1.prg", "image.d64", &image, &size) != NO_ERROR) { + printf("UNRESOLVED: %s\n", description); + } + else if (image[track_offset[17] + 256 + 30] == 258%256 && image[track_offset[17] + 256 + 31] == 258/256 && image[track_offset[22] + 256 + 30] == 3 && image[track_offset[22] + 256 + 31] == 0) { +@@ -622,7 +622,19 @@ main(int argc, char* argv[]) { + printf("FAIL: %s\n", description); + } + remove("1.prg"); +- ++ ++ description = "Loop file should have actual DIR block size for -L"; ++ test++; ++ create_value_file("1.prg", 258 * 254, 1); ++ if (run_binary_cleanup(binary, "-w 1.prg -f LOOP.PRG -L 1", "image.d64", &image, &size) != NO_ERROR) { ++ printf("UNRESOLVED: %s\n", description); ++ } else if (image[track_offset[17] + 256 + 32 + 30] == 2 && image[track_offset[17] + 256 + 32 + 31] == 1) { ++ passed++; ++ } else { ++ printf("FAIL: %s\n", description); ++ } ++ remove("1.prg"); ++ + /* clean up */ + if (image != NULL) { + free(image); +-- +2.21.0 + diff --git a/0012-Fix-for-L-switch-used-always-index-0-and-also-did-no.patch b/0012-Fix-for-L-switch-used-always-index-0-and-also-did-no.patch new file mode 100644 index 0000000..1b7e3c7 --- /dev/null +++ b/0012-Fix-for-L-switch-used-always-index-0-and-also-did-no.patch @@ -0,0 +1,87 @@ +From a4752748ad7a82e42b6187161dce0baf35f5e2bb Mon Sep 17 00:00:00 2001 +From: Claus +Date: Mon, 4 Feb 2019 13:44:46 +0100 +Subject: [PATCH 12/30] Fix for -L switch: used always index 0 and also did not + check for maximum index (issue #7) + +--- + cc1541.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 46 insertions(+), 3 deletions(-) + +diff --git a/cc1541.c b/cc1541.c +index c8da428..f572e87 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -606,6 +606,41 @@ find_file(image_type type, unsigned char* image, char* filename, unsigned char * + return -1; + } + ++/* sets image offset to the next DIR entry, returns 0 when the DIR end was reached */ ++static int ++next_dir_entry(image_type type, unsigned char* image, int *offset) ++{ ++ if (*offset % BLOCKSIZE == 7 * DIRENTRYSIZE) { ++ /* last entry in sector */ ++ int sector_offset = (*offset / BLOCKSIZE) * BLOCKSIZE; ++ int track = image[sector_offset]; ++ if (track == 0) { ++ /* this was the last DIR sector */ ++ return 0; ++ } else { ++ /* follow the t/s link */ ++ int sector = image[sector_offset + 1]; ++ *offset = linear_sector(type, track, sector) * BLOCKSIZE; ++ } ++ } else { ++ *offset += DIRENTRYSIZE; ++ } ++ return 1; ++} ++ ++static int ++num_dir_entries(image_type type, unsigned char* image) ++{ ++ int entries = 0; ++ int offset = linear_sector(type, DIRTRACK, 1) * BLOCKSIZE; ++ do { ++ if (image[offset + 2] != 0) { ++ entries++; ++ } ++ } while (next_dir_entry(type, image, &offset)); ++ return entries; ++} ++ + static void + create_dir_entries(image_type type, unsigned char* image, imagefile* files, int num_files, int dir_sector_interleave, unsigned int shadowdirtrack) + { +@@ -860,9 +895,16 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + if (file->localname != NULL) { + /* find loopfile source file */ + direntryindex = find_file(type, image, file->localname, &track, §or, &file->nrSectors); +- } else if(direntryindex >= file->direntryindex) { +- fprintf(stderr, "Loop file index %d (%d) not found\n", file->loopindex, i + 1); +- exit(-1); ++ } else { ++ if (direntryindex == file->direntryindex) { ++ fprintf(stderr, "Loop file index %d cannot refer to itself\n", file->loopindex, i + 1); ++ exit(-1); ++ } ++ int numfiles = num_dir_entries(type, image); ++ if (direntryindex >= numfiles) { ++ fprintf(stderr, "Loop file index %d is higher than number of files %d\n", file->loopindex, numfiles); ++ exit(-1); ++ } + } + if (direntryindex >= 0) { + file->track = track; +@@ -1523,6 +1565,7 @@ main(int argc, char* argv[]) + return -1; + } + files[nrFiles].mode |= MODE_LOOPFILE; ++ files[nrFiles].loopindex = loopindex - 1; + evalhexescape(filename); + strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); + files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; +-- +2.21.0 + diff --git a/0014-Using-variable-for-compiler-to-prepare-for-MinGW-bui.patch b/0014-Using-variable-for-compiler-to-prepare-for-MinGW-bui.patch new file mode 100644 index 0000000..6375553 --- /dev/null +++ b/0014-Using-variable-for-compiler-to-prepare-for-MinGW-bui.patch @@ -0,0 +1,43 @@ +From fe0799e9db535f210e368feb8c9ca849643c96d9 Mon Sep 17 00:00:00 2001 +From: PTV_Claus +Date: Mon, 4 Feb 2019 20:51:07 +0100 +Subject: [PATCH 14/30] Using variable for compiler to prepare for MinGW build + +--- + Makefile | 4 ++-- + test_cc1541/Makefile | 4 ++-- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/Makefile b/Makefile +index 7776525..ff1d2b3 100644 +--- a/Makefile ++++ b/Makefile +@@ -1,8 +1,8 @@ + cc1541: cc1541.o +- gcc -o $@ $^ ++ $(CC) -o $@ $^ + + %.o: %.c +- gcc -std=c99 -c $< ++ $(CC) -std=c99 -c $< + + clean: + rm -rf *.o cc1541 *~ +diff --git a/test_cc1541/Makefile b/test_cc1541/Makefile +index 04c3680..20a6fe4 100644 +--- a/test_cc1541/Makefile ++++ b/test_cc1541/Makefile +@@ -1,8 +1,8 @@ + test_cc1541: test_cc1541.o +- gcc -o $@ $^ ++ $(CC) -o $@ $^ + + %.o: %.c +- gcc -std=c99 -c $< ++ $(CC) -std=c99 -c $< + + test: test_cc1541 + ./test_cc1541 ../cc1541 +-- +2.21.0 + diff --git a/0018-gitignore-Add-basic-ignore-rules-for-git.patch b/0018-gitignore-Add-basic-ignore-rules-for-git.patch new file mode 100644 index 0000000..2f82f14 --- /dev/null +++ b/0018-gitignore-Add-basic-ignore-rules-for-git.patch @@ -0,0 +1,30 @@ +From ec2afbbf5355864fad9dce582984873473e657b1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:40:17 +0200 +Subject: [PATCH 18/30] gitignore: Add basic ignore rules for git. + +--- + .gitignore | 11 +++++++++++ + 1 file changed, 11 insertions(+) + create mode 100644 .gitignore + +diff --git a/.gitignore b/.gitignore +new file mode 100644 +index 0000000..331ebd7 +--- /dev/null ++++ b/.gitignore +@@ -0,0 +1,11 @@ ++# Backup files ++*~ ++ ++# Compiler output. ++*.o ++ ++# Compiled applications. ++/cc1541 ++/cc1541.exe ++test_cc1541/test_cc1541 ++test_cc1541/test_cc1541.exe +-- +2.21.0 + diff --git a/0019-LICENSE.txt-Add-license-file-for-distribution-packag.patch b/0019-LICENSE.txt-Add-license-file-for-distribution-packag.patch new file mode 100644 index 0000000..9cf3380 --- /dev/null +++ b/0019-LICENSE.txt-Add-license-file-for-distribution-packag.patch @@ -0,0 +1,39 @@ +From d951bdaa1741621409eaa31b0bc1ff73ea7e87bc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 17:10:18 +0200 +Subject: [PATCH 19/30] LICENSE.txt: Add license file for distribution + packaging. + +--- + LICENSE.txt | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + create mode 100644 LICENSE.txt + +diff --git a/LICENSE.txt b/LICENSE.txt +new file mode 100644 +index 0000000..62d83f0 +--- /dev/null ++++ b/LICENSE.txt +@@ -0,0 +1,19 @@ ++Copyright (c) 2008-2018 JackAsser, Krill, Claus ++ ++Permission is hereby granted, free of charge, to any person obtaining a copy ++of this software and associated documentation files (the "Software"), to deal ++in the Software without restriction, including without limitation the rights ++to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++copies of the Software, and to permit persons to whom the Software is ++furnished to do so, subject to the following conditions: ++ ++The above copyright notice and this permission notice shall be included in ++all copies or substantial portions of the Software. ++ ++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ++AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ++SOFTWARE. +-- +2.21.0 + diff --git a/0020-Makefile-Allow-user-specified-compiler-flags-to-be-u.patch b/0020-Makefile-Allow-user-specified-compiler-flags-to-be-u.patch new file mode 100644 index 0000000..abbe633 --- /dev/null +++ b/0020-Makefile-Allow-user-specified-compiler-flags-to-be-u.patch @@ -0,0 +1,44 @@ +From f991450cd6a377641047bdecc8a9708396aa1b35 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:19:17 +0200 +Subject: [PATCH 20/30] Makefile: Allow user-specified compiler flags to be + used. + +--- + Makefile | 4 ++-- + test_cc1541/Makefile | 4 ++-- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/Makefile b/Makefile +index ff1d2b3..4208fe2 100644 +--- a/Makefile ++++ b/Makefile +@@ -1,8 +1,8 @@ + cc1541: cc1541.o +- $(CC) -o $@ $^ ++ $(CC) -o $@ $^ $(LDFLAGS) + + %.o: %.c +- $(CC) -std=c99 -c $< ++ $(CC) -std=c99 $(CFLAGS) -c $< + + clean: + rm -rf *.o cc1541 *~ +diff --git a/test_cc1541/Makefile b/test_cc1541/Makefile +index 20a6fe4..0f97d7e 100644 +--- a/test_cc1541/Makefile ++++ b/test_cc1541/Makefile +@@ -1,8 +1,8 @@ + test_cc1541: test_cc1541.o +- $(CC) -o $@ $^ ++ $(CC) -o $@ $^ $(LDFLAGS) + + %.o: %.c +- $(CC) -std=c99 -c $< ++ $(CC) -std=c99 $(CFLAGS) -c $< + + test: test_cc1541 + ./test_cc1541 ../cc1541 +-- +2.21.0 + diff --git a/0021-Makefile-Run-top-level-clean-target-recursively.patch b/0021-Makefile-Run-top-level-clean-target-recursively.patch new file mode 100644 index 0000000..10e874f --- /dev/null +++ b/0021-Makefile-Run-top-level-clean-target-recursively.patch @@ -0,0 +1,21 @@ +From 283e221c828026e3b5852c455f3b45bfa0888ddc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:23:39 +0200 +Subject: [PATCH 21/30] Makefile: Run top-level clean target recursively. + +--- + Makefile | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Makefile b/Makefile +index 4208fe2..d629792 100644 +--- a/Makefile ++++ b/Makefile +@@ -6,3 +6,4 @@ cc1541: cc1541.o + + clean: + rm -rf *.o cc1541 *~ ++ $(MAKE) -C test_cc1541/ clean +-- +2.21.0 + diff --git a/0022-Makefile-Add-top-level-check-test-target.patch b/0022-Makefile-Add-top-level-check-test-target.patch new file mode 100644 index 0000000..5c46ff0 --- /dev/null +++ b/0022-Makefile-Add-top-level-check-test-target.patch @@ -0,0 +1,28 @@ +From 2af1f1365b5caa02e304be08054fe6a9c527e1ae Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:24:19 +0200 +Subject: [PATCH 22/30] Makefile: Add top-level check / test target. + +--- + Makefile | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/Makefile b/Makefile +index d629792..4f1e13e 100644 +--- a/Makefile ++++ b/Makefile +@@ -4,6 +4,11 @@ cc1541: cc1541.o + %.o: %.c + $(CC) -std=c99 $(CFLAGS) -c $< + ++test: cc1541 ++ $(MAKE) -C test_cc1541/ test ++ ++check: test ++ + clean: + rm -rf *.o cc1541 *~ + $(MAKE) -C test_cc1541/ clean +-- +2.21.0 + diff --git a/0023-test_cc1541-Makefile-Add-check-target.patch b/0023-test_cc1541-Makefile-Add-check-target.patch new file mode 100644 index 0000000..2f5ff5b --- /dev/null +++ b/0023-test_cc1541-Makefile-Add-check-target.patch @@ -0,0 +1,24 @@ +From 9725a90b1865c82d0627a052767625ff2562fba3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:25:58 +0200 +Subject: [PATCH 23/30] test_cc1541/Makefile: Add check target. + +--- + test_cc1541/Makefile | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/test_cc1541/Makefile b/test_cc1541/Makefile +index 0f97d7e..59f3f8d 100644 +--- a/test_cc1541/Makefile ++++ b/test_cc1541/Makefile +@@ -7,5 +7,7 @@ test_cc1541: test_cc1541.o + test: test_cc1541 + ./test_cc1541 ../cc1541 + ++check: test ++ + clean: + rm -rf *.o test_cc1541 *~ +-- +2.21.0 + diff --git a/0024-cc1541-Fix-Wmaybe-uninitialized.patch b/0024-cc1541-Fix-Wmaybe-uninitialized.patch new file mode 100644 index 0000000..d0ffb4d --- /dev/null +++ b/0024-cc1541-Fix-Wmaybe-uninitialized.patch @@ -0,0 +1,25 @@ +From 1149abe4e6a06253a7813063d49fa074ee0d0ae6 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:31:47 +0200 +Subject: [PATCH 24/30] cc1541: Fix Wmaybe-uninitialized. + +--- + cc1541.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/cc1541.c b/cc1541.c +index f572e87..43e6fac 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -658,7 +658,7 @@ create_dir_entries(image_type type, unsigned char* image, imagefile* files, int + + int dirsector = 1; + int dirblock; +- int shadowdirblock; ++ int shadowdirblock = 0; + int entryOffset; + int found = 0; + do { +-- +2.21.0 + diff --git a/0025-cc1541-Fix-Wunused-result.patch b/0025-cc1541-Fix-Wunused-result.patch new file mode 100644 index 0000000..11ca442 --- /dev/null +++ b/0025-cc1541-Fix-Wunused-result.patch @@ -0,0 +1,28 @@ +From a03d5a8fbd54bd8523330df33f94a78f1f2f4e1c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:35:34 +0200 +Subject: [PATCH 25/30] cc1541: Fix Wunused-result. + +--- + cc1541.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/cc1541.c b/cc1541.c +index 43e6fac..811246d 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -952,7 +952,10 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + printf("could not open file %s for reading\n", file->localname); + exit(-1); + } +- fread(filedata, fileSize, 1, f); ++ if (fread(filedata, fileSize, 1, f) != 1) { ++ fprintf(stderr, "ERROR: Unexpected filesize when reading %s\n", file->localname); ++ exit(-1); ++ } + fclose(f); + + if ((file->mode & MODE_MIN_TRACK_MASK) > 0) { +-- +2.21.0 + diff --git a/0026-cc1541-Fix-Wformat-extra-args.patch b/0026-cc1541-Fix-Wformat-extra-args.patch new file mode 100644 index 0000000..1c24a6d --- /dev/null +++ b/0026-cc1541-Fix-Wformat-extra-args.patch @@ -0,0 +1,25 @@ +From eb8c8dfe8c9a6607f8adde4a70611599792db921 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:39:07 +0200 +Subject: [PATCH 26/30] cc1541: Fix Wformat-extra-args. + +--- + cc1541.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/cc1541.c b/cc1541.c +index 811246d..0709297 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -897,7 +897,7 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + direntryindex = find_file(type, image, file->localname, &track, §or, &file->nrSectors); + } else { + if (direntryindex == file->direntryindex) { +- fprintf(stderr, "Loop file index %d cannot refer to itself\n", file->loopindex, i + 1); ++ fprintf(stderr, "Loop file index %d cannot refer to itself\n", file->loopindex); + exit(-1); + } + int numfiles = num_dir_entries(type, image); +-- +2.21.0 + diff --git a/0027-cc1541-Fix-Wformat.patch b/0027-cc1541-Fix-Wformat.patch new file mode 100644 index 0000000..2e51364 --- /dev/null +++ b/0027-cc1541-Fix-Wformat.patch @@ -0,0 +1,25 @@ +From dc8ca51d0938ce47e65bbfcba1e8a47f7a6bd9a9 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:46:32 +0200 +Subject: [PATCH 27/30] cc1541: Fix Wformat. + +--- + cc1541.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/cc1541.c b/cc1541.c +index 0709297..db1451e 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -1584,7 +1584,7 @@ main(int argc, char* argv[]) + } else if (strcmp(argv[j], "-t") == 0) { + usedirtrack = 1; + } else if (strcmp(argv[j], "-d") == 0) { +- if ((argc < j + 2) || !sscanf(argv[++j], "%d", &shadowdirtrack)) { ++ if ((argc < j + 2) || !sscanf(argv[++j], "%u", &shadowdirtrack)) { + printf("Error parsing argument for -d\n"); + return -1; + } +-- +2.21.0 + diff --git a/0028-cc1541-Fix-Wtype-limits.patch b/0028-cc1541-Fix-Wtype-limits.patch new file mode 100644 index 0000000..2887667 --- /dev/null +++ b/0028-cc1541-Fix-Wtype-limits.patch @@ -0,0 +1,27 @@ +From b0f173e20288e300e02d0c99f563ac138e1d58de Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:51:52 +0200 +Subject: [PATCH 28/30] cc1541: Fix Wtype-limits. + +--- + cc1541.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/cc1541.c b/cc1541.c +index db1451e..a07e2ab 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -1113,9 +1113,7 @@ write_files(image_type type, unsigned char* image, imagefile* files, int num_fil + } else { + sector = file->first_sector_new_track; + } +- if (sector < 0) { +- sector += num_sectors_table[prev_track - 1]; +- } ++ sector += num_sectors_table[prev_track - 1]; + sector %= num_sectors_table[prev_track - 1]; + + if ((!usedirtrack) +-- +2.21.0 + diff --git a/0029-test_cc1541-Fix-Wunused-result.patch b/0029-test_cc1541-Fix-Wunused-result.patch new file mode 100644 index 0000000..86ed4cd --- /dev/null +++ b/0029-test_cc1541-Fix-Wunused-result.patch @@ -0,0 +1,28 @@ +From 39886b117cf1cea7dba0cb52b67837f24655e370 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 16:36:34 +0200 +Subject: [PATCH 29/30] test_cc1541: Fix Wunused-result. + +--- + test_cc1541/test_cc1541.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/test_cc1541/test_cc1541.c b/test_cc1541/test_cc1541.c +index bbedf5f..38f310a 100644 +--- a/test_cc1541/test_cc1541.c ++++ b/test_cc1541/test_cc1541.c +@@ -94,7 +94,10 @@ run_binary(const char* binary, const char* options, const char* image_name, char + if (f == NULL) { + return ERROR_NO_OUTPUT; + } +- fread(*image, *size, 1, f); ++ if (fread(*image, *size, 1, f) != 1) { ++ fprintf(stderr, "ERROR: Unexpected filesize when reading %s\n", image_name); ++ return ERROR_NO_OUTPUT; ++ } + fclose(f); + + return NO_ERROR; +-- +2.21.0 + diff --git a/0030-cc1541-Fix-segfault-with-GCC-8-and-O2.patch b/0030-cc1541-Fix-segfault-with-GCC-8-and-O2.patch new file mode 100644 index 0000000..1a13e8f --- /dev/null +++ b/0030-cc1541-Fix-segfault-with-GCC-8-and-O2.patch @@ -0,0 +1,33 @@ +From befd13284bf2c46fd00b7406855dbe062cb5d1aa Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= +Date: Fri, 21 Jun 2019 20:18:10 +0200 +Subject: [PATCH 30/30] cc1541: Fix segfault with GCC 8 and -O2. + +--- + cc1541.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/cc1541.c b/cc1541.c +index a07e2ab..66e6397 100644 +--- a/cc1541.c ++++ b/cc1541.c +@@ -62,7 +62,7 @@ + typedef struct + { + char* localname; +- char filename[FILENAMEMAXSIZE]; ++ char filename[FILENAMEMAXSIZE + 1]; + int loopindex; + int direntryindex; + int direntrysector; +@@ -1521,6 +1521,7 @@ main(int argc, char* argv[]) + evalhexescape(filename); + strncpy(files[nrFiles].filename, filename, FILENAMEMAXSIZE); + } ++ files[nrFiles].filename[FILENAMEMAXSIZE] = '\0'; + files[nrFiles].sectorInterleave = sectorInterleave ? sectorInterleave : defaultSectorInterleave; + files[nrFiles].first_sector_new_track = first_sector_new_track; + files[nrFiles].nrSectorsShown = nrSectorsShown; +-- +2.21.0 + diff --git a/cc1541.spec b/cc1541.spec new file mode 100644 index 0000000..ed036b3 --- /dev/null +++ b/cc1541.spec @@ -0,0 +1,89 @@ +# To reduce boilerplate. +%global make_cmd %make_build CC=%{__cc} \\\ +CFLAGS="%{build_cflags}" LDFLAGS="%{build_ldflags}" + +# Needed meta-data from git repo. +%global owner PTV_Claus +%global git_sha 69a35800d67cab71701e625cac56bfa62dc9c984 +%global sha_short %(c=%{git_sha}; echo ${c:0:12}) + + +Name: cc1541 +Version: 2.0 +Release: 1%{?dist} +Summary: Tool for creating Commodore 1541 Floppy disk images in D64, G64 or D71 format + +License: MIT +URL: https://bitbucket.org/%{owner}/%{name} +Source0: %{url}/get/%{version}.tar.bz2#/%{name}-%{version}.tar.bz2 + +BuildRequires: gcc +BuildRequires: make + +# Patches from upstream. +Patch0001: 0001-Added-B-switch-to-specify-DIR-block-size.-Also-made-.patch +Patch0002: 0002-Tabs-to-spaces.patch +Patch0003: 0004-Add-make-target-to-run-tests.patch +Patch0004: 0006-Added-L-switch-to-reference-loop-files-by-index.patch +Patch0005: 0011-Resolve-strange-deviating-versions.patch +Patch0006: 0012-Fix-for-L-switch-used-always-index-0-and-also-did-no.patch +Patch0007: 0014-Using-variable-for-compiler-to-prepare-for-MinGW-bui.patch +Patch0008: 0018-gitignore-Add-basic-ignore-rules-for-git.patch +Patch0009: 0019-LICENSE.txt-Add-license-file-for-distribution-packag.patch +Patch0010: 0020-Makefile-Allow-user-specified-compiler-flags-to-be-u.patch +Patch0011: 0021-Makefile-Run-top-level-clean-target-recursively.patch +Patch0012: 0022-Makefile-Add-top-level-check-test-target.patch +Patch0013: 0023-test_cc1541-Makefile-Add-check-target.patch +Patch0014: 0024-cc1541-Fix-Wmaybe-uninitialized.patch +Patch0015: 0025-cc1541-Fix-Wunused-result.patch +Patch0016: 0026-cc1541-Fix-Wformat-extra-args.patch +Patch0017: 0027-cc1541-Fix-Wformat.patch +Patch0018: 0028-cc1541-Fix-Wtype-limits.patch +Patch0019: 0029-test_cc1541-Fix-Wunused-result.patch +Patch0020: 0030-cc1541-Fix-segfault-with-GCC-8-and-O2.patch + +%description +This is %{name} v%{version}, a tool for creating Commodore 1541 +Floppy disk images in D64, G64 or D71 format with custom sector +interleaving etc. Also supports extended tracks 35-40 using +either SPEED DOS or DOLPHIN DOS BAM-formatting. + + +%prep +%autosetup -p 1 -n %{owner}-%{name}-%{sha_short} + +# Remove pre-built binaries. +%{__rm} -fr rel/ + + +%build +%{make_cmd} + + +%install +# No install rule in Makefile. +%{__install} -Dpm 0755 %{name} %{buildroot}%{_bindir}/%{name} + + +%check +%{make_cmd} check + + +%files +%license LICENSE.txt +%doc README.md +%{_bindir}/%{name} + + +%changelog +* Fri Jun 21 2019 Björn Esser - 2.0-1 +- Initial import (#1722942) + +* Fri Jun 21 2019 Björn Esser - 2.0-0.3 +- Upstream PR has been merged + +* Fri Jun 21 2019 Björn Esser - 2.0-0.2 +- Remove pre-built binaries from build-tree during %%prep. + +* Fri Jun 21 2019 Björn Esser - 2.0-0.1 +- Initial rpm release (#1722942) diff --git a/sources b/sources new file mode 100644 index 0000000..16cdc0f --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (cc1541-2.0.tar.bz2) = c6598d1ae0c021ff0a02a8b89b671f6ef94e352ca3a00213cfdb567b8a5a2091a4331cdce0fb33e0c002f18bf5501c503b1c6d0a20d18390176feb21f1ab4455