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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <conio.h>
#include <em.h>
#define FORCE_ERROR1 0
#define FORCE_ERROR2 0
#define PAGE_SIZE 128 /* Size in words */
#define BUF_SIZE (PAGE_SIZE + PAGE_SIZE/2)
static unsigned buf[BUF_SIZE];
static void cleanup (void)
/* Remove the driver on exit */
{
em_unload ();
}
static void fill (register unsigned* page, register unsigned char count, register unsigned num)
{
register unsigned char i;
for (i = 0; i < count; ++i, ++page) {
*page = num;
}
}
static void cmp (unsigned page, register const unsigned* buf,
register unsigned char count, register unsigned num)
{
register unsigned char i;
for (i = 0; i < count; ++i, ++buf) {
if (*buf != num) {
cprintf ("\r\nData mismatch in page $%04X at $%04X\r\n"
"Data is $%04X (should be $%04X)\r\n",
page, buf, *buf, num);
#ifdef __ATARI__
cgetc ();
#endif
exit (EXIT_FAILURE);
}
}
}
typedef struct emd_test_s {
char key;
char *displayname;
char *drivername;
} emd_test_t;
static emd_test_t drivers[] = {
#if defined(__APPLE2__)
{ '0', "Apple II auxiliary memory", "a2.auxmem.emd" },
#endif
#if defined(__APPLE2ENH__)
{ '0', "Apple II auxiliary memory", "a2e.auxmem.emd" },
#endif
#if defined(__ATARI__)
{ '0', "Atari 130XE memory", "atr130.emd" },
#endif
#if defined(__ATARIXL__)
{ '0', "Atari 130XE memory", "atrx130.emd" },
#endif
#if defined(__C16__)
{ '0', "C16 RAM above $8000", "c16-ram.emd" },
#endif
#if defined(__C64__)
{ '0', "C64 RAM above $D000", "c64-ram.emd" },
{ '1', "C64 256K", "c64-c256k.emd" },
{ '2', "Double Quick Brown Box", "c64-dqbb.emd" },
{ '3', "GEORAM", "c64-georam.emd" },
{ '4', "Isepic", "c64-isepic.emd" },
{ '5', "RamCart", "c64-ramcart.emd" },
{ '6', "REU", "c64-reu.emd" },
{ '7', "C128 VDC (in C64 mode)", "c64-vdc.emd" },
{ '8', "C64DTV himem", "dtv-himem.emd" },
{ '9', "65816 extra banks", "c64-65816.emd" },
#endif
#if defined(__C128__)
{ '0', "C128 RAM in bank 1", "c128-ram.emd" },
{ '1', "C128 RAM in banks 1, 2 & 3", "c128-ram2.emd" },
{ '2', "GEORAM", "c128-georam.emd" },
{ '3', "RamCart", "c128-ramcart.emd" },
{ '4', "REU", "c128-reu.emd" },
{ '5', "VDC", "c128-vdc.emd" },
{ '6', "Internal Function RAM", "c128-ifnram.emd" },
{ '7', "External Function RAM", "c128-efnram.emd" },
#endif
#if defined(__CBM510__)
{ '0', "CBM5x0 RAM in bank 2", "cbm510-ram.emd" },
#endif
#if defined(__CBM610__)
{ '0', "CBM6x0/7x0 RAM in bank 2", "cbm610-ram.emd" },
#endif
{ 0, NULL, NULL }
};
int main (void)
{
unsigned char Res;
unsigned I;
unsigned Offs;
unsigned PageCount;
unsigned char X, Y;
struct em_copy c;
unsigned index;
signed char valid_key = -1;
char key;
clrscr ();
cputs ("Which RAM exp to test?\r\n\r\n");
for (index = 0; drivers[index].key; ++index) {
cprintf("%c: %s\r\n", drivers[index].key, drivers[index].displayname);
}
while (valid_key < 0) {
key = cgetc();
for (index = 0; drivers[index].key && valid_key < 0; ++index) {
if (key == drivers[index].key) {
valid_key = index;
}
}
}
clrscr ();
Res = em_load_driver (drivers[valid_key].drivername);
if (Res != EM_ERR_OK) {
cprintf ("Error in em_load_driver: %u\r\n", Res);
cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror));
#ifdef __ATARI__
cgetc ();
#endif
exit (EXIT_FAILURE);
}
atexit (cleanup);
/* Get the number of available pages */
PageCount = em_pagecount ();
cprintf ("Loaded ok, page count = $%04X\r\n", PageCount);
/* TEST #1: em_map/em_use/em_commit */
cputs ("Testing em_map/em_use/em_commit");
/* Fill all pages */
cputs ("\r\n Filling ");
X = wherex ();
Y = wherey ();
for (I = 0; I < PageCount; ++I) {
/* Fill the buffer and copy it to em */
fill (em_use (I), PAGE_SIZE, I);
em_commit ();
/* Keep the user happy */
gotoxy (X, Y);
cputhex16 (I);
}
#if FORCE_ERROR1
((unsigned*) em_map (0x03))[0x73] = 0xFFFF;
em_commit ();
#endif
/* Check all pages */
cputs ("\r\n Comparing ");
X = wherex ();
Y = wherey ();
for (I = 0; I < PageCount; ++I) {
/* Get the buffer and compare it */
cmp (I, em_map (I), PAGE_SIZE, I);
/* Keep the user happy */
gotoxy (X, Y);
cputhex16 (I);
}
/* TEST #2: em_copyfrom/em_copyto. */
cputs ("\r\nTesting em_copyfrom/em_copyto");
/* We're filling now 384 bytes per run to test the copy routines with
** other sizes.
*/
PageCount = (PageCount * 2) / 3;
/* Setup the copy structure */
c.buf = buf;
c.count = sizeof (buf);
/* Fill again all pages */
cputs ("\r\n Filling ");
X = wherex ();
Y = wherey ();
c.page = 0;
c.offs = 0;
for (I = 0; I < PageCount; ++I) {
/* Fill the buffer and copy it to em */
fill (buf, BUF_SIZE, I ^ 0xFFFF);
em_copyto (&c);
/* Adjust the em offset */
Offs = c.offs + sizeof (buf);
c.offs = (unsigned char) Offs;
c.page += (Offs >> 8);
/* Keep the user happy */
gotoxy (X, Y);
cputhex16 (I);
}
#if FORCE_ERROR2
c.page = 0x03;
em_copyfrom (&c);
buf[0x73] = 0xFFFF;
em_copyto (&c);
#endif
/* Check all pages */
cputs ("\r\n Comparing ");
X = wherex ();
Y = wherey ();
c.page = 0;
c.offs = 0;
for (I = 0; I < PageCount; ++I) {
/* Get the buffer and compare it */
em_copyfrom (&c);
cmp (I, buf, BUF_SIZE, I ^ 0xFFFF);
/* Adjust the em offset */
Offs = c.offs + sizeof (buf);
c.offs = (unsigned char) Offs;
c.page += (Offs >> 8);
/* Keep the user happy */
gotoxy (X, Y);
cputhex16 (I);
}
/* Success */
cprintf ("\r\nPassed!\r\n");
#ifdef __ATARI__
cgetc ();
#endif
return 0;
}
|