Created
May 15, 2026 03:00
-
-
Save cheapie/e294ec047f481ac1a7911a8a8d6f294b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Drawer Capacity Calculator for RVController | |
| * 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 <stdint.h> | |
| #include <stdbool.h> | |
| #include "rvcontroller-ecalls.h" | |
| #define BASE_SLOTS 32 | |
| #define STACK_MAX 99 | |
| #define STEEL_UPGRADE_MULT 1 | |
| #define GOLD_UPGRADE_MULT 2 | |
| #define OBSIDIAN_UPGRADE_MULT 3 | |
| #define DIAMOND_UPGRADE_MULT 7 | |
| #define MITHRIL_UPGRADE_MULT 12 | |
| bool checkUpgradeCount(int32_t count,int32_t maxcount) { | |
| return (count >= 0 && count <= maxcount); | |
| } | |
| void main(void) { | |
| while (true) { | |
| int32_t capacity = BASE_SLOTS * STACK_MAX; | |
| uint8_t upgrades_used = 0; | |
| printstr("\n\n\nSettings:\n"); | |
| printstr("Base Stack Count: "); | |
| printint(BASE_SLOTS); | |
| printstr("\nMax Stack Size: "); | |
| printint(STACK_MAX); | |
| printchar('\n'); | |
| int32_t upgcount = 0; | |
| while (true) { | |
| printstr("\nSteel Upgrades?\n[0-5] > "); | |
| upgcount = readint(); | |
| printint(upgcount); | |
| printchar('\n'); | |
| if (checkUpgradeCount(upgcount,5)) { | |
| break; | |
| } else { | |
| printstr("Invalid entry"); | |
| } | |
| } | |
| upgrades_used += upgcount; | |
| capacity += BASE_SLOTS * STACK_MAX * STEEL_UPGRADE_MULT * upgcount; | |
| if (upgrades_used < 5) { | |
| while (true) { | |
| printstr("\nGold Upgrades?\n[0-"); | |
| printint(5-upgrades_used); | |
| printstr("] > "); | |
| upgcount = readint(); | |
| printint(upgcount); | |
| printchar('\n'); | |
| if (checkUpgradeCount(upgcount,5-upgrades_used)) { | |
| break; | |
| } else { | |
| printstr("Invalid entry"); | |
| } | |
| } | |
| upgrades_used += upgcount; | |
| capacity += BASE_SLOTS * STACK_MAX * GOLD_UPGRADE_MULT * upgcount; | |
| } | |
| if (upgrades_used < 5) { | |
| while (true) { | |
| printstr("\nObsidian Upgrades?\n[0-"); | |
| printint(5-upgrades_used); | |
| printstr("] > "); | |
| upgcount = readint(); | |
| printint(upgcount); | |
| printchar('\n'); | |
| if (checkUpgradeCount(upgcount,5-upgrades_used)) { | |
| break; | |
| } else { | |
| printstr("Invalid entry"); | |
| } | |
| } | |
| upgrades_used += upgcount; | |
| capacity += BASE_SLOTS * STACK_MAX * OBSIDIAN_UPGRADE_MULT * upgcount; | |
| } | |
| if (upgrades_used < 5) { | |
| while (true) { | |
| printstr("\nDiamond Upgrades?\n[0-"); | |
| printint(5-upgrades_used); | |
| printstr("] > "); | |
| upgcount = readint(); | |
| printint(upgcount); | |
| printchar('\n'); | |
| if (checkUpgradeCount(upgcount,5-upgrades_used)) { | |
| break; | |
| } else { | |
| printstr("Invalid entry"); | |
| } | |
| } | |
| upgrades_used += upgcount; | |
| capacity += BASE_SLOTS * STACK_MAX * DIAMOND_UPGRADE_MULT * upgcount; | |
| } | |
| if (upgrades_used < 5) { | |
| while (true) { | |
| printstr("\nMithril Upgrades?\n[0-"); | |
| printint(5-upgrades_used); | |
| printstr("] > "); | |
| upgcount = readint(); | |
| printint(upgcount); | |
| printchar('\n'); | |
| if (checkUpgradeCount(upgcount,5-upgrades_used)) { | |
| break; | |
| } else { | |
| printstr("Invalid entry"); | |
| } | |
| } | |
| upgrades_used += upgcount; | |
| capacity += BASE_SLOTS * STACK_MAX * MITHRIL_UPGRADE_MULT * upgcount; | |
| } | |
| printstr("\n1 slot: "); | |
| printint(capacity); | |
| printstr("\n2 slots: "); | |
| printint(capacity/2); | |
| printstr("\n4 slots: "); | |
| printint(capacity/4); | |
| printstr("\nPress 0 to run again\n"); | |
| upgcount = readint(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* RVController ecall C Library - C Header Portion | |
| * 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 */ | |
| #ifndef _STDINT_H | |
| #include <stdint.h> | |
| #endif | |
| /* printint(number) | |
| * | |
| * Prints a 32-bit signed integer to standard output. | |
| * number: The number to print */ | |
| void printint(int32_t number); | |
| /* printstr(*str) | |
| * | |
| * Prints a null-terminated ASCII string to standard output. | |
| * *str: Pointer to the start of the string data */ | |
| void printstr(char *str); | |
| /* printchar(c) | |
| * | |
| * Prints a single ASCII character to standard output. | |
| * c: The character to print */ | |
| void printchar(char c); | |
| /* digiline_send(*channel,*msg) | |
| * | |
| * Sends an arbitrary digilines message on an arbitrary channel. | |
| * *channel: Pointer to the start of the null-terminated channel string | |
| * *msg: Pointer to the start of the null-terminated message string */ | |
| void digiline_send(char *channel, char *msg); | |
| /* digiline_bufferlevel() | |
| * | |
| * Reads the current number of digilines messages that have been received | |
| * but not yet read. | |
| * Returns: Number of messages */ | |
| uint8_t digiline_bufferlevel(void); | |
| /* digiline_receive(*channelbuf,channelbuflen,*msgbuf,msgbuflen) | |
| * | |
| * Reads the first (oldest) digilines message from the receive queue and removes | |
| * the message from the queue. | |
| * Null termination will be added to all received strings. | |
| * *channelbuf: Pointer to the location of a buffer into which the channel will be placed | |
| * channelbuflen: The size of the buffer pointed to by channelbuf | |
| * *msgbuf: Pointer to the location of a buffer into which the message will be placed | |
| * msgbuflen: The size of the buffer pointed to by channelbuf */ | |
| void digiline_receive(char *channelbuf, int channelbuflen, char *msgbuf, int msgbuflen); | |
| /* rdcycle() | |
| * | |
| * Reads the number of clock cycles that have passed since the processor was started. | |
| * Returns: Number of clock cycles */ | |
| uint32_t rdcycle(void); | |
| /* rdtime() | |
| * | |
| * Reads the number of seconds that have elapsed since the processor was started. | |
| * Returns: Number of seconds */ | |
| uint32_t rdtime(void); | |
| /* digiline_clearbuffer() | |
| * | |
| * Discards all received digilines messages currently waiting in the queue. */ | |
| void digiline_clearbuffer(void); | |
| /* lightweight_mode(enabled) | |
| * | |
| * Turns lightweight mode (see RVController documentation) or or off. | |
| * enabled: 1 to enable, 0 to disable, other values are reserved */ | |
| void lightweight_mode(char enabled); | |
| /* readint() | |
| * | |
| * Reads a 32-bit signed integer from the console. | |
| * This will block until the user enters a valid number. | |
| * returns: The number typed by the user */ | |
| int32_t readint(void); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #RVController ecall C Library - Assembly Portion | |
| #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 | |
| printint: | |
| # Number to print is already in a0 | |
| li a7,1 # Write number | |
| ecall | |
| ret | |
| printstr: | |
| # String address is already in a0 | |
| li a7,4 | |
| ecall | |
| ret | |
| printchar: | |
| # Character is already in a0 | |
| li a7,11 | |
| ecall | |
| ret | |
| digiline_send: | |
| # Channel pointer is already in a0, message pointer is already in a1 | |
| li a7,129 | |
| ecall | |
| ret | |
| digiline_bufferlevel: | |
| li a7,133 | |
| ecall | |
| # Result is already in a0 | |
| ret | |
| digiline_receive: | |
| # Arguments are already in a0-a3 | |
| li a7,135 | |
| ecall | |
| ret | |
| rdtime: | |
| rdtime a0 | |
| ret | |
| rdcycle: | |
| rdcycle a0 | |
| ret | |
| digiline_clearbuffer: | |
| li a7,134 | |
| ecall | |
| ret | |
| lightweight_mode: | |
| andi a0,a0,1 | |
| csrrs t0,0x800,x0 | |
| bclri t0,t0,0 | |
| or t0,t0,a0 | |
| csrrw x0,0x800,t0 | |
| ret | |
| readint: | |
| li a7,5 | |
| ecall | |
| # Result is already in a0 | |
| ret | |
| .globl printint | |
| .globl printstr | |
| .globl printchar | |
| .globl digiline_send | |
| .globl digiline_bufferlevel | |
| .globl digiline_receive | |
| .globl rdtime | |
| .globl rdcycle | |
| .globl digiline_clearbuffer | |
| .globl lightweight_mode | |
| .globl readint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Assembly stub for C programs targeting RVController | |
| #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 | |
| #This file should always be linked first. | |
| #RVController has a default reset vector of 0, | |
| #therefore _start should end up as the first thing in the file. | |
| .section .text.startup | |
| _start: | |
| # Set up stack pointer | |
| li sp,0x10000 | |
| # Call main function | |
| call main | |
| # Exit program | |
| li a7,10 | |
| ecall | |
| # Shouldn't ever get here, will crash if it does | |
| ret | |
| .globl _start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment