125 lines
3.3 KiB
C
125 lines
3.3 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Authored acceptance fixture: ordinary guest graphics and keyboard input.
|
|
#include <coco.h>
|
|
#include <vcc/gime.h>
|
|
|
|
volatile unsigned fixture_inputs;
|
|
volatile unsigned char fixture_last_key;
|
|
|
|
// A real exported assembly entry, without a fabricated C statement location.
|
|
// CMOC appends the return instruction for this pure assembly function.
|
|
asm void fixture_entry(void)
|
|
{
|
|
asm { nop }
|
|
}
|
|
|
|
#ifdef CUSTOM_GIME
|
|
// Guest-only authored fixture: fill two 64 KiB canvases through an ordinary MMU
|
|
// window, then use the real GIME registers for a panned 320x225 viewport.
|
|
static void fill_row(unsigned char bank, unsigned address, unsigned char ink)
|
|
{
|
|
// Match the SDK's short MMU critical sections: BASIC IRQ code must never
|
|
// run with its normal window replaced. Restore mapping before restoring CC.
|
|
asm {
|
|
pshs cc,y
|
|
orcc #$50
|
|
lda >$ffa4
|
|
pshs a
|
|
lda :bank
|
|
sta >$ffa4
|
|
ldx :address
|
|
ldy #256
|
|
ldb :ink
|
|
@paint stb ,x+
|
|
leay -1,y
|
|
bne @paint
|
|
ldx :address
|
|
ldy #8
|
|
ldb #$33
|
|
@stripe stb ,x+
|
|
leay -1,y
|
|
bne @stripe
|
|
puls a
|
|
sta >$ffa4
|
|
puls cc,y
|
|
}
|
|
}
|
|
|
|
static void fill_canvas(unsigned char first_bank, unsigned char ink)
|
|
{
|
|
unsigned char bank, row;
|
|
for (bank = 0; bank < 8; ++bank)
|
|
for (row = 0; row < 32; ++row)
|
|
fill_row(first_bank + bank, 0x8000 + (unsigned)row * 256, row ? ink : 0x33);
|
|
}
|
|
|
|
static void present_canvas(unsigned char phase)
|
|
{
|
|
unsigned origin = (phase ? 0x4000 : 0) + 0x0200; // physical base +4096 bytes
|
|
*(unsigned char *)0xff98 = 0x80;
|
|
*(unsigned char *)0xff99 = 0x7e; // 320 pixels, 16 colors, 225 lines
|
|
*(unsigned char *)0xff9c = 0;
|
|
*(unsigned char *)0xff9d = origin >> 8;
|
|
*(unsigned char *)0xff9e = origin;
|
|
*(unsigned char *)0xff9f = 0xfe; // 256-byte stride; pan252 wraps within a row
|
|
}
|
|
#endif
|
|
|
|
int main(void)
|
|
{
|
|
unsigned char key;
|
|
if (!gime_open())
|
|
return 1;
|
|
gime_set_palette(0, 0);
|
|
gime_set_palette(1, 9);
|
|
gime_set_palette(2, 18);
|
|
gime_set_palette(3, 63);
|
|
#ifdef CUSTOM_GIME
|
|
{
|
|
unsigned char phase = 0;
|
|
fill_canvas(0, 0x11);
|
|
fill_canvas(16, 0x22);
|
|
present_canvas(phase);
|
|
for (;;)
|
|
{
|
|
fixture_entry();
|
|
key = inkey();
|
|
if (key == 'q' || key == 'Q') break;
|
|
if (key == 'm' || key == 'M')
|
|
{
|
|
phase ^= 1;
|
|
present_canvas(phase);
|
|
}
|
|
}
|
|
}
|
|
#else
|
|
// Opening displays page A and draws into B. Initialize B, then A;
|
|
// afterward A is visible and B is an intentionally different hidden page.
|
|
gime_clear(1);
|
|
gime_fill_rect(24, 24, 96, 48, 3);
|
|
if (!gime_present()) { gime_close(); return 2; }
|
|
gime_clear(2);
|
|
gime_fill_rect(160, 80, 96, 64, 3);
|
|
if (!gime_present()) { gime_close(); return 3; }
|
|
for (;;)
|
|
{
|
|
fixture_entry();
|
|
key = inkey();
|
|
if (!key)
|
|
continue;
|
|
fixture_last_key = key;
|
|
++fixture_inputs;
|
|
if (key == 'q' || key == 'Q')
|
|
break;
|
|
if (key == 'm' || key == 'M')
|
|
{
|
|
gime_fill_rect(8, 144, 48, 24, 3);
|
|
if (!gime_present())
|
|
break;
|
|
}
|
|
}
|
|
#endif
|
|
gime_close();
|
|
return 0;
|
|
}
|