1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-28 10:51:14 +00:00
C02/py65/testmem.c02
2018-07-30 17:20:16 -04:00

115 lines
2.6 KiB
Plaintext

/*******************************************
* TESTMEM - Test Array Handling Functions *
*******************************************/
#include <py65.h02>
#include <stddef.h02>
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <memory.h02>
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()
setdst(&less); printf("less=\"%s\", ");
setdst(&more); printf("more=\"%s\", ");
setdst(&most); printf("most=\"%s\"\n");
putln("memdst(&more);");
memdst(&more);
rcmp = memcmp(2, &most);
printf(rcmp,"memcmp(2, &most)=$%h:");
if (!rcmp) puts(&pass); else puts(&fail);
rcmp = memcmp(4, &most);
printf(rcmp,"memcmp(4, &most)=$%h:");
if (rcmp :-) putln(&pass); else putln(&fail);
rcmp = memcmp(4, &more);
printf("memcmp(4, &more)=$%h:");
if (!rcmp) puts(&pass); else puts(&fail);
rcmp = memcmp(4, &less);
printf("memcmp(4, &less)=$%h:");
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, &lttr); "); memcpy(10, &lttr);
puts("temp="); putln(&temp);
puts("memcmp(10, &lttr);");
rcmp = memcmp(10, &lttr);
if (!rcmp) putln(&pass); else putln(&fail);
puts("memcmp(11, &lttr);");
rcmp = memcmp(11, &lttr);
if (rcmp > 0) putln(&pass); else putln(&fail);
newlin();
memdst(&temp); memcpy(7,"ABCDEF"); printf("temp=\"%s\", ");
memdst(&dest); memcpy(7,"123456"); printf("dest=\"%s\"\n");
putln("memdst(&dest);memswp(3,&temp);");
memdst(&dest); memswp(3,&temp);
memdst(&temp); printf("temp=\"%s\":"); florps(memcmp(7,"123DEF"));
memdst(&dest); printf("dest=\"%s\":"); florps(memcmp(7,"ABC456"));
newlin();
goto exit;
void florps(rcmp) {if (rcmp) putln(&fail); else putln(&pass);}