1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-22 01:31:33 +00:00

Updated test programs conds, echo, echohex, hello, loops

This commit is contained in:
Curtis F Kaylor 2019-11-20 01:08:09 -05:00
parent e09ebf96d6
commit 1057ec28b7
5 changed files with 156 additions and 170 deletions

View File

@ -3,65 +3,57 @@
****************************************/ ****************************************/
//Specify System Header using -H option //Specify System Header using -H option
#include <stddef.h02>
#include <stdlib.h02>
#include <stdio.h02>
char allok; char allok;
void passed() {putstr(" PASS");}
void passln() {passed(); newlin();}
void failed() {putstr(" FAIL"); allok = $00;}
void failln() {failed(); newlin();}
main: main:
allok = #TRUE; allok = $FF; //TRUE
putstr("TEST CONDITIONALS"); newlin();
putstr(" 1<>1"); if (1<>1) failed(); else passed();
putstr(" 1<>2"); if (1<>2) passln(); else failln();
putstr(" 1==1"); if (1==1) passed(); else failed();
putstr(" 1==2"); if (1==2) failln(); else passln();
putstr("1+1=2"); if (1+1 == 2) passed(); else failed();
putstr(" 2<1"); if (2<1) failln(); else passln();
putstr(" 1<1"); if (1<1) failed(); else passed();
putstr(" 1<2"); if (1<2) passln(); else failln();
putstr(" 1<=1"); if (1<=1) passed(); else failed();
putstr(" 1<=2"); if (1<=2) passln(); else failln();
putstr(" 2<=1"); if (2<=1) failed(); else passed();
putstr(" 2>1"); if (2>1) passln(); else failln();
putstr(" 1>1"); if (1>1) failed(); else passed();
putstr(" 1>2"); if (1>2) failln(); else passln();
putstr(" 1>=1"); if (1>=1) passed(); else failed();
putstr(" 1>=2"); if (1>=2) failln(); else passln();
putstr(" 2>=1"); if (2>=1) passed(); else failed();
putstr(" !0:+"); if (!0:+) failln(); else passln();
putstr("$FF:+"); if ($FF:+) failed(); else passed();
putstr(" $FF"); if ($FF) passln(); else failln();
putstr("$FF:-"); if ($FF:-) passed(); else failed();
putstr(" !$FF"); if (!$FF) failln(); else passln();
putstr("$00:+"); if ($00:+) passed(); else failed();
putstr(" $00"); if ($00) failln(); else passln();
putstr("$00:-"); if ($00:-) failed(); else passed();
putstr(" !$00"); if (!$00) passln(); else failln();
putstr(" 1!0"); if (1|0) passed(); else failed();
putstr(" !1!0"); if (!1|0) failln(); else passln();
putstr(" 1&0"); if (1&0) failed(); else passed();
putstr(" !1&0"); if (!1&0) passln(); else failln();
putstr(" 1^1"); if (1^1) failed(); else passed();
putstr(" !1^1"); if (!1^1) passln(); else failln();
if (allok) putstr("ALL TESTS PASSED"); newlin();
getchr();
goto exit;
putln("Test Conditionals");
puts(" 1<>1"); if (1<>1) failed(); else passed();
puts(" 1<>2"); if (1<>2) passln(); else failln();
puts(" 1==1"); if (1==1) passed(); else failed();
puts(" 1==2"); if (1==2) failln(); else passln();
puts("1+1=2"); if (1+1 == 2) passed(); else failed();
puts(" 2<1"); if (2<1) failln(); else passln();
puts(" 1<1"); if (1<1) failed(); else passed();
puts(" 1<2"); if (1<2) passln(); else failln();
puts(" 1<=1"); if (1<=1) passed(); else failed();
puts(" 1<=2"); if (1<=2) passln(); else failln();
puts(" 2<=1"); if (2<=1) failed(); else passed();
puts(" 2>1"); if (2>1) passln(); else failln();
puts(" 1>1"); if (1>1) failed(); else passed();
puts(" 1>2"); if (1>2) failln(); else passln();
puts(" 1>=1"); if (1>=1) passed(); else failed();
puts(" 1>=2"); if (1>=2) failln(); else passln();
puts(" 2>=1"); if (2>=1) passed(); else failed();
puts(" !0:+"); if (!0:+) failln(); else passln();
puts("$FF:+"); if ($FF:+) failed(); else passed();
puts(" $FF"); if ($FF) passln(); else failln();
puts("$FF:-"); if ($FF:-) passed(); else failed();
puts(" !$FF"); if (!$FF) failln(); else passln();
puts("$00:+"); if ($00:+) passed(); else failed();
puts(" $00"); if ($00) failln(); else passln();
puts("$00:-"); if ($00:-) failed(); else passed();
puts(" !$00"); if (!$00) passln(); else failln();
puts(" 1!0"); if (1|0) passed(); else failed();
puts(" !1!0"); if (!1|0) failln(); else passln();
puts(" 1&0"); if (1&0) failed(); else passed();
puts(" !1&0"); if (!1&0) passln(); else failln();
puts(" 1^1"); if (1^1) failed(); else passed();
puts(" !1^1"); if (!1^1) passln(); else failln();
puts(" atoc(\"0\")"); if (atoc("0")) failln(); else passln();
puts(" atoc(\"1\")"); if (atoc("1")) passln(); else failln();
puts(" atoc(\"127\"):+"); if (atoc("127"):+) passln(); else failln();
puts(" atoc(\"128\"):-"); if (atoc("128"):-) passln(); else failln();
if (allok) putln("All Tests Passed");
getc();
goto exit;
void passed() {puts(" Pass");}
void passln() {passed(); newlin();}
void failed() {puts(" Fail"); allok = #FALSE;}
void failln() {failed(); newlin();}

View File

@ -11,6 +11,8 @@
char key; //Key value char key; //Key value
main: main:
putstr("TYPE KEYS TO ECHO"); newlin();
putstr("ESCAPE/STOP TO END"); newlin();
while() { while() {
key = getchr(); key = getchr();
select (key) { select (key) {

View File

@ -1,6 +1,7 @@
/******************************************************* /*******************************************************
* ECHOHEX - Test/Demo program for C02 Standard Header * * ECHOHEX - Test/Demo program for C02 Standard Header *
* Displays ASCII Code of Typed Keys to Screen * * Displays ASCII Code of Typed Keys to Screen *
* RETURN/ENTER moves to new line *
* ESCAPE/STOP key Ends Program * * ESCAPE/STOP key Ends Program *
*******************************************************/ *******************************************************/
@ -9,9 +10,12 @@
char key; //Key value char key; //Key value
main: main:
putstr("PRESS KEYS TO DISPLAY"); newlin();
putstr("ESCAPE/STOP TO END"); newlin();
while() { while() {
key = getchr(); key = getchr();
prbyte(key); prbyte(key);
putchr(' '); putchr(' ');
if (key==#RTNKEY) newlin();
if (key==#ESCKEY) goto exit; if (key==#ESCKEY) goto exit;
} }

View File

@ -5,17 +5,8 @@
//Specify System Header using -H option //Specify System Header using -H option
char key; //Key value
const char hello = "HELLO WORLD";
char i;
main: main:
i = 0; putstr("HELLO WORLD");
while (hello[i]) {
putchr(hello[i]);
i++;
}
newlin(); newlin();
goto exit; goto exit;

View File

@ -6,118 +6,115 @@
#include <stddef.h02> #include <stddef.h02>
#include <stdio.h02> #include <stdio.h02>
char i, b; char aa,ii; //Function Variables
const char failed = " Test Failed!"; char b; //Comparison Variable
char i; //Loop Counter
void putlin() {putstr(); newlin();}
void failed() {putlin(" FAILED");}
void passed() {putlin(" PASSED");}
main: main:
putlin("TESTING LOOPS");
/* Test If/Goto Loop */ /* Test If/Goto Loop */
puts("IF "); putstr("IF ");
i = 0; i = 0;
ifloop: ifloop:
prbyte(i); putchr('0'+i);
putc(' '); i++;
i++; if (i < 8) goto ifloop;
if (i < 10) goto ifloop; if (i=8) passed(); else failed();
newlin();
/* Test While Loop */ /* Test Block If */
puts("WHILE "); putstr("BLOCK ");
i = 0; b = 1;
while (i < 10) { if (b>0) {
prbyte(i); prhex(b);
putc(' '); putstr(" > ");
i++; prhex(0);
} passed();
newlin(); }
else failed();
/* Test Do Loop */ putstr(" IF ");
puts("DO "); b = 0;
i = 0; if (b>0) failed();
do { else {
prbyte(i); putchr('0'+i);
putc(' '); putstr(" = ");
i++; prhex(0);
} while (i<10); passed();
newlin(); }
/* Test For Loop */ /* Test While Loop */
puts("FOR "); putstr("WHILE ");
i = 0; i = 0;
for (i=0;i<10;i++) { while (i < 8) {
prbyte(i); putchr('0'+i);
putc(' '); i++;
} }
newlin(); if (i=8) passed(); else failed();
/* While with Break */ /* Test Do Loop */
puts("BREAK "); putstr("DO ");
i = 0; i = 0;
while ($FF) { do {
if (i = 10) break; putchr('0'+i);
prbyte(i); i++;
putc(' '); } while (i<8);
i++; if (i=8) passed(); else failed();
}
newlin();
/* For with Continue */ /* Test For Loop */
puts("CONT "); putstr("FOR ");
for (i=0;i<10;i++) { i = 0;
if (i & 1) continue; for (i=0;i<8;i++) {
prbyte(i); putchr('0'+i);
putc(' '); }
} if (i=8) passed(); else failed();
newlin();
/* While with Break */
putstr("BREAK ");
i = 0;
while ($FF) {
if (i = 8) break;
putchr('0'+i);
i++;
}
if (i=8) passed(); else failed();
/* For with Continue */
putstr("CONT ");
for (i=0;i<16;i++) {
if (i & 1) { continue; i=$FF;}
putchr('A'+i);
}
if (i=16) passed(); else failed();
/* Test Do with Break and Continue*/ /* Test Do with Break and Continue*/
i = 0; i = 0;
puts("DO BC "); putstr("DO BC ");
do { do {
i++; i++;
if (!i&1) continue; if (!i&1) {continue; i=$FF;}
if (i>15) break; if (i>16) break;
prbyte(i); putchr('A'+i);
putc(' '); } while ($FF);
} while ($FF); if (i=17) passed(); else failed();
newlin();
/* Test If/Else, Select in For Loop */
newlin(); for(i = 0;i<4;i++) {
select (i) {
/* Test Block If */ case 0: putstr("FOR "); b=0;
putln("BLOCK IF"); case 1: putstr(" IF "); b=1;
b = 1; case 2: putstr(" ELSE "); b=2;
if (b>0) { case 3: putstr(" SELECT "); b=3;
prbyte(b); default: putstr(" ERROR! "); b=$FF;
puts(" is greater than "); }
prbyte(0); putchr('0'+i);
newlin(); if (i & 1) putstr("-ODD "); else putstr("-EVEN");
} if (i=b) passed(); else failed();
else }
putln(&failed);
b = 0; putlin("ALL TESTS COMPLETE");
if (b>0) { goto exit;
putln(&failed);
}
else {
prbyte(b);
puts(" is equal to ");
prbyte(0);
newlin();
}
newlin();
/* Test If/Else in For Loop */
putln("FOR/IF/ELSE");
for(i = 0;i<4;i++) {
prbyte(i);
if (i & 1)
putln(" is odd");
else
putln(" is even");
}
newlin();
goto exit;