// SPDX-License-Identifier: GPL-3.0-or-later #include #include #include #include #include #include // Poll the two primary buttons. Reading buttons alone preserves the audio mux. static unsigned char buttonDown; static void checkThruster(void) { unsigned char down = (Joystick_getButtonStates2() & 3) != 3; if (down && !buttonDown) printf("THRUST\n"); buttonDown = down; } // Send one byte at a time so the player can fire while the cartridge is busy. // The firmware asserts busy after accepting the terminator. Give it time to // start, then wait for it to finish before sending another announcement. static unsigned char announce(const char *words) { ssc_phrase phrase; unsigned int start = getTimer(); if (ssc_begin_phrase(&phrase, words) != SSC_OK) return 0; while (ssc_service(&phrase) == SSC_PENDING) { checkThruster(); if ((unsigned int)(getTimer() - start) >= 90) return 0; } start = getTimer(); while (ssc_status() & SSC_SPEECH_IDLE) { checkThruster(); if ((unsigned int)(getTimer() - start) >= 60) return 0; } while (!(ssc_status() & SSC_SPEECH_IDLE)) { checkThruster(); if ((unsigned int)(getTimer() - start) >= 600) return 0; } return 1; } // Make an original two-note beacon. At normal CPU speed 16 frames repeat // about 250 times a second. The right-hand note is one octave higher. static void beacon(void) { struct orch90_frame block[128]; unsigned char side, i, repeat; for (side = 0; side < 2; ++side) { for (i = 0; i < 128; ++i) { block[i].left = side ? 128 : (i & 8 ? 152 : 104); block[i].right = side ? (i & 4 ? 152 : 104) : 128; } for (repeat = 0; repeat < 6; ++repeat) orch90_play(block, 128, ORCH90_CLOCK_NORMAL); } orch90_write(128, 128); } int main(void) { char key, message[24]; unsigned int route; cls(1); printf("TALKING PLANET LANDER\n1 EARTH 2 MARS\n"); do { key = waitkey(0); } while (key != '1' && key != '2'); snprintf(message, sizeof(message), "DESTINATION %s", key == '1' ? "EARTH" : "MARS"); printf("%s\nPRESS FIRE FOR THRUST\n", message); route = ssc_route_audio(); beacon(); if (announce(message)) announce("LANDING COMPLETE"); ssc_restore_audio(route); printf("TOUCHDOWN\n"); return 0; }