Files
VCCPlusOSS/tests/toolchain/input/qualification.c
T

145 lines
4.3 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
#include <coco.h>
#include <vcc/input.h>
#include <vcc/ssc.h>
#include <vcc/orch90.h>
unsigned char stage, ack, report[14];
static VccInput right, left;
#define REG(a) (*(unsigned char *)(a))
static void waitForHost(unsigned char n)
{
stage = n;
asm {
lda :n
@wait cmpa :ack
bne @wait
}
}
/* Marshal the public fields explicitly so the host test is independent of
their layout, padding and signedness in a host C++ compiler. */
static void reportPort(unsigned char *p, const VccInput *s)
{
p[0] = s->x;
p[1] = s->y;
p[2] = s->dx;
p[3] = s->dy;
p[4] = s->held;
p[5] = s->pressed;
p[6] = s->released;
}
static unsigned char readBoth(unsigned char n)
{
unsigned char columns = REG(0xff02), dac = REG(0xff20);
unsigned char muxLow = REG(0xff01) & 63, muxHigh = REG(0xff03) & 63;
unsigned char speaker = REG(0xff23) & 63;
if (n == 1 || n == 7) {
input_init(&right, INPUT_RIGHT);
input_init(&left, INPUT_LEFT);
} else {
input_sample(&right);
input_sample(&left);
}
reportPort(report, &right);
reportPort(report + 7, &left);
return columns == REG(0xff02) && dac == REG(0xff20) &&
muxLow == (REG(0xff01) & 63) && muxHigh == (REG(0xff03) & 63) &&
speaker == (REG(0xff23) & 63);
}
#define COUNT 256
static struct orch90_frame leftSound[COUNT], rightSound[COUNT];
static unsigned char stereo(unsigned char clock)
{
unsigned char capturedPress;
setHighSpeed(clock);
asm {
sync
sync
}
input_init(&right, INPUT_RIGHT);
orch90_write(32, 80);
if (!orch90_play(leftSound, COUNT, clock)) return 0;
input_sample(&right); /* The host pressed fire during the left block. */
capturedPress = right.pressed;
if (!orch90_play(rightSound, COUNT, clock)) return 0;
input_sample(&right); /* The host released it during the right block. */
orch90_write(0, 0);
return capturedPress == INPUT_PRIMARY && right.released == INPUT_PRIMARY;
}
int main(void)
{
unsigned char n;
unsigned int i, start, route = ssc_route_audio();
VccInput inactive;
unsigned char oldFlags, restoredMask, preserved;
input_init(0, INPUT_RIGHT);
input_sample(0);
input_init(&inactive, 7);
input_sample(&inactive);
if (inactive.x != 31 || inactive.y != 31 || inactive.dx || inactive.dy ||
inactive.held || inactive.pressed || inactive.released) {
printf("FAIL INVALID PORT\n"); return 1;
}
for (n = 1; n <= 8; ++n) {
waitForHost(n);
/* Non-default keyboard columns and DAC baseline reveal side effects.
Preserve a consistent test setup across the two guest samples. */
asm {
tfr cc,a
sta :oldFlags
orcc #$50
}
REG(0xff02) = 0xfd;
REG(0xff20) = 0x56;
preserved = readBoth(n);
asm {
tfr cc,a
anda #$50
sta :restoredMask
lda :oldFlags
tfr a,cc
}
if (!preserved || restoredMask != 0x50) {
printf("FAIL PIA\n"); return 1;
}
}
waitForHost(9);
for (i = 0; i < COUNT; ++i) {
leftSound[i].left = (i & 8) ? 64 : 128;
rightSound[i].right = leftSound[i].left;
}
for (n = 0; n < 2; ++n) {
waitForHost(10 + n);
if (!stereo(n)) { printf("FAIL STEREO INPUT\n"); return 1; }
}
setHighSpeed(0);
input_init(&right, INPUT_RIGHT);
if (ssc_say("SURVEY PROBE READY", 16384) != SSC_OK) { printf("FAIL SPEECH\n"); return 1; }
start = getTimer();
while (ssc_status() & SSC_SPEECH_IDLE)
if ((unsigned)(getTimer() - start) > 120) return 1;
waitForHost(12);
input_sample(&right);
if (right.pressed != INPUT_PRIMARY || (ssc_status() & SSC_SPEECH_IDLE)) {
printf("FAIL SPEECH INPUT\n"); return 1;
}
start = getTimer();
while ((unsigned)(getTimer() - start) < 120) {
asm("sync"); /* Sample once per refresh while firmware speaks. */
input_sample(&right);
if (right.held != INPUT_PRIMARY || right.pressed || right.released) {
printf("FAIL SPEECH HOLD\n"); return 1;
}
}
ssc_restore_audio(route);
printf("INPUT PASSED\n");
return 0;
}