]> git.sur5r.net Git - cc65/blob - testcode/lib/em-test.c
Fixed _textcolor definition.
[cc65] / testcode / lib / em-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <conio.h>
6 #include <em.h>
7
8 #define FORCE_ERROR1 0
9 #define FORCE_ERROR2 0
10
11 #define PAGE_SIZE       128                     /* Size in words */
12 #define BUF_SIZE        (PAGE_SIZE + PAGE_SIZE/2)
13 static unsigned buf[BUF_SIZE];
14
15
16
17 static void cleanup (void)
18 /* Remove the driver on exit */
19 {
20     em_unload ();
21 }
22
23
24
25 static void fill (register unsigned* page, register unsigned char count, register unsigned num)
26 {
27     register unsigned char i;
28     for (i = 0; i < count; ++i, ++page) {
29         *page = num;
30     }
31 }
32
33
34
35 static void cmp (unsigned page, register const unsigned* buf,
36                  register unsigned char count, register unsigned num)
37 {
38     register unsigned char i;
39     for (i = 0; i < count; ++i, ++buf) {
40         if (*buf != num) {
41             cprintf ("\r\nData mismatch in page $%04X at $%04X\r\n"
42                      "Data is $%04X (should be $%04X)\r\n",
43                      page, buf, *buf, num);
44 #ifdef __ATARI__
45             cgetc ();
46 #endif
47             exit (EXIT_FAILURE);
48         }
49     }
50 }
51
52 typedef struct emd_test_s {
53     char key;
54     char *displayname;
55     char *drivername;
56 } emd_test_t;
57
58 static emd_test_t drivers[] = {
59
60 #if defined(__APPLE2__)
61     { '0', "Apple II auxiliary memory", "a2.auxmem.emd" },
62 #endif
63
64 #if defined(__APPLE2ENH__)
65     { '0', "Apple II auxiliary memory", "a2e.auxmem.emd" },
66 #endif
67
68 #if defined(__ATARI__)
69     { '0', "Atari 130XE memory", "atr130.emd" },
70 #endif
71
72 #if defined(__ATARIXL__)
73     { '0', "Atari 130XE memory", "atrx130.emd" },
74 #endif
75
76 #if defined(__C16__)
77     { '0', "C16 RAM above $8000", "c16-ram.emd" },
78 #endif
79
80 #if defined(__C64__)
81     { '0', "C64 RAM above $D000", "c64-ram.emd" },
82     { '1', "C64 256K", "c64-c256k.emd" },
83     { '2', "Double Quick Brown Box", "c64-dqbb.emd" },
84     { '3', "GEORAM", "c64-georam.emd" },
85     { '4', "Isepic", "c64-isepic.emd" },
86     { '5', "RamCart", "c64-ramcart.emd" },
87     { '6', "REU", "c64-reu.emd" },
88     { '7', "C128 VDC (in C64 mode)", "c64-vdc.emd" },
89     { '8', "C64DTV himem", "dtv-himem.emd" },
90     { '9', "65816 extra banks", "c64-65816.emd" },
91 #endif
92
93 #if defined(__C128__)
94     { '0', "C128 RAM in bank 1", "c128-ram.emd" },
95     { '1', "C128 RAM in banks 1, 2 & 3", "c128-ram2.emd" },
96     { '2', "GEORAM", "c128-georam.emd" },
97     { '3', "RamCart", "c128-ramcart.emd" },
98     { '4', "REU", "c128-reu.emd" },
99     { '5', "VDC", "c128-vdc.emd" },
100     { '6', "Internal Function RAM", "c128-ifnram.emd" },
101     { '7', "External Function RAM", "c128-efnram.emd" },
102 #endif
103
104 #if defined(__CBM510__)
105     { '0', "CBM5x0 RAM in bank 2", "cbm510-ram.emd" },
106 #endif
107
108 #if defined(__CBM610__)
109     { '0', "CBM6x0/7x0 RAM in bank 2", "cbm610-ram.emd" },
110 #endif
111
112     { 0, NULL, NULL }
113 };
114
115 int main (void)
116 {
117     unsigned char Res;
118     unsigned I;
119     unsigned Offs;
120     unsigned PageCount;
121     unsigned char X, Y;
122     struct em_copy c;
123     unsigned index;
124     signed char valid_key = -1;
125     char key;
126
127     clrscr ();
128     cputs ("Which RAM exp to test?\r\n\r\n");
129     for (index = 0; drivers[index].key; ++index) {
130         cprintf("%c: %s\r\n", drivers[index].key, drivers[index].displayname);
131     }
132
133     while (valid_key < 0) {
134         key = cgetc();
135         for (index = 0; drivers[index].key && valid_key < 0; ++index) {
136             if (key == drivers[index].key) {
137                 valid_key = index;
138             }
139         }
140     }
141
142     clrscr ();
143     Res = em_load_driver (drivers[valid_key].drivername);
144     if (Res != EM_ERR_OK) {
145         cprintf ("Error in em_load_driver: %u\r\n", Res);
146         cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
147 #ifdef __ATARI__
148         cgetc ();
149 #endif
150         exit (EXIT_FAILURE);
151     }
152     atexit (cleanup);
153
154     /* Get the number of available pages */
155     PageCount = em_pagecount ();
156     cprintf ("Loaded ok, page count = $%04X\r\n", PageCount);
157
158     /* TEST #1: em_map/em_use/em_commit */
159     cputs ("Testing em_map/em_use/em_commit");
160
161     /* Fill all pages */
162     cputs ("\r\n  Filling   ");
163     X = wherex ();
164     Y = wherey ();
165     for (I = 0; I < PageCount; ++I) {
166
167         /* Fill the buffer and copy it to em */
168         fill (em_use (I), PAGE_SIZE, I);
169         em_commit ();
170
171         /* Keep the user happy */
172         gotoxy (X, Y);
173         cputhex16 (I);
174     }
175
176 #if FORCE_ERROR1
177     ((unsigned*) em_map (0x03))[0x73] = 0xFFFF;
178     em_commit ();
179 #endif
180
181     /* Check all pages */
182     cputs ("\r\n  Comparing ");
183     X = wherex ();
184     Y = wherey ();
185     for (I = 0; I < PageCount; ++I) {
186
187         /* Get the buffer and compare it */
188         cmp (I, em_map (I), PAGE_SIZE, I);
189
190         /* Keep the user happy */
191         gotoxy (X, Y);
192         cputhex16 (I);
193     }
194
195     /* TEST #2: em_copyfrom/em_copyto. */
196     cputs ("\r\nTesting em_copyfrom/em_copyto");
197
198     /* We're filling now 384 bytes per run to test the copy routines with
199     ** other sizes.
200     */
201     PageCount = (PageCount * 2) / 3;
202
203     /* Setup the copy structure */
204     c.buf   = buf;
205     c.count = sizeof (buf);
206
207     /* Fill again all pages */
208     cputs ("\r\n  Filling   ");
209     X = wherex ();
210     Y = wherey ();
211     c.page = 0;
212     c.offs = 0;
213     for (I = 0; I < PageCount; ++I) {
214
215         /* Fill the buffer and copy it to em */
216         fill (buf, BUF_SIZE, I ^ 0xFFFF);
217         em_copyto (&c);
218
219         /* Adjust the em offset */
220         Offs = c.offs + sizeof (buf);
221         c.offs = (unsigned char) Offs;
222         c.page += (Offs >> 8);
223
224         /* Keep the user happy */
225         gotoxy (X, Y);
226         cputhex16 (I);
227     }
228
229 #if FORCE_ERROR2
230     c.page = 0x03;
231     em_copyfrom (&c);
232     buf[0x73] = 0xFFFF;
233     em_copyto (&c);
234 #endif
235
236     /* Check all pages */
237     cputs ("\r\n  Comparing ");
238     X = wherex ();
239     Y = wherey ();
240     c.page = 0;
241     c.offs = 0;
242     for (I = 0; I < PageCount; ++I) {
243
244         /* Get the buffer and compare it */
245         em_copyfrom (&c);
246         cmp (I, buf, BUF_SIZE, I ^ 0xFFFF);
247
248         /* Adjust the em offset */
249         Offs = c.offs + sizeof (buf);
250         c.offs = (unsigned char) Offs;
251         c.page += (Offs >> 8);
252
253         /* Keep the user happy */
254         gotoxy (X, Y);
255         cputhex16 (I);
256     }
257
258     /* Success */
259     cprintf ("\r\nPassed!\r\n");
260
261 #ifdef __ATARI__
262     cgetc ();
263 #endif
264
265     return 0;
266
267 }