From 85b5fde272be6ab543aa866baebabddc24566bdb Mon Sep 17 00:00:00 2001 From: cheapie Date: Sat, 23 May 2026 20:14:34 -0500 Subject: Add initial content --- c/menu/calculator.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 c/menu/calculator.c (limited to 'c/menu/calculator.c') diff --git a/c/menu/calculator.c b/c/menu/calculator.c new file mode 100644 index 0000000..ff26f07 --- /dev/null +++ b/c/menu/calculator.c @@ -0,0 +1,95 @@ +/* Menu Thing for RVController - Calculator + * 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 +#include +#include "rvcontroller-ecalls.h" + +void runCalculator(void) { + char input[2] = {0}; + int32_t num1 = 0; + int32_t num2 = 0; + int32_t result = 0; + + printstr("\n\n\n\n\n\n"); + printstr("Enter number 1:\n> "); + num1 = readint(); + printint(num1); + printstr("\nEnter number 2:\n> "); + num2 = readint(); + printint(num2); + + bool opok = false; + while (!opok) { + printstr("\nSelect operation:\n[+-*/%&|^<<>>] > "); + readstr(input,2); + printstr(input); + + switch (input[0]) { + case '<': + case '>': + // Duplicate the character for these two to give the illusion that I bothered to store both + // Then fall through + printstr(input); + case '+': + case '-': + case '*': + case '/': + case '%': + case '&': + case '|': + case '^': + printchar('\n'); + opok = true; + break; + default: + printstr("\nInvalid operation\n"); + } + } + + switch (input[0]) { + case '+': + printint(num1+num2); + break; + case '-': + printint(num1-num2); + break; + case '*': + printint(num1*num2); + break; + case '/': + printint(num1/num2); + break; + case '%': + printint(num1%num2); + break; + case '&': + printint(num1&num2); + break; + case '|': + printint(num1|num2); + break; + case '^': + printint(num1^num2); + break; + case '<': + if (num2 < 0 || num2 > 31) { + printstr("Nice try."); + } else { + printint(num1<' : + if (num2 < 0 || num2 > 31) { + printstr("Nice try."); + } else { + printint(num1>>num2); + } + break; + } + + printstr("\nPress any key"); + readstr(input,1); +} -- cgit v1.2.3