]> git.sur5r.net Git - cc65/blob - testcode/lib/em-test.c
Added extended memory test program
[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
9 #define FORCE_ERROR1 0
10 #define FORCE_ERROR2 0
11
12
13 static unsigned buf[128];
14
15
16
17 static void fill (register unsigned* page, register unsigned num)
18 {
19     unsigned char i;
20     for (i = 0; i < 128; ++i, ++page) {
21         *page = num;
22     }
23 }
24
25
26
27 static void cmp (unsigned page, register const unsigned* buf, register unsigned num)
28 {
29     unsigned char i;
30     for (i = 0; i < 128; ++i, ++buf) {
31         if (*buf != num) {
32             cprintf ("\r\nData mismatch in page $%04X at $%04X\r\n"
33                      "Data is $%04X (should be $%04X)\r\n",
34                      page, buf, *buf, num);
35             exit (EXIT_FAILURE);
36         }
37     }
38 }
39
40
41
42 int main (void)
43 {
44     unsigned char Res;
45     unsigned I;
46     unsigned PageCount;
47     unsigned char X, Y;
48     struct em_copy c;
49
50     clrscr ();
51     Res = em_load_driver ("c128-reu.emd");
52     if (Res != EM_ERR_OK) {
53         cprintf ("Error in em_load_driver: %u\r\n", Res);
54         cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
55         exit (EXIT_FAILURE);
56     }
57
58     /* Get the number of available pages */
59     PageCount = em_pagecount ();
60     cprintf ("Loaded ok, page count = $%04X\r\n", PageCount);
61
62     /* Fill all pages */
63     cputs ("Filling   ");
64     X = wherex ();
65     Y = wherey ();
66     for (I = 0; I < PageCount; ++I) {
67         fill (em_use (I), I);
68         em_commit ();
69         gotoxy (X, Y);
70         cputhex16 (I);
71     }
72
73 #if FORCE_ERROR1
74     ((unsigned*) em_map (0x03))[0x73] = 0xFFFF;
75     em_commit ();
76 #endif
77
78     /* Check all pages */
79     cputs ("\r\nComparing ");
80     X = wherex ();
81     Y = wherey ();
82     for (I = 0; I < PageCount; ++I) {
83         cmp (I, em_map (I), I);
84         gotoxy (X, Y);
85         cputhex16 (I);
86     }
87
88     /* Setup the copy structure */
89     c.offs  = 0;
90     c.buf   = buf;
91     c.count = sizeof (buf);
92
93     /* Fill again all pages */
94     cputs ("\r\nFilling   ");
95     X = wherex ();
96     Y = wherey ();
97     for (I = 0; I < PageCount; ++I) {
98         fill (buf, I ^ 0xFFFF);
99         c.page  = I;
100         em_copyto (&c);
101         gotoxy (X, Y);
102         cputhex16 (I);
103     }
104
105 #if FORCE_ERROR2
106     c.page = 0x03;
107     em_copyfrom (&c);
108     buf[0x73] = 0xFFFF;
109     em_copyto (&c);
110 #endif
111
112     /* Check all pages */
113     cputs ("\r\nComparing ");
114     X = wherex ();
115     Y = wherey ();
116     for (I = 0; I < PageCount; ++I) {
117         c.page = I;
118         em_copyfrom (&c);
119         cmp (I, buf, I ^ 0xFFFF);
120         gotoxy (X, Y);
121         cputhex16 (I);
122     }
123     cprintf ("\r\n");
124
125     cprintf ("Passed!\r\n");
126
127     return 0;
128
129 }