From c754be2c9d2049c5636b84860b8eb94727adbd63 Mon Sep 17 00:00:00 2001 From: That-One-Nerd Date: Wed, 25 Jun 2025 13:36:12 -0400 Subject: [PATCH] Incomplete list drawing code. More to come. --- .vscode/c_cpp_properties.json | 22 ++++++++++++ .vscode/settings.json | 6 ++++ src/main.c | 19 ----------- src/main.cpp | 63 +++++++++++++++++++++++++++++++++++ src/main.h | 20 +++++++++++ 5 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json delete mode 100644 src/main.c create mode 100644 src/main.cpp create mode 100644 src/main.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..49f7e81 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,22 @@ +{ + "configurations": [ + { + "name": "CEdev", + "includePath": [ + "${workspaceFolder}/**", + "C:/Users/kyley/Desktop/Coding/Lib/CEdev/include/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.26100.0", + "compilerPath": "C:\\Users\\kyley\\Desktop\\Coding\\Lib\\CEdev\\bin\\ez80-clang.exe", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "linux-clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4b61741 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "screen.h": "c", + "getcsc.h": "c" + } +} \ No newline at end of file diff --git a/src/main.c b/src/main.c deleted file mode 100644 index e7d2a5c..0000000 --- a/src/main.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include - -/* Main function, called first */ -int main(void) -{ - /* Clear the homescreen */ - os_ClrHome(); - - /* Print a string */ - os_PutStrFull("Hello, World."); - - /* Waits for a key */ - while (!os_GetCSC()); - - /* Return 0 for success */ - return 0; -} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..886a044 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include "main.h" + +void demo_func() +{ + os_PutStrLine("and this is the demo func!\n"); +} + +list_item modes[] = { + { "Option 1", demo_func }, + { "Option 2", nullptr }, + { "Option 3", nullptr }, + { "Option 4", nullptr }, + { "Option 5", nullptr }, + { "Option 6", nullptr }, + { "Option 7", nullptr }, + { "Option 8", nullptr }, + { "Option 9", nullptr }, + { "Option 10", demo_func }, + { nullptr, nullptr } +}; + +/* Main function, called first */ +int main(void) +{ + /* Clear the homescreen */ + os_ClrHome(); + + list_config config; + config.start_row = 1; + config.end_row = 5; + display_list(modes, config); + + /* Waits for a key */ + while (!os_GetCSC()); + + /* Return 0 for success */ + return 0; +} + +int display_list(const list_item* list, const list_config& config) +{ + size_t item_count = 0; + for (size_t i = 0; true; i++) + { + const list_item& item = list[i]; + if (item.display_name == nullptr) break; + item_count++; + } + if (item_count == 0) return -1; // No list to display. + + uint8_t max_on_screen = MIN(config.end_row - config.start_row, 10 - config.start_row) + 1; + uint24_t offset = 0; + for (size_t i = 0, j = offset; i < max_on_screen && j < item_count; i++, j++) + { + os_SetCursorPos(config.start_row + i, 0); + os_PutStrLine(list[j].display_name); + } + + return -1; +} diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..496665b --- /dev/null +++ b/src/main.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#define MAX(a, b) (a > b ? a : b) +#define MIN(a, b) (a < b ? a : b) + +typedef struct +{ + const char* display_name; + void (*select_func)(); +} list_item; + +typedef struct +{ + uint8_t start_row; + uint8_t end_row; +} list_config; + +int display_list(const list_item* list, const list_config& config);