return error(string[tok[1]]);
break;
default:
- return error("error directive encountered - aborting assembling");
+ return error("error directive encountered--aborting assembly");
}
}
}
int fd;
int bytes = 0;
long pos, size, bytesRead;
- char msg[256];
char buf1[256];
int i;
// Check to see if we're in BSS, and, if so, throw an error
if (scattr & SBSS)
{
- errors("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
+ error("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
return ERROR;
}
goto allright;
}
- return errors("cannot open: \"%s\"", string[tok[1]]);
+ return error("cannot open: \"%s\"", string[tok[1]]);
}
allright:
if (bytesRead != size)
{
- sprintf(msg, "was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
- error(msg);
+ error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
return ERROR;
}
// Make sure the user didn't try anything like:
// .include equates.s
if (*++tok != EOL)
- return error("extra stuff after filename -- enclose it in quotes");
+ return error("extra stuff after filename--enclose it in quotes");
// Attempt to open the include file in the current directory, then (if that
// failed) try list of include files passed in the enviroment string or by
goto allright;
}
- return errors("cannot open: \"%s\"", fn);
+ return error("cannot open: \"%s\"", fn);
}
allright:
return error("non-absolute byte value");
if (eval + 0x100 >= 0x200)
- {
- sprintf(buffer, "%s (value = $%X)", range_error, eval);
- return error(buffer);
- }
+ return error("%s (value = $%X)", range_error, eval);
D_byte(eval);
}
symbol->sattr = 0;
}
else if (symbol->sattr & DEFINED)
- return errors("multiply-defined label '%s'", p);
+ return error("multiply-defined label '%s'", p);
// Put symbol in "order of definition" list
AddToSymbolDeclarationList(symbol);
symbol->sattr = 0;
}
else if (symbol->sattr & DEFINED)
- return errors("multiply-defined label '%s'", symbolName);
+ return error("multiply-defined label '%s'", symbolName);
// Put symbol in "order of definition" list
AddToSymbolDeclarationList(symbol);
char * tmpstr = string[*tok++];
if (ParseOptimization(tmpstr) != OK)
- {
- char temperr[256];
- sprintf(temperr, "unknown optimization flag '%s'", tmpstr);
- return error(temperr);
- }
+ return error("unknown optimization flag '%s'", tmpstr);
}
else
return error(".opt directive needs every switch enclosed inside quotation marks");
//
#include "error.h"
-#include "token.h"
+#include <stdarg.h>
#include "listing.h"
+#include "token.h"
int errcnt; // Error count
char * err_fname; // Name of error message file
-static const char nl[] = "\n";
static long unused; // For supressing 'write' warnings
//
int at_eol(void)
{
- char msg[256];
-
if (*tok != EOL)
- {
- sprintf(msg, "syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
- error(msg);
- }
+ error("syntax error. expected EOL, found $%X ('%c')", *tok, *tok);
return 0;
}
//
// Setup for error message
-// o Create error listing file (if necessary)
-// o Set current filename
+// o Create error listing file (if necessary)
+// o Set current filename
//
void err_setup(void)
{
char fnbuf[FNSIZ];
-// This seems like it's unnecessary, as token.c seems to take care of this all by itself.
-// Can restore if it's really needed. If not, into the bit bucket it goes. :-)
-// setfnum(cfileno);
-
if (err_fname != NULL)
{
strcpy(fnbuf, err_fname);
//
-// Display error message
+// Display error message (uses printf() style variable arguments)
//
-int error(const char * s)
-{
- char buf[EBUFSIZ];
- unsigned int length;
-
- err_setup();
-
- if (listing > 0)
- ship_ln(s);
-
- sprintf(buf, "%s %d: Error: %s%s", curfname, curlineno, s, nl);
- length = strlen(buf);
-
- if (err_flag)
- unused = write(err_fd, buf, length);
- else
- printf("%s", buf);
-
- taglist('E');
- errcnt++;
-
- return ERROR;
-}
-
-
-int errors(const char * s, char * s1)
+int error(const char * text, ...)
{
char buf[EBUFSIZ];
char buf1[EBUFSIZ];
err_setup();
- sprintf(buf, s, s1);
+
+ va_list arg;
+ va_start(arg, text);
+ vsprintf(buf, text, arg);
+ va_end(arg);
if (listing > 0)
ship_ln(buf);
- sprintf(buf1, "%s %d: Error: %s%s", curfname, curlineno, buf, nl);
+ sprintf(buf1, "%s %d: Error: %s\n", curfname, curlineno, buf);
if (err_flag)
unused = write(err_fd, buf1, (LONG)strlen(buf1));
printf("%s", buf1);
taglist('E');
- ++errcnt;
+ errcnt++;
return ERROR;
}
-int warn(const char * s)
-{
- char buf[EBUFSIZ];
-
- err_setup();
-
- if (listing > 0)
- ship_ln(s);
-
- sprintf(buf, "%s %d: Warning: %s%s", curfname, curlineno, s, nl);
-
- if (err_flag)
- unused = write(err_fd, buf, (LONG)strlen(buf));
- else
- printf("%s", buf);
-
- taglist('W');
-
- return OK;
-}
-
-
-int warns(const char * s, char * s1)
-{
- char buf[EBUFSIZ];
- char buf1[EBUFSIZ];
-
- err_setup();
- sprintf(buf, s, s1);
-
- if (listing > 0)
- ship_ln(s);
-
- sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
-
- if (err_flag)
- unused = write(err_fd, buf1, (LONG)strlen(buf1));
- else
- printf("%s", buf1);
-
- taglist('W');
-
- return OK;
-}
-
-
-int warni(const char * s, unsigned i)
+//
+// Display warning message (uses printf() style variable arguments)
+//
+int warn(const char * text, ...)
{
char buf[EBUFSIZ];
char buf1[EBUFSIZ];
err_setup();
- sprintf(buf, s, i);
+ va_list arg;
+ va_start(arg, text);
+ vsprintf(buf, text, arg);
+ va_end(arg);
if (listing > 0)
ship_ln(buf);
- sprintf(buf1, "%s %d: Warning: %s%s", curfname, curlineno, buf, nl);
+ sprintf(buf1, "%s %d: Warning: %s\n", curfname, curlineno, buf);
if (err_flag)
unused = write(err_fd, buf1, (LONG)strlen(buf1));
if (listing > 0)
ship_ln(s);
- sprintf(buf, "%s %d: Fatal: %s%s", curfname, curlineno, s, nl);
+ sprintf(buf, "%s %d: Fatal: %s\n", curfname, curlineno, s);
if (err_flag)
unused = write(err_fd, buf, (LONG)strlen(buf));
char buf[EBUFSIZ];
err_setup();
- sprintf(buf, "%s %d: Internal Error Number %d%s", curfname, curlineno, n, nl);
+ sprintf(buf, "%s %d: Internal error #%d\n", curfname, curlineno, n);
if (listing > 0)
ship_ln(buf);
extern char * err_fname;
// Exported functions
-int error(const char *);
-int errors(const char *, char *);
+int error(const char *, ...);
+int warn(const char *, ...);
int fatal(const char *);
-int warn(const char *);
-int warns(const char *, char *);
-int warni(const char *, unsigned);
int interror(int);
void cantcreat(const char *);
void err_setup(void);
if (sy->sattre & EQUATEDREG)
{
if ((regbank == BANK_0) && (sy->sattre & BANK_1) && !altbankok)
- warns("equated symbol \'%s\' cannot be used in register bank 0", sy->sname);
+ warn("equated symbol \'%s\' cannot be used in register bank 0", sy->sname);
if ((regbank == BANK_1) && (sy->sattre & BANK_0) && !altbankok)
- warns("equated symbol \'%s\' cannot be used in register bank 1", sy->sname);
+ warn("equated symbol \'%s\' cannot be used in register bank 1", sy->sname);
}
*evalTokenBuffer++ = SYMBOL;
return ERROR;
if (*tok++ != ')')
- return error("missing close parenthesis ')'");
+ return error("missing closing parenthesis ')'");
break;
case '[':
return ERROR;
if (*tok++ != ']')
- return error("missing close parenthesis ']'");
+ return error("missing closing bracket ']'");
break;
case '$':
return ERROR;
if (*tok++ != '}')
- return error("missing close bracket '}'");
+ return error("missing closing brace '}'");
break;
default:
// means it will be fixed up later, and thus, not an error.
if ((symbol->sattre & UNDEF_EQUR) && !riscImmTokenSeen)
{
- errors("undefined register equate '%s'", symbol->sname);
+ error("undefined register equate '%s'", symbol->sname);
//if we return right away, it returns some spurious errors...
// return ERROR;
}
if (symbol->sattre & EQUATEDREG)
{
if ((regbank == BANK_0) && (symbol->sattre & BANK_1) && !altbankok)
- warns("equated symbol '%s' cannot be used in register bank 0", symbol->sname);
+ warn("equated symbol '%s' cannot be used in register bank 0", symbol->sname);
if ((regbank == BANK_1) && (symbol->sattre & BANK_0) && !altbankok)
- warns("equated symbol '%s' cannot be used in register bank 1", symbol->sname);
+ warn("equated symbol '%s' cannot be used in register bank 1", symbol->sname);
}
*evalTokenBuffer++ = SYMBOL;
sattr--; // Pop attrib
if (sval[1] == 0)
- return error("divide by zero");
+ return error("division by zero");
//printf("--> N/N: %i / %i = ", sval[0], sval[1]);
// Compiler is picky here: Without casting these, it discards
{
if (TokenizeLine() == TKEOF)
{
- errors("encountered end-of-file looking for '%s'", dirlist);
+ error("encountered end-of-file looking for '%s'", dirlist);
fatal("cannot continue");
}
//
// Complain about some things are not allowed in '-p' (PRG) mode:
- // o Marks that aren't to LONGs
- // o External references
+ // o Marks that aren't to LONGs
+ // o External references
//
if (prg_flag)
{
-#if 0
- if ((flags & MLONG) == 0)
- error("illegal word relocatable (in .PRG mode)");
-#endif
-
if (symbol != NULL)
- errors("illegal external reference (in .PRG mode) to '%s'",
+ error("illegal external reference (in .PRG mode) to '%s'",
symbol->sname);
}
// Get another line of tokens
if (TokenizeLine() == TKEOF)
{
-if (debug) printf("Assemble: Found TKEOF flag...\n");
+DEBUG { printf("Assemble: Found TKEOF flag...\n"); }
if (list_flag && listflag) // Flush last line of source
listeol();
return;
}
- DEBUG DumpTokenBuffer();
+ DEBUG { DumpTokenBuffer(); }
if (list_flag)
{
// First token MUST be a symbol (Shamus: not sure why :-/)
if (*tok != SYMBOL)
{
- if (*tok>=KW_D0 && *tok<=KW_R31)
- error("cannot use reserved keyword as label name or .equ");
- else
- error("syntax error; expected symbol");
+ if ((*tok >= KW_D0) && (*tok <= KW_R31))
+ error("cannot use reserved keyword as label name or .equ");
+ else
+ error("syntax error; expected symbol");
+
goto loop;
}
}
else
{
- errors("multiple equate to '%s'", sy->sname);
+ error("multiple equate to '%s'", sy->sname);
goto loop;
}
}
if ((sy = lookup(opname, MACRO, 0)) != NULL)
InvokeMacro(sy, siz);
else
- errors("unknown op '%s'", opname);
+ error("unknown op '%s'", opname);
goto loop;
}
}
// Do mnemonics
- // o can't deposit instrs in BSS or ABS
- // o do automatic .EVEN for instrs
- // o allocate space for largest possible instr
- // o can't do ".b" operations with an address register
+ // o can't deposit instrs in BSS or ABS
+ // o do automatic .EVEN for instrs
+ // o allocate space for largest possible instr
+ // o can't do ".b" operations with an address register
if (scattr & SBSS)
{
error("cannot initialize non-storage (BSS) section");
symbol->sattre = 0;
}
else if (symbol->sattr & DEFINED)
- return errors("multiply-defined label '%s'", label);
+ return error("multiply-defined label '%s'", label);
// Put symbol in "order of definition" list if it's not already in it
AddToSymbolDeclarationList(symbol);
//
static inline int MalformedOpcode(int signal)
{
- char buf[16];
- sprintf(buf, "%02X", signal);
- return errors("Malformed opcode [internal $%s]", buf);
+ return error("Malformed opcode [internal $%02X]", signal);
}
+
//
// Function to return "Illegal Indexed Register" error
// Anyone trying to index something other than R14 or R15
//
static inline int IllegalIndexedRegister(int reg)
{
- char buf[16];
- sprintf(buf, "%d", reg - KW_R0);
- return errors("Attempted index reference with non-indexable register (r%s)", buf);
+ return error("Attempted index reference with non-indexable register (r%d)", reg - KW_R0);
}
+
//
// Function to return "Illegal Indexed Register" error for EQUR scenarios
// Trying to use register value within EQUR that isn't 14 or 15
//
-static inline int IllegalIndexedRegisterEqur(SYM *sy)
+static inline int IllegalIndexedRegisterEqur(SYM * sy)
{
- //char buf[160];
- char *buf = NULL;
- buf = (char *)malloc((strlen(sy->sname) + 7) * sizeof(char));
- if (NULL != buf) {
- sprintf(buf, "%s = r%d",sy->sname, sy->svalue);
- return errors("Attempted index reference with non-indexable register within EQUR (%s)", buf);
- }
- return errors("Unable to allocate memory! (IllegalIndexRegisterEqur)", "OOPS");
+ return error("Attempted index reference with non-indexable register within EQUR (%s = r%d)", sy->sname, sy->svalue);
}
+
//
// Build RISC instruction word
//
ccsym = lookup(string[tok[1]], LABEL, 0);
if (ccsym && (ccsym->sattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC))
- {
val = ccsym->svalue;
- }
else
return error("unknown condition code");
}
reg2 = ((int)(eval - ((orgactive ? orgaddr : sloc) + 2))) / 2;
if ((reg2 < -16) || (reg2 > 15))
- error("PC relative overflow");
+ error("PC relative overflow (outside of -16 to 15)");
}
BuildRISCIntructionWord(parm, reg2, reg1);
#define ERROUT 2 // Error output
#define CREATMASK 0
-// (Normally) non-printable tokens
-#define COLON ':' // : (grumble: GNUmacs hates ':')
-#define CONST 'a' // CONST <value>
-#define ACONST 'A' // ACONST <value> <attrib>
-#define STRING 'b' // STRING <address>
-#define STRINGA8 'S' // Atari 800 internal STRING <address>
-#define SYMBOL 'c' // SYMBOL <address>
-#define EOL 'e' // End of line
-#define TKEOF 'f' // End of file (or macro)
-#define DEQUALS 'g' // ==
-#define SET 149 // set
-#define REG 'R' // reg
-#define EQUREG 148 // equreg
-#define CCDEF 183 // ccdef
-#define DCOLON 'h' // ::
-#define GE 'i' // >=
-#define LE 'j' // <=
-#define NE 'k' // <> or !=
-#define SHR 'l' // >>
-#define SHL 'm' // <<
-#define UNMINUS 'n' // Unary '-'
-#define DOTB 'B' // .b or .B or .s or .S
-#define DOTW 'W' // .w or .W
-#define DOTL 'L' // .l or .L
-#define DOTI 'I' // .i or .I
-#define DOTD 'D' // .d or .D
-#define DOTS 'S' // .s or .S (FPU Single)
-#define DOTQ 'Q' // .q oe .Q (FPU Quad)
-#define DOTX 'X' // .x or .X (FPU Extended)
-#define DOTP 'P' // .p or .P (FPU Packed)
-#define ENDEXPR 'E' // End of expression
-
// Object code formats
#define ALCYON 0 // Alcyon/DRI C object format
#define MWC 1 // Mark Williams object format
#define EQUATEDCC 0x0020
#define UNDEF_CC 0x0040
-/* Construct binary constants at compile time
-Code by Tom Torfs */
+// Construct binary constants at compile time
+// Code by Tom Torfs
-/* Helper macros */
+// Helper macros
#define HEX__(n) 0x##n##LU
-#define B8__(x) ((x&0x0000000FLU)?1:0) \
+#define B8__(x) \
+ ((x&0x0000000FLU)?1:0) \
+((x&0x000000F0LU)?2:0) \
+((x&0x00000F00LU)?4:0) \
+((x&0x0000F000LU)?8:0) \
+((x&0x0F000000LU)?64:0) \
+((x&0xF0000000LU)?128:0)
-/* User macros */
-#define B8(d) ((unsigned char)B8__(HEX__(d)))
-#define B16(dmsb,dlsb) (((unsigned short)B8(dmsb)<<8) \
-+ B8(dlsb))
-#define B32(dmsb,db2,db3,dlsb) (((unsigned long)B8(dmsb)<<24) \
-+ ((unsigned long)B8(db2)<<16) \
-+ ((unsigned long)B8(db3)<<8) \
+// User macros
+#define B8(d) ((uint8_t)B8__(HEX__(d)))
+#define B16(dmsb,dlsb) (((uint16_t)B8(dmsb)<<8) + B8(dlsb))
+#define B32(dmsb,db2,db3,dlsb) (((uint32_t)B8(dmsb)<<24) \
++ ((uint32_t)B8(db2)<<16) \
++ ((uint32_t)B8(db3)<<8) \
+ B8(dlsb))
// Optimisation defines
static TOKEN tokbuf[TOKBUFSIZE]; // Token buffer (stack-like, all files)
-char chrtab[] = {
+uint8_t chrtab[0x100] = {
ILLEG, ILLEG, ILLEG, ILLEG, // NUL SOH STX ETX
ILLEG, ILLEG, ILLEG, ILLEG, // EOT ENQ ACK BEL
ILLEG, WHITE, ILLEG, ILLEG, // BS HT LF VT
MULTX, MULTX, // : ;
MULTX, MULTX, MULTX, STSYM+CTSYM, // < = > ?
- MULTX, STSYM+CTSYM+HDIGIT, // @ A
- (char)((BYTE)DOT)+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // B C
- (char)((BYTE)DOT)+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // D E
- STSYM+CTSYM+HDIGIT, STSYM+CTSYM, // F G
- STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // H I J K
- (char)((BYTE)DOT)+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // L M N O
-
- (char)((BYTE)DOT)+STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, // P Q R S
- STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, // T U V W
- STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, SELF, // X Y Z [
- SELF, SELF, MULTX, STSYM+CTSYM, // \ ] ^ _
-
- ILLEG, STSYM+CTSYM+HDIGIT, // ` a
- (char)((BYTE)DOT)+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // b c
- (char)((BYTE)DOT)+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // d e
- STSYM+CTSYM+HDIGIT, STSYM+CTSYM, // f g
- STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // h i j k
- (char)((BYTE)DOT)+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // l m n o
-
- (char)((BYTE)DOT)+STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, // p q r s
- STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, (char)((BYTE)DOT)+STSYM+CTSYM, // t u v w
- (char)((BYTE)DOT)+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, SELF, // x y z {
- SELF, SELF, SELF, ILLEG // | } ~ DEL
+ MULTX, STSYM+CTSYM+HDIGIT, // @ A
+ DOT+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // B C
+ DOT+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // D E
+ STSYM+CTSYM+HDIGIT, STSYM+CTSYM, // F G
+ STSYM+CTSYM, DOT+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // H I J K
+ DOT+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // L M N O
+
+ DOT+STSYM+CTSYM, DOT+STSYM+CTSYM, STSYM+CTSYM, DOT+STSYM+CTSYM, // P Q R S
+ STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, DOT+STSYM+CTSYM, // T U V W
+ STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, SELF,// X Y Z [
+ SELF, SELF, MULTX, STSYM+CTSYM, // \ ] ^ _
+
+ ILLEG, STSYM+CTSYM+HDIGIT, // ` a
+ DOT+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // b c
+ DOT+STSYM+CTSYM+HDIGIT, STSYM+CTSYM+HDIGIT, // d e
+ STSYM+CTSYM+HDIGIT, STSYM+CTSYM, // f g
+ STSYM+CTSYM, DOT+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // h i j k
+ DOT+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, // l m n o
+
+ DOT+STSYM+CTSYM, DOT+STSYM+CTSYM, STSYM+CTSYM, DOT+STSYM+CTSYM, // p q r s
+ STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, DOT+STSYM+CTSYM, // t u v w
+ DOT+STSYM+CTSYM, STSYM+CTSYM, STSYM+CTSYM, SELF, // x y z {
+ SELF, SELF, SELF, ILLEG, // | } ~ DEL
+
+ // Anything above $7F is illegal (and yes, we need to check for this,
+ // otherwise you get strange and spurious errors that will lead you astray)
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG,
+ ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG, ILLEG
};
// Names of registers
break;
case SRC_IREPT: // Alloc and init an IREPT
inobj->inobj.irept = malloc(sizeof(IREPT));
- DEBUG printf("alloc IREPT\n");
+ DEBUG { printf("alloc IREPT\n"); }
break;
}
*d++ = *s++;
if (*s != '}')
- return error("missing '}'");
+ return error("missing closing brace ('}')");
else
s++;
}
// Lookup the argument and copy its (string) value into the
// destination string
- DEBUG printf("argument='%s'\n", mname);
+ DEBUG { printf("argument='%s'\n", mname); }
if ((arg = lookup(mname, MACARG, macnum)) == NULL)
- return errors("undefined argument: '%s'", mname);
+ return error("undefined argument: '%s'", mname);
else
{
// Convert a string of tokens (terminated with EOL) back into
// macro invocation) then it is ignored.
i = (int)arg->svalue;
arg_num:
- DEBUG printf("~argnumber=%d (argBase=%u)\n", i, imacro->argBase);
+ DEBUG { printf("~argnumber=%d (argBase=%u)\n", i, imacro->argBase); }
tk = NULL;
if (i < imacro->im_nargs)
#else
// This fix should be done for strings too
d = symbolString[*tk++];
-DEBUG printf("ExM: SYMBOL=\"%s\"", d);
+DEBUG { printf("ExM: SYMBOL=\"%s\"", d); }
#endif
break;
case STRING:
overflow:
*dst = EOS;
- DEBUG printf("*** OVERFLOW LINE ***\n%s\n", dest);
+ DEBUG { printf("*** OVERFLOW LINE ***\n%s\n", dest); }
return fatal("line too long as a result of macro expansion");
}
// Do repeat at end of .rept block's string list
if (strp == NULL)
{
- DEBUG printf("back-to-top-of-repeat-block count=%d\n", (int)irept->ir_count);
+ DEBUG { printf("back-to-top-of-repeat-block count=%d\n", (int)irept->ir_count); }
irept->ir_nextln = irept->ir_firstln; // copy first line
if (irept->ir_count-- == 0)
{
- DEBUG printf("end-repeat-block\n");
+ DEBUG { printf("end-repeat-block\n"); }
return NULL;
}
int include(int handle, char * fname)
{
// Debug mode
- if (debug)
- printf("[include: %s, cfileno=%u]\n", fname, cfileno);
+ DEBUG { printf("[include: %s, cfileno=%u]\n", fname, cfileno); }
// Alloc and initialize include-descriptors
INOBJ * inobj = a_inobj(SRC_IFILE);
last_fr->frec_next = fr; // Append to list of filerecs
last_fr = fr;
- DEBUG printf("[include: curfname: %s, cfileno=%u]\n", curfname, cfileno);
+ DEBUG { printf("[include: curfname: %s, cfileno=%u]\n", curfname, cfileno); }
return OK;
}
// Give a warning to the user that we had to wipe their bum for them
if (numUnmatched > 0)
- warni("missing %d .endif(s)", numUnmatched);
+ warn("missing %d .endif(s)", numUnmatched);
tok = inobj->in_otok; // Restore tok and otok
etok = inobj->in_etok;
switch (inobj->in_type)
{
case SRC_IFILE: // Pop and release an IFILE
- if (debug)
- printf("[Leaving: %s]\n", curfname);
+ DEBUG { printf("[Leaving: %s]\n", curfname); }
ifile = inobj->inobj.ifile;
ifile->if_link = f_ifile;
f_ifile = ifile;
close(ifile->ifhandle); // Close source file
-if (debug) printf("[fpop (pre): curfname=%s]\n", curfname);
+DEBUG { printf("[fpop (pre): curfname=%s]\n", curfname); }
curfname = ifile->ifoldfname; // Set current filename
-if (debug) printf("[fpop (post): curfname=%s]\n", curfname);
-if (debug) printf("[fpop: (pre) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
+DEBUG { printf("[fpop (post): curfname=%s]\n", curfname); }
+DEBUG { printf("[fpop: (pre) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno); }
curlineno = ifile->ifoldlineno; // Set current line#
DEBUG printf("cfileno=%d ifile->ifno=%d\n", (int)cfileno, (int)ifile->ifno);
cfileno = ifile->ifno; // Restore current file number
-if (debug) printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno);
+DEBUG { printf("[fpop: (post) cfileno=%d ifile->ifno=%d]\n", (int)cfileno, (int)ifile->ifno); }
break;
case SRC_IMACRO: // Pop and release an IMACRO
imacro = inobj->inobj.imacro;
//
int TokenizeLine(void)
{
- char * ln = NULL; // Ptr to current position in line
- char * p; // Random character ptr
+ uint8_t * ln = NULL; // Ptr to current position in line
+ uint8_t * p; // Random character ptr
TOKEN * tk; // Token-deposit ptr
int state = 0; // State for keyword detector
int j = 0; // Var for keyword detector
- char c; // Random char
+ uint8_t c; // Random char
VALUE v; // Random value
- char * nullspot = NULL; // Spot to clobber for SYMBOL termination
+ uint8_t * nullspot = NULL; // Spot to clobber for SYMBOL termination
int stuffnull; // 1:terminate SYMBOL '\0' at *nullspot
- char c1;
+ uint8_t c1;
int stringNum = 0; // Pointer to string locations in tokenized line
retry:
case SRC_IFILE:
if ((ln = GetNextLine()) == NULL)
{
-if (debug) printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n");
+DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IFILE...\n"); }
if (fpop() == 0) // Pop input level
goto retry; // Try for more lines
else
case SRC_IREPT:
if ((ln = GetNextRepeatLine()) == NULL)
{
-if (debug) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n");
+DEBUG { printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); }
fpop();
goto retry;
}
goto goteol;
// Main tokenization loop;
- // o skip whitespace;
- // o handle end-of-line;
- // o handle symbols;
- // o handle single-character tokens (operators, etc.);
- // o handle multiple-character tokens (constants, strings, etc.).
+ // o skip whitespace;
+ // o handle end-of-line;
+ // o handle symbols;
+ // o handle single-character tokens (operators, etc.);
+ // o handle multiple-character tokens (constants, strings, etc.).
for(; *ln!=EOS;)
{
// Skip whitespace, handle EOL
- while ((int)chrtab[*ln] & WHITE)
+ while (chrtab[*ln] & WHITE)
ln++;
// Handle EOL, comment with ';'
v = (VALUE)dotxtab[*ln++];
if (chrtab[*ln] & CTSYM)
- return error("misuse of '.', not allowed in symbols");
+ return error("misuse of '.'; not allowed in symbols");
}
// If the symbol is small, check to see if it's really the name of
// Handle multiple-character tokens
if (c & MULTX)
{
-
switch (*ln++)
{
case '!': // ! or !=
}
// Handle illegal character
- return error("illegal character");
+ return error("illegal character $%02X found", *ln);
}
// Terminate line of tokens and return "success."
#include "rmac.h"
// Include Files and Macros
-#define SRC_IFILE 0 // Input source is IFILE
-#define SRC_IMACRO 1 // Input source is IMACRO
-#define SRC_IREPT 2 // Input source is IREPT
+#define SRC_IFILE 0 // Input source is IFILE
+#define SRC_IMACRO 1 // Input source is IMACRO
+#define SRC_IREPT 2 // Input source is IREPT
// Macros
#define INOBJ struct _inobj
#define IFENT struct _ifent
// Tunable definitions
-#define LNSIZ 1024 // Maximum size of a line of text
-#define TOKBUFSIZE 400 // Size of token-line buffer
-#define QUANTUM 4096L // # bytes to eat at a time from a file
-#define LNBUFSIZ (QUANTUM*2) // Size of file's buffer
-#define KWSIZE 7 // Maximum size of keyword in kwtab.h
+#define LNSIZ 1024 // Maximum size of a line of text
+#define TOKBUFSIZE 400 // Size of token-line buffer
+#define QUANTUM 4096L // # bytes to eat at a time from a file
+#define LNBUFSIZ (QUANTUM*2) // Size of file's buffer
+#define KWSIZE 7 // Maximum size of keyword in kwtab.h
// (Normally) non-printable tokens
-#define COLON ':' // : (grumble: GNUmacs hates ':')
-#define CONST 'a' // CONST <value>
-#define ACONST 'A' // ACONST <value> <attrib>
-#define STRING 'b' // STRING <address>
-#define SYMBOL 'c' // SYMBOL <address>
-#define EOL 'e' // End of line
-#define TKEOF 'f' // End of file (or macro)
-#define DEQUALS 'g' // ==
-#define SET 149 // Set
-#define REG 'R' // Reg
-#define DCOLON 'h' // ::
-#define GE 'i' // >=
-#define LE 'j' // <=
-#define NE 'k' // <> or !=
-#define SHR 'l' // >>
-#define SHL 'm' // <<
-#define UNMINUS 'n' // Unary '-'
-#define DOTB 'B' // .b or .B or .s or .S
-#define DOTW 'W' // .w or .W
-#define DOTL 'L' // .l or .L
-#define DOTI 'I' // .l or .L
-#define DOTX 'X' // .x or .X
-#define DOTD 'D' // .d or .D
-#define DOTP 'P' // .p or .P
-#define DOTQ 'Q' // .q or .Q (essentially an alias for P)
-#define ENDEXPR 'E' // End of expression
+#define COLON ':' // : (grumble: GNUmacs hates ':')
+#define CONST 'a' // CONST <value>
+#define ACONST 'A' // ACONST <value> <attrib>
+#define STRING 'b' // STRING <address>
+#define STRINGA8 'S' // Atari 800 internal STRING <address>
+#define SYMBOL 'c' // SYMBOL <address>
+#define EOL 'e' // End of line
+#define TKEOF 'f' // End of file (or macro)
+#define DEQUALS 'g' // ==
+#define SET 0x95 // Set
+#define REG 'R' // Reg
+#define EQUREG 0x94 // equreg
+#define CCDEF 0xB7 // ccdef
+#define DCOLON 'h' // ::
+#define GE 'i' // >=
+#define LE 'j' // <=
+#define NE 'k' // <> or !=
+#define SHR 'l' // >>
+#define SHL 'm' // <<
+#define UNMINUS 'n' // Unary '-'
+#define DOTB 'B' // .b or .B or .s or .S
+#define DOTW 'W' // .w or .W
+#define DOTL 'L' // .l or .L
+#define DOTI 'I' // .l or .L
+#define DOTX 'X' // .x or .X
+#define DOTD 'D' // .d or .D
+#define DOTP 'P' // .p or .P
+#define DOTQ 'Q' // .q or .Q (essentially an alias for P)
+#define DOTS 'S' // .s or .S (FPU Single)
+#define ENDEXPR 'E' // End of expression
// ^^ operators
-#define CR_DEFINED 'p' // ^^defined - is symbol defined?
-#define CR_REFERENCED 'q' // ^^referenced - was symbol referenced?
-#define CR_STREQ 'v' // ^^streq - compare two strings
-#define CR_MACDEF 'w' // ^^macdef - is macro defined?
-#define CR_TIME 'x' // ^^time - DOS format time
-#define CR_DATE 'y' // ^^date - DOS format date
-#define CR_ABSCOUNT 'z' // ^^abscount - count the number of bytes defined in curent .abs section
+#define CR_DEFINED 'p' // ^^defined - is symbol defined?
+#define CR_REFERENCED 'q' // ^^referenced - was symbol referenced?
+#define CR_STREQ 'v' // ^^streq - compare two strings
+#define CR_MACDEF 'w' // ^^macdef - is macro defined?
+#define CR_TIME 'x' // ^^time - DOS format time
+#define CR_DATE 'y' // ^^date - DOS format date
+#define CR_ABSCOUNT 'z' // ^^abscount - count the number of bytes
+ // defined in curent .abs section
// Character Attributes
-#define ILLEG 0 // Illegal character (unused)
-#define DIGIT 1 // 0-9
-#define HDIGIT 2 // A-F, a-f
-#define STSYM 4 // A-Z, a-z, _~.
-#define CTSYM 8 // A-Z, a-z, 0-9, _~$?
-#define SELF 16 // Single-character tokens: ( ) [ ] etc
-#define WHITE 32 // Whitespace (space, tab, etc.)
-#define MULTX 64 // Multiple-character tokens
-#define DOT 128 // [bwlsBWSL] for what follows a `.'
+#define ILLEG 0 // Illegal character (unused)
+#define DIGIT 1 // 0-9
+#define HDIGIT 2 // A-F, a-f
+#define STSYM 4 // A-Z, a-z, _~.
+#define CTSYM 8 // A-Z, a-z, 0-9, _~$?
+#define SELF 16 // Single-character tokens: ( ) [ ] etc
+#define WHITE 32 // Whitespace (space, tab, etc.)
+#define MULTX 64 // Multiple-character tokens
+#define DOT 128 // [bwlsBWSL] for what follows a '.'
// Conditional assembly structures
IFENT {
#define MAJOR 1 // Major version number
#define MINOR 7 // Minor version number
-#define PATCH 0 // Patch release number
+#define PATCH 1 // Patch release number
#endif // __VERSION_H__