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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
b6004bdcde
commit
f4bc587d0a
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user