1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-22 16:34:15 +00:00
C02/test/blktest.c02

181 lines
5.0 KiB
Plaintext
Raw Normal View History

/*****************************************
* TESTBLK - Test Module block Functions *
*****************************************/
2018-07-31 00:03:56 +00:00
2018-02-14 00:52:14 +00:00
//todo: Test blknxt() and blkprv()
2018-07-31 00:03:56 +00:00
//Specify System Header using -H option
2018-07-31 00:03:56 +00:00
#include <stddef.h02>
2018-02-14 00:52:14 +00:00
#include <stdlib.h02>
#include <intlib.h02>
2018-07-31 00:03:56 +00:00
#include <stdio.h02>
#include <stdiox.h02>
2018-02-14 00:52:14 +00:00
#include <string.h02>
2018-07-31 00:03:56 +00:00
#include <test.h02>
2018-02-14 00:52:14 +00:00
#include <memory.h02>
#include <block.h02>
char c, i, n, r, z;
int chkint, savptr;
2018-02-14 00:52:14 +00:00
char number[5];
2019-03-22 23:32:08 +00:00
const char numbrs = "zero one two threefour five six seveneightnine ten";
const char sorted = {8,5,4,9,1,7,6,3,2,0};
const char name1 = "Dick", name2 = "Jane";
2018-07-31 00:03:56 +00:00
char block[255]; //Array to Use as Block
2018-02-14 00:52:14 +00:00
char temp[127];
2018-07-31 00:03:56 +00:00
char seglo[9],seghi[9];
char aa,xx,yy,zz;
int yx;
2018-02-14 00:52:14 +00:00
struct ssgmt {char key[6]; char flag; char value;};
2018-07-31 00:03:56 +00:00
struct ssgmt sgmt;
struct ssgmt seg1;
struct ssgmt seg2;
struct ssgmt tseg;
2018-02-14 00:52:14 +00:00
char cmpptr(chkint) {putadr(blkptr); return cmpadr(blkptr);}
void chkadr(yx) {putadr(yx);cmpadr(yx);psflln(<yx & >yx);}
char equals(aa,zz) {A = (aa == zz) ? #TRUE : #FALSE;}
char cmpadr(yx) {xx = equals(<chkint, <yx); yy = equals(>chkint, <yx); return xx & yy;}
void clrseg() {setdst(); memset(0, @sgmt);}
char chkmem() {A = equals(memcmp(), 0);}
void prtadr() {putwrd(); putspc();}
void prbadr() {putadr(blkptr); prtadr(blkend); putwrd(blkptr);newlin();}
2018-07-31 00:03:56 +00:00
main:
2018-07-31 00:03:56 +00:00
puts("blkbgn = &$4321; "); blkbgn = &$4321;
puts("blkend = &$4567; "); blkend = &$4567;
putln("blklen = @sgmt;"); blklen = @sgmt;
2018-07-31 00:03:56 +00:00
puts("blkrst(); ");
blkrst();
chkint = &$4321; chkadr(blkptr);
2018-07-31 00:03:56 +00:00
puts("blknxt(); ");
blknxt();
chkint = &$432A; chkadr(blkptr);
2018-07-31 00:03:56 +00:00
puts("blkprv(); ");
blkprv();
chkint = &$4321; chkadr(blkptr);
2018-07-31 00:03:56 +00:00
puts("blkset('@'); ");
blkset('@'); r=cmpptr(&$4321);
while (blkget(1,&sgmt)) {if (sgmt[0]<>'@') r=#FALSE;} psflln(r);
2018-07-31 00:03:56 +00:00
newlin();//if (anykey()==#ESCKEY) goto exit;
setdst(&seg1.key); strcpy(&name1);seg1.flag=#TRUE; seg1.value = 1;
puts("seg1=");prtseg(&seg1);
setdst(&seg2.key); strcpy(&name2);seg2.flag=#FALSE;seg2.value = 2;
puts("seg2=");prtseg(&seg2);
setdst(&sgmt);memcpy(@seg2,&seg2);
puts("sgmt=");prtseg(&sgmt);
newlin();
puts("blkput(@seg1,&seg1); ");
blkrst(); blkput(@seg1,&seg1); r=cmpptr(&$432A);
2018-07-31 00:03:56 +00:00
memdst(&$4321); r = chkmem(@seg1,&seg1) & r;
psflln(r);
puts(" _blk=");prtseg(&$4321);
newlin();
puts("blkswp(@sgmt,&sgmt); ");
blkrst(); blkswp(@sgmt,&sgmt); r = cmpptr(&$4321);
2018-07-31 00:03:56 +00:00
memdst(&$4321); r = chkmem(@seg2,&seg2) & r;
memdst(&sgmt); r = chkmem(@seg1,&seg1) & r;
psflln(r);
puts(" _blk=");prtseg(&$4321);
puts(" sgmt=");prtseg(&sgmt);
anykey();
puts("blkput(@sgmt, &sgmt);\n"); blkset(0); blkrst(); r = #TRUE;
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); savptr=blkptr;
blkput(@sgmt,&sgmt); seglo[i]=<savptr; seghi[i]=>savptr;
putadr(savptr); puts(" _blk="); prtseg(savptr);
setdst(savptr); if (memcmp(@sgmt,&sgmt)) r = #FALSE;
2018-02-14 00:52:14 +00:00
}
2018-07-31 00:03:56 +00:00
puts("blkput:"); psflln(r); newlin();
2018-02-14 00:52:14 +00:00
2018-07-31 00:03:56 +00:00
puts("blkget(@temp, &temp);\n"); blkrst(); r = #TRUE;
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); memclr(@temp, &temp);
putadr(blkptr); r = blkget(@temp, &temp);
2018-07-31 00:03:56 +00:00
setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE;
puts(" temp="); prtseg(&temp);
2018-02-14 00:52:14 +00:00
}
2018-07-31 00:03:56 +00:00
puts("blkget:"); psflln(r); anykey();
2018-02-14 00:52:14 +00:00
2018-07-31 00:03:56 +00:00
puts("blkmem(@sgmt, &sgmt);\n"); r = #TRUE;
for (i=9; i:+; i--) {
printf(i,"%d: "); nsgmt(i,&sgmt);
blkmem(@sgmt,&sgmt);
if (<dstptr<>seglo[i]) r = #FALSE;
if (>dstptr<>seghi[i]) r = #FALSE;
putadr(dstptr); puts(" _blk="); prtseg(dstptr);
2018-02-14 00:52:14 +00:00
}
2018-07-31 00:03:56 +00:00
puts("blkmem:"); psflln(r); newlin();
2018-02-14 00:52:14 +00:00
2018-07-31 00:03:56 +00:00
puts("blkstr(@sgmt, &sgmnt);\n"); r = #TRUE;
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(i,&sgmt); memclr(@temp, &temp);
setdst(&temp); blkstr(&sgmt.key);
if (<srcptr<>seglo[i]) r = #FALSE;
if (>srcptr<>seghi[i]) r = #FALSE;
putadr(srcptr); puts(" temp="); prtseg(&temp);
2018-07-31 00:03:56 +00:00
if (memcmp(@sgmt, &sgmt)) r = #FALSE;
i++; if (i=9) i=0; //evens then odds
2018-02-14 00:52:14 +00:00
}
2018-07-31 00:03:56 +00:00
puts("blkstr:"); psflln(r); anykey();
2018-02-14 00:52:14 +00:00
2018-07-31 00:03:56 +00:00
puts("blksrt(&temp);\n"); r = #TRUE; blksrt(&temp);blkrst();
for (i=0; i<10; i++) {
printf(i,"%d: "); nsgmt(sorted[i],&sgmt); memclr(@temp, &temp);
putadr(blkptr); r = blkget(@temp, &temp);
2018-07-31 00:03:56 +00:00
setdst(&temp); if (memcmp(@sgmt, &sgmt)) r = #FALSE;
puts(" temp="); prtseg(&temp);
}
puts("blksrt:"); psflln(r); newlin();
2018-02-14 00:52:14 +00:00
2018-07-31 00:03:56 +00:00
putln("Tests complete.");
2018-02-14 00:52:14 +00:00
2018-07-31 00:03:56 +00:00
goto exit;
2018-02-14 00:52:14 +00:00
2018-07-31 00:03:56 +00:00
void prtseg(aa,yy,xx) {
setdst(&tseg); memcpy(@tseg,yy,xx);
setdst(&tseg.key); printf("key=\"%s\",");
puts("flag=");if (tseg.flag) puts("TRUE"); else puts("FALSE");
printf(tseg.value,",value=%d\n");
2018-02-14 00:52:14 +00:00
}
2018-07-31 00:03:56 +00:00
//Copy Textual Representation of n to temp
void numstr(n,yy,xx) {
strdst(&temp); strcut(mult(n,5),&numbrs); //Copy Representation
temp[5] = 0; //Cut off remainder of String
z=strchr(' ', &temp); if (z:+) temp[z]=0; //and terminate at space
setdst(.,yy,xx); strcpy(&temp);
2018-02-14 00:52:14 +00:00
}
2018-07-31 00:03:56 +00:00
//Build String Segment in Temp
void nsgmt(n,yx) {
2018-07-31 00:03:56 +00:00
memclr(@tseg,&tseg);
numstr(n,&tseg.key);
tseg.flag = trufls(n);
tseg.value = n;
setdst(yx); memcpy(@tseg,&tseg);
2018-02-14 00:52:14 +00:00
}
2018-07-31 00:03:56 +00:00
//Print Addresses
void pradrs() {
puts(" SRC: $");putwrd(srcptr);
puts(" DST: $");putwrd(dstptr);
puts(" BLK: $");putwrd(blkptr);
2018-07-31 00:03:56 +00:00
newlin();
2018-02-14 00:52:14 +00:00
}