From e8a6ba088ebae7584088dc7c8b748db4ee1b42d6 Mon Sep 17 00:00:00 2001 From: fachat Date: Wed, 15 Aug 2012 03:06:45 +0200 Subject: [PATCH] added 0xHEX and 0OCTAL parsing with -XC compatibility parameter --- xa/man/xa.1 | 3 +++ xa/src/xa.c | 39 +++++++++++++++++++++++++++++++++++++++ xa/src/xa.h | 1 + xa/src/xah.h | 26 +++++++++++++------------- xa/src/xat.c | 20 +++++++++++++++++--- 5 files changed, 73 insertions(+), 16 deletions(-) diff --git a/xa/man/xa.1 b/xa/man/xa.1 index 9032ad8..dcb017b 100644 --- a/xa/man/xa.1 +++ b/xa/man/xa.1 @@ -65,6 +65,9 @@ not affect colon interpretation elsewhere. .B \-R Start assembler in relocating mode. .TP +.B \-N +Allow C-style numerals (starting with digit '0') +.TP .B \-Llabel Defines .B label diff --git a/xa/src/xa.c b/xa/src/xa.c index ca9f0f5..8bd307c 100644 --- a/xa/src/xa.c +++ b/xa/src/xa.c @@ -61,8 +61,12 @@ /* exported globals */ int ncmos, cmosfl, w65816, n65816; + +/* compatibility flags */ int masm = 0; int ppinstr = 0; +int ctypes = 0; /* C compatibility, like "0xab" types */ + int nolink = 0; int romable = 0; int romaddr = 0; @@ -234,6 +238,9 @@ int main(int argc,char *argv[]) if(argv[i][2]==0) romaddr = atoi(argv[++i]); else romaddr = atoi(argv[i]+2); break; + case 'N': /* C style numerals */ + ctypes = 1; + break; case 'G': noglob = 1; break; @@ -860,6 +867,8 @@ static void usage(int default816, FILE *fp) " starts at addr, relocation is not necessary. Overrides -bt\n" " Other segments must be specified with `-b?'\n" " -G suppress list of exported globals\n"); + fprintf(fp, + " -N Allow C-style numerals (starting with '0' digit)\n"); fprintf(fp, " -p? set preprocessor character to ?, default is #\n" " -DDEF=TEXT defines a preprocessor replacement\n" @@ -1141,3 +1150,33 @@ void logout(char *s) fprintf(fperr,"%s",s); } +#if 0 +/*****************************************************************/ + +typedef struct { + char *name; + int *flag; +} compat_set; + +static compat_set compat_sets[] = { + { "MASM", &masm }, + { "CA65", &ca65 }, + { "C", &ctypes }, + { NULL, NULL } +}; + +int set_compat(char *compat_name) { + int i = 0; + while (compat_sets[i].name != NULL) { + if (strcmp(compat_sets[i].name, compat_name) == 0) { + /* set appropriate compatibility flag */ + (*compat_sets[i].flag) = 1; + return 0; + } + i++; + } + return -1; +} + +#endif + diff --git a/xa/src/xa.h b/xa/src/xa.h index b00cbed..7858d4a 100644 --- a/xa/src/xa.h +++ b/xa/src/xa.h @@ -27,6 +27,7 @@ extern int noglob; extern int showblk; extern int relmode; extern int crossref; +extern int ctypes; extern char altppchar; extern int tlen, tbase; diff --git a/xa/src/xah.h b/xa/src/xah.h index 26133b2..daa61dc 100644 --- a/xa/src/xah.h +++ b/xa/src/xah.h @@ -71,20 +71,20 @@ typedef struct { #define BUFSIZE 4096 /* File-Puffegroesse (wg Festplatte) */ -#define E_OK 0 /* Fehlernummern */ -#define E_SYNTAX -1 /* Syntax Fehler */ -#define E_LABDEF -2 /* Label definiert */ -#define E_NODEF -3 /* Label nicht definiert */ -#define E_LABFULL -4 /* Labeltabelle voll */ -#define E_LABEXP -5 /* Label erwartet */ -#define E_NOMEM -6 /* kein Speicher mehr */ -#define E_ILLCODE -7 /* Illegaler Opcode */ -#define E_ADRESS -8 /* Illegale Adressierung */ +#define E_OK 0 /* No error */ +#define E_SYNTAX -1 /* Syntax error */ +#define E_LABDEF -2 /* Label already defined (duplicate label definition) */ +#define E_NODEF -3 /* Label not defined */ +#define E_LABFULL -4 /* Label table full */ +#define E_LABEXP -5 /* Label expected but not found */ +#define E_NOMEM -6 /* out of memory */ +#define E_ILLCODE -7 /* Illegal Opcode */ +#define E_ADRESS -8 /* Illegal Addressing mode */ #define E_RANGE -9 /* Branch out of range */ -#define E_OVERFLOW -10 /* Ueberlauf */ -#define E_DIV -11 /* Division durch Null */ -#define E_PSOEXP -12 /* Pseudo-Opcode erwartet */ -#define E_BLKOVR -13 /* Block-Stack Uebergelaufen */ +#define E_OVERFLOW -10 /* overflow */ +#define E_DIV -11 /* Division by zero */ +#define E_PSOEXP -12 /* Pseudo-Opcode expected but not found */ +#define E_BLKOVR -13 /* Block-Stack overflow */ #define E_FNF -14 /* File not found (pp) */ #define E_EOF -15 /* End of File */ #define E_BLOCK -16 /* Block inkonsistent */ diff --git a/xa/src/xat.c b/xa/src/xat.c index 6f46ee7..9a5f7a4 100644 --- a/xa/src/xat.c +++ b/xa/src/xat.c @@ -1826,16 +1826,30 @@ fprintf(stderr, "could not find %s\n", (char *)s+p); p+=ll; } else - if(s[p]<='9' && s[p]>='0') + if(s[p]<='9' && (s[p]>'0' || (s[p] == '0' && !ctypes))) { tg_dez(s+p,&ll,&v); p+=ll; wval(q,v); } else - - /* handle encodings: hex, binary, octal, quoted strings */ + /* handle encodings: hex, binary, octal, quoted strings */ switch(s[p]) { + case '0': + // only gets here when "ctypes" is set, and starts with 0 + // we here check for the C stype "0xHEX" and "0OCTAL" encodings + if ('x' == tolower(s[p+1])) { + // c-style hex + tg_hex(s+p+2, &ll, &v); + p+=2+ll; + wval(q, v, '$'); + } else { + // c-style octal + tg_oct(s+p+1,&ll,&v); + p+=1+ll; + wval(q,v, '&'); + } + break; case '$': tg_hex(s+p+1,&ll,&v); p+=1+ll;