mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-02-19 19:31:04 +00:00
Define constants using #define instead of const
This commit is contained in:
parent
fc987bb36e
commit
de4124e3b3
20
doc/c02.txt
20
doc/c02.txt
@ -68,7 +68,7 @@ directives, the C02 compiler processes directives directly.
|
||||
|
||||
DEFINE DIRECTIVE
|
||||
|
||||
The #define directive has been deprecated in favor of the const keyword.
|
||||
The #define directive is used to define constants (see below).
|
||||
|
||||
INCLUDE DIRECTIVE
|
||||
|
||||
@ -245,16 +245,14 @@ structures.
|
||||
|
||||
CONSTANTS
|
||||
|
||||
A constant is defined by using the const keyword followed by one or more
|
||||
constant assignments separated with commas and terminated with a semicolon.
|
||||
|
||||
A constant assignment consists of the the constant name, an equals sign,
|
||||
and the literal value to assign to the constant.
|
||||
A constant is defined by using the #define directive followed the constant
|
||||
name (without the # prefix) and the literal value to be assigned to it.
|
||||
|
||||
Examples:
|
||||
const #TRUE = $FF, #FALSE = 0;
|
||||
const #BITS = %01010101;
|
||||
const #ZED = 'Z';
|
||||
#define TRUE $FF
|
||||
#define FALSE 0
|
||||
#define BITS %01010101
|
||||
#define ZED 'Z'
|
||||
|
||||
ENUMERATIONS
|
||||
|
||||
@ -961,8 +959,7 @@ Examples:
|
||||
|
||||
UNIMPLEMENTED FEATURES
|
||||
|
||||
The #define directive generates an error. Defining of constants is done
|
||||
using the const keyword, and defining of macros is not supported.
|
||||
The #define directive allows the definition of constants but not macros.
|
||||
|
||||
The #if, #else, and #endif directives are not recognized at all by the
|
||||
compiler. They may be added in the future.
|
||||
@ -975,4 +972,3 @@ In addition, the signed and unsigned keywords are unrecognized, due to the
|
||||
Because of the 6502's peculiar indirect addressing modes, pointers are not
|
||||
currently implemented. Limited pointer operations may be implemented using
|
||||
zero page variables in the future.
|
||||
|
||||
|
@ -5,10 +5,10 @@
|
||||
* a specific platform. */
|
||||
|
||||
/* System Specific ASCII Key Codes */
|
||||
const DELKEY; //Delete/Backspace Key
|
||||
const ESCKEY; //Escape/Stop Key
|
||||
const RTNKEY; //Return/Enter Key
|
||||
const NULKEY //No Key was Pressed
|
||||
#define DELKEY $7F //Delete/Backspace Key
|
||||
#define ESCKEY $1B //Escape/Stop Key
|
||||
#define RTNKEY $0D //Return/Enter Key
|
||||
#define NULKEY $00 //No Key was Pressed
|
||||
|
||||
/* Zero Page Variables used as Pointers */
|
||||
char strlo,strhi; //String pointer for String and I/O functions
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
|
||||
/* System Specific ASCII Key Codes */
|
||||
const DELKEY; //Delete/Backspace Key
|
||||
const ESCKEY; //Escape/Stop Key
|
||||
const RTNKEY; //Return/Enter Key
|
||||
const NULKEY //No Key was Pressed
|
||||
#define DELKEY $7F //Delete/Backspace Key
|
||||
#define ESCKEY $1B //Escape/Stop Key
|
||||
#define RTNKEY $0D //Return/Enter Key
|
||||
#define NULKEY $00 //No Key was Pressed
|
||||
|
||||
/* Zero Page Variables used as Pointers */
|
||||
char strlo,strhi; //String pointer for String and I/O functions
|
||||
|
@ -1,9 +1,10 @@
|
||||
/* py65mon Header File */
|
||||
|
||||
//Platform Specific Constants
|
||||
const #delkey = $08; //Backspace Key
|
||||
const #esckey = $1B; //Escape Key
|
||||
const #rtnkey = $0D; //Enter Key
|
||||
#define DELKEY $08 //Delete/Backspace Key
|
||||
#define ESCKEY $1B //Escape/Stop Key
|
||||
#define RTNKEY $0D //Return/Enter Key
|
||||
#define NULKEY $00 //No Key was Pressed
|
||||
|
||||
//System Pointer Variables
|
||||
char srclo,srchi; //Source String Pointer for Library Functions
|
||||
|
@ -3,7 +3,8 @@
|
||||
* functions used in libraries. */
|
||||
|
||||
/* Constant Definitions */
|
||||
const #TRUE = $FF, #FALSE = 0;
|
||||
#define #TRUE $FF
|
||||
#define #FALSE $00
|
||||
|
||||
/* Get Destination Pointer *
|
||||
* Returns: Y,X=Destination address */
|
||||
|
36
src/dclrtn.c
36
src/dclrtn.c
@ -52,25 +52,19 @@ void addfnc(void) {
|
||||
bgnblk('{'); //Start Program Block
|
||||
}
|
||||
|
||||
/* Parse Constant Declaration*/
|
||||
void pconst(int m) {
|
||||
DEBUG("Processing constant declarations(s)\n", 0)
|
||||
if (m != MTNONE) ERROR("Illegal Modifier %d in Constant Definition", m, EXIT_FAILURE)
|
||||
do {
|
||||
expect('#'); //Require # prefix
|
||||
getwrd(); //Get constant name
|
||||
DEBUG("Defining constant '%s',", word)
|
||||
strncpy(connam[concnt], word, VARLEN);
|
||||
if (alcvar) setlbl(word); //Set label Assembler Line
|
||||
expect('=');
|
||||
conval[concnt++] = prsbyt(); //Get Value
|
||||
ACMNT(word); //comment value
|
||||
/* Add Constant to Contant Table *
|
||||
* Args: numval = value as int *
|
||||
* Uses: defnam = constant name *
|
||||
* word = value as parsed *
|
||||
* value = value as number */
|
||||
void addcon(int numval) {
|
||||
strncpy(connam[concnt], defnam, VARLEN);
|
||||
if (alcvar) setlbl(defnam); //Set label Assembler Line
|
||||
conval[concnt++] = numval; //Get Value
|
||||
if (alcvar) asmlin(EQUOP, value); //Write Definition
|
||||
DETAIL(" defined as '%s'\n", value)
|
||||
DEBUG("Defined constant '%s'", defnam)
|
||||
DETAIL(" as '%s'\n", value)
|
||||
if (!alcvar) SCMNT(""); //Clear Comment
|
||||
} while (look(','));
|
||||
expect(';');
|
||||
DEBUG("Constant Declaration Completed\n", 0)
|
||||
}
|
||||
|
||||
/* Parse Enum Declaration*/
|
||||
@ -82,13 +76,9 @@ void penum(int m) {
|
||||
do {
|
||||
getwrd(); //get defined identifier
|
||||
DEBUG("Enumerating '%s'\n", word)
|
||||
strncpy(connam[concnt], word, VARLEN);
|
||||
setlbl(word); //Set label Assembler Line
|
||||
conval[concnt++] = enmval; //Set Value
|
||||
strncpy(defnam, word, VARLEN);
|
||||
sprintf(value, "%d", enmval);
|
||||
asmlin(EQUOP, value); //Write Definition
|
||||
DEBUG("Defined as '%s'\n", value)
|
||||
enmval++;
|
||||
addcon(enmval++);
|
||||
} while (look(','));
|
||||
expect('}');
|
||||
expect(';');
|
||||
|
@ -9,5 +9,6 @@ char prmtry[VARLEN+1]; //Function Parameter Y
|
||||
int prmcnt; //Number of Parameters
|
||||
//int lpemtd; //Location Prefix Emitted
|
||||
|
||||
int pmodfr(); //Check for and Parse Modifier
|
||||
int ptype(int m); //Check for and Parse Type Keyword
|
||||
void addcon(int numval); //Add Constant
|
||||
int pmodfr(); //Check for and Parse Modifier
|
||||
int ptype(int m); //Check for and Parse Type Keyword
|
||||
|
@ -59,7 +59,10 @@ void incasm(void) {
|
||||
|
||||
/* Process define directive */
|
||||
void pdefin(void) {
|
||||
ERROR("Define directive not implemented\n", 0, EXIT_FAILURE)
|
||||
DEBUG("Processing DEFINE directive\n", 0)
|
||||
getwrd(); //Get constant name
|
||||
strncpy(defnam, word, CONLEN);
|
||||
addcon(prsbyt()); //Get Value and Add Constant
|
||||
}
|
||||
|
||||
/* Parse ASCII Subdirective */
|
||||
@ -94,9 +97,7 @@ void prszpg(void) {
|
||||
|
||||
/* Process Vartable Subdirective */
|
||||
void pvrtbl(void) {
|
||||
if (vrwrtn)
|
||||
ERROR("Variable table already written", 0, EXIT_FAILURE)
|
||||
|
||||
if (vrwrtn) ERROR("Variable table already written", 0, EXIT_FAILURE)
|
||||
vartbl(); //Write Variable Table
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ char connam[MAXCON+1][CONLEN+1]; //Constant Name Table
|
||||
int conval[MAXCON+1]; //Constant Value Table
|
||||
int concnt; //Number of Constants Defined
|
||||
int conidx; //Index into Constant Tables
|
||||
char defnam[CONLEN+1]; //Defined Constant Name
|
||||
|
||||
int invasc; //Invert ASCII Flag
|
||||
int mskasc; //Set High Bit Flag
|
||||
|
@ -2,18 +2,26 @@
|
||||
|
||||
#pragma origin 1000
|
||||
|
||||
#define TRUE = $FF
|
||||
#define FALSE = 0
|
||||
#define TRUE $FF
|
||||
#define FALSE 0
|
||||
|
||||
#define BITS = %01010101
|
||||
#define ZED = 'Z'
|
||||
#define BITS %01010101
|
||||
#define ZED 'Z'
|
||||
|
||||
#enum SOLO
|
||||
#enum ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN
|
||||
enum {SOLO};
|
||||
enum {ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN};
|
||||
|
||||
char a = {#TRUE, #FALSE};
|
||||
char b;
|
||||
char b = {#TRUE, #FALSE};
|
||||
char c, i;
|
||||
char f = #FALSE;
|
||||
char t = #TRUE;
|
||||
char zed;
|
||||
|
||||
b = #TRUE;
|
||||
|
||||
char nums = {#ZERO, #ONE, #TWO, #THREE, #FOUR, #FIVE, #SIX, #SEVEN, #EIGHT, #NINE, #TEN};
|
||||
|
||||
for (i=#ZERO; i<#TEN; i++) {
|
||||
c = (i = nums[i]) ? #TRUE : #FALSE;
|
||||
putdec(c);
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
/* C02 Syntax Examples */
|
||||
|
||||
/* Constants */
|
||||
const #TRUE = $FF, #FALSE = 0; //Constant
|
||||
#define TRUE $FF //Constants
|
||||
#define FALSE 0
|
||||
#define CR 32
|
||||
enum {BLACK, WHITE, RED, CYAN, PURPLE, GREEN, BLUE, YELLOW};
|
||||
|
||||
/* Structures */
|
||||
@ -9,10 +11,14 @@ struct record {char name[8]; char index;}; //Struct Definition
|
||||
struct record rec; //Struct Declaration
|
||||
|
||||
/* Declarations */
|
||||
char i, j; //Variables
|
||||
char b,c,d,e,f,g,h; //Variables
|
||||
char i,j,k,n,p,q,t,v;
|
||||
char fp;
|
||||
char line,row,col,tmp;
|
||||
char debug = #TRUE; //Variable initialized to constant
|
||||
char flag = %01010101; //Variable initialized to literal
|
||||
char r[7]; //8 byte Array
|
||||
char hmove, s80vid; //Strobe Registers
|
||||
char r[7]; //8 byte Array
|
||||
char s = "string"; //Array initialized to string
|
||||
char m = {1,2,3}; //Array initialized to list
|
||||
char isdgt(); //Forward declaration of function
|
||||
@ -25,8 +31,8 @@ d[j] = r[i] + s[x] + t[y]; //Array Indexing
|
||||
a<< ;b[i]>>; x++; y--; //Post-Operations
|
||||
|
||||
/* Function Calls */
|
||||
i = abs(n); j = min(b,c), k = max(d,e); plot(h,v,c);
|
||||
n = mult(e+f, div(m+n,d)) - t;
|
||||
i = abs(n); j = min(b,c); k = max(d,e); plot(h,v,c);
|
||||
n = mult(div(m+n,d), e) - t;
|
||||
puts("string"); putc(#CR); fputs(fp, &line);
|
||||
c = getc(); i = strchr(c, &s); row,col = scnpos();
|
||||
push d,r; mult(); pop p; //Pass via Stack
|
||||
@ -35,24 +41,24 @@ irect(); inline 10,10,100,100; //Pass Inline Parameters
|
||||
|
||||
/* Control Structures */
|
||||
if (c = 27) goto end;
|
||||
if (n) q = div(n,d) else puts("Division by 0!");
|
||||
if (n) q = div(n,d); else puts("Division by 0!");
|
||||
if (!fp) putln("File not opened");
|
||||
i = 0; while (c < 10) { prbyte(i); i++; }
|
||||
while() { c=rdkey; if (c=0) continue; putchr(c); if (c==13) break; }
|
||||
while() { c=rdkey(); if (c=0) continue; putchr(c); if (c==13) break; }
|
||||
do c = rdkey(); while (c=0);
|
||||
do (c = getchr(); putchr(c); while (c<>13)
|
||||
do {c = getchr(); putchr(c);} while (c<>13);
|
||||
for (c='A'; c<='Z'; c++) putc(c);
|
||||
for (i=strlen(s)-1;i:+;i--) putc(s[i]);
|
||||
for (i=0;c>0;i++) { c=getc(); s[i]=c }
|
||||
for (i=0;c>0;i++) { c=getc(); s[i]=c; }
|
||||
select (getc()) {
|
||||
case $0D: putln("The Enter key");
|
||||
case 'A','a': putln ("The letter A");
|
||||
case 'A','a': putln("The letter A");
|
||||
default: putln("some other key");
|
||||
}
|
||||
end: //Label
|
||||
|
||||
/* Function Declaration */
|
||||
char isdgt(tmp) {
|
||||
if (tmp >= '0') if (tmp <= '9') return true;
|
||||
return false;
|
||||
if (tmp >= '0') if (tmp <= '9') return #TRUE;
|
||||
return #FALSE;
|
||||
}
|
||||
|
@ -6,9 +6,10 @@
|
||||
#pragma padding 1
|
||||
|
||||
/* Constants */
|
||||
const #TRUE = $FF, #FALSE = 0;
|
||||
const #BITS = %01010101;
|
||||
const #ZED = 'Z';
|
||||
#define TRUE $FF
|
||||
#define FALSE 0
|
||||
#define BITS %01010101
|
||||
#define ZED 'Z'
|
||||
|
||||
/* Enumerations */
|
||||
enum {SOLO};
|
||||
|
Loading…
x
Reference in New Issue
Block a user