From 1a6f5303cf55ab7c6f25452bf50f72ed96fc503e Mon Sep 17 00:00:00 2001 From: sweetbread Date: Sun, 28 Jan 2024 00:13:35 +0300 Subject: [PATCH] feat: Languages --- example/hwa.rs | 11 +++++++++-- src/func_constants.inc | 2 ++ src/modules/system.rs | 32 ++++++++++++++++++++++++++++++++ src/sys.rs | 4 ++++ src/syscalls.S | 7 +++++++ 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/example/hwa.rs b/example/hwa.rs index 8c0fcc5..e9fe2d6 100644 --- a/example/hwa.rs +++ b/example/hwa.rs @@ -6,6 +6,7 @@ use cstr_core::{cstr, CStr}; use kos::{ graphics::{display_message, Color, Dot, Size}, input::fetch_key, + system::{get_lang, Lang}, threads::{exit, fetch_event, Event}, windows::{ define_button, define_window, end_window_draw, get_button_id, start_window_draw, @@ -43,11 +44,17 @@ fn draw_window(c: usize) { None, ); + let btn_str = match get_lang() { + Lang::German => format!("Taste gedrückt: {} mal\0", c), + Lang::Russian => format!("Кнопка нажата: {} раз\0", c), + Lang::French => format!("Button enfoncé : {} fois\0", c), + _ => format!("Button pressed: {} times\0", c), + }; + display_message( Dot { x: 10, y: 30 }, Color::rgb(0, 0, 0), - CStr::from_bytes_with_nul(format!("Button pressed: {} times\0", c).as_bytes()) - .unwrap_or(cstr!("String error")), + CStr::from_bytes_with_nul(btn_str.as_bytes()).unwrap_or(cstr!("String error")), None, ); diff --git a/src/func_constants.inc b/src/func_constants.inc index e9fff2c..636d5ab 100644 --- a/src/func_constants.inc +++ b/src/func_constants.inc @@ -10,6 +10,8 @@ SF_REDRAW = 12 SSF_BEGIN_DRAW = 1 SSF_END_DRAW = 2 SF_GET_BUTTON = 17 +SF_SYSTEM_GET = 26 + SSF_SYS_LANG = 5 SF_BOARD = 63 SSF_DEBUG_WRITE = 1 SF_SYS_MISC = 68 diff --git a/src/modules/system.rs b/src/modules/system.rs index d500d25..3506fac 100644 --- a/src/modules/system.rs +++ b/src/modules/system.rs @@ -1,4 +1,5 @@ use crate::sys; +use crate::throw_new; use alloc::string::String; use cstr_core::CStr; @@ -24,6 +25,37 @@ impl Debuggable for &CStr { } } +pub enum Lang { + English, + Finnish, + German, + Russian, + French, + Estonian, + Spanish, + Italian, +} + +pub fn get_lang() -> Lang { + unsafe { + let l = sys::get_lang(); + return match l { + 1 => Lang::English, + 2 => Lang::Finnish, + 3 => Lang::German, + 4 => Lang::Russian, + 5 => Lang::French, + 6 => Lang::Estonian, + 7 => Lang::Spanish, + 8 => Lang::Italian, + _ => { + throw_new!(format!("Unknown lang: {}", l)); + Lang::English + } + }; + } +} + pub fn debug_write(text: Str) { for byte in text.data_iter() { unsafe { diff --git a/src/sys.rs b/src/sys.rs index 9489c35..12fe67d 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -36,6 +36,10 @@ extern "C" { #[link_name = "_get_button_id"] pub fn get_button_id() -> u32; + // 26.5 + #[link_name = "_get_lang"] + pub fn get_lang() -> u32; + // 63.1 #[link_name = "_debug_write"] pub fn _debug_write(cl: u8); diff --git a/src/syscalls.S b/src/syscalls.S index e4216e6..0ac2a77 100644 --- a/src/syscalls.S +++ b/src/syscalls.S @@ -16,6 +16,7 @@ section '.text' public _init_heap public _alloc public _free + public _get_lang _exit: mov eax, SF_TERMINATE_PROCESS @@ -111,3 +112,9 @@ _free: int 0x40 ret +_get_lang: + mov eax, SF_SYSTEM_GET + mov ebx, SSF_SYS_LANG + int 0x40 + ret +