forked from AbleOS/ableos
Compare commits
31 commits
Author | SHA1 | Date | |
---|---|---|---|
koniifer | 986077435f | ||
koniifer | 530b62aa3d | ||
Able | b864463ad8 | ||
Able | 1e1943d940 | ||
47d727855d | |||
koniifer | 5b123be9ea | ||
Able | 2fb17ac610 | ||
koniifer | 1ec9d0fd46 | ||
Able | 59cf6ef4d7 | ||
koniifer | 8cce5ef731 | ||
koniifer | 0fc95160cc | ||
koniifer | 25fecab5b3 | ||
f6bfb73bd7 | |||
koniifer | f8523f5b3e | ||
koniifer | d2cb73c2ce | ||
koniifer | d0bd3714ee | ||
koniifer | e8f1bce4d6 | ||
dc4878bc2b | |||
koniifer | 04ca5f07d5 | ||
ad587fe464 | |||
9a06b329f4 | |||
koniifer | 936c9e6525 | ||
koniifer | a8572da351 | ||
koniifer | b059faa7f8 | ||
koniifer | d55fd895c9 | ||
koniifer | e2dd379fea | ||
koniifer | d907df14dd | ||
koniifer | 3506c83535 | ||
Able | eff1323e94 | ||
Able | 8849017db2 | ||
Able | f3b78d1699 |
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -19,9 +19,9 @@ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.94"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
|
||||
checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
|
@ -73,9 +73,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.4"
|
||||
version = "1.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf"
|
||||
checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
@ -175,9 +175,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
|||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
|
||||
checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
|
@ -213,12 +213,12 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "hbbytecode"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a1e692eac73fbf44f1fbf816832aaae0ea8f04d7"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#08fc9d6ab6a8dd539255bf45d892f4b7f08776c5"
|
||||
|
||||
[[package]]
|
||||
name = "hblang"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a1e692eac73fbf44f1fbf816832aaae0ea8f04d7"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#08fc9d6ab6a8dd539255bf45d892f4b7f08776c5"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"hbbytecode",
|
||||
|
@ -229,7 +229,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "hbvm"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#a1e692eac73fbf44f1fbf816832aaae0ea8f04d7"
|
||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#08fc9d6ab6a8dd539255bf45d892f4b7f08776c5"
|
||||
dependencies = [
|
||||
"hbbytecode",
|
||||
]
|
||||
|
@ -421,9 +421,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.168"
|
||||
version = "0.2.169"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
|
||||
[[package]]
|
||||
name = "limine"
|
||||
|
@ -726,9 +726,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.90"
|
||||
version = "2.0.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
|
||||
checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -9,7 +9,7 @@ ktest = []
|
|||
[dependencies]
|
||||
# embedded-graphics = "0.8"
|
||||
hbvm = { git = "https://git.ablecorp.us/AbleOS/holey-bytes.git", features = [
|
||||
"nightly",
|
||||
"nightly", "alloc", "disasm"
|
||||
] }
|
||||
ktest_macro = { path = "ktest_macro" }
|
||||
log = "0.4"
|
||||
|
|
|
@ -15,8 +15,10 @@ fn calc_start_of_page(ptr: u64) -> u64 {
|
|||
panic!("unaligned");
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Memory {
|
||||
// TODO: map page aligned segments of memory into a table or some sort here
|
||||
logger: hbvm::mem::InstrLogger,
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
|
@ -56,4 +58,11 @@ impl hbvm::mem::Memory for Memory {
|
|||
unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T {
|
||||
(addr.get() as *const T).read()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn log_instr(&mut self, at: Address, regs: &[hbvm::value::Value]) {
|
||||
log::debug!("exec: [{:02x}] {}", at.get(), unsafe {
|
||||
self.logger.display_instr(at, regs)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ impl ExecThread {
|
|||
|
||||
pub unsafe fn new(program: &[u8], entrypoint: Address) -> Self {
|
||||
let mut vm = Vm::new(
|
||||
mem::Memory {},
|
||||
mem::Memory::default(),
|
||||
Address::new(program.as_ptr() as u64 + entrypoint.get()),
|
||||
);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ fatfs = { version = "0.3", default-features = false, features = [
|
|||
] }
|
||||
toml = "0.8"
|
||||
hblang.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git"
|
||||
# hblang.path = "../../holey-bytes/lang/"
|
||||
log = "0.4"
|
||||
raw-cpuid = "11"
|
||||
ureq = { version = "2", default-features = false, features = ["tls"] }
|
||||
|
|
|
@ -109,7 +109,7 @@ impl Package {
|
|||
std::fs::write(format!("target/programs/{}.hbf", self.name), &out)?;
|
||||
out.clear();
|
||||
|
||||
hblang::run_compiler(
|
||||
let err = hblang::run_compiler(
|
||||
&path,
|
||||
Options {
|
||||
resolver: Some(hblang::ABLEOS_PATH_RESOLVER),
|
||||
|
@ -119,9 +119,10 @@ impl Package {
|
|||
},
|
||||
out,
|
||||
&mut warnings,
|
||||
)?;
|
||||
);
|
||||
std::fs::write(format!("target/programs/{}.hba", self.name), &out)?;
|
||||
out.clear();
|
||||
return err;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -253,10 +253,10 @@ TERM_BACKDROP={}
|
|||
);
|
||||
match p.build(&mut out) {
|
||||
Ok(()) => {}
|
||||
Err(_) => {
|
||||
writeln!(errors, "========= while compiling {} =========", path)
|
||||
Err(e) => {
|
||||
writeln!(errors, "========= while compiling {} {} =========", path, e)
|
||||
.unwrap();
|
||||
errors.push_str(core::str::from_utf8(&out).expect("no"));
|
||||
errors.push_str(&String::from_utf8_lossy(&out));
|
||||
out.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,18 +9,18 @@ widgets := @use("widgets/widgets.hb")
|
|||
ui := @use("ui.hb")
|
||||
|
||||
WindowID := struct {
|
||||
host_id: int,
|
||||
window_id: int,
|
||||
host_id: uint,
|
||||
window_id: uint,
|
||||
}
|
||||
|
||||
VoidWindowID := WindowID.(0, 0)
|
||||
|
||||
create_window := fn(channel: int): ^render.Surface {
|
||||
create_window := fn(channel: uint): ^render.Surface {
|
||||
// get the horizon buffer
|
||||
// request a new window and provide the callback buffer
|
||||
// wait to recieve a message
|
||||
|
||||
windowing_system_buffer := buffer.search("XHorizon\0")
|
||||
windowing_system_buffer := buffer.search("XHorizon")
|
||||
mem_buf := memory.request_page(1)
|
||||
|
||||
if windowing_system_buffer == 0 {
|
||||
|
@ -29,13 +29,13 @@ create_window := fn(channel: int): ^render.Surface {
|
|||
x := 0
|
||||
loop if x > 1000 break else x += 1
|
||||
|
||||
ret := buffer.recv([u8; 4096], windowing_system_buffer, mem_buf)
|
||||
ret := buffer.recv([4096]u8, windowing_system_buffer, mem_buf)
|
||||
if ret == null {
|
||||
log.info("No messages\0")
|
||||
log.info("No messages")
|
||||
}
|
||||
|
||||
if *mem_buf == 0 {
|
||||
log.info("No messages\0")
|
||||
log.info("No messages")
|
||||
}
|
||||
|
||||
return @as(^render.Surface, idk)
|
||||
|
|
|
@ -6,7 +6,7 @@ render := @use("../../../libraries/render/src/lib.hb");
|
|||
.{Surface} := render;
|
||||
.{Font} := render.text
|
||||
|
||||
UI := struct {raw: ^u8, raw_length: uint, is_dirty: bool, surface: Surface, // Each child has their WidgetType as their first byte
|
||||
UI := struct {raw: []u8, is_dirty: bool, surface: Surface, // Each child has their WidgetType as their first byte
|
||||
// children: ^^u8,
|
||||
}
|
||||
|
||||
|
@ -19,29 +19,26 @@ render_ui := fn(surface: Surface, ui: UI): void {
|
|||
render.put_surface(surface, ui.surface, pos, false)
|
||||
}
|
||||
|
||||
sexpr_parser := fn(sexpr: ^u8): UI {
|
||||
cursor := sexpr
|
||||
sexpr_parser := fn(sexpr: []u8): UI {
|
||||
i := 0
|
||||
paren_balance := 0
|
||||
loop {
|
||||
if *cursor == 0 {
|
||||
if i == sexpr.len {
|
||||
if paren_balance != 0 {
|
||||
log.error("Unbalanced Parens\0")
|
||||
log.error("Unbalanced Parens")
|
||||
}
|
||||
break
|
||||
} else if *cursor == 40 {
|
||||
log.info("Open paren\0")
|
||||
} else if sexpr[i] == '(' {
|
||||
log.info("Open paren")
|
||||
paren_balance += 1
|
||||
} else if *cursor == 41 {
|
||||
log.info("Closed paren\0")
|
||||
} else if sexpr[i] == ')' {
|
||||
log.info("Closed paren")
|
||||
paren_balance -= 1
|
||||
}
|
||||
|
||||
cursor += 1
|
||||
i += 1
|
||||
}
|
||||
|
||||
length := string.length(sexpr)
|
||||
|
||||
ui_surface := render.new_surface(100, 100)
|
||||
|
||||
return UI.(sexpr, length, true, ui_surface)
|
||||
return UI.(sexpr, true, ui_surface)
|
||||
}
|
|
@ -10,27 +10,22 @@ Label := struct {
|
|||
magic: uint,
|
||||
is_dirty: bool,
|
||||
surface: Surface,
|
||||
text: ^u8,
|
||||
text_length: uint,
|
||||
text: []u8,
|
||||
bg: Color,
|
||||
fg: Color,
|
||||
|
||||
new_label := fn(text: ^u8, width: uint): Self {
|
||||
new_label := fn(text: []u8, width: uint): Self {
|
||||
text_surface := render.Surface.new(width, 20)
|
||||
text_length := string.length(text)
|
||||
label := Self.(3, true, text_surface, text, text_length, render.BLACK, render.WHITE)
|
||||
label := Self.(3, true, text_surface, text, render.BLACK, render.WHITE)
|
||||
return label
|
||||
}
|
||||
|
||||
set_label_text := fn(self: Self, text: ^u8): void {
|
||||
text_length := string.length(text)
|
||||
|
||||
$set_label_text := fn(self: ^Self, text: []u8): void {
|
||||
self.is_dirty = true
|
||||
self.text = text
|
||||
self.text_length = text_length
|
||||
}
|
||||
|
||||
$set_color := fn(self: Self, bg: Color, fg: Color): void {
|
||||
$set_color := fn(self: ^Self, bg: Color, fg: Color): void {
|
||||
self.bg = bg
|
||||
self.fg = fg
|
||||
self.is_dirty = true
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
stn := @use("../../stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{log, buffer, memory} := stn
|
||||
keycodes := @use("keycodes.hb")
|
||||
|
||||
|
@ -8,7 +8,7 @@ events := @use("events.hb");
|
|||
recieve_key_event := fn(): ?KeyEvent {
|
||||
kevent := KeyEvent.(false, false, 0)
|
||||
|
||||
buf_id := buffer.search("PS/2 Keyboard\0")
|
||||
buf_id := buffer.search("PS/2 Keyboard")
|
||||
|
||||
// Read out of the Keyboard buffer here
|
||||
buffer.recv(KeyEvent, buf_id, &kevent)
|
||||
|
@ -23,7 +23,7 @@ recieve_key_event := fn(): ?KeyEvent {
|
|||
recieve_mouse_event := fn(): ?MouseEvent {
|
||||
mevent := MouseEvent.(0, 0, false, false, false)
|
||||
|
||||
buf_id := buffer.search("PS/2 Mouse\0")
|
||||
buf_id := buffer.search("PS/2 Mouse")
|
||||
|
||||
// Read out of the Mouse buffer here
|
||||
buffer.recv(MouseEvent, buf_id, &mevent)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.{string, memory, buffer, log} := @use("../../stn/src/lib.hb")
|
||||
.{string, memory, buffer, log} := @use("stn")
|
||||
|
||||
PCIAddress := struct {
|
||||
bus: u8,
|
||||
|
@ -51,9 +51,9 @@ check_device := fn(bus: u8, device: u8): PciDeviceInfo {
|
|||
pci_id := get_ids(bus, device, 0)
|
||||
|
||||
if pci_id.vendor == 0xFFFF {
|
||||
log.warn(":|\0")
|
||||
log.warn(":|")
|
||||
} else {
|
||||
log.info(":)\0")
|
||||
log.info(":)")
|
||||
}
|
||||
address := calculate_address(bus, device, 0, 0x8)
|
||||
reg2 := config_read32(bus, device, 0, 0x8)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.{Color, Surface, new_surface, put_surface} := @use("../lib.hb");
|
||||
.{log} := @use("../../../stn/src/lib.hb")
|
||||
.{Color, Surface, new_surface, put_surface} := @use("lib:render");
|
||||
.{log} := @use("stn")
|
||||
|
||||
BitmapFileHeader := packed struct {
|
||||
magic: u16,
|
||||
|
@ -37,7 +37,7 @@ from := fn(bmp: ^u8): ?Surface {
|
|||
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
|
||||
|
||||
if file_header.magic != 0x4D42 | info_header.width == 0 | info_header.height == 0 {
|
||||
log.error("Invalid BMP image.\0")
|
||||
log.error("Invalid BMP image.")
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.{log} := @use("../../../stn/src/lib.hb");
|
||||
.{Surface} := @use("../lib.hb")
|
||||
.{log} := @use("stn");
|
||||
.{Surface} := @use("lib:render")
|
||||
bmp := @use("bmp.hb")
|
||||
qoi := @use("qoi.hb")
|
||||
$BMP := 0x4D42
|
||||
|
@ -19,7 +19,7 @@ from := fn(file: ^u8): ?Surface {
|
|||
format := get_format(file)
|
||||
|
||||
if format == null {
|
||||
log.error("Could not detect image format.\0")
|
||||
log.error("Could not detect image format.")
|
||||
return null
|
||||
} else if format == BMP {
|
||||
return bmp.from(file)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
.{Color, Surface, new_surface} := @use("../lib.hb");
|
||||
.{log} := @use("../../../stn/src/lib.hb")
|
||||
.{Color, Surface, new_surface} := @use("lib:render");
|
||||
.{log} := @use("stn")
|
||||
|
||||
/* source:
|
||||
https://github.com/phoboslab/qoi/blob/master/qoi.h */
|
||||
|
@ -40,12 +40,12 @@ from := fn(qoi: ^u8): ?Surface {
|
|||
height := be_to_le(header.height)
|
||||
|
||||
if be_to_le(header.magic) != QOI_MAGIC | width == 0 | height == 0 | header.channels < 3 | header.channels > 4 {
|
||||
log.error("Invalid QOI image.\0")
|
||||
log.error("Invalid QOI image.")
|
||||
return null
|
||||
}
|
||||
|
||||
surface := Surface.new(width, height)
|
||||
index := @as([Color; 64], idk)
|
||||
index := @as([64]Color, idk)
|
||||
|
||||
run := 0
|
||||
px := Color.(0, 0, 0, 255)
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
|
||||
// safety: don't use before init() or you will get a memory access violation
|
||||
framebuffer := memory.dangling(Color)
|
||||
utf8_len_table := [u8].(0, 0, 2, 3)
|
||||
utf8_len_table := u8.[0, 0, 2, 3]
|
||||
|
||||
init := fn(doublebuffer: bool): Surface {
|
||||
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
|
||||
width := dt.get(uint, "framebuffer/fb0/width\0")
|
||||
height := dt.get(uint, "framebuffer/fb0/height\0")
|
||||
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr")
|
||||
width := dt.get(uint, "framebuffer/fb0/width")
|
||||
height := dt.get(uint, "framebuffer/fb0/height")
|
||||
if doublebuffer {
|
||||
return Surface.new(width, height)
|
||||
} else {
|
||||
|
@ -306,7 +306,7 @@ Surface := struct {
|
|||
}
|
||||
}
|
||||
|
||||
put_text := fn(self: Self, font: Font, pos: Vec2(uint), color: Color, str: ^u8): void {
|
||||
put_text := fn(self: Self, font: Font, pos: Vec2(uint), color: Color, str: []u8): void {
|
||||
cursor := Vec2(uint).(pos.x, pos.y)
|
||||
|
||||
max_y := self.height - font.height
|
||||
|
@ -314,48 +314,50 @@ Surface := struct {
|
|||
char_advance := font.width + font.char_gap
|
||||
self_width := self.width
|
||||
|
||||
loop if *str == 0 break else {
|
||||
i := 0
|
||||
|
||||
loop if i >= str.len break else {
|
||||
if cursor.y > max_y break
|
||||
|
||||
glyph_data := @as(^u8, idk)
|
||||
code_point := @as(uint, 0)
|
||||
|
||||
if (*str & 0x80) == 0 {
|
||||
if *str == 10 {
|
||||
if (str[i] & 0x80) == 0 {
|
||||
if str[i] == '\n' {
|
||||
cursor.x = pos.x
|
||||
cursor.y += next_line_y
|
||||
str += 1
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
|
||||
if font.unicode == null {
|
||||
if *str > font.num_glyphs {
|
||||
str += 1
|
||||
if str[i] > font.num_glyphs {
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
glyph_data = get_glyph(font, *str)
|
||||
glyph_data = get_glyph(font, str[i])
|
||||
} else {
|
||||
if *str < UNC_TABLE_SIZE {
|
||||
glyph_index := *(font.unicode + *str)
|
||||
if str[i] < UNC_TABLE_SIZE {
|
||||
glyph_index := *(font.unicode + str[i])
|
||||
if glyph_index == 0xFFFF {
|
||||
str += 1
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
glyph_data = font.data + glyph_index * font.bytes_per_glyph
|
||||
} else {
|
||||
str += 1
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
}
|
||||
str += 1
|
||||
i += 1
|
||||
} else if font.unicode != null {
|
||||
first_byte := *str
|
||||
first_byte := str[i]
|
||||
num_bytes := @as(uint, 0)
|
||||
|
||||
num_bytes = utf8_len_table[first_byte >> 5 & 0x3]
|
||||
|
||||
if num_bytes == 0 {
|
||||
str += 1
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -365,25 +367,25 @@ Surface := struct {
|
|||
bytes_processed := 1
|
||||
|
||||
loop if bytes_processed >= num_bytes break else {
|
||||
str += 1
|
||||
if *str == 0 | (*str & 0xC0) != 0x80 {
|
||||
i += 1
|
||||
if i == str.len | (str[i] & 0xC0) != 0x80 {
|
||||
valid_sequence = false
|
||||
}
|
||||
if valid_sequence == false {
|
||||
break
|
||||
}
|
||||
code_point = code_point << 6 | *str & 0x3F
|
||||
code_point = code_point << 6 | str[i] & 0x3F
|
||||
bytes_processed += 1
|
||||
}
|
||||
|
||||
if valid_sequence == false {
|
||||
str += 1
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
|
||||
str += 1
|
||||
i += 1
|
||||
|
||||
if code_point == 10 {
|
||||
if code_point == '\n' {
|
||||
cursor.x = pos.x
|
||||
cursor.y += next_line_y
|
||||
continue
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.{log, memory} := @use("../../stn/src/lib.hb")
|
||||
.{log, memory} := @use("stn")
|
||||
|
||||
PSF1Header := packed struct {
|
||||
magic: u16,
|
||||
|
@ -31,7 +31,7 @@ Font := struct {
|
|||
font_from_psf1 := fn(psf: ^u8): ?Font {
|
||||
header := @as(^PSF1Header, @bitcast(psf))
|
||||
if header.magic != 0x436 {
|
||||
log.error("failed to load psf font: not a psf1 font, idiot\0")
|
||||
log.error("failed to load psf font: not a psf1 font, idiot")
|
||||
return null
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ font_from_psf1 := fn(psf: ^u8): ?Font {
|
|||
font_from_psf2 := fn(psf: ^u8, unicode: bool): ?Font {
|
||||
header := @as(^PSF2Header, @bitcast(psf))
|
||||
if header.magic != 0x864AB572 {
|
||||
log.error("failed to load psf font: not a psf2 font, idiot\0")
|
||||
log.error("failed to load psf font: not a psf2 font, idiot")
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.{log, panic, memory} := @use("../lib.hb")
|
||||
.{log, panic, memory} := @use("stn")
|
||||
alloc_return := @use("alloc_return.hb")
|
||||
|
||||
/* the block size is 64 bytes, 64 blocks of 64 bytes.
|
||||
|
@ -30,7 +30,7 @@ BlockAlloc := struct {
|
|||
offset += 1
|
||||
return .(0, null)
|
||||
} else {
|
||||
log.info("Already Allocated\0")
|
||||
log.info("Already Allocated")
|
||||
}
|
||||
|
||||
// else {
|
||||
|
@ -40,7 +40,7 @@ BlockAlloc := struct {
|
|||
// if self.ptr != null {
|
||||
// return .(64, self.ptr + offset * 64)
|
||||
// } else {
|
||||
// // panic.panic("Allocator is not inited.\0")
|
||||
// // panic.panic("Allocator is not inited.")
|
||||
// // return .(0, null)
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
string := @use("string.hb")
|
||||
|
||||
$await := fn(buffer_id: uint): void {
|
||||
return @eca(7, buffer_id)
|
||||
}
|
||||
|
@ -22,20 +20,18 @@ $write_length := fn(length: uint, msg: ^u8, buffer_id: uint): void {
|
|||
|
||||
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}
|
||||
|
||||
create := fn(msg: ^u8): uint {
|
||||
// for some reason not inlining here breaks things
|
||||
return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
||||
$create := fn(msg: []u8): uint {
|
||||
return @eca(3, 0, BufferMsg.(0, msg.ptr, msg.len), @sizeof(BufferMsg))
|
||||
}
|
||||
|
||||
$create_nameless := fn(): uint {
|
||||
return @eca(1, 0)
|
||||
}
|
||||
|
||||
$delete_buffer := fn(buffer_id: uint): void {
|
||||
$delete := fn(buffer_id: uint): void {
|
||||
return @eca(2, buffer_id)
|
||||
}
|
||||
|
||||
search := fn(msg: ^u8): uint {
|
||||
// for some reason not inlining here breaks things
|
||||
return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
||||
$search := fn(msg: []u8): uint {
|
||||
return @eca(3, 0, BufferMsg.(3, msg.ptr, msg.len), @sizeof(BufferMsg))
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
.{string} := @use("../../stn/src/lib.hb")
|
||||
|
||||
get := fn($Expr: type, query: ^u8): Expr {
|
||||
return @eca(3, 5, query, string.length(query))
|
||||
$get := fn($Expr: type, query: []u8): Expr {
|
||||
return @eca(3, 5, query, query.len)
|
||||
}
|
|
@ -2,7 +2,7 @@ acs := @use("acs.hb");
|
|||
.{DiskID, FileID} := acs
|
||||
|
||||
// Paths without a node-disk component are to be treated as local files.
|
||||
// file_path := "DID:/test\0";
|
||||
// file_path := "DID:/test"
|
||||
Path := struct {
|
||||
// DiskID holds the host id
|
||||
disk_id: DiskID,
|
||||
|
|
273
sysdata/libraries/stn/src/fmt.hb
Normal file
273
sysdata/libraries/stn/src/fmt.hb
Normal file
|
@ -0,0 +1,273 @@
|
|||
.{Kind, usize, string, signed_int, panic, float, integer, memory, log: .{LogLevel}} := @use("stn")
|
||||
|
||||
fmt_int := fn(v: @Any(), str: []u8, radix: @TypeOf(v)): uint {
|
||||
is_negative := signed_int(@TypeOf(v)) & v < 0
|
||||
prefix_len := 0
|
||||
if is_negative {
|
||||
v = -v
|
||||
str[0] = '-'
|
||||
prefix_len += 1
|
||||
}
|
||||
|
||||
if radix == 16 {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0x".ptr)
|
||||
prefix_len += 2
|
||||
} else if radix == 2 {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0b".ptr)
|
||||
prefix_len += 2
|
||||
} else if radix == 8 {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0o".ptr)
|
||||
prefix_len += 2
|
||||
}
|
||||
|
||||
if v == 0 {
|
||||
str[prefix_len] = '0'
|
||||
return prefix_len + 1
|
||||
}
|
||||
|
||||
i := prefix_len
|
||||
loop if v <= 0 break else {
|
||||
remainder := v % radix
|
||||
v /= radix
|
||||
if remainder > 9 {
|
||||
str[i] = @intcast(remainder - 10 + 'A')
|
||||
} else {
|
||||
str[i] = @intcast(remainder + '0')
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
string.reverse(str[prefix_len..i])
|
||||
return i
|
||||
}
|
||||
|
||||
fmt_bool := fn(v: bool, str: []u8): uint {
|
||||
if v {
|
||||
*@as(^[4]u8, @bitcast(str.ptr)) = *@bitcast("true".ptr)
|
||||
return 4
|
||||
} else {
|
||||
*@as(^[5]u8, @bitcast(str.ptr)) = *@bitcast("false".ptr)
|
||||
return 5
|
||||
}
|
||||
}
|
||||
|
||||
$FP_TOLERANCE := 0.00000001
|
||||
|
||||
fmt_float := fn(v: @Any(), str: []u8, precision: uint, radix: int): uint {
|
||||
is_negative := v < 0
|
||||
|
||||
prefix_len := 0
|
||||
|
||||
if is_negative {
|
||||
v = -v
|
||||
str[0] = '-'
|
||||
prefix_len += 1
|
||||
}
|
||||
|
||||
if radix == 16 {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0x".ptr)
|
||||
prefix_len += 2
|
||||
} else if radix == 2 {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0b".ptr)
|
||||
prefix_len += 2
|
||||
} else if radix == 8 {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + prefix_len)) = *@bitcast("0o".ptr)
|
||||
prefix_len += 2
|
||||
}
|
||||
|
||||
integer_part := @fti(v)
|
||||
fractional_part := v - @itf(integer_part)
|
||||
|
||||
i := prefix_len
|
||||
loop if integer_part == 0 & i > prefix_len break else {
|
||||
remainder := integer_part % radix
|
||||
integer_part /= radix
|
||||
if remainder > 9 {
|
||||
str[i] = @intcast(remainder - 10 + 'A')
|
||||
} else {
|
||||
str[i] = @intcast(remainder + '0')
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
string.reverse(str[prefix_len..i])
|
||||
str[i] = '.'
|
||||
i += 1
|
||||
|
||||
p := precision
|
||||
loop if p <= 0 | fractional_part < FP_TOLERANCE break else {
|
||||
fractional_part *= @itf(radix)
|
||||
digit := @fti(fractional_part)
|
||||
if digit > 9 {
|
||||
str[i] = @intcast(digit - 10 + 'A')
|
||||
} else {
|
||||
str[i] = @intcast(digit + '0')
|
||||
}
|
||||
i += 1
|
||||
fractional_part -= @itf(digit)
|
||||
p -= 1
|
||||
}
|
||||
|
||||
return i
|
||||
}
|
||||
|
||||
fmt_container := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||
T2 := @TypeOf(v)
|
||||
kind := Kind.of(T2)
|
||||
i := 0
|
||||
len := 0
|
||||
if kind == .Struct {
|
||||
*@as(^[@intcast(@nameof(T2).len)]u8, @bitcast(str.ptr + len)) = *@bitcast(@nameof(T2).ptr)
|
||||
len += @nameof(T2).len;
|
||||
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr)
|
||||
len += 2
|
||||
} else if kind == .Slice {
|
||||
*@as(^[@intcast(@nameof(@ChildOf(T2)).len)]u8, @bitcast(str.ptr + len)) = *@bitcast(@nameof(@ChildOf(T2)).ptr)
|
||||
len += @nameof(@ChildOf(T2)).len;
|
||||
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".[".ptr)
|
||||
len += 2
|
||||
} else if kind == .Tuple {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr)
|
||||
len += 2
|
||||
}
|
||||
$loop {
|
||||
v_sub := v[i]
|
||||
len += @inline(format, v_sub, str[len..], opts)
|
||||
i += 1
|
||||
if i == @lenof(T2) break else {
|
||||
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(", ".ptr)
|
||||
len += 2
|
||||
}
|
||||
}
|
||||
if kind == .Struct | kind == .Tuple {
|
||||
*@as(^[1]u8, @bitcast(str.ptr + len)) = *@bitcast(")".ptr)
|
||||
len += 1
|
||||
} else if kind == .Slice {
|
||||
*@as(^[1]u8, @bitcast(str.ptr + len)) = *@bitcast("]".ptr)
|
||||
len += 1
|
||||
}
|
||||
return len
|
||||
}
|
||||
|
||||
fmt_nullable := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||
if v == null {
|
||||
*@as(^[4]u8, @bitcast(str.ptr)) = *@bitcast("null".ptr)
|
||||
return 4
|
||||
} else {
|
||||
return @inline(format, @as(@ChildOf(@TypeOf(v)), v), str, opts)
|
||||
}
|
||||
}
|
||||
|
||||
fmt_enum := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||
T := @TypeOf(v)
|
||||
len := @nameof(T).len;
|
||||
*@as(^[@intcast(@nameof(T).len)]u8, @bitcast(str.ptr)) = *@bitcast(@nameof(T).ptr);
|
||||
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr)
|
||||
len += 2
|
||||
len += fmt_int(@as(usize(T), @bitcast(v)), str[len..], 10);
|
||||
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(")".ptr)
|
||||
return len + 1
|
||||
}
|
||||
|
||||
/* TODO:
|
||||
* Custom formatters using struct methods (T._fmt(self, str): uint),
|
||||
* Format struct fields "Name.{a: x, b: y, c: z}"
|
||||
* Optionally tabulate
|
||||
* Add more FormatOption fields
|
||||
* Support scientific notation for floating point
|
||||
* Support format string
|
||||
*/
|
||||
|
||||
FormatOptions := struct {
|
||||
precision: uint = 2,
|
||||
radix: uint = 10,
|
||||
// temporarily here, will change later maybe
|
||||
log: LogLevel = .Info,
|
||||
}
|
||||
|
||||
/* SAFETY:
|
||||
* Assumes the buffer is wide enough for the formatted text and a null char
|
||||
* Does not clear the buffer for you
|
||||
*/
|
||||
|
||||
format := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
|
||||
T := @TypeOf(v)
|
||||
match Kind.of(T) {
|
||||
.Pointer => return @inline(fmt_int, @as(uint, @bitcast(v)), str, 16),
|
||||
.Builtin => {
|
||||
if integer(T) {
|
||||
return @inline(fmt_int, v, str, @intcast(opts.radix))
|
||||
} else if T == bool {
|
||||
return @inline(fmt_bool, v, str)
|
||||
} else if float(T) {
|
||||
return @inline(fmt_float, v, str, opts.precision, @intcast(opts.radix))
|
||||
}
|
||||
},
|
||||
.Opt => return @inline(fmt_nullable, v, str, opts),
|
||||
.Enum => return @inline(fmt_enum, v, str, opts),
|
||||
.Struct => return @inline(fmt_container, v, str, opts),
|
||||
.Tuple => return @inline(fmt_container, v, str, opts),
|
||||
.Slice => if T != []u8 return @inline(fmt_container, v, str, opts) else {
|
||||
i := 0
|
||||
loop if i == v.len break else {
|
||||
str[i] = v[i]
|
||||
i += 1
|
||||
}
|
||||
return v.len
|
||||
},
|
||||
_ => @error("Type: \"", T, "\" is not supported."),
|
||||
}
|
||||
}
|
||||
|
||||
format_with_str := fn(v: @Any(), read: []u8, write: []u8, opts: FormatOptions): uint {
|
||||
T := @TypeOf(v)
|
||||
n := string.count(read, '{')
|
||||
if n != string.count(read, '}') panic("Missing closing '}' in format string.")
|
||||
if Kind.of(T) == .Tuple {
|
||||
if @lenof(T) != n panic("Format string has different number of '{}' than args given.")
|
||||
m := 0
|
||||
i := 0
|
||||
j := 0
|
||||
$loop if m > @lenof(T) break else {
|
||||
if m == @lenof(T) {
|
||||
loop if i == read.len break else {
|
||||
write[j] = read[i]
|
||||
i += 1
|
||||
j += 1
|
||||
}
|
||||
m += 1
|
||||
} else {
|
||||
v2 := v[m]
|
||||
loop if i == read.len break else {
|
||||
if read[i] == '{' & read[i + 1] == '}' {
|
||||
j += format(v2, write[j..], opts)
|
||||
i += 2
|
||||
break
|
||||
} else {
|
||||
write[j] = read[i]
|
||||
i += 1
|
||||
j += 1
|
||||
}
|
||||
}
|
||||
m += 1
|
||||
}
|
||||
}
|
||||
return j
|
||||
} else if n > 1 {
|
||||
panic("Format string has multiple '{}' but value provided is not a tuple.")
|
||||
} else {
|
||||
i := 0
|
||||
j := 0
|
||||
loop if i == read.len break else {
|
||||
if read[i] == '{' & read[i + 1] == '}' {
|
||||
j += format(v, write[j..], opts)
|
||||
i += 2
|
||||
} else {
|
||||
write[j] = read[i]
|
||||
i += 1
|
||||
j += 1
|
||||
}
|
||||
}
|
||||
return j
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/;
|
||||
|
||||
.{math, random} := @use("../lib.hb")
|
||||
.{math, random} := @use("stn")
|
||||
|
||||
$ARBITRARY0 := 0x243F6A8885A308D3
|
||||
$ARBITRARY1 := 0x13198A2E03707344
|
||||
|
@ -38,7 +38,7 @@ $ARBITRARY6 := 0xC0AC29B7C97C50DD
|
|||
$ARBITRARY7 := 0x3F84D5B5B5470917
|
||||
$ARBITRARY8 := 0x9216D5D98979FB1B
|
||||
$ARBITRARY9 := 0xD1310BA698DFB5AC
|
||||
$FIXED_GLOBAL_SEED := [uint].(ARBITRARY4, ARBITRARY5, ARBITRARY6, ARBITRARY7)
|
||||
$FIXED_GLOBAL_SEED := uint.[ARBITRARY4, ARBITRARY5, ARBITRARY6, ARBITRARY7]
|
||||
|
||||
global_seed := 0
|
||||
|
||||
|
@ -103,7 +103,7 @@ hash_bytes_long := fn(bytes: ^u8, len: uint, s0: uint, s1: uint, s2: uint, s3: u
|
|||
|
||||
if remainder > 0 {
|
||||
remainder_start := bytes + len - math.max(uint, remainder, 16)
|
||||
return hash_bytes_medium(remainder_start, math.max(uint, remainder, 16), s0, s1, fold_seed)
|
||||
return @inline(hash_bytes_medium, remainder_start, math.max(uint, remainder, 16), s0, s1, fold_seed)
|
||||
}
|
||||
|
||||
return s0 ^ s1
|
||||
|
@ -159,17 +159,9 @@ FoldHasher := struct {
|
|||
}
|
||||
self.accumulator = folded_multiply(s0, s1)
|
||||
} else if len < 256 {
|
||||
self.accumulator = hash_bytes_medium(bytes, len, s0, s1, self.fold_seed)
|
||||
self.accumulator = @inline(hash_bytes_medium, bytes, len, s0, s1, self.fold_seed)
|
||||
} else {
|
||||
self.accumulator = hash_bytes_long(
|
||||
bytes,
|
||||
len,
|
||||
s0,
|
||||
s1,
|
||||
self.expand_seed2,
|
||||
self.expand_seed3,
|
||||
self.fold_seed,
|
||||
)
|
||||
self.accumulator = @inline(hash_bytes_long, bytes, len, s0, s1, self.expand_seed2, self.expand_seed3, self.fold_seed)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
acs := @use("acs.hb")
|
||||
allocators := @use("alloc/lib.hb")
|
||||
fmt := @use("fmt.hb")
|
||||
hashers := @use("hash/lib.hb")
|
||||
string := @use("string.hb")
|
||||
log := @use("log.hb")
|
||||
|
@ -12,17 +13,30 @@ dt := @use("dt.hb")
|
|||
process := @use("process.hb")
|
||||
sleep := @use("sleep.hb")
|
||||
|
||||
// todo: replace with comptime message (for zero cost)
|
||||
panic := fn(message: ?^u8): never {
|
||||
log.error("Error: Panic Called, Message:\0")
|
||||
if message == null {
|
||||
log.error("None\0")
|
||||
} else {
|
||||
log.error(message)
|
||||
}
|
||||
panic := fn(message: ?[]u8): never {
|
||||
log.printf("HBLang Panic: {}", message, .{log: .Error})
|
||||
die
|
||||
}
|
||||
|
||||
Kind := enum {
|
||||
Builtin,
|
||||
Struct,
|
||||
Tuple,
|
||||
Enum,
|
||||
Union,
|
||||
Pointer,
|
||||
Slice,
|
||||
Opt,
|
||||
Function,
|
||||
Template,
|
||||
Global,
|
||||
Const,
|
||||
Module,
|
||||
$of := fn($T: type): Self {
|
||||
return @bitcast(@kindof(T))
|
||||
}
|
||||
}
|
||||
|
||||
$unsigned_int := fn($T: type): bool {
|
||||
return T == uint | T == u8 | T == u16 | T == u32
|
||||
}
|
||||
|
@ -39,10 +53,14 @@ $float := fn($T: type): bool {
|
|||
return T == f32 | T == f64
|
||||
}
|
||||
|
||||
$primitive := fn($T: type): bool {
|
||||
return integer(T) | float(T) | T == bool
|
||||
$usize := fn($T: type): type {
|
||||
if @sizeof(T) == 1 return u8 else if @sizeof(T) == 2 return u16 else if @sizeof(T) == 4 return u32 else return uint
|
||||
}
|
||||
|
||||
$float_bytes := fn($T: type): type {
|
||||
if T == f64 return uint else if T == f32 return u32
|
||||
$bits := fn($T: type): usize(T) {
|
||||
return @sizeof(T) << 3
|
||||
}
|
||||
|
||||
$bitmask := fn($T: type): usize(T) {
|
||||
return -1
|
||||
}
|
|
@ -1,13 +1,41 @@
|
|||
string := @use("string.hb")
|
||||
.{string, fmt, memory} := @use("stn")
|
||||
|
||||
LogMsg := packed struct {level: u8, string: ^u8, strlen: uint}
|
||||
LogMsg := packed struct {level: LogLevel, string: ^u8, strlen: uint}
|
||||
|
||||
log := fn(level: u8, message: ^u8): void {
|
||||
return @eca(3, 1, LogMsg.(level, message, @inline(string.length, message)), @sizeof(LogMsg))
|
||||
LogLevel := enum {
|
||||
Error,
|
||||
Warn,
|
||||
Info,
|
||||
Debug,
|
||||
Trace,
|
||||
}
|
||||
|
||||
error := fn(message: ^u8): void return @inline(log, 0, message)
|
||||
warn := fn(message: ^u8): void return @inline(log, 1, message)
|
||||
info := fn(message: ^u8): void return @inline(log, 2, message)
|
||||
debug := fn(message: ^u8): void return @inline(log, 3, message)
|
||||
trace := fn(message: ^u8): void return @inline(log, 4, message)
|
||||
$log := fn(level: LogLevel, message: []u8): void {
|
||||
return @eca(3, 1, LogMsg.(level, message.ptr, message.len), @sizeof(LogMsg))
|
||||
}
|
||||
|
||||
$error := fn(message: []u8): void return log(LogLevel.Error, message)
|
||||
$warn := fn(message: []u8): void return log(LogLevel.Warn, message)
|
||||
$info := fn(message: []u8): void return log(LogLevel.Info, message)
|
||||
$debug := fn(message: []u8): void return log(LogLevel.Debug, message)
|
||||
$trace := fn(message: []u8): void return log(LogLevel.Trace, message)
|
||||
|
||||
print_buffer := memory.dangling(u8)
|
||||
|
||||
print := fn(v: @Any(), opts: fmt.FormatOptions): void {
|
||||
if print_buffer == memory.dangling(u8) {
|
||||
print_buffer = memory.request_page(1)
|
||||
}
|
||||
len := @inline(fmt.format, v, print_buffer[0..memory.PAGE_SIZE], opts)
|
||||
@eca(3, 1, LogMsg.(opts.log, print_buffer, len), @sizeof(LogMsg))
|
||||
memory.set(u8, &0, print_buffer, len)
|
||||
}
|
||||
|
||||
printf := fn(str: []u8, v: @Any(), opts: fmt.FormatOptions): void {
|
||||
if print_buffer == memory.dangling(u8) {
|
||||
print_buffer = memory.request_page(1)
|
||||
}
|
||||
len := @inline(fmt.format_with_str, v, str, print_buffer[0..memory.PAGE_SIZE], opts)
|
||||
@eca(3, 1, LogMsg.(opts.log, print_buffer, len), @sizeof(LogMsg))
|
||||
memory.set(u8, &0, print_buffer, len)
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -1,216 +1,172 @@
|
|||
length := fn(ptr: ^u8): uint {
|
||||
len := 0
|
||||
loop if *(ptr + len) == 0 return len else len += 1
|
||||
}
|
||||
// todo: splice function
|
||||
|
||||
display_int := fn(num: int, p: ^u8, radix: uint): ^u8 {
|
||||
is_negative := num < 0
|
||||
if is_negative num = -num
|
||||
|
||||
ptr := p
|
||||
|
||||
if num == 0 {
|
||||
*ptr = 0x30;
|
||||
*(ptr + 1) = 0
|
||||
return p
|
||||
}
|
||||
|
||||
loop if num == 0 break else {
|
||||
remainder := num % @bitcast(radix)
|
||||
num /= @bitcast(radix);
|
||||
*ptr = @intcast(remainder + 0x30)
|
||||
if remainder > 9 {
|
||||
*ptr = @intcast(remainder - 10 + 0x41)
|
||||
}
|
||||
ptr += 1
|
||||
}
|
||||
|
||||
if is_negative {
|
||||
*ptr = 0x2D
|
||||
ptr += 1
|
||||
}
|
||||
// ! it gets broked when you do this ??
|
||||
// *ptr = 0
|
||||
|
||||
@inline(reverse, p)
|
||||
return p
|
||||
}
|
||||
|
||||
reverse := fn(s: ^u8): void {
|
||||
j := s + @inline(length, s) - 1
|
||||
reverse := fn(str: []u8): void {
|
||||
if str.len == 0 return;
|
||||
j := str.len - 1
|
||||
i := 0
|
||||
temp := @as(u8, 0)
|
||||
loop if s < j {
|
||||
temp = *s;
|
||||
*s = *j;
|
||||
*j = temp
|
||||
s += 1
|
||||
loop if i < j {
|
||||
temp = str[i]
|
||||
str[i] = str[j]
|
||||
str[j] = temp
|
||||
i += 1
|
||||
j -= 1
|
||||
} else return
|
||||
}
|
||||
|
||||
equals := fn(lhs: ^u8, rhs: ^u8): bool {
|
||||
if lhs == rhs {
|
||||
equals := fn(lhs: []u8, rhs: []u8): bool {
|
||||
if lhs.len != rhs.len return false
|
||||
if lhs.ptr == rhs.ptr return true
|
||||
i := 0
|
||||
loop if i == lhs.len break else {
|
||||
if lhs[i] != rhs[i] return false
|
||||
i += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
loop if *lhs != *rhs {
|
||||
return false
|
||||
} else if *lhs == 0 {
|
||||
return true
|
||||
} else {
|
||||
lhs += 1
|
||||
rhs += 1
|
||||
|
||||
clear := fn(str: []u8): void {
|
||||
i := 0
|
||||
loop if i == str.len break else {
|
||||
str[i] = 0
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
clear := fn(ptr: ^u8): void {
|
||||
loop if *ptr == 0 break else {
|
||||
*ptr = 0
|
||||
ptr += 1
|
||||
}
|
||||
}
|
||||
|
||||
split_once := fn(haystack: ^u8, needle: u8): ?^u8 {
|
||||
loop if *haystack == needle return haystack else if *haystack == 0 return null else haystack += 1
|
||||
}
|
||||
|
||||
split_once_str := fn(haystack: ^u8, needle: ^u8): ?^u8 {
|
||||
if *needle == 0 return null
|
||||
|
||||
loop if *haystack == 0 return null else {
|
||||
if *haystack == *needle {
|
||||
h := haystack
|
||||
n := needle
|
||||
|
||||
split_once := fn(haystack: []u8, needle: @Any()): ?struct {left: []u8, right: []u8} {
|
||||
T := @TypeOf(needle)
|
||||
i := 0
|
||||
if T == []u8 {
|
||||
if needle.len == 0 return null
|
||||
loop {
|
||||
n += 1
|
||||
h += 1
|
||||
if *n == 0 {
|
||||
return haystack
|
||||
} else if *h == 0 | *h != *n {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
haystack += 1
|
||||
}
|
||||
}
|
||||
|
||||
Split := struct {
|
||||
str: ^u8,
|
||||
needle: u8,
|
||||
done: bool,
|
||||
}
|
||||
|
||||
split := fn(iter: ^u8, needle: u8): Split {
|
||||
return .(
|
||||
iter,
|
||||
needle,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
iter_split := fn(iter: ^Split): ?^u8 {
|
||||
if iter.done | *iter.str == 0 {
|
||||
return null
|
||||
}
|
||||
|
||||
next := split_once(iter.str + 1, iter.needle)
|
||||
|
||||
if next == null {
|
||||
iter.done = true
|
||||
return iter.str
|
||||
}
|
||||
s := iter.str
|
||||
iter.str = next + 1
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
SplitStr := struct {
|
||||
str: ^u8,
|
||||
needle: ^u8,
|
||||
done: bool,
|
||||
}
|
||||
|
||||
split_str := fn(iter: ^u8, needle: ^u8): SplitStr {
|
||||
return .(
|
||||
iter,
|
||||
needle,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
iter_split_str := fn(iter: ^SplitStr): ?^u8 {
|
||||
if iter.done | *iter.str == 0 {
|
||||
return null
|
||||
}
|
||||
|
||||
next := split_once_str(iter.str, iter.needle)
|
||||
|
||||
if next == null {
|
||||
iter.done = true
|
||||
return iter.str
|
||||
}
|
||||
|
||||
s := iter.str
|
||||
|
||||
iter.str = next + length(iter.needle)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
find_once := fn(haystack: ^u8, needle: u8): ?uint {
|
||||
return @bitcast(@inline(split_once, haystack, needle) - haystack)
|
||||
}
|
||||
|
||||
find_once_str := fn(haystack: ^u8, needle: ^u8): ?uint {
|
||||
return @bitcast(@inline(split_once_str, haystack, needle) - haystack)
|
||||
}
|
||||
|
||||
count := fn(haystack: ^u8, needle: ^u8): uint {
|
||||
c := 0
|
||||
loop if *haystack == needle {
|
||||
c += 1
|
||||
haystack += 1
|
||||
} else if *haystack == 0 return c else haystack += 1
|
||||
}
|
||||
|
||||
count_str := fn(haystack: ^u8, needle: ^u8): uint {
|
||||
if *needle == 0 return 0
|
||||
c := 0
|
||||
loop if *haystack == 0 return c else {
|
||||
if *haystack == *needle {
|
||||
h := haystack
|
||||
n := needle
|
||||
|
||||
if i + needle.len > haystack.len return null
|
||||
if haystack[i] == needle[0] {
|
||||
matches := true
|
||||
n := 1
|
||||
loop {
|
||||
if n == needle.len break
|
||||
if haystack[i + n] != needle[n] {
|
||||
matches = false
|
||||
break
|
||||
}
|
||||
n += 1
|
||||
h += 1
|
||||
if *n == 0 {
|
||||
c += 1
|
||||
break
|
||||
} else if *h == 0 | *h != *n {
|
||||
break
|
||||
}
|
||||
|
||||
if matches return .(haystack[0..i], haystack[i + needle.len..])
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
haystack += 1
|
||||
} else if T == u8 {
|
||||
loop {
|
||||
if haystack[i] == needle {
|
||||
return .(haystack[0..i], haystack[i + 1..])
|
||||
} else if i == haystack.len return null
|
||||
i += 1
|
||||
}
|
||||
} else {
|
||||
@error("Type of needle must be []u8 or u8.")
|
||||
}
|
||||
}
|
||||
|
||||
left_trim := fn(str: ^u8, sub: ^u8): ^u8 {
|
||||
original := str
|
||||
if *str == *sub {
|
||||
loop if *sub == 0 {
|
||||
return str
|
||||
} else if *str != *sub {
|
||||
return original
|
||||
} else if *str == 0 {
|
||||
return original
|
||||
split := fn(iter: []u8, needle: @Any()): struct {
|
||||
str: []u8,
|
||||
needle: @TypeOf(needle),
|
||||
done: bool,
|
||||
|
||||
next := fn(self: ^Self): ?[]u8 {
|
||||
if self.done return null;
|
||||
|
||||
splits := split_once(self.str, self.needle)
|
||||
if splits != null {
|
||||
self.str = splits.right
|
||||
return splits.left
|
||||
} else {
|
||||
str += 1
|
||||
sub += 1
|
||||
self.done = true
|
||||
return self.str
|
||||
}
|
||||
}
|
||||
} {
|
||||
T := @TypeOf(needle)
|
||||
if T != []u8 & T != u8 {
|
||||
@error("Type of needle must be []u8 or u8.")
|
||||
}
|
||||
return .(iter, needle, false)
|
||||
}
|
||||
|
||||
chars := fn(iter: []u8): struct {
|
||||
str: []u8,
|
||||
|
||||
next := fn(self: ^Self): ?u8 {
|
||||
if self.str.len == 0 return null
|
||||
self.str = self.str[1..]
|
||||
return self.str[0]
|
||||
}
|
||||
} {
|
||||
return .(iter)
|
||||
}
|
||||
|
||||
count := fn(haystack: []u8, needle: @Any()): uint {
|
||||
T := @TypeOf(needle)
|
||||
i := 0
|
||||
c := 0
|
||||
if T == []u8 {
|
||||
if needle.len == 0 return null
|
||||
loop {
|
||||
if i + needle.len > haystack.len return c
|
||||
if haystack[i] == needle[0] {
|
||||
matches := true
|
||||
n := 1
|
||||
loop {
|
||||
if n == needle.len break
|
||||
if haystack[i + n] != needle[n] {
|
||||
matches = false
|
||||
break
|
||||
}
|
||||
n += 1
|
||||
}
|
||||
|
||||
if matches c += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
} else if T == u8 {
|
||||
loop {
|
||||
if haystack[i] == needle c += 1 else if i == haystack.len return c
|
||||
i += 1
|
||||
}
|
||||
} else {
|
||||
@error("Type of needle must be []u8 or u8.")
|
||||
}
|
||||
}
|
||||
|
||||
left_trim := fn(str: []u8, sub: []u8): []u8 {
|
||||
i := 0
|
||||
if str[0] == sub[0] {
|
||||
loop if i == sub.len {
|
||||
return str[i..str.len]
|
||||
} else if str[i] != sub[i] | i == str.len {
|
||||
break
|
||||
} else {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
right_trim := fn(str: []u8, sub: []u8): []u8 {
|
||||
i := 0
|
||||
if str[str.len - 1] == sub[sub.len - 1] {
|
||||
loop if i == sub.len {
|
||||
return str[0..str.len - i]
|
||||
} else if str[str.len - i - 1] != sub[sub.len - i - 1] | i == str.len {
|
||||
break
|
||||
} else {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
trim := fn(str: []u8, sub: []u8): []u8 {
|
||||
return right_trim(left_trim(str, sub), sub)
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
.{math: .{Vec2}, buffer, log, memory, string} := @use("../../stn/src/lib.hb");
|
||||
.{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb");
|
||||
.{Surface, Color} := @use("../../render/src/lib.hb")
|
||||
.{math: .{Vec2}, buffer, log, memory, string} := @use("stn");
|
||||
.{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("lib:sunset_proto");
|
||||
.{Surface, Color} := @use("lib:render")
|
||||
|
||||
// ! in the future this should be safely handled
|
||||
channel := Channel.(0, 0)
|
||||
|
||||
find_server := fn(): void {
|
||||
log.info("client: locating server\0")
|
||||
log.info("client: locating server")
|
||||
channel2 := await_channel()
|
||||
channel.server = channel2.server
|
||||
channel.client = channel2.client
|
||||
log.info("client: server located\0")
|
||||
log.info("client: server located")
|
||||
}
|
||||
|
||||
new := fn(props: WindowProps): ?Window {
|
||||
|
@ -19,13 +19,13 @@ new := fn(props: WindowProps): ?Window {
|
|||
if response.header.kind != message.ack {
|
||||
return null
|
||||
}
|
||||
log.info("client: recv ack\0")
|
||||
log.info("client: recv ack")
|
||||
send_message(WindowProps, message.props, props, response.body.server)
|
||||
windowdata := await_message(WindowData, response.body.client)
|
||||
if windowdata.header.kind != message.ack {
|
||||
return null
|
||||
}
|
||||
log.info("client: recv windowdata\0")
|
||||
log.info("client: recv windowdata")
|
||||
surface := Surface.new(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y)
|
||||
return .(windowdata.body, surface)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
.{math: .{Vec2}, buffer, memory} := @use("stn");
|
||||
.{Surface} := @use("../../render/src/lib.hb")
|
||||
.{Surface} := @use("lib:render")
|
||||
|
||||
$BUFFER_SERVER := "sunset_server\0"
|
||||
$BUFFER_CLIENT := "sunset_client\0"
|
||||
$BUFFER_SERVER := "sunset_server"
|
||||
$BUFFER_CLIENT := "sunset_client"
|
||||
|
||||
Channel := packed struct {
|
||||
client: uint,
|
||||
|
@ -85,8 +85,7 @@ Message := fn($Expr: type): type {
|
|||
WindowProps := struct {
|
||||
position: Vec2(uint),
|
||||
dimensions: Vec2(uint),
|
||||
// ! replace with owned string type later
|
||||
title: ^u8,
|
||||
title: []u8,
|
||||
}
|
||||
|
||||
WindowData := struct {
|
||||
|
|
|
@ -6,28 +6,28 @@ WindowServer := struct {
|
|||
window_count: uint,
|
||||
channel: Channel,
|
||||
// ! replace this with a collection when we get an allocator
|
||||
windows: [?Window; 10],
|
||||
windows: [10]?Window,
|
||||
font: text.Font,
|
||||
}
|
||||
|
||||
// ! in the future this should be safely handled
|
||||
server := @as(WindowServer, idk)
|
||||
|
||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
||||
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||
|
||||
start := fn(): void {
|
||||
font := text.font_from_psf2(@bitcast(&psf), false)
|
||||
if font == null {
|
||||
log.error("server: failed to load asset\0")
|
||||
log.error("server: failed to load asset")
|
||||
return
|
||||
}
|
||||
server = .(
|
||||
0,
|
||||
.{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)},
|
||||
.(null, null, null, null, null, null, null, null, null, null),
|
||||
.[null, null, null, null, null, null, null, null, null, null],
|
||||
@as(text.Font, font),
|
||||
)
|
||||
log.info("server: started server\0")
|
||||
log.info("server: started server")
|
||||
}
|
||||
|
||||
incoming := fn(): bool {
|
||||
|
@ -36,14 +36,14 @@ incoming := fn(): bool {
|
|||
return true
|
||||
}
|
||||
if msg.kind == message.syn {
|
||||
log.info("server: recv syn\0")
|
||||
log.info("server: recv syn")
|
||||
channel := Channel.(buffer.create_nameless(), buffer.create_nameless())
|
||||
send_message(Channel, message.ack, channel, server.channel.client)
|
||||
props := await_message(WindowProps, channel.server)
|
||||
if props.header.kind != message.props {
|
||||
return true
|
||||
}
|
||||
log.info("server: recv props\0")
|
||||
log.info("server: recv props")
|
||||
// ! do inspection of requested props here
|
||||
data := WindowData.(props.body, channel, permissions.default)
|
||||
send_message(WindowData, message.ack, data, channel.client)
|
||||
|
@ -51,8 +51,7 @@ incoming := fn(): bool {
|
|||
// decorations
|
||||
{
|
||||
title := data.props.title
|
||||
title_length := string.length(title)
|
||||
deco_length := title_length * 10
|
||||
deco_length := title.len * 10
|
||||
// draw the window tab bar
|
||||
surface.put_filled_rect(.(0, 0), .(data.props.dimensions.x + DECO_WIDTH + deco_length, DECO_HEIGHT_TOP), DECO_COLOUR)
|
||||
// Draw the window tab
|
||||
|
@ -101,7 +100,8 @@ collect_frames := fn(): void {
|
|||
send_header(message.ack, window.data.channel.client)
|
||||
ptr := await_message(^Color, window.data.channel.server)
|
||||
if ptr.header.kind != message.ack {
|
||||
return
|
||||
i += 1
|
||||
continue
|
||||
}
|
||||
window.surface.put_surface(
|
||||
Surface.(
|
||||
|
|
|
@ -1,46 +1,43 @@
|
|||
.{log} := @use("../../../libraries/stn/src/lib.hb")
|
||||
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||
render := @use("../../../libraries/render/src/lib.hb")
|
||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{Vec2} := stn.math
|
||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
||||
stn := @use("stn")
|
||||
sunset := @use("lib:sunset_proto")
|
||||
render := @use("lib:render")
|
||||
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||
horizon_api := @use("lib:horizon_api");
|
||||
|
||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
||||
.{Vec2} := stn.math;
|
||||
.{log} := stn;
|
||||
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
||||
|
||||
main := fn(): void {
|
||||
sunset.client.find_server()
|
||||
|
||||
window := sunset.client.new(.(.(400, 100), .(400, 300), "ableFetch!\0"))
|
||||
window := sunset.client.new(.(.(10, 10), .(400, 300), "ableFetch!"))
|
||||
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false))
|
||||
// pos := Vec2(uint).(1, 100)
|
||||
|
||||
if window == null {
|
||||
log.error("got no window\0")
|
||||
log.error("got no window")
|
||||
return
|
||||
}
|
||||
|
||||
text_label := Label.new_label("kernel : akern 0.2.0\0", 300)
|
||||
text_label.set_color(sunset.server.DECO_COLOUR, render.BLACK)
|
||||
text_label := Label.new_label("kernel : akern 0.2.0", 300)
|
||||
text_label_2 := Label.new_label("os : ableos", 300)
|
||||
text_label_3 := Label.new_label("wm : sunset", 300)
|
||||
text_label.set_color(render.BLACK, render.WHITE)
|
||||
|
||||
text_label_2 := Label.new_label("os : ableos\0", 300)
|
||||
text_label_2.set_color(sunset.server.DECO_COLOUR, render.BLACK)
|
||||
text_label_3 := Label.new_label("wm : sunset\0", 300)
|
||||
text_label_3.set_color(sunset.server.DECO_COLOUR, render.BLACK)
|
||||
text_label_2.set_color(render.BLACK, render.WHITE)
|
||||
text_label_3.set_color(render.BLACK, render.WHITE)
|
||||
|
||||
pos1 := Vec2(uint).(1, 1)
|
||||
pos2 := Vec2(uint).(1, 20)
|
||||
pos3 := Vec2(uint).(1, 40)
|
||||
|
||||
render_label_to_surface(window.surface, text_label, font, pos1)
|
||||
render_label_to_surface(window.surface, text_label_2, font, pos2)
|
||||
render_label_to_surface(window.surface, text_label_3, font, pos3)
|
||||
loop {
|
||||
render.clear(window.surface, render.BLACK)
|
||||
// render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 40), false)
|
||||
pos := Vec2(uint).(1, 100)
|
||||
|
||||
render_label_to_surface(window.surface, text_label, font, pos)
|
||||
pos = Vec2(uint).(1, 120)
|
||||
|
||||
render_label_to_surface(window.surface, text_label_2, font, pos)
|
||||
|
||||
pos = Vec2(uint).(1, 140)
|
||||
render_label_to_surface(window.surface, text_label_3, font, pos)
|
||||
|
||||
// stn.log.info("AAAA")
|
||||
_ = sunset.client.send_frame(window)
|
||||
// stn.sleep.sleep_until_interrupt(100)
|
||||
}
|
||||
}
|
5
sysdata/programs/angels_halo/README.md
Normal file
5
sysdata/programs/angels_halo/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# angels_halo
|
||||
|
||||
A Minix 3 style reincarnation service.
|
||||
|
||||
Running in the background restarting your drivers.
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "sunset_client_2"
|
||||
authors = ["koniifer"]
|
||||
name = "angels_halo"
|
||||
authors = ["able"]
|
||||
|
||||
[dependants.libraries]
|
||||
|
7
sysdata/programs/angels_halo/pkg.lisp
Normal file
7
sysdata/programs/angels_halo/pkg.lisp
Normal file
|
@ -0,0 +1,7 @@
|
|||
(pkg angels-halo
|
||||
(authors ("able"))
|
||||
(version 0 1 0))
|
||||
|
||||
(dependencies
|
||||
(libraries ())
|
||||
(programs (hblang)))
|
18
sysdata/programs/angels_halo/src/main.hb
Normal file
18
sysdata/programs/angels_halo/src/main.hb
Normal file
|
@ -0,0 +1,18 @@
|
|||
stn := @use("stn");
|
||||
.{log} := stn;
|
||||
.{ProcessID} := stn.acs
|
||||
|
||||
Strategy := enum {
|
||||
None,
|
||||
Restart,
|
||||
}
|
||||
|
||||
MonitoredProcess := struct {
|
||||
pid: ProcessID,
|
||||
}
|
||||
|
||||
main := fn(): int {
|
||||
log.info("Angels Halo reincarnation server started.")
|
||||
|
||||
return 0
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
.{memory, buffer, log} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{memory, buffer, log} := @use("stn");
|
||||
.{inb, outb} := memory
|
||||
|
||||
regs := @use("regs.hb");
|
||||
|
@ -28,7 +28,7 @@ sloop := fn(i: u8): void {
|
|||
// identify := fn(): u8 {
|
||||
// a := inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||
// outb(ATA_PRIMARY_DRIVE_HEAD, 0xA0)
|
||||
// log.info("Primary drive head set.\0")
|
||||
// log.info("Primary drive head set.")
|
||||
|
||||
// a = inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||
// outb(ATA_PRIMARY_SECCOUNT, 0)
|
||||
|
@ -43,10 +43,10 @@ sloop := fn(i: u8): void {
|
|||
// outb(ATA_PRIMARY_COMM_REGSTAT, 0xE7)
|
||||
|
||||
// status := inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||
// log.info("Waiting for status.\0")
|
||||
// log.info("Waiting for status.")
|
||||
// loop {
|
||||
// if (status & STAT_BSY) == 0 {
|
||||
// log.info("Status got.\0")
|
||||
// log.info("Status got.")
|
||||
// break
|
||||
// } else {
|
||||
// sloop()
|
||||
|
@ -54,14 +54,14 @@ sloop := fn(i: u8): void {
|
|||
// status = inb(ATA_PRIMARY_COMM_REGSTAT)
|
||||
// }
|
||||
// if status == 0 {
|
||||
// log.error("No drive detected.\0")
|
||||
// log.error("No drive detected.")
|
||||
|
||||
// return 0
|
||||
// }
|
||||
// log.info("Status indicates presence of a drive. Polling while STAT_BSY... \0")
|
||||
// log.info("Status indicates presence of a drive. Polling while STAT_BSY... ")
|
||||
// loop {
|
||||
// if (status & STAT_BSY) == 0 {
|
||||
// log.info("Status got.\0")
|
||||
// log.info("Status got.")
|
||||
// break
|
||||
// } else {
|
||||
// sloop()
|
||||
|
@ -73,7 +73,7 @@ sloop := fn(i: u8): void {
|
|||
// hi := inb(ATA_PRIMARY_LBA_HI)
|
||||
|
||||
// if (mid | hi) == 0 {
|
||||
// log.error("The drive is not ATA. (Who knows what it is.)\0")
|
||||
// log.error("The drive is not ATA. (Who knows what it is.)")
|
||||
// return 0
|
||||
// }
|
||||
|
||||
|
@ -81,7 +81,7 @@ sloop := fn(i: u8): void {
|
|||
// }
|
||||
|
||||
drive_reset := fn(): void {
|
||||
log.warn("Drive resetting.\0")
|
||||
log.warn("Drive resetting.")
|
||||
outb(ATA_PRIMARY_DEVCTL, 0x4)
|
||||
sloop(4)
|
||||
outb(ATA_PRIMARY_DEVCTL, 0x0)
|
||||
|
@ -100,17 +100,17 @@ poll := fn(): u8 {
|
|||
|
||||
status = inb(ATA_PRIMARY_IO + ATA_REG_STAT)
|
||||
if (status & ATA_SR_DF) == 0 {
|
||||
log.error("ATA PRIMARY DRIVE FAULT\0")
|
||||
log.error("ATA PRIMARY DRIVE FAULT")
|
||||
return 1
|
||||
}
|
||||
|
||||
if (status & ATA_SR_ERR) == 0 {
|
||||
log.error("ATA PRIMARY ERR\0")
|
||||
log.error("ATA PRIMARY ERR")
|
||||
return 2
|
||||
}
|
||||
|
||||
if (status & ATA_SR_DRQ) == 0 {
|
||||
log.error("ATA PRIMARY DRQ\0")
|
||||
log.error("ATA PRIMARY DRQ")
|
||||
return 3
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ main := fn(): int {
|
|||
a := inb(0x4600)
|
||||
b := inb(0x4700)
|
||||
|
||||
// c := buffer.search("XNumber\0")
|
||||
// c := buffer.search("XNumber")
|
||||
// c := identify()
|
||||
|
||||
d := drive_reset()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
READ_ONLY := @as(u32, 0x1)
|
||||
HIDDEN := @as(u32, 0x2)
|
||||
SYSTEM := @as(u32, 0x4)
|
||||
VOLUME_ID := @as(u32, 0x8)
|
||||
DIRECTORY := @as(u32, 0x10)
|
||||
ARCHIVE := @as(u32, 0x20)
|
||||
$READ_ONLY := 0x1
|
||||
$HIDDEN := 0x2
|
||||
$SYSTEM := 0x4
|
||||
$VOLUME_ID := 0x8
|
||||
$DIRECTORY: 0x10
|
||||
$ARCHIVE := 0x20
|
||||
LFN := READ_ONLY | HIDDEN | SYSTEM | VOLUME_ID
|
|
@ -1,19 +1,19 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{string, memory, buffer, log} := stn
|
||||
|
||||
VALID_JUMP_BYTES := [u8].(0xEB, 0x3C, 0x90)
|
||||
VALID_JUMP_BYTES := u8.[0xEB, 0x3C, 0x90]
|
||||
|
||||
OemIdent := struct {
|
||||
dos_version: [u8; 8],
|
||||
dos_version_name: [u8; 8],
|
||||
dos_version: [8]u8,
|
||||
dos_version_name: [8]u8,
|
||||
|
||||
new := fn(major: int, minor: int): OemIdent {
|
||||
return .(.(0, 0, 0, 0, 0, 0, 0, 0), .(0, 0, 0, 0, 0, 0, 0, 0))
|
||||
return .(.[0, 0, 0, 0, 0, 0, 0, 0], .[0, 0, 0, 0, 0, 0, 0, 0])
|
||||
}
|
||||
}
|
||||
|
||||
BiosParameterBlock := struct {
|
||||
jump_bytes: [u8; 3],
|
||||
jump_bytes: [3]u8,
|
||||
oem_ident: OemIdent,
|
||||
bytes_per_sector: u16,
|
||||
sectors_per_cluster: u8,
|
||||
|
@ -53,16 +53,16 @@ FatVersionNumber := struct {
|
|||
minor_version: u8,
|
||||
}
|
||||
|
||||
FormatReservation := [u8; 12]
|
||||
FormatReservation := [12]u8
|
||||
|
||||
// Padded with spaces.
|
||||
VolumeName := [u8; 11]
|
||||
VolumeName := [11]u8
|
||||
|
||||
SystemIdentifierString := [u8; 8]
|
||||
VALID_SYSTEM_IDENTIFIER_STRING := [u8].(46, 41, 54, 33, 32, 20, 20, 20)
|
||||
SystemIdentifierString := [8]u8
|
||||
VALID_SYSTEM_IDENTIFIER_STRING := u8.[46, 41, 54, 33, 32, 20, 20, 20]
|
||||
BOOTABLE_PARTITION_SIGNATURE := @as(u32, 0xAA55)
|
||||
|
||||
BootCode := [u8; 420]
|
||||
BootCode := [420]u8
|
||||
|
||||
ExtendedBootRecord := struct {
|
||||
sectors_per_fat: u32,
|
||||
|
@ -89,25 +89,25 @@ ExtendedBootRecord := struct {
|
|||
sanity_check := fn(ebr: ExtendedBootRecord): int {
|
||||
ret := 0
|
||||
if ebr.drive_number != 0x0 | ebr.drive_number != 0x80 {
|
||||
log.warn("EBR-Drive-Number sanity check failed\0")
|
||||
log.warn("EBR-Drive-Number sanity check failed")
|
||||
}
|
||||
|
||||
if ebr.signature != 0x28 | ebr.signature != 0x29 {
|
||||
log.warn("EBR-Signature sanity check failed\0")
|
||||
log.warn("EBR-Signature sanity check failed")
|
||||
}
|
||||
|
||||
// ! comparison between [u8] is not supported in hblang
|
||||
// if ebr.system_identifier_string != VALID_SYSTEM_IDENTIFIER_STRING {
|
||||
// log.warn("EBR-Signature-Identifier-String sanity check failed\0")
|
||||
// log.warn("EBR-Signature-Identifier-String sanity check failed")
|
||||
// }
|
||||
return 0
|
||||
}
|
||||
|
||||
new := fn(): ExtendedBootRecord {
|
||||
version := FatVersionNumber.(0, 0)
|
||||
fmt_res := FormatReservation.(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
vol_name := @as([u8; 11], idk)
|
||||
boot_code := @as([u8; 420], idk)
|
||||
fmt_res := u8.[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
vol_name := @as([11]u8, idk)
|
||||
boot_code := @as([420]u8, idk)
|
||||
|
||||
return ExtendedBootRecord.(
|
||||
0,
|
||||
|
@ -135,38 +135,38 @@ VALID_TRAIL_FS_INFO := @as(u32, 0xAA550000)
|
|||
FSInfo := struct {
|
||||
// Must be 0x41615252 to indicate a valid FSInfo structure
|
||||
lead_signature: u32,
|
||||
lead_reserved: [u8; 480],
|
||||
lead_reserved: [480]u8,
|
||||
// If the value is 0xFFFFFFFF, then the free count is unknown and must be computed. However, this value might be incorrect and should at least be range checked (<= volume cluster count)
|
||||
last_known_free_cluster_count: u32,
|
||||
last_known_avalible_cluster: u32,
|
||||
trail_reserved: [u8; 12],
|
||||
trail_reserved: [12]u8,
|
||||
trail_signature: u32,
|
||||
|
||||
sanity_check := fn(fs_info: FSInfo): uint {
|
||||
ret := 0
|
||||
if fs_info.lead_signature != VALID_LEAD_FS_INFO {
|
||||
ret &= 1
|
||||
log.warn("Invalid leading signature in FSInfo.\0")
|
||||
log.warn("Invalid leading signature in FSInfo.")
|
||||
}
|
||||
if fs_info.last_known_free_cluster_count == 0xFFFFFFFF {
|
||||
ret &= 2
|
||||
log.warn("Last known free cluster count unknown.\0")
|
||||
log.warn("Last known free cluster count unknown.")
|
||||
}
|
||||
if fs_info.last_known_avalible_cluster == 0xFFFFFFFF {
|
||||
ret &= 4
|
||||
log.warn("Last known avalible cluster count unknown.\0")
|
||||
log.warn("Last known avalible cluster count unknown.")
|
||||
}
|
||||
if fs_info.trail_signature != VALID_TRAIL_FS_INFO {
|
||||
ret &= 8
|
||||
log.warn("Invalid trailing signature in FSInfo.\0")
|
||||
log.warn("Invalid trailing signature in FSInfo.")
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
new := fn(): FSInfo {
|
||||
lead_reserved := @as([u8; 480], idk)
|
||||
trail_reserved := @as([u8; 12], idk)
|
||||
lead_reserved := @as([480]u8, idk)
|
||||
trail_reserved := @as([12]u8, idk)
|
||||
return FSInfo.(
|
||||
VALID_LEAD_FS_INFO,
|
||||
lead_reserved,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
attributes := @use("attributes.hb")
|
||||
datetime := @use("datetime.hb")
|
||||
|
||||
FileName := [u8; 11]
|
||||
FileName := [11]u8
|
||||
|
||||
// This is the File Allocation Table entry that tells us where on disk the File is.
|
||||
FileEntry := struct {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{string, memory, buffer, log} := stn
|
||||
|
||||
attributes := @use("attributes.hb")
|
||||
|
@ -8,17 +8,17 @@ bios_parameter_block := @use("bios_parameter_block.hb");
|
|||
.{bpb_sanity_check, ebr_sanity_check, fs_info_sanity_check} := bios_parameter_block;
|
||||
.{BiosParameterBlock, ExtendedBootRecord, FSInfo} := bios_parameter_block
|
||||
|
||||
FAT12_THRESHOLD := 4085
|
||||
FAT16_THRESHOLD := 65525
|
||||
$FAT12_THRESHOLD := 4085
|
||||
$FAT16_THRESHOLD := 65525
|
||||
|
||||
ExFAT := 0
|
||||
FAT12 := 1
|
||||
FAT16 := 2
|
||||
FAT32 := 3
|
||||
$EXFAT := 0
|
||||
$FAT12 := 1
|
||||
$FAT16 := 2
|
||||
$FAT32 := 3
|
||||
|
||||
calculate_fat_type := fn(sector_size: uint, total_clusters: uint): uint {
|
||||
if sector_size == 0 {
|
||||
return ExFAT
|
||||
return EXFAT
|
||||
} else if total_clusters < 4085 {
|
||||
return FAT12
|
||||
} else if total_clusters < 65525 {
|
||||
|
@ -36,7 +36,7 @@ main := fn(): int {
|
|||
fat_type := calculate_fat_type(1, 100)
|
||||
|
||||
if fat_type != FAT32 {
|
||||
log.warn("filesystem_fat32 driver only supports Fat32.\0")
|
||||
log.warn("filesystem_fat32 driver only supports Fat32.")
|
||||
}
|
||||
|
||||
bsc := bpb.sanity_check()
|
||||
|
@ -49,7 +49,7 @@ main := fn(): int {
|
|||
// Open file
|
||||
if msg_type == 0 {
|
||||
// Paths without a node-disk component are to be treated as local files.
|
||||
file_path := "node-disk:/test\0"
|
||||
file_path := "node-disk:/test"
|
||||
} else {
|
||||
// error
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{string, memory, buffer, random, log} := stn;
|
||||
.{Vec2} := stn.math
|
||||
|
||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
||||
horizon_api := @use("lib:horizon_api");
|
||||
.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label;
|
||||
.{sexpr_parser, render_ui} := horizon_api.ui
|
||||
|
||||
render := @use("../../../libraries/render/src/lib.hb");
|
||||
render := @use("lib:render");
|
||||
.{Surface} := render;
|
||||
.{Font} := render.text
|
||||
|
||||
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
||||
intouch := @use("lib:intouch")
|
||||
|
||||
Window := struct {
|
||||
// TODO: Replace this with widgets
|
||||
|
@ -21,23 +21,23 @@ Window := struct {
|
|||
y: int,
|
||||
}
|
||||
|
||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
||||
img := @embed("../../../assets/wallpaper.qoi")
|
||||
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||
img := @embed("sysdata:assets/wallpaper.qoi")
|
||||
|
||||
main := fn(): int {
|
||||
win_buff := buffer.create("XHorizon\0")
|
||||
win_buff := buffer.create("XHorizon")
|
||||
|
||||
screen := render.init(true)
|
||||
|
||||
// Clear the screen to black.
|
||||
render.clear(screen, render.black)
|
||||
screen.clear(render.BLACK)
|
||||
|
||||
wallpaper := render.image.from(@bitcast(&img))
|
||||
if wallpaper == null {
|
||||
return 1
|
||||
}
|
||||
|
||||
window := render.new_surface(screen.width / 3, screen.height / 3)
|
||||
window := render.Surface.new(screen.width / 3, screen.height / 3)
|
||||
|
||||
mem_buf := memory.request_page(1)
|
||||
color := random.any(render.Color)
|
||||
|
@ -48,16 +48,16 @@ main := fn(): int {
|
|||
|
||||
mouse_x := @as(i16, 0)
|
||||
mouse_y := @as(i16, 0)
|
||||
text_label := new_label("Hi\0")
|
||||
text_label := new_label("Hi")
|
||||
|
||||
// widgets := "()\0"
|
||||
// widgets := "()"
|
||||
// ui := sexpr_parser(widgets)
|
||||
|
||||
loop {
|
||||
// Clear the screen
|
||||
render.clear(screen, render.black)
|
||||
screen.clear(render.BLACK)
|
||||
|
||||
render.put_surface(screen, wallpaper, .(0, 0), false)
|
||||
screen.put_surface(wallpaper, .(0, 0), false)
|
||||
|
||||
// TODO: Read the window buffer here
|
||||
{
|
||||
|
@ -65,33 +65,33 @@ main := fn(): int {
|
|||
|
||||
if false {
|
||||
// Scroll bar :ThumbsUp:
|
||||
render.put_rect(screen, .(100, 100), .(100, 10), render.white)
|
||||
render.put_filled_rect(screen, .(110, 100), .(20, 10), render.white)
|
||||
screen.put_rect(.(100, 100), .(100, 10), render.WHITE)
|
||||
screen.put_filled_rect(.(110, 100), .(20, 10), render.WHITE)
|
||||
|
||||
render.put_rect(screen, .(90, 110), .(10, 100), render.white)
|
||||
render.put_filled_rect(screen, .(90, 120), .(10, 20), render.white)
|
||||
screen.put_rect(.(90, 110), .(10, 100), render.WHITE)
|
||||
screen.put_filled_rect(.(90, 120), .(10, 20), render.WHITE)
|
||||
}
|
||||
|
||||
{
|
||||
// osu dots
|
||||
render.put_rect(screen, .(400, 100), .(100, 100), render.red)
|
||||
render.put_rect(screen, .(100, 100 + 300), .(100, 100), render.red)
|
||||
screen.put_rect(.(400, 100), .(100, 100), render.RED)
|
||||
screen.put_rect(.(100, 100 + 300), .(100, 100), render.RED)
|
||||
}
|
||||
|
||||
{
|
||||
pos := Vec2(uint).(1, screen.height - 21)
|
||||
render_label_to_surface(screen, text_label, font, pos)
|
||||
render.put_rect(screen, .(0, screen.height - 21), .(screen.width - 1, 20), render.white)
|
||||
screen.put_rect(.(0, screen.height - 21), .(screen.width - 1, 20), render.WHITE)
|
||||
}
|
||||
|
||||
// Screen border
|
||||
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
|
||||
screen.put_rect(.(0, 0), .(screen.width - 1, screen.height - 1), render.WHITE)
|
||||
|
||||
// get input events from drivers via intouch
|
||||
if false {
|
||||
key_event := intouch.recieve_key_event()
|
||||
if key_event != null {
|
||||
log.info("Key event \0")
|
||||
log.info("Key event ")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ main := fn(): int {
|
|||
//
|
||||
|
||||
if mouse_event != null {
|
||||
// log.warn("Mouse event received\0")
|
||||
// log.warn("Mouse event received")
|
||||
|
||||
change_x := @as(i16, mouse_event.x_change)
|
||||
change_x = change_x << 8
|
||||
|
@ -127,18 +127,18 @@ main := fn(): int {
|
|||
mouse_y -= change_y
|
||||
|
||||
if mouse_event.left {
|
||||
set_label_text(text_label, "LEFT CLICK\0")
|
||||
set_label_text(text_label, "LEFT CLICK")
|
||||
}
|
||||
if mouse_event.middle {
|
||||
set_label_text(text_label, "MIDDLE CLICK\0")
|
||||
set_label_text(text_label, "MIDDLE CLICK")
|
||||
}
|
||||
if mouse_event.right {
|
||||
set_label_text(text_label, "RIGHT CLICK\0")
|
||||
set_label_text(text_label, "RIGHT CLICK")
|
||||
}
|
||||
}
|
||||
|
||||
render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.black)
|
||||
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white)
|
||||
screen.put_filled_rect(.(mouse_x, mouse_y), .(20, 20), render.BLACK)
|
||||
screen.put_rect(.(mouse_x, mouse_y), .(20, 20), render.WHITE)
|
||||
|
||||
// Send events to focused window
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ main := fn(): int {
|
|||
// TODO: Get windows out of a collection and iter through
|
||||
|
||||
// Sync the screen
|
||||
render.sync(screen)
|
||||
screen.sync()
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{string, memory, buffer, log} := stn
|
||||
|
||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
||||
horizon_api := @use("lib:horizon_api");
|
||||
.{create_window} := horizon_api
|
||||
|
||||
ignim := @use("../../../libraries/ignim/src/lib.hb");
|
||||
ignim := @use("lib:ignim");
|
||||
.{errors} := ignim
|
||||
|
||||
psf := @embed("../../../consolefonts/tamsyn/10x20r.psf")
|
||||
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||
|
||||
main := fn(): int {
|
||||
x := 0
|
||||
// loop if x > 10000 break else x += 1
|
||||
|
||||
windowing_system_buffer := buffer.search("XHorizon\0")
|
||||
windowing_system_buffer := buffer.search("XHorizon")
|
||||
// TODO: get WindowID
|
||||
wid := create_window(windowing_system_buffer)
|
||||
if false {
|
||||
program_name := "Horizon Testing Program\0"
|
||||
program_name := "Horizon Testing Program"
|
||||
program_version := ignim.version.make_version(0, 1, 0)
|
||||
engine_name := "None\0"
|
||||
engine_name := "None"
|
||||
engine_version := ignim.version.make_version(0, 0, 0)
|
||||
api_version := ignim.version.make_api_version(0, 1, 0, 0)
|
||||
|
||||
|
@ -32,7 +32,7 @@ main := fn(): int {
|
|||
// // TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance
|
||||
ret := ignim.instance.create_instance(&create_info, 0, &instance)
|
||||
if ret == errors.IncompatibleDriver {
|
||||
log.error("Driver Incompatible with Vulkan\0")
|
||||
log.error("Driver Incompatible with Vulkan")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{memory, buffer, log, string, math} := stn;
|
||||
.{inb, outb} := memory
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.{memory, log} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{memory, log} := @use("stn");
|
||||
.{bit0, bit1, bit5, bit6, bit7} := @use("bits.hb");
|
||||
.{Port, PORT_AT_STARTUP} := @use("port.hb")
|
||||
|
||||
|
@ -87,15 +87,15 @@ init := fn(): void {
|
|||
}
|
||||
|
||||
if (port1.exists | port2.exists) == false {
|
||||
log.error("No ports detected! No input will be processed! Cannot handle this!\0")
|
||||
log.error("No ports detected! No input will be processed! Cannot handle this!")
|
||||
}
|
||||
|
||||
if port1.exists {
|
||||
log.info("Port 1 exists.\0")
|
||||
log.info("Port 1 exists.")
|
||||
enable_port1()
|
||||
}
|
||||
if port2.exists {
|
||||
log.info("Port 2 exists.\0")
|
||||
log.info("Port 2 exists.")
|
||||
enable_port2()
|
||||
}
|
||||
}
|
|
@ -1,11 +1,10 @@
|
|||
.{memory, log, buffer, string} := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{MouseEvent} := @use("../../../libraries/intouch/src/lib.hb").events;
|
||||
.{memory, log, buffer, string} := @use("stn");
|
||||
.{MouseEvent} := @use("lib:intouch").events;
|
||||
.{bit0, bit1, bit2, bit3, bit4} := @use("bits.hb")
|
||||
devices := @use("devices.hb")
|
||||
controller := @use("controller.hb");
|
||||
.{Info, Port} := controller
|
||||
mouse := @use("mouse.hb")
|
||||
format_page := memory.dangling(u8)
|
||||
|
||||
mouse_buffer := 0
|
||||
keyboard_buffer := 0
|
||||
|
@ -72,10 +71,10 @@ process := fn(port: ^controller.Port): void {
|
|||
port.device.value = port.packet[1] | port.packet[0] << 8
|
||||
enable_streaming(port)
|
||||
}
|
||||
log.info("Identified device!\0")
|
||||
log.info(string.display_int(port.device.value, format_page, 16))
|
||||
log.info("Identified device!")
|
||||
log.print(port.device.value, .{radix: 16})
|
||||
} else {
|
||||
log.info("KEY PRESSED\0")
|
||||
log.info("KEY PRESSED")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,13 +107,12 @@ check_complete := fn(port: ^controller.Port): bool {
|
|||
}
|
||||
|
||||
main := fn(): void {
|
||||
mouse_buffer = buffer.create("PS/2 Mouse\0")
|
||||
format_page = memory.alloc(u8, 1024)
|
||||
mouse_buffer = buffer.create("PS/2 Mouse")
|
||||
|
||||
controller.init()
|
||||
|
||||
if controller.port1.exists {
|
||||
//log.info("Port 1 exists.\0")
|
||||
//log.info("Port 1 exists.")
|
||||
controller.send_byte(@bitcast(0), 0xF4)
|
||||
}
|
||||
if controller.port2.exists {
|
||||
|
@ -125,10 +123,10 @@ main := fn(): void {
|
|||
info = controller.get_info()
|
||||
|
||||
if controller.timed_out(info) {
|
||||
log.error("Timeout error! Cannot handle these!\0")
|
||||
log.error("Timeout error! Cannot handle these!")
|
||||
}
|
||||
if controller.check_parity(info) {
|
||||
log.error("Parity error! Cannot handle these!\0")
|
||||
log.error("Parity error! Cannot handle these!")
|
||||
}
|
||||
/*
|
||||
if controller.has_input(info) {
|
||||
|
|
|
@ -7,7 +7,7 @@ $Reboot := State.(1)
|
|||
Port := packed struct {
|
||||
exists: bool,
|
||||
device: DeviceID,
|
||||
packet: [u8; 8],
|
||||
packet: [8]u8,
|
||||
packet_length: u8,
|
||||
can_hot_plug: bool,
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ Port := packed struct {
|
|||
$PORT_AT_STARTUP := Port.(
|
||||
true,
|
||||
NO_DEVICE,
|
||||
.(0, 0, 0, 0, 0, 0, 0, 0),
|
||||
.[0, 0, 0, 0, 0, 0, 0, 0],
|
||||
0,
|
||||
true,
|
||||
)
|
|
@ -1,7 +1,7 @@
|
|||
.{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb")
|
||||
.{memory, buffer, log, string, math} := @use("stn")
|
||||
Vec2 := math.Vec2
|
||||
|
||||
intouch := @use("../../../libraries/intouch/src/lib.hb");
|
||||
intouch := @use("lib:intouch");
|
||||
.{MouseEvent} := intouch.events
|
||||
|
||||
i9 := packed struct {sign: bool, value: u8}
|
||||
|
@ -21,7 +21,7 @@ reset_mouse := fn(): void {
|
|||
@inline(send_byte, 0x64, 0xD4)
|
||||
@inline(send_byte, 0x60, 0xFF)
|
||||
loop if memory.inb(0x60) == 0xAA {
|
||||
log.info("Self check passed.\0")
|
||||
log.info("Self check passed.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -82,11 +82,11 @@ set_up_mouse := fn(): void {
|
|||
button_states := @as(u8, 0)
|
||||
|
||||
main := fn(): int {
|
||||
mouse_buffer := buffer.create("PS/2 Mouse\0")
|
||||
mouse_buffer := buffer.create("PS/2 Mouse")
|
||||
format_page := memory.alloc(u8, 1024)
|
||||
|
||||
send_byte(0x64, 0xA8)
|
||||
log.info("Aux mouse device enabled.\0")
|
||||
log.info("Aux mouse device enabled.")
|
||||
|
||||
set_up_mouse()
|
||||
|
||||
|
@ -102,7 +102,7 @@ main := fn(): int {
|
|||
|
||||
if status == 0xAA {
|
||||
loop if memory.inb(0x60) == 0 break
|
||||
log.info("Mouse plugged in!\0")
|
||||
log.info("Mouse plugged in!")
|
||||
set_up_mouse()
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb")
|
||||
stn := @use("stn")
|
||||
|
||||
main := fn(): int {
|
||||
stn.log.info("\r
|
||||
|
@ -9,7 +9,7 @@ main := fn(): int {
|
|||
| : '=.:.=' : |\r
|
||||
| : :'.___.': : |\r
|
||||
'-:__:__:__:__:-'\r
|
||||
\0")
|
||||
")
|
||||
|
||||
return 0
|
||||
}
|
|
@ -10,7 +10,7 @@ example := fn(): void {
|
|||
image_bmp := render.image.from(@bitcast(&@embed("sysdata:assets/mini.bmp")))
|
||||
|
||||
if image_qoi == null | image_bmp == null {
|
||||
log.error("failed to load images for whatever reason\0")
|
||||
log.error("failed to load images for whatever reason")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -14,26 +14,27 @@ $Y_MAX := 1.12
|
|||
// $Y_MIN := 0.31
|
||||
// $Y_MAX := 0.306
|
||||
|
||||
// zoom into that weird curve part of the main cardioid
|
||||
// $X_MIN := 0.25
|
||||
// $X_MAX := 0.34
|
||||
// $Y_MIN := -0.075
|
||||
// $Y_MAX := 0.075
|
||||
|
||||
$MAX_ITERATION := 300
|
||||
|
||||
$USE_SUNSET := false
|
||||
$USE_SUNSET := true
|
||||
|
||||
palette := [render.Color].(render.LIGHT_RED, render.LIGHT_YELLOW, render.LIGHT_GREEN, render.LIGHT_CYAN, render.LIGHT_BLUE, render.LIGHT_MAGENTA)
|
||||
palette := render.Color.[.(50, 0, 60, 0), .(93, 0, 157, 0), .(140, 98, 229, 0), .(191, 190, 255, 0), .(226, 234, 255, 0), .(242, 250, 255, 0), .(226, 234, 255, 0), .(191, 190, 255, 0), .(140, 98, 229, 0), .(93, 0, 157, 0), .(50, 0, 60, 0)]
|
||||
$LEN_PALETTE := @sizeof(@TypeOf(palette)) / @sizeof(render.Color)
|
||||
|
||||
example := fn(): void {
|
||||
z := math.log(f32, 10.0, 100.0)
|
||||
z2 := math.sign(f32, 10.0)
|
||||
z = math.min(f32, 10.0, 100.0)
|
||||
z = math.max(f32, 10.0, 100.0)
|
||||
|
||||
screen := @as(render.Surface, idk)
|
||||
window := @as(?sunset.Window, null)
|
||||
if USE_SUNSET {
|
||||
sunset.client.find_server()
|
||||
window = sunset.client.new(.(.(400, 140), .(400, 400), "Mandelbrot Set\0"))
|
||||
window = sunset.client.new(.(.(450, 140), .(400, 400), "Mandelbrot Set"))
|
||||
if window == null {
|
||||
log.error("got no window\0")
|
||||
log.error("got no window")
|
||||
return
|
||||
}
|
||||
screen = window.surface
|
||||
|
@ -91,4 +92,7 @@ example := fn(): void {
|
|||
_ = sunset.client.send_frame(window)
|
||||
}
|
||||
}
|
||||
if USE_SUNSET loop {
|
||||
_ = sunset.client.send_frame(window)
|
||||
}
|
||||
}
|
51
sysdata/programs/render_example/src/examples/plotter.hb
Normal file
51
sysdata/programs/render_example/src/examples/plotter.hb
Normal file
|
@ -0,0 +1,51 @@
|
|||
math := @use("stn:math")
|
||||
render := @use("lib:render")
|
||||
|
||||
/* expected result:
|
||||
red tangent graph
|
||||
*/
|
||||
|
||||
$f := fn(x: uint): int {
|
||||
x_f := @as(f32, @itf(@bitcast(x)))
|
||||
y_f := math.tan(x_f * 0.03) * 20
|
||||
return @fti(y_f)
|
||||
}
|
||||
|
||||
y_asymptote := fn(screen: render.Surface, x: uint): void {
|
||||
y := 0
|
||||
loop if y >= screen.height break else {
|
||||
screen.put_pixel(.(x, y), render.GRAY)
|
||||
y += 4
|
||||
}
|
||||
}
|
||||
|
||||
example := fn(): void {
|
||||
screen := render.init(false)
|
||||
x := 0
|
||||
height := @as(int, @bitcast(screen.height))
|
||||
width := @as(int, @bitcast(screen.width))
|
||||
screen.put_hline(screen.height / 2, 0, screen.width, render.LIGHT_GRAY)
|
||||
loop if x >= screen.width break else {
|
||||
y1 := height / 2 - f(x)
|
||||
y2 := height / 2 - f(x + 1)
|
||||
if y1 > height y1 = height else if y1 < 0 {
|
||||
y_asymptote(screen, x)
|
||||
x += 1
|
||||
continue
|
||||
}
|
||||
if y2 > height {
|
||||
y_asymptote(screen, x)
|
||||
x += 1
|
||||
continue
|
||||
} else if y2 < 0 y2 = 0
|
||||
|
||||
if math.abs(int, y2 - y1) > 1 {
|
||||
screen.put_vline(x, @bitcast(y1), @bitcast(y2), render.RED)
|
||||
} else {
|
||||
screen.put_pixel(.(x, @bitcast(y1)), render.RED)
|
||||
screen.put_pixel(.(x, @bitcast(y2)), render.RED)
|
||||
}
|
||||
|
||||
x += 1
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
.{random} := @use("../../../../libraries/stn/src/lib.hb")
|
||||
render := @use("../../../../libraries/render/src/lib.hb")
|
||||
.{random} := @use("stn")
|
||||
render := @use("lib:render")
|
||||
|
||||
example := fn(): void {
|
||||
screen := render.init(false)
|
||||
|
|
|
@ -39,7 +39,7 @@ example := fn(): void {
|
|||
return
|
||||
}
|
||||
|
||||
msg := "sticky note:\n\0"
|
||||
msg := "sticky note:\n"
|
||||
msg_len := string.length(msg)
|
||||
|
||||
buf := memory.alloc(u8, 4096)
|
||||
|
@ -240,4 +240,4 @@ map_keys := fn(scancode: u8): u8 {
|
|||
}
|
||||
return ps2_table[scancode]
|
||||
}
|
||||
ps2_table := [u8].(0x0, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x8, 0x9, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0xA, 0x0, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B, 0x27, 0x60, 0x0, 0x5C, 0x7A, 0x78, 0x63, 0x76, 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x0, 0x2A, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x8, 0x9, 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0xA, 0x0, 0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A, 0x22, 0x7E, 0x0, 0x7C, 0x5A, 0x58, 0x43, 0x56, 0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x0, 0x0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
ps2_table := u8.[0x0, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x8, 0x9, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0xA, 0x0, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B, 0x27, 0x60, 0x0, 0x5C, 0x7A, 0x78, 0x63, 0x76, 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x0, 0x2A, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x8, 0x9, 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0xA, 0x0, 0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A, 0x22, 0x7E, 0x0, 0x7C, 0x5A, 0x58, 0x43, 0x56, 0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x0, 0x0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
|
@ -1,11 +1,11 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{sleep, log, memory} := stn
|
||||
|
||||
main := fn(): int {
|
||||
loop {
|
||||
log.info("BEFORE\0")
|
||||
log.info("BEFORE")
|
||||
sleep.sleep_until_interrupt(8)
|
||||
log.info("AFTER\0")
|
||||
log.info("AFTER")
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||
render := @use("../../../libraries/render/src/lib.hb")
|
||||
sunset := @use("lib:sunset_proto")
|
||||
render := @use("lib:render")
|
||||
|
||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{log} := stn;
|
||||
.{Vec2} := stn.math
|
||||
|
||||
|
@ -26,17 +26,17 @@ GameState := struct {
|
|||
main := fn(): void {
|
||||
sunset.client.find_server()
|
||||
|
||||
window := sunset.client.new(.(.(600, 400), .(200, 200), "SDoom\0"))
|
||||
window := sunset.client.new(.(.(600, 400), .(200, 200), "SDoom"))
|
||||
|
||||
if window == null {
|
||||
log.error("got no window\0")
|
||||
log.error("got no window")
|
||||
return
|
||||
}
|
||||
|
||||
game_state := GameState.new()
|
||||
|
||||
loop {
|
||||
render.clear(window.surface, render.black)
|
||||
window.surface.clear(render.BLACK)
|
||||
width := 100
|
||||
idx := 1
|
||||
|
||||
|
@ -44,7 +44,7 @@ main := fn(): void {
|
|||
if idx >= width {
|
||||
break
|
||||
}
|
||||
render.put_vline(window.surface, idx, 10, 100, render.white)
|
||||
window.surface.put_vline(idx, 10, 100, render.WHITE)
|
||||
idx += 1
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
.{memory, buffer} := @use("../../../libraries/stn/src/lib.hb")
|
||||
.{memory, buffer} := @use("stn")
|
||||
|
||||
serial_print := fn(ptr: ^u8): void {
|
||||
serial_print := fn(str: []u8): void {
|
||||
letter := @as(u8, 0)
|
||||
loop if *ptr == 0 break else {
|
||||
letter = *ptr
|
||||
i := 0
|
||||
loop if i == str.len break else {
|
||||
letter = str[i]
|
||||
memory.outb(0xF803, letter)
|
||||
ptr += 1
|
||||
i += 1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
serial_println := fn(ptr: ^u8): void {
|
||||
serial_print(ptr)
|
||||
serial_println := fn(str: []u8): void {
|
||||
serial_print(str)
|
||||
memory.outb(0xF803, 12)
|
||||
memory.outb(0xF803, 13)
|
||||
return
|
||||
|
@ -19,28 +20,28 @@ serial_println := fn(ptr: ^u8): void {
|
|||
|
||||
main := fn(): int {
|
||||
// This must be done first and foremost to prevent racing
|
||||
a := buffer.create("XNumber\0")
|
||||
serial_println("Starting Serial Driver.\0")
|
||||
a := buffer.create("XNumber")
|
||||
serial_println("Starting Serial Driver.")
|
||||
|
||||
mem := memory.request_page(1)
|
||||
mem := memory.request_page(1)[1..memory.PAGE_SIZE]
|
||||
|
||||
loop {
|
||||
ptr := @as(^u8, @eca(4, a, mem, 0x1000))
|
||||
if ptr == 0 {
|
||||
serial_println("No message\0")
|
||||
serial_println("No message")
|
||||
}
|
||||
if ptr > 0 {
|
||||
serial_println("Yes message\0")
|
||||
serial_println("Yes message")
|
||||
serial_println(mem)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Note that the first byte is reserved, pad accordingly.
|
||||
b := buffer.search("XNumber\0")
|
||||
b := buffer.search("XNumber")
|
||||
|
||||
if a == b {
|
||||
serial_println("Stopping Serial Driver.\0")
|
||||
serial_println("Stopping Serial Driver.")
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
.{log} := @use("../../../libraries/stn/src/lib.hb")
|
||||
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||
render := @use("../../../libraries/render/src/lib.hb")
|
||||
.{log} := @use("stn")
|
||||
sunset := @use("lib:sunset_proto")
|
||||
render := @use("lib:render")
|
||||
|
||||
bmp := @embed("../../../assets/mini.bmp")
|
||||
bmp := @embed("sysdata:assets/mini.bmp")
|
||||
|
||||
main := fn(): void {
|
||||
sunset.client.find_server()
|
||||
|
||||
image := render.image.bmp.from(@bitcast(&bmp))
|
||||
if image == null {
|
||||
log.error("got no image\0")
|
||||
log.error("got no image")
|
||||
return
|
||||
}
|
||||
|
||||
window := sunset.client.new(.(.(100, 100), .(200, 200), "Hello,\0"))
|
||||
window := sunset.client.new(.(.(400, 400), .(200, 200), "Hello"))
|
||||
|
||||
if window == null {
|
||||
log.error("got no window\0")
|
||||
log.error("got no window")
|
||||
return
|
||||
}
|
||||
x := 0
|
||||
loop {
|
||||
render.clear(window.surface, render.black)
|
||||
render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 20), false)
|
||||
window.surface.clear(render.BLACK)
|
||||
window.surface.put_surface(image, .(image.width + x % window.data.props.dimensions.x, 20), false)
|
||||
_ = sunset.client.send_frame(window)
|
||||
x += 1
|
||||
}
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
.{log} := @use("../../../libraries/stn/src/lib.hb")
|
||||
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||
render := @use("../../../libraries/render/src/lib.hb")
|
||||
|
||||
bmp := @embed("../../../assets/able.bmp")
|
||||
|
||||
main := fn(): void {
|
||||
sunset.client.find_server()
|
||||
|
||||
image := render.image.bmp.from(@bitcast(&bmp))
|
||||
if image == null {
|
||||
log.error("got no image\0")
|
||||
return
|
||||
}
|
||||
|
||||
window := sunset.client.new(.(.(400, 100), .(400, 240), "Sunset!\0"))
|
||||
|
||||
if window == null {
|
||||
log.error("got no window\0")
|
||||
return
|
||||
}
|
||||
x := 0
|
||||
loop {
|
||||
render.clear(window.surface, render.black)
|
||||
render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 40), false)
|
||||
_ = sunset.client.send_frame(window)
|
||||
x += 1
|
||||
}
|
||||
}
|
|
@ -1,20 +1,44 @@
|
|||
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||
render := @use("../../../libraries/render/src/lib.hb")
|
||||
intouch := @use("../../../libraries/intouch/src/lib.hb")
|
||||
sunset := @use("lib:sunset_proto")
|
||||
render := @use("lib:render")
|
||||
intouch := @use("lib:intouch")
|
||||
|
||||
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
|
||||
horizon_api := @use("lib:horizon_api");
|
||||
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
|
||||
|
||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{Vec2} := stn.math
|
||||
stn := @use("stn");
|
||||
.{Vec2, clamp} := stn.math
|
||||
|
||||
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
||||
img := @embed("../../../assets/wallpaper.qoi")
|
||||
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
|
||||
img := @embed("sysdata:assets/wallpaper.qoi")
|
||||
|
||||
Mouse := struct {
|
||||
x: int,
|
||||
y: int,
|
||||
// TODO: Make this configurable via wm config
|
||||
cursor_width: u8,
|
||||
|
||||
max_x: uint,
|
||||
max_y: uint,
|
||||
|
||||
new := fn(max_x: uint, max_y: uint): Self {
|
||||
center_x := max_x / 2
|
||||
center_y := max_y / 2
|
||||
|
||||
return Self.(@bitcast(center_x), @bitcast(center_y), 3, max_x, max_y)
|
||||
}
|
||||
/*
|
||||
center := fn(self: Self){
|
||||
center_x := max_x / 2
|
||||
center_y := max_y / 2
|
||||
|
||||
return Self.(center_x, center_y, 3, max_x, max_y)
|
||||
}*/
|
||||
}
|
||||
|
||||
main := fn(): int {
|
||||
sunset.server.start()
|
||||
defer {
|
||||
stn.log.info("Sunset Server Exit\0")
|
||||
stn.log.info("Sunset Server Exit")
|
||||
}
|
||||
|
||||
screen := render.init(true)
|
||||
|
@ -23,64 +47,42 @@ main := fn(): int {
|
|||
|
||||
wallpaper := render.image.from(@bitcast(&img))
|
||||
if wallpaper == null {
|
||||
// stn.panic("Wallpaper not loaded\0")
|
||||
// stn.panic("Wallpaper not loaded")
|
||||
return 1
|
||||
}
|
||||
|
||||
mouse_x := 100
|
||||
mouse_y := 100
|
||||
// mouse_x := 100
|
||||
// mouse_y := 100
|
||||
|
||||
text_label := Label.new_label("\0", 1024)
|
||||
mouse := Mouse.new(screen.width, screen.height)
|
||||
//mouse.center()
|
||||
|
||||
text_label := Label.new_label("", 1024)
|
||||
text_label.set_color(sunset.server.DECO_COLOUR, render.BLACK)
|
||||
|
||||
loop {
|
||||
mouse_event := intouch.recieve_mouse_event()
|
||||
if mouse_event != null {
|
||||
change_x := @as(i16, mouse_event.x_change)
|
||||
change_x = change_x << 8
|
||||
change_x = change_x >> 8
|
||||
|
||||
mouse_x += change_x
|
||||
if mouse_x <= 0 {
|
||||
mouse_x = 0
|
||||
}
|
||||
if mouse_x >= screen.width - 20 {
|
||||
mouse_x = @intcast(screen.width - 21)
|
||||
}
|
||||
|
||||
change_y := @as(i16, mouse_event.y_change)
|
||||
change_y = change_y << 8
|
||||
change_y = change_y >> 8
|
||||
|
||||
mouse_y -= change_y
|
||||
if mouse_y < 0 {
|
||||
mouse_y = 1
|
||||
}
|
||||
if mouse_y >= screen.height - 20 {
|
||||
mouse_y = @intcast(screen.height - 21)
|
||||
}
|
||||
mouse.x = clamp(int, mouse.x + mouse_event.x_change, mouse.cursor_width, @bitcast(screen.width - mouse.cursor_width))
|
||||
mouse.y = clamp(int, mouse.y - mouse_event.y_change, mouse.cursor_width, @bitcast(screen.height - mouse.cursor_width))
|
||||
|
||||
if mouse_event.left {
|
||||
text_label.set_label_text("LEFT CLICK\0")
|
||||
}
|
||||
if mouse_event.middle {
|
||||
text_label.set_label_text("MIDDLE CLICK\0")
|
||||
}
|
||||
if mouse_event.right {
|
||||
text_label.set_label_text("RIGHT CLICK\0")
|
||||
text_label.set_label_text("LEFT CLICK")
|
||||
} else if mouse_event.middle {
|
||||
text_label.set_label_text("MIDDLE CLICK")
|
||||
} else if mouse_event.right {
|
||||
text_label.set_label_text("RIGHT CLICK")
|
||||
}
|
||||
}
|
||||
{
|
||||
screen.clear(render.BLACK)
|
||||
screen.put_surface(wallpaper, .(0, 0), false)
|
||||
|
||||
screen.put_rect(.(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR)
|
||||
}
|
||||
|
||||
if sunset.server.incoming() {
|
||||
_ = sunset.server.incoming()
|
||||
sunset.server.collect_frames()
|
||||
sunset.server.render_clients(screen)
|
||||
}
|
||||
|
||||
{
|
||||
/* Omnibar */
|
||||
|
@ -92,8 +94,9 @@ main := fn(): int {
|
|||
|
||||
// Mouse cursor
|
||||
{
|
||||
screen.put_filled_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER)
|
||||
screen.put_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR)
|
||||
p := Vec2(uint).(@bitcast(mouse.x), @bitcast(mouse.y))
|
||||
screen.put_filled_circle(p, mouse.cursor_width, sunset.server.DECO_COLOUR_DARKER)
|
||||
screen.put_circle(p, mouse.cursor_width, sunset.server.DECO_COLOUR)
|
||||
}
|
||||
|
||||
screen.sync()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{string, memory, buffer, log} := stn
|
||||
|
||||
pci := @use("../../../libraries/pci/src/lib.hb");
|
||||
pci := @use("lib:pci");
|
||||
.{PCIAddress, get_ids, config_read32} := pci
|
||||
|
||||
reg := @use("./reg.hb")
|
||||
|
@ -71,7 +71,7 @@ svga_device := fn(): SVGADevice {
|
|||
|
||||
// TODO : this function is broken
|
||||
GetBARAddr := fn(addr: PCIAddress, index: int): u32 {
|
||||
//bar := config_read32(addr, offsetof(PCIConfigSpace, BAR[index]));
|
||||
//bar := config_read32(addr, offsetof(PCIConfigSpace, BAR[index]))
|
||||
bar := config_read32(0, 3, 0, 0)
|
||||
PCI_CONF_BAR_IO := 0
|
||||
|
||||
|
@ -94,7 +94,7 @@ setup_device := fn(svga_dev: ^SVGADevice): void {
|
|||
pci_dev := pci.check_device(0, 3)
|
||||
|
||||
if pci_dev.device_id.vendor != PCI_VENDOR_ID_VMWARE {
|
||||
log.error("SVGA device not found\0")
|
||||
log.error("SVGA device not found")
|
||||
return
|
||||
}
|
||||
//| pci_dev.device_id.device != PCI_DEVICE_ID_VMWARE_SVGA2 {
|
||||
|
@ -115,7 +115,7 @@ setup_device := fn(svga_dev: ^SVGADevice): void {
|
|||
svga_dev.fbSize = svga_dev.width * svga_dev.height * svga_dev.bpp / 8
|
||||
|
||||
svga_dev.vramSize = read_reg(svga_dev, 0x10)
|
||||
log.info("SVGA device initialized successfully\0")
|
||||
log.info("SVGA device initialized successfully")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ setup_framebuffer := fn(svga_dev: ^SVGADevice): void {
|
|||
write_reg(svga_dev, reg.SVGA_REG_HEIGHT, svga_dev.height)
|
||||
write_reg(svga_dev, reg.SVGA_REG_BITS_PER_PIXEL, svga_dev.bpp)
|
||||
|
||||
log.info("Framebuffer setup complete\0")
|
||||
log.info("Framebuffer setup complete")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
device := @use("device.hb")
|
||||
pci := @use("../../../libraries/pci/src/lib.hb")
|
||||
pci := @use("lib:pci")
|
||||
|
||||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{string, memory, buffer, log} := stn
|
||||
|
||||
reg := @use("reg.hb")
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
stn := @use("../../../libraries/stn/src/lib.hb");
|
||||
.{sleep} := stn
|
||||
stn := @use("stn");
|
||||
.{sleep, buffer} := stn
|
||||
|
||||
main := fn(): int {
|
||||
tmpfs_buffer := buffer.create("TmpFS\0")
|
||||
tmpfs_buffer := buffer.create("TmpFS")
|
||||
loop {
|
||||
// TODO
|
||||
// sleep.sleep_until_buffer(tmpfs_buffer)
|
||||
|
|
|
@ -3,5 +3,5 @@ serial_driver := @use("./tests/serial_driver.hb")
|
|||
|
||||
main := fn(): uint {
|
||||
// return serial_driver.test()
|
||||
return stn.sleep.test()
|
||||
return stn.hashers.test()
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
.{string, buffer} := @use("../../../../libraries/stn/src/lib.hb")
|
||||
.{string, buffer} := @use("stn")
|
||||
|
||||
log_info := fn(): void {
|
||||
a := buffer.search("XNumber\0")
|
||||
a := buffer.search("XNumber")
|
||||
if a == 0 {
|
||||
} else {
|
||||
msg := "XABC\0"
|
||||
msg := "XABC"
|
||||
msg_length := string.length(msg)
|
||||
@eca(3, a, msg, msg_length)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
stn := @use("../../../../../libraries/stn/src/lib.hb");
|
||||
stn := @use("stn");
|
||||
.{allocators, panic, log} := stn
|
||||
|
||||
AStruct := struct {
|
||||
|
@ -20,10 +20,10 @@ test := fn(): uint {
|
|||
}
|
||||
bstruct := balloc.alloc(AStruct, 2)
|
||||
if bstruct.ptr == null {
|
||||
log.info("Hi\0")
|
||||
log.info("Hi")
|
||||
// panic.panic("BlockAlloc actually didn't allocate.")
|
||||
} else {
|
||||
log.info("Allocator functioned.\0")
|
||||
log.info("Allocator functioned.")
|
||||
}
|
||||
balloc.dealloc(&bstruct.ptr, AStruct, 2)
|
||||
return 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
.{log} := @use("../../../libraries/stn/src/lib.hb")
|
||||
.{log, sleep} := @use("stn")
|
||||
|
||||
main := fn(): void {
|
||||
log.info("Hello, World!\0")
|
||||
loop {
|
||||
}
|
||||
log.info("Hello, World!")
|
||||
// fake interrupt, sleep forever
|
||||
sleep.sleep_until_interrupt(100)
|
||||
}
|
Binary file not shown.
|
@ -1,18 +1,15 @@
|
|||
.{dt, memory, string, log} := @use("../../../../../libraries/stn/src/lib.hb")
|
||||
.{dt, log} := @use("stn")
|
||||
|
||||
test := fn(): uint {
|
||||
buffer := memory.request_page(1)
|
||||
|
||||
log.info(string.display_int(dt.get(int, "framebuffer/fb0/width\0"), buffer, 10))
|
||||
string.clear(buffer)
|
||||
|
||||
log.info(string.display_int(dt.get(int, "cpu/cpu0/architecture\0"), buffer, 10))
|
||||
string.clear(buffer)
|
||||
log.print(dt.get(int, "framebuffer/fb0/width"), .{})
|
||||
log.print(dt.get(int, "framebuffer/fb0/height"), .{})
|
||||
log.print(dt.get(^uint, "framebuffer/fb0/ptr"), .{})
|
||||
log.print(dt.get(int, "cpu/cpu0/architecture"), .{})
|
||||
|
||||
// 0 -> memory mapped
|
||||
// 1 -> port mapped
|
||||
|
||||
log.info(string.display_int(dt.get(int, "serial_ports/sp0/mapping\0"), buffer, 10))
|
||||
log.print(dt.get(int, "serial_ports/sp0/mapping"), .{})
|
||||
|
||||
return 0
|
||||
}
|
37
sysdata/programs/test/src/tests/stn/fmt.hb
Normal file
37
sysdata/programs/test/src/tests/stn/fmt.hb
Normal file
|
@ -0,0 +1,37 @@
|
|||
.{log, math} := @use("stn");
|
||||
.{Color} := @use("lib:render")
|
||||
|
||||
StructThingy := struct {
|
||||
a: uint,
|
||||
b: int,
|
||||
c: SubStructThingy,
|
||||
}
|
||||
|
||||
SubStructThingy := struct {
|
||||
a: f32,
|
||||
b: bool,
|
||||
}
|
||||
|
||||
EnumThingy := enum {
|
||||
The,
|
||||
TheOther,
|
||||
}
|
||||
|
||||
test := fn(): uint {
|
||||
log.print(@nameof(?u8), .{log: .Error})
|
||||
log.print("Hello, World", .{})
|
||||
log.print(EnumThingy.The, .{})
|
||||
log.print(StructThingy.(-100, -100, .(-math.PI, true)), .{log: .Warn})
|
||||
log.print(SubStructThingy.(-math.E, false), .{})
|
||||
log.print(Color.{r: 255, g: 254, b: 253, a: 252}, .{radix: 2})
|
||||
log.print(@as(f64, math.LN_2), .{radix: 16, precision: 1 << 32})
|
||||
log.print(u8.[1, 2, 3], .{})
|
||||
log.print(&SubStructThingy.(0.0, true), .{})
|
||||
log.print(@as(?u32, null), .{})
|
||||
log.print(@as(?u32, 200), .{})
|
||||
log.print(.(@as(?u32, null), 200, 3.14), .{})
|
||||
log.printf("{}, {}, {}", .("Hello", math.PI, Color.{r: 101, g: 102, b: 103, a: 104}), .{})
|
||||
log.printf("{}", "Goodbye", .{})
|
||||
|
||||
return 0
|
||||
}
|
|
@ -1,32 +1,25 @@
|
|||
.{hashers, log, memory, string} := @use("../../../../../libraries/stn/src/lib.hb")
|
||||
.{hashers, log, memory, fmt, string, math} := @use("stn")
|
||||
|
||||
test := fn(): uint {
|
||||
buffer := memory.request_page(1)
|
||||
target := "abcdefghijklmnop\0"
|
||||
strings := [^u8].("abcdefshijklmnop\0", "abcdefghijklnnop\0", "abcdefshijklmnop\0", "abcdefghijklmnop\0", "abcdefghijflmnop\0", "dbcdefghijklmnop\0", "abcdefghijklmnop\0")
|
||||
len := @sizeof(@TypeOf(strings)) / @sizeof(^u8)
|
||||
strlen := string.length(target)
|
||||
target := "abcdefghijklmnop"
|
||||
strings := .["abcdefshijklmnop", "abcdefghijklnnop", "abcdefshijklmnop", "abcdefghijklmnop", "abcdefghijflmnop", "dbcdefghijklmnop", "abcdefghijklmnop"]
|
||||
len := @sizeof(@TypeOf(strings)) / @sizeof([]u8)
|
||||
|
||||
// hasher := hashers.foldhash.FoldHasher.new(1)
|
||||
hasher := hashers.foldhash.FoldHasher.default()
|
||||
hasher.write(target, strlen)
|
||||
hasher.write(target.ptr, target.len)
|
||||
correct := hasher.finish()
|
||||
|
||||
log.warn("target:\0")
|
||||
log.warn(target)
|
||||
log.printf("target string: {}, target hash: {}", .(target, correct), .{radix: 16})
|
||||
|
||||
i := 0
|
||||
loop if i == len break else {
|
||||
defer i += 1
|
||||
|
||||
hasher.reset()
|
||||
hasher.write(strings[i], strlen)
|
||||
hasher.write(strings[i].ptr, strings[i].len)
|
||||
d := hasher.finish()
|
||||
if d == correct {
|
||||
log.warn("match found\0")
|
||||
}
|
||||
log.info(strings[i])
|
||||
log.debug(string.display_int(@bitcast(d), buffer, 16))
|
||||
string.clear(buffer)
|
||||
log.printf("matches: {}, string: {}, hash: {}", .(d == correct, strings[i], d), .{radix: 16})
|
||||
}
|
||||
return 0
|
||||
}
|
|
@ -3,3 +3,4 @@ allocators := @use("./allocators.hb")
|
|||
sleep := @use("./sleep.hb")
|
||||
dt := @use("./dt.hb")
|
||||
process := @use("./process.hb")
|
||||
fmt := @use("./fmt.hb")
|
|
@ -1,20 +1,13 @@
|
|||
.{process, log, string, memory} := @use("../../../../../libraries/stn/src/lib.hb")
|
||||
.{process, log} := @use("stn")
|
||||
|
||||
exe := @embed("./assets/hello_world_and_spin.hbf")
|
||||
|
||||
test := fn(): uint {
|
||||
buf := "\0\0\0\0\0\0\0"
|
||||
loop {
|
||||
log.info(
|
||||
string.display_int(
|
||||
@bitcast(process.spawn(@bitcast(&exe), 356)),
|
||||
buf,
|
||||
10,
|
||||
),
|
||||
)
|
||||
log.print(process.spawn(@bitcast(&exe), 356), .{})
|
||||
// spin so we don't spawn 10 quattuordecillion processes
|
||||
i := 0
|
||||
loop if i == 1000000 break else i += 1
|
||||
loop if i == 20000000 break else i += 1
|
||||
}
|
||||
return 0
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
.{sleep, log} := @use("../../../../../libraries/stn/src/lib.hb")
|
||||
.{sleep, log} := @use("stn")
|
||||
|
||||
test := fn(): uint {
|
||||
log.info("BEFORE\0")
|
||||
log.info("BEFORE")
|
||||
sleep.sleep_until_interrupt(32)
|
||||
log.info("AFTER\0")
|
||||
log.info("AFTER")
|
||||
return 0
|
||||
}
|
1
sysdata/programs/vfsaur/README.md
Normal file
1
sysdata/programs/vfsaur/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# vfsaur
|
11
sysdata/programs/vfsaur/meta.toml
Normal file
11
sysdata/programs/vfsaur/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "vfsaur"
|
||||
authors = [""]
|
||||
|
||||
[dependants.libraries]
|
||||
|
||||
[dependants.binaries]
|
||||
hblang.version = "1.0.0"
|
||||
|
||||
[build]
|
||||
command = "hblang src/main.hb"
|
67
sysdata/programs/vfsaur/src/main.hb
Normal file
67
sysdata/programs/vfsaur/src/main.hb
Normal file
|
@ -0,0 +1,67 @@
|
|||
stn := @use("stn");
|
||||
|
||||
.{string, buffer, log, acs} := stn;
|
||||
.{info} := log;
|
||||
.{BufferID} := acs
|
||||
|
||||
FilesystemServiceListing := struct {
|
||||
// The Root to match against of the file system
|
||||
root: []u8,
|
||||
// The buffer to forward fs requests to.
|
||||
buffer_id: BufferID,
|
||||
|
||||
new := fn(root: []u8, buffer_id: BufferID): Self {
|
||||
return .(root, buffer_id)
|
||||
}
|
||||
}
|
||||
|
||||
Path := struct {
|
||||
root: []u8,
|
||||
path: []u8,
|
||||
}
|
||||
|
||||
MessageTypes := enum {
|
||||
Create,
|
||||
Delete,
|
||||
// Used to register filesystem handlers.
|
||||
Mount,
|
||||
}
|
||||
|
||||
VFSMessage := struct {
|
||||
msg_type: MessageTypes,
|
||||
}
|
||||
|
||||
main := fn(): int {
|
||||
log.info("VFSaur starting.")
|
||||
vfs_buff := buffer.create("VFS")
|
||||
|
||||
bid := BufferID.(0, 0)
|
||||
fsl := FilesystemServiceListing.new("acs", bid)
|
||||
fsl2 := FilesystemServiceListing.new("boot", bid)
|
||||
|
||||
full_path := "acs:/path/to/a/file"
|
||||
a := parse_str_to_path(full_path)
|
||||
if a != null {
|
||||
log.info(a.root)
|
||||
log.info(a.path)
|
||||
}
|
||||
vfs_event := VFSMessage.(MessageTypes.Mount)
|
||||
|
||||
loop {
|
||||
buffer.recv(VFSMessage, vfs_buff, &vfs_event)
|
||||
if vfs_event.msg_type == MessageTypes.Mount {
|
||||
// TODO: get info from the message itself
|
||||
fsl3 := FilesystemServiceListing.new("acs", bid)
|
||||
}
|
||||
// TODO: sleep till vfs_buff message
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
parse_str_to_path := fn(full_path: []u8): ?Path {
|
||||
path := string.split_once(full_path, ':')
|
||||
if path == null {
|
||||
return null
|
||||
}
|
||||
return Path.(path.left, path.right)
|
||||
}
|
|
@ -23,8 +23,8 @@ resolution = "1024x768x24"
|
|||
|
||||
[boot.limine.ableos.modules]
|
||||
|
||||
[boot.limine.ableos.modules.render_example]
|
||||
path = "boot:///render_example.hbf"
|
||||
# [boot.limine.ableos.modules.render_example]
|
||||
# path = "boot:///render_example.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.sunset_server]
|
||||
# path = "boot:///sunset_server.hbf"
|
||||
|
@ -46,3 +46,12 @@ path = "boot:///render_example.hbf"
|
|||
|
||||
# [boot.limine.ableos.modules.diskio_driver]
|
||||
# path = "boot:///diskio_driver.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.angels_halo]
|
||||
# path = "boot:///angels_halo.hbf"
|
||||
|
||||
# [boot.limine.ableos.modules.test]
|
||||
# path = "boot:///test.hbf"
|
||||
|
||||
[boot.limine.ableos.modules.vfsaur]
|
||||
path = "boot:///vfsaur.hbf"
|
||||
|
|
Loading…
Reference in a new issue