diff --git a/README.md b/README.md index 9a50128..ad8bd44 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ If the CPU reads a byte that is not an instruction, it goes to the fault handler | `-M ` | Write out which source files the output depends on, as a make rule. | | `-h`, `--help` | Show help and usage information. | -Without `-o` the output takes the source file's name with a `.bin` extension, in the directory you called the assembler from. Included files are looked for beside the file that includes them, and then along the directories given with `-I`. +Without `-o` the output takes the source file's name, in the directory you called the assembler from, with the extension the format asks for: `.bin` for a boot image and `.sbx` for a loadable program. Included files are looked for beside the file that includes them, and then along the directories given with `-I`. ## Managing Disks: SplitDisk diff --git a/Source/Assembler/Assembler.c b/Source/Assembler/Assembler.c index 2f13c06..9753ea0 100644 --- a/Source/Assembler/Assembler.c +++ b/Source/Assembler/Assembler.c @@ -20,7 +20,16 @@ int dataLength = 0; uint8_t Program[0xFFFF], Data[0xFFFF]; +// What an assembled file is called when nobody said. The extension follows the FORMAT +// rather than being always .bin: a boot image is what the machine starts from and a +// loadable program is what a running system loads, and this repository has called them +// .bin and .sbx apart for long enough that a .bin holding SBEX is a small lie. +// +// The assembler that runs on SplitBit already chose this way. Two assemblers naming their +// output differently from the same source is exactly the sort of difference that wastes an +// afternoon. char* createOutputFileName(const char *inputFilePath) { + const char *extension = programIsLoadable() ? ".sbx" : ".bin"; // Make a copy of inputFilePath, since basename may modify it char *pathCopy = strdup(inputFilePath); if (!pathCopy) { @@ -37,26 +46,25 @@ char* createOutputFileName(const char *inputFilePath) { // Check if the filename ends with ".asm" char *outputFileName; if (len > 4 && strcmp(fileName + len - 4, ".asm") == 0) { - // Allocate memory for the new file name with ".bin" extension - outputFileName = malloc(len - 4 + 5); // Remove ".asm" (4 chars) and add ".bin" (4 chars + null terminator) + // Remove ".asm" (4 chars) and add the extension (4 chars plus a null terminator). + outputFileName = malloc(len - 4 + 5); if (!outputFileName) { fprintf(stderr, "Error: Memory allocation failed for output file name.\n"); free(pathCopy); exit(1); } - // Copy the filename up to ".asm" and add ".bin" strncpy(outputFileName, fileName, len - 4); - strcpy(outputFileName + len - 4, ".bin"); + strcpy(outputFileName + len - 4, extension); } else { - // If there's no ".asm" extension, add ".bin" to the full filename - outputFileName = malloc(len + 5); // Original length + ".bin" + null terminator + // No ".asm" to replace, so the extension goes on the end of the whole name. + outputFileName = malloc(len + 5); if (!outputFileName) { fprintf(stderr, "Error: Memory allocation failed for output file name.\n"); free(pathCopy); exit(1); } strcpy(outputFileName, fileName); - strcat(outputFileName, ".bin"); + strcat(outputFileName, extension); } free(pathCopy); // Free the temporary path copy diff --git a/SplitBit Assembler Manual.md b/SplitBit Assembler Manual.md index f4fca3e..382093b 100644 --- a/SplitBit Assembler Manual.md +++ b/SplitBit Assembler Manual.md @@ -417,7 +417,7 @@ Assembler [options] | Option | Meaning | | -- | -- | -| -o, --output \ | Write the output to this path. Without it, the output is named after the source file, with a .bin extension, in the directory the assembler was run from. | +| -o, --output \ | Write the output to this path. Without it, the output is named after the source file, in the directory the assembler was run from, taking .bin if it is a boot image and .sbx if it is a loadable program. | | -I, --include \ | Look in this directory for included files. May be given more than once, and the directories are searched in the order given. | | -M, --depend \ | Write out which source files went into the output, as a make rule. | | -h, --help | Print the options and stop. |