87 lines
2.8 KiB
C
87 lines
2.8 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Mailbox lets the host inspect the real guest's RAM/scanout at stable points.
|
|
#include <cmoc.h>
|
|
#include <vcc/gime.h>
|
|
|
|
unsigned char stage, advanceStage;
|
|
|
|
static void checkpoint(unsigned char n)
|
|
{
|
|
stage = n;
|
|
asm {
|
|
lda :n
|
|
@wait cmpa :advanceStage
|
|
bne @wait
|
|
}
|
|
}
|
|
|
|
// Keep this marker visible in the linker map for the instruction/VSYNC trace.
|
|
void finishedFlips(void)
|
|
{
|
|
checkpoint(4);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
unsigned char i, unexpected, savedBank;
|
|
unsigned char *inactiveBank = (unsigned char *)0xffa8;
|
|
if (gime_present()) { printf("FAIL IDLE PRESENT\n"); return 1; }
|
|
gime_close();
|
|
gime_set_palette(1, 5);
|
|
gime_clear(7);
|
|
// Refuse a screen bank owned by the inactive task, preserving its mapping.
|
|
savedBank = *inactiveBank;
|
|
*inactiveBank = 0x24;
|
|
unexpected = gime_open();
|
|
if (unexpected) gime_close();
|
|
if ((*inactiveBank & 0x3f) != 0x24) unexpected = 1;
|
|
*inactiveBank = savedBank;
|
|
if (unexpected) { printf("FAIL RESERVED BANK\n"); return 1; }
|
|
asm("orcc", "#$10");
|
|
unexpected = gime_open();
|
|
asm("andcc", "#$ef");
|
|
if (unexpected) { gime_close(); printf("FAIL IRQ OPEN\n"); return 1; }
|
|
if (!gime_open()) { printf("GRAPHICS UNAVAILABLE\n"); return 0; }
|
|
if (gime_open()) { gime_close(); printf("FAIL SECOND OPEN\n"); return 1; }
|
|
|
|
gime_set_palette(0, 0);
|
|
gime_set_palette(1, 9); // blue
|
|
gime_set_palette(2, 36); // red
|
|
gime_set_palette(3, 63); // white
|
|
gime_clear(1);
|
|
// Byte 8191 at (62,51) is adjacent to an 8 KiB bank boundary.
|
|
gime_fill_rect(63, 51, 4, 2, 2);
|
|
gime_fill_rect(318, 191, 14, 4, 2);
|
|
gime_plot(319, 191, 3);
|
|
gime_plot(320, 191, 2);
|
|
gime_plot(319, 192, 2);
|
|
gime_fill_rect(42, 18, 0, 9, 2);
|
|
gime_plot(19, 30, 16);
|
|
checkpoint(1); // first page remains visible
|
|
if (!gime_present()) return 2;
|
|
gime_clear(2); // immediately reuse the old front page
|
|
checkpoint(2);
|
|
if (!gime_present()) return 3;
|
|
checkpoint(3);
|
|
|
|
// Consecutive swaps without drawing must still be frame-paced.
|
|
for (i = 0; i < 4; ++i)
|
|
if (!gime_present()) return 4;
|
|
finishedFlips();
|
|
// A missing interrupt must time out and leave both page identities intact.
|
|
asm("orcc", "#$10");
|
|
unexpected = gime_present();
|
|
gime_plot(319, 191, 1);
|
|
checkpoint(6);
|
|
gime_close(); // Even a stopped timer must allow cleanup.
|
|
asm("andcc", "#$ef");
|
|
if (unexpected) { printf("FAIL IRQ TIMEOUT\n"); return 1; }
|
|
gime_close();
|
|
if (gime_present()) { printf("FAIL CLOSED PRESENT\n"); return 1; }
|
|
if (!gime_open()) { printf("FAIL REOPEN\n"); return 1; }
|
|
gime_close();
|
|
checkpoint(5);
|
|
printf("GRAPHICS PASSED\n");
|
|
return 0;
|
|
}
|