mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-12-01 14:51:52 +00:00
Allow address as target of goto
This commit is contained in:
parent
748876aa64
commit
0ad6894a5b
36
src/expr.c
36
src/expr.c
@ -122,31 +122,38 @@ void prstrm(void) {
|
|||||||
skpspc();
|
skpspc();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process Address Reference */
|
/* Process Address Reference
|
||||||
|
* Args: adract = Address Action (adacts) *
|
||||||
|
* symbol = Symbol to Process */
|
||||||
void prcadr(int adract, char* symbol) {
|
void prcadr(int adract, char* symbol) {
|
||||||
DEBUG("Processing address '%s'\n", word)
|
DEBUG("Processing address '%s'\n", word)
|
||||||
strcpy(word,"#>(");
|
strcpy(word,"#>(");
|
||||||
strcat(word,symbol);
|
strcat(word,symbol);
|
||||||
strcat(word,")");
|
strcat(word,")");
|
||||||
if (adract == 1) { asmlin("LDA", word); asmlin("PHA", ""); }
|
if (adract == ADPUSH) { asmlin("LDA", word); asmlin("PHA", ""); }
|
||||||
else asmlin("LDY", word);
|
else asmlin("LDY", word);
|
||||||
strcpy(word,"#<(");
|
strcpy(word,"#<(");
|
||||||
strcat(word,symbol);
|
strcat(word,symbol);
|
||||||
strcat(word,")");
|
strcat(word,")");
|
||||||
if (adract == 1) { asmlin("LDA", word); asmlin("PHA", ""); }
|
if (adract == ADPUSH) { asmlin("LDA", word); asmlin("PHA", ""); }
|
||||||
else asmlin("LDX", word);
|
else asmlin("LDX", word);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse and Compile Address of Operator */
|
/* Parse and Compile Address of Operator *
|
||||||
|
* Args: adract = Address Action */
|
||||||
void prsadr(int adract) {
|
void prsadr(int adract) {
|
||||||
DEBUG("Parsing address\n", 0)
|
DEBUG("Parsing address\n", 0)
|
||||||
if (isnpre()) prsnum(0xFFFF);
|
if (isnpre()) prsnum(0xFFFF);
|
||||||
else prsvar(FALSE, TRUE);
|
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 */
|
/* Parse and Create Anonymous String *
|
||||||
void prsstr(int adract) {
|
* 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)
|
DEBUG("Parsing anonymous string\n", 0)
|
||||||
newlbl(vrname); //Generate Variable Name
|
newlbl(vrname); //Generate Variable Name
|
||||||
value[0] = 0; //Use Variable Size 0
|
value[0] = 0; //Use Variable Size 0
|
||||||
@ -154,15 +161,18 @@ void prsstr(int adract) {
|
|||||||
prsdts(); //Parse Data String
|
prsdts(); //Parse Data String
|
||||||
setdat(); //Set Variable Data
|
setdat(); //Set Variable Data
|
||||||
varcnt++; //Increment Variable Counter
|
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 */
|
/* Check for and Process Address or String *
|
||||||
int chkadr(int adract) {
|
* Args: adract = Address Action *
|
||||||
|
* alwstr = Allow String */
|
||||||
|
int chkadr(int adract, int alwstr) {
|
||||||
DEBUG("Checking for Address or String\n", 0)
|
DEBUG("Checking for Address or String\n", 0)
|
||||||
int result = TRUE;
|
int result = TRUE;
|
||||||
if (look('&')) prsadr(adract);
|
if (look('&')) prsadr(adract);
|
||||||
else if (match('"')) prsstr(adract);
|
else if (match('"')) prsstr(adract, alwstr);
|
||||||
else result = FALSE;
|
else result = FALSE;
|
||||||
skpspc();
|
skpspc();
|
||||||
return result;
|
return result;
|
||||||
@ -175,9 +185,9 @@ void prsfnc(char trmntr) {
|
|||||||
pshtrm(); //Push Function Name onto Term Stack
|
pshtrm(); //Push Function Name onto Term Stack
|
||||||
skpchr(); //skip open paren
|
skpchr(); //skip open paren
|
||||||
CCMNT('(');
|
CCMNT('(');
|
||||||
if (!chkadr(0) && isxpre() || match('*')) {
|
if (!chkadr(ADLDYX, TRUE) && isxpre() || match('*')) {
|
||||||
if (!look('*')) prsxpr(0);
|
if (!look('*')) prsxpr(0);
|
||||||
if (look(',') && !chkadr(0)) {
|
if (look(',') && !chkadr(ADLDYX, TRUE)) {
|
||||||
if (!look('*')) {
|
if (!look('*')) {
|
||||||
prstrm(); asmlin("LDY", term);
|
prstrm(); asmlin("LDY", term);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
* C02 Expession Parsing Routines *
|
* C02 Expession Parsing Routines *
|
||||||
**********************************/
|
**********************************/
|
||||||
|
|
||||||
|
enum adacts {ADNONE, ADLDYX, ADPUSH};
|
||||||
|
|
||||||
char term[255]; //Term parsed from equation
|
char term[255]; //Term parsed from equation
|
||||||
|
|
||||||
char oprstk[MAXTRM]; //Operator Stack
|
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 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 chkidx(); //Check for, Parse, and Process Index
|
||||||
void prcftm(); //Process First Term
|
void prcftm(); //Process First Term
|
||||||
void prsadr(int adract); //Parse and Compile Address of Operator
|
void prsadr(int adract); //Parse and Compile Address of Operator
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#define TF(x) (x) ? TRUE : FALSE;
|
#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
|
enum etypes {ETDEF, ETMAC}; //Definition Types
|
||||||
|
|
||||||
char nxtwrd[LINELEN]; //Next Word (from DEFINE lookup)
|
char nxtwrd[LINELEN]; //Next Word (from DEFINE lookup)
|
||||||
|
@ -274,7 +274,7 @@ void pelse(void) {
|
|||||||
/* parse and compile if statement */
|
/* parse and compile if statement */
|
||||||
void pgoto(void) {
|
void pgoto(void) {
|
||||||
DEBUG("Parsing GOTO statement\n", 0)
|
DEBUG("Parsing GOTO statement\n", 0)
|
||||||
getwrd();
|
if (!chkadr(ADNONE, FALSE)) getwrd();
|
||||||
expect(';');
|
expect(';');
|
||||||
asmlin("JMP", word);
|
asmlin("JMP", word);
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ void ppop(void) {
|
|||||||
void ppush(void) {
|
void ppush(void) {
|
||||||
DEBUG("Parsing PUSH statement\n", 0)
|
DEBUG("Parsing PUSH statement\n", 0)
|
||||||
do {
|
do {
|
||||||
if (!chkadr(1)) {
|
if (!chkadr(ADPUSH, TRUE)) {
|
||||||
prsxpr(0); //Parse Expression
|
prsxpr(0); //Parse Expression
|
||||||
asmlin("PHA",""); //Push Result on Stack
|
asmlin("PHA",""); //Push Result on Stack
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,12 @@ enum dtypes {DTBYTE, DTSTR, DTARRY}; //Variable Data Types
|
|||||||
#define MTZP 4 //Zero Page
|
#define MTZP 4 //Zero Page
|
||||||
#define MTALGN 128 //Aligned
|
#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 symdef(char *name); //Is Variable defined (TRUE or FALSE)
|
||||||
int rambas; //RAM Base Address (0=None)
|
int rambas; //RAM Base Address (0=None)
|
||||||
int wrtbas; //Write Base Address (0=None)
|
int wrtbas; //Write Base Address (0=None)
|
||||||
|
Loading…
Reference in New Issue
Block a user