2018-02-14 00:52:14 +00:00
|
|
|
/*******************************************
|
|
|
|
* TESTBLK - Test Array Handling 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
|
|
|
|
2018-02-14 00:52:14 +00:00
|
|
|
#include <py65.h02>
|
2018-07-31 00:03:56 +00:00
|
|
|
#include <stddef.h02>
|
2018-02-14 00:52:14 +00:00
|
|
|
#include <stdlib.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;
|
|
|
|
char savlo,savhi,tmplo,tmphi; //Address Pointer
|
2018-07-31 00:03:56 +00:00
|
|
|
char chkhi,chklo; //Address Check
|
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;
|
2018-02-14 00:52:14 +00:00
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
struct ssgmt {
|
|
|
|
char key[6];
|
|
|
|
char flag;
|
|
|
|
char value;
|
|
|
|
};
|
2018-02-14 00:52:14 +00:00
|
|
|
|
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
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
main:
|
|
|
|
|
|
|
|
puts("blkbgn(&4321); ");
|
|
|
|
blkbgn(&$4321); //Set Block Start
|
|
|
|
setchk(&$4321); chkadr(blkshi,blkslo);
|
|
|
|
|
|
|
|
puts("blkend(&$4567); ");
|
|
|
|
blkend(&$4567); //Set Block End
|
|
|
|
setchk(&$4567); chkadr(blkehi,blkelo);
|
|
|
|
|
|
|
|
puts("blkseg(@sgmt); ");
|
|
|
|
blkseg(@sgmt);
|
|
|
|
printf(blklen,"blklen=%d:");
|
|
|
|
if (blklen == @sgmt) passln(); else failln();
|
|
|
|
|
|
|
|
puts("blkrst(); ");
|
|
|
|
blkrst();
|
|
|
|
setchk(&$4321); chkadr(blkhi,blklo);
|
|
|
|
|
|
|
|
puts("blknxt(); ");
|
|
|
|
blknxt();
|
|
|
|
setchk(&$432A); chkadr(blkhi,blklo);
|
|
|
|
|
|
|
|
puts("blkprv(); ");
|
|
|
|
blkprv();
|
|
|
|
setchk(&$4321); chkadr(blkhi,blklo);
|
|
|
|
|
|
|
|
puts("blkset('@'); ");
|
|
|
|
blkset('@'); r=chkptr(&$4321);
|
|
|
|
while (blkget(1,&sgmt)) {if (sgmt<>'@') r=#FALSE;} psflln(r);
|
|
|
|
|
|
|
|
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=chkptr(&$432A);
|
|
|
|
memdst(&$4321); r = chkmem(@seg1,&seg1) & r;
|
|
|
|
psflln(r);
|
|
|
|
puts(" _blk=");prtseg(&$4321);
|
|
|
|
newlin();
|
|
|
|
|
|
|
|
puts("blkswp(@sgmt,&sgmt); ");
|
|
|
|
blkrst(); blkswp(@sgmt,&sgmt); r = chkptr(&$4321);
|
|
|
|
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); savlo=blklo;savhi=blkhi;
|
|
|
|
blkput(@sgmt,&sgmt); seglo[i]=savlo; seghi[i]=savhi;
|
|
|
|
putadr(*,savhi,savlo); puts(" _blk="); prtseg(*,savhi,savlo);
|
|
|
|
setdst(*,savhi,savlo); 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(*,blkhi,blklo); r = blkget(@temp, &temp);
|
|
|
|
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 (dstlo<>seglo[i]) r = #FALSE;
|
|
|
|
if (dsthi<>seghi[i]) r = #FALSE;
|
|
|
|
putadr(*,dsthi,dstlo); puts(" _blk="); prtseg(*,dsthi,dstlo);
|
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 (srclo<>seglo[i]) r = #FALSE;
|
|
|
|
if (srchi<>seghi[i]) r = #FALSE;
|
|
|
|
putadr(*,srchi,srclo); puts(" temp="); prtseg(&temp);
|
|
|
|
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(*,blkhi,blklo); r = blkget(@temp, &temp);
|
|
|
|
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
|
|
|
char chkptr() {
|
|
|
|
setchk(); //pass through args
|
|
|
|
putadr(*,blkhi,blklo);
|
|
|
|
return cmpadr(*,blkhi,blklo);
|
|
|
|
}
|
|
|
|
void setchk() {
|
|
|
|
chklo=X; chkhi=Y;
|
|
|
|
}
|
2018-02-14 00:52:14 +00:00
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
void chkadr(tmphi,tmplo) {
|
|
|
|
putadr(*,tmphi,tmplo);
|
|
|
|
cmpadr(*,tmphi,tmplo);
|
|
|
|
psflln(tmplo & tmphi);
|
|
|
|
}
|
2018-02-14 00:52:14 +00:00
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
char cmpadr(aa,yy,xx) {
|
|
|
|
xx = (chklo == xx) ? #TRUE : #FALSE;
|
|
|
|
yy = (chkhi == yy) ? #TRUE : #FALSE;
|
|
|
|
return xx & yy;
|
2018-02-14 00:52:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
void clrseg() {
|
|
|
|
setdst(); memset(0, @sgmt);
|
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
|
|
|
char chkmem() {
|
|
|
|
aa = memcmp(); //pass through args
|
|
|
|
aa = (aa==0) ? #TRUE : #FALSE;
|
|
|
|
return aa;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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,tmphi,tmplo) {
|
|
|
|
memclr(@tseg,&tseg);
|
|
|
|
numstr(n,&tseg.key);
|
|
|
|
tseg.flag = trufls(n);
|
|
|
|
tseg.value = n;
|
|
|
|
setdst(*,tmphi,tmplo); memcpy(@tseg,&tseg);
|
2018-02-14 00:52:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
//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();
|
2018-02-14 00:52:14 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 00:03:56 +00:00
|
|
|
//Print Block Addresses
|
|
|
|
void prbadr() {
|
|
|
|
prbyte(blkshi);prbyte(blkslo);putc(' ');
|
|
|
|
prbyte(blkehi);prbyte(blkelo);putc(' ');
|
|
|
|
prbyte(blkhi);prbyte(blklo);newlin();
|
|
|
|
}
|
2018-02-14 00:52:14 +00:00
|
|
|
|