1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-24 15:31:17 +00:00
C02/py65/teststk.c02

200 lines
4.6 KiB
Plaintext
Raw Permalink Normal View History

2018-07-26 14:33:03 +00:00
/***********************************************
* TESTSTK - Test Stack Manipulation Functions *
***********************************************/
#include <py65.h02>
#include <stddef.h02>
2018-07-26 14:33:03 +00:00
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <string.h02>
#include <memory.h02>
#include <stack.h02>
char c,f,g,i;
2018-07-26 14:33:03 +00:00
char aa,xx,yy;
char lo,hi;
2019-03-22 23:32:08 +00:00
const char r={6,7,8,9};
const char s="Test String";
2018-07-26 14:33:03 +00:00
char t[255];
main:
for (i=0;i<$20;i++) srclo[i]=0; //Initialize Pointers
puts("Setting Stack Start Address\t");
puts("stkbgn($7FFF);\t");
2018-07-26 14:33:03 +00:00
stkbgn(&$7FFF); lo=stkslo; hi=stkshi;
setdst("stks"); cklohi(&$7FFF);
puts("Setting Stack End Address\t");
puts("stkend($807E)\t");
2018-07-26 14:33:03 +00:00
stkend(&$807E); lo=stkelo; hi=stkehi;
setdst("stke"); cklohi(&$807E);
puts("Setting Stack Pointer Address\t");
puts("stkset($8765)\t");
2018-07-26 14:33:03 +00:00
stkset(&$8765); lo=stklo; hi=stkhi;
setdst("stk"); cklohi(0,&$8765);
puts("Resetting Stack Pointer\t\t");
puts("stkrst()\t");
2018-07-26 14:33:03 +00:00
stkrst(); lo=stklo; hi=stkhi;
setdst("stk"); cklohi(0,&$7FFF);
puts("Getting Stack Pointer Address\t");
puts("stkptr()\t");
2018-07-26 14:33:03 +00:00
aa, hi, lo = stkptr();
setdst(""); cklohi(0,&$7FFF);
puts("Setting Source to Stack Pointer\t");
puts("stksrc()\t");
2018-07-26 14:33:03 +00:00
stksrc(); lo=srclo; hi=srchi;
setdst("src"); cklohi(0,&$7FFF);
puts("Setting Dest. to Stack Pointer\t");
puts("stkdst()\t");
2018-07-26 14:33:03 +00:00
stkdst(); lo=dstlo; hi=dsthi;
setdst("src"); cklohi(0,&$7FFF);
puts("Incrementing Stack Pointer\t");
puts("stkinc()\t");
2018-07-26 14:33:03 +00:00
stkinc(); lo=stklo; hi=stkhi;
setdst("stk"); cklohi(0,&$8000);
puts("Decrementing Stack Pointer\t");
puts("stkdec()\t");
2018-07-26 14:33:03 +00:00
stkdec(); lo=stklo; hi=stkhi;
setdst("stk"); cklohi(0,&$7FFF);
puts("Pushing Array onto Stack\t");
puts("stkpsh(@r,$r)\t");
2018-07-26 14:33:03 +00:00
aa,hi,lo=stkptr(); //Save Stack Pointer
f=stkpsh(@r,&r); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
setdst(*,hi,lo); g=(memcmp(@r, &r)==0) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(f & g);
chkptr(&$8004);
puts("Duplicating Top of Stack\t");
puts("stkdup()\t");
2018-07-26 14:33:03 +00:00
aa,hi,lo=stkptr(); //Save Stack Pointer
f=stkdup(); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
setdst(*,hi,lo); g=(memcmp(@r, &r)==0) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(f & g);
chkptr(&$8009);
puts("Pushing String onto Stack\t");
puts("stkstr(&s)\t");
2018-07-26 14:33:03 +00:00
aa,hi,lo=stkptr(); //Save Stack Pointer
f=stkstr(&s); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
setdst(*,hi,lo); g=(strcmp(&s)==0) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(f & g);
chkptr(&$8016);
puts("Duplicating Second Stack Entry\t");
puts("stkovr()\t");
aa,hi,lo=stkptr(); //Save Stack Pointer
f=stkovr(); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
setdst(*,hi,lo); g=(memcmp(@r, &r)==0) ? #TRUE : #FALSE;
psorfl(f & g);
chkptr(&$801B);
c = anykey(); if (c == #esckey) goto exit;
puts("Dropping Duplicate off Stack\t");
puts("stkdrp()\t");
f=stkdrp(); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
g=(f==4) ? #TRUE : #FALSE;
psorfl(f & g);
chkptr(&$8016);
2018-07-26 14:33:03 +00:00
puts("Copying String from Stack\t");
puts("stktop(&t)\t");
2018-07-26 14:33:03 +00:00
f=stktop(&t); setdst(&t); printf("\"%s\":");
2019-03-22 23:32:08 +00:00
g=(strcmp(&s)==0) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(f & g);
chkptr(&$8016);
puts("Popping String off Stack\t");
puts("stkpop(&t)\t");
2018-07-26 14:33:03 +00:00
f=stkpop(&t); setdst(&t); printf("\"%s\":");
2019-03-22 23:32:08 +00:00
g=(strcmp(&s)==0) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(f & g);
chkptr(&$8009);
puts("Dropping Duplicate off Stack\t");
puts("stkdrp()\t");
2018-07-26 14:33:03 +00:00
f=stkdrp(); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
g=(f==4) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(f & g);
chkptr(&$8004);
puts("Popping Array off Stack\t\t");
puts("stkpop(&t)\t");
2018-07-26 14:33:03 +00:00
f=stkpop(&t); prtary(f); puts(": ");
2019-03-22 23:32:08 +00:00
g=(memcmp(f,&r)==0) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(f & g);
chkptr(&$7FFF);
puts("Popping off Empty Stack\t\t");
puts("stkpop(&t)\t");
2018-07-26 14:33:03 +00:00
f=stkpop(&t); printf(f,"bytes=%d:");
if (f) fail(); else pass();
chkptr(&$7FFF);
puts("Overflowing Stack\t\t");
puts("stkpsh(255,&t)\t");
2018-07-26 14:33:03 +00:00
f=stkpsh(255,&t); printf(f,"bytes=%d:");
if (f) fail(); else pass();
chkptr(&$7FFF);
putln("Tests Complete");
2018-07-26 14:33:03 +00:00
goto exit;
void chkptr(aa,yy,xx) {
puts("\tChecking Stack Pointer\t\t\t");
puts("address=$"); prbyte(stkhi); prbyte(stklo); putc(':');
2019-03-22 23:32:08 +00:00
xx = (stklo == xx) ? #TRUE : #FALSE;
yy = (stkhi == yy) ? #TRUE : #FALSE;
psorfl(xx & yy);
2018-07-26 14:33:03 +00:00
}
void prtary(aa) {
putc('{');
for (i=0;i<aa;i++) {
if (i) putc(',');
putdec(t[i]);
}
putc('}');
}
void cklohi(aa,yy,xx) {
putdst(); puts("lo=$"); prbyte(lo); putc(' ');
putdst(); puts("hi=$"); prbyte(hi); putc(':');
2019-03-22 23:32:08 +00:00
xx = (lo == xx) ? #TRUE : #FALSE;
yy = (hi == yy) ? #TRUE : #FALSE;
2018-07-26 14:33:03 +00:00
psorfl(xx & yy);
}
void prtstk() {puts(" stk");if (aa) putc(aa);}
void psorfl(aa) {if (aa) pass(); else {fail(); goto exit;}}
void pass() {putln(" Pass");}
void fail() {putln(" Fail");}
puts("Swapping Top and Second Entry\t");
puts("stkswp()\t");
f=stkswp(); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
g=(f==12) ? #TRUE : #FALSE;
psorfl(f & g);
chkptr(&$801B);
puts("Dropping Swapped Entry off Stack\t");
puts("stkdrp()\t");
f=stkdrp(); printf(f,"bytes=%d:");
2019-03-22 23:32:08 +00:00
g=(f==4) ? #TRUE : #FALSE;
psorfl(f & g);
chkptr(&$8016);