Various small fixes.

This commit is contained in:
waltje
2023-09-29 22:31:02 -04:00
parent 3024da579f
commit 01ae91919a
9 changed files with 43 additions and 57 deletions

7
TODO
View File

@@ -1,5 +1,3 @@
- end-of-macro generates empty list line
- macro variable arguments
- first page title gets lost (we need to buffer lines for each page, and
@@ -15,6 +13,5 @@
for dot labels, and so on.
--> addr width, codebytes done
- check (again) to make sure explicit assignments keep the assigned width
of a value ($0000 is 16bit, $00 is 8, and so on.)
label symbols must ALWAYS be 'word' type.
- REPEAT still messes up line numbers

View File

@@ -8,7 +8,7 @@
*
* General expression handler.
*
* Version: @(#)expr.c 1.0.12 2023/09/08
* Version: @(#)expr.c 1.0.14 2023/09/28
*
* Authors: Fred N. van Kempen, <waltje@varcem.com>
* Bernd B”ckmann, <https://codeberg.org/boeckmann/asm6502>
@@ -91,6 +91,7 @@ number(char **p)
{
value_t num = { 0 };
uint8_t type = 0;
int digits = 0;
char *pt = *p;
if (**p == '&') {
@@ -110,9 +111,10 @@ do_oct:
error(ERR_NUM, NULL);
do {
num.v = num.v * 8 + digit((*p)++);
digits++;
} while (**p >= '0' && **p <= '7');
type = NUM_TYPE(num.v);
type = (digits > 6) ? TYPE_DWORD : (digits > 3) ? TYPE_WORD : TYPE_BYTE;
} else if (**p == '$') {
(*p)++;
do_hex:
@@ -120,9 +122,10 @@ do_hex:
error(ERR_NUM, NULL);
do {
num.v = (num.v << 4) + digit((*p)++);
digits++;
} while (isxdigit(**p));
type = ((*p - pt) > 7) ? TYPE_DWORD : ((*p - pt) > 3) ? TYPE_WORD : NUM_TYPE(num.v);
type = (digits > 4) ? TYPE_DWORD : (digits > 2) ? TYPE_WORD : TYPE_BYTE;
} else if (**p == '%') {
(*p)++;
do_bin:
@@ -130,9 +133,10 @@ do_bin:
error(ERR_NUM, NULL);
do {
num.v = (num.v << 1) + digit((*p)++);
digits++;
} while ((**p == '0') || (**p == '1'));
type = ((*p - pt) > 17) ? TYPE_DWORD : ((*p - pt) > 9) ? TYPE_WORD : NUM_TYPE(num.v);
type = (digits > 16) ? TYPE_DWORD : (digits > 8) ? TYPE_WORD : TYPE_BYTE;
} else if (**p == '0') {
/* Check if we have the '0x' (C style) form. */
(*p)++;
@@ -148,15 +152,16 @@ do_bin:
* '0..', without the suffix. We will accept the
* suffix, but not anything else.
*/
while (isxdigit(**p))
while (isxdigit(**p)) {
num.v = (num.v << 4) + digit((*p)++);
/* Set type. We do it here to avoid the extra char below. */
type = ((*p - pt) > 7) ? TYPE_DWORD : ((*p - pt) > 3) ? TYPE_WORD : NUM_TYPE(num.v);
digits++;
}
/* Quietly accept the '0..H' form. */
if (**p == 'h' || **p == 'H')
(*p)++;
type = (digits > 4) ? TYPE_DWORD : (digits > 2) ? TYPE_WORD : TYPE_BYTE;
} else {
/* No explicit radix specifier present, go with the default. */
switch (radix) {
@@ -306,10 +311,10 @@ program_counter:
goto program_counter;
} else if (**p == '\'') {
/* Single character. */
(*p)++;
if (is_end(**p) || (**p < 0x20))
error(ERR_CHR, NULL);
(*p)++;
res.v = **p;
res.t = TYPE_BYTE | VALUE_DEFINED;
@@ -332,7 +337,7 @@ program_counter:
(*p)++;
res.t = VALUE_DEFINED | NUM_TYPE(res.v);
} else if (isalpha(**p)) {
} else if (islabel(**p)) {
/* Symbol reference. */
nident(p, id);
pt = *p;
@@ -708,11 +713,7 @@ expr(char **p)
} else if (starts_with(*p, "[!b]")) {
/* Forced conversion to byte. */
*p += 4;
#if 1
res = to_byte(expr(p), 1); // convert entire expression
#else
res = to_byte(compare(p), 1);
#endif
} else if (starts_with(*p, "[d]")) {
/* Lossless conversion to doubleword. */
*p += 3;
@@ -725,11 +726,7 @@ expr(char **p)
} else if (starts_with(*p, "[!w]")) {
/* Forced conversion to word. */
*p += 4;
#if 1
res = to_word(expr(p), 1); // convert entire expression
#else
res = to_word(compare(p), 1);
#endif
} else {
/* Iterate. */
res = compare(p);

View File

@@ -8,7 +8,7 @@
*
* Definitions for the entire application.
*
* Version: @(#)global.h 1.0.14 2023/09/26
* Version: @(#)global.h 1.0.16 2023/09/28
*
* Author: Fred N. van Kempen, <waltje@varcem.com>
*
@@ -68,6 +68,7 @@
#define IS_END(c) ((!(c)) || IS_EOL((c)))
#define IS_SPACE(c) (((c) == '\t') || ((c) == ' '))
#define IS_IDENT(c) (((c) == DOT_CHAR) || ((c) == '_'))
#define islabel(c) (isalpha((c)) || ((c) == '_'))
#define MAX_FILENAMES 256 + 1 // maximum include files
#define MAX_IFLEVEL 16 // maximum depth of IF levels
@@ -94,9 +95,9 @@ typedef struct value {
/* For the value-specific directives. */
#define VALUE_DEFINED 0x80
#define DEFINED(x) (((x).t & VALUE_DEFINED) != 0)
#define UNDEFINED(x) (((x).t & VALUE_DEFINED) == 0)
#define SET_DEFINED(v) ((v).t = ((v).t | VALUE_DEFINED))
#define SET_UNDEFINED(v) ((v).t = (v).t & TYPE_MASK);
#define UNDEFINED(x) (! DEFINED(x))
#define SET_DEFINED(v) ((v).t |= VALUE_DEFINED)
#define SET_UNDEFINED(v) ((v).t &= ~TYPE_MASK);
#define INFER_DEFINED(a,b) \
if (UNDEFINED(a) || UNDEFINED(b)) { SET_UNDEFINED(a); } \
else { SET_DEFINED(a); }
@@ -127,9 +128,9 @@ typedef struct sym_ {
} symbol_t;
/* Symbol-specific directives. */
#define IS_LBL(x) (((x)->kind & KIND_LBL) != 0)
#define IS_VAR(x) (((x)->kind & KIND_VAR) != 0)
#define IS_MAC(x) (((x)->kind & KIND_MAC) != 0)
#define IS_LBL(x) ((x)->kind == KIND_LBL)
#define IS_VAR(x) ((x)->kind == KIND_VAR)
#define IS_MAC(x) ((x)->kind == KIND_MAC)
struct pseudo;

View File

@@ -8,7 +8,7 @@
*
* Handle the listfile output.
*
* Version: @(#)list.c 1.0.13 2023/09/26
* Version: @(#)list.c 1.0.14 2023/09/28
*
* Author: Fred N. van Kempen, <waltje@varcem.com>
*
@@ -54,7 +54,7 @@
#define LIST_PLENGTH 66 // number of lines per page
#define LIST_PWIDTH 80 // number of characters per line
#define LIST_AWIDTH 4 // number of digits in addresses
#define LIST_AWIDTH 6 // number of digits in addresses
#define LIST_NBYTES 4 // this many code bytes per line
#define LIST_CHAR_FF "\014" // FormFeed character

View File

@@ -295,7 +295,6 @@ macro_close(char **p)
{
if (curmac != NULL) {
*p = curmac->saved;
printf("CONT(%s)\n", *p);
curmac = NULL;
maclevel--;

View File

@@ -8,7 +8,7 @@
*
* Parse the source input, process it, and generate output.
*
* Version: @(#)parse.c 1.0.13 2023/09/26
* Version: @(#)parse.c 1.0.14 2023/09/28
*
* Authors: Fred N. van Kempen, <waltje@varcem.com>
* Bernd B”ckmann, <https://codeberg.org/boeckmann/asm6502>
@@ -597,10 +597,17 @@ pass(char **p, int pass)
/* OK, skip into the next line. */
skip_eol(p);
/* End of macro reached? */
if (**p == ETX_CHAR) {
/* Close macro and jump back into source. */
macro_close(p);
/* Now back in source file, skip EOL here, too. */
skip_eol(p);
}
/* End of current file reached? */
if (**p == EOF_CHAR) {
/* Skip the EOF.. */
(*p)++;

View File

@@ -8,7 +8,7 @@
*
* Handle directives and pseudo-ops.
*
* Version: @(#)pseudo.c 1.0.11 2023/09/16
* Version: @(#)pseudo.c 1.0.12 2023/09/28
*
* Authors: Fred N. van Kempen, <waltje@varcem.com>
* Bernd B”ckmann, <https://codeberg.org/boeckmann/asm6502>
@@ -96,6 +96,7 @@ string_lit(char **p, char *buf, int bufsize, int quot)
/* The ".addr <expr>" directive. */
//FIXME: this is for the SC/MP and INS8060 only!
static char *
do_addr(char **p, int pass)
{
@@ -281,21 +282,6 @@ do_byte(char **p, int pass)
len = string_lit(p, buf, STR_LEN, 1);
emit_str(buf, len, pass);
pc += len;
} else if (**p == '\'') {
(*p)++;
if (**p == '\'')
error(ERR_CHR, NULL);
buf[0] = **p;
(*p)++;
if (**p != '\'')
error(ERR_CHREND, NULL);
len = 1;
emit_str(buf, len, pass);
(*p)++;
pc++;
} else {
v = expr(p);
@@ -364,7 +350,6 @@ do_define(char **p, int pass)
nodata:
v.v = 1;
SET_DEFINED(v);
}
define_variable(id, v, 0);
@@ -520,7 +505,7 @@ do_end(char **p, int pass)
static char *
do_end_list(char *str)
{
sprintf(str, "$= %06X", sa);
sprintf(str, "$= %0*X", list_awidth, sa);
return str;
}

View File

@@ -67,8 +67,8 @@
#include "../target.h"
#define USE_JS 0 // include "JS" pseudo
#define USE_LDPI 0 // include "LDPI" pseudo
#define USE_JS 1 // include "JS" pseudo
#define USE_LDPI 1 // include "LDPI" pseudo
typedef enum {

View File

@@ -8,7 +8,7 @@
*
* Define application version and build info.
*
* Version: @(#)version.h 1.0.12 2023/09/26
* Version: @(#)version.h 1.0.13 2023/09/28
*
* Author: Fred N. van Kempen, <waltje@varcem.com>
*
@@ -55,8 +55,8 @@
/* Version info. */
#define APP_VER_MAJOR 1
#define APP_VER_MINOR 0
#define APP_VER_REV 20
#define APP_VER_PATCH 3
#define APP_VER_REV 21
#define APP_VER_PATCH 1
/* Standard C preprocessor macros. */