From d9468f2efda16ca5b75c61e219313a1e17a81f49 Mon Sep 17 00:00:00 2001 From: zongor Date: Sun, 21 Dec 2025 16:37:20 -0800 Subject: [PATCH] update docs, setup minimal builds for web gui/tui + linux gui/tui --- .gitignore | 2 + README.org | 19 ++- ROADMAP.org | 38 +++++ SPECIFICATION.org | 44 +++++ arch/linux/gui/main.c | 20 +++ arch/linux/tui/main.c | 13 ++ arch/web/gui/main.c | 33 ++++ arch/web/gui/shell_minimal.html | 288 ++++++++++++++++++++++++++++++++ arch/web/main.c | 0 arch/web/tui/main.c | 23 +++ arch/web/tui/shell_minimal.html | 288 ++++++++++++++++++++++++++++++++ build | 116 +++++++++++++ vm.c | 0 libc.c => vm/libc.c | 0 libc.h => vm/libc.h | 0 vm/vm.c | 6 + vm.h => vm/vm.h | 10 +- 17 files changed, 892 insertions(+), 8 deletions(-) create mode 100644 arch/web/gui/main.c create mode 100644 arch/web/gui/shell_minimal.html delete mode 100644 arch/web/main.c create mode 100644 arch/web/tui/main.c create mode 100644 arch/web/tui/shell_minimal.html mode change 100644 => 100755 build delete mode 100644 vm.c rename libc.c => vm/libc.c (100%) rename libc.h => vm/libc.h (100%) create mode 100644 vm/vm.c rename vm.h => vm/vm.h (61%) diff --git a/.gitignore b/.gitignore index 890881b..a21312c 100644 --- a/.gitignore +++ b/.gitignore @@ -103,3 +103,5 @@ Module.symvers Mkfile.old dkms.conf +# project specific +out/ \ No newline at end of file diff --git a/README.org b/README.org index 72ee99c..5b72e8b 100644 --- a/README.org +++ b/README.org @@ -11,7 +11,8 @@ Undâr conforms to permacomputing principles. -Permacomputing as defined by the [[https://wiki.xxiivv.com/site/permacomputing.html][xxiivv wiki]]: "permacomputing encourages the maximization of hardware lifespan, minimization of energy usage and focuses on the use of already available computational resources. +Permacomputing as defined by the [[https://wiki.xxiivv.com/site/permacomputing.html][xxiivv wiki]]: +"permacomputing encourages the maximization of hardware lifespan, minimization of energy usage and focuses on the use of already available computational resources. it values maintenance and refactoring of systems to keep them efficient, instead of planned obsolescence, permacomputing practices planned longevity. it is about using computation only when it has a strengthening effect on ecosystems." @@ -27,9 +28,19 @@ Undâr is intended to run on anything with a C compiler. From constrained system * Getting Started -** +** Requirements +*** Main +- Git +- C compiler +*** Optional +- SDL2 + - For GUI linux and web versions +- Emscripten + - For web version -** Build (linux version) +** Build + +Note: the linux version is the default (for now) #+BEGIN_SRC sh git clone https://git.alfrescocavern.com/zongor/undar-lang.git @@ -46,7 +57,7 @@ cd undar-lang && ./build * Inspirations -- [[https://plan9.io/][Plan 9]] : 9P, Unified I/O, Tunnels. +- [[https://man.9front.org/][Plan 9]] : 9P, Unified I/O, Tunnels. - [[https://en.wikipedia.org/wiki/Lisp_(programming_language)][Lisp]] : REPL, introspection. - [[https://fortran-lang.org/][Fortran]] : Array semantics. - [[https://en.wikipedia.org/wiki/C_(programming_language)][C]] / [[https://ziglang.org/][Zig]] : Efficentcy, simplicity. diff --git a/ROADMAP.org b/ROADMAP.org index c0e4a7a..34e6639 100644 --- a/ROADMAP.org +++ b/ROADMAP.org @@ -1,2 +1,40 @@ #+TITLE Project Roadmap +** Features +- [ ] Primitive Types +- [ ] Q16.16 fixed point real numbers +- [ ] Arithmetic Opcodes +- [ ] Assembler +- [ ] Device Tunnels + - [ ] Terminal + - [ ] Display + - [ ] Mouse + - [ ] Keyboard + - [ ] File + - [ ] Network + - [ ] Sound + - [ ] Gamepad + - [ ] Joystick +- [ ] Compiler +- [ ] Arrays +- [ ] Plexes +- [ ] Fonts +- [ ] Actor system +- [ ] Localization + +** Standard Library +- [ ] Graphics + - [ ] 2D immediate mode UI + - [ ] 3D graphics +- [ ] Physics + - [ ] 3D collisions +- [ ] Trigonometry +- [ ] Unit of measure + +** Projects +- [ ] Paint +- [ ] 3D Platformer POC +- [ ] Multiplayer 3D MMO POC +- [ ] Code Editor +- [ ] Self hosted assembler +- [ ] Self hosted compiler diff --git a/SPECIFICATION.org b/SPECIFICATION.org index 066983d..04577be 100644 --- a/SPECIFICATION.org +++ b/SPECIFICATION.org @@ -1 +1,45 @@ #+TITLE Project Specification + +* Binary interface + +The VM does not use floating point numbers, it instead uses fixed point numbers. + +This is for portability reasons as some devices might not have a FPU in them + +especially microcontrollers and some retro game systems like the PS1. + +** Numbers +| type | size (bytes) | description | +|------+--------------+---------------------------------------| +| u8 | 1 | unsigned 8bit, alias =char= and =byte= | +| bool | 1 | unsigned 8bit, =false= or =true= | +| i8 | 1 | signed 8bit for interop | +| u16 | 2 | unsigned 16bit for interop | +| i16 | 2 | signed 16bit for interop | +| u32 | 4 | unsigned 32bit, alias =nat= | +| i32 | 4 | signed 32bit, alias =int= | +| f32 | 4 | signed 32bit fixed number, alias =real= | + +* Memory + +Uses a harvard style archecture, meaning the code and ram memory +are split up into two seperate blocks. + +In the C version you can see these are two seperate arrays 'code' and 'mem'. + +During compilation constants and local variables are put onto 'mem' + +* Opcodes + +Most opcodes are 4 bytes + +[opcode][dest][src1][src2] + +A small number are multibyte like load-long-immidiate + +[multibyte-opcode][0u8][0u8][opcode] . [u32] + +These are decoded during runtime and selected. + +In theory, bitshift decoding is faster than +accessing an unknown n bytes of memory in the 'code' array. diff --git a/arch/linux/gui/main.c b/arch/linux/gui/main.c index e69de29..ff88bd1 100644 --- a/arch/linux/gui/main.c +++ b/arch/linux/gui/main.c @@ -0,0 +1,20 @@ +#include "../../../vm/vm.h" +#include +#include + +int main() { + VM vm = {0}; + + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + printf("SDL initialization failed: %s\n", SDL_GetError()); + return 1; + } + SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0"); + + while(step_vm(&vm)) { + // do stuff + } + + printf("done\n"); + return 0; +} diff --git a/arch/linux/tui/main.c b/arch/linux/tui/main.c index e69de29..85fd125 100644 --- a/arch/linux/tui/main.c +++ b/arch/linux/tui/main.c @@ -0,0 +1,13 @@ +#include "../../../vm/vm.h" +#include + +int main() { + VM vm = {0}; + + while(step_vm(&vm)) { + // do stuff + } + + printf("done\n"); + return 0; +} diff --git a/arch/web/gui/main.c b/arch/web/gui/main.c new file mode 100644 index 0000000..1113027 --- /dev/null +++ b/arch/web/gui/main.c @@ -0,0 +1,33 @@ +#include + +#include "../../../vm/vm.h" +#undef true +#undef false + +#include +#include +#include + +VM vm = {0}; + +void mainloop() { + if (!step_vm(&vm)) { + emscripten_cancel_main_loop(); + return; + } +} + +int main() { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + printf("SDL initialization failed: %s\n", SDL_GetError()); + return 1; + } + SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0"); + + emscripten_set_canvas_element_size("#canvas", 640, 480); + + printf("VM loaded successfully\n"); + + emscripten_set_main_loop(mainloop, 0, 1); + return 0; +} diff --git a/arch/web/gui/shell_minimal.html b/arch/web/gui/shell_minimal.html new file mode 100644 index 0000000..8a8c6db --- /dev/null +++ b/arch/web/gui/shell_minimal.html @@ -0,0 +1,288 @@ + + + + + + Emscripten-Generated Code + + + +
+
emscripten
+
Downloading...
+
+ +
+
+ +
+
+
+ Resize canvas + Lock/hide mouse pointer +     + +
+ +
+ +
+ + {{{ SCRIPT }}} + + \ No newline at end of file diff --git a/arch/web/main.c b/arch/web/main.c deleted file mode 100644 index e69de29..0000000 diff --git a/arch/web/tui/main.c b/arch/web/tui/main.c new file mode 100644 index 0000000..20b3ebd --- /dev/null +++ b/arch/web/tui/main.c @@ -0,0 +1,23 @@ +#include "../../../vm/vm.h" +#undef true +#undef false + +#include +#include +#include + +VM vm = {0}; + +void mainloop(void) { + if (!step_vm(&vm)) { + emscripten_cancel_main_loop(); + return; + } +} + +int main(void) { + printf("VM loaded successfully\n"); + + emscripten_set_main_loop(mainloop, 0, 1); + return 0; +} diff --git a/arch/web/tui/shell_minimal.html b/arch/web/tui/shell_minimal.html new file mode 100644 index 0000000..8a8c6db --- /dev/null +++ b/arch/web/tui/shell_minimal.html @@ -0,0 +1,288 @@ + + + + + + Emscripten-Generated Code + + + +
+
emscripten
+
Downloading...
+
+ +
+
+ +
+
+
+ Resize canvas + Lock/hide mouse pointer +     + +
+ +
+ +
+ + {{{ SCRIPT }}} + + \ No newline at end of file diff --git a/build b/build old mode 100644 new mode 100755 index 13f4793..3c8f8de --- a/build +++ b/build @@ -1,2 +1,118 @@ #!/bin/sh +# if an error occurs exit +set -e + +# set defaults for these if they don't exist +if [ -z $ARCH ]; then + ARCH='linux' +fi + +if [ -z $MODE ]; then + MODE='debug' +fi + +if [ -z $UI ]; then + UI='tui' +fi + +case $ARCH in + "linux") + if [ -z $CC ]; then + CC='gcc' + fi + ;; + "web") + CC=emcc + ;; +esac + +# setup dirs +SRC_DIR=./arch/$ARCH/$UI +BUILD_DIR=./out/$ARCH/$UI + +# clean cmd +case $1 in + "clean") + echo "Deleting $BUILD_DIR" + rm -rf $BUILD_DIR + exit 0 +esac + +# run cmd +case $1 in + "run") + + case $ARCH in + "linux") + $BUILD_DIR/undar $2 + ;; + "web") + emrun $BUILD_DIR/undar.html + ;; + esac + + exit 0 +esac + +# create the build dir if it doesnt exist +if [ -d $BUILD_DIR ]; then + echo "Building to $BUILD_DIR" +else + echo "$BUILD_DIR not found, creating" + mkdir -p $BUILD_DIR +fi + +# setup the build flags based on the build mode +case $MODE in + "debug") + BUILD_FLAGS="-g -Wall -Wextra -Werror -pedantic" + ;; + "release") + BUILD_FLAGS="-O2 -Wall -Wextra -Werror -pedantic" + ;; +esac + +# set up the flags based on the UI +case $UI in + "tui") + case $CC in + "gcc") + LINK_FLAGS="" + ;; + "emcc") + LINK_FLAGS="-s ASYNCIFY --shell-file $SRC_DIR/shell_minimal.html" + ;; + esac + ;; + "gui") + case $CC in + "gcc") + LINK_FLAGS="$(sdl2-config --libs --cflags)" + ;; + "emcc") + LINK_FLAGS="-s USE_SDL=2 -s ASYNCIFY --shell-file $SRC_DIR/shell_minimal.html" + ;; + esac + ;; +esac + +# build the core VM +VM_BUILD_FLAGS="$BUILD_FLAGS -std=c89 -ffreestanding -nostdlib -fno-builtin" +${CC} -c vm/libc.c -o $BUILD_DIR/libc.o $VM_BUILD_FLAGS +${CC} -c vm/vm.c -o $BUILD_DIR/vm.o $VM_BUILD_FLAGS + +# Set up the final build command +case $ARCH in + "linux") + BUILD_CMD="$CC -o $BUILD_DIR/undar $SRC_DIR/main.c $LINK_FLAGS $BUILD_DIR/libc.o $BUILD_DIR/vm.o $BUILD_FLAGS $LINK_FLAGS" + ;; + "web") + BUILD_CMD="$CC $SRC_DIR/main.c $BUILD_DIR/libc.o $BUILD_DIR/vm.o -o $BUILD_DIR/undar.html $BUILD_FLAGS $LINK_FLAGS" + ;; +esac + +echo "$BUILD_CMD" +${BUILD_CMD} + +echo "Finished building to $BUILD_DIR/undar" diff --git a/vm.c b/vm.c deleted file mode 100644 index e69de29..0000000 diff --git a/libc.c b/vm/libc.c similarity index 100% rename from libc.c rename to vm/libc.c diff --git a/libc.h b/vm/libc.h similarity index 100% rename from libc.h rename to vm/libc.h diff --git a/vm/vm.c b/vm/vm.c new file mode 100644 index 0000000..4ae2857 --- /dev/null +++ b/vm/vm.c @@ -0,0 +1,6 @@ +#include "vm.h" + +bool step_vm(VM *vm) { + USED(vm); + return false; +} diff --git a/vm.h b/vm/vm.h similarity index 61% rename from vm.h rename to vm/vm.h index 9ea32e8..f0b3d8e 100644 --- a/vm.h +++ b/vm/vm.h @@ -4,19 +4,21 @@ #include "libc.h" typedef enum { - NOOP, + NOOP } Opcode; typedef struct vm_s VM; +#define CODE_SIZE 4096 #define MEM_SIZE 65536 struct vm_s { - u32 pc; - u8 mem[MEM_SIZE]; + u32 pc; + u32 code[CODE_SIZE]; + u8 mem[MEM_SIZE]; }; -bool init_vm(VM *vm); +extern bool init_vm(VM *vm); bool step_vm(VM *vm); #endif