1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-15 17:08:51 +00:00

Added Various .c02 files from test/

This commit is contained in:
Curtis F Kaylor 2019-11-19 13:52:21 -05:00
parent a56007da8f
commit f83a5d1e71
6 changed files with 739 additions and 0 deletions

21
test/hello.c02 Normal file
View File

@ -0,0 +1,21 @@
/*****************************************************
* HELLO - Test/Demo program for C02 Standard Header *
* Prints "HELLO WORLD" and exits *
*****************************************************/
//Specify System Header using -H option
char key; //Key value
const char hello = "HELLO WORLD";
char i;
main:
i = 0;
while (hello[i]) {
putchr(hello[i]);
i++;
}
newlin();
goto exit;

87
test/ints.c02 Normal file
View File

@ -0,0 +1,87 @@
/****************************************************
* INTS - Test Integer Variables and Function Calls */
//Specify System Header using -H option
#include <screen.h02>
#include <stddef.h02>
#include <stdlib.h02>
#include <intlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <string.h02>
#include <test.h02>
char n; //Number of Characters
char r[255]; //Test Array
char s[128]; //Test String
const char istr = "9876";
const char t = "CONST STRING.";
alias int nmi = $FFFA; //NMI Vector
alias int rst = $FFFC; //Reset Vector
alias int brk = $FFFE; //Break Vector
int addr; //Various Addresses
int eoj; //End of Job
const int less = $789A;
const int more = $BCDE;
int yx, dd; //Function Arguments and Variables
char aa, xx, yy;
struct record {char name[8], index; int addr;};
struct record rec;
main:
eoj = getend();
setdst(&rec.name); strcpy("FRED");
rec.index = $AB;
rec.addr = $CDEF;
newlin();
/* Print Vector Contents */
setdst(nmi); printf("NMI=$%w%n");
setdst(rst); printf("RST=$%w%n");
setdst(brk); printf("BRK=$%w%n%n");
/* Print Contents of EOJ */
setdst(eoj); printf("EOJ=$%w%n%n");
anykey();
/* Test Function Call Arguments */
putln("ADDR=49152"); addr = 49152; setdst(&49152); cmpdst(addr);
putln("ADDR=&T"); addr = &t; setdst(t); cmpdst(addr);
putln("ADDR=&REC"); addr = &rec; setdst(&rec); cmpdst(addr);
putln("ADDR=&REC.NAME"); addr = &rec.name; setdst(&rec.name); cmpdst(addr);
putln("ADDR=&REC.INDEX"); addr = &rec.index; setdst(&rec.index); cmpdst(addr);
putln("ADDR=&REC.ADDR"); addr = &rec.addr; setdst(&rec.addr); cmpdst(addr);
anykey();
puts("GOTO (EOJ)");
goto (eoj);
failln();
goto exit;
end:
passln();
goto exit;
int getend() {
return &end;
}
void prtwrd(., yy, xx) {
putchr('$'); puthex(yy); puthex(xx);
}
void cmpdst(yx) {
dd = getdst();
prtwrd(yx); putchr('='); prtwrd(dd);
if (>yx == >dd and <yx == <dd) passln(); else failln();
newlin();
}

55
test/keydefs.c02 Normal file
View File

@ -0,0 +1,55 @@
/**********************************************
* KEYDEFS - Test/Demo for keydefs.h02 module *
**********************************************/
//Specify System Header using -H option
#include <keydef.h02>
char key; //Key value
main:
putstr("PRESS KEYS TO SEE DEFINITIONS"); newlin();
while() {
key = getchr();
if (!key) continue;
select (key) {
case #KEYBCK: putstr("BACKSPACE");
case #KEYBRK: putstr("BREAK");
case #KEYCLR: putstr("CLEAR");
case #KEYCPY: putstr("COPY");
case #KEYDEL: putstr("DELETE");
case #KEYDN : putstr("DOWN");
case #KEYESC: putstr("ESCAPE");
case #KEYFN1: putstr("F1");
case #KEYFN2: putstr("F2");
case #KEYFN3: putstr("F3");
case #KEYFN4: putstr("F4");
case #KEYFN5: putstr("F5");
case #KEYFN6: putstr("F6");
case #KEYFN7: putstr("F7");
case #KEYFN8: putstr("F8");
case #KEYFN9: putstr("F9");
case #KEYFNA: putstr("F10");
case #KEYFNB: putstr("F11");
case #KEYFNC: putstr("F12");
case #KEYHLP: putstr("HELP");
case #KEYHOM: putstr("HOME");
case #KEYINS: putstr("INSERT");
case #KEYLFT: putstr("LEFT");
case #KEYRGT: putstr("RIGHT");
case #KEYRTN: putstr("RETURN");
case #KEYRTS: putstr("SHIFT-RETURN");
case #KEYRUN: putstr("RUN");
case #KEYRVF: putstr("RVS-OFF");
case #KEYRVS: putstr("RVS-ON");
case #KEYSPS: putstr("SHIFT-SPACE");
case #KEYTAB: putstr("TAB");
case #KEYTAS: putstr("SHIFT-TAB");
case #KEYUP : putstr("UP");
case ' ': putstr("SPACE");
default: if (key > ' ' and key <> #DELKEY) putchr(key);
}
putstr(" ["); prbyte(key); putstr("] ");
if (key == #ESCKEY) break;
}
goto exit;

105
test/testilib.c02 Normal file
View File

@ -0,0 +1,105 @@
/****************************************************
* INTS - Test Integer Variables and Function Calls */
//Specify System Header using -H option
#include <screen.h02>
#include <stddef.h02>
#include <stdlib.h02>
#include <intlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <string.h02>
#include <test.h02>
char size;
char s[128]; //Test String
int ivar,ival; //Integer Variables
int icmp,itot,ires; //Function Variables
int less, more; //Test Values for imin() and imax()
int yx, dd; //Function Arguments and Variables
void cpival(icmp) {
if (>ival <> >icmp or <ival <> <icmp) {
putwrd(ival); puts("<>"); putwrd(icmp);
failln();
goto exit;
}
}
/* Test imin() and imax() */
void minmax() {
newlin();
puts("LESS=$"); putwrd(less); puts(",MORE=$"); putwrd(more); newlin();
puts(" IMIN()=$"); setsrc(less);
ival = imin(more); putwrd(ival); newlin();
cpival(less);
puts(" IMAX()=$"); setsrc(less);
ival = imax(more); putwrd(ival); newlin();
cpival(more);
}
/* Test cvibcd() and upbcdi() */
void intbcd(ival) {
newlin(); puts("CVIBCD($"); putwrd(ival); puts(")=$");
cvibcd(ival); puthex(temp2); puthex(temp1); puthex(temp0);
}
/* Test itoa() and atoi() */
void itaati(ivar) {
newlin();
puts("ITOA($"); putwrd(ivar); puts(")=\"");
setdst(s); size = itoa(ivar); puts(s); putln("\"");
puts("ATOI(\""); puts(s); puts("\")=$");
ival = atoi(s); putwrd(ival); newlin();
//cpival(ivar);
}
/* Test iadd() and isub() */
void addsub(ivar) {
newlin();
putint(ival); putchr('+'); putint(ivar); putchr('=');
setsrc(ival); itot = iadd(ivar); putint(itot); newlin();
putint(itot); putchr('-'); putint(ivar); putchr('=');
setsrc(itot); ires = isub(ivar); putint(ires); newlin();
cpival(ires);
}
/* Test imult() and idiv() */
void mltdiv(ivar) {
newlin();
putint(ival); putchr('X'); putint(ivar); putchr('=');
setsrc(ival); itot = imult(ivar); putint(itot); newlin();
putint(itot); putchr('/'); putint(ivar); putchr('=');
setsrc(itot); ires = idiv(ivar); putint(ires); newlin();
cpival(ires);
}
main:
less = $009A; more = $00DE; minmax();
less = $789A; more = $78DE; minmax();
less = $7800; more = $BC00; minmax();
less = $789A; more = $BCDE; minmax();
anykey();
itaati(&0);
itaati(&234);
itaati(&256);
itaati(&456);
itaati(&23456);
itaati(&$FFFF);
anykey();
ival = &23; addsub(&34);
ival = &1234; addsub(&5678);
ival = &23456; addsub(&34567);
ival = &$7700; addsub(&$6600);
ival = &$7FFF; addsub(&$8000);
anykey();
//ival = &123; mltdiv(&234);
goto exit;

199
test/testslib.c02 Normal file
View File

@ -0,0 +1,199 @@
/**************************************************
* TESTSLIB - Test Library stdlib.h02 for py65mon *
**************************************************/
//Specify System Header using -H option
#include <stddef.h02>
#include <stdlib.h02>
void prtcma() {putchr(',');}
void prtlin() {putstr(); newlin();}
void prtok() {prtlin(" OK");}
main:
//goto tstcvb;
tstabs: //Test abs()
char onum, anum, cnum;
putstr("ABS()");
//test abs() positive numbers
onum = 0;
aploop:
anum = abs(onum);
if (onum <> anum) goto abserr;
onum++;
if (onum < $80) goto aploop;
//test abs() negative numbers
anloop:
anum = abs(onum);
cnum = -onum;
if (anum <> cnum) goto abserr;
onum++;
if (onum > $00) goto anloop;
prtok();
tstmlt: //Test mult()
char mltplr, mltpnd, acmlsb, acmmsb, acmlst;
char prodct, ovrflw;
putstr("MULT()");
mltplr = 1;
mrloop:
mltpnd = 1; acmlst = 0;
acmlsb = 0; acmmsb = 0;
mdloop:
acmlsb = acmlsb + mltplr;
if (acmlsb<acmlst) acmmsb++;
acmlst = acmlsb;
prodct,ovrflw = mult(mltplr,mltpnd);
if (prodct <> acmlsb) goto merror;
mltpnd++;
if (mltpnd > 0) goto mdloop;
mltplr++;
if (mltplr > 0) goto mrloop;
prtok();
tstdiv: //Test div()
char maxmpd, divdnd, divisr, quotnt;
putstr("DIV()");
mltplr = 255;
maxmpd = 1;
drloop:
mltpnd = 1;
acmlsb = 0;
ddloop:
acmlsb = acmlsb + mltplr;
prodct = mult(mltplr, mltpnd);
quotnt = div(prodct, mltpnd);
if (quotnt <> mltplr) goto derror;
mltpnd++;
if (mltpnd < maxmpd) goto ddloop;
mltplr>>;
maxmpd<<;
if (mltplr <> 0) goto drloop;
prtok();
tstrnd: //Test rand() and rands()
char countr, rndnum, rndtbl[255];
putstr("RAND()");
rands(1); //Seed Random Number Generator;
countr = 0;
riloop:
rndtbl[countr] = 0;
countr++;
if (countr <> 0) goto riloop;
rnloop:
rndnum = rand();
if (rndtbl[rndnum] > 0) goto rnderr;
rndtbl[rndnum] = $FF;
countr++;
if (countr < 255) goto rnloop;
prtok();
tstcvb: //Test cvbcd()
char cvbchr,cvblo,cvbhi;
goto tstc2a;
putstr("CVBCD()");
cvbchr = 0; cvblo = 0; cvbhi = 0;
cvloop:
cvbcd(cvbchr);
getchr();
if (temp1 <> cvblo or temp2 <> cvbhi) goto cvberr;
cvblo++;
if (cvblo & $0f > 9) {
cvblo = cvblo & $f0 + $10;
if (cvblo >= $a0) {
cvblo = cvblo & $0f;
cvbhi++;
}
}
cvbchr++;
if (cvbchr) goto cvloop;
prtok();
tstc2a: //Test ctoa();
char srcchr, dstchr, tststr[4];
putstr("CTOA()");
srcchr = 0;
caloop:
ctoa(srcchr, &tststr);
dstchr = atoc(&tststr);
if (srcchr <> dstchr) goto c2aerr;
srcchr++;
if (srcchr <> 0) goto caloop;
prtok();
goto exit;
abserr:
putstr("ABS(");
prbyte(onum);
putchr(')');
putchr('=');
prbyte(anum);
putchr(',');
prbyte(cnum);
newlin();
goto exit;
merror:
newlin();
prbyte(mltplr);
putchr('*');
prbyte(mltpnd);
putchr('=');
//prbyte(ovrflw);
prbyte(prodct);
putchr(',');
//prbyte(acmmsb);
prbyte(acmlsb);
newlin();
goto exit;
derror:
newlin();
prbyte(divdnd);
putchr('/');
prbyte(divisr);
putchr('=');
prbyte(quotnt);
putchr(',');
prbyte(mltplr);
newlin();
goto exit;
rnderr:
putstr("RAND()=");
prbyte(rndnum);
putchr(',');
prbyte(countr);
newlin();
goto exit;
cvberr:
putstr(" !CVBCD(");
prbyte(cvbchr);
putstr(")=$");
prbyte(TEMP2);
prbyte(TEMP1);
newlin();
goto exit;
c2aerr:
putstr(" !CTOA(");
prbyte(srcchr);
putstr(")=");
prbyte(dstchr);
newlin();
goto exit;

272
test/xmemtest.c02 Normal file
View File

@ -0,0 +1,272 @@
/**************************************
* TESTXMEM - Test Library xmemory.h02 *
**************************************/
//use -h option on command line
#include <screen.h02>
#include <stddef.h02>
#include <stdlib.h02>
#include <intlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <xmemory.h02>
char aa; //Function Arguments
alias char banked = $A000; //Beginning of Banked Memory
int icount;
char i; //Index Variable
char chrctr; //Get/Put Character
int intger; //Get/Put Integer
char r[255],w[255]; //Read/Write Arrays
char ibank, ipage, ibyte; //Index Bank, Page, and Byte
char lbank, lpage, lbyte; //Logical Bank, Page, and Byte
char mbank, mpage, mbyte; //Memory Bank, Page, and Byte
char pbank, ppage, pbyte; //Physical Bank, Page, and Byte
char sbank, spage, sbyte; //Starting Bank, Page, and Byte
char ebank, epage, ebyte; //Starting Bank, Page, and Byte
void passed() { putln("PASSED");}
void paddrs(aa) {
if (aa) newlin(); else puts(", ");
printf(setdst(xgetpa()),"PA=$%h%w, ");
printf(setdst(xgetla()),"LA=$%h%w ");
}
void perror() {
printf(); //Implied Arguments
paddrs(#FALSE);
newlin();
goto exit;
}
/* Test xclcpa() and xclcla() */
void tstlpl(sbank,spage,sbank) {
ibank=sbank; ipage=spage; ibyte=sbyte;
while (ibank<=#XLBANK) {
putc('.');
while() {
while() {
//printf(setdst(ibank,ipage,ibyte),"%n ORIGINAL: $%h%w");
pbank,ppage,pbyte = xclcpa(ibank,ipage,ibyte);
//printf(setdst()," PHYSICAL: $%h%w");
lbank,lpage,lbyte = xclcla(pbank,ppage,pbyte);
//printf(setdst(),", LOGICAL: $%h%w");
if (lbank<>ibank or lpage<>ipage or ibyte<>lbyte)
perror(setdst(ibank,ipage,ibyte),"%nERROR IN BANK $%h ADDRESS $%w");
if (getkey()==#ESCKEY) goto exit;
ibyte=ibyte+$10; if (!ibyte) break;
} ipage++; if (!ipage) break;
} ibank++; if (!ibank) break;
}
}
/* Test xgetla() and xsetla() */
void tstgsl(ibank,ipage,ibank) {
while (ibank<=#XLBANK) {
putc('.');
while() {
while() {
//printf(setdst(ibank,ipage,ibyte),"%n SET: $%h%w");
xsetla(ibank,ipage,ibyte);
lbank,lpage,lbyte = xgetla();
//printf(setdst(),", GOT: $%h%w");
if (lbank<>ibank or lpage<>ipage or ibyte<>lbyte)
perror(setdst(ibank,ipage,ibyte),"%nERROR IN BANK $%h ADDRESS $%w");
if (getkey()==#ESCKEY) goto exit;
ibyte=ibyte+$10; if (!ibyte) break;
} ipage++; if (!ipage) break;
} ibank++; if (!ibank) break;
}
}
/* Test xincpa() */
void tstipa(ibank,ipage,ibank) {
xsetla(ibank,ipage,ibyte); //Set Logical Address to 0
while (ibank<=#XLBANK) {
putc('.');
while() {
//clrscr();
while() {
pbank,ppage,pbyte = xgetpa(ibank,ipage,ibyte);
//printf(setdst(),"$%h%w:");
lbank,lpage,lbyte = xgetla(); //Get Logical Address
//printf(setdst(),"$%h%w ");
if (lbank<>ibank or lpage<>ipage or ibyte<>lbyte)
perror(setdst(ibank,ipage,ibyte),"%nERROR IN BANK $%h ADDRESS $%w");
xincpa(); //Increment Physical Address
ibyte++; if (!ibyte) break;
} ipage++; if (!ipage) break;
if (getkey()==#ESCKEY) goto exit;
} ibank++; if (!ibank) break;
}
}
/* Test xgetc() and xputc() */
void tstgpc(sbank,spage,sbyte) {
while() {
//printf(setdst(),"$%h%w");
putc('.');
ibank=sbank; ipage=spage; ibyte=sbyte;
xsetla(ibank,ipage,ibyte);
i=0; do { xputc(i); i++; } while (i);
xsetla(ibank,ipage,ibyte);
i=0; do {
if (xgetc()<>i) perror(setdst(xgetpa()),"%nERROR IN BANK $%h ADDRESS $%w");
i++;
} while (i);
sbank++;spage++;sbyte++;
if (!sbank or sbank>#XLBANK) break;
}
}
/* Test xgeti() and xputi() */
void tstgpi(sbank,spage,sbyte) {
while() {
//*printf(setdst(),"$%h%w");
putc('.');
ibank=sbank; ipage=spage; ibyte=sbyte;
//Write 256 Integers
xsetla(ibank,ipage,ibyte);
i=0; do {
mpage=i;mbyte=i^$FF;
xputi(.,mpage,mbyte);
i++;
} while (i);
//Read 256 Integers
xsetla(ibank,ipage,ibyte);
i=0; do {
mpage=i;mbyte=i^$FF;
intger = xgeti();
if (<intger<>mbyte or >intger<>mpage)
perror(setdst(xgetpa()),"%nERROR IN BANK $%h ADDRESS $%w");
i++;
} while (i);
//Set Next Start Address
sbank++;spage++;sbyte++;
if (!sbank or sbank>#XLBANK) break;
}
}
/* Test xgetl() and xputl() */
void tstgpl(sbank,spage,sbyte) {
while() {
//*printf(setdst(),"$%h%w");
putc('.');
ibank=sbank; ipage=spage; ibyte=sbyte;
//Write 256 Integers
xsetla(ibank,ipage,ibyte);
i=0; do {
mbyte=i; mpage=i^$FF; mbank = -i;
xputi(mbank,mpage,mbyte);
i++;
} while (i);
//Read 256 Integers
xsetla(ibank,ipage,ibyte);
i=0; do {
mbyte=i; mpage=i^$FF; mbank = -i;
intger = xgeti();
if (<intger<>mbyte or >intger<>mpage)
perror(setdst(xgetpa()),"%nERROR IN BANK $%h ADDRESS $%w");
i++;
} while (i);
//Set Next Start Address
sbank++;spage++;sbyte++;
if (!sbank or sbank>#XLBANK) break;
}
}
/* Test xread() and xwrite() */
void tstxrw(sbank,spage,epage) {
i=0; do {w[i]=i;i++;} while (i); //Fill Write Array
ibank=sbank;
while (ibank<=#XLBANK) {
putc('.');
//Write 256,1-255 bytes of Array
ipage=spage; xsetla(ibank,0,ipage);
do {
//paddrs(#TRUE);
//inline $ff;
xwrite(ipage,&w);
//if (banked=61) perror("MEMORY OVERWRITE ERROR!");
ipage++;
} while (ipage<>epage);
//paddrs(#TRUE);
//Read 256,1-255 bytes of Array
ipage=spage; xsetla(ibank,0,ipage);
do {
//printf(ipage,"%n%h:");
//inline $ff;
//paddrs(#TRUE);
xread(ipage,&r);
i=0; do {
//printf(r[i],"%h."); printf(w[i],"%h,");
if (r[i]<>w[i]) perror(i,"ERROR IN INDEX %d");
i++;
} while(i<>ipage);
ipage++;
} while (ipage<>epage);
ibank++; if (!ibank) break;
}
}
/* Test xload() and xsave() */
void tstxls(sbank,spage,sbyte) {
setsrc(&$F000); //Most Systems have ROM from $F000 to $FFFF
xsetla(sbank,spage,sbyte);
xsave(&$1000); //Save through $FFFF
setdst(&$8000); //There's usually free RAM here
xsetla(sbank,spage,sbyte);
xload(&$1000); //Load bytes saved from $F000 to $FFFF
srcptr = &$F000; dstptr = &$8000; icount = &$1000;
while (<icount or >icount) {
//putwrd(srcptr); putchr(':'); puthex(*srcptr); putspc();
//putwrd(dstptr); putchr(':'); puthex(*dstptr); putspc();
if (*srcptr <> *dstptr) perror("ERROR IN XLOAD() AND/OR XSAVE()\n");
if (!<icount) putc('.');
srcptr++; dstptr++; icount--;
}
}
main:
if (!#XLBANK) perror("Extended Memory Not Supported");
/*
puts("TESTING XCLCPA() AND XCLCLA()");
tstlpl($00,$00,$00);
passed();
//XGETPA() AND XSETPA() NOT DIRECTLY TESTED
//VALID VALUES ARE SYSTEM DEPENDENT
puts("TESTING XGETLA() AND XSETLA()");
tstgsl($00,$00,$00);
passed();
puts("TESTING XINCPA().............");
tstipa($00,$00,$00);
passed();
puts("TESTING XPUTC() AND XGETC()..");
tstgpc($00,$00,$00);
passed();
puts("TESTING XPUTI() AND XGETI()..");
tstgpi($00,$00,$00);
passed();
puts("TESTING XREAD() AND XWRITE().");
tstxrw($00,$00,$7F);
passed();
*/
puts("TESTING XLOAD() AND XSAVE().");
tstxls($00,$00,$00);
passed();
goto exit;