1
0
forked from Rust/Core

feat: Languages

This commit is contained in:
Gleb Zaharov 2024-01-28 00:13:35 +03:00
parent 289d977ea8
commit 1a6f5303cf
5 changed files with 54 additions and 2 deletions

View File

@ -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,
);

View File

@ -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

View File

@ -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<Str: Debuggable>(text: Str) {
for byte in text.data_iter() {
unsafe {

View File

@ -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);

View File

@ -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