1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-29 16:51:10 +00:00
C02/test/miotest.c02

183 lines
4.7 KiB
Plaintext
Raw Normal View History

2018-07-08 02:52:04 +00:00
/****************************************
* TESTMIO - Test Memory File Functions *
****************************************/
2020-09-30 16:34:41 +00:00
//Specify System Header using -H option
2019-03-22 23:32:08 +00:00
#include <stddef.h02>
2018-07-08 02:52:04 +00:00
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
2020-09-30 16:34:41 +00:00
#include <intlib.h02>
2018-07-19 03:47:50 +00:00
#include <memory.h02>
2018-07-08 02:52:04 +00:00
#include <memio.h02>
2018-07-19 03:47:50 +00:00
#include <string.h02>
2018-07-08 02:52:04 +00:00
2019-03-22 23:32:08 +00:00
#define ZP $80 //Zero Page Location for Memory Pointer
2018-07-08 02:52:04 +00:00
char lsb, msb; //Memory Pointer Contents
char passed; //Flags
2018-07-19 03:47:50 +00:00
char f[255]; //Array to use as file
char fp,mp,op; //Memory File Pointers
char c, e, i; //Testing Variables
char s[128]; //Array for String Read/Writes
2019-03-22 23:32:08 +00:00
const char digits = "0123456789";
const char upcase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char locase = "abcdefghijklmnopqrstuvwxyz";
2018-07-19 03:47:50 +00:00
alias char outfil = $9000; //Output File
2018-07-08 02:52:04 +00:00
main:
mp = 0; //Initialize Memory Pointer
putln("Opening memory file at $8000.");
2019-03-22 23:32:08 +00:00
mp = mopen(#ZP, &$8000);
2018-07-08 02:52:04 +00:00
puts(" Memory pointer: ");
prbyte(mp);
2019-03-22 23:32:08 +00:00
if (mp == #ZP) pass(); else fail();
2018-07-08 02:52:04 +00:00
puts(" Address: ");
lsb, msb = maddr(mp);
prbyte(msb); prbyte(lsb);
passed = 1;
if (msb <> $80) passed = 0;
if (lsb <> $00) passed = 0;
if (passed) pass(); else fail();
puts(" Error? ");
e = merror(mp);
prbyte(e);
if (e) { puts(" Yes"); fail(); }
else { puts(" No "); pass(); }
newlin();
2018-07-19 03:47:50 +00:00
2018-07-08 02:52:04 +00:00
putln("Reading File using mgetc()");
2018-07-19 03:47:50 +00:00
while (!meof(mp)) {
2018-07-08 02:52:04 +00:00
c = mgetc(mp);
2018-07-19 03:47:50 +00:00
if (c < 32 ) c = 32;
putc(c);
}
newlin();
anykey();
putln("Reading File using mgets()");
2019-03-22 23:32:08 +00:00
mp = mopen(#ZP, &$8000);
2018-07-19 03:47:50 +00:00
while (!meof(mp)) {
lsb, msb = maddr(mp);
prbyte(msb); prbyte(lsb);
i, c = mgets(mp, &s);
printf(i, " %r");
printf(c, " %x: ");
2018-07-19 03:47:50 +00:00
puts(&s);
if (c <> $0A) newlin();
}
anykey();
/* Test mputc() with mopen() to array */
putln("Opening array f as memory file");
2019-03-22 23:32:08 +00:00
fp = mopen(#ZP+2, &f);
2018-07-19 03:47:50 +00:00
puts(" Memory pointer: "); prbyte(fp);
if (merror(fp)) fail(); else pass();
putln("Writing file using mgetc()");
for (i=32; i<127; i++) {putc(i); mputc(fp,i);}
newlin(); mputc(fp, 13); //Carriage Return
putln("Checking Array Contents");
passed = 1;
for (i=0; i<95; i++) {c = f[i]; putc(c); if (i+32<>c) passed = 0;}
newlin(); //if (f[95]<>13) passed = 0;
if (passed) pass(); else fail();
anykey();
/* Test mputs(), mputln(), and mclose() with mopen() to alias */
putln("Filling memory area outfil");
for (i = 0; i<255; i++) outfil[i] = '@';
putln("Opening location outfil as memory file");
2019-03-22 23:32:08 +00:00
op = mopen(#ZP+4, &outfil);
2018-07-19 03:47:50 +00:00
puts(" Memory pointer: "); prbyte(op);
if (merror(op)) fail(); else pass();
puts("Writing upcase to file using mputln():");
mputln(op, &upcase);
if (merror(op)) fail(); else pass();
puts("Writing locase to file using mputln():");
mputln(op, &locase);
if (merror(op)) fail(); else pass();
puts("Writing digits to file using mputs():");
mputs(op, &digits);
if (merror(op)) fail(); else pass();
puts("Flushing file:");
if (mflush(op)) fail(); else pass();
anykey();
/* Test mgetc(), and mgets() with mopen() to alias */
putln("Opening location outfil as memory file");
2019-03-22 23:32:08 +00:00
op = mopen(#ZP+4, &outfil);
2018-07-19 03:47:50 +00:00
puts(" Memory pointer: "); prbyte(op);
if (merror(op)) fail(); else pass();
puts("Reading from file using mgetc(): ");
i=0; while () {c=mgetc(op);s[i]=c;if (c<' ') break; i++;} s[i]=0;
puts(&s); strdst(&upcase); if (strcmp(&s)) fail(); else pass();
puts("Reading from file using mgets(): ");
i,c = mgets(op, &s); putln(&s);
printf(i, " Characters read: %d"); if (strlen(&locase)+1 == i) pass(); else fail();
printf(c, " Last char read: %x"); if (c == 13) pass(); else fail();
2018-07-19 03:47:50 +00:00
puts("Reading from file using mgets(): ");
i,c = mgets(op, &s); putln(&s);
printf(i, " Characters read: %d"); if (strlen(&digits) == i) pass(); else fail();
printf(c, " Last char read: %x"); if (c) fail(); else pass();
2018-07-19 03:47:50 +00:00
puts("Checking for End of File: ");
e = meof(op); putdec(e); if (e) pass(); else fail();
puts("Closing File:");
mclose(op); if (merror(op)) pass(); else fail();
anykey();
putln("Clearing memory at $9000.");
memdst(&$9000);
memset(0, 255);
mp = 0; //Initialize Memory Pointer
putln("Opening memory file at $9000.");
2019-03-22 23:32:08 +00:00
mp = mopen(#ZP, &$9000);
2018-07-19 03:47:50 +00:00
putln("Writing to memory file using mwrite()");
msrc(&digits); mwrite(mp, 10);
msrc(&upcase); mwrite(mp, 26);
msrc(&locase); mwrite(mp, 26);
newlin();
putln("Opening memory file at $9000.");
2019-03-22 23:32:08 +00:00
mp = mopen(#ZP, &$9000);
2018-07-19 03:47:50 +00:00
putln("Reading from memory file using mread()");
2019-03-22 23:32:08 +00:00
iarray(&s); mread(mp, 10); puts(&s); putc(':'); if (strcmp(&digits)) fail(); else pass();
iarray(&s); mread(mp, 26); puts(&s); putc(':'); if (strcmp(&upcase)) fail(); else pass();
iarray(&s); mread(mp, 26); puts(&s); putc(':'); if (strcmp(&locase)) fail(); else pass();
2020-09-30 16:34:41 +00:00
mread(mp,0); putdec(s[0]); putc(':'); if (s[0]) fail(); else pass();
2018-07-08 02:52:04 +00:00
goto exit;
void pass() { putln(" Passed"); }
void fail() { putln(" Failed"); }
2018-07-19 03:47:50 +00:00
void iarray() { memdst(); memset(0, 255); }