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.
This commit is contained in:
waltje
2023-06-16 22:41:14 -04:00
parent 087ce28886
commit fbb0bfde88
7 changed files with 57 additions and 27 deletions

5
.gitignore vendored
View File

@@ -1,8 +1,11 @@
# Local stuff
.gitignore
.git*
.depends*
foo*
*.cmd
*.sh
foo*
test*
tests/
# Prerequisites

View File

@@ -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

View File

@@ -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, <waltje@varcem.com>
* Bernd B”ckmann, <https://codeberg.org/boeckmann/asm6502>
@@ -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"
};

View File

@@ -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, <waltje@varcem.com>
*

View File

@@ -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, <waltje@varcem.com>
*
@@ -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);
}

View File

@@ -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, <waltje@varcem.com>
* Bernd B”ckmann, <https://codeberg.org/boeckmann/asm6502>
@@ -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 <address>" 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 },

View File

@@ -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.