mirror of
https://github.com/RevCurtisP/C02.git
synced 2024-11-21 10:32:08 +00:00
Updated test programs conds, echo, echohex, hello, loops
This commit is contained in:
parent
e09ebf96d6
commit
1057ec28b7
104
test/conds.c02
104
test/conds.c02
@ -3,65 +3,57 @@
|
||||
****************************************/
|
||||
|
||||
//Specify System Header using -H option
|
||||
#include <stddef.h02>
|
||||
#include <stdlib.h02>
|
||||
#include <stdio.h02>
|
||||
|
||||
char allok;
|
||||
|
||||
void passed() {putstr(" PASS");}
|
||||
void passln() {passed(); newlin();}
|
||||
void failed() {putstr(" FAIL"); allok = $00;}
|
||||
void failln() {failed(); newlin();}
|
||||
|
||||
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();}
|
||||
|
@ -11,6 +11,8 @@
|
||||
char key; //Key value
|
||||
|
||||
main:
|
||||
putstr("TYPE KEYS TO ECHO"); newlin();
|
||||
putstr("ESCAPE/STOP TO END"); newlin();
|
||||
while() {
|
||||
key = getchr();
|
||||
select (key) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*******************************************************
|
||||
* ECHOHEX - Test/Demo program for C02 Standard Header *
|
||||
* Displays ASCII Code of Typed Keys to Screen *
|
||||
* RETURN/ENTER moves to new line *
|
||||
* ESCAPE/STOP key Ends Program *
|
||||
*******************************************************/
|
||||
|
||||
@ -9,9 +10,12 @@
|
||||
char key; //Key value
|
||||
|
||||
main:
|
||||
putstr("PRESS KEYS TO DISPLAY"); newlin();
|
||||
putstr("ESCAPE/STOP TO END"); newlin();
|
||||
while() {
|
||||
key = getchr();
|
||||
prbyte(key);
|
||||
putchr(' ');
|
||||
if (key==#RTNKEY) newlin();
|
||||
if (key==#ESCKEY) goto exit;
|
||||
}
|
||||
|
@ -5,17 +5,8 @@
|
||||
|
||||
//Specify System Header using -H option
|
||||
|
||||
char key; //Key value
|
||||
|
||||
const char hello = "HELLO WORLD";
|
||||
char i;
|
||||
|
||||
main:
|
||||
i = 0;
|
||||
while (hello[i]) {
|
||||
putchr(hello[i]);
|
||||
i++;
|
||||
}
|
||||
putstr("HELLO WORLD");
|
||||
newlin();
|
||||
goto exit;
|
||||
|
||||
|
205
test/loops.c02
205
test/loops.c02
@ -6,118 +6,115 @@
|
||||
#include <stddef.h02>
|
||||
#include <stdio.h02>
|
||||
|
||||
char i, b;
|
||||
const char failed = " Test Failed!";
|
||||
char aa,ii; //Function Variables
|
||||
char b; //Comparison Variable
|
||||
char i; //Loop Counter
|
||||
|
||||
void putlin() {putstr(); newlin();}
|
||||
void failed() {putlin(" FAILED");}
|
||||
void passed() {putlin(" PASSED");}
|
||||
|
||||
main:
|
||||
putlin("TESTING LOOPS");
|
||||
|
||||
/* Test If/Goto Loop */
|
||||
puts("IF ");
|
||||
i = 0;
|
||||
ifloop:
|
||||
prbyte(i);
|
||||
putc(' ');
|
||||
i++;
|
||||
if (i < 10) goto ifloop;
|
||||
newlin();
|
||||
/* Test If/Goto Loop */
|
||||
putstr("IF ");
|
||||
i = 0;
|
||||
ifloop:
|
||||
putchr('0'+i);
|
||||
i++;
|
||||
if (i < 8) goto ifloop;
|
||||
if (i=8) passed(); else failed();
|
||||
|
||||
/* Test While Loop */
|
||||
puts("WHILE ");
|
||||
i = 0;
|
||||
while (i < 10) {
|
||||
prbyte(i);
|
||||
putc(' ');
|
||||
i++;
|
||||
}
|
||||
newlin();
|
||||
/* Test Block If */
|
||||
putstr("BLOCK ");
|
||||
b = 1;
|
||||
if (b>0) {
|
||||
prhex(b);
|
||||
putstr(" > ");
|
||||
prhex(0);
|
||||
passed();
|
||||
}
|
||||
else failed();
|
||||
|
||||
/* Test Do Loop */
|
||||
puts("DO ");
|
||||
i = 0;
|
||||
do {
|
||||
prbyte(i);
|
||||
putc(' ');
|
||||
i++;
|
||||
} while (i<10);
|
||||
newlin();
|
||||
putstr(" IF ");
|
||||
b = 0;
|
||||
if (b>0) failed();
|
||||
else {
|
||||
putchr('0'+i);
|
||||
putstr(" = ");
|
||||
prhex(0);
|
||||
passed();
|
||||
}
|
||||
|
||||
/* Test For Loop */
|
||||
puts("FOR ");
|
||||
i = 0;
|
||||
for (i=0;i<10;i++) {
|
||||
prbyte(i);
|
||||
putc(' ');
|
||||
}
|
||||
newlin();
|
||||
/* Test While Loop */
|
||||
putstr("WHILE ");
|
||||
i = 0;
|
||||
while (i < 8) {
|
||||
putchr('0'+i);
|
||||
i++;
|
||||
}
|
||||
if (i=8) passed(); else failed();
|
||||
|
||||
/* While with Break */
|
||||
puts("BREAK ");
|
||||
i = 0;
|
||||
while ($FF) {
|
||||
if (i = 10) break;
|
||||
prbyte(i);
|
||||
putc(' ');
|
||||
i++;
|
||||
}
|
||||
newlin();
|
||||
/* Test Do Loop */
|
||||
putstr("DO ");
|
||||
i = 0;
|
||||
do {
|
||||
putchr('0'+i);
|
||||
i++;
|
||||
} while (i<8);
|
||||
if (i=8) passed(); else failed();
|
||||
|
||||
/* For with Continue */
|
||||
puts("CONT ");
|
||||
for (i=0;i<10;i++) {
|
||||
if (i & 1) continue;
|
||||
prbyte(i);
|
||||
putc(' ');
|
||||
}
|
||||
newlin();
|
||||
/* Test For Loop */
|
||||
putstr("FOR ");
|
||||
i = 0;
|
||||
for (i=0;i<8;i++) {
|
||||
putchr('0'+i);
|
||||
}
|
||||
if (i=8) passed(); else failed();
|
||||
|
||||
/* 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*/
|
||||
i = 0;
|
||||
puts("DO BC ");
|
||||
do {
|
||||
i++;
|
||||
if (!i&1) continue;
|
||||
if (i>15) break;
|
||||
prbyte(i);
|
||||
putc(' ');
|
||||
} while ($FF);
|
||||
newlin();
|
||||
i = 0;
|
||||
putstr("DO BC ");
|
||||
do {
|
||||
i++;
|
||||
if (!i&1) {continue; i=$FF;}
|
||||
if (i>16) break;
|
||||
putchr('A'+i);
|
||||
} while ($FF);
|
||||
if (i=17) passed(); else failed();
|
||||
|
||||
|
||||
newlin();
|
||||
|
||||
/* Test Block If */
|
||||
putln("BLOCK IF");
|
||||
b = 1;
|
||||
if (b>0) {
|
||||
prbyte(b);
|
||||
puts(" is greater than ");
|
||||
prbyte(0);
|
||||
newlin();
|
||||
}
|
||||
else
|
||||
putln(&failed);
|
||||
b = 0;
|
||||
if (b>0) {
|
||||
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;
|
||||
/* Test If/Else, Select in For Loop */
|
||||
for(i = 0;i<4;i++) {
|
||||
select (i) {
|
||||
case 0: putstr("FOR "); b=0;
|
||||
case 1: putstr(" IF "); b=1;
|
||||
case 2: putstr(" ELSE "); b=2;
|
||||
case 3: putstr(" SELECT "); b=3;
|
||||
default: putstr(" ERROR! "); b=$FF;
|
||||
}
|
||||
putchr('0'+i);
|
||||
if (i & 1) putstr("-ODD "); else putstr("-EVEN");
|
||||
if (i=b) passed(); else failed();
|
||||
}
|
||||
|
||||
putlin("ALL TESTS COMPLETE");
|
||||
goto exit;
|
||||
|
Loading…
Reference in New Issue
Block a user