aboutsummaryrefslogtreecommitdiffstats
path: root/c/libc.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-18 00:38:38 +0200
committeruser <user@clank>2026-07-18 00:38:38 +0200
commitba2d7ae1d7b319645b10aaa31a7f664f9f80c25c (patch)
treee01e6c7c710a661defe2515ff9657f08cddcb283 /c/libc.c
parenttools: gbtype prints hub errors to stderr and exits 1 (diff)
downloadgbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.tar.gz
gbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.tar.xz
gbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.zip
refactor: c/ -> usr/, compiled program blobs out of the source tree
Userland sources live in usr/ (fits the Unix theme better than 'c'). SDCC output .bin blobs land in build/usr/ with the other build artifacts instead of littering the source dir; programs.asm INCBINs them from there. Byte-identical ROM.
Diffstat (limited to 'c/libc.c')
-rw-r--r--c/libc.c67
1 files changed, 0 insertions, 67 deletions
diff --git a/c/libc.c b/c/libc.c
deleted file mode 100644
index a48a64c..0000000
--- a/c/libc.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* gbos libc C helpers (compiled once, linked into every program). */
-#include "gbos.h"
-
-/* sleep for approximately 'ms' milliseconds (cooperative; other procs run).
- The kernel counts in 1/64-second units (~15.6 ms), so we round ms to that. */
-void msleep(unsigned int ms) {
- unsigned int u = ms >> 4; /* ~ms/15.6, close enough for a delay */
- if (u > 255) u = 255;
- if (u == 0 && ms) u = 1;
- gsleep((unsigned char)u);
-}
-
-/* print an unsigned int in decimal */
-void putu(unsigned int n) {
- char buf[5];
- unsigned char i = 0;
- if (n == 0) { putc('0'); return; }
- while (n) { buf[i++] = '0' + (n % 10); n = n / 10; }
- while (i) putc(buf[--i]);
-}
-
-/* parse a decimal number (stops at the first non-digit) */
-unsigned char atou(const char *s) {
- unsigned char n = 0;
- while (*s >= '0' && *s <= '9') { n = n * 10 + (*s - '0'); s++; }
- return n;
-}
-
-/* tokenize the argument string in place into argv[]; returns argc.
- (replaces the spaces in the arg string with NULs) */
-unsigned char argv_parse(char **argv, unsigned char maxv) {
- char *p = getargs();
- unsigned char argc = 0;
- for (;;) {
- while (*p == ' ') p++;
- if (*p == 0) break;
- if (argc < maxv) argv[argc] = p;
- argc++;
- while (*p != 0 && *p != ' ') p++;
- if (*p == ' ') *p++ = 0;
- }
- return argc;
-}
-
-/* return nonzero if single-char flag `f` appears (as -f or within -abc) */
-unsigned char hasflag(char **argv, unsigned char argc, char f) {
- unsigned char i, j;
- for (i = 0; i < argc; i++) {
- if (argv[i][0] != '-') continue;
- for (j = 1; argv[i][j]; j++)
- if (argv[i][j] == f) return 1;
- }
- return 0;
-}
-
-/* return the value for option -<opt> ("-n 5" or "-n5"), or 0 if absent */
-char *optval(char **argv, unsigned char argc, char opt) {
- unsigned char i;
- for (i = 0; i < argc; i++) {
- if (argv[i][0] == '-' && argv[i][1] == opt) {
- if (argv[i][2]) return &argv[i][2];
- if (i + 1 < argc) return argv[i+1];
- return 0;
- }
- }
- return 0;
-}