forked from RevCurtisP/C02
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmio.c02
181 lines (138 loc) · 4.61 KB
/
testmio.c02
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/****************************************
* TESTMIO - Test Memory File Functions *
****************************************/
#include <py65.h02>
#include <stddef.h02>
#include <stdlib.h02>
#include <stdio.h02>
#include <stdiox.h02>
#include <memory.h02>
#include <memio.h02>
#include <string.h02>
#define ZP $80 //Zero Page Location for Memory Pointer
char lsb, msb; //Memory Pointer Contents
char passed; //Flags
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
const char digits = "0123456789";
const char upcase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char locase = "abcdefghijklmnopqrstuvwxyz";
alias char outfil = $9000; //Output File
main:
mp = 0; //Initialize Memory Pointer
putln("Opening memory file at $8000.");
mp = mopen(#ZP, &$8000);
puts(" Memory pointer: ");
prbyte(mp);
if (mp == #ZP) pass(); else fail();
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();
putln("Reading File using mgetc()");
while (!meof(mp)) {
c = mgetc(mp);
if (c < 32 ) c = 32;
putc(c);
}
newlin();
anykey();
putln("Reading File using mgets()");
mp = mopen(#ZP, &$8000);
while (!meof(mp)) {
lsb, msb = maddr(mp);
prbyte(msb); prbyte(lsb);
i, c = mgets(mp, &s);
printf(i, " %r");
printf(c, " %h: ");
puts(&s);
if (c <> $0A) newlin();
}
anykey();
/* Test mputc() with mopen() to array */
putln("Opening array f as memory file");
fp = mopen(#ZP+2, &f);
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");
op = mopen(#ZP+4, &outfil);
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");
op = mopen(#ZP+4, &outfil);
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: %h"); if (c == 13) pass(); else fail();
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: %h"); if (c) fail(); else pass();
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.");
mp = mopen(#ZP, &$9000);
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.");
mp = mopen(#ZP, &$9000);
putln("Reading from memory file using mread()");
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();
mread(mp,0); putdec(s); putc(':'); if (s) fail(); else pass();
goto exit;
void pass() { putln(" Passed"); }
void fail() { putln(" Failed"); }
void iarray() { memdst(); memset(0, 255); }