1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-29 01:49:19 +00:00

Allow address as target of goto

This commit is contained in:
Curtis F Kaylor 2018-12-03 16:27:25 -05:00
parent 748876aa64
commit 0ad6894a5b
5 changed files with 35 additions and 17 deletions

View File

@ -122,31 +122,38 @@ void prstrm(void) {
skpspc();
}
/* Process Address Reference */
/* Process Address Reference
* Args: adract = Address Action (adacts) *
* symbol = Symbol to Process */
void prcadr(int adract, char* symbol) {
DEBUG("Processing address '%s'\n", word)
strcpy(word,"#>(");
strcat(word,symbol);
strcat(word,")");
if (adract == 1) { asmlin("LDA", word); asmlin("PHA", ""); }
if (adract == ADPUSH) { asmlin("LDA", word); asmlin("PHA", ""); }
else asmlin("LDY", word);
strcpy(word,"#<(");
strcat(word,symbol);
strcat(word,")");
if (adract == 1) { asmlin("LDA", word); asmlin("PHA", ""); }
if (adract == ADPUSH) { asmlin("LDA", word); asmlin("PHA", ""); }
else asmlin("LDX", word);
}
/* Parse and Compile Address of Operator */
/* Parse and Compile Address of Operator *
* Args: adract = Address Action */
void prsadr(int adract) {
DEBUG("Parsing address\n", 0)
if (isnpre()) prsnum(0xFFFF);
else prsvar(FALSE, TRUE);
prcadr(adract, value); //Compile Address Reference
if (adract) prcadr(adract, value); //Compile Address Reference
else strcpy(word, value); //Save for Calling Routine
}
/* Parse and Create Anonymous String */
void prsstr(int adract) {
/* Parse and Create Anonymous String *
* Args: adract = Address Action *
* alwstr = Allow String */
void prsstr(int adract, int alwstr) {
if (!alwstr) ERROR("Illegal String Reference", 0, EXIT_FAILURE)
DEBUG("Parsing anonymous string\n", 0)
newlbl(vrname); //Generate Variable Name
value[0] = 0; //Use Variable Size 0
@ -154,15 +161,18 @@ void prsstr(int adract) {
prsdts(); //Parse Data String
setdat(); //Set Variable Data
varcnt++; //Increment Variable Counter
prcadr(adract, vrname); //Compile Address Reference
if (adract) prcadr(adract, vrname); //Compile Address Reference
else strcpy(word, vrname); //Save for Calling Routine
}
/* Check for and Process Address or String */
int chkadr(int adract) {
/* Check for and Process Address or String *
* Args: adract = Address Action *
* alwstr = Allow String */
int chkadr(int adract, int alwstr) {
DEBUG("Checking for Address or String\n", 0)
int result = TRUE;
if (look('&')) prsadr(adract);
else if (match('"')) prsstr(adract);
else if (match('"')) prsstr(adract, alwstr);
else result = FALSE;
skpspc();
return result;
@ -175,9 +185,9 @@ void prsfnc(char trmntr) {
pshtrm(); //Push Function Name onto Term Stack
skpchr(); //skip open paren
CCMNT('(');
if (!chkadr(0) && isxpre() || match('*')) {
if (!chkadr(ADLDYX, TRUE) && isxpre() || match('*')) {
if (!look('*')) prsxpr(0);
if (look(',') && !chkadr(0)) {
if (look(',') && !chkadr(ADLDYX, TRUE)) {
if (!look('*')) {
prstrm(); asmlin("LDY", term);
}

View File

@ -2,6 +2,8 @@
* C02 Expession Parsing Routines *
**********************************/
enum adacts {ADNONE, ADLDYX, ADPUSH};
char term[255]; //Term parsed from equation
char oprstk[MAXTRM]; //Operator Stack
@ -10,7 +12,7 @@ int trmidx; //Next Index in Stack
int trmcnt; //Number of total terms in current expression
int chkadr(int adract); //Check for and Process Address or String
int chkadr(int adract, int alwstr); //Check for and Process Address or String
void chkidx(); //Check for, Parse, and Process Index
void prcftm(); //Process First Term
void prsadr(int adract); //Parse and Compile Address of Operator

View File

@ -4,7 +4,7 @@
#define TF(x) (x) ? TRUE : FALSE;
enum stypes {LITERAL, VARIABLE, REGISTER, ARRAY, STRUCTURE, FUNCTION}; //Symbol Types
enum stypes {LITERAL, VARIABLE, REGISTER, ARRAY, STRUCTURE, FUNCTION, ADDRESS, INTEGER}; //Symbol Types
enum etypes {ETDEF, ETMAC}; //Definition Types
char nxtwrd[LINELEN]; //Next Word (from DEFINE lookup)

View File

@ -274,7 +274,7 @@ void pelse(void) {
/* parse and compile if statement */
void pgoto(void) {
DEBUG("Parsing GOTO statement\n", 0)
getwrd();
if (!chkadr(ADNONE, FALSE)) getwrd();
expect(';');
asmlin("JMP", word);
}
@ -333,7 +333,7 @@ void ppop(void) {
void ppush(void) {
DEBUG("Parsing PUSH statement\n", 0)
do {
if (!chkadr(1)) {
if (!chkadr(ADPUSH, TRUE)) {
prsxpr(0); //Parse Expression
asmlin("PHA",""); //Push Result on Stack
}

View File

@ -57,6 +57,12 @@ enum dtypes {DTBYTE, DTSTR, DTARRY}; //Variable Data Types
#define MTZP 4 //Zero Page
#define MTALGN 128 //Aligned
/*Value Parsing Flags (BitMask) */
#define ALWDEF 0 //Allow Default
#define ALWREG 1 //Allow Register
#define ALWCON 2 //Allow CONST Variable
#define ALWINT 4 //Allow Integer
int symdef(char *name); //Is Variable defined (TRUE or FALSE)
int rambas; //RAM Base Address (0=None)
int wrtbas; //Write Base Address (0=None)