/********************************************
 * C02 - C-like language for 6502 processor *
 * Test file for Compiler                   *
 ********************************************/

#pragma padding 1

/* Constants */
#define TRUE $FF
#define FALSE 0
#define BITS %01010101
#define ZED     'Z'

/* Enumerations */
enum {SOLO};
enum {BLACK, WHITE, RED, CYAN, PURPLE, GREEN, BLUE, YELLOW};
enum {NONE, FIRST, SECOND, THIRD};
enum {ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN};

/* Variable Types */
char b , i;  //byte type has been removed
char c,d,f;  //a char is an unsigned 8 bit number
char r[15];  //reserves dimension bytes
char z[15];
const char n = {1, 2, 3, 4, 5};
const char s = "This is a string.";
const char m = {"mixed", 1, "const", 2, "array", 3}; 
char aa,xx,yy ; //Function parameter variables
char STROBE; //Strobe Register

/* Aliased Variables */
alias char zp = $80;    //aliased to zero page
alias char via = $D000; //aliased to i/o mapped device
alias char cc = c;      //aliased to variable
alias char rr = r;      //aliased to array

/* Aliased Function */
//alias void chrout() = $F000; //aliased to ROM routine

/* Function Declaration */
char myfunc();
  return b-c-d;
  return;

main:

/* Register Assignments */
b = A;
c = X + 1;
d = Y - 1;
A = 'A';
A = c - 1;
A = strlen(s);
X = 0;
Y = 'Y';
X = c;

/* Variable Assignments */
b=-1+2-3;
c='@' & 5;
d = b|c^$FF;
f = %10100101;

/* Write to Strobe Register */
STROBE;

/* Variable Post-Operators */
d++;
d--;
b<<;
c>>;

/* Register Post-Operators */
X++;
Y++;
X--;
Y--;
A>>;
A<<;

i = 0;
r[i] = i;
r[i]++;
z[i]=r[i];
b=z[A]+z[X]+z[Y]+z[0]+z[i];

funcx:
f = testfn(b);           //Simple Variable
f = testfn(r[i]);        //Array Element
f = testfn(r[i],b);      //Two Parameters
f = testfn(r[i],b);      //Two Parameters
f = testfn(r[b],r[c]);   //Two Array Elements
f = testfn(r[1],r[2]);   //Two Array Elements
f = testfn(r[1],r[2],b); //Three Parameters
f = testfn(s);           //Implicit Address
f = testfn(&s);          //Explicit Address
f = testfn(b,s);         //Byte and Implicit Address
f = testfn(b,&s);        //Byte and Explicit Address
f = testfn(r[i],s);      //Array Element and Implicit Address
f = testfn(r[1],&s);     //Array Element and Explicit Address
f = testfn(b+c+d,r);     //Expression in Function Call 
f = testfn(getkey(b)+c); //Nested Function Call 

funcs:
prchr(b+c+d);
testfn(prchr(b));
testfn(b,c,d);
testfn(b+c+d,r[i],f);
testfn(&s); //Explicit Address Reference
testfn(s); //Implicit Address Reference
dofn(?,yy);
dofn(?,yy,xx);
dofn(aa,?,xx);
dofn(?,?,XX);

/*
defs:
c = CR;
echo(CR);
#error
*/

flwctl:
if (d<>f) i = b + c;

if (i=0) 
  i++; 
else
  i--;
  
here: if (getkey() & $7F == $1B) goto exit;  

there: goto flwctl;

goto &$C000;

if (#TRUE) putln("TRUE");
else if (#FALSE) putln("FALSE");

i = 0;
while (i < 10) {
  i++;
}
while (i:+) {
  i--;
}

do {
  c = rdkey();
} while (c=0);

do {
  c = rdkey();
  if (c=0) continue;
  if (c=27) break;
} while (c<>13);


for (i=1; i<9; i++)
  prchr(i);

if (@z == @r)
  for (i=0; i<=@z; i++) 
    z[i] = r[i];

if (d<f) i=b; else i=c; //Regular IF
i = (d<f) ? b : c;      //Shortcut IF

char tstfnc() {
  r[0] = 0;
  z[0] = 0;  
  return i;
}

void vdfnc1(aa) { 
  aa = aa + 1;
}

void vdfnc2(aa, yy) { 
  aa = aa + yy;
}

void vdfnc3(aa, yy, xx) { 
  aa = aa + yy + xx;
}

push &s, b+c+d, r[i];
stkfnc(); //Push/Pop Parameters
pop d, ?, z[f];


iprint(); inline "Hello World";
irect(); inline 10,10,100,100;
isort(); inline &r;

blkbgn(&$C000);
blkend(&$C400);

while () { 
  i++;
  break;
}

exit();

