From 97142cb95b19c4b07a721a0b449c308b04d64e58 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 16 May 2024 05:46:44 -0400 Subject: blob2xex: warn on address wraparound. --- blob2xex.1 | 38 ++++++++++++++++++++++++++++++++------ blob2xex.c | 9 ++++++++- blob2xex.rst | 34 ++++++++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/blob2xex.1 b/blob2xex.1 index 0780513..ee00503 100644 --- a/blob2xex.1 +++ b/blob2xex.1 @@ -117,14 +117,40 @@ Print version number and exit. .sp Error messages and warnings are printed to standard error, and are hopefully self\-explanatory. Any message containing \fIfatal\fP causes -\fBblob2xex\fP to exit without creating the output file. +\fBblob2xex\fP to exit with nonzero status, without creating the output +file. .sp Messages containing \fIwarning\fP are non\-fatal, and the output file is -created. The only warning messages are there to let you know if your -\&.xex file\(aqs start/end addresses mean it would load into ROM (or, the -unmapped area at \fB$C000\fP on a 400/800). Normally this means the .xex -file won\(aqt load properly on the Atari, but feel free to ignore the -warnings if you know exactly what you\(aqre doing. +created. There are only a few possible warnings: +.INDENT 0.0 +.INDENT 3.5 +.INDENT 0.0 +.TP +.B start/end address XXXX loads into ROM. +This means your .exe file\(aqs start/end addresses will load the +file into ROM (or the unmapped area at \fB$C000\fP on a 400/800). +Normally this means the .xex file won\(aqt load properly on the +Atari, but feel free to ignore this warning if you know exactly +what you\(aqre doing. +.TP +.B address would exceed $FFFF! truncated N bytes to N. +The segment would wrap around the Atari\(aqs 64KB address space. +\fBblob2xex\fP has truncated the input so the last address +loaded is \fB$FFFF\fP\&. This warning usually means you gave the +wrong load address or the wrong input file entirely. +.TP +.B extra arguments after last input file ignored. +You gave at least one option that would affect the next file, +after the last file on the command line. Such options are ignored, +since there\(aqs no file for them to apply to. Probably you made +a typo or forgot the last input file. +.UNINDENT +.UNINDENT +.UNINDENT +.SH EXIT STATUS +.sp +Zero for success (the output file was created), even if there were +warnings. Non\-zero for failure (the output file wasn\(aqt created). .SH EXAMPLES .SS Simple Example .sp diff --git a/blob2xex.c b/blob2xex.c index 0f17371..413fb52 100644 --- a/blob2xex.c +++ b/blob2xex.c @@ -99,8 +99,12 @@ int write_segment( } /* make sure we don't wrap the Atari's address space. */ - if(size + loadaddr > 0xffff) + if(size + loadaddr > 0xffff) { + int oldsize = size; size = (size - loadaddr) + 1; + fprintf(stderr, SELF ": " + "warning: %s: address would exceed $FFFF! truncated %d bytes to %d.\n", infile, oldsize, size); + } /* read bytes, or until EOF (which is not an error) */ while(size) { @@ -209,6 +213,7 @@ int main(int argc, char **argv) { if( (bytes = write_segment(infile, outfile, loadaddr, initaddr, offset, size)) ) { segcount++; loadaddr += bytes; + loadaddr %= 0xffff; } else { segcount = 0; break; @@ -245,6 +250,8 @@ int main(int argc, char **argv) { fprintf(stderr, SELF ": read %d input files, wrote %d segments to %s.\n", incount, segcount, outfile); } else { + if(xex_verbose) + fprintf(stderr, SELF ": no output file created, due to fatal error.\n"); unlink(outfile); return 1; } diff --git a/blob2xex.rst b/blob2xex.rst index a3161ab..9984b2b 100644 --- a/blob2xex.rst +++ b/blob2xex.rst @@ -97,14 +97,36 @@ DIAGNOSTICS Error messages and warnings are printed to standard error, and are hopefully self-explanatory. Any message containing *fatal* causes -**blob2xex** to exit without creating the output file. +**blob2xex** to exit with nonzero status, without creating the output +file. Messages containing *warning* are non-fatal, and the output file is -created. The only warning messages are there to let you know if your -.xex file's start/end addresses mean it would load into ROM (or, the -unmapped area at **$C000** on a 400/800). Normally this means the .xex -file won't load properly on the Atari, but feel free to ignore the -warnings if you know exactly what you're doing. +created. There are only a few possible warnings: + + start/end address XXXX loads into ROM. + This means your .exe file's start/end addresses will load the + file into ROM (or the unmapped area at **$C000** on a 400/800). + Normally this means the .xex file won't load properly on the + Atari, but feel free to ignore this warning if you know exactly + what you're doing. + + address would exceed $FFFF! truncated N bytes to N. + The segment would wrap around the Atari's 64KB address space. + **blob2xex** has truncated the input so the last address + loaded is **$FFFF**. This warning usually means you gave the + wrong load address or the wrong input file entirely. + + extra arguments after last input file ignored. + You gave at least one option that would affect the next file, + after the last file on the command line. Such options are ignored, + since there's no file for them to apply to. Probably you made + a typo or forgot the last input file. + +EXIT STATUS +=========== + +Zero for success (the output file was created), even if there were +warnings. Non-zero for failure (the output file wasn't created). EXAMPLES ======== -- cgit v1.2.3