From cf2e6bf382af67d8b0261af326926894bf59d849 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 6 Oct 2025 19:18:30 -0500 Subject: [PATCH] cmd screen --- src/console/cmd/cmdscreen.h | 78 +++++++++++++++++++++++++++++++++++++ src/util/string.c | 14 +++++++ src/util/string.h | 9 +++++ 3 files changed, 101 insertions(+) diff --git a/src/console/cmd/cmdscreen.h b/src/console/cmd/cmdscreen.h index de2a173..1216533 100644 --- a/src/console/cmd/cmdscreen.h +++ b/src/console/cmd/cmdscreen.h @@ -8,6 +8,7 @@ #pragma once #include "console/console.h" #include "display/screen.h" +#include "util/string.h" void cmdScreen(const consolecmdexec_t *exec) { if(exec->argc < 1) { @@ -19,4 +20,81 @@ void cmdScreen(const consolecmdexec_t *exec) { SCREEN.mode = SCREEN_MODE_BACKBUFFER; return; } + + #if DISPLAY_SIZE_DYNAMIC == 1 + if(strcmp(exec->argv[0], "fixed") == 0) { + if(exec->argc < 3) { + consolePrint("Expected 3 arguments: fixed "); + return; + } + + int32_t w, h; + if(!stringToI32(exec->argv[1], &w) || w <= 0) { + consolePrint("Invalid width: %s", exec->argv[1]); + return; + } + if(!stringToI32(exec->argv[2], &h) || h <= 0) { + consolePrint("Invalid height: %s", exec->argv[2]); + return; + } + + SCREEN.mode = SCREEN_MODE_FIXED_SIZE; + SCREEN.fixedSize.width = w; + SCREEN.fixedSize.height = h; + return; + } + + if(strcmp(exec->argv[0], "aspect") == 0) { + if(exec->argc < 2) { + consolePrint("Expected 2 arguments: aspect "); + return; + } + + float_t r; + if(!stringToF32(exec->argv[1], &r) || r <= 0) { + consolePrint("Invalid aspect ratio: %s", exec->argv[1]); + return; + } + + SCREEN.mode = SCREEN_MODE_ASPECT_RATIO; + SCREEN.aspectRatio.ratio = r; + return; + } + + if(strcmp(exec->argv[0], "height") == 0) { + if(exec->argc < 2) { + consolePrint("Expected 2 arguments: height "); + return; + } + + int32_t h; + if(!stringToI32(exec->argv[1], &h) || h <= 0) { + consolePrint("Invalid height: %s", exec->argv[1]); + return; + } + + SCREEN.mode = SCREEN_MODE_FIXED_HEIGHT; + SCREEN.fixedHeight.height = h; + return; + } + + if(strcmp(exec->argv[0], "width") == 0) { + if(exec->argc < 2) { + consolePrint("Expected 2 arguments: width "); + return; + } + + int32_t w; + if(!stringToI32(exec->argv[1], &w) || w <= 0) { + consolePrint("Invalid width: %s", exec->argv[1]); + return; + } + + SCREEN.mode = SCREEN_MODE_FIXED_WIDTH; + SCREEN.fixedWidth.width = w; + return; + } + #endif + + consolePrint("Unknown mode: %s", exec->argv[0]); } \ No newline at end of file diff --git a/src/util/string.c b/src/util/string.c index e250911..76be012 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -133,6 +133,20 @@ bool_t stringToU16(const char_t *str, uint16_t *out) { return true; } +bool_t stringToF32(const char_t *str, float_t *out) { + assertNotNull(str, "str must not be NULL"); + assertNotNull(out, "out must not be NULL"); + + char_t *endptr; + errno = 0; + float_t result = strtof(str, &endptr); + if (errno != 0 || *endptr != '\0') { + return false; + } + *out = result; + return true; +} + bool_t stringEndsWith(const char_t *str, const char_t *suffix) { assertNotNull(str, "str must not be NULL"); assertNotNull(suffix, "suffix must not be NULL"); diff --git a/src/util/string.h b/src/util/string.h index 25a369c..189e5a6 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -127,6 +127,15 @@ bool_t stringToI16(const char_t *str, int16_t *out); */ bool_t stringToU16(const char_t *str, uint16_t *out); +/** + * Converts a string to a float. + * + * @param str The string to convert. + * @param out The output float. + * @return TRUE if the conversion was successful, FALSE otherwise. + */ +bool_t stringToF32(const char_t *str, float_t *out); + /** * Determines if a string ends with a specified suffix. *