mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-22 01:31:33 +00:00
200 lines
3.4 KiB
Plaintext
200 lines
3.4 KiB
Plaintext
/**************************************************
|
|
* 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;
|
|
|