diff options
| author | cheapie <no-email-for-you@example.com> | 2026-05-23 20:14:34 -0500 |
|---|---|---|
| committer | cheapie <no-email-for-you@example.com> | 2026-05-23 20:14:34 -0500 |
| commit | 85b5fde272be6ab543aa866baebabddc24566bdb (patch) | |
| tree | b4f2e3bb634effe51c2bdc5585ca4ea8b98d6dfa /c/menu/screensaver.c | |
| download | rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar.gz rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar.bz2 rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.tar.xz rvcontroller-85b5fde272be6ab543aa866baebabddc24566bdb.zip | |
Add initial content
Diffstat (limited to 'c/menu/screensaver.c')
| -rw-r--r-- | c/menu/screensaver.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/c/menu/screensaver.c b/c/menu/screensaver.c new file mode 100644 index 0000000..70e1647 --- /dev/null +++ b/c/menu/screensaver.c @@ -0,0 +1,137 @@ +/* Menu Thing for RVController - Screensaver + * A product of Advanced Mesecons Devices, a Cheapie Systems company + * This is free and unencumbered software released into the public domain. + * See http://unlicense.org/ for more information */ + +#include <stdbool.h> +#include <stdint.h> +#include "rvcontroller-ecalls.h" + +char screensaverbuf[] = "\n \n \n \n \n \n "; + +int strlen(char *string) { + int i; + for (i = 0;string[i] != 0;i++) {} + return i; +} + +void screensaverWriteText(char *text, int column, int row, bool erase) { + int textlen = strlen(text); + if (column < 0) { + // Cut the left side off of the text and change the start position to the left side of the screen + text = text + (0 - column); + textlen = textlen + column; + column = 0; + } else if (column + textlen > 19) { + // Cut the right side off of the text + textlen = 20 - column; + } + for (int i=0;i < textlen;i++) { + if (erase) { + screensaverbuf[(row*21)+column+i+1] = 0x20; + } else { + screensaverbuf[(row*21)+column+i+1] = text[i]; + } + } +} + +void doMarquee(void) { + char text[] = "RVController "; + int col = 19; + int row = randomint(0,5); + console_clearbuffer(); + while (console_readchar() == 0) { + col--; + if (col < (0 - strlen(text))) { + col = 20; + row = randomint(0,5); + } + screensaverWriteText(text,col,row,false); + printstr(screensaverbuf); + } + screensaverWriteText(text,col,row,true); +} + +void doBouncingText(void) { + char text[] = "RVController"; + int col = 0; + int row = 0; + int xdir = 1; + int ydir = 1; + console_clearbuffer(); + while (console_readchar() == 0) { + screensaverWriteText(text,col,row,true); + col = col + xdir; + row = row + ydir; + if (col <= 0) { xdir = 1; } + if (col >= (19 - strlen(text))) { xdir = -1; } + if (row <= 0) { ydir = 1; } + if (row >= 5) { ydir = -1; } + screensaverWriteText(text,col,row,false); + printstr(screensaverbuf); + } + screensaverWriteText(text,col,row,true); +} + +void doMatrix(void) { + int row[] = {-8,-4,-1,-5,-2}; // "Random" positions off the top of the screen to give "random" start delays + int col[] = {1,18,2,12,9}; + int len[] = {3,4,5,6,7}; + char textscratch[] = " "; + console_clearbuffer(); + while (console_readchar() == 0) { + for (int i=0;i<=4;i++) { + row[i]++; + textscratch[0] = randomint(0x21,0x7a); + if (row[i] <= 5 && row[i] >= 0) { + screensaverWriteText(textscratch,col[i],row[i],false); + } + if ((row[i] - len[i]) <= 5 && (row[i] - len[i]) >= 0) { + screensaverWriteText(textscratch,col[i],(row[i] - len[i]),true); + } else if ((row[i] - len[i]) > 5 && randomint(0,1) == 1) { + row[i] = 0 - randomint(1,3); + col[i] = randomint(0,19); + len[i] = randomint(2,8); + } + } + printstr(screensaverbuf); + } + for (int i=0;i <= 5;i++) { + screensaverWriteText(" ",0,i,true); + } +} + +void runScreensaver(void) { + char inputbuf[9]; + bool quit = false; + while (!quit) { + printstr("\n\n\n\n\n\n\n"); + printstr("SCREENSAVER\n"); + printstr("1: Marquee\n"); + printstr("2: Bouncing Text\n"); + printstr("3: Matrix\n"); + printstr("\n"); + printstr("0: Exit"); + readstr(inputbuf,2); + switch (inputbuf[0]) { + case '0': + quit = true; + break; + case '1': + doMarquee(); + quit = true; + break; + case '2': + doBouncingText(); + quit = true; + break; + case '3': + doMatrix(); + quit = true; + break; + default: + printstr("\nInvalid option\n\nPress any key\n\n\n"); + readstr(inputbuf,1); + } + } +} |
