From fbb0bfde88aa9bc4afae182989c03a1213b6069b Mon Sep 17 00:00:00 2001 From: waltje Date: Fri, 16 Jun 2023 22:41:14 -0400 Subject: [PATCH] Err, fixed output.c (handling unknown formats crashed the app..) Fixed typo in error.c (misplaced comma) Changed list.c to always put PC in hex-6, not hex-4. Added the missing .NOFILL to pseudo.c. Updated tests/c64_prg.asm to use the .nofill directive. --- .gitignore | 5 ++++- CHANGELOG | 1 + src/error.c | 6 +++--- src/list.c | 2 +- src/output.c | 54 +++++++++++++++++++++++++++++------------------ src/pseudo.c | 13 +++++++++++- tests/c64_prg.asm | 3 ++- 7 files changed, 57 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index b85b2c4..5aa6c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,11 @@ # Local stuff .gitignore +.git* .depends* -foo* *.cmd +*.sh +foo* +test* tests/ # Prerequisites diff --git a/CHANGELOG b/CHANGELOG index f0a9cdd..7c9512a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -88,6 +88,7 @@ implemented properly, we will have to re-work the "generating output" code to do it as it goes (in pass 2), and not only at the end of that pass. This allows such "jumping" to be handled by those file formats. ++ Added the NOFILL directive (same as -F on commandline.) + Added Motorola SRecord support for the 16-bit S19 format. - fix the sub-relative include path If one includes a "../foo/bar/bla.inc" file, and then that file also does diff --git a/src/error.c b/src/error.c index 8dc960c..f78589b 100644 --- a/src/error.c +++ b/src/error.c @@ -8,7 +8,7 @@ * * Handle any errors. * - * Version: @(#)error.c 1.0.4 2023/06/05 + * Version: @(#)error.c 1.0.5 2023/06/16 * * Authors: Fred N. van Kempen, * Bernd B”ckmann, @@ -73,7 +73,7 @@ const char *err_msgs[ERR_MAXERR] = { "assert failed", "can not create file", "can not open file", - "file format not enabled" + "file format not enabled", "unknown directive", "unknown instruction", "comma expected", @@ -110,7 +110,7 @@ const char *err_msgs[ERR_MAXERR] = { "malformed character constant", "string too long", "string expected", - "maximum number of include files reached", + "maximum number of include files reached" }; diff --git a/src/list.c b/src/list.c index 14d3c99..705e54a 100644 --- a/src/list.c +++ b/src/list.c @@ -8,7 +8,7 @@ * * Handle the listfile output. * - * Version: @(#)list.c 1.0.8 2023/06/15 + * Version: @(#)list.c 1.0.9 2023/06/16 * * Author: Fred N. van Kempen, * diff --git a/src/output.c b/src/output.c index 5cae57a..c3b3315 100644 --- a/src/output.c +++ b/src/output.c @@ -30,7 +30,11 @@ * (or the .NOFILL assembler directive) can be used to disable * this behavior. * - * Version: @(#)output.c 1.0.5 2023/06/15 + * FIXME: We probably should merge the little/big endian functions + * into one, and have the backends select the proper mode for + * them at runtime. + * + * Version: @(#)output.c 1.0.6 2023/06/16 * * Author: Fred N. van Kempen, * @@ -204,7 +208,6 @@ output_open(const char *fn) char *p, *pfx, *s; /* Initialize. */ - out_max = out_format = 0; out_orgdone = 0; out_file = NULL; output_buff = out_line = NULL; @@ -232,12 +235,17 @@ output_open(const char *fn) if (p != NULL) p++; -again: - if ((p == NULL) || !strcasecmp(p, "bin")) { - if (p == NULL) - strcat(s, ".bin"); - out_file = fopen(s, "wb"); - } else if (!strcasecmp(p, "ihex") || !strcasecmp(p, "hex")) { + /* If no suffix at all, attach one. */ + if (p == NULL) { + p = "bin"; + strcat(s, ".bin"); + } + + /* But.. prefixes override a suffix. */ + if (pfx != NULL) + p = pfx; + + if (!strcasecmp(p, "ihex") || !strcasecmp(p, "hex")) { out_max = IHEX_MAX; out_format = 1; out_file = fopen(s, "w"); @@ -246,25 +254,31 @@ again: out_format = 2; out_file = fopen(s, "w"); } else { - if (pfx == NULL) - error(ERR_NO_FMT, p); + /* No known format name, assume raw-binary. */ + out_max = out_format = 0; + + /* If this was a prefix: we did not recognize it. */ + if (p == pfx) { + fprintf(stderr, "Error: %s (%s)\n", err_msgs[ERR_NO_FMT], p); + return 0; + } + + /* All good, create the file. */ + out_file = fopen(s, "wb"); } - /* Now check the prefix, which overrides any suffix. */ - if (pfx != NULL) { - p = pfx; - pfx = NULL; - goto again; + if (out_file == NULL) { + fprintf(stderr, "Error: %s (%s)\n", err_msgs[ERR_CREATE], s); + return 0; } - if (out_file == NULL) - error(ERR_CREATE, s); - /* Allocate line buffer if needed. */ if (out_max > 0) { out_line = malloc(out_max); - if (out_line == NULL) - error(ERR_MEM, "line buffer"); + if (out_line == NULL) { + fprintf(stderr, "Error: %s (%s)\n", err_msgs[ERR_MEM], "line buffer"); + return 0; + } memset(out_line, 0x00, out_max); } diff --git a/src/pseudo.c b/src/pseudo.c index 9d3b674..4908420 100644 --- a/src/pseudo.c +++ b/src/pseudo.c @@ -8,7 +8,7 @@ * * Handle directives and pseudo-ops. * - * Version: @(#)pseudo.c 1.0.7 2023/06/15 + * Version: @(#)pseudo.c 1.0.8 2023/06/16 * * Authors: Fred N. van Kempen, * Bernd B”ckmann, @@ -912,6 +912,16 @@ do_include(char **p, int pass) } +/* The ".nofill" directive. */ +static char * +do_nofill(char **p, int pass) +{ + opt_F = 0; + + return NULL; +} + + /* The ".org
" directive. */ static char * do_org(char **p, int pass) @@ -1256,6 +1266,7 @@ static const pseudo_t pseudos[] = { { "IFN", 1, 0, do_ifn, NULL }, { "IFNDEF", 1, 0, do_ifndef, NULL }, { "INCLUDE", 0, 0, do_include, NULL }, + { "NOFILL", 0, 0, do_nofill, NULL }, { "ORG", 0, 0, do_org, do_org_list }, { "PAGE", 0, 0, do_page, NULL }, { "RADIX", 0, 0, do_radix, NULL }, diff --git a/tests/c64_prg.asm b/tests/c64_prg.asm index 79306d3..e20ce87 100644 --- a/tests/c64_prg.asm +++ b/tests/c64_prg.asm @@ -8,11 +8,12 @@ LOAD = $0801 ; load address .word LOAD ; .PRG header: load address + .nofill ; make sure we do not fill .org LOAD ; we start at this address basic: ; BASIC code: 10 SYS 2062 .word @end, 10 ; ptr to next basic line and line number 10 .byte SYS, " 2062", 0 ; SYS token and address string of subroutine -@end .word 0 ; null ptr to indicate end of basic text +@end: .word 0 ; null ptr to indicate end of basic text ; End of preamble code.