Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,167 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// A real guest client. The host constructs the card and checks it again afterwards.
|
||||
#include <cmoc.h>
|
||||
#include <coco.h>
|
||||
#include <stdio.h>
|
||||
#include <vcc/sdc.h>
|
||||
|
||||
#define CHECK(x) do { if (!(x)) { printf("FAIL LINE %u\n", (unsigned)__LINE__); return 1; } } while (0)
|
||||
|
||||
static SdcEntry entry;
|
||||
static char overlong[256];
|
||||
|
||||
static asm byte irqMask(void)
|
||||
{
|
||||
asm {
|
||||
tfr cc,b
|
||||
andb #$50
|
||||
}
|
||||
}
|
||||
|
||||
// Called only between guest operations; preserve every CC bit except IRQ/FIRQ.
|
||||
static asm void setIrqMask(byte mask)
|
||||
{
|
||||
asm {
|
||||
tfr cc,b
|
||||
andb #$af
|
||||
orb 3,s
|
||||
tfr b,cc
|
||||
}
|
||||
}
|
||||
|
||||
static int checkMasks(void)
|
||||
{
|
||||
static const byte masks[] = { 0, 0x10, 0x40, 0x50 };
|
||||
byte original = irqMask();
|
||||
byte i, entered, returned, status;
|
||||
for (i = 0; i < sizeof(masks); ++i) {
|
||||
setIrqMask(masks[i]);
|
||||
entered = irqMask();
|
||||
status = sdc_probe();
|
||||
returned = irqMask();
|
||||
setIrqMask(original);
|
||||
CHECK(entered == masks[i] && returned == entered && status == SDC_OK);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int listing(void)
|
||||
{
|
||||
unsigned char i, result, index, seen[17], parent = 0, child = 0;
|
||||
memset(seen, 0, sizeof(seen));
|
||||
CHECK(sdc_list_begin("/GROUP/*") == SDC_OK);
|
||||
while ((result = sdc_list_next(&entry)) == SDC_OK) {
|
||||
if (!strcmp(entry.name, "..")) {
|
||||
CHECK(entry.attributes & SDC_DIRECTORY);
|
||||
++parent;
|
||||
} else if (!strcmp(entry.name, "CHILD")) {
|
||||
CHECK(entry.attributes & SDC_DIRECTORY);
|
||||
++child;
|
||||
} else {
|
||||
CHECK(strlen(entry.name) == 7 && entry.name[0] == 'A');
|
||||
index = (entry.name[1] - '0') * 10 + entry.name[2] - '0';
|
||||
CHECK(index < 17 && !seen[index] && !(entry.attributes & SDC_DIRECTORY));
|
||||
seen[index] = 1;
|
||||
CHECK(entry.size == (unsigned long)(index + 1));
|
||||
CHECK(!!(entry.attributes & SDC_READ_ONLY) == (index == 0));
|
||||
}
|
||||
}
|
||||
CHECK(result == SDC_END && parent == 1 && child == 1);
|
||||
for (i = 0; i < 17; ++i) CHECK(seen[i]);
|
||||
CHECK(sdc_list_next(&entry) == SDC_END);
|
||||
|
||||
CHECK(sdc_list_begin("/group/*.txt") == SDC_OK);
|
||||
for (i = 0; i < 16; ++i) CHECK(sdc_list_next(&entry) == SDC_OK);
|
||||
CHECK(sdc_list_next(&entry) == SDC_END);
|
||||
CHECK(sdc_list_begin("/GROUP/*.XYZ") == SDC_OK);
|
||||
CHECK(sdc_list_next(&entry) == SDC_END);
|
||||
|
||||
CHECK(sdc_list_begin(NULL) == SDC_OK);
|
||||
CHECK(sdc_list_next(&entry) == SDC_OK);
|
||||
// Starting a second enumeration replaces the first.
|
||||
CHECK(sdc_list_begin("/SURVEY/MARS.DSK") == SDC_OK);
|
||||
CHECK(sdc_list_next(&entry) == SDC_OK && !strcmp(entry.name, "MARS.DSK"));
|
||||
CHECK(entry.size == 161280UL && sdc_list_next(&entry) == SDC_END);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int readByte(const char *path, int expected)
|
||||
{
|
||||
FILE *f = fopen(path, "rb");
|
||||
CHECK(f && fgetc(f) == expected && fgetc(f) == EOF && feof(f));
|
||||
CHECK(fclose(f) == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mounts(byte protectedCard)
|
||||
{
|
||||
byte *driveOneFAT = (byte *)(0x0800 + 74);
|
||||
CHECK(sdc_mounted(0, &entry) == SDC_OK && !strcmp(entry.name, "BOOT.DSK"));
|
||||
CHECK(entry.size == 161280UL && !!(entry.attributes & SDC_READ_ONLY) == protectedCard);
|
||||
CHECK(sdc_mounted(1, &entry) == SDC_NOT_FOUND);
|
||||
CHECK(sdc_mount(1, "/survey/earth.dsk") == SDC_OK);
|
||||
CHECK(sdc_mounted(1, &entry) == SDC_OK && !strcmp(entry.name, "EARTH.DSK"));
|
||||
CHECK(!readByte("ROVER.DAT:1", 'E'));
|
||||
|
||||
CHECK(sdc_mount(1, "/SURVEY/UNKNOWN.DSK") == SDC_NOT_FOUND);
|
||||
CHECK(sdc_mount(1, "/BAD.DSK") == SDC_INVALID);
|
||||
CHECK(sdc_mount(1, "/BUNDLE.DSK") == SDC_INVALID);
|
||||
CHECK(sdc_mount(1, "/SURVEY/MAR*.DSK") == SDC_INVALID);
|
||||
CHECK(sdc_mount(1, "/SURVEY/MAR") == SDC_INVALID);
|
||||
CHECK(sdc_mount(1, "/BOOT.DSK") == SDC_IN_USE);
|
||||
CHECK(sdc_mount(1, "") == SDC_INVALID);
|
||||
CHECK(sdc_mount(1, NULL) == SDC_INVALID);
|
||||
CHECK(sdc_mount(2, "/SURVEY/MARS.DSK") == SDC_INVALID);
|
||||
CHECK(sdc_mounted(2, &entry) == SDC_INVALID);
|
||||
memset(overlong, 'A', sizeof(overlong) - 1);
|
||||
CHECK(sdc_mount(1, overlong) == SDC_INVALID);
|
||||
CHECK(sdc_mounted(1, &entry) == SDC_OK && !strcmp(entry.name, "EARTH.DSK"));
|
||||
CHECK(!readByte("ROVER.DAT:1", 'E'));
|
||||
|
||||
// Independently exercise both DOS cache guards in guest memory.
|
||||
CHECK(!driveOneFAT[0] && !driveOneFAT[1]);
|
||||
driveOneFAT[0] = 1;
|
||||
CHECK(sdc_mount(1, "/SURVEY/MARS.DSK") == SDC_IN_USE);
|
||||
driveOneFAT[0] = 0;
|
||||
driveOneFAT[1] = 1;
|
||||
CHECK(sdc_mount(1, "/SURVEY/MARS.DSK") == SDC_IN_USE);
|
||||
driveOneFAT[1] = 0;
|
||||
CHECK(!readByte("ROVER.DAT:1", 'E'));
|
||||
|
||||
CHECK(sdc_mount(1, "/SURVEY/MARS.DSK") == SDC_OK);
|
||||
CHECK(sdc_mounted(1, &entry) == SDC_OK && !strcmp(entry.name, "MARS.DSK"));
|
||||
CHECK(!readByte("ROVER.DAT:1", 'M') && !readByte("BOOTMAP.DAT:0", 'B'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unavailable(void)
|
||||
{
|
||||
CHECK(sdc_probe() == SDC_UNAVAILABLE);
|
||||
CHECK(sdc_list_begin("*") == SDC_UNAVAILABLE);
|
||||
CHECK(sdc_mounted(0, &entry) == SDC_UNAVAILABLE);
|
||||
CHECK(sdc_mount(0, "/SURVEY/MARS.DSK") == SDC_UNAVAILABLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char choice;
|
||||
cls(1);
|
||||
printf("SELECT SDC TEST\n");
|
||||
choice = waitkey(0);
|
||||
if (choice == 'T') {
|
||||
CHECK(sdc_probe() == SDC_TIMEOUT); // Waiting for idle.
|
||||
CHECK(sdc_mounted(0, &entry) == SDC_TIMEOUT); // Waiting for data.
|
||||
CHECK(sdc_probe() == SDC_OK);
|
||||
CHECK(!readByte("BOOTMAP.DAT:0", 'B'));
|
||||
} else if (choice == 'S' || choice == 'W') {
|
||||
CHECK(sdc_probe() == SDC_OK);
|
||||
CHECK(!readByte("BOOTMAP.DAT:0", 'B')); // DOS uses the next sector exactly as requested.
|
||||
if (checkMasks() || listing() || mounts(choice == 'S')) return 1;
|
||||
} else {
|
||||
CHECK(choice == 'F');
|
||||
if (unavailable()) return 1;
|
||||
}
|
||||
printf("SDC CHECKS PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user