Added a very hacky text UI

This commit is contained in:
Jozef Nagy 2025-05-20 19:24:16 +02:00
parent 06fb67beca
commit dae7b9c869
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
16 changed files with 296 additions and 33783 deletions

View file

@ -43,7 +43,7 @@ LIVECD := $(RELEASE_DIR)/aurix-$(GITREV)-livecd_$(ARCH)-$(PLATFORM).iso
LIVEHDD := $(RELEASE_DIR)/aurix-$(GITREV)-livehdd_$(ARCH)-$(PLATFORM).img
LIVESD := $(RELEASE_DIR)/aurix-$(GITREV)-livesd_$(ARCH)-$(PLATFORM).img
QEMU_FLAGS := -m 2G -smp 4 -serial stdio
QEMU_FLAGS := -m 2G -smp 4 -rtc base=localtime -serial stdio
# QEMU Audio support
#QEMU_FLAGS += -audiodev coreaudio,id=coreaudio0 -device ich9-intel-hda -device hda-output,audiodev=coreaudio0

View file

@ -30,7 +30,10 @@
#include <stddef.h>
#define DEFAULT_ENTRY 0
#define DEFAULT_TIMEOUT 30
// default timeout of 0 disables the UI entirely, which is essentialy what *should* happen now since the UI
// is... in a catastrophic state. Just remember to set this back to 30 once the UI is ready
#define DEFAULT_TIMEOUT 0
// #define DEFAULT_TIMEOUT 30
char *config_paths[] = {
"\\AxBoot\\axboot.cfg",

View file

@ -22,5 +22,8 @@
struct language i18n_csCZ = {
.shutdown = "Vypnout",
.reboot = "Restartovat",
.reboot_to_firmware = "Přejít do nastavení firmwaru"
.reboot_to_firmware = "Přejít do nastavení firmwaru",
.resolution = "Rozlišení",
.language = "Jazyk"
};

View file

@ -22,5 +22,8 @@
struct language i18n_enUS = {
.shutdown = "Shutdown",
.reboot = "Reboot",
.reboot_to_firmware = "Reboot to Firmware"
.reboot_to_firmware = "Reboot to Firmware",
.resolution = "Resolution",
.language = "Language"
};

View file

@ -19,6 +19,20 @@
#include <i18n.h>
extern struct language i18n_csCZ;
extern struct language i18n_enUS;
struct language *i18n_lang = &i18n_enUS;
struct language_selection i18n_languages[] = {
{
"Čeština",
"cs_CZ",
&i18n_csCZ
},
{
"English",
"en_US",
&i18n_enUS
}
};
struct language_selection *i18n_curlang = &i18n_languages[1]; // english

View file

@ -38,6 +38,12 @@ void axboot_init()
//config_init();
// boot straight away
if (config_get_timeout() < 1) {
struct axboot_entry *entries = config_get_entries();
loader_load(&(entries[config_get_default()]));
}
ui_init();
debug("axboot_init(): Returned from main menu, something went wrong. Halting!");

View file

@ -20,9 +20,11 @@
#include <config/config.h>
#include <lib/string.h>
#include <ui/framebuffer.h>
#include <ui/keyboard.h>
#include <ui/mouse.h>
#include <ui/font.h>
#include <ui/ui.h>
#include <loader/loader.h>
#include <time/dt.h>
#include <i18n.h>
#include <axboot.h>
@ -30,6 +32,18 @@
#include <print.h>
#include <stdint.h>
enum {
EVENT_TIME = (1 << 0),
EVENT_TIMEOUT = (1 << 1),
EVENT_MOUSE = (1 << 2),
EVENT_NEXT_ENTRY = (1 << 3),
EVENT_PREV_ENTRY = (1 << 4),
EVENT_NEXT_TAB = (1 << 5),
EVENT_LANG_CHANGE = (1 << 6),
};
struct datetime last_dt;
bool gui_init(struct ui_context *ctx)
@ -47,37 +61,72 @@ bool tui_init(struct ui_context *ctx)
return false;
}
int w;
int width = ctx->fb_modes[ctx->current_mode].width;
int height = ctx->fb_modes[ctx->current_mode].height;
int width_center = width / 2;
int height_center = height / 2;
int w, h;
// display string at the top center of the screen
char *top_string = BOOTLOADER_NAME_STR " v" BOOTLOADER_VERSION_STR;
ssfn_bbox(&(ctx->font), top_string, &w, NULL, NULL, NULL);
terminal_setcur(ctx, ctx->fb_modes[ctx->current_mode].width / 2 - (w / 2), ctx->fb_modes[ctx->current_mode].height / 32);
terminal_setcur(ctx, width_center - (w / 2), height / 32);
terminal_print(ctx, top_string);
// display current language
char lang_str[64];
snprintf((char *)&lang_str, 64, "%s: %s", i18n_curlang->lang->language, i18n_curlang->name);
ssfn_bbox(&(ctx->font), (char *)lang_str, &w, &h, NULL, NULL);
terminal_setcur(ctx, width - w - ctx->font.size, height - h);
terminal_print(ctx, (char *)lang_str);
// display all entries
int entry_count = config_get_entry_count();
int entry_height_offset = height_center - ((h * entry_count) / 2);
struct axboot_entry *entries = config_get_entries();
for (int i = 0; i < entry_count; i++) {
debug("tui_init(): Drawing entries... (%u/%u)\n", i, entry_count);
ssfn_bbox(&(ctx->font), entries[i].name, &w, &h, NULL, NULL);
terminal_setcur(ctx, width_center - (w/2), entry_height_offset + (i * h));
terminal_print(ctx, entries[i].name);
}
// highlight default entry
int default_entry = ctx->current_selection;
char final_selent[128];
int f_w, f_h;
ssfn_bbox(&(ctx->font), " ", &f_w, &f_h, NULL, NULL);
snprintf((char *)&final_selent, 128, "> %s <", entries[default_entry].name);
ssfn_bbox(&(ctx->font), entries[default_entry].name, &w, &h, NULL, NULL);
terminal_setcur(ctx, width_center - (w/2) - (f_w*2), entry_height_offset + (default_entry * h));
terminal_print(ctx, "> ");
terminal_setcur(ctx, width_center + (w/2), entry_height_offset + (default_entry * h));
terminal_print(ctx, " <");
return true;
}
void gui_draw(struct ui_context *ctx, void *mouse_status, void *event)
void gui_draw(struct ui_context *ctx, struct datetime *dt, struct language_selection *newlang, struct mouse_event *mouse_status, uint8_t event)
{
(void)ctx;
(void)dt;
(void)newlang;
(void)mouse_status;
(void)event;
}
void tui_draw(struct ui_context *ctx, void *mouse_status, void *event)
void tui_draw(struct ui_context *ctx, struct datetime *dt, struct language_selection *newlang, struct mouse_event *mouse_status, uint8_t event)
{
(void)mouse_status;
(void)event;
// display the current date and time at the bottom left corner of the screen
int w, h;
struct datetime dt;
get_datetime(&dt);
if (memcmp(&dt, &last_dt, sizeof(struct datetime)) != 0) {
if (event & EVENT_TIME) {
int w, h;
char dt_str[20] = {0}; // YYYY/mm/dd HH:MM:SS
snprintf((char *)&dt_str, 20, "%.4u/%.2u/%.2u %.2u:%.2u:%.2u", dt.year, dt.month, dt.day, dt.h, dt.m, dt.s);
snprintf((char *)&dt_str, 20, "%.4u/%.2u/%.2u %.2u:%.2u:%.2u", dt->year, dt->month, dt->day, dt->h, dt->m, dt->s);
ssfn_bbox(&(ctx->font), (char *)dt_str, &w, &h, NULL, NULL);
@ -89,7 +138,44 @@ void tui_draw(struct ui_context *ctx, void *mouse_status, void *event)
terminal_setcur(ctx, 0, ctx->fb_modes[ctx->current_mode].height - h);
terminal_print(ctx, (char *)dt_str);
last_dt = dt;
// update last datetime
last_dt = *dt;
}
// timeout update
if (event & EVENT_TIMEOUT) {
// TODO
}
// select next entry
if (event & EVENT_NEXT_ENTRY) {
// TODO
}
// select previous entry
if (event & EVENT_PREV_ENTRY) {
// TODO
}
// update language
if (event & EVENT_LANG_CHANGE) {
int w, h;
char curlang_str[64];
snprintf((char *)&curlang_str, 64, "%s: %s", i18n_curlang->lang->language);
ssfn_bbox(&(ctx->font), (char *)curlang_str, &w, &h, NULL, NULL);
for (uint32_t y = ctx->fb_modes[ctx->current_mode].height - (2*h); y < ctx->fb_modes[ctx->current_mode].height - h; y++) {
for (int x = 0; x < w; x++) {
*((uint32_t *)ctx->fb_addr + (ctx->fb_modes[ctx->current_mode].pitch / ctx->fb_modes[ctx->current_mode].bpp) * y + x) = 0xFF000000;
}
}
i18n_curlang = newlang;
char newlang_str[64];
snprintf((char *)&curlang_str, 64, "%s: %s", i18n_curlang->lang->language);
ssfn_bbox(&(ctx->font), (char *)curlang_str, &w, &h, NULL, NULL);
terminal_setcur(ctx, ctx->fb_modes[ctx->current_mode].width - w, ctx->fb_modes[ctx->current_mode].height - h);
terminal_print(ctx, (char *)newlang_str);
}
}
@ -124,7 +210,9 @@ void ui_init()
ctx.font_buf.y = 0;
ctx.font_buf.fg = 0xFFFFFFFF;
void (*ui_callback)(struct ui_context*,void*,void*) = NULL;
ctx.current_selection = config_get_default();
void (*ui_callback)(struct ui_context*,struct datetime*,struct language_selection*,struct mouse_event*,uint8_t) = NULL;
switch (ctx.ui) {
case UI_MODERN: {
@ -146,9 +234,57 @@ void ui_init()
}
}
struct datetime dt;
struct mouse_event me;
while (1) {
ui_callback(&ctx, NULL, NULL);
//get_mouse(&m_x, &m_y, &m_but);
//debug("Mouse X = %u | Mouse Y = %u\n", m_x, m_y);
uint8_t event = 0;
// datetime?
get_datetime(&dt);
if (memcmp(&dt, &last_dt, sizeof(struct datetime)) != 0) {
event |= EVENT_TIME;
}
// mouse movement?
get_mouse(&(me.x), &(me.y), &(me.but));
if (memcmp(&me, &(ctx.last_mouse), sizeof(struct mouse_event)) != 0) {
event |= EVENT_MOUSE;
}
// keypress?
uint16_t scancode;
get_keypress(&scancode);
if (scancode != 0) {
switch (scancode) {
case SCANCODE_ARROW_DOWN:
event |= EVENT_NEXT_ENTRY;
break;
case SCANCODE_ARROW_UP:
event |= EVENT_PREV_ENTRY;
break;
case SCANCODE_ENTER:
// clear the screen
for (uint32_t y = 0; y < ctx.fb_modes[ctx.current_mode].height; y++) {
for (uint32_t x = 0; x < ctx.fb_modes[ctx.current_mode].width; x++) {
*((uint32_t *)ctx.fb_addr + (ctx.fb_modes[ctx.current_mode].pitch / ctx.fb_modes[ctx.current_mode].bpp) * y + x) = 0xFF000000;
}
}
struct axboot_entry *entries = config_get_entries();
loader_load(&entries[ctx.current_selection]);
break;
default:
break;
}
}
if (event != 0) {
ui_callback(&ctx, &dt, NULL, &me, event);
} else {
#ifdef __x86_64
__asm__ volatile("hlt");
#endif
//arch_wait();
}
}
}

View file

@ -24,8 +24,17 @@ struct language {
char *shutdown;
char *reboot;
char *reboot_to_firmware;
char *resolution;
char *language;
};
extern struct language *i18n_lang;
struct language_selection {
char *name;
char *code;
struct language *lang;
};
extern struct language_selection *i18n_curlang;
#endif /* _I18N_H */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,31 @@
/*********************************************************************************/
/* Module Name: keyboard.c */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _UI_KEYBOARD_H
#define _UI_KEYBOARD_H
#include <stdint.h>
#define SCANCODE_ARROW_UP 0x1
#define SCANCODE_ARROW_DOWN 0x2
#define SCANCODE_ENTER 43
void get_keypress(uint16_t *scancode);
#endif /* _UI_KEYBOARD_H */

View file

@ -39,6 +39,12 @@
#include <stdint.h>
struct mouse_event {
uint16_t x;
uint16_t y;
uint8_t but;
};
struct ui_context {
uint32_t *fb_addr;
struct fb_mode *fb_modes;
@ -46,6 +52,11 @@ struct ui_context {
int current_mode;
int ui;
struct mouse_event last_mouse;
int current_selection;
int last_selection;
struct terminal terminal;
ssfn_t font;

View file

@ -51,6 +51,9 @@ EFI_STATUS uefi_entry(EFI_HANDLE ImageHandle,
gSystemTable = SystemTable;
gBootServices = SystemTable->BootServices;
// reset input
gSystemTable->ConIn->Reset(gSystemTable->ConIn, EFI_FALSE);
// clear the screen
gSystemTable->ConOut->ClearScreen(gSystemTable->ConOut);

View file

@ -0,0 +1,39 @@
/*********************************************************************************/
/* Module Name: keyboard.c */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#include <ui/keyboard.h>
#include <stdint.h>
#include <print.h>
#include <efi.h>
#include <efilib.h>
void get_keypress(uint16_t *scancode)
{
EFI_INPUT_KEY key;
if (gSystemTable->ConIn->ReadKeyStroke(gSystemTable->ConIn, &key) == EFI_SUCCESS) {
if (key.UnicodeChar == L'\r') {
*scancode = SCANCODE_ENTER;
return;
}
*scancode = key.ScanCode;
} else {
*scancode = 0;
}
}

View file

@ -1,51 +0,0 @@
# Soapine configuration
To work and do what you told it to do, Soapine uses a configuration file.
## Location
Soapine will search for the configuration in:
* `(boot partition)\soapine.cfg`
* `(boot partition)\soapine\soapine.cfg`
* `(boot partition)\EFI\BOOT\soapine.cfg`
* `(boot partition)\EFI\soapine.cfg`
If Soapine finds the config file, he parses it and jump to his usual menu. Else, Soapine will display a stop screen saying that you need to fix your configuration
## Accepted value types
* String literal (`"Hello, World!"`)
* Decimal (`2`)
* Hexadecimal (`0x2`)
* Hexadecimal color (`#FFFFFF`)
* Boolean (`true/false`)
## Declarations
Declarations are values that components of Soapine will search for:
If you declare `VERBOSE` with a value of true, Soapine will itself put in verbose mode.
You can do a declaration by writing the name + an equal sign + the value (using the accepted value types), that will make `NAME=VALUE`.
If an unused declaration is provided (for example `FORCE_SOAPINE_TO_LIKE_ME=true`), Soapine will simply ignore it, but it will still be present.
Here are some example declarations:
* `MENU_BRANDING="Raphaël's Custom Soapine!!"` (string literal)
* `MENU_HEADERBAR_BG=#FFFFFF` (Hexadecimal color)
* `MENU_HEADERBAR_MARGIN=1` (decimal)
* `VERBOSE=true` (boolean)
* `LOAD_ADDRESS=0x1000` (hexadecimal)
## Menu entries
Menu entries allow you to show an operating system (that can be loaded with the supported protocols!) on the menu.
They are declared like that:
```c
menu_entry "Project Jupiter" {
};
```
*(yes i decided to give a C-like syntax to it)*
You can put a small number of declarations inside the menu entries. (PROTOCOL, IMAGE_PATH, CMDLINE, RESOLUTION) (Providing the `PROTOCOL` and `IMAGE_PATH` declarations is required for Soapine to boot your OS!)
## Supported declarations
None for now (we just got the config parser working!)
At least, you can still define entries!

View file

@ -1,10 +0,0 @@
# Soapine's philosophy
Soapine is meant to be lightweight, while being useful to everyone:
* Ship the bootloader with multiple features (even the weirdest features)
* Ability to extend the bootloader with ELF extensions: If you wanna write an extension to support PE loading, ***DO IT***.
Soapine is also meant to be customizable:
* You can modify each bit of the bootloader: If you wanna center the headerbar text, you ***CAN***
* You can change the default values in Soapine's source code.

17
docs/boot/TRANSLATING.md Normal file
View file

@ -0,0 +1,17 @@
# Translating AxBoot
To translate AxBoot, copy `en_US.c` in the `common/i18n` directory and rename it (and the translation structure) to the target language code.
Before translating each string, open `common/i18n/i18n.c` and register the new language:
```c
extern struct language i18n_xxXX;
struct language_selection i18n_languages[] = {
{
"English", // Localized language name (eg. English, Čeština, Svenska, ...)
"en_US", // Language code
&i18n_enUS // reference to the language structure
},
/* ... */
}
```