Blob Blame History Raw
From fe384f8b1e6b36796219838784ed1c00ff28fc5b Mon Sep 17 00:00:00 2001
From: Claus <claus@protovision.games>
Date: Thu, 9 Feb 2023 17:07:43 +0100
Subject: [PATCH 23/23] Adding tests for the bugfix related to allocation for
 mixed transwarp/non-transwarp files and -r
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Björn Esser <besser82@fedoraproject.org>
---
 cc1541.c      |  2 +-
 test_cc1541.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/cc1541.c b/cc1541.c
index c83fa26..71a566a 100644
--- a/cc1541.c
+++ b/cc1541.c
@@ -2977,7 +2977,7 @@ write_files(image_type type, unsigned char *image, imagefile *files, int num_fil
 
     for (int i = 0; i < num_files; i++) {
         imagefile *file = files + i;
-        unsigned char track = 1; /* reset start search track for every file, as Transwarp files are allocated differently */
+        unsigned char track = 1; /* reset start search track for every file, as Transwarp and -r might leave free blocks below */
 
         if (type == IMAGE_D81) {
             file->sectorInterleave = 1; /* caught in command line parsing anyway, but does not hurt */
diff --git a/test_cc1541.c b/test_cc1541.c
index 60e4671..bda1b8d 100644
--- a/test_cc1541.c
+++ b/test_cc1541.c
@@ -646,6 +646,20 @@ main(int argc, char* argv[])
     printf("%0*d:  %s:  %s\n", test_pad, test, result_str[result], description);
     remove("1.prg");
 
+    description = "Next file should be allocated in track 0 after -r";
+    ++test;
+    create_value_file("1.prg", 254, 1);
+    if (run_binary_cleanup(binary, "-r 13 -f 1 -w 1.prg -f 2 -w 1.prg", "image.d64", &image, &size, false) != NO_ERROR) {
+        result = TEST_UNRESOLVED;
+    } else if (block_is_filled(image, track_offset[0] / 256 + 10, 1)) {
+        result = TEST_PASS;
+        ++passed;
+    } else {
+        result = TEST_FAIL;
+    }
+    printf("%0*d:  %s:  %s\n", test_pad, test, result_str[result], description);
+    remove("1.prg");
+
     description = "File should start on sector 14 for -b";
     ++test;
     create_value_file("1.prg", 254, 1);
@@ -1925,6 +1939,20 @@ main(int argc, char* argv[])
     printf("%0*d:  %s:  %s\n", test_pad, test, result_str[result], description);
     remove("1.prg");
 
+    description = "Standard file should be allocated in track 0 for transwarp image";
+    ++test;
+    create_value_file("1.prg", 1 * 254, 1);
+    if (run_binary_cleanup(binary, "-b 0 -f file1 -w 1.prg -w \"transwarp v0.86.prg\"", "image.d64", &image, &size, false) != NO_ERROR) {
+        result = TEST_UNRESOLVED;
+    } else if (block_is_filled(image, track_offset[0] / 256 + 0, 1)) {
+        result = TEST_PASS;
+        ++passed;
+    } else {
+        result = TEST_FAIL;
+    }
+    printf("%0*d:  %s:  %s\n", test_pad, test, result_str[result], description);
+    remove("1.prg");
+
     description = "Sector on new track should not be limited to number of sectors on old track";
     ++test;
     create_value_file("1.prg", 254 * 20, 1); /* track 24 has 19 blocks, track 25 only 18 */
-- 
2.39.1