From c2fad8d3e010c3fadf6101b4efa6903d0d95d9d6 Mon Sep 17 00:00:00 2001 From: Andre Fachat Date: Fri, 27 Oct 2023 15:00:50 +0200 Subject: [PATCH] dsbexpr --- xa/src/xa.c | 17 +++-------------- xa/src/xaa.c | 10 +++++++--- xa/src/xah.h | 3 +++ xa/src/xat.c | 2 +- xa/tests/usb65/Makefile | 5 ++++- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/xa/src/xa.c b/xa/src/xa.c index 5c11c08..0f241e7 100644 --- a/xa/src/xa.c +++ b/xa/src/xa.c @@ -954,17 +954,6 @@ static void usage(int default816, FILE *fp) " --help display this help and exit\n"); } -/* -static char *ertxt[] = { "Syntax","Label definiert", - "Label nicht definiert","Labeltabelle voll", - "Label erwartet","Speicher voll","Illegaler Opcode", - "Falsche Adressierungsart","Branch ausserhalb des Bereichs", - "Ueberlauf","Division durch Null","Pseudo-Opcode erwartet", - "Block-Stack-Ueberlauf","Datei nicht gefunden", - "End of File","Block-Struktur nicht abgeschlossen", - "NoBlk","NoKey","NoLine","OKDef","DSB","NewLine", - "NewFile","CMOS-Befehl","pp:Falsche Anzahl Parameter" }; -*/ static char *ertxt[] = { "Syntax", // E_SYNTAX =-1 "Label already defined", // E_LABDEF =-2 @@ -1003,9 +992,9 @@ static char *ertxt[] = { "Illegal quantity", // E_ILLQUANT =-35 ".bin", // E_BIN =-36 "#error directive", // E_UERROR =-37 - "Assertion", // E_AERROR =-38 + "Assertion", // E_AERROR =-38 + "DSB has negative length", // E_NEGDSBLEN =-39 /* placeholders for future fatal errors */ - "", // -39 "", // -40 "", // -41 "", // -42 @@ -1042,7 +1031,7 @@ static char *ertxt[] = { "Open preprocessor directive at end of file (intentional?)", // W_OPENPP =-72 "Included binary data exceeds 64KB", // W_OVER64K =-73 "Included binary data exceeds 16MB", // W_OVER16M =-74 - "MVN/MVP $XXXX syntax is deprecated and will be removed", // W_OLDMVNS =-75 + "Subtracting pointer from constant not supported in -R mode", // W_SUBTRACT =-75 /* more placeholders */ "", // -76 "", // -77 diff --git a/xa/src/xaa.c b/xa/src/xaa.c index 98fff52..db8cc3c 100644 --- a/xa/src/xaa.c +++ b/xa/src/xaa.c @@ -201,15 +201,19 @@ printf("pointer: v=%04x, afl=%04x\n",*v,afl); { if(afl || *nafl) { /* check pointer arithmetic */ if((afl == *nafl) && (afl!=SEG_UNDEFZP) && (afl!=SEG_UNDEF) && o==2) { - afl = 0; /* substract two pointers */ + afl = 0; /* subtract two pointers */ } else if(((afl && !*nafl) || (*nafl && !afl)) && o==1) { afl=(afl | *nafl); /* add constant to pointer */ } else if((afl && !*nafl) && o==2) { - afl=(afl | *nafl); /* substract constant from pointer */ + afl=(afl | *nafl); /* subtract constant from pointer */ } else { - /* allow math in the same segment */ + if((!afl && *nafl) && o==2) { + /* subtract pointer from constant */ + errout(W_SUBTRACT); + } + /* allow math in the same segment */ if(segment!=SEG_ABS && segment != afl) { if(!dsb_len) { /*printf("ILLPOINTER=dsb_len=%d,segment=%d\n",dsb_len, segment);*/ diff --git a/xa/src/xah.h b/xa/src/xah.h index 7b4abfd..8a0b5bb 100644 --- a/xa/src/xah.h +++ b/xa/src/xah.h @@ -140,6 +140,8 @@ typedef struct { #define E_BIN -36 /* okdef */ #define E_UERROR -37 /* #error */ #define E_AERROR -38 /* .assert failed */ +#define E_NEGDSBLEN -39 /* .dsb has negative length */ + /* errors thru 64 are placeholders available for use */ #define W_ADRRELOC -65 /* word relocation in byte value */ @@ -152,6 +154,7 @@ typedef struct { #define W_OPENPP -72 /* warning about open preprocessor directive */ #define W_OVER64K -73 /* included binary over 64K in 6502 mode */ #define W_OVER16M -74 /* included binary over 16M in 65816 mode */ +#define W_SUBTRACT -75 /* subtract a segment pointer from a constant - not supported in -R mode */ /* warnings 75-77 are placeholders available for use */ /* Meta-values for the token list. Note must not overlap with the diff --git a/xa/src/xat.c b/xa/src/xat.c index 86cbf40..52671ea 100644 --- a/xa/src/xat.c +++ b/xa/src/xat.c @@ -1623,7 +1623,7 @@ fprintf(stderr, "mvn mvp: %i %i %i %i %i\n", t[0], t[i], wide, i, j); if(!(er=a_term(t+1,&j,&i,pc[segment],&afl,&label,0))) { if (j<0) - er=E_SYNTAX; + er=E_NEGDSBLEN; else /* if(t[i+1]!=',') diff --git a/xa/tests/usb65/Makefile b/xa/tests/usb65/Makefile index 584b21a..8202be6 100644 --- a/xa/tests/usb65/Makefile +++ b/xa/tests/usb65/Makefile @@ -1,7 +1,7 @@ XA=../../xa -all: test1 test2 +all: test1 test2 test3 test1: test1.a65 ${XA} -XC -R -U $< @@ -9,3 +9,6 @@ test1: test1.a65 test2: test2.a65 ${XA} -R -U $< +test3: test3.a65 + ${XA} -R -U $< +