mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-25 06:31:25 +00:00
160 lines
3.9 KiB
Plaintext
160 lines
3.9 KiB
Plaintext
/****************************************************
|
|
* INTS - Test Integer Variables and Function Calls */
|
|
|
|
//Specify System Header using -H option
|
|
#include <screen.h02>
|
|
#include <stddef.h02>
|
|
#include <stdlib.h02>
|
|
#include <intlib.h02>
|
|
#include <stdio.h02>
|
|
#include <stdiox.h02>
|
|
#include <string.h02>
|
|
#include <test.h02>
|
|
|
|
char size;
|
|
char s[128]; //Test String
|
|
|
|
char cval,cnum,ctot; //Character Function Variables
|
|
int ivar,ival; //Integer Variables
|
|
int icmp,itot,ires; //Function Variables
|
|
int less, more; //Test Values for imin() and imax()
|
|
|
|
int yx, dd; //Function Arguments and Variables
|
|
|
|
void cpival(icmp) {
|
|
if (>ival <> >icmp or <ival <> <icmp) {
|
|
putwrd(ival); puts("<>"); putwrd(icmp);
|
|
failln();
|
|
goto exit;
|
|
}
|
|
}
|
|
|
|
/* Test imin() and imax() */
|
|
void minmax() {
|
|
newlin();
|
|
puts("LESS=$"); putwrd(less); puts(",MORE=$"); putwrd(more); newlin();
|
|
puts(" IMIN()=$"); setsrc(less);
|
|
ival = imin(more); putwrd(ival); newlin();
|
|
cpival(less);
|
|
puts(" IMAX()=$"); setsrc(less);
|
|
ival = imax(more); putwrd(ival); newlin();
|
|
cpival(more);
|
|
}
|
|
|
|
/* Test cvibcd() and upbcdi() */
|
|
void intbcd(ival) {
|
|
newlin(); puts("CVIBCD($"); putwrd(ival); puts(")=$");
|
|
cvibcd(ival); puthex(temp2); puthex(temp1); puthex(temp0);
|
|
}
|
|
|
|
/* Test itoa() and atoi() */
|
|
void itaati(ivar) {
|
|
newlin();
|
|
puts("ITOA($"); putwrd(ivar); puts(")=\"");
|
|
setdst(s); size = itoa(ivar); puts(s); putln("\"");
|
|
puts("ATOI(\""); puts(s); puts("\")=$");
|
|
ival = atoi(s); putwrd(ival); newlin();
|
|
cpival(ivar);
|
|
}
|
|
|
|
/* Test iadd() and isub() */
|
|
//**needs iaddc()
|
|
void addsub(ivar) {
|
|
newlin();
|
|
putint(ival); putc('+'); putint(ivar); putc('=');
|
|
setsrc(ival); ctot, itot = iadd(ivar);
|
|
putint(itot); puts(" carry=$"); puthex(ctot); newlin();
|
|
putint(itot); putc('-'); putint(ivar); putc('=');
|
|
setsrc(itot); ires = isub(ivar);
|
|
putint(itot); puts(" carry=$"); puthex(ctot); newlin();
|
|
cpival(ires);
|
|
}
|
|
|
|
/* Test imult() and idiv() */
|
|
void mltdiv(ivar) {
|
|
newlin();
|
|
putint(ival); putc('*'); putint(ivar); putc('=');
|
|
setdst(ival); cval,itot = imult(ivar); putint(itot);
|
|
if (cval) puts(" OVERFLOW!"); newlin();
|
|
putint(itot); putc('/'); putint(ivar); putc('=');
|
|
setdst(itot); ires = idiv(ivar); putint(ires); newlin();
|
|
cpival(ires);
|
|
ival>>; setsrc(ival); cval,itot = iadd(itot);
|
|
if (cval) return; //Number to Large to Modulo
|
|
putint(itot); putc('%'); putint(ivar); putc('=');
|
|
setdst(itot); ires = imod(ivar); putint(ires); newlin();
|
|
cpival(ires);
|
|
}
|
|
|
|
void prshft() {
|
|
puts(); putc('('); putdec(cval); puts(",%");
|
|
cnum = >ivar; putbin(cnum); putspc();
|
|
cnum = <ivar; putbin(cnum); puts(")=");
|
|
}
|
|
|
|
void prctot() {putc('%'); putbin(ctot); putspc();}
|
|
|
|
void pritot() {
|
|
putc('%'); cnum = >itot; putbin(cnum);
|
|
putspc(); cnum = <itot; putbin(cnum); putspc();
|
|
}
|
|
|
|
/* Test ishftl() and ishiftr() */
|
|
void shftlr(cval, ivar) {
|
|
newlin();
|
|
ival = ivar; for (cnum = 0; cnum < cval; cnum++) ival<<; prshft("ISHFTL");
|
|
ctot, itot = ishftl(cval, ivar); prctot(); pritot(); newlin();
|
|
cpival(itot);
|
|
ival = ivar; for (cnum = 0; cnum < cval; cnum++) ival>>; prshft("ISHFTR");
|
|
ctot, itot = ishftr(cval, ivar); pritot(); prctot(); newlin();
|
|
cpival(itot);
|
|
}
|
|
|
|
|
|
main:
|
|
|
|
less = $009A; more = $00DE; minmax();
|
|
less = $789A; more = $78DE; minmax();
|
|
less = $7800; more = $BC00; minmax();
|
|
less = $789A; more = $BCDE; minmax();
|
|
less = $F18F; more = $F18F; minmax();
|
|
anykey();
|
|
|
|
itaati(&0);
|
|
itaati(&234);
|
|
itaati(&256);
|
|
itaati(&456);
|
|
itaati(&23456);
|
|
itaati(&$FFFF);
|
|
anykey();
|
|
|
|
ival = &23; addsub(&34);
|
|
ival = &1234; addsub(&5678);
|
|
ival = &23456; addsub(&34567);
|
|
ival = &$7700; addsub(&$6600);
|
|
ival = &$7FFF; addsub(&$8000);
|
|
ival = &$FDEC; addsub(&$CDEF);
|
|
anykey();
|
|
|
|
ival = &23; mltdiv(&34);
|
|
ival = &123; mltdiv(&234);
|
|
ival = &255; mltdiv(&257);
|
|
anykey();
|
|
|
|
shftlr(0,&$AA55);
|
|
shftlr(1,&$A55A);
|
|
shftlr(2,&$F00F);
|
|
shftlr(3,&$0FF0);
|
|
shftlr(4,&$AA55);
|
|
shftlr(7,&$A55A);
|
|
anykey();
|
|
shftlr(8,&$AA55);
|
|
shftlr(9,&$A55A);
|
|
shftlr(11,&$0FF0);
|
|
shftlr(12,&$AA55);
|
|
shftlr(15,&$A55A);
|
|
shftlr(16,&$F00F);
|
|
|
|
|
|
goto exit;
|