diff --git a/a02.c b/a02.c index b460078..a188ebd 100644 --- a/a02.c +++ b/a02.c @@ -18,7 +18,7 @@ int orgadr; //Origin Address int curadr; //Current Address int lstadr; //List Address -struct sym {int block; char name[MAXLBL+1]; int bytes, value;}; +struct sym {int block; char name[MAXLBL+1]; int bytes, value, refrd;}; struct sym symbol; //Current Symbol struct sym symtbl[MAXSYM]; //Global Symbol Table int symcnt; //Number of Global Labels @@ -31,6 +31,8 @@ char cmmnt[MAXSTR]; //Assembly Line Comment char mcode[MAXSTR]; //Generated Bytes char strng[MAXSTR]; //Parsed String +int opridx; //Index into Operand + unsigned char token, opmod; //OpCode Token, Modifier unsigned int amode; //Addressing Modes int zpage, opval; //ZeroPage Flag, Operand Value @@ -41,10 +43,11 @@ char bytstr[5]; //String Representation of Byte char inplin[MAXSTR]; //Input Buffer char *linptr; //Pointer into Input Buffer int lineno; //Input File Line Number -int opridx; //Index into Operand -int passno; //Assembler Pass Number (1 or 2) int savlno; //Line Number (Saved) +int passno; //Assembler Pass Number (1 or 2) +int endasm; //End Assembly Flag + char prgnam[256]; //Assembler Path and Name (from Command Line) char inpnam[256]; //Input File Name char outnam[256]; //Output File Name @@ -114,6 +117,14 @@ void setsym(int value, int bytes) { symbol.value = value; if (bytes) symbol.bytes = bytes; else symbol.bytes = (value > 0xFF) ? 2 : 1; + symbol.refrd = FALSE; +} + +/* Add Character to Beginning of String */ +void pfxstr(char c, char* s) { + for (int i=strlen(s)+1; i; i--) + s[i] = s[i-1]; //Copy All Characters to the Right + s[0] = c; //Insert Character at Beginning } /* Parse Label from Input Line @@ -137,10 +148,8 @@ int plabel(void) { strcpy(symbol.name, label); setsym(curadr, 0); } - if (block) { - for (int i=strlen(label)+1; i; i--) label[i] = label[i-1]; - label[0] = '.'; - } + if (block) pfxstr('.', label); + skpspc(); //Skip to Mnemonic, Comment, or EOL return found; } @@ -205,6 +214,7 @@ struct sym *evlsym() { for (int i=0; name[i]; i++) if (opridxrefrd = TRUE; //Symbol was Referenced return result; } @@ -299,6 +309,16 @@ void asmwrd(void) { } while (cpychr(',')); } +/* Assemble FILL Pseudo-Op */ +void asmaln(void) { + if (DEBUG) puts("Assembling ALIGN Pseudo-Op"); + int size = evlopd(0xFFFF); if (size < 2) return; + if (DEBUG) printf("Aligning to %d Bytes\n", size); + int fill = size - (curadr % size); if (fill == size) return; + if (DEBUG) printf("Filling %d Bytes\n", fill); + for (int i=0; i