1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-06-01 05:41:34 +00:00

Updated x16/include .a02 files to use 65C02 opcodes

This commit is contained in:
Curtis F Kaylor 2019-11-14 23:56:33 -05:00
parent 7f4e98826c
commit cf56e15c01
31 changed files with 2121 additions and 1923 deletions

Binary file not shown.

Binary file not shown.

19
src/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/c02.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true
}
]
}

View File

@ -52,9 +52,17 @@ 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/");
}
/* Parse Pointer Dereference Assignment */
void ppntr(void) {
lsrtrn = FALSE; //Clear RETURN flag
if (xstmnt[0]) ERROR("Expected '%s' statement\n", xstmnt, EXIT_FAILURE)
prcasp(';');
}
/* Reads and parses the next Word in Source File */
void pword(void) {
lsrtrn = FALSE; //Clear RETURN flag
@ -82,7 +90,7 @@ void pdrctv(void) {
void prolog(void) {
DEBUG("Writing Assembly Prolog\n", 0)
asmlin(CPUOP,CPUARG);
asmlin(CPUOP,cputyp);
setcmt("Program ");
addcmt(srcnam);
cmtlin();
@ -110,6 +118,7 @@ void compile(void) {
else if (match('}')) endblk(TRUE); //End Multi-Line Program Block
else if (match('#')) pdrctv(); //Parse Directive
else if (match('/')) skpcmt(TRUE); //Skip Comment
else if (match('*')) ppntr(); //Parse Pointer
else if (isalph()) pword(); //Parse Word
else ERROR("Unexpected character '%c'\n", nxtchr, EXIT_FAILURE)
}
@ -130,12 +139,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)
@ -173,6 +186,16 @@ void pargs(int argc, char *argv[]) {
if (outnam[0]) DEBUG("outnam set to '%s'\n", outnam)
}
/* Validate CPU Type *
* Uses: cputype *
* Sets: cmos */
void chkcpu(void) {
if (strcmp(cputyp, "6502") == 0) cmos = FALSE;
else if (strcmp(cputyp, "65C02") == 0) cmos = TRUE;
else ERROR("Invalid CPU Type %s\n", cputyp, EXIT_FAILURE)
}
int main(int argc, char *argv[]) {
debug = TRUE; //Output Debug Info
gencmt = TRUE; //Generate Assembly Language Comments
@ -182,6 +205,7 @@ int main(int argc, char *argv[]) {
init(); //Initialize Global Variables
pargs(argc, argv); //Parse Command Line Arguments
chkcpu(); //Validate CPU Type
opnsrc(); //Open Source File
opnout(); //Open Output File

View File

@ -29,7 +29,7 @@
#define CPUARG "6502" //Target CPU Operand
#define ORGOP "ORG" //Origin Pseudo-Op
#define EQUOP "EQU" //Equate Pseudo-Op
#define BYTEOP "DC" //Define Byte Pseudo-Op
#define BYTEOP "BYTE" //Define Byte Pseudo-Op
#define STROP "DS" //Define String Pseudo-Op
#define ALNOP "ALIGN" //Align Pseudo-Op
#define USEGOP "SEG.U" //Uninitalized Segment Pseudo-Op
@ -49,6 +49,7 @@ void prttim(); //Print elapsed time
#define ERROR(fmt, val, err) {fprintf(stderr, fmt, val);exterr(err);}
int debug; //Print Debug Info (TRUE or FALSE)
int cmos; //Flag: Use 65C02 Instruction Set
int gencmt; //Generate Assembly Language Comments
char asmcmt[LINELEN]; //Processed Assembly Language Comment
@ -65,7 +66,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

View File

@ -53,6 +53,7 @@ void addfnc(void) {
infunc = TRUE; //Set Inside Function Definition Flag
DEBUG("Set infunc to %d\n", infunc)
setlbl(fncnam); //Set Function Entry Point
asmlin(LOCOP, ""); //Set Local Variables Boundary
if (prmtra[0]) asmlin("STA", prmtra); //Store First Parameter
if (prmtry[0]) asmlin("STY", prmtry); //Store Second Parameter
if (prmtrx[0]) asmlin("STX", prmtrx); //Store Third Parameter

View File

@ -20,6 +20,8 @@ void pshtrm(void) {
oprstk[trmidx] = oper; //Put Current Operator on Stack
strcpy(trmstk[trmidx], term); //Put Current Term on Stack
trmidx++; //Increment Stack Pointer
DEBUG("expr.pshtrm: Pushed term %s ", term)
DETAIL("and operator '%onto stack'\n", oper)
}
/* Pop Term and Operator off Stack */
@ -27,6 +29,8 @@ void poptrm(void) {
trmidx--; //Decrement Stack Pointer
strcpy(term, trmstk[trmidx]); //Restore Current Term from Stack
oper = oprstk[trmidx]; //Restore Current Operator from Stack
DEBUG("expr.pshtrm: Popped term %s ", term)
DETAIL("and operator '%c' off stack\n", oper)
}
/* Parse value (literal or identifier) *
@ -35,13 +39,14 @@ void poptrm(void) {
* Sets: value - the value (as a string) *
* valtyp - value type */
void prsval(int alwreg, int alwcon) {
DEBUG("Parsing value\n", 0)
DEBUG("expr.prsval: Parsing value\n", 0)
skpspc();
if (islpre()) prslit(); //Parse Literal
else if (isalph()) prsvar(alwreg, alwcon); //Parse Variable
else if (isbtop()) prsbop(); //Parse Byte Operator
else expctd("literal or variable");
DEBUG("Parsed value of type %d\n", valtyp)
DEBUG("expr.prsval: Parsed value %s ", value)
DETAIL("of type %d\n", valtyp)
skpspc();
}
@ -58,7 +63,7 @@ void prcmns(void) {
void prsidx(int clbrkt) {
expect('[');
prsval(TRUE, TRUE); //Parse Value, Allow Registers & Constants
DEBUG("Parsed array index '%s'\n", value)
DEBUG("expr.prsidx: Parsed array index '%s'\n", value)
if (clbrkt) expect(']');
}
@ -69,6 +74,7 @@ void prsidx(int clbrkt) {
* word - array index raw string *
* Sets: term - modified variable name */
void prcsix(void) {
DEBUG("expr.prcsix: Processing simple array index %s\n", word);
if (valtyp == LITERAL) {
strcat(term, "+");
strcat(term, word);
@ -80,10 +86,12 @@ void prcsix(void) {
else if (strcmp(value, "X")!=0) asmlin("LDX", value);
strcat(term, ",X");
}
DEBUG("expr.prcsix: Set term to %s\n", term);
}
/* Process Expression Array Index */
void prcxix(void) {
DEBUG("expr.prcxix: Processing Expression Array Index", 0)
pshtrm(); //Push Array Variable onto Term Stack
if (trmcnt) asmlin("PHA", ""); //Save Accumulator if not first term
prcftm(FALSE); //Process First Term of Expression
@ -92,6 +100,7 @@ void prcxix(void) {
if (trmcnt) asmlin("PLA", ""); //Restore Accumator if not first term
poptrm(); //Pop Array Variable off Term Stack
strcat(term, ",X");
DEBUG("expr.prcxix: Set term to %s\n", term);
}
/* Check for, Parse, and Process Index */
@ -111,15 +120,58 @@ void chkidx(void) {
}
}
/* Parse Pointer *
* Sets: term - Compiled Pointer */
void prsptr(void) {
DEBUG("Parsing pointer\n", 0)
expect('*'); //Pointer Dereference Operator
prsvar(FALSE,FALSE); //Parse Variable to Dereference
strcpy(term, value);
if (varble.modifr != MTZP) ERROR("Illegal dereference of non-pointer variable %s.\n", value, EXIT_FAILURE)
DEBUG("expr.prsptr: Set term to %s\n", term);
}
/* Process Pointer Index *
* Sets: term - Compiled Pointer */
void prcptx(char *index) {
DEBUG("expr.prcptx: Processing Dereferenced Pointer %s ", term)
DETAIL("index [%s]\n", index)
if (strcmp(index,"X")==0) ERROR("Illegal use of register X\n", 0, EXIT_FAILURE);
if (strcmp(index,"A")==0) asmlin("TAY", "");
else if (strcmp(index,"Y") != 0) asmlin("LDY", index);
}
/* Process Pointer *
* Sets: term - Compiled Pointer */
int prcptr(void) {
prsptr();
DEBUG("expr.prcptr: Dereferencing Pointer %s\n", value);
if (valtyp == ARRAY) {
prsidx(TRUE);
prcptx(value);
sprintf(word, "(%s),Y", term);
} else if (cmos) {
sprintf(word, "(%s)", term);
} else {
asmlin("LDY","0");
sprintf(word, "(%s),Y", term);
}
strcpy(term, word);
DEBUG("expr.prcptr: Set term to %s\n", term);
return FALSE; //Return Value Not an Integer
}
/* Parse Term in Expression *
* Sets: term - the term (as a string) */
* Sets: term - the term (as a string) *
* Returns: TRUE if term is an integer */
int prstrm(int alwint) {
DEBUG("Parsing term\n", 0)
if (match('*')) return prcptr(); //Parse and Deference Pointer
prsval(FALSE, TRUE); //Parse Value - Disallow Registers, Allow Constants
if (valtyp == FUNCTION) ERROR("Function call only allowed in first term\n", 0, EXIT_FAILURE)
strcpy(term, value);
if (valtyp == VARIABLE && prcvar(alwint)) return TRUE;
DEBUG("Parsed term %s\n", term)
if (valtyp == VARIABLE && prcivr(alwint)) return TRUE;
DEBUG("expr.prstrm: Parsed term %s\n", term)
chkidx(); //Check for Array Index
skpspc();
return FALSE;
@ -204,21 +256,42 @@ void prsbop(void) {
/* Parse Function Argument or Return Values */
void prsfpr(char trmntr) {
int pusha = 0; int pushy = 0; //A and Y Arguments Pushed
if (!chkadr(ADLDYX, TRUE) && isxpre() || match('.')) {
if (!look('.')) {if (prsxpf(0)) goto prsfne;}
if (look('.')) pusha = 255;
else {if (prsxpf(0)) goto prsfne;}
if (look(',') && !chkadr(ADLDYX, TRUE)) {
if (!look('.')) {
if (look('.')) {
pushy = -1;
}
else {
if (look('(')) {
if (pusha==0) {pusha = 1; asmlin("PHA","");} //Save A on Stack
prsxpr(')'); asmlin("TAY", ""); //Evaluate Expression, and Copy to Y
}
else {
if (prstrm(TRUE)) goto prsfne;
asmlin("LDY", term);
}
}
if (look(',')) {
if (look('(')) {
if (pusha==0) {pusha = 1; asmlin("PHA","");} //Save A on Stack
if (pushy==0) {pushy = 1; asmlin("PHA",""); asmlin("PHY","");} //Save Y on Stack
prsxpr(')'); asmlin("TAX", ""); //Evaluate Expression, and Copy to X
}
else {
prsval(FALSE, TRUE); //Parse Value - Disallow Registers, Allow Constants
if (valtyp > VARIABLE) ERROR("Illegal Value Function Argument\n", 0, EXIT_FAILURE);
if (valtyp == VARIABLE && vartyp != VTCHAR) ERROR("Illegal Variable Type\n", 0, EXIT_FAILURE);
asmlin("LDX", value); }
asmlin("LDX", value);
}
}
}
}
prsfne:
if (pushy==1) {asmlin("PLA",""); asmlin("TAY","");} //Pull Y Off Stack
if (pusha==1) asmlin("PLA",""); //Pull A Off Stack
expect(trmntr);
}
@ -244,8 +317,10 @@ void prcvri(void) {
asmlin("LDY", value);
}
/* Process Variable in Term */
int prcvar(int alwint) {
/* Process Integer Variable in Term *
* Args: alwint = Allow Integer-Like Variable *
* Returns: Integer-Like Variable Processed - TRUE/FALSE */
int prcivr(int alwint) {
switch (vartyp) {
case VTINT:
if (!alwint) ERROR("Illegal Use of Integer Variable %s\n", word, EXIT_FAILURE)
@ -268,7 +343,7 @@ int prcvar(int alwint) {
int prcftm(int alwint) {
DEBUG("Processing first term '%s'\n", value)
strcpy(term, value);
if (valtyp == VARIABLE && prcvar(alwint)) return TRUE;
if (valtyp == VARIABLE && prcivr(alwint)) return TRUE;
if (valtyp == FUNCTION) prsfnc(0); //Parse Expression Function
else if (wordis("A")) return FALSE;
else if (wordis("X")) asmlin("TXA", "");
@ -280,6 +355,12 @@ int prcftm(int alwint) {
/* Parse first term of expession *
* First term can include function calls */
int prsftm(int alwint) {
DEBUG("Parsing first term\n", 0)
if (match('*')) {
prcptr(); //Parse and Deference Pointer
asmlin("LDA", term);
return FALSE;
}
prsval(TRUE, TRUE); //Parse Value, Allow Registers & Constants
return prcftm(alwint);
}
@ -355,6 +436,7 @@ void prsxpi(char trmntr, int asmxpr) {
prsvar(FALSE, TRUE);
if (valtyp == FUNCTION) {
strcpy(term, value);
DEBUG("expr.prsxpi: Set term to %s\n", term)
prsfnc(0); //Parse Expression Function
} else if (valtyp == STRUCTURE) {
prsmbr(value);

View File

@ -15,14 +15,16 @@ int trmcnt; //Number of total terms in current expression
int chkadr(int adract, int alwstr); //Check for and Process Address or String
void chkidx(); //Check for, Parse, and Process Index
int prcftm(int alwint); //Process First Term
void prcptx(char *index); //Process Pointer Index
void prcvri(void); //Process Integer Variable
int prcvar(int alwint); //Process Variable in Term
int prcivr(int alwint); //Process Integer Variable in Term
void prsadr(int adract); //Parse and Compile Address of Operator
void prsbop(void); //Parse Byte Operator
void prsval(int alwreg, int alwcon); //Parse Value
void prsfnc(char trmntr); //Parse function call
void prsfpr(char trmntr); //Parse Function Paraeters or Return
void prsidx(); //Parse Array Index
void prsptr(void); //Parse Pointer
int prstrm(int alwint); //Parse Term in Expression
void prsrxp(char trmntr); //Parse Rest of Expression
int prsxpf(char trmntr); //Parse Expression in Function Call

View File

@ -37,8 +37,8 @@ void pincnm(void) {
sublen[subidx] = strlen(subnam[subidx]);
subnam[subidx][sublen[subidx]++] = '/';
}
dlmtr = '>';
}
dlmtr = '>';
}
else if (dlmtr != '"')
ERROR("Unexpected character '%c' after include\n", dlmtr, EXIT_FAILURE)
@ -86,7 +86,7 @@ void pdefin(void) {
/* Parse ASCII Subdirective */
void pascii(void) {
getwrd(); //Get Pragma Subdirective
getwrd(); //Get Subdirective Argument
DEBUG("Parsing subdirective '%s'\n", word)
if (wordis("INVERT"))
invasc = TRUE;
@ -146,7 +146,7 @@ void pprgma(void) {
else if (wordis("ORIGIN"))
porign(); //Parse Origin
else if (wordis("PADDING"))
ppddng(); //Parse Origin
ppddng(); //Parse Padding
else if (wordis("RAMBASE"))
prambs(); //Parse RamBase
else if (wordis("VARTABLE"))

View File

@ -13,6 +13,8 @@
#include "asm.h"
#include "parse.h"
#include "label.h"
#include "expr.h"
#include "stmnt.h"
/* Various tests against nxtchr */
int match(char c) {return TF(nxtchr == c);}
@ -81,12 +83,15 @@ void skpspc(void) {
* otherwise FALSE */
int look(char c) {
int found;
DEBUG("parse.look: 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 +141,8 @@ void getwrd(void) {
while (isanum()) word[wrdlen++] = toupper(getnxt());
word[wrdlen] = 0;
ACMNT(word);
DEBUG("parse.getwrd: Read word '%s' ", word)
DETAIL("delimited by '%c'\n", nxtchr)
}
/* Escape Character */
@ -154,31 +161,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 *
@ -357,21 +374,24 @@ void poperr(char* name) {
}
/* Process Post Operator */
void prcpst(int isint, char* name, char *index) {
DEBUG("Processing post operation '%c'\n", oper)
void prcpst(int isint, char* name, char *index, char indtyp, char ispntr) {
DEBUG("parse.prcpst: Processing post operation '%c'\n", oper)
if (ispntr) ERROR("Post Operation on dereferenced pointer %s not supported\n", name, EXIT_FAILURE)
//sprintf(word,"(%s),Y", name); strcpy(name, word); }
char name1[VARLEN+3];
strcpy(name1, name); strcat(name1, "+1");
if (strlen(index)) {
asmlin("LDX", index);
strcat(name,",X");
if (ispntr) prcptx(index); //Process Pointer Index
else prcidx(indtyp, name, index); //Process Index
}
else if (ispntr) asmlin("LDY","0");
switch(oper) {
case '+':
if (strcmp(name, "X")==0) asmlin("INX", "");
else if (strcmp(name, "Y")==0) asmlin("INY", "");
else if (strcmp(name, "A")==0) poperr(name); //65C02 supports implicit INC, 6502 does not
else if (strcmp(name, "A")==0 && !cmos) poperr(name); //65C02 supports implicit INC, 6502 does not
else {
asmlin("INC", name);
asmlin("INC", word);
if (isint) {
newlbl(skplbl);
asmlin("BNE", skplbl);
@ -383,7 +403,7 @@ void prcpst(int isint, char* name, char *index) {
case '-':
if (strcmp(name, "X")==0) asmlin("DEX", "");
else if (strcmp(name, "Y")==0) asmlin("DEY", "");
else if (strcmp(name, "A")==0) poperr(name); //65C02 supports implicit DEC, 6502 does not
else if (strcmp(name, "A")==0 && !cmos) poperr(name); //65C02 supports implicit DEC, 6502 does not
else {
if (isint) {
newlbl(skplbl);
@ -419,7 +439,7 @@ void prcpst(int isint, char* name, char *index) {
}
/* Parse Post Operator */
int prspst(char trmntr, int isint, char* name, char* index) {
int prspst(char trmntr, int isint, char* name, char* index, char indtyp, char ispntr) {
oper = getnxt();
CCMNT(oper);
DEBUG("Checking for post operation '%c'\n", oper)
@ -427,7 +447,7 @@ int prspst(char trmntr, int isint, char* name, char* index) {
skpchr();
CCMNT(oper);
expect(trmntr);
prcpst(isint, name, index); //Process Post-Op
prcpst(isint, name, index, indtyp, ispntr); //Process Post-Op
return 0;
}
DEBUG("Not a post operation\n", 0)

View File

@ -55,7 +55,7 @@ int prsbyt(); //Parse Numeric Byte
void prslit(); //Parse Literal
int prsnum(int maxval); //Parse Numeric
void prsopr(); //Parse Arithmetic Operator
int prspst(char trmntr, int isint, char* name, char* index); //Parse Post Operator
int prspst(char trmntr, int isint, char* name, char* index, char indtyp, char ispntr); //Parse Post Operator
int psizof(void); //Parse SizeOf Operator
int pidxof(void); //Parse SizeOf Operator
void skpchr(); //Skip Next Character

View File

@ -21,6 +21,7 @@
void bgnblk(char blkchr) {
DEBUG("Beginning program block\n", 0)
if (blkchr) {
DEBUG("Expecting Block Delimiter '%c'\n", blkchr);
expect(blkchr);
inblck = TRUE;
}
@ -72,42 +73,52 @@ void prcidx(int idxtyp, char *name, char *index)
/* Set word to assignment variable *
* adding write offset (if set) */
void setasn(char *name) {
strcpy(word, name);
void setasn(char *name, char ispntr) {
if (ispntr) strcpy(word,"(");
else word[0] = 0;
strcat(word, name);
if (wrtofs[0]) strcat(word, wrtofs);
if (ispntr) strcat(word,")");
}
void prcixy(char rgstr, char* idx, int ivt) {
DEBUG("Processing %c register indexed assignment\n", rgstr)
if (strlen(idx)) { //Process X variable Index
if (ivt != LITERAL) {
asmlin("PHA", ""); //Save Accumulator
if (rgstr == 'X') asmlin("TXA", ""); //Transfer Return Value to Accumulator
else asmlin("TYA", "");
prcidx(ivt, word, idx); //Process Index
asmlin("STA", word); //Store Return Value
asmlin("PLA", ""); //Restore Accumulator
} else {
prcidx(ivt, word, idx); //Process Index
if (rgstr == 'X') asmlin("STX", word); //Store Return Value
else asmlin("STY", word);
}
}
}
/* Process Assignment of X and Y variables */
void prcaxy(void) {
DEBUG("Processing X assignment variable '%s'\n", xsnvar)
if (xsnvar[0]) {
setasn(xsnvar);
if (strlen(xsnidx)) { //Process X variable Index
if (xsnivt != LITERAL) {
asmlin("PHA", ""); //Save Accumulator
asmlin("TXA", ""); //Transfer Return Value to Accumulator
prcidx(xsnivt, word, xsnidx); //Process Index
asmlin("STA", word); //Store Return Value
asmlin("PLA", ""); //Restore Accumulator
} else {
prcidx(xsnivt, word, xsnidx); //Process Index
asmlin("STX", word); //Store Return Value
}
}
setasn(xsnvar, FALSE);
if (strlen(xsnidx)) prcixy('X', xsnidx, xsnivt); //Process Index
else asmlin("STX", word); //Store Return Value
xsnvar[0] = 0;
}
DEBUG("Processing Y assignment variable '%s'\n", ysnvar)
if (ysnvar[0]) {
setasn(ysnvar);
if (strlen(ysnidx)) prcidx(ysnivt, word, ysnidx); //Process Index
asmlin("STY", word); //Store Return Value
setasn(ysnvar, FALSE);
if (strlen(ysnidx)) prcixy('Y', ysnidx, ysnivt); //Process Index
else asmlin("STY", word); //Store Return Value
ysnvar[0] = 0;
}
}
/* Process Assignment */
void prcasn(char trmntr) {
void prcasn(char trmntr, char ispntr) {
expect('=');
if (look('(')) prssif(trmntr); //Parse Shortcut If
else prsxpr(trmntr); //Parse Expression
@ -117,8 +128,15 @@ void prcasn(char trmntr) {
else if (strcmp(asnvar, "Y")==0) asmlin("TAY", "");
else if (strcmp(asnvar, "A")==0) return;
DEBUG("Processing assignment variable '%s'\n", asnvar)
setasn(asnvar);
if (asnidx[0]) prcidx(asnivt, word, asnidx); //Process Index
setasn(asnvar, ispntr);
if (asnidx[0]) {
if (ispntr) prcptx(asnidx); //Process Pointer Index
else prcidx(asnivt, word, asnidx); //Process Index
}
else if (ispntr && !cmos) {
strcat(word, ",Y");
asmlin("LDY","0");
}
asmlin("STA", word); //Store Return Value
}
@ -138,10 +156,30 @@ int getidx(char* idx) {
prsidx(TRUE); //Parse Array Index
if (valtyp == LITERAL) strncpy(idx, word, VARLEN);
else strncpy(idx, value, VARLEN);
DEBUG("Parsed index %s\n", idx)
DEBUG("stmnt.getidx: Parsed index %s\n", idx)
return valtyp;
}
/* Process Accumulator Assignment Variable */
int prcava(char *name, char trmntr, char ispntr) {
strcpy(asnvar, name);
asntyp = valtyp; //Set Assigned Variable Type
DEBUG("stmnt.prcava: Set STA variable to %s\n", asnvar)
if (asntyp == VARIABLE && look(';')) {
asmlin("STA", asnvar);
return TRUE;
}
if (asntyp == ARRAY) asnivt = getidx(asnidx); //Get Array Index and Type
else asnidx[0] = 0;
if (ispntr && strcmp(asnidx, "X") == 0) ERROR("Illegal use of register X\n", 0, EXIT_FAILURE)
DEBUG("stmnt.prcava: Set STA index to '%s'", asnidx) DETAIL(" and type to %d\n", asnivt)
if (ispopr()) {
if (prspst(trmntr, FALSE, asnvar, asnidx, asnivt, ispntr)) expctd("post operator");
return TRUE;
}
return FALSE;
}
/* Process Assignment Variable(s) */
void prcavr(char trmntr) {
chksym(TRUE, FALSE, word);
@ -149,24 +187,11 @@ void prcavr(char trmntr) {
strcpy(vrname, word); //save variable to assign to
if (valtyp == STRUCTURE) prsmbr(vrname); //Updates word and vartyp
if (vartyp == VTINT) {
if (ispopr()) {if (prspst(trmntr, TRUE, vrname, "")) expctd("post operator");}
if (ispopr()) {if (prspst(trmntr, TRUE, vrname, "", 0, FALSE)) expctd("post operator");}
else prcasi(trmntr); //Process Integer Assignment
return;
}
strcpy(asnvar, vrname);
asntyp = valtyp; //Set Assigned Variable Type
DEBUG("Set STA variable to %s\n", asnvar)
if (asntyp == VARIABLE && look(';')) {
asmlin("STA", asnvar);
return;
}
if (asntyp == ARRAY) asnivt = getidx(asnidx); //Get Array Index and Type
else asnidx[0] = 0;
DEBUG("Set STA index to '%s'", asnidx) DETAIL(" and type to %d\n", asnivt)
if (ispopr()) {
if (prspst(trmntr, FALSE, asnvar, asnidx)) expctd("post operator");
return;
}
if (prcava(vrname, trmntr, FALSE)) return;
if (look(',')) {
if (asntyp == REGISTER) ERROR("Register %s not allowed in plural assignment\n", asnvar, EXIT_FAILURE)
prsvar(FALSE, FALSE); //get variable name
@ -184,7 +209,7 @@ void prcavr(char trmntr) {
else xsnidx[0] = 0;
}
}
prcasn(trmntr);
prcasn(trmntr, FALSE);
}
/* Parse 'asm' String Parameter */
@ -209,12 +234,23 @@ void pasm(void) {
asmlin(opcode, word);
}
/* Parse and Compile Assignment of Pointer */
void prcasp(char trmntr) {
prsptr(); //Parse Pointer Dereference
DEBUG("stmnt.prcasp: Processing assignment to dereferenced pointer %s\n", value)
if (prcava(value, trmntr, TRUE)) return; //Process Accumulator Assignment Variable
prcasn(trmntr, TRUE);
}
/* Parse and Compile an Assignment */
void prsasn(char trmntr) {
if (match('*')) prcasp(trmntr);
else {
getwrd(); //Get Variable to be Assigned
DEBUG("Parsing assignment of word %s\n", word)
prcavr(trmntr);
}
}
/* parse and compile 'break'/'continue' statement */
void pbrcnt(int lbflag)
@ -372,11 +408,16 @@ void ppush(void) {
}
/* parse and compile return statement */
void pretrn(void) {
void pretrn(int INTRPT) {
DEBUG("Parsing RETURN statement\n", 0)
skpspc();
if (INTRPT) {
expect(';');
asmlin("RTI", "");
} else {
prsfpr(';'); //Parse Function Return Valuea
asmlin("RTS", "");
}
lsrtrn = TRUE; //Set RETURN flag
}
@ -524,8 +565,10 @@ void pstmnt(void) {
ppop();
else if (wordis("PUSH"))
ppush();
else if (wordis("RESUME"))
pretrn(TRUE);
else if (wordis("RETURN"))
pretrn();
pretrn(FALSE);
else
prssym();
if (lblcnt && !inblck) {

View File

@ -17,5 +17,7 @@ char xstmnt[LINELEN]; //Expected Statement
void bgnblk(char blkchr); //End Program Block
void endblk(int blkflg); //End Program Block
void prcasp(char trmntr); //Process Pointer Assignment
void prcidx(int idxtyp, char *name, char *index);
void pdowhl(); //Parse and Compile WHILE after DO
void pstmnt(); //Parse and Compile Program Statement

View File

@ -21,7 +21,7 @@
* varcnt if not found *
* Returns: TRUE if found, otherwise FALSE */
int fndvar(char *name) {
DEBUG("Looking up variable '%s'\n", name)
DEBUG("vars,fndvar: Looking up variable '%s'\n", name)
for (varidx=0; varidx<varcnt; varidx++) {
if (strcmp(vartbl[varidx].name, name) == 0) {
memcpy(&varble, &vartbl[varidx], sizeof(varble));
@ -37,7 +37,7 @@ int fndvar(char *name) {
* sctcnt if not found *
* Returns: TRUE if found, otherwise FALSE */
int fndstc(char *name) {
DEBUG("Looking up struct '%s'\n", name)
DEBUG("vars.fndstc: Looking up struct '%s'\n", name)
for (stcidx=0; stcidx<stccnt; stcidx++)
if (strcmp(strcts[stcidx].name, name) == 0) return TRUE;
return FALSE;
@ -48,7 +48,7 @@ int fndstc(char *name) {
* stmcnt if not found *
* Returns: TRUE if found, otherwise FALSE */
int fndmbr(int idx, char *name) {
DEBUG("Looking up member '%s'\n", word)
DEBUG("vars.fndmbr: Looking up member '%s'\n", word)
for (mbridx=0; mbridx<mbrcnt; mbridx++) {
if (membrs[mbridx].strcti != idx) continue;
if (strcmp(membrs[mbridx].name, name) == 0) {
@ -88,7 +88,7 @@ void prcmbr(char* name) {
getwrd(); //Get Member Name
valtyp = gettyp(); //Determine Variable Type
if (valtyp == FUNCTION) ERROR("Illegal Function Reference\n", 0, EXIT_FAILURE)
DEBUG("Checking for member %s", word) DETAIL(" with struct index %d\n", stcidx)
DEBUG("vars.prcmbr: Checking for member %s", word) DETAIL(" with struct index %d\n", stcidx)
if (!fndmbr(stcidx, word)) ERROR("Struct does Not Contain Member %s\n", word, EXIT_FAILURE)
mbrofs += membr.offset; //Get Member Offet in Struct
}
@ -117,7 +117,7 @@ void prsvrw(int alwreg, int alwcon) {
valtyp = gettyp(); //Determine Variable Type
if (valtyp != FUNCTION) chksym(alwreg, alwcon, word);
strcpy(value, word);
DEBUG("Parsed variable '%s'\n", value)
DEBUG("vars.prsvrw: Parsed variable '%s'\n", value)
if (valtyp == STRUCTURE) prsmbr(value);
}
@ -143,7 +143,7 @@ void reqvar(int alwary) {
* Returns: variable size (as integer */
int pidxof(void) {
expect('?'); //Check for and Skip SizeOf Operator
DEBUG("Parsing IndexOf operator", 0);
DEBUG("vars.pidxof: Parsing IndexOf operator", 0);
mbridx = -1; //Set Member Index to None
reqvar(FALSE); //Parse Variable Name to get Size Of
if (mbridx > -1) {
@ -159,7 +159,7 @@ int pidxof(void) {
* Returns: variable size (as integer */
int psizof(void) {
expect('@'); //Check for and Skip SizeOf Operator
DEBUG("Parsing SizeOf operator", 0);
DEBUG("vars.pdizof: Parsing SizeOf operator", 0);
mbridx = -1; //Set Member Index to None
reqvar(FALSE); //Parse Variable Name to get Size Of
if (mbridx > -1) {
@ -181,7 +181,7 @@ int psizof(void) {
/* Parse Data Array */
void prsdta(void) {
DEBUG("Parsing Array Data\n", 0)
DEBUG("vars.prsdta: Parsing Array Data\n", 0)
int i;
dtype = DTARRY;
expect('{');
@ -202,7 +202,7 @@ void prsdts(void) {
dtype = DTSTR;
getstr();
strcpy(value, word);
DEBUG("Parsed Data String '%s'\n", value)
DEBUG("vars.prsdts: Parsed Data String '%s'\n", value)
}
/* Store variable data *
@ -212,34 +212,34 @@ void prsdts(void) {
void setdat(void) {
int i;
if (dtype == DTBYTE) {
DEBUG("Setting variable data to '%d'\n", litval)
DEBUG("vars.setdat: Setting variable data to '%d'\n", litval)
dlen = 1;
datvar[dsize++] = litval;
}
else if (dtype == DTINT) {
DEBUG("Setting variable data to '%d'\n", litval)
DEBUG("vars.setdat: Setting variable data to '%d'\n", litval)
dlen = 2;
datvar[dsize++] = litval & 0xFF;
datvar[dsize++] = litval >> 8;
}
else if (dtype == DTARRY) {
DEBUG("Setting variable data to array of length %d\n", dlen)
DEBUG("vars.setdat: Setting variable data to array of length %d\n", dlen)
for (i=0; i<dlen; i++) datvar[dsize++] = dattmp[i];
}
else {
DEBUG("Setting variable data to '%s'\n", value)
DEBUG("vars.setdat: Setting variable data to '%s'\n", value)
dlen = strlen(value);
for (i=0; i<dlen; i++) datvar[dsize++] = value[i];
}
datlen[varcnt] = dlen;
dattyp[varcnt] = dtype;
DEBUG("Total data allocated: %d bytes\n", dsize)
DEBUG("vars.setdat: Total data allocated: %d bytes\n", dsize)
}
/* Parse and store variable data */
void prsdat(int m, int t) {
if ((m & MTCONST) == 0) ERROR("Initialization allowed only on variables declared CONST\n", 0, EXIT_FAILURE);
DEBUG("Parsing variable data\n", 0)
DEBUG("vars.prsdat: Parsing variable data\n", 0)
skpspc();
if (t == VTINT) {dtype = DTINT; litval = prsnum(0xFFFF); } //Parse Integer
else if (islpre()) {dtype = DTBYTE; prslit(); } //Parse Data Literal
@ -253,7 +253,7 @@ void prsdat(int m, int t) {
* Uses: vrname - variable name *
* value - variable size */
void setvar(int m, int t) {
DEBUG("Added variable '%s' ", vrname);
DEBUG("vars.setvar: Added variable '%s' ", vrname);
strncpy(vartbl[varcnt].name, vrname, VARLEN);
vartbl[varcnt].modifr = m;
vartbl[varcnt].type = t;
@ -294,17 +294,17 @@ void addvar(int m, int t) {
}
else {
if (t == VTSTRUCT) {
DEBUG("Setting variable size to %d\n", strct.size)
DEBUG("vars.addvar: Setting variable size to %d\n", strct.size)
sprintf(value, "%d", strct.size);
} else if (t == VTINT) {
DEBUG("Setting variable size to %d\n", 2)
DEBUG("vars.addvar: Setting variable size to %d\n", 2)
sprintf(value, "%d", 2);
} else if (match('[')) {
t = VTARRAY; //Set Type to Array
CCMNT('[')
skpchr();
if (alcvar) {
DEBUG("Parsing array size\n", 0)
DEBUG("vars.addvar: Parsing array size\n", 0)
sprintf(value, "%d", prsnum(0xFF) + 1);
}
expect(']');

View File

@ -25,7 +25,7 @@ RGBCLR: LSR ;Divide Red Value by 16
LSR
ORA TEMP0 ;Combine with Green
TAX ;and Return as LSB
.DC $7A ;PLY Return Red as MSB
PLY ;Return Red as MSB
RTS
;clrrgb(c) - Convert Palette Color to RGB Values
@ -34,7 +34,7 @@ RGBCLR: LSR ;Divide Red Value by 16
;Returns: A = Red Value (0-255)
; Y = Green Value (0-255)
; X = Blue Value (0-255)
CLRRGB: .DC $5A ;PHY Save MSB
CLRRGB: PHY ;Save MSB
TXA ;Copy LSB into Accumulator
AND #$F0 ;Isolate Green Value
TAY ;and Return in Y
@ -73,7 +73,7 @@ GETCLN: LDX $9F25 ;Get Current Data Port
; Y = Green Value (0-255)
; X = Blue Value (0-255)
GETRGB: JSR GETCLN ;Get Next Color Entry
JMP CLRRGB ;Convert to RGB and Return
BRA CLRRGB ;Convert to RGB and Return
;setclr(idx) - Set Color Entry idx in Palette
;Args: A = Color Entry Index
@ -106,7 +106,7 @@ SETCLN: TXA ;Copy LSB to Accumulator
;Destroys: TEMP0
;Affects: A,Y,X
SETRGB: JSR RGBCLR ;Convert RGB to Vera Color Value
JMP SETCLN ;and Write to Next Palette Entry
BRA SETCLN ;and Write to Next Palette Entry
;setidy(idx) - Set Palette Index and Entry Count
;Args: A = Palette Index

View File

@ -86,7 +86,7 @@ GETVIM: .DC $04 ;Chroma Disable Bit Mask
GETVSP: LDA #7 ;Set Reg Offset to Vertical Stop
JSR GETHVS ;Read Registers
LSR ;Shift Left One Bit
JMP GETVSS ;Then Four More Bits and Mask
BRA GETVSS ;Then Four More Bits and Mask
;getvsr() - Get Vertical Start
;Affects: A
@ -108,7 +108,7 @@ GETHSP: LDA #5 ;Set Lookup Index to Horizontal Start
JSR GETHVS ;Read Registers
LSR ;Shift Left Two Bits
LSR
JMP GETHSS ;then Mask and Return
BRA GETHSS ;then Mask and Return
;gethsr() - Get Horizontal Start
;Affects: A
@ -129,7 +129,7 @@ GETHVS: JSR GETDCB ;Read LSB from Register
LDA #8 ;Load Register Offset for High Bits
STA $9F20 ;Set As Address LSB
LDA $9F23,X ;and Read High Bits into A
.DC $FA ;PLX ;Restore LSB into X
PLX ;Restore LSB into X
RTS
;setbdr() - Set Border Color

View File

@ -263,7 +263,7 @@ SETLRM: AND TEMP1 ;Apply Mask
;Returns: A = Contents of Register
; X = Current Data Port
SETLRR: ;.dc $ff
.DC $5A ;PHY Save Value to Write
PHY ;Save Value to Write
JSR GETLRP ;Get Layer Page in Y
PLA ;Restore Value to Write
JMP SETREG ;and Write to Register
@ -278,7 +278,7 @@ SETLRR: ;.dc $ff
SETLRS: ;.dc $ff
JSR SAVREG ;Save Layer, Value, and Mask
JSR GETLRS ;Get Layer Size Register
JMP SETLRM ;Mask in Value and Write Back
BRA SETLRM ;Mask in Value and Write Back
;setmod() - Set Layer 0/1 Mode
;Args: A = Layer (0/1)

View File

@ -24,7 +24,7 @@ ASLADR: ASL TEMP1 ;Shift LSB Left
ROL TEMP0 ;Rotate Carry Left into LSB
DEX ;Decrement Shift Count
BNE ASLADR ;and Loop if Not Zero
JMP RESREG ;Return Bank, MSB, LSB
BRA RESREG ;Return Bank, MSB, LSB
;chkadr(opts,addr) - Check Vera Address
;Args: A = Bank + Auto-Increment
@ -163,7 +163,7 @@ SETVRB: STA TEMP1 ;Save Bit Pattern
JSR GETVRG ;Read Register
AND TEMP0 ;Mask Result
ORA TEMP1 ;Set Bits
JMP SETBYN ;Write Back to Register
BRA SETBYN ;Write Back to Register
;setreg(addr) - Set Register
;Args: A = Value to Write

View File

@ -28,7 +28,7 @@ MAXSPR EQU 128 ;Maximum Sprite Index
ADDSPD: JSR SAVREG ;Save Sprite Index, Addend
JSR GETSPD ;Read Sprite Address Register
JSR ADDTXY ;Add Number to Address
JMP SETSTD ;Write Sprite (TEMP0) Address Register
BRA SETSTD ;Write Sprite (TEMP0) Address Register
;subspd(index,number) - Decrement Sprite Address Register
;Args: A = Sprite Index
@ -37,7 +37,7 @@ ADDSPD: JSR SAVREG ;Save Sprite Index, Addend
SUBSPD: JSR SAVREG ;Save Sprite Index, Addend
JSR GETSPD ;Read Sprite Address Register
JSR ADDTXY ;Add Number to Address
JMP SETSTD ;Write Sprite (TEMP0) Address Register
BRA SETSTD ;Write Sprite (TEMP0) Address Register
;clrspr(index) - Set Sprite Attributes
;Args: A = Sprite Index
@ -133,7 +133,7 @@ GETSXF: RTS
GETSPW: JSR GETSPS ;Get Sprite Size Register
ASL ;Shift Left 2 Bits
ASL
JMP GETSP6 ;Then Right 6 Bits
BRA GETSP6 ;Then Right 6 Bits
;getsph(index) - Get Sprite Height Specifier
;Args: A = Sprite Index
@ -327,7 +327,7 @@ SETSPZ: PHA ;Save Sprite Depth
SETSP2: ASL ;Move to Bits 2 and 3
ASL
STX TEMP1 ;Save Bit Mask
JMP SETSP6 ;Set Bits in Control Register
BRA SETSP6 ;Set Bits in Control Register
;getspu(index) - Get Sprite Width, Height, and Mode
;Args: A = Sprite Index
@ -344,7 +344,7 @@ GETSPU: STA TEMP0 ;Save Sprite Index
LDA TEMP0 ;Retrieve Sprite Index
JSR GETSPP ;Get Mode
TAX ;Return Mode in X
.DC $7A ;PLY Height in Y
PLY ;Height in Y
PLA ;and Width in A
RTS
@ -364,7 +364,7 @@ GETSPL: JSR GETSPU ;Get Width, Height, Mode and Execute GETSCL
;Affects: A
;Returns: Y,X = Data Size in Bytes
GETSCL: ;.DC $FF ;Debug
.DC $DA ;PHX Save Mode
PHX ;Save Mode
PHA ;Save Width
TYA ;Copy Height to Accumulator
JSR GETSCS ;Calculate Height in Pixles
@ -376,7 +376,7 @@ GETSLK: ASL TEMP1 ;Multiply LSB
ROL ;and MSB by 2
DEY ;Decrement Counter
BNE GETSLK ;and Loop if Not Zero
.DC $FA ;PLX Retrieve Mode
PLX ;Retrieve Mode
BNE GETSSK ;If 0 (4 Bits Per Pixel)
LSR ; Divide MSB
ROR TEMP1 ; snd LSB by 2
@ -444,7 +444,7 @@ SETSPW: PHA ;Save Sprite Index
LDX #$CF ;Set Bit Mask
TYA ;Copy Specifier to Accumulator
AND #$03 ;Isolate Bits 0 and 1
JMP SETSP4 ;Shift Left Four Bits and Write Masked
BRA SETSP4 ;Shift Left Four Bits and Write Masked
;setsph(index) - Set Sprite Height Specifier
;Args: A = Sprite Index
@ -458,7 +458,7 @@ SETSP4: ASL
ASL
ASL
ASL
JMP SETSP7 ;Write Masked to Size Register
BRA SETSP7 ;Write Masked to Size Register
;setspp(index) - Set Sprite Palette Offset
;Args: A = Sprite Index
@ -471,7 +471,7 @@ SETSP7: STA TEMP0 ;Save Value
STX TEMP1 ;Save Bit Mask
PLA ;Retrieve Sprite Index
JSR GETSPS ;Get Sprite Size Register
JMP SETSP8 ;Apply Mask, Set Bits, and Write
BRA SETSP8 ;Apply Mask, Set Bits, and Write
;setsps(index,value) - Set Sprite Attribute Size Register
;Args: A = Sprite Index

View File

@ -9,7 +9,8 @@ ECHO Compiling File %1.c02 for Commander X16
..\c02.exe -h x16 -s x16 -s cbm %1 >%1.dbg
IF %ERRORLEVEL% NEQ 0 GOTO EOF
ECHO Assembling File %1.asm
C:\Programs\dasm %1.asm -f1 -o%1.prg -l%1.lst -s%1.sym
..\a02.exe -p %1.asm %1.asm %1.lst >%1.out
REM C:\Programs\dasm %1.asm -f1 -o%1.prg -l%1.lst -s%1.sym
IF %ERRORLEVEL% NEQ 0 GOTO EOF