From cb9a65ae20b6ffe941b58df3cafaa9f829ac7c3f Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Sun, 27 Oct 2024 19:58:38 -0700 Subject: [PATCH] Expand self-tests around catalog data --- software/hardware-test/src/main.c | 139 +++++++++++++++++++----------- 1 file changed, 88 insertions(+), 51 deletions(-) diff --git a/software/hardware-test/src/main.c b/software/hardware-test/src/main.c index 7f9e8c2..b295dff 100644 --- a/software/hardware-test/src/main.c +++ b/software/hardware-test/src/main.c @@ -11,6 +11,7 @@ #include #include "menu_font.h" +#include "segavideo_format.h" #include "segavideo_menu.h" #include "segavideo_player.h" @@ -35,6 +36,9 @@ #define PAL_WHITE PAL2 #define PAL_YELLOW PAL3 +// Maximum number of entries in a video catalog file. +#define MAX_CATALOG_SIZE 127 + // Macros to complete sram_march_test in sram-common.h char march_error_1[256]; char march_error_2[256]; @@ -259,57 +263,7 @@ int main(bool hardReset) { } - // 13. Perform various intensive memory tests through the firmware. - // There are many different passes of this, with different patterns to verify. - line++; // blank line - int memory_test_pass_line = line; - line += 2; - int memory_test_error_line = line; - line += 2; - - VDP_setTextPalette(PAL_WHITE); - // 0 1 - // 012345678901234567 - VDP_drawText("SRAM test pass 00", 0, memory_test_pass_line); - VDP_drawText("......................", 1, memory_test_pass_line + 1); - - for (int pass = 0; pass < SRAM_MARCH_TEST_NUM_PASSES; ++pass) { - waitMs(1); - *KINETOSCOPE_PORT_COMMAND = CMD_MARCH_TEST; - *KINETOSCOPE_PORT_ARG = pass; - waitMs(1); - *KINETOSCOPE_PORT_TOKEN = 1; - - VDP_setTextPalette(PAL_WHITE); - char counter[3] = { - '0' + ((pass / 10) % 10), - '0' + (pass % 10), - '\0', - }; - VDP_drawText(counter, 15, memory_test_pass_line); - // "!": indicates that the uC is filling the SRAM with data. - VDP_drawText("!", pass + 1, memory_test_pass_line + 1); - - if (!waitForToken(/* timeout_seconds= */ 30)) { - VDP_setTextPalette(PAL_YELLOW); - VDP_drawText("SRAM test command timed out.", 1, line++); - break; - } - // "?": indicates that the Sega is reading the SRAM. - VDP_drawText("?", pass + 1, memory_test_pass_line + 1); - - bool ok = sram_march_test(pass); - VDP_setTextPalette(ok ? PAL_WHITE : PAL_YELLOW); - VDP_drawText(ok ? "P" : "F", pass + 1, memory_test_pass_line + 1); - if (!ok) { - VDP_drawText(march_error_1, 0, memory_test_error_line); - VDP_drawText(march_error_2, 0, memory_test_error_line + 1); - waitMs(10 * 1000); - } - } - - - // 14. Test network connectivity and writing data to SRAM. + // 13. Test network connectivity and writing data to SRAM. do { *KINETOSCOPE_PORT_ERROR = 0; *KINETOSCOPE_PORT_COMMAND = CMD_CONNECT_NET; @@ -347,7 +301,38 @@ int main(bool hardReset) { VDP_setTextPalette(PAL_WHITE); VDP_drawText("Catalog header validated.", 1, line++); } + } while (false); + + + // 14. Count the size of the catalog. + const SegaVideoHeader* header = (const SegaVideoHeader*)KINETOSCOPE_DATA; + int num_videos = 0; + while (header->magic[0]) { + num_videos++; + header++; + + if (num_videos > MAX_CATALOG_SIZE) { + VDP_clearTextArea(0, line, 32, 1); + VDP_setTextPalette(PAL_YELLOW); + VDP_drawText("Video catalog overflow!", 1, line++); + break; + } + VDP_clearTextArea(0, line, 32, 1); + VDP_setTextPalette(PAL_WHITE); + VDP_drawText(header->title, 0, line); + } + char catalog_count_buf[32]; + // 0 1 2 3 + // 0123456789012345678901234567890 + // 12345678901 + sprintf(catalog_count_buf, "Catalog size: %d", num_videos); + VDP_setTextPalette(PAL_WHITE); + VDP_drawText(catalog_count_buf, 0, line++); + + + // 15. Attempt to start streaming a video. + do { *KINETOSCOPE_PORT_COMMAND = CMD_START_VIDEO; *KINETOSCOPE_PORT_ARG = 0; *KINETOSCOPE_PORT_TOKEN = 1; @@ -371,6 +356,58 @@ int main(bool hardReset) { } } while (false); + + // 16. Perform various intensive memory tests through the firmware. + // There are many different passes of this, with different patterns to verify. + line++; // blank line + int memory_test_pass_line = line; + line += 2; + int memory_test_error_line = line; + line += 2; + + VDP_setTextPalette(PAL_WHITE); + // 0 1 + // 012345678901234567 + VDP_drawText("SRAM test pass 00", 0, memory_test_pass_line); + VDP_drawText("......................", 1, memory_test_pass_line + 1); + + for (int pass = 0; pass < SRAM_MARCH_TEST_NUM_PASSES; ++pass) { + waitMs(1); + *KINETOSCOPE_PORT_COMMAND = CMD_MARCH_TEST; + *KINETOSCOPE_PORT_ARG = pass; + waitMs(1); + *KINETOSCOPE_PORT_TOKEN = 1; + + VDP_setTextPalette(PAL_WHITE); + char counter[3] = { + '0' + ((pass / 10) % 10), + '0' + (pass % 10), + '\0', + }; + VDP_drawText(counter, 15, memory_test_pass_line); + // "!": indicates that the uC is filling the SRAM with data. + VDP_drawText("!", pass + 1, memory_test_pass_line + 1); + + if (!waitForToken(/* timeout_seconds= */ 30)) { + VDP_setTextPalette(PAL_YELLOW); + VDP_drawText("SRAM test command timed out.", 1, line++); + break; + } + // "?": indicates that the Sega is reading the SRAM. + VDP_drawText("?", pass + 1, memory_test_pass_line + 1); + + bool ok = sram_march_test(pass); + VDP_setTextPalette(ok ? PAL_WHITE : PAL_YELLOW); + VDP_drawText(ok ? "P" : "F", pass + 1, memory_test_pass_line + 1); + if (!ok) { + VDP_drawText(march_error_1, 0, memory_test_error_line); + VDP_drawText(march_error_2, 0, memory_test_error_line + 1); + waitMs(10 * 1000); + } + } + + + // 16. Done! line++; // blank line VDP_drawText("Testing complete!", 0, line++); while (true) {