1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-18 21:07:28 +00:00
C02/test/testsl.c02
2018-08-19 18:24:02 -04:00

221 lines
3.5 KiB
Plaintext

/************************************************
* TESTSL - Test Library stdlib.h02 for py65mon *
************************************************/
//Specify System Header using -H option
#include <stddef.h02>
#include <stdlib.h02>
main:
tstabs: //Test abs()
char onum, anum, cnum;
prchr('A');
prchr('B');
prchr('S');
prchr(' ');
//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;
prchr('O');
prchr('K');
newlin();
tstmlt: //Test mult()
char mltplr, mltpnd, acmlsb, acmmsb, acmlst;
char prodct, ovrflw;
mltplr = 1;
mrloop:
prbyte(mltplr);
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;
//if (ovrflw <> acmmsb) goto merror;
mltpnd++;
if (mltpnd > 0) goto mdloop;
mltplr++;
if (mltplr > 0) goto mrloop;
newlin();
prchr('M');
prchr('U');
prchr('L');
prchr('T');
prchr(' ');
prchr('O');
prchr('K');
newlin();
tstdiv: //Test div()
char maxmpd, divdnd, divisr, quotnt;
mltplr = 255;
maxmpd = 1;
drloop:
prbyte(mltplr);
mltpnd = 1;
acmlsb = 0;
ddloop:
prbyte(mltpnd);
acmlsb = acmlsb + mltplr;
prodct = mult(mltplr, mltpnd);
quotnt = div(prodct, mltpnd);
if (quotnt <> mltplr) goto derror;
mltpnd++;
if (mltpnd < maxmpd) goto ddloop;
newlin();
mltplr>>;
maxmpd<<;
if (mltplr <> 0) goto drloop;
newlin();
prchr('D');
prchr('I');
prchr('V');
prchr(' ');
prchr('O');
prchr('K');
newlin();
tstrnd: //Test rand() and rands()
char countr, rndnum, rndtbl[255];
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;
prbyte(rndnum);
prchr(' ');
countr++;
if (countr < 255) goto rnloop;
newlin();
prchr('R');
prchr('A');
prchr('N');
prchr('D');
prchr(' ');
prchr('O');
prchr('K');
newlin();
tstc2a: //Test ctoa();
char srcchr, dstchr, tststr[4];
srcchr = 0;
caloop:
prbyte(srcchr);
prchr(' ');
ctoa(srcchr, &tststr);
dstchr = atoc(&tststr);
if (srcchr <> dstchr) goto c2aerr;
srcchr++;
if (srcchr <> 0) goto caloop;
newlin();
prchr('C');
prchr('T');
prchr('O');
prchr('A');
prchr(' ');
prchr('O');
prchr('K');
newlin();
goto exit;
abserr:
prchr('A');
prchr('B');
prchr('S');
prchr('(');
prbyte(onum);
prchr(')');
prchr('=');
prbyte(anum);
prchr(',');
prbyte(cnum);
newlin();
goto exit;
merror:
newlin();
prbyte(mltplr);
prchr('*');
prbyte(mltpnd);
prchr('=');
//prbyte(ovrflw);
prbyte(prodct);
prchr(',');
//prbyte(acmmsb);
prbyte(acmlsb);
newlin();
goto exit;
derror:
newlin();
prbyte(divdnd);
prchr('/');
prbyte(divisr);
prchr('=');
prbyte(quotnt);
prchr(',');
prbyte(mltplr);
newlin();
goto exit;
rnderr:
prchr('R');
prchr('A');
prchr('N');
prchr('D');
prchr('(');
prchr(')');
prchr('=');
prbyte(rndnum);
prchr(',');
prbyte(countr);
newlin();
goto exit;
c2aerr:
prchr('C');
prchr('T');
prchr('O');
prchr('A');
prchr('(');
prbyte(srcchr);
prchr(')');
prchr('=');
prbyte(dstchr);
newlin();
goto exit;