mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-22 01:31:33 +00:00
Added py65mon test programs
This commit is contained in:
parent
2d01054cf3
commit
80b160ae75
@ -40,7 +40,7 @@ main:
|
||||
|
||||
puts("!$FF "); if (!$FF) puts(&failed); else puts(&passed);
|
||||
puts("!$00 "); if (!$00) puts(&passed); else puts(&failed);
|
||||
puts("!1|0 "); if (!1|0) puts(&failed); else puts(&failed);
|
||||
puts("!1|0 "); if (!1|0) puts(&failed); else puts(&passed);
|
||||
puts("!1&0 "); if (!1&0) puts(&passed); else puts(&failed);
|
||||
puts("!1^1 "); if (!1^1) putln(&passed); else putln(&failed);
|
||||
|
||||
|
20
py65/echomin.c02
Normal file
20
py65/echomin.c02
Normal file
@ -0,0 +1,20 @@
|
||||
/***************************************
|
||||
* ECHO - Demo C02 program for py65mon *
|
||||
* using minimal header file *
|
||||
* Echoes typed characters to display *
|
||||
* ESC key aborts to monitor *
|
||||
***************************************/
|
||||
|
||||
#include <py65min.h02>
|
||||
|
||||
char key; //Key value
|
||||
|
||||
main:
|
||||
while() {
|
||||
key = rdkey();
|
||||
if (key = $1B) break;
|
||||
prchr(key);
|
||||
if (key = $0D) prchr($0A);
|
||||
}
|
||||
goto exit;
|
||||
|
21
py65/forforpf.c02
Normal file
21
py65/forforpf.c02
Normal file
@ -0,0 +1,21 @@
|
||||
/******************************************
|
||||
* FORFORPF - Test Nested FOR with PRINTF *
|
||||
******************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdlib.h02>
|
||||
#include <stdio.h02>
|
||||
#include <stdiox.h02>
|
||||
|
||||
char i,j,result;
|
||||
main:
|
||||
for (i=0;i<5;i++)
|
||||
{
|
||||
for (j=0;j<5;j++)
|
||||
{
|
||||
result=div(mult(mult(i,5)+j,3),5)+32; //(i*5+j)*3/5+32;
|
||||
printf(result,"%d");
|
||||
newlin();
|
||||
}
|
||||
}
|
||||
goto exit;
|
136
py65/strings.c02
Normal file
136
py65/strings.c02
Normal file
@ -0,0 +1,136 @@
|
||||
/**********************************************
|
||||
* STRINGS - Demonstrate string.h02 functions *
|
||||
**********************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdio.h02>
|
||||
#include <stdlib.h02>
|
||||
#include <string.h02>
|
||||
#include <stringx.h02>
|
||||
|
||||
char slen, scmp, spos;
|
||||
char s1 = "First string.";
|
||||
char s2 = "Second string.";
|
||||
char stest = "123456789012345678901234567890";
|
||||
char stemp[32];
|
||||
char sless = "This string is less.";
|
||||
char smore = "This string is more.";
|
||||
char sprt[4];
|
||||
char pass = "Pass";
|
||||
char fail = "Fail";
|
||||
|
||||
main:
|
||||
//Demo strchr(), strrch()
|
||||
putln(&s1); //Print s1 to screen
|
||||
puts("Position of first 's' is: ");
|
||||
spos = strchr('s', &s1); //Get position of 's'
|
||||
ctoa(spos, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
puts("Position of first 'x' is: ");
|
||||
spos = strchr('x', &s1); //Get position of 's'
|
||||
ctoa(spos, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
puts("Position of last 's' is: ");
|
||||
spos = strrch('s', &s1); //Get position of 's'
|
||||
ctoa(spos, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
puts("Position of last 'x' is: ");
|
||||
spos = strrch('x', &s1); //Get position of 's'
|
||||
ctoa(spos, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
newlin();
|
||||
|
||||
//Demo strlen();
|
||||
putln(&stest); //Print stest to screen
|
||||
slen = strlen(&stest); //Get string length
|
||||
ctoa(slen, &sprt); //Convert to string
|
||||
puts("Length of string is ");
|
||||
putln(&sprt); //Print length to screen
|
||||
newlin();
|
||||
|
||||
//Demo setstr();
|
||||
strdst(&stemp); //Set stemp as destination street
|
||||
puts("Address of stemp is $");
|
||||
prbyte(dsthi); //Print stored address to string
|
||||
prbyte(dstlo);
|
||||
newlin();
|
||||
newlin();
|
||||
|
||||
//Demo strcpy()
|
||||
putln("Copying s1 to stemp: ");
|
||||
strdst(&stemp); //Set Destination String
|
||||
slen = strcpy(&s1); //Copy s1 into Destination String
|
||||
puts("String stemp contains: ");
|
||||
putln(&stemp); //Print stest to screen
|
||||
ctoa(slen, &sprt); //Convert to string
|
||||
puts("Total characters copied: ");
|
||||
putln(&sprt); //Print length to screen
|
||||
newlin();
|
||||
|
||||
//Demo strcat()
|
||||
putln("Concatenating s2 to stemp: ");
|
||||
strdst(&stemp); //Set Destination String
|
||||
slen = strcat(&s2); //Copy s1 into Destination String
|
||||
puts("String stemp contains: ");
|
||||
putln(&stemp); //Print stest to screen
|
||||
ctoa(slen, &sprt); //Convert to string
|
||||
puts("Length of concatenated string is ");
|
||||
putln(&sprt); //Print length to screen
|
||||
newlin();
|
||||
|
||||
//Demo strcut()
|
||||
putln("Cutting s2 at position 7 to stemp: ");
|
||||
strdst(&stemp); //Set Destination String
|
||||
slen = strcut(7, &s2); //Copy s1 into Destination String
|
||||
puts("String stemp contains: ");
|
||||
putln(&stemp); //Print stest to screen
|
||||
ctoa(slen, &sprt); //Convert to string
|
||||
puts("Length of cut string is ");
|
||||
putln(&sprt); //Print length to screen
|
||||
newlin();
|
||||
|
||||
//Demo strcmp();
|
||||
puts("Comparing sless to smore: ");
|
||||
strdst(&sless);
|
||||
scmp = strcmp(&smore);
|
||||
prbyte(scmp); newlin();
|
||||
puts("Comparing sless to sless: ");
|
||||
strdst(&sless);
|
||||
scmp = strcmp(&sless);
|
||||
prbyte(scmp); newlin();
|
||||
puts("Comparing smore to sless: ");
|
||||
strdst(&smore);
|
||||
scmp = strcmp(&sless);
|
||||
prbyte(scmp); newlin();
|
||||
newlin();
|
||||
|
||||
//Demo strspn();
|
||||
putln(&stest); //Print test to screen
|
||||
puts("Span matching \"0123\" is: ");
|
||||
strdst(&stest); //Set string to search
|
||||
slen = strspn("0123"); //Get position of "123"
|
||||
ctoa(slen, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
puts("Span matching \"0123456789\" is: ");
|
||||
strdst(&stest); //Set string to search
|
||||
slen = strspn("0123456789"); //Get position of "123"
|
||||
ctoa(slen, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
puts("Span matching \"789\" is: ");
|
||||
strdst(&stest); //Set string to search
|
||||
slen = strspn("789"); //Get position of "123"
|
||||
ctoa(slen, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
newlin();
|
||||
|
||||
//Demo strstr();
|
||||
putln(&stest); //Print test to screen
|
||||
puts("Position of \"234\" is: ");
|
||||
strdst(&stest); //Set string to search
|
||||
spos = strstr("234"); //Get position of "123"
|
||||
ctoa(spos, &sprt); //Convert to string
|
||||
putln(&sprt); //Print position to screen
|
||||
newlin();
|
||||
|
||||
goto exit;
|
||||
|
19
py65/test65.c02
Normal file
19
py65/test65.c02
Normal file
@ -0,0 +1,19 @@
|
||||
/**********************************************
|
||||
* TEST65 - Test Library py65.h02 for py65mon *
|
||||
**********************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
|
||||
char c; //Character
|
||||
char key; //Key read from keyboard
|
||||
|
||||
main:
|
||||
key = getkey(); //Read key from console
|
||||
if (key = $1B) //If Escape was pressed
|
||||
goto exit; // return to monitor
|
||||
prbyte(key); //Print ASCII value of key
|
||||
prchr(' '); // and a space
|
||||
prchr(key); //Print key character
|
||||
prchr(' '); // and another space
|
||||
goto main; //Loop
|
||||
|
163
py65/testblk.c02
Normal file
163
py65/testblk.c02
Normal file
@ -0,0 +1,163 @@
|
||||
/*******************************************
|
||||
* TESTBLK - Test Array Handling Functions *
|
||||
*******************************************/
|
||||
|
||||
//todo: Test blknxt() and blkprv()
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdio.h02>
|
||||
#include <stdlib.h02>
|
||||
#include <string.h02>
|
||||
#include <memory.h02>
|
||||
#include <block.h02>
|
||||
|
||||
char TRUE=$FF, FALSE=$00;
|
||||
|
||||
char c, i, n, r, z;
|
||||
char savlo,savhi,tmplo,tmphi; //Address Pointer
|
||||
char number[5];
|
||||
char numbrs = "zero one two threefour five six seveneightnine ten";
|
||||
char name1 = "Dick", name2 = "Jane";
|
||||
char temp[127];
|
||||
|
||||
char seglen = 7;
|
||||
char sgmt[6]; //Structure: [0-5]=Text, [6]=Binary
|
||||
char seg1[6],seg2[6];
|
||||
|
||||
char pass = " Pass ";
|
||||
char fail = " Fail ";
|
||||
|
||||
//Copy Textual Representation of n to temp
|
||||
void numcpy(n) {
|
||||
strdst(&temp);
|
||||
strcut(mult(n,5), &numbrs); //Copy Representation
|
||||
temp[5] = 0; //Cut off remainder of String
|
||||
z = strchr(' ', &temp);
|
||||
if (z:+) //Search for space in string
|
||||
temp[z] = 0; //and terminate at that point
|
||||
}
|
||||
|
||||
//Build String Segment in Temp
|
||||
void numtmp(n) {
|
||||
numcpy(n); //Copy Textual Representation to temp[0:5]
|
||||
temp[6] = i; //Set
|
||||
}
|
||||
|
||||
//Print Addresses
|
||||
void pradrs() {
|
||||
tmplo=srclo;tmphi=srchi;
|
||||
puts(" SRC: $");prbyte(tmphi);prbyte(tmplo);
|
||||
puts(" DST: $");prbyte(dsthi);prbyte(dstlo);
|
||||
puts(" BLK: $");prbyte(blkhi);prbyte(blklo);
|
||||
newlin();
|
||||
}
|
||||
|
||||
//Print Block Addresses
|
||||
void prbadr() {
|
||||
prbyte(blkshi);prbyte(blkslo);putc(' ');
|
||||
prbyte(blkehi);prbyte(blkelo);putc(' ');
|
||||
prbyte(blkhi);prbyte(blklo);newlin();
|
||||
}
|
||||
|
||||
main:
|
||||
|
||||
puts("blkbgn(&$4000);");
|
||||
blkbgn(&$4000); //Set Block Start
|
||||
if (blkshi == $40) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("blkend(&$4400);");
|
||||
blkend(&$4400); //Set Block End
|
||||
if (blkehi == $44) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("blkseg(seglen);");
|
||||
blkseg(seglen);
|
||||
if (blklen == seglen) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("blkrst(); ");
|
||||
blkrst();
|
||||
if (blkhi == $40) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("blkset('@'); ");
|
||||
blkset('@');
|
||||
r = $FF;
|
||||
blkrst();
|
||||
while (blkget(1,&sgmt)) {
|
||||
if (sgmt <> '@') r = $00;
|
||||
}
|
||||
if (r) putln(&pass); else putln(&fail);
|
||||
|
||||
setdst(&seg1); strcpy(&name1);seg1[6] = 1;
|
||||
setdst(&seg2); strcpy(&name2);seg2[6] = 2;
|
||||
puts("blkswp(seglen, &seg2);");
|
||||
blkrst();
|
||||
blkput(seglen, &seg1);
|
||||
blkrst();
|
||||
setdst(&temp);
|
||||
blkswp(seglen, &seg2);
|
||||
r = $FF;
|
||||
blkget(seglen, &sgmt);
|
||||
if (strcmp(&name2)) r = $00;
|
||||
if (sgmt[6] <> 2) r = $00;
|
||||
setdst(&seg2);
|
||||
if (strcmp(&name1)) r = $00;
|
||||
if (seg2[6] <> 1) r = $00;
|
||||
if (r) putln(&pass); else putln(&fail);
|
||||
|
||||
blkset(0);
|
||||
puts("blkput(seglen, &temp);");
|
||||
r = TRUE;
|
||||
blkrst();
|
||||
for (i=0; i<10; i++) {
|
||||
numtmp(i);
|
||||
savlo=blklo;savhi=blkhi;
|
||||
blkput(seglen, &temp);
|
||||
dstlo=savlo;dsthi=savhi;
|
||||
if (memcmp(seglen,&temp)) r = FALSE;
|
||||
}
|
||||
if (blklo <> 70) r = TRUE;
|
||||
if (r) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("blkmem(seglen, &temp);");
|
||||
r = $FF;
|
||||
for (i=9; i:+; i--) {
|
||||
numtmp(i);
|
||||
r = blkmem(seglen, &temp);
|
||||
if (mult(seglen,i) <> dstlo) r = 0;
|
||||
}
|
||||
if (r) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("blkstr(seglen, &temp);");
|
||||
r = $FF;
|
||||
for (i=0; i<10; i++) {
|
||||
numtmp(i);
|
||||
setdst(&sgmt);
|
||||
r = blkstr(seglen, &temp);
|
||||
if (sgmt[6] <> i) r = 0;
|
||||
}
|
||||
if (r) putln(&pass); else putln(&fail);
|
||||
|
||||
blkrst();
|
||||
puts("blkget(seglen, &sgmt);");
|
||||
r = $FF;
|
||||
for (i=0; i<10; i++) {
|
||||
numtmp(i);
|
||||
setdst(&sgmt);
|
||||
r = blkget(seglen, &sgmt);
|
||||
if (memcmp(seglen, &temp)) r = 0;
|
||||
}
|
||||
if (r) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("blksrt(&temp);");
|
||||
blksrt(&temp);
|
||||
r = TRUE;
|
||||
seg1[0] = 0;
|
||||
blkrst();
|
||||
while(blkget(seglen, &seg2)) {
|
||||
if (!seg2[0]) break;
|
||||
if (strcmp(&seg1)<>1) r = FALSE;
|
||||
strdst(&seg1);strcpy(&seg2);
|
||||
}
|
||||
if (r) putln(&pass); else putln(&fail);
|
||||
|
||||
goto exit;
|
||||
|
60
py65/testct.c02
Normal file
60
py65/testct.c02
Normal file
@ -0,0 +1,60 @@
|
||||
/**********************************************
|
||||
* TESTCT - Test Library ctype.h02 in py65mon *
|
||||
**********************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <ctype.h02>
|
||||
|
||||
char c, i;
|
||||
|
||||
main:
|
||||
i = 0;
|
||||
|
||||
head:
|
||||
prchr(' ');
|
||||
prchr(' ');
|
||||
prchr(' ');
|
||||
prchr(' ');
|
||||
prchr(' ');
|
||||
prchr('C'); //Control
|
||||
prchr('S'); //White Space
|
||||
prchr('P'); //Punctuation
|
||||
prchr('D'); //Digit
|
||||
prchr('H'); //Hex Digit
|
||||
prchr('U'); //Upper Case
|
||||
prchr('L'); //Lower Case
|
||||
prchr('A'); //Alphabetic
|
||||
prchr('N'); //Alphanumeric
|
||||
prchr('G'); //Graphic
|
||||
prchr('R'); //Printable
|
||||
prchr('B'); //Binary
|
||||
newlin();
|
||||
|
||||
loop:
|
||||
prbyte(i);
|
||||
prchr(' ');
|
||||
c = i;
|
||||
if (c < $20) c = $20;
|
||||
if (c >= $7F) c = $20;
|
||||
prchr(c);
|
||||
prchr(' ');
|
||||
c = isctrl(i) & $0A | $20; prchr(c);
|
||||
c = isspce(i) & $0A | $20; prchr(c);
|
||||
c = ispnct(i) & $0A | $20; prchr(c);
|
||||
c = isdigt(i) & $0A | $20; prchr(c);
|
||||
c = ishdgt(i) & $0A | $20; prchr(c);
|
||||
c = isuppr(i) & $0A | $20; prchr(c);
|
||||
c = islowr(i) & $0A | $20; prchr(c);
|
||||
c = isalph(i) & $0A | $20; prchr(c);
|
||||
c = isalnm(i) & $0A | $20; prchr(c);
|
||||
c = isgrph(i) & $0A | $20; prchr(c);
|
||||
c = isprnt(i) & $0A | $20; prchr(c);
|
||||
c = isbdgt(i) & $0A | $20; prchr(c);
|
||||
newlin();
|
||||
i++;
|
||||
if (i == 0) goto exit;
|
||||
if (i & $0F <> 0) goto loop;
|
||||
newlin();
|
||||
c = getkey();
|
||||
if (c == $1B) goto exit;
|
||||
goto head;
|
18
py65/testif.c02
Normal file
18
py65/testif.c02
Normal file
@ -0,0 +1,18 @@
|
||||
/****************************************
|
||||
* TESTIF - Test C02 If/Then Statements *
|
||||
****************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdio.h02>
|
||||
|
||||
char true = $FF;
|
||||
char false = $00;
|
||||
char pass = " Passed";
|
||||
char fail = " Failed";
|
||||
|
||||
main:
|
||||
puts("if (true): "); if (true) putln(&pass); else putln(&fail);
|
||||
puts("if (false): "); if (false) putln(&fail); else putln(&pass);
|
||||
|
||||
goto exit;
|
||||
|
122
py65/testmem.c02
Normal file
122
py65/testmem.c02
Normal file
@ -0,0 +1,122 @@
|
||||
/*******************************************
|
||||
* TESTMEM - Test Array Handling Functions *
|
||||
*******************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdio.h02>
|
||||
#include <memory.h02>
|
||||
|
||||
char TRUE = $FF, FALSE = 0;
|
||||
char c, d, f, i, n, p;
|
||||
char rlen, rcmp, rpos;
|
||||
char byts[255];
|
||||
char lttr[255];
|
||||
char nmbr[255];
|
||||
char temp[255];
|
||||
char dest[255];
|
||||
char less = "less";
|
||||
char more = "more";
|
||||
char most = "most";
|
||||
char fail = " Fail ";
|
||||
char pass = " Pass ";
|
||||
|
||||
void prtemp() {
|
||||
puts("temp: ");
|
||||
for (i=0; i<255; i++) {
|
||||
prbyte(temp[i]);
|
||||
//putchr(' ');
|
||||
}
|
||||
}
|
||||
|
||||
main:
|
||||
|
||||
//Populate arrays
|
||||
i = 0; c = 'a'; d = '0';
|
||||
do {
|
||||
byts[i] = i;
|
||||
lttr[i] = c;
|
||||
c++; if (c>'z') c = 'a';
|
||||
nmbr[i] = d;
|
||||
d++; if (d>'9') d = '0';
|
||||
i++;
|
||||
} while (i>0);
|
||||
|
||||
//Test memchr()
|
||||
putln("memdst(&byts);"); memdst(&byts);
|
||||
puts("memchr(i, 255);");
|
||||
p = TRUE;
|
||||
for (i=0; i<255; i++) {
|
||||
//prbyte(i); prchr('='); prbyte(byts[i]); prchr(',');
|
||||
c = memchr(i,255);
|
||||
//prbyte(c); prchr(' '); prchr(' ');
|
||||
if (c <> i) p = FALSE;
|
||||
}
|
||||
if (p) putln(&pass); else putln(&fail);
|
||||
newlin();
|
||||
|
||||
//Test memcmp()
|
||||
puts("less="); puts(&less);
|
||||
puts(" more="); puts(&more);
|
||||
puts(" most="); putln(&most);
|
||||
|
||||
putln("memdst(&more);");
|
||||
memdst(&more);
|
||||
|
||||
puts("memcmp(2, &most):");
|
||||
rcmp = memcmp(2, &most);
|
||||
if (!rcmp) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("memcmp(4, &most):");
|
||||
rcmp = memcmp(4, &most);
|
||||
if (rcmp :-) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("memcmp(3, &more):");
|
||||
rcmp = memcmp(3, &more);
|
||||
if (!rcmp) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("memcmp(3, &less):");
|
||||
rcmp = memcmp(3, &less);
|
||||
if (rcmp > 0) putln(&pass); else putln(&fail);
|
||||
newlin();
|
||||
|
||||
//Test memset() and memcpy()
|
||||
putln("memdst(&temp);");
|
||||
memdst(&temp);
|
||||
|
||||
puts("memset(0,20); ");
|
||||
memset(0,20);
|
||||
|
||||
puts("temp=");
|
||||
putln(&temp);
|
||||
|
||||
puts("memset('@',20); ");
|
||||
memset('@',20);
|
||||
|
||||
puts("temp=");
|
||||
putln(&temp);
|
||||
|
||||
puts("memcpy(10, <tr); ");
|
||||
memcpy(10, <tr);
|
||||
|
||||
puts("temp=");
|
||||
putln(&temp);
|
||||
|
||||
puts("memcmp(10, <tr);");
|
||||
rcmp = memcmp(10, <tr);
|
||||
if (!rcmp) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("memcmp(11, <tr);");
|
||||
rcmp = memcmp(11, <tr);
|
||||
if (rcmp > 0) putln(&pass); else putln(&fail);
|
||||
newlin();
|
||||
|
||||
memdst(&temp); memcpy("ABCDEF");
|
||||
memdst(&dest); memcpy("123456");
|
||||
puts("memdst(&dest);memswp(3,&temp);");
|
||||
memswp(3,&temp);
|
||||
rcmp = memcmp(6,"ABC456");
|
||||
memdst(&temp); rcmp = memcmp(6,"123DEF") | rcmp;
|
||||
if (rcmp) putln(&fail); else putln(&pass);
|
||||
goto exit;
|
||||
|
||||
|
212
py65/testsl.c02
Normal file
212
py65/testsl.c02
Normal file
@ -0,0 +1,212 @@
|
||||
/************************************************
|
||||
* TESTSL - Test Library stdlib.h02 for py65mon *
|
||||
************************************************/
|
||||
|
||||
#include <py65.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, prodct, acmltr;
|
||||
|
||||
mltplr = 1;
|
||||
mrloop:
|
||||
prbyte(mltplr);
|
||||
mltpnd = 1;
|
||||
acmltr = 0;
|
||||
mdloop:
|
||||
acmltr = acmltr + mltplr;
|
||||
prodct = mult(mltplr,mltpnd);
|
||||
if (prodct <> acmltr) 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;
|
||||
acmltr = 0;
|
||||
ddloop:
|
||||
prbyte(mltpnd);
|
||||
acmltr = acmltr + 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(prodct);
|
||||
prchr(',');
|
||||
prbyte(acmltr);
|
||||
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;
|
||||
|
124
py65/teststr.c02
Normal file
124
py65/teststr.c02
Normal file
@ -0,0 +1,124 @@
|
||||
/******************************************
|
||||
* TESTSTR - Test Common String Functions *
|
||||
******************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdio.h02>
|
||||
#include <string.h02>
|
||||
|
||||
char slen, scmp, spos, stot;
|
||||
char frst = "string one.";
|
||||
char scnd = "string two.";
|
||||
char temp[32];
|
||||
char dest[32];
|
||||
char less = "less";
|
||||
char more = "more";
|
||||
char most = "most";
|
||||
char test = "test";
|
||||
char pass = "Pass ";
|
||||
char fail = "Fail ";
|
||||
|
||||
main:
|
||||
//Test strchr
|
||||
puts("test="); putln(&test);
|
||||
|
||||
puts("strchr('t', &test): ");
|
||||
spos = strchr('t', &test);
|
||||
if (spos = 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strchr('s', &test): ");
|
||||
spos = strchr('s', &test);
|
||||
if (spos = 2) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strchr('x', &test): ");
|
||||
spos = strchr('x', &test);
|
||||
if (spos = $FF) putln(&pass); else putln(&fail);
|
||||
|
||||
//Test strrch
|
||||
|
||||
puts("strrch('t', &test): ");
|
||||
spos = strrch('t', &test);
|
||||
if (spos = 3) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strrch('s', &test): ");
|
||||
spos = strrch('s', &test);
|
||||
if (spos = 2) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strchr('x', &test): ");
|
||||
spos = strchr('x', &test);
|
||||
if (spos = $FF) putln(&pass); else putln(&fail);
|
||||
|
||||
//Test strlen
|
||||
puts("strlen(&test): ");
|
||||
slen = strlen(&test);
|
||||
if (slen = 4) putln(&pass);
|
||||
else putln(&fail);
|
||||
newlin();
|
||||
|
||||
//Test strcmp
|
||||
puts("less="); puts(&less);
|
||||
puts(" more="); puts(&more);
|
||||
puts(" most="); putln(&most);
|
||||
|
||||
putln("strdst(&more)");
|
||||
strdst(&more);
|
||||
|
||||
puts("strcmp(&most): ");
|
||||
scmp = strcmp(&most);
|
||||
if (scmp :-) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strcmp(&more): ");
|
||||
scmp = strcmp(&more);
|
||||
if (!scmp) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strcmp(&less): ");
|
||||
scmp = strcmp(&less);
|
||||
if (scmp > 0) putln(&pass); else putln(&fail);
|
||||
newlin();
|
||||
|
||||
//Test strcpy, strcat, strstr
|
||||
temp[0] = 0; //Clear temp
|
||||
puts("temp="); puts(&temp);
|
||||
puts(" frst="); puts(&frst);
|
||||
puts(" scnd="); putln(&scnd);
|
||||
|
||||
putln("strdst(&temp)");
|
||||
strdst(&temp);
|
||||
|
||||
puts("strcpy(&frst): ");
|
||||
strcpy(&frst);
|
||||
scmp = strcmp(&frst);
|
||||
if (scmp = 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strcmp(&frst): ");
|
||||
scmp = strcmp(&frst);
|
||||
if (scmp = 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strcat(&scnd): ");
|
||||
slen = strlen(&temp);
|
||||
stot = strlen(&scnd) + slen;
|
||||
strcat(&scnd);
|
||||
if (strlen(&temp) == stot) putln(&pass); else putln(&fail);
|
||||
|
||||
puts("strstr(&frst): ");
|
||||
spos = strstr(&frst);
|
||||
if (spos = 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strstr(&scnd): ");
|
||||
spos = strstr(&scnd);
|
||||
if (spos = slen) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strstr(&test): ");
|
||||
spos = strstr(&test);
|
||||
if (spos = $FF) putln(&pass); else putln(&fail);
|
||||
|
||||
putln("strdst(&dest);");
|
||||
strdst(&dest);
|
||||
puts("strcut(slen, &temp): ");
|
||||
stot = strcut(slen, &temp);
|
||||
scmp = strcmp(&scnd);
|
||||
if (scmp = 0) putln(&pass);
|
||||
else putln(&fail);
|
||||
|
||||
goto exit;
|
||||
|
115
py65/teststx.c02
Normal file
115
py65/teststx.c02
Normal file
@ -0,0 +1,115 @@
|
||||
/********************************************
|
||||
* TESTSTX - Test Extended String Functions *
|
||||
********************************************/
|
||||
|
||||
#include <py65.h02>
|
||||
#include <stdio.h02>
|
||||
#include <string.h02>
|
||||
#include <stringx.h02>
|
||||
|
||||
char slen, sres;
|
||||
char span = "abcdef";
|
||||
char smax[128];
|
||||
char scba = "cba";
|
||||
char sfed = "fed";
|
||||
char sxyz = "xyz";
|
||||
char snul = "";
|
||||
char pass = "Pass ";
|
||||
char fail = "Fail ";
|
||||
|
||||
|
||||
void tests(slen) {
|
||||
|
||||
//Test scba
|
||||
puts("strspn(&scba): ");
|
||||
sres = strspn(&scba);
|
||||
if (sres == 3) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strbrk(&scba): ");
|
||||
sres = strbrk(&scba);
|
||||
if (sres == 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strpbk(&scba): ");
|
||||
sres = strpbk(&scba);
|
||||
if (sres == 0) putln(&pass); else putln(&fail);
|
||||
|
||||
//Test span
|
||||
puts("strspn(&span): ");
|
||||
sres = strspn(&span);
|
||||
if (sres == 6) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strbrk(&span): ");
|
||||
sres = strbrk(&span);
|
||||
if (sres == 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strpbk(&span): ");
|
||||
sres = strpbk(&span);
|
||||
if (sres == 0) putln(&pass); else putln(&fail);
|
||||
|
||||
//Test sfed
|
||||
puts("strspn(&sfed): ");
|
||||
sres = strspn(&sfed);
|
||||
if (sres == 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strbrk(&sfed): ");
|
||||
sres = strbrk(&sfed);
|
||||
if (sres == 3) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strpbk(&sfed): ");
|
||||
sres = strpbk(&sfed);
|
||||
if (sres == 3) putln(&pass); else putln(&fail);
|
||||
|
||||
//Test sxyz
|
||||
puts("strspn(&sxyz): ");
|
||||
sres = strspn(&sxyz);
|
||||
if (sres == 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strbrk(&sxyz): ");
|
||||
sres = strbrk(&sxyz);
|
||||
if (sres == slen) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strpbk(&sxyz): ");
|
||||
sres = strpbk(&sxyz);
|
||||
if (sres == 255) putln(&pass); else putln(&fail);
|
||||
|
||||
//Test snull
|
||||
puts("strspn(&snul): ");
|
||||
sres = strspn(&snul);
|
||||
if (sres == 0) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strbrk(&snul): ");
|
||||
sres = strbrk(&snul);
|
||||
if (sres == slen) puts(&pass); else puts(&fail);
|
||||
|
||||
puts("strpbk(&snul): ");
|
||||
sres = strpbk(&snul);
|
||||
if (sres == 255) putln(&pass); else puts(&fail);
|
||||
newlin();
|
||||
|
||||
}
|
||||
|
||||
main:
|
||||
//Initialize smax
|
||||
char i;
|
||||
for (i=0; i<128; i++) smax[i] = i & 15 + 'a';
|
||||
|
||||
//Display Test Strings
|
||||
puts("span="); putln(&span);
|
||||
puts("smax="); putln(&smax);
|
||||
puts("scba="); putln(&scba);
|
||||
puts("sxyz="); putln(&sxyz);
|
||||
puts("snul="); putln(&snul);
|
||||
newlin();
|
||||
|
||||
//Test span
|
||||
putln("strdst(&span);");
|
||||
strdst(&span);
|
||||
tests(strlen(&span));
|
||||
|
||||
//Test smax
|
||||
putln("strdst(&smax);");
|
||||
strdst(&smax);
|
||||
tests(strlen(&smax));
|
||||
|
||||
goto exit;
|
||||
|
Loading…
Reference in New Issue
Block a user