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,70 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Mission Announcer. Select ssc, input and bcontrol in Project Settings. */
|
||||
#include <cmoc.h>
|
||||
#include <coco.h>
|
||||
#include <vcc/input.h>
|
||||
#include <vcc/ssc.h>
|
||||
|
||||
#define VOICE_SLOT 1
|
||||
#define ALERT_SLOT 2
|
||||
#define MESSAGE_SLOT 3
|
||||
#define POLL_LIMIT 30000
|
||||
|
||||
/* Z + "or" + an unstressed vowel: give our invented planet a voice. */
|
||||
static const unsigned char zora[] = { SSC_AL_ZZ, SSC_AL_OR, SSC_AL_AX };
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned int route, lastSample, now, landings = 0;
|
||||
unsigned char key, status;
|
||||
VccInput stick;
|
||||
|
||||
cls(1);
|
||||
printf("MISSION ANNOUNCER\n");
|
||||
route = ssc_route_audio();
|
||||
/* Store each recipe once. The two slot numbers belong to separate banks. */
|
||||
status = ssc_store_allophones(VOICE_SLOT, zora, sizeof(zora), POLL_LIMIT);
|
||||
if (status == SSC_OK)
|
||||
status = ssc_store_phrase(MESSAGE_SLOT, "WELCOME ABOARD", POLL_LIMIT);
|
||||
if (status == SSC_OK)
|
||||
status = ssc_store_enveloped_tone(ALERT_SLOT, 0, 420, SSC_ENV_DECAY,
|
||||
1800, 18, POLL_LIMIT);
|
||||
if (status == SSC_OK) {
|
||||
input_init(&stick, INPUT_RIGHT);
|
||||
lastSample = getTimer();
|
||||
printf("1 ANNOUNCE ZORA\n2 CREW MESSAGE\nFIRE LANDING ALERT\nQ RETURN TO BASIC\n");
|
||||
while (status == SSC_OK) {
|
||||
key = inkey();
|
||||
if (key == 'Q' || key == 'q')
|
||||
break;
|
||||
if (key == '1') {
|
||||
status = ssc_play_allophones(VOICE_SLOT, POLL_LIMIT);
|
||||
if (status == SSC_OK)
|
||||
printf("APPROACHING ZORA\n");
|
||||
} else if (key == '2') {
|
||||
status = ssc_play_phrase(MESSAGE_SLOT, POLL_LIMIT);
|
||||
if (status == SSC_OK)
|
||||
printf("WELCOME ABOARD\n");
|
||||
}
|
||||
/* Joystick readings share the audio mux. Sample once per guest tick. */
|
||||
now = getTimer();
|
||||
if (now == lastSample)
|
||||
continue;
|
||||
lastSample = now;
|
||||
input_sample(&stick);
|
||||
/* A press is an edge: holding the button counts as one landing. */
|
||||
if (status == SSC_OK && (stick.pressed & INPUT_PRIMARY)) {
|
||||
status = ssc_play_stored_effect(ALERT_SLOT, POLL_LIMIT);
|
||||
if (status == SSC_OK)
|
||||
printf("LANDING ALERT %u\n", ++landings);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* A partial command may remain after timeout. Reset only on that path. */
|
||||
if (status == SSC_TIMEOUT)
|
||||
ssc_reset();
|
||||
ssc_restore_audio(route);
|
||||
if (status != SSC_OK)
|
||||
printf("CHECK CARTRIDGE AND FIRMWARE\n");
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Planet Atlas creates ATLAS.DAT on drive 0 the first time you run it.
|
||||
#include <coco.h>
|
||||
#include <decbfile.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define ATLAS_NAME "ATLAS.DAT:0"
|
||||
#define CARD_SIZE 24
|
||||
static const char cards[][CARD_SIZE] = {
|
||||
"MERCURY: CRATERS", "VENUS: CLOUDS", "EARTH: BLUE SEA", "MARS: RED RIDGE"
|
||||
};
|
||||
|
||||
/* Keep any atlas already on the disk. On a fresh disk, write four cards. */
|
||||
static FILE *openAtlas(void)
|
||||
{
|
||||
FILE *atlas = fopen(ATLAS_NAME, "r+b");
|
||||
int complete;
|
||||
if (atlas || vcc_file_error() != DECB_ERR_NOT_FOUND)
|
||||
return atlas;
|
||||
atlas = fopen(ATLAS_NAME, "wb");
|
||||
if (!atlas)
|
||||
return NULL;
|
||||
complete = fwrite(cards, CARD_SIZE, 4, atlas) == 4;
|
||||
if (fclose(atlas) == EOF || !complete)
|
||||
return NULL;
|
||||
return fopen(ATLAS_NAME, "r+b");
|
||||
}
|
||||
|
||||
/* Read exactly one card from the current position. Leave room for a zero
|
||||
so even a card that fills all 24 bytes can be displayed as a C string. */
|
||||
static int showCard(FILE *atlas)
|
||||
{
|
||||
char card[CARD_SIZE + 1];
|
||||
if (fread(card, CARD_SIZE, 1, atlas) != 1)
|
||||
return 0;
|
||||
card[CARD_SIZE] = 0;
|
||||
printf("%s\n", card);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int takeTrip(FILE *atlas, int number)
|
||||
{
|
||||
/* Card numbers begin at 1. Disk offsets begin at 0. */
|
||||
long offset = (long)(number - 1) * CARD_SIZE;
|
||||
long bookmark;
|
||||
if (fseek(atlas, offset, SEEK_SET) != 0)
|
||||
return 0;
|
||||
bookmark = ftell(atlas); // Save the start before reading the card.
|
||||
if (bookmark < 0)
|
||||
return 0;
|
||||
printf("YOUR PICK AT BYTE %ld\n", bookmark);
|
||||
if (!showCard(atlas))
|
||||
return 0;
|
||||
|
||||
printf("HOME BASE\n");
|
||||
if (fseek(atlas, 2L * CARD_SIZE, SEEK_SET) != 0 || !showCard(atlas))
|
||||
return 0;
|
||||
printf("BACK TO YOUR BOOKMARK\n");
|
||||
if (fseek(atlas, bookmark, SEEK_SET) != 0 || !showCard(atlas))
|
||||
return 0;
|
||||
|
||||
rewind(atlas); // The first card is Mercury again.
|
||||
printf("FIRST CARD\n");
|
||||
return ftell(atlas) == 0L && showCard(atlas);
|
||||
}
|
||||
|
||||
/* Enter a whole record number. Base zero accepts 2 and 0x2 for Venus. */
|
||||
static int choosePlanet(void)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
char *line, *end;
|
||||
unsigned long number;
|
||||
printf("PICK A PLANET (1-4), THEN ENTER\n");
|
||||
line = readline();
|
||||
if (!line)
|
||||
return 0;
|
||||
if (!isdigit((unsigned char)*line))
|
||||
{
|
||||
printf("START WITH A DIGIT\n");
|
||||
continue;
|
||||
}
|
||||
errno = 0;
|
||||
number = strtoul(line, &end, 0);
|
||||
if (*end)
|
||||
printf("EXTRA CHARACTER: %c\n", *end);
|
||||
else if (errno == ERANGE || number < 1UL || number > 4UL)
|
||||
printf("CHOOSE A NUMBER FROM 1 TO 4\n");
|
||||
else
|
||||
return (int)number; // Now the value is small enough for an int.
|
||||
}
|
||||
}
|
||||
|
||||
/* The last padding byte is a visit flag. A custom card that uses the whole
|
||||
field for its description has no spare byte; leave its text intact. */
|
||||
static int recordVisit(FILE *atlas, int number)
|
||||
{
|
||||
char card[CARD_SIZE];
|
||||
long start = (long)(number - 1) * CARD_SIZE;
|
||||
if (fseek(atlas, start, SEEK_SET) != 0 || fread(card, CARD_SIZE, 1, atlas) != 1)
|
||||
return 0;
|
||||
if (!memchr(card, 0, CARD_SIZE - 1) ||
|
||||
(card[CARD_SIZE - 1] != 0 && card[CARD_SIZE - 1] != 'V'))
|
||||
{
|
||||
printf("NO ROOM FOR VISIT MARK\n");
|
||||
return 1;
|
||||
}
|
||||
if (card[CARD_SIZE - 1] == 'V')
|
||||
{
|
||||
printf("ALREADY VISITED\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Position the update stream between reading the card and writing its flag.
|
||||
if (fseek(atlas, start + CARD_SIZE - 1, SEEK_SET) != 0 ||
|
||||
fputc('V', atlas) == EOF || fflush(atlas) == EOF)
|
||||
return 0;
|
||||
printf("VISIT SAVED\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *atlas;
|
||||
int number, ok;
|
||||
cls(1);
|
||||
atlas = openAtlas();
|
||||
if (!atlas)
|
||||
{
|
||||
printf("CANNOT OPEN ATLAS.DAT\n");
|
||||
return 1;
|
||||
}
|
||||
printf("PLANET ATLAS\n1 MERCURY 2 VENUS\n3 EARTH 4 MARS\n");
|
||||
number = choosePlanet();
|
||||
if (!number)
|
||||
{
|
||||
fclose(atlas);
|
||||
printf("CANNOT READ KEYBOARD\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
cls(1);
|
||||
printf("PLANET ATLAS\n\n");
|
||||
ok = takeTrip(atlas, number);
|
||||
if (!ok)
|
||||
printf("CANNOT READ ATLAS CARD\n");
|
||||
else if (!recordVisit(atlas, number))
|
||||
{
|
||||
printf("CANNOT SAVE VISIT\n");
|
||||
ok = 0;
|
||||
}
|
||||
if (fclose(atlas) == EOF)
|
||||
ok = 0;
|
||||
if (ok)
|
||||
printf("ATLAS CLOSED\n");
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Run on a practice disk. This exercise recognizes the four Planet char cards[][CARD_SIZE].
|
||||
#include <coco.h>
|
||||
#include <decbfile.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define LIVE "ATLAS.DAT:0"
|
||||
#define DRAFT "ATLAS.NEW:0"
|
||||
#define BACKUP "ATLAS.BAK:0"
|
||||
|
||||
#define CARD_SIZE 24
|
||||
static const char original[][CARD_SIZE] = {
|
||||
"MERCURY: CRATERS", "VENUS: CLOUDS", "EARTH: BLUE SEA", "MARS: RED RIDGE"
|
||||
};
|
||||
static const char newMars[CARD_SIZE] = "MARS: DUST STORM";
|
||||
static char live[4][CARD_SIZE], draft[4][CARD_SIZE], backup[4][CARD_SIZE];
|
||||
|
||||
enum { ABSENT, FIRST, SECOND, UNRECOGNIZED, DISK_ERROR };
|
||||
|
||||
/* A valid edition contains four exact cards. Each may also have a visit mark
|
||||
in its final byte. Check file length as well as text before changing a name. */
|
||||
static int inspect(const char *name, char cards[][CARD_SIZE])
|
||||
{
|
||||
unsigned i;
|
||||
FILE *f = fopen(name, "rb");
|
||||
if (!f)
|
||||
return vcc_file_error() == DECB_ERR_NOT_FOUND ? ABSENT : DISK_ERROR;
|
||||
size_t count = fread(cards, 1, sizeof(original), f);
|
||||
int extra = fgetc(f);
|
||||
int failed = ferror(f);
|
||||
if (fclose(f) == EOF || failed)
|
||||
return DISK_ERROR;
|
||||
if (count != sizeof(original) || extra != EOF)
|
||||
return UNRECOGNIZED;
|
||||
for (i = 0; i < 4; ++i)
|
||||
{
|
||||
char mark = cards[i][CARD_SIZE - 1];
|
||||
if (mark != 0 && mark != 'V')
|
||||
return UNRECOGNIZED;
|
||||
if (memcmp(cards[i], original[i], CARD_SIZE - 1) != 0)
|
||||
{
|
||||
if (i == 3 && memcmp(cards[3], newMars, CARD_SIZE - 1) == 0)
|
||||
return SECOND;
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
return FIRST;
|
||||
}
|
||||
|
||||
/* Write only after the caller has checked that the name is unused. */
|
||||
static int writeCards(const char *name, const void *cards)
|
||||
{
|
||||
FILE *f = fopen(name, "wb");
|
||||
if (!f)
|
||||
return 0;
|
||||
int complete = fwrite(cards, 1, sizeof(original), f) == sizeof(original);
|
||||
return fclose(f) == 0 && complete;
|
||||
}
|
||||
|
||||
static void reviseMars(char cards[][CARD_SIZE])
|
||||
{
|
||||
// The old visit mark belongs to the traveler. Keep the last byte.
|
||||
memcpy(cards[3], newMars, CARD_SIZE - 1);
|
||||
}
|
||||
|
||||
static int recover(int draftState)
|
||||
{
|
||||
// The live name was missing. Restore the known old edition first.
|
||||
if (rename(BACKUP, LIVE) != 0)
|
||||
return 0;
|
||||
printf("ORIGINAL ATLAS RESTORED\n%s\n", backup[3]);
|
||||
reviseMars(backup);
|
||||
if (draftState == SECOND && memcmp(backup, draft, sizeof(original)) == 0)
|
||||
return remove(DRAFT) == 0;
|
||||
if (draftState != ABSENT)
|
||||
printf("KEPT UNEXPECTED ATLAS.NEW\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int saveAtlas(void)
|
||||
{
|
||||
int current = inspect(LIVE, live);
|
||||
int old = inspect(BACKUP, backup);
|
||||
int next = inspect(DRAFT, draft);
|
||||
if (current == DISK_ERROR || old == DISK_ERROR || next == DISK_ERROR)
|
||||
return 0;
|
||||
if (current == ABSENT && old == FIRST)
|
||||
return recover(next);
|
||||
if (current == SECOND && next == ABSENT)
|
||||
{
|
||||
printf("ATLAS ALREADY UPDATED\n%s\n", live[3]);
|
||||
return 1;
|
||||
}
|
||||
if (current == ABSENT && old == ABSENT && next == ABSENT)
|
||||
{
|
||||
if (!writeCards(LIVE, original) || inspect(LIVE, live) != FIRST ||
|
||||
memcmp(live, original, sizeof(original)) != 0)
|
||||
return 0;
|
||||
current = FIRST;
|
||||
}
|
||||
if (current != FIRST || old != ABSENT)
|
||||
{
|
||||
printf("CHECK THE THREE ATLAS FILES\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
reviseMars(live); // Only the copy in RAM has changed.
|
||||
if (next == ABSENT)
|
||||
{
|
||||
if (!writeCards(DRAFT, live))
|
||||
return 0;
|
||||
next = inspect(DRAFT, draft);
|
||||
}
|
||||
if (next != SECOND || memcmp(live, draft, sizeof(original)) != 0)
|
||||
{
|
||||
printf("CHECK ATLAS.NEW\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Both files are closed. At this checkpoint the old edition is complete
|
||||
// under BACKUP, and the new edition is complete under DRAFT.
|
||||
if (rename(LIVE, BACKUP) != 0)
|
||||
return 0;
|
||||
printf("BACKUP IN PLACE\nPRESS A KEY TO INSTALL\n");
|
||||
waitkey(0);
|
||||
if (rename(DRAFT, LIVE) != 0)
|
||||
return 0;
|
||||
printf("UPDATED ATLAS SAVED\n%s\n", draft[3]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cls(1);
|
||||
printf("PLANET ATLAS BACKUP\n");
|
||||
if (saveAtlas())
|
||||
return 0;
|
||||
printf("SAVE STOPPED - CHECK DISK\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Draw a small landing beacon on a CoCo 3. Link bgraph. */
|
||||
#include <coco.h>
|
||||
#include <Primitive.h>
|
||||
|
||||
/* BGraph's 320x16 routines use 160 bytes per row. We need just 13 rows. */
|
||||
enum { SIDE = 13, MIDDLE = 6, STRIDE = 160, INK = 3 };
|
||||
static byte stamp[SIDE * STRIDE];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
byte x, y;
|
||||
byte *slots = (byte *) 0xFFB0;
|
||||
byte oldPaper = slots[0] & 63, oldInk = slots[INK] & 63;
|
||||
if (!hscreen(2))
|
||||
return 1;
|
||||
paletteRGB(0, 0, 0, 0);
|
||||
paletteRGB(INK, 3, 3, 3);
|
||||
for (x = 0; x < SIDE; ++x)
|
||||
{
|
||||
Primitive_setPixel320x16(x, MIDDLE, INK, stamp);
|
||||
Primitive_setPixel320x16(MIDDLE, x, INK, stamp);
|
||||
}
|
||||
|
||||
/* Let Disk BASIC find the visible page. Magnify each stamp dot 3 by 3. */
|
||||
for (y = 0; y < SIDE; ++y)
|
||||
for (x = 0; x < SIDE; ++x)
|
||||
{
|
||||
byte dx, dy;
|
||||
byte color = Primitive_getPixel320x16(x, y, stamp);
|
||||
for (dy = 0; dy < 3; ++dy)
|
||||
for (dx = 0; dx < 3; ++dx)
|
||||
hset(140 + 3 * x + dx, 76 + 3 * y + dy, color);
|
||||
}
|
||||
waitkey(FALSE);
|
||||
hscreen(0);
|
||||
palette(0, oldPaper);
|
||||
palette(INK, oldInk);
|
||||
printf("BEACON CENTER: %u\n", (unsigned) Primitive_getPixel320x16(MIDDLE, MIDDLE, stamp));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Count a delivery on two planets. The manifest stays in guest RAM. */
|
||||
#include <cmoc.h>
|
||||
#include <coco.h>
|
||||
|
||||
struct Shipment
|
||||
{
|
||||
const char *destination;
|
||||
byte crates;
|
||||
byte mealsPerCrate;
|
||||
};
|
||||
|
||||
static const struct Shipment manifest[] =
|
||||
{
|
||||
{ "EARTH", 12, 20 },
|
||||
{ "MARS", 8, 15 }
|
||||
};
|
||||
|
||||
/* A pointer lets us read one row without copying the whole structure. */
|
||||
static word mealsFor(const struct Shipment *shipment)
|
||||
{
|
||||
return (word) shipment->crates * shipment->mealsPerCrate;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
word total = 0;
|
||||
byte row;
|
||||
|
||||
width(40);
|
||||
for (row = 0; row < sizeof(manifest) / sizeof(manifest[0]); ++row)
|
||||
{
|
||||
word meals = mealsFor(&manifest[row]);
|
||||
printf("%s: %u MEALS\n", manifest[row].destination, meals);
|
||||
total += meals;
|
||||
}
|
||||
printf("TOTAL: %u MEALS\n", total);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Crew log: each seat holds 1 when occupied and 0 when empty. */
|
||||
#include <cmoc.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static unsigned char storage[96];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char *seats, *larger;
|
||||
if (!vcc_heap_init(storage, sizeof(storage)))
|
||||
return 1;
|
||||
|
||||
seats = (unsigned char *) calloc(2, sizeof(*seats));
|
||||
if (!seats)
|
||||
return 1;
|
||||
printf("CREW AT LAUNCH: %u\n", (unsigned)(seats[0] + seats[1]));
|
||||
seats[0] = seats[1] = 1;
|
||||
|
||||
/* Keep the current seat list until we know it can grow. */
|
||||
larger = (unsigned char *) realloc(seats, 3);
|
||||
if (!larger)
|
||||
{
|
||||
free(seats);
|
||||
return 1;
|
||||
}
|
||||
seats = larger;
|
||||
seats[2] = 1;
|
||||
printf("CREW AFTER GROWTH: %u\n", (unsigned)(seats[0] + seats[1] + seats[2]));
|
||||
|
||||
/* The request exceeds the entire 96-byte budget. */
|
||||
larger = (unsigned char *) realloc(seats, 200);
|
||||
if (larger)
|
||||
{
|
||||
free(larger);
|
||||
return 1;
|
||||
}
|
||||
printf("NO ROOM FOR 200\n");
|
||||
printf("CREW STILL ABOARD: %u\n", (unsigned)(seats[0] + seats[1] + seats[2]));
|
||||
free(seats);
|
||||
printf("CREW LOG CLOSED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* The deck count belongs to the caller. Link cardgame. */
|
||||
#include <cardgame.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
byte deck[3] = { 1, 2, 3 };
|
||||
byte count = 3;
|
||||
byte drawn = pickCardFromDeck(deck, &count);
|
||||
printf("DREW %u, %u LEFT\n", (unsigned) drawn, (unsigned) count);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Descent Computer. Use the CoCo BASIC float backend and link vcccompat. */
|
||||
#include <cmoc.h>
|
||||
#include <coco.h>
|
||||
#include <vcc/decimal.h>
|
||||
|
||||
/* Print a complete instrument reading or mark the field unavailable. */
|
||||
static void reading(const char *label, float value, byte places, const char *unit)
|
||||
{
|
||||
char field[12];
|
||||
int length = vcc_fixed(field, sizeof(field), value, places);
|
||||
if (length < 0 || (unsigned)length >= sizeof(field))
|
||||
printf("%s--- %s\n", label, unit);
|
||||
else
|
||||
printf("%s%s %s\n", label, field, unit);
|
||||
}
|
||||
|
||||
static void report(float firstHeight, float lastHeight, float seconds)
|
||||
{
|
||||
float speed;
|
||||
if (seconds <= 0.0f) {
|
||||
printf("CHECK RADAR INTERVAL\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Falling gives a negative speed. Keep the full value for the estimate. */
|
||||
speed = (lastHeight - firstHeight) / seconds;
|
||||
reading("HEIGHT ", lastHeight, 2, "M");
|
||||
reading("SPEED ", speed, 2, "M/S");
|
||||
if (speed < 0.0f)
|
||||
reading("ETA ", lastHeight / -speed, 1, "S");
|
||||
else
|
||||
printf("ETA NO DESCENT\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cls(1);
|
||||
printf("DESCENT COMPUTER\n\n");
|
||||
/* Two radar heights in metres, measured two seconds apart. */
|
||||
report(105.50f, 101.75f, 2.0f);
|
||||
printf("\nRADAR PASS COMPLETE\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Insert two keys into a tiny terminal editor. Link ebitor. */
|
||||
#include <Ebitor.h>
|
||||
#include <sg4term.h>
|
||||
|
||||
static byte readKey(void *cookie)
|
||||
{
|
||||
return inkey();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char log[32] = "";
|
||||
ebitor_Window window = { 32, 15, 0, 0, 0, 0 };
|
||||
width(32);
|
||||
sg4term_init((char *) 0x0400, &window, readKey, NULL, (word *) 0x0112);
|
||||
Ebitor_init(log, sizeof(log), 32, 15, sg4term_clear, sg4term_locate,
|
||||
sg4term_getCursorPos, sg4term_print, sg4term_printPrefix,
|
||||
sg4term_clrtoeol, sg4term_scrollWindowUp, sg4term_scrollWindowDown,
|
||||
sg4term_waitEditorKey);
|
||||
Ebitor_setContentLength(0);
|
||||
Ebitor_locateCursorAtSavedPosition();
|
||||
Ebitor_processKey('O');
|
||||
Ebitor_processKey('K');
|
||||
Ebitor_processKey(ebitor_KEY_ARROW_LEFT); /* Commit the inserted run and move left. */
|
||||
Ebitor_saveCursorPosition();
|
||||
unsigned count = Ebitor_getContentLength();
|
||||
Ebitor_shutdown();
|
||||
cls(255);
|
||||
log[count] = 0; /* Two characters fit comfortably in our buffer. */
|
||||
printf("LOG: %s\n", log);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Work on a practice disk. Each run starts a new FIELD.LOG on drive 0.
|
||||
#include <coco.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define LOG_NAME "FIELD.LOG:0"
|
||||
|
||||
/* Each reader starts at the beginning and sees the length saved on disk. */
|
||||
static int showLog(void)
|
||||
{
|
||||
char line[40];
|
||||
FILE *reader = fopen(LOG_NAME, "r");
|
||||
int ok;
|
||||
if (!reader)
|
||||
return 0;
|
||||
while (fgets(line, sizeof(line), reader))
|
||||
printf("%s", line);
|
||||
ok = !ferror(reader);
|
||||
if (fclose(reader) == EOF)
|
||||
ok = 0;
|
||||
return ok;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *writer;
|
||||
int ok;
|
||||
cls(1);
|
||||
printf("PLANET FIELD LOG\n");
|
||||
writer = fopen(LOG_NAME, "w");
|
||||
if (!writer)
|
||||
{
|
||||
printf("CANNOT START FIELD.LOG\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Publish the first observation while we still hold the writer. */
|
||||
ok = fputs("EARTH: BLUE SEA\n", writer) != EOF && fflush(writer) == 0;
|
||||
if (ok)
|
||||
{
|
||||
printf("CHECKPOINT READER SEES:\n");
|
||||
ok = showLog();
|
||||
}
|
||||
if (ok)
|
||||
{
|
||||
printf("SPACE TO LAND ON MARS\n");
|
||||
while (waitkey(0) != ' ') {}
|
||||
ok = fputs("MARS: RED RIDGE\n", writer) != EOF;
|
||||
}
|
||||
|
||||
/* Closing delivers the second observation and releases the stream. */
|
||||
if (fclose(writer) == EOF)
|
||||
ok = 0;
|
||||
if (!ok)
|
||||
{
|
||||
printf("CHECK DISK AND LOG\n");
|
||||
return 1;
|
||||
}
|
||||
printf("FINAL READER SEES:\n");
|
||||
if (!showLog())
|
||||
{
|
||||
printf("CANNOT READ FIELD.LOG\n");
|
||||
return 1;
|
||||
}
|
||||
printf("SURVEY FILED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
10 OPEN "I",#-1,"FLIGHT"
|
||||
20 IF EOF(-1) THEN 60
|
||||
30 LINE INPUT #-1,A$
|
||||
40 PRINT A$
|
||||
50 GOTO 20
|
||||
60 CLOSE #-1
|
||||
70 PRINT "END OF FLIGHT"
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Give Mission Control two observations it can read back in recording order.
|
||||
#include <coco.h>
|
||||
#include <vcc/cassette.h>
|
||||
|
||||
static int recordFlight(void)
|
||||
{
|
||||
int status = vcc_tape_open_write("FLIGHT");
|
||||
if (status != VCC_TAPE_OK)
|
||||
return status;
|
||||
|
||||
status = vcc_tape_write_line("EARTH BLUE SEA");
|
||||
if (status == VCC_TAPE_OK)
|
||||
status = vcc_tape_write_line("MARS RED RIDGE");
|
||||
/* Closing writes the end-of-file block on a successful recording. */
|
||||
int closed = vcc_tape_close();
|
||||
return status == VCC_TAPE_OK ? closed : status;
|
||||
}
|
||||
|
||||
static int replayFlight(void)
|
||||
{
|
||||
char observation[32];
|
||||
int status = vcc_tape_open_read("FLIGHT");
|
||||
if (status != VCC_TAPE_OK)
|
||||
return status;
|
||||
|
||||
while ((status = vcc_tape_read_line(observation, sizeof observation)) == VCC_TAPE_OK)
|
||||
printf("%s\n", observation);
|
||||
int closed = vcc_tape_close();
|
||||
/* A damaged last block also stops the loop. Only EOF completes the flight. */
|
||||
return status == VCC_TAPE_EOF ? closed : status;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cls(1);
|
||||
printf("FLIGHT RECORDER\n");
|
||||
printf("W WRITE R READ\n");
|
||||
char choice;
|
||||
do {
|
||||
choice = waitkey(0);
|
||||
} while (choice != 'W' && choice != 'w' && choice != 'R' && choice != 'r');
|
||||
|
||||
int write = choice == 'W' || choice == 'w';
|
||||
int status = write ? recordFlight() : replayFlight();
|
||||
if (status != VCC_TAPE_OK) {
|
||||
printf("TAPE ERROR %d\n", status);
|
||||
return 1;
|
||||
}
|
||||
printf("%s\n", write ? "FLIGHT SAVED" : "END OF FLIGHT");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Send a text report through the CoCo printer port. No disk file is needed.
|
||||
#include <coco.h>
|
||||
#include <vcc/printer.h>
|
||||
|
||||
static int printLanding(unsigned visit, const char *planet, const char *observation)
|
||||
{
|
||||
/* Two digits for the visit, a five-character field for the planet. */
|
||||
return vcc_printer_printf("%02u %-5s %s\n", visit, planet, observation);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
cls(1);
|
||||
printf("FLIGHT CONTROL\n");
|
||||
printf("START CAPTURE IN PRINTER OUTPUT\n");
|
||||
printf("PRESS SPACE TO SEND REPORT\n");
|
||||
while (waitkey(0) != ' ') {}
|
||||
|
||||
/* Ordinary printf still goes to the screen. These four lines go to the port. */
|
||||
if (vcc_printer_printf("TP-10 FLIGHT REPORT\n") < 0 ||
|
||||
printLanding(1, "EARTH", "BLUE SEA") < 0 ||
|
||||
printLanding(2, "MARS", "RED RIDGE") < 0 ||
|
||||
vcc_printer_printf("END OF REPORT\n") < 0)
|
||||
{
|
||||
printf("REPORT FORMAT ERROR\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* The guest cannot tell whether the Mac is capturing the port. */
|
||||
printf("REPORT SENT TO PRINTER PORT\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
10 OPEN "O",#-1,"FLIGHT"
|
||||
20 PRINT #-1,"EARTH TIDE POOL"
|
||||
30 PRINT #-1,"MARS DUST DEVIL"
|
||||
40 CLOSE #-1
|
||||
50 PRINT "FLIGHT SAVED"
|
||||
@@ -0,0 +1,84 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Stereo Flyby. Link orch90, input and bcontrol, in that order. */
|
||||
#include <cmoc.h>
|
||||
#include <coco.h>
|
||||
#include <vcc/input.h>
|
||||
#include <vcc/orch90.h>
|
||||
|
||||
#define FRAMES 2048
|
||||
#define FIRST_COLUMN 2
|
||||
#define LAST_COLUMN 29
|
||||
#define STAR_ROW 8
|
||||
#define SHIP_ROW 10
|
||||
|
||||
/* Keep the sample in guest RAM for as long as the interrupt can read it. */
|
||||
static struct orch90_frame beacon[FRAMES];
|
||||
|
||||
static void makeBeacon(void)
|
||||
{
|
||||
static const byte wave[] = {
|
||||
128, 146, 162, 172, 176, 172, 162, 146,
|
||||
128, 110, 94, 84, 80, 84, 94, 110
|
||||
};
|
||||
unsigned i;
|
||||
for (i = 0; i < FRAMES; ++i) {
|
||||
/* The first note comes from the left. The right note is an octave up.
|
||||
128 in both channels is the quiet space between notes. */
|
||||
beacon[i].left = i < 768 ? wave[i & 15] : 128;
|
||||
beacon[i].right = i >= 1024 && i < 1792 ? wave[(i << 1) & 15] : 128;
|
||||
}
|
||||
}
|
||||
|
||||
static void mark(byte column, byte row, char symbol)
|
||||
{
|
||||
locate(column, row);
|
||||
putchar(symbol);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
VccInput stick;
|
||||
unsigned lastUpdate, now;
|
||||
byte ship = 15, star = LAST_COLUMN, key;
|
||||
|
||||
width(32);
|
||||
cls(1);
|
||||
makeBeacon();
|
||||
input_init(&stick, INPUT_RIGHT);
|
||||
printf("STEREO FLYBY\n\n1 TRANSMIT BEACON\nRIGHT STICK STEER Q QUIT\n");
|
||||
locate(1, 7); printf("+----------------------------+");
|
||||
locate(1, 12); printf("+----------------------------+");
|
||||
mark(ship, SHIP_ROW, '^');
|
||||
mark(star, STAR_ROW, '*');
|
||||
lastUpdate = getTimer();
|
||||
for (;;) {
|
||||
key = inkey();
|
||||
if (key == 'Q' || key == 'q')
|
||||
break;
|
||||
if (key == '1' && !orch90_active()) {
|
||||
locate(0, 5);
|
||||
if (orch90_start(beacon, FRAMES, 1, ORCH90_CLOCK_NORMAL))
|
||||
printf("BEACON ON AIR");
|
||||
else
|
||||
printf("PLAYBACK UNAVAILABLE");
|
||||
}
|
||||
/* The guest clock drives the flight display. Audio advances between
|
||||
updates, even when this loop is busy drawing or reading input. */
|
||||
now = getTimer();
|
||||
if ((unsigned)(now - lastUpdate) < 4)
|
||||
continue;
|
||||
lastUpdate = now;
|
||||
input_sample(&stick);
|
||||
mark(ship, SHIP_ROW, ' ');
|
||||
if (stick.dx < 0 && ship > FIRST_COLUMN) --ship;
|
||||
if (stick.dx > 0 && ship < LAST_COLUMN) ++ship;
|
||||
mark(ship, SHIP_ROW, '^');
|
||||
mark(star, STAR_ROW, ' ');
|
||||
star = star == FIRST_COLUMN ? LAST_COLUMN : star - 1;
|
||||
mark(star, STAR_ROW, '*');
|
||||
}
|
||||
orch90_stop();
|
||||
locate(0, 14);
|
||||
printf("FLYBY COMPLETE\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Draw letters in the four graphics pages reserved by fresh Disk BASIC. Link hirestxt. */
|
||||
#include <hirestxt.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct HiResTextScreenInit2 setup;
|
||||
byte *page = (byte *) ((word) * (byte *) 0x00BC << 8);
|
||||
memset(&setup, 0, sizeof(setup));
|
||||
setup.init.numColumns = 51;
|
||||
setup.init.writeCharAtFuncPtr = writeCharAt_51cols;
|
||||
setup.init.textScreenBuffer = page;
|
||||
setup.init.timer = (word *) 0x0112; /* BASIC's 60 Hz clock */
|
||||
if (!pmode(4, page))
|
||||
return 1;
|
||||
pcls(0);
|
||||
screen(1, 1);
|
||||
initHiResTextScreen2(&setup);
|
||||
writeString("MARS STATION");
|
||||
waitkey(FALSE);
|
||||
closeHiResTextScreen();
|
||||
screen(0, 0);
|
||||
printf("BACK FROM THE GRAPHICS PAGE\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Land on the gold pad. Link gime, bgraph and bcontrol. */
|
||||
#include <vcc/gime.h>
|
||||
#include <Primitive.h>
|
||||
#include <Joystick.h>
|
||||
|
||||
enum { SPACE, WHITE, CYAN, GOLD, FLAME, BLUE, VIOLET };
|
||||
enum { CRAFT_W = 20, CRAFT_H = 16, PAD_LEFT = 220, PAD_RIGHT = 270 };
|
||||
typedef struct { unsigned x, y; } Position;
|
||||
|
||||
/* BGraph supplies the line algorithm. Send each pixel to the hidden page. */
|
||||
static void pixel(word x, byte y, byte color, void *unused)
|
||||
{
|
||||
(void) unused;
|
||||
gime_plot(x, y, color);
|
||||
}
|
||||
|
||||
static void landscape(void)
|
||||
{
|
||||
static const byte ridge[] = {183, 167, 177, 161, 176, 170, 184, 165, 177, 168};
|
||||
unsigned i; /* Star and ridge x coordinates extend beyond 255. */
|
||||
/* gime_open cleared both pages to SPACE before the first frame. */
|
||||
for (i = 0; i < 22; ++i)
|
||||
gime_plot(7 + i * 14, 8 + (i * 13) % 34, WHITE);
|
||||
/* The crescent and stars sit above the flight area. */
|
||||
gime_fill_rect(258, 18, 12, 2, GOLD);
|
||||
gime_fill_rect(254, 20, 6, 10, GOLD);
|
||||
gime_fill_rect(258, 30, 12, 2, GOLD);
|
||||
gime_fill_rect(0, 184, GIME_WIDTH, GIME_HEIGHT - 184, BLUE);
|
||||
for (i = 0; i < 9; ++i)
|
||||
Primitive_line(i * 35, ridge[i], (i + 1) * 35, ridge[i + 1], VIOLET, pixel, 0);
|
||||
gime_fill_rect(PAD_LEFT, 160, PAD_RIGHT - PAD_LEFT, 2, GOLD);
|
||||
gime_fill_rect(PAD_LEFT + 3, 162, 2, 12, CYAN);
|
||||
gime_fill_rect(PAD_RIGHT - 5, 162, 2, 12, CYAN);
|
||||
}
|
||||
|
||||
static void drawCraft(unsigned x, unsigned y)
|
||||
{
|
||||
gime_fill_rect(x + 7, y, 6, 2, WHITE);
|
||||
gime_fill_rect(x + 5, y + 2, 10, 5, CYAN);
|
||||
gime_fill_rect(x + 8, y + 3, 4, 3, BLUE);
|
||||
gime_fill_rect(x + 2, y + 7, 16, 4, WHITE);
|
||||
gime_fill_rect(x + 3, y + 11, 2, 4, GOLD);
|
||||
gime_fill_rect(x + 15, y + 11, 2, 4, GOLD);
|
||||
gime_fill_rect(x, y + 15, 5, 1, WHITE);
|
||||
gime_fill_rect(x + 15, y + 15, 5, 1, WHITE);
|
||||
gime_fill_rect(x + 8, y + 11, 4, 3, FLAME);
|
||||
}
|
||||
|
||||
static int direction(byte axis, byte lowProbe, byte lowBit, byte highProbe, byte highBit)
|
||||
{
|
||||
/* When a key is held, it takes precedence over this joystick axis. */
|
||||
if (isKeyPressed(lowProbe, lowBit))
|
||||
return -2;
|
||||
if (isKeyPressed(highProbe, highBit))
|
||||
return 2;
|
||||
Joystick_selectAnalogMuxInputs(axis);
|
||||
if (!Joystick_compareAxis(16))
|
||||
return -2;
|
||||
return Joystick_compareAxis(48) ? 2 : 0;
|
||||
}
|
||||
|
||||
static unsigned move(int value, int delta, int minimum, int maximum)
|
||||
{
|
||||
value += delta;
|
||||
if (value < minimum) return minimum;
|
||||
if (value > maximum) return maximum;
|
||||
return value;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Position craft = {144, 82}, previous[2];
|
||||
byte page = 0, initialized = 0, landed = 0, presented = 1;
|
||||
static const byte colors[] = {0x00, 0x3F, 0x1B, 0x34, 0x26, 0x08, 0x29};
|
||||
byte i;
|
||||
if (!gime_open())
|
||||
{
|
||||
printf("USE A SUPPORTED COCO 3 BASIC SETUP\n");
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < sizeof(colors); ++i)
|
||||
gime_set_palette(i, colors[i]);
|
||||
Joystick_disableSound();
|
||||
|
||||
while (!isKeyPressed(KEY_PROBE_Q, KEY_BIT_Q))
|
||||
{
|
||||
if (initialized < 2)
|
||||
{
|
||||
landscape(); /* Each physical page gets the scenery once. */
|
||||
++initialized;
|
||||
}
|
||||
else
|
||||
gime_fill_rect(previous[page].x, previous[page].y, CRAFT_W, CRAFT_H, SPACE);
|
||||
|
||||
craft.x = move(craft.x, direction(0, KEY_PROBE_A, KEY_BIT_A, KEY_PROBE_D, KEY_BIT_D), 0, GIME_WIDTH - CRAFT_W);
|
||||
craft.y = move(craft.y, direction(1, KEY_PROBE_W, KEY_BIT_W, KEY_PROBE_S, KEY_BIT_S), 44, 160 - CRAFT_H);
|
||||
drawCraft(craft.x, craft.y);
|
||||
previous[page] = craft; /* Where to erase when this page comes around again. */
|
||||
presented = gime_present();
|
||||
if (!presented)
|
||||
break;
|
||||
page ^= 1;
|
||||
if (craft.y == 160 - CRAFT_H && craft.x >= PAD_LEFT && craft.x + CRAFT_W <= PAD_RIGHT)
|
||||
{
|
||||
landed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Joystick_selectAnalogMuxInputs(0);
|
||||
Joystick_enableSound();
|
||||
gime_close();
|
||||
if (!presented)
|
||||
{
|
||||
printf("DISPLAY TIMING UNAVAILABLE\n");
|
||||
return 1;
|
||||
}
|
||||
printf("%s\n", landed ? "ON THE PAD!" : "FLIGHT ENDED");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Fit a call sign on a four-character cargo tag. Default CMOC runtime. */
|
||||
#include <cmoc.h>
|
||||
|
||||
static int setTag(char *tag, size_t capacity, const char *name)
|
||||
{
|
||||
size_t length = strlen(name);
|
||||
if (length >= capacity)
|
||||
return 0; /* Leave the previous tag intact. */
|
||||
memcpy(tag, name, length + 1); /* Copy the terminating zero as well. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char tag[5] = "";
|
||||
if (!setTag(tag, sizeof(tag), "MARS"))
|
||||
return 1;
|
||||
printf("TAG: %s, LETTERS: %u\n", tag, (unsigned) strlen(tag));
|
||||
if (!setTag(tag, sizeof(tag), "EARTH") && strcmp(tag, "MARS") == 0)
|
||||
printf("EARTH TOO LONG. KEPT %s\n", tag);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Count on the pool to reject a request larger than its region. Link wydealloc. */
|
||||
#include <wydealloc.h>
|
||||
#include <cmoc.h>
|
||||
|
||||
static unsigned char storage[64];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
MemPool pool;
|
||||
void *small, *tooBig;
|
||||
if (!MemPool_init(&pool, storage, storage + sizeof(storage)))
|
||||
return 1;
|
||||
small = MemPool_alloc(&pool, 8);
|
||||
tooBig = MemPool_alloc(&pool, 80);
|
||||
printf("SMALL %s, LARGE %s\n", small ? "OK" : "FAILED", tooBig ? "OK" : "REFUSED");
|
||||
MemPool_free(&pool, small);
|
||||
MemPool_free(&pool, tooBig);
|
||||
small = MemPool_alloc(&pool, 8);
|
||||
printf("AFTER FREE: %s\n", small ? "OK" : "FAILED");
|
||||
MemPool_free(&pool, small);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Survey the gold deposit. Link gime, input and bcontrol. */
|
||||
#include <coco.h>
|
||||
#include <vcc/gime.h>
|
||||
#include <vcc/input.h>
|
||||
|
||||
enum { SKY, WHITE, CYAN, GOLD, MAGENTA, ROCK, SHADOW };
|
||||
enum { LAUNCH_Y = 66, DEPOSIT_X = 216, DEPOSIT_Y = 152, MAX_CHARGE = 16 };
|
||||
|
||||
typedef struct {
|
||||
unsigned shipX, probeX;
|
||||
byte probeY; /* Zero when no probe is in flight. */
|
||||
} Flight;
|
||||
|
||||
/* The craft and probe fly through clear sky, so a hidden page can erase
|
||||
its previous sprites without saving any of the scenery beneath them. */
|
||||
static void scenery(void)
|
||||
{
|
||||
static const byte horizon[] = {172, 170, 168, 171, 174, 175, 179, 180, 178, 173,
|
||||
170, 166, 162, 165, 172, 176, 180, 177, 174, 171};
|
||||
unsigned i;
|
||||
for (i = 0; i < 20; ++i) {
|
||||
unsigned x = i * 16;
|
||||
unsigned top = horizon[i];
|
||||
gime_fill_rect(x, top, 16, 192 - top, ROCK);
|
||||
gime_fill_rect(x, top, 16, 1, MAGENTA);
|
||||
if (i % 3 == 0) gime_fill_rect(x + 6, top + 6, 7, 2, SHADOW);
|
||||
gime_plot(x + 4, 20 + i * 7 % 23, WHITE);
|
||||
}
|
||||
gime_fill_rect(264, 15, 8, 2, GOLD); /* Crescent over the landing site. */
|
||||
gime_fill_rect(261, 17, 3, 7, GOLD);
|
||||
gime_fill_rect(264, 24, 8, 2, GOLD);
|
||||
gime_fill_rect(DEPOSIT_X + 2, DEPOSIT_Y + 3, 4, 11, CYAN);
|
||||
gime_fill_rect(DEPOSIT_X + 20, DEPOSIT_Y + 3, 4, 22, CYAN);
|
||||
gime_fill_rect(7, 7, 52, 8, WHITE); /* Charge gauge surround. */
|
||||
}
|
||||
|
||||
static void drawShip(unsigned x)
|
||||
{
|
||||
gime_fill_rect(x + 6, 49, 8, 2, WHITE);
|
||||
gime_fill_rect(x + 4, 51, 12, 6, CYAN);
|
||||
gime_fill_rect(x + 8, 52, 5, 3, SHADOW);
|
||||
gime_fill_rect(x, 57, 20, 4, WHITE);
|
||||
gime_fill_rect(x + 2, 61, 3, 3, GOLD);
|
||||
gime_fill_rect(x + 15, 61, 3, 3, GOLD);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static const byte colors[] = {0x00, 0x3f, 0x1b, 0x34, 0x29, 0x08, 0x01};
|
||||
VccInput stick;
|
||||
Flight now = {144, 0, 0}, old[2];
|
||||
unsigned launched = 0;
|
||||
byte ready = 0, charge = 0, limit = 0, charging = 0, found = 0;
|
||||
byte page = 0, freshPages = 2, i;
|
||||
|
||||
if (!gime_open()) {
|
||||
printf("USE COCO 3 BASIC WITH 512K OR MORE\n");
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < sizeof(colors); ++i) gime_set_palette(i, colors[i]);
|
||||
input_init(&stick, INPUT_RIGHT);
|
||||
|
||||
while (!isKeyPressed(KEY_PROBE_Q, KEY_BIT_Q)) {
|
||||
input_sample(&stick); /* One sample for this entire update. */
|
||||
if (stick.dx < 0 && now.shipX >= 2) now.shipX -= 2;
|
||||
if (stick.dx > 0 && now.shipX < GIME_WIDTH - 20) now.shipX += 2;
|
||||
|
||||
if (stick.pressed & INPUT_PRIMARY) {
|
||||
++launched; /* Start one new probe at the craft. */
|
||||
now.probeX = now.shipX + 9;
|
||||
now.probeY = LAUNCH_Y;
|
||||
limit = LAUNCH_Y + 24 + 4 * ready;
|
||||
charge = 0;
|
||||
charging = 1;
|
||||
} else if (now.probeY) {
|
||||
if (now.probeY >= limit) now.probeY = 0;
|
||||
else now.probeY += 2;
|
||||
}
|
||||
if (charging && (stick.held & INPUT_PRIMARY) && charge < MAX_CHARGE)
|
||||
++charge; /* Build energy for the NEXT probe. */
|
||||
if (charging && (stick.released & INPUT_PRIMARY)) {
|
||||
ready = charge; /* Lock in the range for the next press. */
|
||||
charging = 0;
|
||||
}
|
||||
if (now.probeY + 3 >= DEPOSIT_Y && now.probeX >= DEPOSIT_X &&
|
||||
now.probeX < DEPOSIT_X + 26) {
|
||||
found = 1;
|
||||
now.probeY = 0;
|
||||
}
|
||||
|
||||
if (freshPages) {
|
||||
scenery();
|
||||
--freshPages;
|
||||
} else {
|
||||
gime_fill_rect(old[page].shipX, 49, 20, 15, SKY);
|
||||
if (old[page].probeY)
|
||||
gime_fill_rect(old[page].probeX, old[page].probeY, 2, 4, SKY);
|
||||
}
|
||||
drawShip(now.shipX);
|
||||
if (now.probeY) gime_fill_rect(now.probeX, now.probeY, 2, 4, CYAN);
|
||||
gime_fill_rect(DEPOSIT_X, DEPOSIT_Y, 26, 3, found ? CYAN : GOLD);
|
||||
gime_fill_rect(9, 9, 48, 4, SHADOW);
|
||||
gime_fill_rect(9, 9, 3 * (charging ? charge : ready), 4, charging ? GOLD : CYAN);
|
||||
old[page] = now;
|
||||
if (!gime_present()) {
|
||||
gime_close();
|
||||
printf("DISPLAY TIMING UNAVAILABLE\n");
|
||||
return 1;
|
||||
}
|
||||
page ^= 1;
|
||||
}
|
||||
gime_close();
|
||||
printf("PROBES LAUNCHED: %u\n", launched);
|
||||
if (found) printf("DEPOSIT SURVEYED\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Run twice on the same practice disk. Each flight adds one observation.
|
||||
#include <coco.h>
|
||||
#include <decbfile.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LOG_NAME "TRIP.LOG:0"
|
||||
|
||||
static int fly(FILE *log)
|
||||
{
|
||||
char line[32];
|
||||
unsigned visits = 0;
|
||||
const char *planet;
|
||||
|
||||
/* a+ opens even a new log at byte zero so we can read earlier flights. */
|
||||
while (fgets(line, sizeof(line), log))
|
||||
{
|
||||
if ((visits == 0 && strcmp(line, "VISIT 1: EARTH\n") == 0) ||
|
||||
(visits == 1 && strcmp(line, "VISIT 2: MARS\n") == 0))
|
||||
++visits;
|
||||
else
|
||||
{
|
||||
printf("UNRECOGNIZED TRIP.LOG\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (ferror(log))
|
||||
return 0;
|
||||
if (visits == 2)
|
||||
{
|
||||
printf("BOTH VISITS ALREADY FILED\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Move the cursor to the first record. With a+, output still appends. */
|
||||
if (fseek(log, 0L, SEEK_SET) != 0)
|
||||
return 0;
|
||||
planet = visits ? "MARS" : "EARTH";
|
||||
printf("AT BYTE ZERO\nFILING %s\n", planet);
|
||||
if (fprintf(log, "VISIT %u: %s\n", visits + 1, planet) < 0)
|
||||
return 0;
|
||||
|
||||
/* This short record is buffered. Keep the stream open if saving fails. */
|
||||
while (fflush(log) == EOF)
|
||||
{
|
||||
char key;
|
||||
if (ferror(log) != DECB_ERR_IO)
|
||||
return 0;
|
||||
printf("SAVE FAILED\nKEEP THE SAME DISK IN DRIVE 0\n");
|
||||
printf("IF PROTECTED, TURN PROTECT OFF\nR: RETRY Q: QUIT\n");
|
||||
do {
|
||||
key = waitkey(0);
|
||||
} while (key != 'R' && key != 'r' && key != 'Q' && key != 'q');
|
||||
if (key == 'Q' || key == 'q')
|
||||
return 0;
|
||||
/* Retry just the flush. Printing the observation again could duplicate it. */
|
||||
clearerr(log);
|
||||
printf("RETRYING SAVE\n");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *log;
|
||||
char line[32];
|
||||
int ok;
|
||||
cls(1);
|
||||
printf("RETURN TRIP\n");
|
||||
log = fopen(LOG_NAME, "a+");
|
||||
if (!log)
|
||||
{
|
||||
printf("CANNOT OPEN TRIP.LOG\n");
|
||||
return 1;
|
||||
}
|
||||
ok = fly(log);
|
||||
/* Check the result of closing the stream, even after an explicit flush. */
|
||||
if (fclose(log) == EOF)
|
||||
ok = 0;
|
||||
if (!ok)
|
||||
{
|
||||
printf("CHECK DISK AND LOG\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* A new reader shows what the next flight will find on the disk. */
|
||||
log = fopen(LOG_NAME, "r");
|
||||
if (!log)
|
||||
{
|
||||
printf("CANNOT REOPEN TRIP.LOG\n");
|
||||
return 1;
|
||||
}
|
||||
printf("REOPENED TRIP.LOG\n");
|
||||
while (fgets(line, sizeof(line), log))
|
||||
printf("%s", line);
|
||||
ok = !ferror(log);
|
||||
if (fclose(log) == EOF)
|
||||
ok = 0;
|
||||
if (!ok)
|
||||
{
|
||||
printf("CANNOT READ TRIP.LOG\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Two landscapes, one working array. Link bank, gime and hirestxt. */
|
||||
#include <coco.h>
|
||||
#include <font5x8.h>
|
||||
#include <vcc/bank.h>
|
||||
#include <vcc/gime.h>
|
||||
|
||||
enum { COLUMNS = 20, FIRST_COLUMN = 10, FLOOR = 169 };
|
||||
enum { NIGHT, INK, WHITE, GOLD, WINDOW, EARTH_FAR, EARTH_SOIL, EARTH_EDGE,
|
||||
MARS_FAR, MARS_SOIL, MARS_EDGE };
|
||||
|
||||
static const byte earth[COLUMNS] = {
|
||||
128, 122, 116, 120, 132, 140, 136, 128, 122, 126,
|
||||
132, 140, 146, 138, 134, 122, 112, 120, 132, 140
|
||||
};
|
||||
static const byte mars[COLUMNS] = {
|
||||
156, 146, 132, 128, 140, 154, 150, 140, 142, 148,
|
||||
152, 146, 136, 126, 118, 130, 142, 154, 146, 138
|
||||
};
|
||||
|
||||
/* Pierre Sarrazin's HiresText font has five ink columns, encoded as zero bits. */
|
||||
static void label(unsigned x, byte y, const char *text)
|
||||
{
|
||||
while (*text) {
|
||||
const byte *glyph = font5x8 + ((unsigned)*text++ - ' ') * 8;
|
||||
byte row, col;
|
||||
for (row = 0; row < 8; ++row)
|
||||
for (col = 0; col < 5; ++col)
|
||||
if (!(glyph[row] & (0x80 >> col)))
|
||||
gime_plot(x + col, y + row, WHITE);
|
||||
x += 6;
|
||||
}
|
||||
}
|
||||
|
||||
static byte draw(const byte *ridge, byte onMars, byte column)
|
||||
{
|
||||
char reading[10]; /* "RIDGE $FF" and its terminator. */
|
||||
unsigned i, x = column * 16;
|
||||
byte farRock = onMars ? MARS_FAR : EARTH_FAR;
|
||||
byte soil = onMars ? MARS_SOIL : EARTH_SOIL;
|
||||
byte edge = onMars ? MARS_EDGE : EARTH_EDGE;
|
||||
|
||||
gime_clear(NIGHT);
|
||||
for (i = 0; i < COLUMNS; ++i) {
|
||||
unsigned left = i * 16;
|
||||
unsigned farY = 101 + ((i * 7 + (onMars ? 19 : 5)) % 27);
|
||||
gime_plot(left + 3, 31 + i * 11 % 43, WHITE);
|
||||
gime_fill_rect(left, farY, 16, FLOOR - farY, farRock);
|
||||
gime_fill_rect(left, ridge[i], 16, FLOOR - ridge[i], soil);
|
||||
gime_fill_rect(left, ridge[i], 16, 2, edge);
|
||||
if ((i & 1) == 0 && ridge[i] + 9 < FLOOR)
|
||||
gime_fill_rect(left + 3, ridge[i] + 8, 6, 1, farRock);
|
||||
}
|
||||
/* A crescent hangs above the distant range. */
|
||||
gime_fill_rect(259, 28, 8, 2, edge);
|
||||
gime_fill_rect(256, 30, 4, 8, edge);
|
||||
gime_fill_rect(259, 38, 8, 2, edge);
|
||||
/* A small survey craft and the sounding line beneath it. */
|
||||
for (i = 67; i < ridge[column]; i += 6)
|
||||
gime_plot(x + 8, i, GOLD);
|
||||
gime_fill_rect(x + 5, 51, 8, 5, WINDOW);
|
||||
gime_fill_rect(x + 2, 56, 13, 3, WHITE);
|
||||
gime_fill_rect(x, 59, 16, 3, edge);
|
||||
gime_fill_rect(x + 4, 62, 2, 3, GOLD);
|
||||
gime_fill_rect(x + 11, 62, 2, 3, GOLD);
|
||||
|
||||
label(8, 8, onMars ? "MARS SURVEY" : "EARTH SURVEY");
|
||||
sprintf(reading, "RIDGE $%02X", (unsigned)ridge[column]);
|
||||
label(131, 8, reading);
|
||||
label(258, 8, onMars ? "BANK $29" : "BANK $28");
|
||||
gime_fill_rect(8, 19, 304, 1, edge);
|
||||
gime_fill_rect(0, FLOOR, 320, 192 - FLOOR, INK);
|
||||
label(8, 176, "A/D FLY SPACE SWAP R RAISE ON MARS Q QUIT");
|
||||
return gime_present();
|
||||
}
|
||||
|
||||
static byte survey(void)
|
||||
{
|
||||
byte ridge[COLUMNS], column = FIRST_COLUMN, onMars = 0;
|
||||
unsigned offset;
|
||||
|
||||
/* Seed once. Changing planets must read the saved map, not reseed it. */
|
||||
if (!bank_write(0, earth, COLUMNS) ||
|
||||
!bank_write(BANK_PAGE_SIZE, mars, COLUMNS))
|
||||
return 0;
|
||||
for (;;) {
|
||||
byte key;
|
||||
offset = onMars ? BANK_PAGE_SIZE : 0u;
|
||||
if (!bank_read(offset, ridge, COLUMNS) || !draw(ridge, onMars, column))
|
||||
return 0;
|
||||
do {
|
||||
key = waitkey(0);
|
||||
if (key >= 'a' && key <= 'z') key -= 'a' - 'A';
|
||||
if (key == 'Q') return 1;
|
||||
if (key == ' ') { onMars ^= 1; break; }
|
||||
if (key == 'A' && column > 0) { --column; break; }
|
||||
if (key == 'D' && column + 1 < COLUMNS) { ++column; break; }
|
||||
if (key == 'R' && onMars && ridge[column] >= 96) {
|
||||
/* Screen y grows downward. Save just the changed byte. */
|
||||
ridge[column] -= 16;
|
||||
if (!bank_write(offset + column, &ridge[column], 1))
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static const byte colors[] = {
|
||||
0x01, 0x00, 0x3f, 0x36, 0x1b, 0x0a, 0x15, 0x1e, 0x21, 0x26, 0x37
|
||||
};
|
||||
byte i, ok;
|
||||
if (!bank_open()) {
|
||||
printf("USE STANDARD COCO 3 BASIC WITH 512K OR MORE\n");
|
||||
return 1;
|
||||
}
|
||||
if (!gime_open()) {
|
||||
bank_close();
|
||||
printf("GRAPHICS UNAVAILABLE\n");
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < sizeof(colors); ++i) gime_set_palette(i, colors[i]);
|
||||
ok = survey();
|
||||
gime_close();
|
||||
bank_close();
|
||||
printf("%s\n", ok ? "SURVEY COMPLETE" : "SURVEY TRANSFER OR DISPLAY FAILED");
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Three rooms in a straight corridor. Link astar. */
|
||||
#include <astar.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
AStarNode rooms[3];
|
||||
AStarGraph map = { rooms, 3, 1 };
|
||||
AStarPathIterator it;
|
||||
AStarNode *room;
|
||||
byte i;
|
||||
for (i = 0; i < 3; ++i)
|
||||
astar_initNode(rooms + i, NULL, i < 2, FALSE);
|
||||
if (!astar_searchGrid(&map, 0, 0, 2, 0))
|
||||
return 1;
|
||||
astar_startPathIteration(&it, &map, 2, 0);
|
||||
printf("BACK FROM GOAL:");
|
||||
while ((room = astar_advancePathIteration(&it)) != NULL)
|
||||
printf(" %u", (unsigned) (room - rooms));
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Fly the right stick to a position and press its first button. Link bcontrol. */
|
||||
#include <Joystick.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
byte axes[4] = { 0, 0, 0, 0 };
|
||||
byte buttons;
|
||||
word start;
|
||||
printf("MOVE THE RIGHT STICK AND FIRE\n");
|
||||
Joystick_disableSound();
|
||||
start = getTimer();
|
||||
do
|
||||
{
|
||||
buttons = Joystick_getButtonStates();
|
||||
} while ((buttons & 1) && (word) (getTimer() - start) < 600);
|
||||
Joystick_getAxisValues(axes, 0x03);
|
||||
Joystick_selectAnalogMuxInputs(0);
|
||||
Joystick_enableSound();
|
||||
printf("RIGHT X=%u Y=%u\n", (unsigned) axes[0], (unsigned) axes[1]);
|
||||
printf("BUTTON %s\n", (buttons & 1) ? "UP" : "DOWN");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/* Sound a landing signal and give the interrupt vector back. Link bsound. */
|
||||
#include <Player.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Player player;
|
||||
printf("BEACON ON\n");
|
||||
Player_init(&player, TRUE, NULL);
|
||||
Player_sound(130, 12);
|
||||
Player_shutdown();
|
||||
printf("BEACON OFF\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user