Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9b0d72d
feat: add kernel API table and implementation for function pointers
Rhylanscript Oct 19, 2026
81f0ecf
feat: refactor app registration and add shell API command
Rhylanscript Oct 19, 2026
0a37814
feat: update linker script and build process to include vigil_api.o
Rhylanscript Oct 19, 2026
fedaabe
Merge pull request #63 from Rhylanscript/feat/app-api
Rhylanscript Oct 19, 2026
b9b0571
feat: add loadapp command to shell to execute app loading from disk
Rhylanscript Oct 19, 2026
d0b46e5
feat: add app loader for loading VAPP files from disk
Rhylanscript Oct 19, 2026
e28c294
feat: simplistic app loaded from disk for testing
Rhylanscript Oct 19, 2026
255c6e2
feat: add linker script for loadable VIGIL apps
Rhylanscript Oct 19, 2026
c14c061
chore: helper install_app script for copying files to VIGIL disk image
Rhylanscript Oct 19, 2026
5b8c08f
feat: add loader support and update build script for loadable apps
Rhylanscript Oct 19, 2026
46d3866
Merge pull request #64 from Rhylanscript/feat/app-loader
Rhylanscript Oct 19, 2026
a0ec26d
feat: move calculator app out of kernel
Rhylanscript Oct 19, 2026
51f301f
chore: update build process for calculator to install on disk instead…
Rhylanscript Oct 19, 2026
5702435
Merge pull request #66 from Rhylanscript/feat/app-calc
Rhylanscript Oct 19, 2026
09beda8
feat: generalise apps in launcher
Rhylanscript Oct 19, 2026
229bcbb
feat: extend kernel API with menu, prompt, and launcher functions; in…
Rhylanscript Oct 19, 2026
d12cc19
Merge pull request #67 from Rhylanscript/feat/app-api-v2
Rhylanscript Oct 19, 2026
fb9bf74
feat: move files app out of kernel
Rhylanscript Oct 19, 2026
f563137
chore: update build process for files app
Rhylanscript Oct 19, 2026
dff0d6a
Merge pull request #68 from Rhylanscript/feat/app-files
Rhylanscript Oct 19, 2026
d8407f8
feat: move notepad app out of kernel
Rhylanscript Oct 19, 2026
21c293a
chore: update build process for notepad app
Rhylanscript Oct 19, 2026
33b53e6
Merge pull request #69 from Rhylanscript/feat/app-notepad
Rhylanscript Oct 19, 2026
b23d103
chore: add error handling for notepad app installation in build script
Rhylanscript Oct 19, 2026
457b012
chore: update QEMU boot options in run.bat to boot in SDL mode by def…
Rhylanscript Oct 20, 2026
40dd37c
docs: update README with builtin/loaded app info
Rhylanscript Oct 20, 2026
56a1095
Merge pull request #70 from Rhylanscript/chore/cleanup
Rhylanscript Oct 20, 2026
fc7cb08
fix: remove duplicate `on_prompt_done` assignment
Rhylanscript Oct 20, 2026
1716b8f
chore: update .gitignore to include python cache files
Rhylanscript Oct 20, 2026
d2b5656
test: add unit tests for app installation functionality
Rhylanscript Oct 20, 2026
7ec93f6
ci: add CI workflow for building and testing VIGIL
Rhylanscript Oct 20, 2026
ecc1f04
ci: find `nasm.exe` and add to `GITHUB_PATH`
Rhylanscript Oct 20, 2026
f3ae3c2
ci: update test discovery path in CI workflow
Rhylanscript Oct 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CI

on:
pull_request:
push:
branches:
- main

jobs:
build:
runs-on: windows-2022

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install NASM
shell: pwsh
run: |
choco install nasm --yes --no-progress
if ($LASTEXITCODE -ne 0) { throw "NASM installation failed" }

$nasm = Get-Command nasm.exe -ErrorAction SilentlyContinue
if ($nasm) {
$nasmPath = $nasm.Source
} else {
$candidates = @(
(Join-Path $env:ProgramFiles "NASM\nasm.exe"),
(Join-Path $env:ChocolateyInstall "bin\nasm.exe")
)
$nasmPath = $candidates |
Where-Object { Test-Path -LiteralPath $_ } |
Select-Object -First 1
}
if (-not $nasmPath) { throw "nasm.exe was not found after installation" }

& $nasmPath -v
if ($LASTEXITCODE -ne 0) { throw "NASM is not available on PATH" }
Add-Content -Path $env:GITHUB_PATH -Value (Split-Path -Parent $nasmPath)

- name: Install i686-elf toolchain
shell: pwsh
run: |
$version = "15.2.0"
$archive = Join-Path $env:RUNNER_TEMP "i686-elf-tools-windows.zip"
$destination = Join-Path $env:RUNNER_TEMP "i686-elf-tools"
Invoke-WebRequest `
-Uri "https://github.com/lordmilko/i686-elf-tools/releases/download/$version/i686-elf-tools-windows.zip" `
-OutFile $archive
Expand-Archive -Path $archive -DestinationPath $destination

$gcc = Get-ChildItem -Path $destination -Filter "i686-elf-gcc.exe" -Recurse |
Select-Object -First 1
if (-not $gcc) { throw "i686-elf-gcc.exe was not found in the toolchain archive" }
Add-Content -Path $env:GITHUB_PATH -Value $gcc.DirectoryName

- name: Run installer tests
run: python -m unittest discover -s tools -p "test_*.py" -v

- name: Build VIGIL
shell: pwsh
run: |
cmd /c scripts\build.bat
if ($LASTEXITCODE -ne 0) { throw "VIGIL build failed" }
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Thumbs.db
.env
*.env

# python
__pycache__/
*.py[cod]
*.pyc

# builds
build/
dist/
Expand Down
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ VIGIL boots from its own two stage bootloader into a 32-bit graphical desktop wi

### Terminal

Command line shell with an 8 entry command history (cycle using up & down arrows).
The Terminal is a Command line shell built into the kernel with an 8 entry command history (cycle using up & down arrows).

| Command | What it does |
| ------------------------- | ------------------------------------------------------------------------- |
Expand All @@ -34,28 +34,38 @@ Command line shell with an 8 entry command history (cycle using up & down arrows
| `folder <path>` | Create a folder at `<path>` |
| `rename <path> <name>` | Rename a file at `<path>` to `<name>` |
| `files [folder]` | Lists saved files in specified folder. If left blank defaults to root dir |
| `loadapp <path>` | Loads an app file from disk |

### Notepad

A text editor with a blinking cursor, arrow keys, Home, End, Delete, Backspace and Tab. Defaults to editing the file `/notes`. Using the `edit` command in shell allows editing of any file.

### Files

A simple file viewing app, where you can navigate the file tree. Clicking on a file will open it in notepad, clicking a folder will change the view to the contents of that folder. Files / Folders can be managed from the app, for example, right clicking a file will bring up options such as renaming, deleting, or seeing more information about it.
A simple file browser for navigating the file tree. Click a file to open it in Notepad, and click a folder to view its contents. Right click a file for options such as renaming, deleting, or viewing more information about it.

### Calculator

A simple calculator app with simple operations such as (`-`, `+`, `*`, `/`, & `%`). Each command is linked to a keypress.
A simple calculator supporting `-`, `+`, `*`, `/`, and `%`, operated with the keyboard.

### Hello

A small example app demonstrating that apps can be loaded from the storage disk rather than being built into the kernel.

### Using apps

Click an app on the home screen to launch it. The `-` button (or the `Esc` key) minimizes an app and keeps it running in the taskbar whereas the `X` button closes it completely.
Click an app on the home screen to launch it. The `-` button (or the `Esc` key) minimizes an app and keeps it running in the taskbar, while the `X` button closes it completely.

### Builtin vs Loaded Apps

The Terminal is built into the kernel, while Calculator, Files, Hello, and Notepad are compiled separately and installed in the `apps` folder on the persistent storage disk and loaded by the launcher at startup. Loaded apps use the kernel's VIGIL API to access services such as graphics and the filesystem, they are not isolated from the kernel.

## How it works

1. **Stage 1:** the 512 byte boot sector the BIOS loads first, then it reads stage 2 from disk.
2. **Stage 2:** enables the A20 line (access to memory above 1mb), asks the BIOS for a 1024x768 graphics mode, sets up the GDT, and switches the CPU to protected mode
3. **The kernel:** (C) installs interrupt handlers, remaps the interrupt controller, starts the timer, keyboard and mouse, then hands control to the launcher, which runs forever
1. **Stage 1:** The BIOS loads the 512-byte boot sector, which then reads stage 2 from disk
2. **Stage 2:** Enables the A20 line (access to memory above 1mb), asks the BIOS for a 1024x768 graphics mode, sets up the GDT, and switches the CPU to protected mode
3. **The kernel:** Installs interrupt handlers, remaps the interrupt controller, starts the timer, keyboard, and mouse, then hands control to the launcher
4. **Loadable apps:** The launcher loads app files from the `apps` folder on the separate storage disk into memory and registers them for the home screen

| Part | Details |
| ------------- | --------------------------------------------------------------------- |
Expand All @@ -65,18 +75,18 @@ Click an app on the home screen to launch it. The `-` button (or the `Esc` key)
| Input | PS/2 keyboard (Shift, Caps Lock, Ctrl, arrows) and PS/2 mouse |
| Memory | First-fit heap allocator over a 1 MB pool |
| Storage | ATA PIO disk driver on a separate 10 MB virtual disk |
| Filesystem | Up to 16 files, 16 char long names, with nested folder structure |
| Filesystem | Up to 32 files and folders, 15-character names, with nested folders |

## Running it

I work on VIGIL on windows (unfortunately). I have some helper batch scripts for executing simple actions for me, which need [NASM][nasm], the [i686-elf cross-compiler tools][elf-tools], and [QEMU][qemu].
VIGILs helper batch scripts are for Windows and require [NASM][nasm], the [i686-elf cross-compiler tools][elf-tools], [Python 3][python], and [QEMU][qemu].

```bash
:: compile everything into dist/vigil.img
vigil build

:: boot it in QEMU (use --sdl)
vigil run
:: boot it in QEMU with an SDL window (--no-sdl boots it normally)
vigil run [--no-sdl]

:: build, then run
vigil dev
Expand All @@ -85,7 +95,7 @@ vigil dev
vigil clean
```

Side note - I would PROBABLY recommend running the run command with `--sdl` as an arguement (but this isnt available for dev, so I kind of stopped using it... I should probably add that functionality for dev......)
`vigil build` creates the boot image and installs the loadable apps onto `dist/storage.img`. The storage disk persists between builds, so close QEMU before building and reinstalling apps.

## License

Expand All @@ -96,5 +106,6 @@ Repo is under an [MIT license][license].
[nasm]: https://www.nasm.us/
[elf-tools]: https://github.com/lordmilko/i686-elf-tools
[qemu]: https://www.qemu.org/
[python]: https://www.python.org/downloads/

[license]: LICENSE
65 changes: 41 additions & 24 deletions apps/calculator/calculator.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// apps/calculator/calculator.c

#include "calculator.h"
#include "app.h"
#include "api.h"
#include "calc.h"
#include "button.h"
#include "graphics.h"
#include "font.h"
#include "kstring.h"
#include "keyboard.h"
#include "mouse.h"
#include "font.h"
#include "title_bar.h"
#include "taskbar.h"

// --- API pointer ---

static const vigil_api_t* api = 0;

// --- layout (pixels) ---

#define KEY_W 96
Expand Down Expand Up @@ -105,16 +106,16 @@ static gfx_color_t color_for(key_kind_t kind) {

static uint32_t band_height(void) {
uint32_t used = TITLE_BAR_HEIGHT + TASKBAR_HEIGHT;
if (gfx_screen_height() > used) {
return gfx_screen_height() - used;
if (api->gfx_screen_height() > used) {
return api->gfx_screen_height() - used;
}
return 0;
}

static void compute_layout(void) {
origin_x = 0;
if (gfx_screen_width() > CALC_WIDTH) {
origin_x = (gfx_screen_width() - CALC_WIDTH) / 2;
if (api->gfx_screen_width() > CALC_WIDTH) {
origin_x = (api->gfx_screen_width() - CALC_WIDTH) / 2;
}

origin_y = TITLE_BAR_HEIGHT;
Expand All @@ -140,8 +141,8 @@ static void compute_layout(void) {
// --- drawing ---

static void draw_display(void) {
gfx_fill_rect(origin_x, origin_y, CALC_WIDTH, DISPLAY_H, DISPLAY_BG);
gfx_draw_rect_outline(origin_x, origin_y, CALC_WIDTH, DISPLAY_H, GFX_WHITE);
api->gfx_fill_rect(origin_x, origin_y, CALC_WIDTH, DISPLAY_H, DISPLAY_BG);
api->gfx_draw_rect_outline(origin_x, origin_y, CALC_WIDTH, DISPLAY_H, GFX_WHITE);

const char* text;
char number[12];
Expand All @@ -155,28 +156,28 @@ static void draw_display(void) {
text = "Error: number too big";
color = GFX_RED;
} else {
kitoa(calc_display_value(), number);
api->kitoa(calc_display_value(), number);
text = number;
}

uint32_t text_width = kstrlen(text) * FONT_WIDTH;
uint32_t text_width = api->kstrlen(text) * FONT_WIDTH;
uint32_t text_x = origin_x + CALC_WIDTH - DISPLAY_PAD - text_width;
uint32_t text_y = origin_y + (DISPLAY_H - FONT_HEIGHT) / 2;
gfx_draw_string(text_x, text_y, text, color);
api->gfx_draw_string(text_x, text_y, text, color);

char symbol = calc_op_symbol(calc_pending_op());
if (symbol != 0 && error == CALC_OK) {
gfx_draw_char(origin_x + DISPLAY_PAD, origin_y + DISPLAY_PAD, symbol, GFX_GREEN);
api->gfx_draw_char(origin_x + DISPLAY_PAD, origin_y + DISPLAY_PAD, symbol, GFX_GREEN);
}
}

static void paint(void) {
gfx_fill_rect(0, TITLE_BAR_HEIGHT, gfx_screen_width(), band_height(), GFX_BLACK);
api->gfx_fill_rect(0, TITLE_BAR_HEIGHT, api->gfx_screen_width(), band_height(), GFX_BLACK);

draw_display();

for (int i = 0; i < CALC_KEY_COUNT; i++) {
button_draw(&buttons[i]);
api->button_draw(&buttons[i]);
}
}

Expand All @@ -195,19 +196,19 @@ static void press_key(const key_def_t* key) {

// --- app_t slots ---

void calculator_start(void) {
static void calculator_start(void) {
calc_clear();
compute_layout();
paint();
}

void calculator_redraw(void) {
static void calculator_redraw(void) {
compute_layout();
paint();
}

void calculator_handle_char(char c) {
mouse_hide_cursor();
static void calculator_handle_char(char c) {
api->mouse_hide_cursor();

calc_op_t op = calc_op_from_char(c);

Expand All @@ -230,12 +231,28 @@ void calculator_handle_char(char c) {
draw_display();
}

void calculator_handle_click(int32_t x, int32_t y) {
int index = button_find_at(buttons, CALC_KEY_COUNT, x, y);
static void calculator_handle_click(int32_t x, int32_t y) {
int index = api->button_find_at(buttons, CALC_KEY_COUNT, x, y);
if (index < 0) {
return;
}

press_key(&keys[index]);
draw_display();
}

// --- the entry point the loader calls ---

int app_entry(const vigil_api_t* kernel_api, app_t* out_app) {
if (kernel_api->version != VIGIL_API_VERSION || kernel_api->struct_size < sizeof(vigil_api_t)) {
return 1;
}
api = kernel_api;

out_app->name = "Calculator";
out_app->start = calculator_start;
out_app->redraw = calculator_redraw;
out_app->on_key = calculator_handle_char;
out_app->on_click = calculator_handle_click;
return 0;
}
Loading
Loading