diff --git a/Cargo.lock b/Cargo.lock index 1e015747..46647884 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" dependencies = [ "hashbrown 0.15.1", "hbbytecode", @@ -245,7 +245,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" dependencies = [ "hbbytecode", ] diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 680aec89..1912c593 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -1,27 +1,27 @@ string := @use("string.hb") -recv := fn($Expr: type, buffer_id: int, memory_map_location: ^u8): void { +recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^u8): void { return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) } -write := fn($Expr: type, msg: ^Expr, buffer_id: int): void { +write := fn($Expr: type, msg: ^Expr, buffer_id: uint): void { return @eca(3, buffer_id, msg, @sizeof(Expr)) } -recv_length := fn(buffer_id: int, memory_map_location: ^u8, length: int): void { +recv_length := fn(buffer_id: uint, memory_map_location: ^u8, length: uint): void { return @eca(4, buffer_id, memory_map_location, length) } -write_length := fn(msg: ^u8, buffer_id: int, length: int): void { +write_length := fn(msg: ^u8, buffer_id: uint, length: uint): void { return @eca(3, buffer_id, msg, length) } BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint} -create := fn(msg: ^u8): int { +create := fn(msg: ^u8): uint { return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } -search := fn(msg: ^u8): int { +search := fn(msg: ^u8): uint { return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/math.hb b/sysdata/libraries/stn/src/math.hb index f22e17fb..1365d0da 100644 --- a/sysdata/libraries/stn/src/math.hb +++ b/sysdata/libraries/stn/src/math.hb @@ -40,7 +40,7 @@ $TABLE_SIZE := @as(i32, 256) sin := fn(theta: f32): f32 { si := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) - d := theta - @floatcast(@itf(si)) * 2.0 * PI / @itf(TABLE_SIZE) + d := theta - @floatcast(@itf(si)) * 2.0 * PI / @floatcast(@itf(TABLE_SIZE)) ci := si + TABLE_SIZE / 4 & TABLE_SIZE - 1 si &= TABLE_SIZE - 1 return SIN_TABLE[@bitcast(si)] + (SIN_TABLE[@bitcast(ci)] - 0.5 * SIN_TABLE[@bitcast(si)] * d) * d @@ -48,10 +48,10 @@ sin := fn(theta: f32): f32 { cos := fn(theta: f32): f32 { ci := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) - d := theta - @floatcast(@itf(ci)) * 2.0 * PI / @itf(TABLE_SIZE) + d := theta - @floatcast(@itf(ci)) * 2.0 * PI / @floatcast(@itf(TABLE_SIZE)) si := ci + TABLE_SIZE / 4 & TABLE_SIZE - 1 ci &= TABLE_SIZE - 1 - return SIN_TABLE[@bitcast(si)] + (SIN_TABLE[@bitcast(ci)] - 0.5 * SIN_TABLE[@bitcast(si)] * d) * d + return SIN_TABLE[@bitcast(si)] - (SIN_TABLE[@bitcast(ci)] + 0.5 * SIN_TABLE[@bitcast(si)] * d) * d } tan := fn(theta: f32): f32 { diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index f0b951ab..821e46fd 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -2,6 +2,17 @@ PAGE_SIZE := 4096 MAX_ALLOC := 0xFF MAX_FREE := 0xFF +is_uninit := fn($Expr: type, ptr: ^Expr): bool { + i := 0 + loop if *(@as(^u8, @bitcast(ptr)) + i) != 0 return false else if i + 1 == @sizeof(Expr) return true else i += 1 +} + +uninit := fn($Expr: type): Expr { + empty := @as(Expr, idk) + @inline(set, u8, &0, @bitcast(&empty), @sizeof(Expr)) + return empty +} + dangling := fn($Expr: type): ^Expr { return @bitcast(@alignof(Expr)) } diff --git a/sysdata/libraries/sunset_proto/src/client.hb b/sysdata/libraries/sunset_proto/src/client.hb new file mode 100644 index 00000000..da1950c3 --- /dev/null +++ b/sysdata/libraries/sunset_proto/src/client.hb @@ -0,0 +1,62 @@ +.{math: .{Vec2}, buffer, log, memory} := @use("../../stn/src/lib.hb"); +.{Surface, new_surface} := @use("../../render/src/lib.hb"); +.{WindowWrapper, WindowID, WindowProps, WindowMessage, message, BUFFER} := @use("./lib.hb") + +buffer_id := @as(?uint, null) + +new_window := fn(props: WindowProps): ?WindowWrapper { + if buffer_id == null { + log.error("client: (request_new) buffer id is null. did you init the client?\0") + return null + } + buf := memory.uninit(?WindowWrapper) + buffer.write(WindowMessage, &.(message.new, 0, @sizeof(WindowProps), @bitcast(&props), @bitcast(&buf)), @unwrap(buffer_id)) + loop if memory.is_uninit(?WindowWrapper, &buf) == false break else { + } + // loop until i write a better socket + i := 0 + loop if i >= 1000 break else i += 1 + return buf +} + +update_window_props := fn(wrapper: WindowWrapper): ?WindowProps { + log.error("todo: sunset_proto/src/client/update_window_props.hb\0") + if buffer_id == null { + log.error("client: (request_update_properties) buffer id is null. did you init the client?\0") + return null + } + // TODO: buffer.write(WINDOWING_BUFFER, update properties) request + return null +} + +request_shutdown := fn(): ?bool { + if buffer_id == null { + log.error("client: (request_shutdown) buffer id is null. did you init the client?\0") + return null + } + buf := memory.uninit(?u8) + buffer.write(WindowMessage, &.(message.shutdown, 0, 0, memory.dangling(u8), @bitcast(&buf)), @unwrap(buffer_id)) + loop if memory.is_uninit(?u8, &buf) == false break else { + } + // loop until i write a better socket + i := 0 + loop if i >= 1000 break else i += 1 + // had to do ?u8 here, ?bool didnt work + if buf == null | @unwrap(buf) != 255 { + return false + } else { + return true + } +} + +init := fn(): void { + log.info("client: waiting for server\0") + id := 0 + loop if id != 0 { + buffer_id = id + log.info("client: done waiting\0") + return + } else { + id = buffer.search(BUFFER) + } +} \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb new file mode 100644 index 00000000..7006f7d1 --- /dev/null +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -0,0 +1,36 @@ +.{math: .{Vec2}} := @use("../../stn/src/lib.hb"); +.{Surface} := @use("../../render/src/lib.hb") + +$BUFFER := "sunset\0" + +client := @use("./client.hb") +server := @use("./server.hb") +message := @use("./message.hb") + +WindowID := uint +MessageKind := uint + +WindowMessage := packed struct { + kind: MessageKind, + id: WindowID, + length: uint, + data_ptr: ^u8, + // need to replace this with a buffer id + callback: ^u8, +} + +WindowProps := struct { + position: Vec2(uint), + dimensions: Vec2(uint), + title: ^u8, +} + +WindowWrapper := struct { + id: WindowID, + props: WindowProps, +} + +Window := struct { + surface: Surface, + props: WindowProps, +} \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/message.hb b/sysdata/libraries/sunset_proto/src/message.hb new file mode 100644 index 00000000..700ab52a --- /dev/null +++ b/sysdata/libraries/sunset_proto/src/message.hb @@ -0,0 +1,4 @@ +$new := 0 +$destroy := 1 +$update_props := 2 +$shutdown := 3 \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb new file mode 100644 index 00000000..4581571e --- /dev/null +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -0,0 +1,34 @@ +.{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb"); +.{Surface, new_surface} := @use("../../render/src/lib.hb"); +.{WindowWrapper, WindowID, WindowProps, WindowMessage, BUFFER} := @use("./lib.hb") + +WindowServer := struct {window_count: uint, buffer_id: uint} + +server := @as(?WindowServer, null) + +new_window_id := fn(): WindowID { + return random.any(uint) +} + +init := fn(): bool { + log.info("server: starting server\0") + server = .(0, buffer.create(BUFFER)) + return true +} + +recieve := fn(): ?WindowMessage { + if server == null { + log.error("server: (request_new) server is null. did you init the client?\0") + return null + } + buf := memory.uninit(WindowMessage) + buffer.recv(WindowMessage, @unwrap(server).buffer_id, @bitcast(&buf)) + if memory.is_uninit(WindowMessage, &buf) { + return null + } + return buf +} + +should_shutdown := fn(): bool { + return false +} \ No newline at end of file diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index 1b7ac838..0666373d 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -60,9 +60,9 @@ main := fn(): int { // TODO: Read the window buffer here { - // ret := buffer.recv([u8; 4096], win_buff, mem_buf) - // for some reason this null check causes the compiler to spin forever - // if ret == null { + // buffer.recv([u8; 4096], win_buff, mem_buf) + // // for some reason this null check causes the compiler to spin forever + // if *mem_buf == 0 { // log.info("No messages\0") // } else { // log.info("Handle Messages\0") diff --git a/sysdata/programs/sunset_client/meta.toml b/sysdata/programs/sunset_client/meta.toml new file mode 100644 index 00000000..cbc588cc --- /dev/null +++ b/sysdata/programs/sunset_client/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "sunset_client" +authors = ["koniifer"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/sunset_client/src/main.hb b/sysdata/programs/sunset_client/src/main.hb new file mode 100644 index 00000000..a9def721 --- /dev/null +++ b/sysdata/programs/sunset_client/src/main.hb @@ -0,0 +1,24 @@ +.{log, string} := @use("../../../libraries/stn/src/lib.hb") +sunset := @use("../../../libraries/sunset_proto/src/lib.hb") + +main := fn(): void { + sunset.client.init() + log.info("client: request new window\0") + window := sunset.client.new_window(.(.(100, 100), .(150, 150), "Hello, World!\0")) + if window == null { + log.error("Could not create window\0") + return + } + log.info("client: window created. title:\0") + log.info(window.props.title) + window.props.position = .(500, 500) + props := @unwrap(sunset.client.update_window_props(window)) + if props.position.x != window.props.position.x { + log.error("client: we did not update props\0") + } + log.info("client: sending shutdown request\0") + shutdown := sunset.client.request_shutdown() + if shutdown == null { + log.error("client: didnt shutdown the server\0") + } +} \ No newline at end of file diff --git a/sysdata/programs/sunset_server/meta.toml b/sysdata/programs/sunset_server/meta.toml new file mode 100644 index 00000000..84c7d22f --- /dev/null +++ b/sysdata/programs/sunset_server/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "sunset_server" +authors = ["koniifer"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb new file mode 100644 index 00000000..c3e2011e --- /dev/null +++ b/sysdata/programs/sunset_server/src/main.hb @@ -0,0 +1,36 @@ +.{log} := @use("../../../libraries/stn/src/lib.hb") +render := @use("../../../libraries/render/src/lib.hb"); +.{server, message, WindowWrapper, WindowProps} := @use("../../../libraries/sunset_proto/src/lib.hb") + +psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf") + +main := fn(): void { + screen := render.init(false) + font := render.text.font_from_psf2(@bitcast(&psf), false) + if font == null { + return + } + if server.init() == false { + log.error("Failed to create server\0") + return + } + loop if server.should_shutdown() break else { + recv := server.recieve() + if recv == null { + continue + } else if recv.kind == message.new { + props := *@as(^WindowProps, @bitcast(recv.data_ptr)); + *@as(^?WindowWrapper, @bitcast(recv.callback)) = WindowWrapper.(0, props) + render.put_rect(screen, props.position, props.dimensions, render.white) + render.put_text(screen, font, props.position + .(1, 1), render.white, props.title) + render.put_hline(screen, props.position.y + font.height + 2, props.position.x, props.position.x + props.dimensions.x, render.white) + log.info("server: made a new window\0") + } else if recv.kind == message.shutdown { + *@as(^?u8, @bitcast(recv.callback)) = 255 + break + } + } + + render.put_text(screen, font, .(0, 0), render.white, "Shutdown triggered\0") + log.info("Server shutdown\0") +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 688c7627..da9cbd07 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -34,5 +34,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -[boot.limine.ableos.modules.ps2_driver] -path = "boot:///ps2_driver.hbf" +[boot.limine.ableos.modules.sunset_client] +path = "boot:///sunset_client.hbf" + +[boot.limine.ableos.modules.sunset_server] +path = "boot:///sunset_server.hbf" diff --git a/todo.md b/todo.md new file mode 100644 index 00000000..c1b6ea21 --- /dev/null +++ b/todo.md @@ -0,0 +1,38 @@ +@konii + Windowing System + Rendering + +@able + Windowing System + Interrupt Forwarding + + +@peony + PS/2 + XYZ + + +@kodin + AIDL AbleOS Interface Description Language + UI-SEXPR lispy ui decl language + +@morshy + Simple Userland Allocator + +@unassigned + FileIO (Fat32) + DiskIO (Undecided Disk type) + Proper Memory Protection + Channels (Two buffers bundled together to form two way communication) + Kernel Testing Framework (A rust framework for testing the kernel) + Userland Testing Framework (An hblang framework for testing the userspace) + PCI/E (Honestly I have no fucking clue whats going on with PCI or why userland cant properly read it) + Kernel Reimpl (Do not you dare think about this yet its only here as an option to show goals) + + AbleOS Compiler Collection + acc-asm + hblang^2 (hblang compiler in hblang) + + + +