mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-22 01:31:33 +00:00
Added CPU Type and Numeric Literal String Escapes
This commit is contained in:
parent
0bd11dbaed
commit
2b5f96c7d0
@ -52,6 +52,7 @@ void init(void) {
|
||||
xsnvar[0] = 0; //Assigned X Variable Name
|
||||
ysnvar[0] = 0; //Assigned Y Variable Name
|
||||
subcnt = 0; //Include Subdirectories
|
||||
strcpy(cputyp, CPUARG); //Set CPU Type to Default Value
|
||||
strcpy(incdir, "../include/");
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ void pdrctv(void) {
|
||||
|
||||
void prolog(void) {
|
||||
DEBUG("Writing Assembly Prolog\n", 0)
|
||||
asmlin(CPUOP,CPUARG);
|
||||
asmlin(CPUOP,cputyp);
|
||||
setcmt("Program ");
|
||||
addcmt(srcnam);
|
||||
cmtlin();
|
||||
@ -130,12 +131,16 @@ int popt(int arg, int argc, char *argv[]) {
|
||||
strncpy (argstr, argv[arg], 31);
|
||||
if (strlen(argstr) != 2) ERROR("malformed option %s\n", argstr, EXIT_FAILURE)
|
||||
opt = toupper(argstr[1]);
|
||||
if (strchr("HS", opt)) {
|
||||
if (strchr("CHS", opt)) {
|
||||
if (++arg >= argc) ERROR("Option -%c requires an argument\n", opt, EXIT_FAILURE)
|
||||
strncpy(optarg, argv[arg], 31);
|
||||
}
|
||||
DEBUG("Processing Command Line Option -%c\n", argstr[1])
|
||||
switch (opt) {
|
||||
case 'C':
|
||||
strcpy(cputyp, optarg);
|
||||
DEBUG("CPU Type set to '%s'\n", cputyp)
|
||||
break;
|
||||
case 'H':
|
||||
strcpy(hdrnam, optarg);
|
||||
DEBUG("Header Name set to '%s'\n", hdrnam)
|
||||
|
@ -65,7 +65,10 @@ int savchr; //Holds nxtchr when switching input files
|
||||
int wrdlen; //Length of Parsed Word
|
||||
char word[LINELEN]; //Word parsed from source file
|
||||
char uword[LINELEN]; //Word converted to uppercase
|
||||
int pstlen; //Length of Parsed String
|
||||
char pstrng[LINELEN]; //String parsed fron source file
|
||||
char cmtasm[LINELEN]; //Assembly Language Comment Text
|
||||
char cputyp[LINELEN]; //CPU Type
|
||||
|
||||
char hdrnam[FNAMLEN]; //Header File Name
|
||||
char incdir[FNAMLEN]; //Include File Directory
|
||||
|
23
src/parse.c
23
src/parse.c
@ -81,12 +81,15 @@ void skpspc(void) {
|
||||
* otherwise FALSE */
|
||||
int look(char c) {
|
||||
int found;
|
||||
DEBUG("Looking for '%c', ", c);
|
||||
skpspc();
|
||||
found = match(c);
|
||||
if (found) {
|
||||
skpchr();
|
||||
CCMNT(c);
|
||||
DETAIL("Found\n", 0);
|
||||
}
|
||||
else DETAIL("Not found\n", 0);
|
||||
return found;
|
||||
}
|
||||
|
||||
@ -136,6 +139,8 @@ void getwrd(void) {
|
||||
while (isanum()) word[wrdlen++] = toupper(getnxt());
|
||||
word[wrdlen] = 0;
|
||||
ACMNT(word);
|
||||
DEBUG("Read word '%s'", word)
|
||||
DETAIL("Delimited by '%c'\n", nxtchr)
|
||||
}
|
||||
|
||||
/* Escape Character */
|
||||
@ -154,31 +159,41 @@ char escape(char c) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Escape Numeric Literal */
|
||||
char escnum(void) {
|
||||
DEBUG("Escaping numeric literal\n", 0);
|
||||
char c = prsnum(0xff);
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Get String *
|
||||
* Sets: word = parsed string
|
||||
* wrdlen = length of string (including terminator) */
|
||||
void getstr(void) {
|
||||
char strdel;
|
||||
int escnxt = FALSE;
|
||||
wrdlen = 0;
|
||||
pstlen = 0;
|
||||
DEBUG("Parsing string\n", 0)
|
||||
strdel = getnxt(); //Get String Delimiter
|
||||
CCMNT(strdel);
|
||||
while(!match(strdel) || escnxt) {
|
||||
if (isnl()) ERROR("String Not Terminated", 0, EXIT_FAILURE)
|
||||
CCMNT(nxtchr);
|
||||
if (escnxt) {
|
||||
word[wrdlen++] = escape(getnxt());
|
||||
if (isnpre()) pstrng[pstlen++] = escnum();
|
||||
else pstrng[pstlen++] = escape(getnxt());
|
||||
escnxt = FALSE;
|
||||
}
|
||||
else {
|
||||
if (match('\\')) escnxt = TRUE;
|
||||
else word[wrdlen++] = prcchr(nxtchr);
|
||||
else pstrng[pstlen++] = prcchr(nxtchr);
|
||||
skpchr();
|
||||
}
|
||||
}
|
||||
skpchr(); //Skip End Delimiter
|
||||
CCMNT(strdel);
|
||||
word[wrdlen] = 0;
|
||||
pstrng[pstlen] = 0;
|
||||
strcpy(word,pstrng); wrdlen=pstlen;
|
||||
}
|
||||
|
||||
/* Read Binary number from input file *
|
||||
|
Loading…
Reference in New Issue
Block a user