From f4bc587d0ab4b75466d4f031939b76a7bb46e6e3 Mon Sep 17 00:00:00 2001 From: Anachronaut Date: Fri, 21 Aug 2026 14:54:51 -0400 Subject: [PATCH] The C assembler names its output for the format, not always .bin It always wrote .bin, whatever it had built. So assembling a loadable program without -o produced Say.bin containing SBEX - a boot image name on a file the machine cannot boot, in a repository whose whole convention is that a .bin is started from and a .sbx is loaded. Successfully wrote SplitBit boot image to "hello.bin". Successfully wrote SplitBit loadable program to "Say.sbx". programIsLoadable() already existed and is already what decides which writer runs; the name now asks it too. Nothing in the build depended on the old behaviour, because everything that assembles anything passes -o. THE ASSEMBLER THAT RUNS ON SPLITBIT ALREADY DID IT THIS WAY. Two assemblers naming their output differently from the same source is exactly the kind of difference that wastes an afternoon, and the newer one was right. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW --- README.md | 2 +- Source/Assembler/Assembler.c | 22 +++++++++++++++------- SplitBit Assembler Manual.md | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) 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. |