]> git.sur5r.net Git - cc65/blob - testcode/lib/em-test.c
Started on making c128 function ram emd's.
[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", "a2e.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", "atr130.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 #endif
91
92 #if defined(__C128__)
93     { '0', "C128 RAM in bank 1", "c128-ram.emd" },
94     { '1', "C128 RAM in banks 1, 2 & 3", "c128-ram2.emd" },
95     { '2', "GEORAM", "c128-georam.emd" },
96     { '3', "RamCart", "c128-ramcart.emd" },
97     { '4', "REU", "c128-reu.emd" },
98     { '5', "VDC", "c128-vdc.emd" },
99     { '6', "Internal Function RAM", "c128-ifnram.emd" },
100 #endif
101
102 #if defined(__CBM510__)
103     { '0', "CBM5x0 RAM in bank 2", "cbm510-ram.emd" },
104 #endif
105
106 #if defined(__CBM610__)
107     { '0', "CBM6x0/7x0 RAM in bank 2", "cbm610-ram.emd" },
108 #endif
109
110     { 0, NULL, NULL }
111 };
112
113 int main (void)
114 {
115     unsigned char Res;
116     unsigned I;
117     unsigned Offs;
118     unsigned PageCount;
119     unsigned char X, Y;
120     struct em_copy c;
121     unsigned index;
122     signed char valid_key = -1;
123     char key;
124
125     clrscr ();
126     cputs ("Which RAM exp to test?\r\n\r\n");
127     for (index = 0; drivers[index].key; ++index) {
128         cprintf("%c: %s\r\n", drivers[index].key, drivers[index].displayname);
129     }
130
131     while (valid_key < 0) {
132         key = cgetc();
133         for (index = 0; drivers[index].key && valid_key < 0; ++index) {
134             if (key == drivers[index].key) {
135                 valid_key = index;
136             }
137         }
138     }
139
140     clrscr ();
141     Res = em_load_driver (drivers[valid_key].drivername);
142     if (Res != EM_ERR_OK) {
143         cprintf ("Error in em_load_driver: %u\r\n", Res);
144         cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
145 #ifdef __ATARI__
146         cgetc ();
147 #endif
148         exit (EXIT_FAILURE);
149     }
150     atexit (cleanup);
151
152     /* Get the number of available pages */
153     PageCount = em_pagecount ();
154     cprintf ("Loaded ok, page count = $%04X\r\n", PageCount);
155
156     /* TEST #1: em_map/em_use/em_commit */
157     cputs ("Testing em_map/em_use/em_commit");
158
159     /* Fill all pages */
160     cputs ("\r\n  Filling   ");
161     X = wherex ();
162     Y = wherey ();
163     for (I = 0; I < PageCount; ++I) {
164
165         /* Fill the buffer and copy it to em */
166         fill (em_use (I), PAGE_SIZE, I);
167         em_commit ();
168
169         /* Keep the user happy */
170         gotoxy (X, Y);
171         cputhex16 (I);
172     }
173
174 #if FORCE_ERROR1
175     ((unsigned*) em_map (0x03))[0x73] = 0xFFFF;
176     em_commit ();
177 #endif
178
179     /* Check all pages */
180     cputs ("\r\n  Comparing ");
181     X = wherex ();
182     Y = wherey ();
183     for (I = 0; I < PageCount; ++I) {
184
185         /* Get the buffer and compare it */
186         cmp (I, em_map (I), PAGE_SIZE, I);
187
188         /* Keep the user happy */
189         gotoxy (X, Y);
190         cputhex16 (I);
191     }
192
193     /* TEST #2: em_copyfrom/em_copyto. */
194     cputs ("\r\nTesting em_copyfrom/em_copyto");
195
196     /* We're filling now 384 bytes per run to test the copy routines with
197     ** other sizes.
198     */
199     PageCount = (PageCount * 2) / 3;
200
201     /* Setup the copy structure */
202     c.buf   = buf;
203     c.count = sizeof (buf);
204
205     /* Fill again all pages */
206     cputs ("\r\n  Filling   ");
207     X = wherex ();
208     Y = wherey ();
209     c.page = 0;
210     c.offs = 0;
211     for (I = 0; I < PageCount; ++I) {
212
213         /* Fill the buffer and copy it to em */
214         fill (buf, BUF_SIZE, I ^ 0xFFFF);
215         em_copyto (&c);
216
217         /* Adjust the em offset */
218         Offs = c.offs + sizeof (buf);
219         c.offs = (unsigned char) Offs;
220         c.page += (Offs >> 8);
221
222         /* Keep the user happy */
223         gotoxy (X, Y);
224         cputhex16 (I);
225     }
226
227 #if FORCE_ERROR2
228     c.page = 0x03;
229     em_copyfrom (&c);
230     buf[0x73] = 0xFFFF;
231     em_copyto (&c);
232 #endif
233
234     /* Check all pages */
235     cputs ("\r\n  Comparing ");
236     X = wherex ();
237     Y = wherey ();
238     c.page = 0;
239     c.offs = 0;
240     for (I = 0; I < PageCount; ++I) {
241
242         /* Get the buffer and compare it */
243         em_copyfrom (&c);
244         cmp (I, buf, BUF_SIZE, I ^ 0xFFFF);
245
246         /* Adjust the em offset */
247         Offs = c.offs + sizeof (buf);
248         c.offs = (unsigned char) Offs;
249         c.page += (Offs >> 8);
250
251         /* Keep the user happy */
252         gotoxy (X, Y);
253         cputhex16 (I);
254     }
255
256     /* Success */
257     cprintf ("\r\nPassed!\r\n");
258
259 #ifdef __ATARI__
260     cgetc ();
261 #endif
262
263     return 0;
264
265 }