From cf917927a53d227bf1fd5e228da93a1c00216c1e Mon Sep 17 00:00:00 2001 From: koniifer Date: Mon, 11 Nov 2024 01:03:01 +0000 Subject: [PATCH 01/14] incomplete sunset redesign --- kernel/src/holeybytes/ecah.rs | 2 +- sysdata/libraries/intouch/src/lib.hb | 2 +- sysdata/libraries/stn/src/buffer.hb | 2 +- sysdata/libraries/stn/src/memory.hb | 11 +- sysdata/libraries/sunset_proto/src/client.hb | 113 ++++++++++-------- sysdata/libraries/sunset_proto/src/lib.hb | 20 ++-- sysdata/libraries/sunset_proto/src/message.hb | 10 +- sysdata/libraries/sunset_proto/src/server.hb | 65 +++++++--- sysdata/programs/horizon/src/main.hb | 2 +- sysdata/programs/sunset_client/src/main.hb | 20 +--- sysdata/programs/sunset_server/src/main.hb | 35 +----- 11 files changed, 139 insertions(+), 143 deletions(-) diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index ab45e64..8a03816 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -182,7 +182,7 @@ pub fn handler(vm: &mut Vm) { } else { unsafe { let ptr = map_ptr as *mut u8; - ptr.copy_from(msg.as_ptr(), msg.len()); + ptr.copy_from_nonoverlapping(msg.as_ptr(), msg.len()); } debug!("Recieve {:?} from Buffer({})", msg, buffer_id); diff --git a/sysdata/libraries/intouch/src/lib.hb b/sysdata/libraries/intouch/src/lib.hb index dca49d4..a6c5a91 100644 --- a/sysdata/libraries/intouch/src/lib.hb +++ b/sysdata/libraries/intouch/src/lib.hb @@ -15,7 +15,7 @@ recieve_mouse_event := fn(): ?MouseEvent { buf_id := buffer.search("PS/2 Mouse\0") // Read out of the Mouse buffer here - buffer.recv(MouseEvent, buf_id, @bitcast(&mevent)) + buffer.recv(MouseEvent, buf_id, &mevent) if mevent.x_change != 0 | mevent.y_change != 0 | mevent.left | mevent.middle | mevent.right { return mevent diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 1912c59..aa16637 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -1,6 +1,6 @@ string := @use("string.hb") -recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^u8): void { +recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void { return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) } diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index 821e46f..5bebd68 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -2,15 +2,8 @@ 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 +uninit := fn($Expr: type): ?Expr { + return null } dangling := fn($Expr: type): ^Expr { diff --git a/sysdata/libraries/sunset_proto/src/client.hb b/sysdata/libraries/sunset_proto/src/client.hb index da1950c..bc23e0d 100644 --- a/sysdata/libraries/sunset_proto/src/client.hb +++ b/sysdata/libraries/sunset_proto/src/client.hb @@ -1,62 +1,79 @@ .{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") +.{Window, WindowData, WindowProps, MessageHeader, 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 - } -} +server_id := @as(?uint, null) init := fn(): void { log.info("client: waiting for server\0") id := 0 loop if id != 0 { - buffer_id = id + server_id = id log.info("client: done waiting\0") return } else { id = buffer.search(BUFFER) } +} + +// wait_for_message := fn($Expr: type, ptr: ^?Expr, buffer_id: uint): bool { +// timer := 0 +// loop if timer < 1000 { +// buffer.recv(?Expr, buffer_id, ptr) +// if *ptr != null { +// return true +// } +// timer -= 1 +// } +// return false +// } + +new := fn(props: WindowProps): ?Window { + if server_id == null { + init() + } + buffer.write(?MessageHeader, &@as(?MessageHeader, .(message.syn, @sizeof(WindowProps))), @unwrap(server_id)) + log.info("client: sent syn\0") + + timer := 0 + response := memory.uninit(MessageHeader) + // if wait_for_message(MessageHeader, &response, @unwrap(server_id)) == false { + // return null + // } + loop if timer < 1000 { + buffer.recv(?MessageHeader, @unwrap(server_id), &response) + if response != null { + break + } + timer += 1 + } else { + log.error("client: no response in timeout\0") + return null + } + if response.kind != message.ack { + log.error("client: refused\0") + return null + } + log.info("client: received ack\0") + + buffer_id := response.data + buffer.write(?WindowProps, &@as(?WindowProps, props), buffer_id) + log.info("client: sent props\0") + + timer = 0 + response2 := memory.uninit(WindowData) + loop if timer < 1000 { + buffer.recv(?WindowData, buffer_id, &response2) + + if response2 != null { + log.info("client: received window data\0") + surface := new_surface( + response2.props.dimensions.x, + response2.props.dimensions.y, + ) + return .(@as(WindowData, response2), surface) + } + timer += 1 + } + return null } \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index 7006f7d..b5f8a95 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -7,30 +7,24 @@ 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, +MessageHeader := packed struct { + kind: uint, + data: uint, } WindowProps := struct { position: Vec2(uint), dimensions: Vec2(uint), + // replace with owned string type later title: ^u8, } -WindowWrapper := struct { - id: WindowID, +WindowData := struct { props: WindowProps, + buffer_id: uint, } Window := struct { + data: WindowData, 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 index 700ab52..9c69092 100644 --- a/sysdata/libraries/sunset_proto/src/message.hb +++ b/sysdata/libraries/sunset_proto/src/message.hb @@ -1,4 +1,6 @@ -$new := 0 -$destroy := 1 -$update_props := 2 -$shutdown := 3 \ No newline at end of file +$syn := 1 +$ack := 2 +$refused := 3 +$quit := 4 +$update_props := 5 +$shutdown := 6 \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index 4581571..46d4617 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -1,32 +1,63 @@ .{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") +.{Window, WindowProps, WindowData, MessageHeader, BUFFER, message} := @use("./lib.hb") -WindowServer := struct {window_count: uint, buffer_id: uint} +WindowServer := struct { + window_count: uint, + id: uint, + // replace this with an actual collection when we get an allocator + windows: ^WindowData, +} server := @as(?WindowServer, null) -new_window_id := fn(): WindowID { - return random.any(uint) -} - -init := fn(): bool { +init := fn(): void { + if server != null { + return + } log.info("server: starting server\0") - server = .(0, buffer.create(BUFFER)) - return true + windows := memory.alloc(WindowData, 10) + server = .(0, buffer.create(BUFFER), windows) } -recieve := fn(): ?WindowMessage { +handle_connections := fn(): bool { if server == null { - log.error("server: (request_new) server is null. did you init the client?\0") - return null + return false } - buf := memory.uninit(WindowMessage) - buffer.recv(WindowMessage, @unwrap(server).buffer_id, @bitcast(&buf)) - if memory.is_uninit(WindowMessage, &buf) { - return null + recv := memory.uninit(MessageHeader) + buffer.recv(?MessageHeader, @unwrap(server).id, &recv) + if recv == null { + return true + } else if recv.kind == message.syn { + buffer_id := buffer.create("asdf\0") + buffer.write(?MessageHeader, &@as(?MessageHeader, .(message.ack, buffer_id)), @unwrap(server).id) + log.info("server: sent ack\0") + + timer := 0 + resp := memory.uninit(WindowProps) + loop if timer < 1000 { + buffer.recv(?WindowProps, buffer_id, &resp) + if resp != null { + break + } + timer += 1 + } else { + log.error("server: no props in timeout\0") + return true + } + log.info("server: received props\0") + surface := new_surface(resp.dimensions.x, resp.dimensions.y) + data := WindowData.(@as(WindowProps, resp), buffer_id) + buffer.write(?WindowData, &@as(?WindowData, data), buffer_id) + log.info("server: sent window data\0"); + *(@unwrap(server).windows + @unwrap(server).window_count) = data + @unwrap(server).window_count += 1 + } else if recv.kind == message.quit { + // todo: quit + } else if recv.kind == message.shutdown { + return false } - return buf + return true } should_shutdown := fn(): bool { diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index 0666373..9ead559 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -96,7 +96,7 @@ main := fn(): int { // if mouse_event != null { - // log.warn("Mouse event recieved\0") + // log.warn("Mouse event received\0") change_x := @as(i16, mouse_event.x_change) change_x = change_x << 8 diff --git a/sysdata/programs/sunset_client/src/main.hb b/sysdata/programs/sunset_client/src/main.hb index a9def72..86b8ac7 100644 --- a/sysdata/programs/sunset_client/src/main.hb +++ b/sysdata/programs/sunset_client/src/main.hb @@ -2,23 +2,11 @@ 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")) + window := sunset.client.new(.(.(100, 100), .(100, 100), "Hello, World!\0")) if window == null { - log.error("Could not create window\0") + log.error("client: window was null\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") - } + log.info("client: window title:\0") + log.info(window.data.props.title) } \ No newline at end of file diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index c3e2011..98f421b 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -1,36 +1,7 @@ -.{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") +sunset := @use("../../../libraries/sunset_proto/src/lib.hb") main := fn(): void { - screen := render.init(false) - font := render.text.font_from_psf2(@bitcast(&psf), false) - if font == null { - return + sunset.server.init() + loop if sunset.server.handle_connections() { } - 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 From e40a22fccdee7b9c1b0afce5031f0b4938f99c47 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 11 Nov 2024 01:23:14 -0600 Subject: [PATCH 02/14] Commit --- sysdata/libraries/intouch/src/events.hb | 10 ++---- sysdata/libraries/intouch/src/lib.hb | 11 +++++++ sysdata/programs/horizon/src/main.hb | 31 ++++++++----------- .../programs/ps2_keyboard_driver/src/main.hb | 18 +++++++++-- sysdata/programs/render_example/src/main.hb | 2 +- sysdata/system_config.toml | 16 +++++----- 6 files changed, 51 insertions(+), 37 deletions(-) diff --git a/sysdata/libraries/intouch/src/events.hb b/sysdata/libraries/intouch/src/events.hb index c26fb95..546cb52 100644 --- a/sysdata/libraries/intouch/src/events.hb +++ b/sysdata/libraries/intouch/src/events.hb @@ -1,13 +1,9 @@ keycodes := @use("keycodes.hb"); .{KeyCode} := keycodes -KeyEvent := struct { - // 0 if down - // 1 if up - up: u8, - // 0 if not just triggered - // 1 if just triggered - just_triggered: u8, +KeyEvent := packed struct { + up: bool, + just_triggered: bool, key: KeyCode, } diff --git a/sysdata/libraries/intouch/src/lib.hb b/sysdata/libraries/intouch/src/lib.hb index a6c5a91..14ac86e 100644 --- a/sysdata/libraries/intouch/src/lib.hb +++ b/sysdata/libraries/intouch/src/lib.hb @@ -6,6 +6,17 @@ events := @use("events.hb"); .{KeyEvent, MouseEvent} := events recieve_key_event := fn(): ?KeyEvent { + kevent := KeyEvent.(false, false, 0) + + buf_id := buffer.search("PS/2 Keyboard\0") + + // Read out of the Keyboard buffer here + buffer.recv(KeyEvent, buf_id, &kevent) + + if kevent.just_triggered { + return kevent + } + return null } diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index 9ead559..114c492 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -56,23 +56,13 @@ main := fn(): int { loop { // Clear the screen render.clear(screen, render.black) + render.put_surface(screen, wallpaper, .(0, 0), false) // TODO: Read the window buffer here { - // 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") - // } } - // get input events from drivers via intouch - // key_event := intouch.recieve_key_event(); - // log.info("before mouse event check\0"); - if false { // Scroll bar :ThumbsUp: render.put_rect(screen, .(100, 100), .(100, 10), render.white) @@ -83,6 +73,7 @@ main := fn(): int { } { + // Bottom Bar 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) @@ -91,6 +82,14 @@ main := fn(): int { // Screen border render.put_rect(screen, .(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") + } + } + { mouse_event := intouch.recieve_mouse_event() // @@ -133,13 +132,9 @@ main := fn(): int { } } - // render mouse - lum := render.indexptr(screen, mouse_x, mouse_y) - if lum.r / 3 + lum.g / 3 + lum.b / 3 < 128 { - render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white) - } else { - render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.black) - } + 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) + // Send events to focused window } diff --git a/sysdata/programs/ps2_keyboard_driver/src/main.hb b/sysdata/programs/ps2_keyboard_driver/src/main.hb index 150d3b0..41485ca 100644 --- a/sysdata/programs/ps2_keyboard_driver/src/main.hb +++ b/sysdata/programs/ps2_keyboard_driver/src/main.hb @@ -1,4 +1,8 @@ -.{memory, log, buffer} := @use("../../../libraries/stn/src/lib.hb") +stn := @use("../../../libraries/stn/src/lib.hb"); +.{memory, log, buffer} := stn + +intouch := @use("../../../libraries/intouch/src/lib.hb"); +.{KeyEvent} := intouch send_byte := fn(byte: u8): u8 { memory.outb(96, byte) @@ -6,23 +10,31 @@ send_byte := fn(byte: u8): u8 { } main := fn(): int { - buf := buffer.create("XKeyboard\0") + buf := buffer.create("PS/2 Keyboard\0") _ = send_byte(238) log.info("PS/2 Driver Loaded\0") + if send_byte(238) == 238 { log.info("PS/2 Keyboard Echoed\0") } + if send_byte(244) == 250 { log.info("Enabled scanning\0") } + prev_input := 250 loop { + loop if (memory.inb(0x64) & 0x20) == 0x20 break + input := memory.inb(96) + if input == prev_input { continue } prev_input = input - buffer.write(u8, &input, buf) + kevent := KeyEvent.(false, true, input) + + buffer.write(KeyEvent, &kevent, buf) } return 0 } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index ab66cfa..77cb04c 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1 +1 @@ -.{example: main} := @use("./examples/orbit.hb") \ No newline at end of file +.{example: main} := @use("./examples/text.hb") \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index da9cbd0..406a1ac 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -25,17 +25,17 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.render_example] # path = "boot:///render_example.hbf" -# [boot.limine.ableos.modules.horizon] -# path = "boot:///horizon.hbf" +[boot.limine.ableos.modules.horizon] +path = "boot:///horizon.hbf" -# [boot.limine.ableos.modules.ps2_mouse_driver] -# path = "boot:///ps2_mouse_driver.hbf" +[boot.limine.ableos.modules.ps2_mouse_driver] +path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -[boot.limine.ableos.modules.sunset_client] -path = "boot:///sunset_client.hbf" +# [boot.limine.ableos.modules.sunset_client] +# path = "boot:///sunset_client.hbf" -[boot.limine.ableos.modules.sunset_server] -path = "boot:///sunset_server.hbf" +# [boot.limine.ableos.modules.sunset_server] +# path = "boot:///sunset_server.hbf" From 8ad7542b9c0cb15538480850e4891f416c253f99 Mon Sep 17 00:00:00 2001 From: koniifer Date: Mon, 11 Nov 2024 21:48:43 +0000 Subject: [PATCH 03/14] sunset work, stn changes, and fiddling with kernel logging clutter --- Cargo.lock | 18 +-- kernel/src/arch/x86_64/mod.rs | 6 +- kernel/src/arch/x86_64/pci/mod.rs | 2 +- kernel/src/holeybytes/ecah.rs | 2 +- .../kernel_services/logging_service.rs | 27 ++-- kernel/src/kmain.rs | 15 ++- sysdata/libraries/stn/src/buffer.hb | 14 +- sysdata/libraries/stn/src/string.hb | 120 +++++------------- sysdata/libraries/sunset_proto/src/client.hb | 110 +++++++--------- sysdata/libraries/sunset_proto/src/lib.hb | 32 ++++- sysdata/libraries/sunset_proto/src/message.hb | 4 +- sysdata/libraries/sunset_proto/src/server.hb | 63 ++++----- .../programs/ps2_keyboard_driver/src/main.hb | 2 +- sysdata/programs/ps2_mouse_driver/src/main.hb | 2 +- .../render_example/src/examples/colors.hb | 6 +- sysdata/programs/sunset_client/src/main.hb | 18 ++- sysdata/programs/sunset_server/src/main.hb | 2 +- 17 files changed, 202 insertions(+), 241 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4664788..095b1af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611cc2ae7d2e242c457e4be7f97036b8ad9ca152b499f53faf99b1ed8fc2553f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "anyhow" @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d99672b75179b79249c4b6b91dfccef0b757fa3a" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b6274f3455d0545a64f2cc866b39d409e0a73427" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d99672b75179b79249c4b6b91dfccef0b757fa3a" 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#b6274f3455d0545a64f2cc866b39d409e0a73427" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d99672b75179b79249c4b6b91dfccef0b757fa3a" dependencies = [ "hbbytecode", ] @@ -675,18 +675,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.214" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index d0270ff..aa4f6cd 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -111,7 +111,7 @@ unsafe extern "C" fn oops() -> ! { unsafe extern "C" fn start() -> ! { logging::init(); crate::logger::init().expect("failed to set logger"); - log::info!("Initialising AKern {}", crate::VERSION); + log::debug!("Initialising AKern {}", crate::VERSION); static HDHM_REQ: HhdmRequest = HhdmRequest::new(0); memory::init_pt(VirtAddr::new( @@ -190,7 +190,7 @@ unsafe extern "C" fn start() -> ! { // TODO: Add in rdseed and rdrand as sources for randomness let _rand = xml::XMLElement::new("Random"); - log::trace!("Getting boot modules"); + log::debug!("Getting boot modules"); let bm = MOD_REQ.get_response().get(); let mut bootmodules = alloc::vec::Vec::new(); @@ -228,7 +228,7 @@ unsafe extern "C" fn start() -> ! { break; } } - log::info!("Boot module count: {:?}", bootmodules.len()); + log::debug!("Boot module count: {:?}", bootmodules.len()); assert_eq!(bm.module_count, bootmodules.len() as u64); } diff --git a/kernel/src/arch/x86_64/pci/mod.rs b/kernel/src/arch/x86_64/pci/mod.rs index af0fe63..878ef4c 100644 --- a/kernel/src/arch/x86_64/pci/mod.rs +++ b/kernel/src/arch/x86_64/pci/mod.rs @@ -69,7 +69,7 @@ pub fn check_device(bus: u8, device: u8) -> Option { } let (reg2, addr) = unsafe { pci_config_read_2(bus, device, 0, 0x8) }; - log::info!("pci device-({}) addr {} is {}", device, addr, reg2); + log::debug!("pci device-({}) addr {} is {}", device, addr, reg2); let class = ((reg2 >> 16) & 0x0000_FFFF) as u16; let pci_class = PciFullClass::from_u16(class); let header_type = get_header_type(bus, device, 0); diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 8a03816..b4ef634 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -58,10 +58,10 @@ pub fn handler(vm: &mut Vm) { true => IpcBuffer::new(true, length), }, ); - info!("Buffer ID: {}", buff_id); vm.registers[1] = hbvm::value::Value(buff_id); } 2 => { + log::error!("Oops, deleting buffers is not implemented.") // Delete buffer } 3 => { diff --git a/kernel/src/holeybytes/kernel_services/logging_service.rs b/kernel/src/holeybytes/kernel_services/logging_service.rs index b1fbf4a..ea61cec 100644 --- a/kernel/src/holeybytes/kernel_services/logging_service.rs +++ b/kernel/src/holeybytes/kernel_services/logging_service.rs @@ -9,7 +9,20 @@ use log::Record; pub fn log_msg_handler(_vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> { let msg_vec = block_read(mem_addr, length); - let log_level = msg_vec[0]; + use log::Level::*; + let log_level = match msg_vec[0] { + 0 | 48 => Error, + 1 | 49 => Warn, + 2 | 50 => Info, + 3 | 51 => Debug, + 4 | 52 => Trace, + _ => { + return Err(LogError::InvalidLogFormat); + } + }; + if log_level > log::max_level() { + return Ok(()); + } let strptr = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()); let strlen = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as usize; @@ -20,18 +33,6 @@ pub fn log_msg_handler(_vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), match core::str::from_utf8(&str) { Ok(strr) => { - use log::Level::*; - let log_level = match log_level { - 0 | 48 => Error, - 1 | 49 => Warn, - 2 | 50 => Info, - 3 | 51 => Debug, - 4 | 52 => Trace, - _ => { - return Err(LogError::InvalidLogFormat); - } - }; - log::logger().log( &Record::builder() .args(format_args!("{}", strr)) diff --git a/kernel/src/kmain.rs b/kernel/src/kmain.rs index 347aa34..7ca0780 100644 --- a/kernel/src/kmain.rs +++ b/kernel/src/kmain.rs @@ -71,7 +71,18 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { let cmd = module.cmd.trim_matches('"'); let cmd_len = cmd.len() as u64; - log::info!("Spawning {} with arguments \"{}\"", module.path, cmd); + log::info!( + "Starting {}", + module + .path + .split('/') + .last() + .unwrap() + .split('.') + .next() + .unwrap() + ); + log::debug!("Spawning {} with arguments \"{}\"", module.path, cmd); // decode AbleOS Executable format let header = &module.bytes[0..46]; @@ -92,7 +103,7 @@ pub fn kmain(_cmdline: &str, boot_modules: BootModules) -> ! { let code_length = u64::from_le_bytes(header[7..15].try_into().unwrap()); let data_length = u64::from_le_bytes(header[15..23].try_into().unwrap()); let end = (code_length + data_length) as usize; - log::info!("{code_length} + {data_length} = {end}"); + log::debug!("{code_length} + {data_length} = {end}"); let mut thr = ExecThread::new(&module.bytes[offset..end], Address::new(0)); if cmd_len > 0 { diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index aa16637..e54b959 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -4,15 +4,15 @@ recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void { return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) } -write := fn($Expr: type, msg: ^Expr, buffer_id: uint): void { +write := fn($Expr: type, buffer_id: uint, msg: ^Expr): void { return @eca(3, buffer_id, msg, @sizeof(Expr)) } -recv_length := fn(buffer_id: uint, memory_map_location: ^u8, length: uint): void { +recv_length := fn(length: uint, memory_map_location: ^u8, buffer_id: uint): void { return @eca(4, buffer_id, memory_map_location, length) } -write_length := fn(msg: ^u8, buffer_id: uint, length: uint): void { +write_length := fn(length: uint, msg: ^u8, buffer_id: uint): void { return @eca(3, buffer_id, msg, length) } @@ -22,6 +22,14 @@ create := fn(msg: ^u8): uint { return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } +create_without_name := fn(): uint { + return @eca(1, 0) +} + +delete_buffer := fn(buffer_id: uint): void { + return @eca(2, buffer_id) +} + 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/string.hb b/sysdata/libraries/stn/src/string.hb index efea870..e617498 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -4,118 +4,60 @@ length := fn(ptr: ^u8): uint { } display_int := fn(num: int, p: ^u8, radix: uint): ^u8 { + is_negative := num < 0 + if is_negative num = -num + ptr := p - negative := num < 0 - if negative { - num = -num - } - if radix == 2 { - *ptr = 48 - ptr += 1; - *ptr = 98 - ptr += 1 - } else if radix == 16 { - *ptr = 48 - ptr += 1; - *ptr = 120 - ptr += 1 - } else if radix == 8 { - *ptr = 48 - ptr += 1; - *ptr = 111 - ptr += 1 - } - digits_start := ptr if num == 0 { - *ptr = 48 - ptr += 1 - } else { - loop if num == 0 break else { - digit := num % @bitcast(radix) - if digit < 10 { - *ptr = @intcast(digit) + 48 - } else { - *ptr = @intcast(digit) + 55 - } - ptr += 1 - num /= @bitcast(radix) - } + *ptr = 0x30; + *(ptr + 1) = 0 + return p } - if negative { - *ptr = 45 + 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 - }; + } - *ptr = 0 - - @inline(reverse, digits_start) + 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 { - i := 0 - j := @inline(length, s) - 1 + j := s + @inline(length, s) - 1 temp := @as(u8, 0) - loop if i >= j break else { - temp = *(s + i); - *(s + i) = *(s + j); - *(s + j) = temp - i += 1 + loop if s < j { + temp = *s; + *s = *j; + *j = temp + s += 1 j -= 1 - } - return + } else return } equals := fn(lhs: ^u8, rhs: ^u8): bool { if lhs == rhs { return true } - i := 0 - loop if *(lhs + i) != *(rhs + i) { + loop if *lhs != *rhs { return false } else if *lhs == 0 { return true } else { - i += 1 + lhs += 1 + rhs += 1 } -} - -contains := fn(haystack: ^u8, needle: ^u8): bool { - haystack_len := @inline(length, haystack) - needle_len := @inline(length, needle) - - if needle_len == 0 { - return true - } - if haystack_len < needle_len { - return false - } - - max_start := haystack_len - needle_len - - pos := 0 - loop if pos > max_start break else { - is_match := true - offset := 0 - - loop if offset >= needle_len break else { - if *(haystack + pos + offset) != *(needle + offset) { - is_match = false - } - if is_match == false { - break - } - offset += 1 - } - - if is_match { - return true - } - pos += 1 - } - - return false } \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/client.hb b/sysdata/libraries/sunset_proto/src/client.hb index bc23e0d..6590754 100644 --- a/sysdata/libraries/sunset_proto/src/client.hb +++ b/sysdata/libraries/sunset_proto/src/client.hb @@ -1,79 +1,59 @@ .{math: .{Vec2}, buffer, log, memory} := @use("../../stn/src/lib.hb"); -.{Surface, new_surface} := @use("../../render/src/lib.hb"); -.{Window, WindowData, WindowProps, MessageHeader, message, BUFFER} := @use("./lib.hb") +.{Window, WindowData, WindowProps, MessageHeader, send_message, message, await_buffer, await_message, BUFFER} := @use("./lib.hb") +render := @use("../../render/src/lib.hb") -server_id := @as(?uint, null) +server_id := @as(uint, idk) +screen := @as(render.Surface, idk) -init := fn(): void { - log.info("client: waiting for server\0") - id := 0 - loop if id != 0 { - server_id = id - log.info("client: done waiting\0") - return - } else { - id = buffer.search(BUFFER) - } +find_server := fn(): void { + // ! to be removed in the future + screen = render.init(false) + render.clear(screen, render.black) + log.debug("client: waiting for server\0") + server_id = await_buffer(BUFFER) + log.debug("client: found server\0") } -// wait_for_message := fn($Expr: type, ptr: ^?Expr, buffer_id: uint): bool { -// timer := 0 -// loop if timer < 1000 { -// buffer.recv(?Expr, buffer_id, ptr) -// if *ptr != null { -// return true -// } -// timer -= 1 -// } -// return false -// } - new := fn(props: WindowProps): ?Window { - if server_id == null { - init() - } - buffer.write(?MessageHeader, &@as(?MessageHeader, .(message.syn, @sizeof(WindowProps))), @unwrap(server_id)) - log.info("client: sent syn\0") - - timer := 0 - response := memory.uninit(MessageHeader) - // if wait_for_message(MessageHeader, &response, @unwrap(server_id)) == false { - // return null - // } - loop if timer < 1000 { - buffer.recv(?MessageHeader, @unwrap(server_id), &response) - if response != null { - break - } - timer += 1 - } else { - log.error("client: no response in timeout\0") - return null - } + send_message(MessageHeader, .(message.syn, 0), server_id) + log.debug("client: sent syn\0") + response := await_message(MessageHeader, server_id) if response.kind != message.ack { - log.error("client: refused\0") + log.error("client: refused syn\0") return null } - log.info("client: received ack\0") + log.debug("client: got ack\0") buffer_id := response.data - buffer.write(?WindowProps, &@as(?WindowProps, props), buffer_id) - log.info("client: sent props\0") + send_message(WindowProps, props, buffer_id) + log.debug("client: sent props\0") - timer = 0 - response2 := memory.uninit(WindowData) - loop if timer < 1000 { - buffer.recv(?WindowData, buffer_id, &response2) + response2 := await_message(WindowData, buffer_id) + log.debug("client: got window data\0") + surface := render.new_surface( + response2.props.dimensions.x, + response2.props.dimensions.y, + ) + return .(@as(WindowData, response2), surface) +} - if response2 != null { - log.info("client: received window data\0") - surface := new_surface( - response2.props.dimensions.x, - response2.props.dimensions.y, - ) - return .(@as(WindowData, response2), surface) - } - timer += 1 - } - return null +// ! client buffers are not being read by the server yet +quit := fn(client: Window): void { + send_message(MessageHeader, .(message.quit, 0), client.data.buffer_id) +} + +shutdown_server := fn(): void { + send_message(MessageHeader, .(message.shutdown, 0), server_id) +} + +update_props := fn(client: Window): bool { + log.error("client: update props unimplemented\0") + return false +} + +//! temporarily just throw our window at the screen +frame_ready := fn(client: Window): void { + send_message(MessageHeader, .(message.ready, 0), client.data.buffer_id) + log.warn("client: we are blitting to screen from the client\n\r this is temporary behaviour\0") + render.put_surface(screen, client.surface, client.data.props.position, false) } \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index b5f8a95..053ee05 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -1,4 +1,4 @@ -.{math: .{Vec2}} := @use("../../stn/src/lib.hb"); +.{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb"); .{Surface} := @use("../../render/src/lib.hb") $BUFFER := "sunset\0" @@ -7,6 +7,34 @@ client := @use("./client.hb") server := @use("./server.hb") message := @use("./message.hb") +receive_message := fn($Expr: type, buffer_id: uint): ?Expr { + recv := @as(?Expr, null) + @inline(buffer.recv, ?Expr, buffer_id, &recv) + return recv +} + +send_message := fn($Expr: type, msg: Expr, buffer_id: uint): void { + @inline(buffer.write, ?Expr, buffer_id, &@as(?Expr, msg)) +} + +await_buffer := fn(name: ^u8): uint { + id := 0 + loop if id != 0 return id else id = buffer.search(BUFFER) +} + +await_message := fn($Expr: type, buffer_id: uint): Expr { + response := @as(?Expr, null) + loop { + @inline(buffer.recv, ?Expr, buffer_id, &response) + if response != null { + i := 0 + return @as(Expr, response) + } + } +} + +// ! we need a better message format but this will do for now. +// enums would be nice MessageHeader := packed struct { kind: uint, data: uint, @@ -15,7 +43,7 @@ MessageHeader := packed struct { WindowProps := struct { position: Vec2(uint), dimensions: Vec2(uint), - // replace with owned string type later + // ! replace with owned string type later title: ^u8, } diff --git a/sysdata/libraries/sunset_proto/src/message.hb b/sysdata/libraries/sunset_proto/src/message.hb index 9c69092..b12d3d7 100644 --- a/sysdata/libraries/sunset_proto/src/message.hb +++ b/sysdata/libraries/sunset_proto/src/message.hb @@ -1,6 +1,8 @@ +// ! all values in this file are subject to change. $syn := 1 $ack := 2 $refused := 3 $quit := 4 $update_props := 5 -$shutdown := 6 \ No newline at end of file +$shutdown := 6 +$ready := 7 \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index 46d4617..1c14ee8 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -1,65 +1,46 @@ .{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb"); .{Surface, new_surface} := @use("../../render/src/lib.hb"); -.{Window, WindowProps, WindowData, MessageHeader, BUFFER, message} := @use("./lib.hb") +.{Window, WindowProps, WindowData, MessageHeader, BUFFER, message, receive_message, send_message, await_message} := @use("./lib.hb") WindowServer := struct { window_count: uint, id: uint, - // replace this with an actual collection when we get an allocator + // ! replace this with an actual collection when we get an allocator windows: ^WindowData, } -server := @as(?WindowServer, null) +// ! in the future this should be safely handled +server := @as(WindowServer, idk) -init := fn(): void { - if server != null { - return - } - log.info("server: starting server\0") +start := fn(): void { windows := memory.alloc(WindowData, 10) server = .(0, buffer.create(BUFFER), windows) + log.debug("server: started server\0") } +// ! this function will be rewritten to several functions that allow the server mainloop to handle these itself handle_connections := fn(): bool { - if server == null { - return false - } - recv := memory.uninit(MessageHeader) - buffer.recv(?MessageHeader, @unwrap(server).id, &recv) + recv := receive_message(MessageHeader, server.id) if recv == null { return true - } else if recv.kind == message.syn { - buffer_id := buffer.create("asdf\0") - buffer.write(?MessageHeader, &@as(?MessageHeader, .(message.ack, buffer_id)), @unwrap(server).id) - log.info("server: sent ack\0") + } + if recv.kind == message.syn { + buffer_id := buffer.create_without_name() + + send_message(MessageHeader, .(message.ack, buffer_id), server.id) + log.debug("server: sent ack\0") + + resp := await_message(WindowProps, buffer_id) + log.debug("server: received props\0") - timer := 0 - resp := memory.uninit(WindowProps) - loop if timer < 1000 { - buffer.recv(?WindowProps, buffer_id, &resp) - if resp != null { - break - } - timer += 1 - } else { - log.error("server: no props in timeout\0") - return true - } - log.info("server: received props\0") - surface := new_surface(resp.dimensions.x, resp.dimensions.y) data := WindowData.(@as(WindowProps, resp), buffer_id) - buffer.write(?WindowData, &@as(?WindowData, data), buffer_id) - log.info("server: sent window data\0"); - *(@unwrap(server).windows + @unwrap(server).window_count) = data - @unwrap(server).window_count += 1 - } else if recv.kind == message.quit { - // todo: quit + send_message(WindowData, data, buffer_id) + log.debug("server: sent window data\0"); + *(server.windows + server.window_count) = data + server.window_count += 1 } else if recv.kind == message.shutdown { + log.warn("server: shutdown handled without validation\n\r this is temporary behaviour\0") return false } return true -} - -should_shutdown := fn(): bool { - return false } \ No newline at end of file diff --git a/sysdata/programs/ps2_keyboard_driver/src/main.hb b/sysdata/programs/ps2_keyboard_driver/src/main.hb index 41485ca..9d2c8df 100644 --- a/sysdata/programs/ps2_keyboard_driver/src/main.hb +++ b/sysdata/programs/ps2_keyboard_driver/src/main.hb @@ -34,7 +34,7 @@ main := fn(): int { prev_input = input kevent := KeyEvent.(false, true, input) - buffer.write(KeyEvent, &kevent, buf) + buffer.write(KeyEvent, buf, &kevent) } return 0 } \ No newline at end of file diff --git a/sysdata/programs/ps2_mouse_driver/src/main.hb b/sysdata/programs/ps2_mouse_driver/src/main.hb index 5468017..1faa417 100644 --- a/sysdata/programs/ps2_mouse_driver/src/main.hb +++ b/sysdata/programs/ps2_mouse_driver/src/main.hb @@ -145,7 +145,7 @@ main := fn(): int { event.x_change = x_change event.y_change = y_change - buffer.write(MouseEvent, &event, mouse_buffer) + buffer.write(MouseEvent, mouse_buffer, &event) } return 0 diff --git a/sysdata/programs/render_example/src/examples/colors.hb b/sysdata/programs/render_example/src/examples/colors.hb index bb23933..d6c14db 100644 --- a/sysdata/programs/render_example/src/examples/colors.hb +++ b/sysdata/programs/render_example/src/examples/colors.hb @@ -12,10 +12,10 @@ example := fn(): void { loop { render.clear(screen, color) render.sync(screen) - if (color.b & 255) == 255 | (color.b & 255) == 0 { - n = -n + if color.b == 255 | color.b == 0 { + // compiler bug workaround + n = 0 - n } color.b += n } - return } \ No newline at end of file diff --git a/sysdata/programs/sunset_client/src/main.hb b/sysdata/programs/sunset_client/src/main.hb index 86b8ac7..1dfc989 100644 --- a/sysdata/programs/sunset_client/src/main.hb +++ b/sysdata/programs/sunset_client/src/main.hb @@ -1,12 +1,20 @@ .{log, string} := @use("../../../libraries/stn/src/lib.hb") sunset := @use("../../../libraries/sunset_proto/src/lib.hb") +render := @use("../../../libraries/render/src/lib.hb") main := fn(): void { - window := sunset.client.new(.(.(100, 100), .(100, 100), "Hello, World!\0")) - if window == null { - log.error("client: window was null\0") + sunset.client.find_server() + client := sunset.client.new(.(.(100, 100), .(100, 100), "Hello, World!\0")) + if client == null { + log.error("we did not get a window\0") return } - log.info("client: window title:\0") - log.info(window.data.props.title) + if sunset.client.update_props(client) == false { + log.error("we did not update props\0") + } + + render.put_filled_circle(client.surface, .(50, 50), 20, render.white) + sunset.client.frame_ready(client) + sunset.client.quit(client) + sunset.client.shutdown_server() } \ No newline at end of file diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index 98f421b..79dc01e 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -1,7 +1,7 @@ sunset := @use("../../../libraries/sunset_proto/src/lib.hb") main := fn(): void { - sunset.server.init() + sunset.server.start() loop if sunset.server.handle_connections() { } } \ No newline at end of file From e6d8f5c822788280020be7d72e133d2db168568d Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 11 Nov 2024 17:49:11 -0600 Subject: [PATCH 04/14] todo changes --- todo.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/todo.md b/todo.md index c1b6ea2..b29d223 100644 --- a/todo.md +++ b/todo.md @@ -19,12 +19,14 @@ @morshy Simple Userland Allocator +@funky + Kernel Testing Framework (A rust framework for testing the kernel) + @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) From dc9273b3c1e6097c06a876eac7c4bddcc50febb2 Mon Sep 17 00:00:00 2001 From: koniifer Date: Tue, 12 Nov 2024 20:14:37 +0000 Subject: [PATCH 05/14] various opts and keeping on top of compiler changes --- Cargo.lock | 10 +- .../holeybytes/kernel_services/mem_serve.rs | 42 +----- sysdata/libraries/render/src/image/bmp.hb | 4 +- sysdata/libraries/render/src/image/qoi.hb | 6 +- sysdata/libraries/render/src/software.hb | 137 +++++++++--------- sysdata/libraries/render/src/text.hb | 8 +- sysdata/libraries/stn/src/buffer.hb | 12 +- sysdata/libraries/stn/src/math.hb | 31 +--- sysdata/libraries/stn/src/memory.hb | 33 +++-- sysdata/libraries/stn/src/random.hb | 2 +- sysdata/libraries/sunset_proto/src/client.hb | 2 +- sysdata/libraries/sunset_proto/src/lib.hb | 6 +- sysdata/libraries/sunset_proto/src/server.hb | 2 +- .../render_example/src/examples/colors.hb | 4 +- .../render_example/src/examples/text.hb | 2 +- sysdata/programs/render_example/src/main.hb | 2 +- sysdata/system_config.toml | 12 +- 17 files changed, 136 insertions(+), 179 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 095b1af..02a6658 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,9 +82,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.1.37" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" +checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8" dependencies = [ "shlex", ] @@ -228,12 +228,12 @@ dependencies = [ [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d99672b75179b79249c4b6b91dfccef0b757fa3a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b71031c1463c2bec1984316ea5f5173a9e09c028" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d99672b75179b79249c4b6b91dfccef0b757fa3a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b71031c1463c2bec1984316ea5f5173a9e09c028" 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#d99672b75179b79249c4b6b91dfccef0b757fa3a" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b71031c1463c2bec1984316ea5f5173a9e09c028" dependencies = [ "hbbytecode", ] diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index b769390..3f9c6b2 100644 --- a/kernel/src/holeybytes/kernel_services/mem_serve.rs +++ b/kernel/src/holeybytes/kernel_services/mem_serve.rs @@ -25,42 +25,16 @@ fn alloc_page(vm: &mut Vm, _mem_addr: u64, _length: usize) -> Result<(), MemoryS } #[inline(always)] -unsafe fn memset(mut dest: *mut u8, src: *const u8, count: usize, size: usize) { - const BLOCK_SIZE: usize = 64; - let mut remaining = count * size; +unsafe fn memset(dest: *mut u8, src: *const u8, count: usize, size: usize) { + let total_size = count * size; + src.copy_to_nonoverlapping(dest, size); - if remaining < 16 { - src.copy_to_nonoverlapping(dest, remaining); - return; - } + let mut copied = size; - let mut buffer = [0u8; BLOCK_SIZE]; - let mut buffer_size = size; - src.copy_to_nonoverlapping(buffer.as_mut_ptr(), size); - - while core::intrinsics::likely(buffer_size * 2 <= BLOCK_SIZE) { - buffer - .as_mut_ptr() - .copy_to_nonoverlapping(buffer.as_mut_ptr().add(buffer_size), buffer_size); - buffer_size *= 2; - } - - let buffer_ptr = buffer.as_ptr() as *const u64; - - while (dest as usize) & 7 != 0 && remaining >= 8 { - buffer.as_ptr().copy_to_nonoverlapping(dest, 1); - dest = dest.add(1); - remaining -= 1; - } - - while core::intrinsics::likely(remaining >= 8) { - *(dest as *mut u64) = *buffer_ptr; - dest = dest.add(8); - remaining -= 8; - } - - if remaining > 0 { - buffer.as_ptr().copy_to_nonoverlapping(dest, remaining); + while copied < total_size { + let copy_size = copied.min(total_size - copied); + dest.add(copied).copy_from_nonoverlapping(dest, copy_size); + copied += copy_size; } } diff --git a/sysdata/libraries/render/src/image/bmp.hb b/sysdata/libraries/render/src/image/bmp.hb index d9950c6..9c48dac 100644 --- a/sysdata/libraries/render/src/image/bmp.hb +++ b/sysdata/libraries/render/src/image/bmp.hb @@ -1,5 +1,5 @@ .{Color, Surface, new_surface, put_surface} := @use("../lib.hb"); -.{log, memory} := @use("../../../stn/src/lib.hb") +.{log} := @use("../../../stn/src/lib.hb") BitmapFileHeader := packed struct { magic: u16, @@ -41,7 +41,7 @@ from := fn(bmp: ^u8): ?Surface { return null } - lhs := Surface.(@bitcast(bmp + file_header.offset), info_header.width, info_header.height) + lhs := Surface.(@bitcast(bmp + file_header.offset), info_header.width, info_header.height, info_header.width * info_header.height) rhs := new_surface(info_header.width, info_header.height) put_surface(rhs, lhs, .(0, 0), true) diff --git a/sysdata/libraries/render/src/image/qoi.hb b/sysdata/libraries/render/src/image/qoi.hb index 2f4c888..a090e3a 100644 --- a/sysdata/libraries/render/src/image/qoi.hb +++ b/sysdata/libraries/render/src/image/qoi.hb @@ -1,5 +1,5 @@ .{Color, Surface, new_surface} := @use("../lib.hb"); -.{log, memory} := @use("../../../stn/src/lib.hb") +.{log} := @use("../../../stn/src/lib.hb") /* source: https://github.com/phoboslab/qoi/blob/master/qoi.h */ @@ -13,7 +13,7 @@ $QOI_OP_RUN := 0xC0 $QOI_OP_RGB := 0xFE $QOI_OP_RGBA := 0xFF $QOI_MASK_2 := 0xC0 -QOI_COLOR_HASH := fn(c: Color): u8 { +$QOI_COLOR_HASH := fn(c: Color): u8 { return (c.r * 3 + c.g * 5 + c.b * 7 + c.a * 11) % 64 } $QOI_MAGIC := 0x716F6966 @@ -89,7 +89,7 @@ from := fn(qoi: ^u8): ?Surface { run = b1 & 0x3F } - index[@inline(QOI_COLOR_HASH, px)] = px + index[QOI_COLOR_HASH(px)] = px }; *(surface.buf + px_pos) = px diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index 0c4780e..262461e 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -10,19 +10,21 @@ Surface := struct { buf: ^Color, width: uint, height: uint, + size: uint, } new_surface := fn(width: uint, height: uint): Surface { return .( - @inline(memory.alloc, Color, width * height), + memory.alloc(Color, width * height), width, height, + width * height, ) } clone_surface := fn(surface: ^Surface): Surface { new := new_surface(surface.width, surface.height) - @inline(memory.copy, Color, surface.buf, new.buf, @intcast(surface.width * surface.height)) + memory.copy(Color, surface.buf, new.buf, @intcast(surface.size)) return new } @@ -33,42 +35,38 @@ init := fn(doublebuffer: bool): Surface { if doublebuffer { return new_surface(width, height) } else { - return .(framebuffer, width, height) + return .(framebuffer, width, height, width * height) } } -clear := fn(surface: Surface, color: Color): void { - return @inline(memory.set, Color, &color, surface.buf, surface.width * surface.height) +$clear := fn(surface: Surface, color: Color): void { + memory.set(Color, &color, surface.buf, surface.width * surface.height) } -sync := fn(surface: Surface): void { - if surface.buf == framebuffer { - return - } - return @inline(memory.copy, Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height)) +$sync := fn(surface: Surface): void { + memory.copy(Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height)) } -index := fn(surface: Surface, x: uint, y: uint): uint { +$index := fn(surface: Surface, x: uint, y: uint): uint { return x + surface.width * y } -indexptr := fn(surface: Surface, x: uint, y: uint): ^Color { - return surface.buf + @inline(index, surface, x, y) +$indexptr := fn(surface: Surface, x: uint, y: uint): ^Color { + return surface.buf + index(surface, x, y) } -put_pixel := fn(surface: Surface, pos: Vec2(uint), color: Color): void { - *@inline(indexptr, surface, pos.x, pos.y) = color - return +$put_pixel := fn(surface: Surface, pos: Vec2(uint), color: Color): void { + return *indexptr(surface, pos.x, pos.y) = color } put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void { - top_start_idx := @inline(indexptr, surface, pos.x, pos.y) - bottom_start_idx := @inline(indexptr, surface, pos.x, pos.y + tr.y - 1) + top_start_idx := indexptr(surface, pos.x, pos.y) + bottom_start_idx := indexptr(surface, pos.x, pos.y + tr.y - 1) rows_to_fill := tr.y loop if rows_to_fill <= 1 break else { - @inline(memory.set, Color, &color, top_start_idx, tr.x) - @inline(memory.set, Color, &color, bottom_start_idx, tr.x) + memory.set(Color, &color, top_start_idx, tr.x) + memory.set(Color, &color, bottom_start_idx, tr.x) top_start_idx += surface.width bottom_start_idx -= surface.width @@ -76,16 +74,16 @@ put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: } if rows_to_fill == 1 { - @inline(memory.set, Color, &color, top_start_idx, tr.x) + memory.set(Color, &color, top_start_idx, tr.x) } return } put_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void { - start_idx := @inline(indexptr, surface, pos.x, pos.y) - end_idx := @inline(indexptr, surface, pos.x, pos.y + tr.y) - right_start_idx := @inline(indexptr, surface, pos.x + tr.x, pos.y) + start_idx := indexptr(surface, pos.x, pos.y) + end_idx := indexptr(surface, pos.x, pos.y + tr.y) + right_start_idx := indexptr(surface, pos.x + tr.x, pos.y) loop if start_idx > end_idx break else { *start_idx = color; @@ -94,8 +92,8 @@ put_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): right_start_idx += surface.width } - @inline(memory.set, Color, &color, @inline(indexptr, surface, pos.x, pos.y), @bitcast(tr.x + 1)) - @inline(memory.set, Color, &color, @inline(indexptr, surface, pos.x, pos.y + tr.y), @bitcast(tr.x + 1)) + memory.set(Color, &color, indexptr(surface, pos.x, pos.y), @bitcast(tr.x + 1)) + memory.set(Color, &color, indexptr(surface, pos.x, pos.y + tr.y), @bitcast(tr.x + 1)) return } @@ -112,7 +110,7 @@ put_line_low := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Colo y := p0.y x := p0.x loop if x == p1.x break else { - *@inline(indexptr, surface, x, y) = color + *indexptr(surface, x, y) = color if D > 0 { y += yi D += 2 * (dy - dx) @@ -136,7 +134,7 @@ put_line_high := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Col x := p0.x y := p0.y loop if y == p1.y break else { - *@inline(indexptr, surface, x, y) = color + *indexptr(surface, x, y) = color if D > 0 { x += xi D += 2 * (dx - dy) @@ -169,8 +167,8 @@ put_surface := fn(surface: Surface, top: Surface, pos: Vec2(uint), flip_v: bool) src_top_cursor := top.buf src_bottom_cursor := top.buf + top.width * (top.height - 1) - dst_top_idx := @inline(indexptr, surface, pos.x, pos.y) - dst_bottom_idx := @inline(indexptr, surface, pos.x, pos.y + top.height - 1) + dst_top_idx := indexptr(surface, pos.x, pos.y) + dst_bottom_idx := indexptr(surface, pos.x, pos.y + top.height - 1) dst_increment := surface.width @@ -184,8 +182,8 @@ put_surface := fn(surface: Surface, top: Surface, pos: Vec2(uint), flip_v: bool) rows_to_copy := top.height loop if rows_to_copy <= 1 break else { - @inline(memory.copy, Color, src_top_cursor, dst_top_idx, top.width) - @inline(memory.copy, Color, src_bottom_cursor, dst_bottom_idx, top.width) + memory.copy(Color, src_top_cursor, dst_top_idx, top.width) + memory.copy(Color, src_bottom_cursor, dst_bottom_idx, top.width) dst_top_idx += dst_increment dst_bottom_idx -= dst_increment @@ -195,7 +193,7 @@ put_surface := fn(surface: Surface, top: Surface, pos: Vec2(uint), flip_v: bool) } if rows_to_copy == 1 { - @inline(memory.copy, Color, src_top_cursor, dst_top_idx, top.width) + memory.copy(Color, src_top_cursor, dst_top_idx, top.width) } return @@ -233,7 +231,7 @@ put_vline := fn(surface: Surface, x: uint, y0: uint, y1: uint, color: Color): vo y := y0 loop if y == y1 break else { - *@inline(indexptr, surface, x, y) = color + *indexptr(surface, x, y) = color y += 1 } @@ -247,7 +245,8 @@ put_hline := fn(surface: Surface, y: uint, x0: uint, x1: uint, color: Color): vo x0 = x1 x1 = tmp } - @inline(memory.set, Color, &color, @inline(indexptr, surface, x0, y), @bitcast(x1 - x0 - 1)) + // x0 = math.min(x0, x1) + memory.set(Color, &color, indexptr(surface, x0, y), @bitcast(x1 - x0 - 1)) return } @@ -255,29 +254,29 @@ put_hline := fn(surface: Surface, y: uint, x0: uint, x1: uint, color: Color): vo put_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void { x := 0 y := radius - error := @as(int, 3) - @as(int, @intcast(2 * radius)); - *@inline(indexptr, surface, pos.x + radius, pos.y) = color; - *@inline(indexptr, surface, pos.x - radius, pos.y) = color; - *@inline(indexptr, surface, pos.x, pos.y + radius) = color; - *@inline(indexptr, surface, pos.x, pos.y - radius) = color + error := @as(int, 3) - @intcast(2 * radius); + *indexptr(surface, pos.x + radius, pos.y) = color; + *indexptr(surface, pos.x - radius, pos.y) = color; + *indexptr(surface, pos.x, pos.y + radius) = color; + *indexptr(surface, pos.x, pos.y - radius) = color loop if y < x break else { x += 1 if error > 0 { y -= 1 - error += 4 * (@as(int, @intcast(x)) - @as(int, @intcast(y))) + 10 + error += 4 * (@intcast(x) - @intcast(y)) + 10 } else { error += 4 * @intcast(x) + 6 }; - *@inline(indexptr, surface, pos.x + x, pos.y + y) = color; - *@inline(indexptr, surface, pos.x + y, pos.y + x) = color; - *@inline(indexptr, surface, pos.x - x, pos.y + y) = color; - *@inline(indexptr, surface, pos.x - y, pos.y + x) = color; - *@inline(indexptr, surface, pos.x + x, pos.y - y) = color; - *@inline(indexptr, surface, pos.x + y, pos.y - x) = color; - *@inline(indexptr, surface, pos.x - x, pos.y - y) = color; - *@inline(indexptr, surface, pos.x - y, pos.y - x) = color + *indexptr(surface, pos.x + x, pos.y + y) = color; + *indexptr(surface, pos.x + y, pos.y + x) = color; + *indexptr(surface, pos.x - x, pos.y + y) = color; + *indexptr(surface, pos.x - y, pos.y + x) = color; + *indexptr(surface, pos.x + x, pos.y - y) = color; + *indexptr(surface, pos.x + y, pos.y - x) = color; + *indexptr(surface, pos.x - x, pos.y - y) = color; + *indexptr(surface, pos.x - y, pos.y - x) = color } return @@ -286,24 +285,24 @@ put_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): put_filled_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void { x := 0 y := radius - error := @as(int, 3) - @as(int, @intcast(2 * radius)) - @inline(put_hline, surface, pos.y - x, pos.x - radius, pos.x + radius, color); - *@inline(indexptr, surface, pos.x, pos.y + radius) = color; - *@inline(indexptr, surface, pos.x, pos.y - radius) = color + error := @as(int, 3) - @intcast(2 * radius) + put_hline(surface, pos.y - x, pos.x - radius, pos.x + radius, color); + *indexptr(surface, pos.x, pos.y + radius) = color; + *indexptr(surface, pos.x, pos.y - radius) = color loop if y < x break else { x += 1 if error > 0 { - @inline(put_hline, surface, pos.y + y, pos.x - x, pos.x + x, color) - @inline(put_hline, surface, pos.y - y, pos.x - x, pos.x + x, color) + put_hline(surface, pos.y + y, pos.x - x, pos.x + x, color) + put_hline(surface, pos.y - y, pos.x - x, pos.x + x, color) y -= 1 - error += 4 * (@as(int, @intcast(x)) - @as(int, @intcast(y))) + 10 + error += 4 * (@intcast(x) - @intcast(y)) + 10 } else { error += 4 * @intcast(x) + 6 } - @inline(put_hline, surface, pos.y + x, pos.x - y, pos.x + y, color) - @inline(put_hline, surface, pos.y - x, pos.x - y, pos.x + y, color) + put_hline(surface, pos.y + x, pos.x - y, pos.x + y, color) + put_hline(surface, pos.y - x, pos.x - y, pos.x + y, color) } return @@ -312,24 +311,24 @@ put_filled_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: put_textured_circle := fn(surface: Surface, source: Surface, source_pos: Vec2(uint), pos: Vec2(uint), radius: uint): void { x := 0 y := radius - error := @as(int, 3) - @as(int, @intcast(2 * radius)) - @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - y, source_pos.y), @inline(indexptr, surface, pos.x - y, pos.y), 2 * y); - *@inline(indexptr, surface, pos.x, pos.y + y) = *@inline(indexptr, source, source_pos.x, source_pos.y + y); - *@inline(indexptr, surface, pos.x, pos.y - y) = *@inline(indexptr, source, source_pos.x, source_pos.y - y) + error := @as(int, 3) - @intcast(2 * radius) + memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y), indexptr(surface, pos.x - y, pos.y), 2 * y); + *indexptr(surface, pos.x, pos.y + y) = *indexptr(source, source_pos.x, source_pos.y + y); + *indexptr(surface, pos.x, pos.y - y) = *indexptr(source, source_pos.x, source_pos.y - y) loop if y < x break else { x += 1 if error > 0 { - @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - x, source_pos.y + y), @inline(indexptr, surface, pos.x - x, pos.y + y), 2 * x) - @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - x, source_pos.y - y), @inline(indexptr, surface, pos.x - x, pos.y - y), 2 * x) + memory.copy(Color, indexptr(source, source_pos.x - x, source_pos.y + y), indexptr(surface, pos.x - x, pos.y + y), 2 * x) + memory.copy(Color, indexptr(source, source_pos.x - x, source_pos.y - y), indexptr(surface, pos.x - x, pos.y - y), 2 * x) y -= 1 - error += 4 * (@as(int, @intcast(x)) - @as(int, @intcast(y))) + 10 + error += 4 * (@intcast(x) - @intcast(y)) + 10 } else { error += 4 * @intcast(x) + 6 } - @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - y, source_pos.y + x), @inline(indexptr, surface, pos.x - y, pos.y + x), 2 * y) - @inline(memory.copy, Color, @inline(indexptr, source, source_pos.x - y, source_pos.y - x), @inline(indexptr, surface, pos.x - y, pos.y - x), 2 * y) + memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y + x), indexptr(surface, pos.x - y, pos.y + x), 2 * y) + memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y - x), indexptr(surface, pos.x - y, pos.y - x), 2 * y) } return @@ -364,7 +363,7 @@ put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str: str += 1 continue } - glyph_data = @inline(get_glyph, font, *str) + glyph_data = get_glyph(font, *str) } else { if *str < UNC_TABLE_SIZE { glyph_index := *(font.unicode + *str) @@ -436,7 +435,7 @@ put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str: cursor.y += next_line_y } - dest := @inline(indexptr, surface, cursor.x, cursor.y) + dest := indexptr(surface, cursor.x, cursor.y) rows := font.height loop if rows == 0 break else { diff --git a/sysdata/libraries/render/src/text.hb b/sysdata/libraries/render/src/text.hb index 5a70a07..795855e 100644 --- a/sysdata/libraries/render/src/text.hb +++ b/sysdata/libraries/render/src/text.hb @@ -74,16 +74,16 @@ font_from_psf2 := fn(psf: ^u8, unicode: bool): ?Font { return font } -get_glyph := fn(font: Font, index: u8): ^u8 { +$get_glyph := fn(font: Font, index: u8): ^u8 { return font.data + @as(uint, index) * font.bytes_per_glyph } -UNC_TABLE_SIZE := 1 << 16 +$UNC_TABLE_SIZE := 1 << 16 init_unicode := fn(font: ^Font): void { font.unicode = memory.alloc(u16, UNC_TABLE_SIZE) - @inline(memory.set, u16, &0xFFFF, font.unicode, UNC_TABLE_SIZE) + memory.set(u16, &0xFFFF, font.unicode, UNC_TABLE_SIZE) table := font.data + font.num_glyphs * font.bytes_per_glyph curr_glyph := @as(u16, 0) @@ -121,8 +121,6 @@ init_unicode := fn(font: ^Font): void { next_byte := *table if (next_byte & 0xC0) != 0x80 { valid = false - } - if valid == false { break } unicode = unicode << 6 | next_byte & 0x3F diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index e54b959..2a448b8 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -1,18 +1,18 @@ string := @use("string.hb") -recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void { +$recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^Expr): void { return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) } -write := fn($Expr: type, buffer_id: uint, msg: ^Expr): void { +$write := fn($Expr: type, buffer_id: uint, msg: ^Expr): void { return @eca(3, buffer_id, msg, @sizeof(Expr)) } -recv_length := fn(length: uint, memory_map_location: ^u8, buffer_id: uint): void { +$recv_length := fn(length: uint, memory_map_location: ^u8, buffer_id: uint): void { return @eca(4, buffer_id, memory_map_location, length) } -write_length := fn(length: uint, msg: ^u8, buffer_id: uint): void { +$write_length := fn(length: uint, msg: ^u8, buffer_id: uint): void { return @eca(3, buffer_id, msg, length) } @@ -22,11 +22,11 @@ create := fn(msg: ^u8): uint { return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } -create_without_name := fn(): uint { +$create_without_name := fn(): uint { return @eca(1, 0) } -delete_buffer := fn(buffer_id: uint): void { +$delete_buffer := fn(buffer_id: uint): void { return @eca(2, buffer_id) } diff --git a/sysdata/libraries/stn/src/math.hb b/sysdata/libraries/stn/src/math.hb index 1365d0d..d60495c 100644 --- a/sysdata/libraries/stn/src/math.hb +++ b/sysdata/libraries/stn/src/math.hb @@ -1,29 +1,14 @@ -abs := fn($Expr: type, x: Expr): Expr { - mask := x >> @bitcast(@sizeof(Expr) - 1) - return (x ^ mask) - mask +$abs := fn($Expr: type, x: Expr): Expr { + return (x ^ x >> @sizeof(Expr) - 1) - (x >> @sizeof(Expr) - 1) } -min := fn($Expr: type, a: Expr, b: Expr): Expr { - c := a - b - return b + (c & c >> @bitcast(@sizeof(Expr) - 1)) +$min := fn($Expr: type, a: Expr, b: Expr): Expr { + return b + (a - b & a - b >> @sizeof(Expr) - 1) } -max := fn($Expr: type, a: Expr, b: Expr): Expr { - c := a - b - return a - (c & c >> @bitcast(@sizeof(Expr) - 1)) +$max := fn($Expr: type, a: Expr, b: Expr): Expr { + return a - (a - b & a - b >> @sizeof(Expr) - 1) } -signum := fn($Expr: type, x: Expr): int { - if x > @as(Expr, @intcast(0)) { - return 1 - } else if x < @as(Expr, @intcast(0)) { - return -1 - } else { - return 0 - } -} -signincl := fn($Expr: type, x: Expr): int { - if x > @as(Expr, @intcast(0)) { - return 1 - } - return -1 +$sign := fn($Expr: type, x: Expr): i8 { + return @bitcast(x > 0) - @bitcast(x < 0) } Vec2 := fn($Expr: type): type { diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index 5bebd68..03a6cfe 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -1,8 +1,8 @@ -PAGE_SIZE := 4096 -MAX_ALLOC := 0xFF -MAX_FREE := 0xFF +$PAGE_SIZE := 4096 +$MAX_ALLOC := 0xFF +$MAX_FREE := 0xFF -uninit := fn($Expr: type): ?Expr { +$uninit := fn($Expr: type): ?Expr { return null } @@ -10,16 +10,17 @@ dangling := fn($Expr: type): ^Expr { return @bitcast(@alignof(Expr)) } -calc_pages := fn($Expr: type, num: uint): uint { +$calc_pages := fn($Expr: type, num: uint): uint { return 1 + @sizeof(Expr) * num / PAGE_SIZE } +// ! will be replaced, don't get attached alloc := fn($Expr: type, num: uint): ^Expr { - pages := @inline(calc_pages, Expr, num) + pages := calc_pages(Expr, num) if pages <= MAX_ALLOC { return @bitcast(request_page(@intcast(pages))) } - ptr := request_page(0xFF) + ptr := request_page(MAX_ALLOC) remaining := pages - MAX_ALLOC loop if remaining < MAX_ALLOC break else { _ = request_page(@intcast(MAX_ALLOC)) @@ -30,46 +31,46 @@ alloc := fn($Expr: type, num: uint): ^Expr { } // ! stub -free := fn($Expr: type, ptr: ^Expr, num: uint, nullify: bool): void { +$free := fn($Expr: type, ptr: ^Expr, num: uint, nullify: bool): void { return } RqPageMsg := packed struct {a: u8, count: u8} -request_page := fn(count: u8): ^u8 { +$request_page := fn(count: u8): ^u8 { return @eca(3, 2, &RqPageMsg.(0, count), @sizeof(RqPageMsg)) } RlPageMsg := packed struct {a: u8, count: u8, ptr: ^u8} -release_page := fn(ptr: ^u8, count: u8): void { +$release_page := fn(ptr: ^u8, count: u8): void { return @eca(3, 2, &RlPageMsg.(1, count, ptr), @sizeof(RlPageMsg)) } OutbMsg := packed struct {a: u8, b: u8, addr: u16, value: u8} -outb := fn(addr: u16, value: u8): void { +$outb := fn(addr: u16, value: u8): void { return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg)) } InbMsg := packed struct {a: u8, b: u8, addr: u16} -inb := fn(addr: u16): u8 { +$inb := fn(addr: u16): u8 { return @eca(3, 3, &InbMsg.(0, 0, addr), @sizeof(InbMsg)) } OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32} -outl := fn(addr: u16, value: u32): void { +$outl := fn(addr: u16, value: u32): void { return @eca(3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg)) } InlMsg := packed struct {a: u8, b: u8, addr: u16} -inl := fn(addr: u16): u32 { +$inl := fn(addr: u16): u32 { return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg)) } CopyMsg := packed struct {a: u8, count: u32, src: ^u8, dest: ^u8} -copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { +$copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { return @eca(3, 2, &CopyMsg.(4, @intcast(count * @sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg)) } SetMsg := packed struct {a: u8, count: u32, size: u32, src: ^u8, dest: ^u8} -set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { +$set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { return @eca(3, 2, &SetMsg.(5, @intcast(count), @intcast(@sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg)) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/random.hb b/sysdata/libraries/stn/src/random.hb index 4fb7b3f..a7e5ec2 100644 --- a/sysdata/libraries/stn/src/random.hb +++ b/sysdata/libraries/stn/src/random.hb @@ -3,5 +3,5 @@ any := fn($Expr: type): Expr { } range := fn($Expr: type, min: Expr, max: Expr): Expr { - return @inline(any, Expr) % (max - min) + @intcast(1) + min + return *@eca(3, 4, &@as(Expr, idk), @sizeof(Expr)) % (max - min) + *@bitcast(&1) + min } \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/client.hb b/sysdata/libraries/sunset_proto/src/client.hb index 6590754..9044bdb 100644 --- a/sysdata/libraries/sunset_proto/src/client.hb +++ b/sysdata/libraries/sunset_proto/src/client.hb @@ -34,7 +34,7 @@ new := fn(props: WindowProps): ?Window { response2.props.dimensions.x, response2.props.dimensions.y, ) - return .(@as(WindowData, response2), surface) + return .(response2, surface) } // ! client buffers are not being read by the server yet diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index 053ee05..f4f0a5d 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -9,12 +9,12 @@ message := @use("./message.hb") receive_message := fn($Expr: type, buffer_id: uint): ?Expr { recv := @as(?Expr, null) - @inline(buffer.recv, ?Expr, buffer_id, &recv) + buffer.recv(?Expr, buffer_id, &recv) return recv } send_message := fn($Expr: type, msg: Expr, buffer_id: uint): void { - @inline(buffer.write, ?Expr, buffer_id, &@as(?Expr, msg)) + buffer.write(?Expr, buffer_id, &@as(?Expr, msg)) } await_buffer := fn(name: ^u8): uint { @@ -25,7 +25,7 @@ await_buffer := fn(name: ^u8): uint { await_message := fn($Expr: type, buffer_id: uint): Expr { response := @as(?Expr, null) loop { - @inline(buffer.recv, ?Expr, buffer_id, &response) + buffer.recv(?Expr, buffer_id, &response) if response != null { i := 0 return @as(Expr, response) diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index 1c14ee8..b205070 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -33,7 +33,7 @@ handle_connections := fn(): bool { resp := await_message(WindowProps, buffer_id) log.debug("server: received props\0") - data := WindowData.(@as(WindowProps, resp), buffer_id) + data := WindowData.(resp, buffer_id) send_message(WindowData, data, buffer_id) log.debug("server: sent window data\0"); *(server.windows + server.window_count) = data diff --git a/sysdata/programs/render_example/src/examples/colors.hb b/sysdata/programs/render_example/src/examples/colors.hb index d6c14db..5560e9a 100644 --- a/sysdata/programs/render_example/src/examples/colors.hb +++ b/sysdata/programs/render_example/src/examples/colors.hb @@ -10,11 +10,11 @@ example := fn(): void { color := render.light_cyan n := @as(u8, 1) loop { + // ! dead code elimination bug render.clear(screen, color) render.sync(screen) if color.b == 255 | color.b == 0 { - // compiler bug workaround - n = 0 - n + n = -n } color.b += n } diff --git a/sysdata/programs/render_example/src/examples/text.hb b/sysdata/programs/render_example/src/examples/text.hb index 74ae601..a817407 100644 --- a/sysdata/programs/render_example/src/examples/text.hb +++ b/sysdata/programs/render_example/src/examples/text.hb @@ -46,7 +46,7 @@ example := fn(): void { bottom := buf + msg_len - @inline(memory.copy, u8, msg, buf, msg_len) + memory.copy(u8, msg, buf, msg_len) cursor := bottom draw_window(window, font, buf, cursor) diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 77cb04c..9369afd 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1 +1 @@ -.{example: main} := @use("./examples/text.hb") \ No newline at end of file +.{example: main} := @use("./examples/colors.hb") \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 406a1ac..ab597c0 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -22,14 +22,14 @@ 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.horizon] -path = "boot:///horizon.hbf" +# [boot.limine.ableos.modules.horizon] +# path = "boot:///horizon.hbf" -[boot.limine.ableos.modules.ps2_mouse_driver] -path = "boot:///ps2_mouse_driver.hbf" +# [boot.limine.ableos.modules.ps2_mouse_driver] +# path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" From b07bac1f1f63e79adddefacc3e13b6fe07a2ea29 Mon Sep 17 00:00:00 2001 From: koniifer Date: Wed, 13 Nov 2024 17:03:31 +0000 Subject: [PATCH 06/14] broken --- Cargo.lock | 10 +-- sysdata/libraries/render/TODO.md | 3 - sysdata/libraries/stn/src/buffer.hb | 2 +- sysdata/libraries/sunset_proto/src/client.hb | 86 +++++++++--------- sysdata/libraries/sunset_proto/src/lib.hb | 88 +++++++++++++++---- sysdata/libraries/sunset_proto/src/message.hb | 4 +- .../libraries/sunset_proto/src/permissions.hb | 5 ++ sysdata/libraries/sunset_proto/src/server.hb | 70 +++++++++------ sysdata/programs/render_example/src/main.hb | 2 +- sysdata/programs/sunset_client/src/main.hb | 17 ++-- sysdata/programs/sunset_server/src/main.hb | 5 +- sysdata/system_config.toml | 12 +-- 12 files changed, 188 insertions(+), 116 deletions(-) create mode 100644 sysdata/libraries/sunset_proto/src/permissions.hb diff --git a/Cargo.lock b/Cargo.lock index 02a6658..bc4f684 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#b71031c1463c2bec1984316ea5f5173a9e09c028" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#b71031c1463c2bec1984316ea5f5173a9e09c028" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" 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#b71031c1463c2bec1984316ea5f5173a9e09c028" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" dependencies = [ "hbbytecode", ] @@ -824,9 +824,9 @@ dependencies = [ [[package]] name = "uart_16550" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4922792855b1bce30997fbaa5418597902c278a92d20dfe348e6f062c3bd861d" +checksum = "e492212ac378a5e00da953718dafb1340d9fbaf4f27d6f3c5cab03d931d1c049" dependencies = [ "bitflags 2.6.0", "rustversion", diff --git a/sysdata/libraries/render/TODO.md b/sysdata/libraries/render/TODO.md index c17ae88..83ee875 100644 --- a/sysdata/libraries/render/TODO.md +++ b/sysdata/libraries/render/TODO.md @@ -1,7 +1,4 @@ # Images -- General over image format -- Support formats: - - PNG - Animation # API diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 2a448b8..17f5a3f 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -22,7 +22,7 @@ create := fn(msg: ^u8): uint { return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } -$create_without_name := fn(): uint { +$create_nameless := fn(): uint { return @eca(1, 0) } diff --git a/sysdata/libraries/sunset_proto/src/client.hb b/sysdata/libraries/sunset_proto/src/client.hb index 9044bdb..9346e6c 100644 --- a/sysdata/libraries/sunset_proto/src/client.hb +++ b/sysdata/libraries/sunset_proto/src/client.hb @@ -1,59 +1,65 @@ -.{math: .{Vec2}, buffer, log, memory} := @use("../../stn/src/lib.hb"); -.{Window, WindowData, WindowProps, MessageHeader, send_message, message, await_buffer, await_message, BUFFER} := @use("./lib.hb") -render := @use("../../render/src/lib.hb") +.{math: .{Vec2}, buffer, log, memory, string} := @use("../../stn/src/lib.hb"); +.{Channel, Window, send_header, send_message, await_channel, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb"); +.{new_surface, Color} := @use("../../render/src/lib.hb") -server_id := @as(uint, idk) -screen := @as(render.Surface, idk) +// ! in the future this should be safely handled +channel := @as(Channel, idk) find_server := fn(): void { - // ! to be removed in the future - screen = render.init(false) - render.clear(screen, render.black) - log.debug("client: waiting for server\0") - server_id = await_buffer(BUFFER) - log.debug("client: found server\0") + log.info("client: locating server\0") + channel = await_channel() + log.info("client: server located\0") } new := fn(props: WindowProps): ?Window { - send_message(MessageHeader, .(message.syn, 0), server_id) - log.debug("client: sent syn\0") - response := await_message(MessageHeader, server_id) - if response.kind != message.ack { - log.error("client: refused syn\0") + send_header(message.syn, channel.server) + response := await_message(Channel, channel.client) + if response.header.kind != message.ack { + log.info(string.display_int(@bitcast(response.header.kind), "\0\0\0\0\0\0\0\0\0\0\0\0\0", 10)) return null } - log.debug("client: got ack\0") - - buffer_id := response.data - send_message(WindowProps, props, buffer_id) - log.debug("client: sent props\0") - - response2 := await_message(WindowData, buffer_id) - log.debug("client: got window data\0") - surface := render.new_surface( - response2.props.dimensions.x, - response2.props.dimensions.y, - ) - return .(response2, surface) + log.info("client: recv ack\0") + 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") + surface := new_surface(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y) + return .(windowdata.body, surface) } -// ! client buffers are not being read by the server yet quit := fn(client: Window): void { - send_message(MessageHeader, .(message.quit, 0), client.data.buffer_id) + send_header(message.quit, client.data.channel.server) } -shutdown_server := fn(): void { - send_message(MessageHeader, .(message.shutdown, 0), server_id) +connected := fn(client: Window): bool { + return true } -update_props := fn(client: Window): bool { - log.error("client: update props unimplemented\0") +shutdown_server := fn(client: Window): bool { return false } -//! temporarily just throw our window at the screen -frame_ready := fn(client: Window): void { - send_message(MessageHeader, .(message.ready, 0), client.data.buffer_id) - log.warn("client: we are blitting to screen from the client\n\r this is temporary behaviour\0") - render.put_surface(screen, client.surface, client.data.props.position, false) +update_props := fn(client: Window): bool { + return false +} + +update_permissions := fn(client: Window): bool { + return false +} + +send_frame := fn(client: Window): bool { + server_id := client.data.channel.server + client_id := client.data.channel.client + send_header(message.frame_ready, server_id) + response := await_message(uint, client_id) + if response.header.kind != message.ack { + return false + } + log.info("client: recv ack\0") + // ! FOR NOW, server will ALWAYS be local, + // ! so we can send pointer to surface. + send_message(^Color, message.ack, client.surface.buf, server_id) + return true } \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index f4f0a5d..498447f 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -1,43 +1,92 @@ .{math: .{Vec2}, buffer, memory} := @use("../../stn/src/lib.hb"); .{Surface} := @use("../../render/src/lib.hb") -$BUFFER := "sunset\0" +$BUFFER_SERVER := "sunset_server\0" +$BUFFER_CLIENT := "sunset_client\0" + +Channel := packed struct { + client: uint, + server: uint, +} client := @use("./client.hb") server := @use("./server.hb") message := @use("./message.hb") +permissions := @use("./permissions.hb") -receive_message := fn($Expr: type, buffer_id: uint): ?Expr { - recv := @as(?Expr, null) - buffer.recv(?Expr, buffer_id, &recv) - return recv +opaque := fn(i: uint): bool { + if i == 0 { + return true + } + return false } -send_message := fn($Expr: type, msg: Expr, buffer_id: uint): void { - buffer.write(?Expr, buffer_id, &@as(?Expr, msg)) +sleep := fn(): void { + i := 10000000 + loop if opaque(i) break else i -= 1 } -await_buffer := fn(name: ^u8): uint { - id := 0 - loop if id != 0 return id else id = buffer.search(BUFFER) +$send_message := fn($Expr: type, kind: uint, msg: Expr, buffer_id: uint): void { + buffer.write(?Message(Expr), buffer_id, &@as(?Message(Expr), .(.(kind), msg))) } -await_message := fn($Expr: type, buffer_id: uint): Expr { - response := @as(?Expr, null) +$send_header := fn(kind: uint, buffer_id: uint): void { + buffer.write(?MessageHeader, buffer_id, &@as(?MessageHeader, .(kind))) +} + +$recv_message := fn($Expr: type, buffer_id: uint): Message(Expr) { + response := @as(?Message(Expr), null) + buffer.recv(?Message(Expr), buffer_id, &response) + return response +} + +$recv_header := fn(buffer_id: uint): ?MessageHeader { + response := @as(?MessageHeader, null) + buffer.recv(?MessageHeader, buffer_id, &response) + return response +} + +await_channel := fn(): Channel { + server_id := 0 + loop if server_id == 0 { + server_id = buffer.search(BUFFER_SERVER) + } + client_id := 0 + loop if client_id == 0 { + client_id = buffer.search(BUFFER_CLIENT) + } + return .{client: client_id, server: server_id} +} + +await_message := fn($Expr: type, buffer_id: uint): Message(Expr) { + response := @as(?Message(Expr), null) loop { - buffer.recv(?Expr, buffer_id, &response) + buffer.recv(?Message(Expr), buffer_id, &response) if response != null { - i := 0 - return @as(Expr, response) + return @as(Message(Expr), response) + } + } +} + +await_header := fn(buffer_id: uint): MessageHeader { + response := @as(?MessageHeader, null) + loop { + buffer.recv(?MessageHeader, buffer_id, &response) + if response != null { + return @as(?MessageHeader, response) } } } -// ! we need a better message format but this will do for now. -// enums would be nice MessageHeader := packed struct { kind: uint, - data: uint, +} + +Message := fn($Expr: type): type { + return packed struct { + header: MessageHeader, + body: Expr, + } } WindowProps := struct { @@ -49,7 +98,8 @@ WindowProps := struct { WindowData := struct { props: WindowProps, - buffer_id: uint, + channel: Channel, + permissions: uint, } Window := struct { diff --git a/sysdata/libraries/sunset_proto/src/message.hb b/sysdata/libraries/sunset_proto/src/message.hb index b12d3d7..918f55e 100644 --- a/sysdata/libraries/sunset_proto/src/message.hb +++ b/sysdata/libraries/sunset_proto/src/message.hb @@ -3,6 +3,6 @@ $syn := 1 $ack := 2 $refused := 3 $quit := 4 -$update_props := 5 +$props := 5 $shutdown := 6 -$ready := 7 \ No newline at end of file +$frame_ready := 7 \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/permissions.hb b/sysdata/libraries/sunset_proto/src/permissions.hb new file mode 100644 index 0000000..57bf4d8 --- /dev/null +++ b/sysdata/libraries/sunset_proto/src/permissions.hb @@ -0,0 +1,5 @@ +$none := 0b0 +$exclusive_framebuffer := 0b1 +$shutdown := 0b100 + +$default := none \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index b205070..f44bb44 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -1,46 +1,60 @@ .{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb"); -.{Surface, new_surface} := @use("../../render/src/lib.hb"); -.{Window, WindowProps, WindowData, MessageHeader, BUFFER, message, receive_message, send_message, await_message} := @use("./lib.hb") +.{Color, Surface, new_surface, put_surface, sync} := @use("../../render/src/lib.hb"); +.{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("./lib.hb") WindowServer := struct { window_count: uint, - id: uint, + channel: Channel, // ! replace this with an actual collection when we get an allocator - windows: ^WindowData, + windows: [?WindowData; 10], } // ! in the future this should be safely handled server := @as(WindowServer, idk) start := fn(): void { - windows := memory.alloc(WindowData, 10) - server = .(0, buffer.create(BUFFER), windows) - log.debug("server: started server\0") + server = .(0, .{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)}, .(null, null, null, null, null, null, null, null, null, null)) + log.info("server: started server\0") } -// ! this function will be rewritten to several functions that allow the server mainloop to handle these itself -handle_connections := fn(): bool { - recv := receive_message(MessageHeader, server.id) - if recv == null { +incoming := fn(): bool { + msg := recv_header(server.channel.server) + if msg == null { return true } - if recv.kind == message.syn { - buffer_id := buffer.create_without_name() - - send_message(MessageHeader, .(message.ack, buffer_id), server.id) - log.debug("server: sent ack\0") - - resp := await_message(WindowProps, buffer_id) - log.debug("server: received props\0") - - data := WindowData.(resp, buffer_id) - send_message(WindowData, data, buffer_id) - log.debug("server: sent window data\0"); - *(server.windows + server.window_count) = data - server.window_count += 1 - } else if recv.kind == message.shutdown { - log.warn("server: shutdown handled without validation\n\r this is temporary behaviour\0") - return false + if msg.kind == message.syn { + log.info("server: recv syn\0") + channel := Channel.(buffer.create_nameless(), buffer.create_nameless()) + send_message(Channel, message.ack, channel, channel.client) + props := await_message(WindowProps, channel.server) + if props.header.kind != message.props { + return true + } + log.info("server: recv props\0") + // ! do inspection of requested props here + send_message(WindowData, message.ack, .(props.body, channel, permissions.default), channel.client) } return true +} + +render_clients := fn(screen: Surface): void { + i := 0 + loop if i == 10 break else { + window := server.windows[i] + if window == null { + continue + } + header := recv_header(window.channel.server) + if header == null | @unwrap(header).kind != message.frame_ready { + continue + } + send_header(message.ack, window.channel.client) + ptr := await_message(^Color, window.channel.server) + if ptr.header.kind != message.ack { + continue + } + put_surface(screen, .(ptr.body, window.props.dimensions.x, window.props.dimensions.y, window.props.dimensions.x * window.props.dimensions.y), window.props.position, false) + i += 1 + } + sync(screen) } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 9369afd..77cb04c 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1 +1 @@ -.{example: main} := @use("./examples/colors.hb") \ No newline at end of file +.{example: main} := @use("./examples/text.hb") \ No newline at end of file diff --git a/sysdata/programs/sunset_client/src/main.hb b/sysdata/programs/sunset_client/src/main.hb index 1dfc989..eec5c12 100644 --- a/sysdata/programs/sunset_client/src/main.hb +++ b/sysdata/programs/sunset_client/src/main.hb @@ -4,17 +4,14 @@ render := @use("../../../libraries/render/src/lib.hb") main := fn(): void { sunset.client.find_server() - client := sunset.client.new(.(.(100, 100), .(100, 100), "Hello, World!\0")) - if client == null { - log.error("we did not get a window\0") + + window := sunset.client.new(.(.(100, 100), .(100, 100), "Hello, World!\0")) + if window == null { + log.error("got no window\0") return } - if sunset.client.update_props(client) == false { - log.error("we did not update props\0") + render.put_filled_circle(window.surface, .(50, 50), 25, render.white) + if sunset.client.send_frame(window) == false { + log.error("did not send frame\0") } - - render.put_filled_circle(client.surface, .(50, 50), 20, render.white) - sunset.client.frame_ready(client) - sunset.client.quit(client) - sunset.client.shutdown_server() } \ No newline at end of file diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index 79dc01e..f11694e 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -1,7 +1,10 @@ sunset := @use("../../../libraries/sunset_proto/src/lib.hb") +render := @use("../../../libraries/render/src/lib.hb") main := fn(): void { + screen := render.init(true) sunset.server.start() - loop if sunset.server.handle_connections() { + loop if sunset.server.incoming() { + sunset.server.render_clients(screen) } } \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index ab597c0..da9cbd0 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -22,8 +22,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.horizon] # path = "boot:///horizon.hbf" @@ -34,8 +34,8 @@ path = "boot:///render_example.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" -# [boot.limine.ableos.modules.sunset_client] -# path = "boot:///sunset_client.hbf" +[boot.limine.ableos.modules.sunset_client] +path = "boot:///sunset_client.hbf" -# [boot.limine.ableos.modules.sunset_server] -# path = "boot:///sunset_server.hbf" +[boot.limine.ableos.modules.sunset_server] +path = "boot:///sunset_server.hbf" From 56ee0fe85188458e4f7c29f4417c7c4900ca1297 Mon Sep 17 00:00:00 2001 From: Able Date: Wed, 13 Nov 2024 14:16:32 -0600 Subject: [PATCH 07/14] misc --- Cargo.lock | 6 +++--- kernel/src/arch/x86_64/interrupts.rs | 10 ++++++++++ sysdata/programs/horizon/src/main.hb | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc4f684..2a1a426 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#d01e31b2034e53098f92dfb07b183a21857ded1e" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f524013c34ff5868eadc0afdf1168239f31c7ee0" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f524013c34ff5868eadc0afdf1168239f31c7ee0" 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#d01e31b2034e53098f92dfb07b183a21857ded1e" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f524013c34ff5868eadc0afdf1168239f31c7ee0" dependencies = [ "hbbytecode", ] diff --git a/kernel/src/arch/x86_64/interrupts.rs b/kernel/src/arch/x86_64/interrupts.rs index 02b8e2c..25c2931 100644 --- a/kernel/src/arch/x86_64/interrupts.rs +++ b/kernel/src/arch/x86_64/interrupts.rs @@ -11,6 +11,7 @@ static mut LAPIC: LocalApic = unsafe { MaybeUninit::zeroed().assume_init() }; static mut IDT: InterruptDescriptorTable = unsafe { MaybeUninit::zeroed().assume_init() }; #[repr(u8)] +#[derive(Debug)] enum Interrupt { Timer = 32, ApicErr = u8::MAX - 1, @@ -66,11 +67,20 @@ extern "x86-interrupt" fn timer(_isf: InterruptStackFrame) { } extern "x86-interrupt" fn apic_err(_: InterruptStackFrame) { + interrupt(Interrupt::ApicErr); + panic!("Internal APIC error"); } extern "x86-interrupt" fn spurious(_: InterruptStackFrame) { + interrupt(Interrupt::Spurious); + unsafe { LAPIC.end_of_interrupt(); } } + +fn interrupt(interrupt_type: Interrupt){ + log::info!("Interrupt type {:?}", interrupt_type); + panic!() +} \ No newline at end of file diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index 114c492..7ccd0bd 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -73,7 +73,12 @@ main := fn(): int { } { - // Bottom Bar + // osu dots + render.put_rect(screen, .(400, 100), .(100, 100), render.red) + render.put_rect(screen, .(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) From b6261d014d64642c5c5cac2cb7436da0670c0acf Mon Sep 17 00:00:00 2001 From: koniifer Date: Wed, 13 Nov 2024 23:08:20 +0000 Subject: [PATCH 08/14] bad frame synchronisation implementation --- Cargo.lock | 6 +- sysdata/libraries/sunset_proto/src/client.hb | 12 ++-- sysdata/libraries/sunset_proto/src/lib.hb | 14 ++--- sysdata/libraries/sunset_proto/src/server.hb | 59 ++++++++++++-------- sysdata/programs/sunset_client/src/main.hb | 16 ++++-- 5 files changed, 62 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a1a426..bc4f684 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#f524013c34ff5868eadc0afdf1168239f31c7ee0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#f524013c34ff5868eadc0afdf1168239f31c7ee0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" 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#f524013c34ff5868eadc0afdf1168239f31c7ee0" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" dependencies = [ "hbbytecode", ] diff --git a/sysdata/libraries/sunset_proto/src/client.hb b/sysdata/libraries/sunset_proto/src/client.hb index 9346e6c..d47f5a8 100644 --- a/sysdata/libraries/sunset_proto/src/client.hb +++ b/sysdata/libraries/sunset_proto/src/client.hb @@ -1,13 +1,15 @@ .{math: .{Vec2}, buffer, log, memory, string} := @use("../../stn/src/lib.hb"); -.{Channel, Window, send_header, send_message, await_channel, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb"); +.{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb"); .{new_surface, Color} := @use("../../render/src/lib.hb") // ! in the future this should be safely handled -channel := @as(Channel, idk) +channel := Channel.(0, 0) find_server := fn(): void { log.info("client: locating server\0") - channel = await_channel() + channel2 := await_channel(channel) + channel.server = channel2.server + channel.client = channel2.client log.info("client: server located\0") } @@ -15,7 +17,6 @@ new := fn(props: WindowProps): ?Window { send_header(message.syn, channel.server) response := await_message(Channel, channel.client) if response.header.kind != message.ack { - log.info(string.display_int(@bitcast(response.header.kind), "\0\0\0\0\0\0\0\0\0\0\0\0\0", 10)) return null } log.info("client: recv ack\0") @@ -57,9 +58,8 @@ send_frame := fn(client: Window): bool { if response.header.kind != message.ack { return false } - log.info("client: recv ack\0") // ! FOR NOW, server will ALWAYS be local, // ! so we can send pointer to surface. send_message(^Color, message.ack, client.surface.buf, server_id) - return true + return await_header(client_id).kind == message.ack } \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index 498447f..630d960 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -46,16 +46,14 @@ $recv_header := fn(buffer_id: uint): ?MessageHeader { return response } -await_channel := fn(): Channel { - server_id := 0 - loop if server_id == 0 { - server_id = buffer.search(BUFFER_SERVER) +await_channel := fn(channel: Channel): Channel { + loop if channel.server != 0 break else { + channel.server = buffer.search(BUFFER_SERVER) } - client_id := 0 - loop if client_id == 0 { - client_id = buffer.search(BUFFER_CLIENT) + loop if channel.client != 0 break else { + channel.client = buffer.search(BUFFER_CLIENT) } - return .{client: client_id, server: server_id} + return channel } await_message := fn($Expr: type, buffer_id: uint): Message(Expr) { diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index f44bb44..23e250b 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -1,19 +1,27 @@ .{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb"); -.{Color, Surface, new_surface, put_surface, sync} := @use("../../render/src/lib.hb"); +.{Color, Surface, new_surface, put_surface, sync, put_rect, put_filled_rect, text, put_text} := @use("../../render/src/lib.hb"); .{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("./lib.hb") WindowServer := struct { window_count: uint, channel: Channel, - // ! replace this with an actual collection when we get an allocator + // ! replace this with a collection when we get an allocator windows: [?WindowData; 10], + font: text.Font, } // ! in the future this should be safely handled server := @as(WindowServer, idk) +psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf") + start := fn(): void { - server = .(0, .{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)}, .(null, null, null, null, null, null, null, null, null, null)) + font := text.font_from_psf2(@bitcast(&psf), false) + if font == null { + log.error("server: failed to load asset\0") + return + } + server = .(0, .{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)}, .(null, null, null, null, null, null, null, null, null, null), @as(text.Font, font)) log.info("server: started server\0") } @@ -25,36 +33,43 @@ incoming := fn(): bool { if msg.kind == message.syn { log.info("server: recv syn\0") channel := Channel.(buffer.create_nameless(), buffer.create_nameless()) - send_message(Channel, message.ack, channel, channel.client) + 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") // ! do inspection of requested props here - send_message(WindowData, message.ack, .(props.body, channel, permissions.default), channel.client) + data := WindowData.(props.body, channel, permissions.default) + send_message(WindowData, message.ack, data, channel.client) + server.windows[server.window_count] = data + server.window_count += 1 } return true } render_clients := fn(screen: Surface): void { - i := 0 - loop if i == 10 break else { - window := server.windows[i] - if window == null { - continue - } - header := recv_header(window.channel.server) - if header == null | @unwrap(header).kind != message.frame_ready { - continue - } - send_header(message.ack, window.channel.client) - ptr := await_message(^Color, window.channel.server) - if ptr.header.kind != message.ack { - continue - } - put_surface(screen, .(ptr.body, window.props.dimensions.x, window.props.dimensions.y, window.props.dimensions.x * window.props.dimensions.y), window.props.position, false) - i += 1 + // support one window for test case + window := server.windows[0] + if window == null { + return } + header := recv_header(window.channel.server) + if header == null { + return + } + if header.kind != message.frame_ready { + return + } + send_header(message.ack, window.channel.client) + ptr := await_message(^Color, window.channel.server) + if ptr.header.kind != message.ack { + return + } + put_surface(screen, .(ptr.body, window.props.dimensions.x, window.props.dimensions.y, window.props.dimensions.x * window.props.dimensions.y), window.props.position, false) + put_rect(screen, window.props.position - .(1, 1), window.props.dimensions + .(1, 1), .(255, 255, 255, 255)) + put_filled_rect(screen, window.props.position - .(1, 21), .(window.props.dimensions.x + 2, 20), .(255, 255, 255, 255)) + put_text(screen, server.font, window.props.position - .(-2, 20), .(0, 0, 0, 255), window.props.title) sync(screen) + send_header(message.ack, window.channel.client) } \ No newline at end of file diff --git a/sysdata/programs/sunset_client/src/main.hb b/sysdata/programs/sunset_client/src/main.hb index eec5c12..8b46a12 100644 --- a/sysdata/programs/sunset_client/src/main.hb +++ b/sysdata/programs/sunset_client/src/main.hb @@ -1,17 +1,21 @@ -.{log, string} := @use("../../../libraries/stn/src/lib.hb") +.{log} := @use("../../../libraries/stn/src/lib.hb") sunset := @use("../../../libraries/sunset_proto/src/lib.hb") render := @use("../../../libraries/render/src/lib.hb") main := fn(): void { sunset.client.find_server() - - window := sunset.client.new(.(.(100, 100), .(100, 100), "Hello, World!\0")) + window := sunset.client.new(.(.(100, 100), .(700, 100), "Hello, World!\0")) if window == null { log.error("got no window\0") return } - render.put_filled_circle(window.surface, .(50, 50), 25, render.white) - if sunset.client.send_frame(window) == false { - log.error("did not send frame\0") + x := 0 + loop { + render.clear(window.surface, render.cyan) + render.put_filled_circle(window.surface, .(50 + x % window.data.props.dimensions.x, 50), 25, render.magenta) + if sunset.client.send_frame(window) == false { + log.error("did not send frame\0") + } + x += 1 } } \ No newline at end of file From 95b4a921dc4e5890bf18cbf7a24c2ac7b5905ee8 Mon Sep 17 00:00:00 2001 From: koniifer Date: Thu, 14 Nov 2024 16:43:23 +0000 Subject: [PATCH 09/14] improve & optimise window decoration code --- Cargo.lock | 4 +- sysdata/libraries/sunset_proto/src/lib.hb | 12 ----- sysdata/libraries/sunset_proto/src/server.hb | 51 +++++++++++++------- sysdata/programs/sunset_client/src/main.hb | 13 ++++- sysdata/programs/sunset_server/src/main.hb | 1 + 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc4f684..5dc6c13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,9 +82,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aeb932158bd710538c73702db6945cb68a8fb08c519e6e12706b94263b36db8" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "shlex", ] diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index 630d960..f5df7b6 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -14,18 +14,6 @@ server := @use("./server.hb") message := @use("./message.hb") permissions := @use("./permissions.hb") -opaque := fn(i: uint): bool { - if i == 0 { - return true - } - return false -} - -sleep := fn(): void { - i := 10000000 - loop if opaque(i) break else i -= 1 -} - $send_message := fn($Expr: type, kind: uint, msg: Expr, buffer_id: uint): void { buffer.write(?Message(Expr), buffer_id, &@as(?Message(Expr), .(.(kind), msg))) } diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index 23e250b..6737a40 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -6,7 +6,7 @@ WindowServer := struct { window_count: uint, channel: Channel, // ! replace this with a collection when we get an allocator - windows: [?WindowData; 10], + windows: [?Window; 10], font: text.Font, } @@ -42,34 +42,51 @@ incoming := fn(): bool { // ! do inspection of requested props here data := WindowData.(props.body, channel, permissions.default) send_message(WindowData, message.ack, data, channel.client) - server.windows[server.window_count] = data + surface := new_window_decorations(data.props.dimensions) + put_filled_rect(surface, .(0, 0), data.props.dimensions + .(DECO_WIDTH, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM), DECO_COLOUR) + put_filled_rect(surface, .(0, 0), .(data.props.dimensions.x + DECO_WIDTH, DECO_HEIGHT_TOP), DECO_COLOUR) + put_text(surface, server.font, .(2, 1), .(0, 0, 0, 255), data.props.title) + server.windows[server.window_count] = .(data, surface) server.window_count += 1 } return true } -render_clients := fn(screen: Surface): void { - // support one window for test case +$DECO_WIDTH := 2 +$DECO_HEIGHT_TOP := 20 +$DECO_HEIGHT_BOTTOM := 1 +$DECO_COLOUR := Color.(100, 200, 255, 255) + +new_window_decorations := fn(dimensions: math.Vec2(uint)): Surface { + return new_surface(dimensions.x + DECO_WIDTH, dimensions.y + DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM) +} + +// ! compositor code. this currently disallows tearing. + +collect_frames := fn(): void { window := server.windows[0] if window == null { return } - header := recv_header(window.channel.server) - if header == null { + header := recv_header(window.data.channel.server) + if header == null | @unwrap(header).kind != message.frame_ready { return } - if header.kind != message.frame_ready { + send_header(message.ack, window.data.channel.client) + ptr := await_message(^Color, window.data.channel.server) + // ! weird compiler error + // if ptr.header.kind != message.ack { + // return + // } + put_surface(window.surface, Surface.(ptr.body, window.data.props.dimensions.x, window.data.props.dimensions.y, window.data.props.dimensions.x * window.data.props.dimensions.y), .(DECO_WIDTH / 2, DECO_HEIGHT_TOP), false) + send_header(message.ack, window.data.channel.client) +} + +render_clients := fn(screen: Surface): void { + window := server.windows[0] + if window == null { return } - send_header(message.ack, window.channel.client) - ptr := await_message(^Color, window.channel.server) - if ptr.header.kind != message.ack { - return - } - put_surface(screen, .(ptr.body, window.props.dimensions.x, window.props.dimensions.y, window.props.dimensions.x * window.props.dimensions.y), window.props.position, false) - put_rect(screen, window.props.position - .(1, 1), window.props.dimensions + .(1, 1), .(255, 255, 255, 255)) - put_filled_rect(screen, window.props.position - .(1, 21), .(window.props.dimensions.x + 2, 20), .(255, 255, 255, 255)) - put_text(screen, server.font, window.props.position - .(-2, 20), .(0, 0, 0, 255), window.props.title) + put_surface(screen, window.surface, window.data.props.position, false) sync(screen) - send_header(message.ack, window.channel.client) } \ No newline at end of file diff --git a/sysdata/programs/sunset_client/src/main.hb b/sysdata/programs/sunset_client/src/main.hb index 8b46a12..a4cb5f6 100644 --- a/sysdata/programs/sunset_client/src/main.hb +++ b/sysdata/programs/sunset_client/src/main.hb @@ -2,9 +2,18 @@ sunset := @use("../../../libraries/sunset_proto/src/lib.hb") render := @use("../../../libraries/render/src/lib.hb") +bmp := @embed("../../../assets/mini.bmp") + main := fn(): void { sunset.client.find_server() - window := sunset.client.new(.(.(100, 100), .(700, 100), "Hello, World!\0")) + + image := render.image.from(@bitcast(&bmp)) + if image == null { + log.error("got no image\0") + return + } + + window := sunset.client.new(.(.(100, 100), .(480, 200), "sunset windowing demo paddingpaddingpadding\0")) if window == null { log.error("got no window\0") return @@ -12,7 +21,7 @@ main := fn(): void { x := 0 loop { render.clear(window.surface, render.cyan) - render.put_filled_circle(window.surface, .(50 + x % window.data.props.dimensions.x, 50), 25, render.magenta) + render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 20), false) if sunset.client.send_frame(window) == false { log.error("did not send frame\0") } diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index f11694e..96f749e 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -5,6 +5,7 @@ main := fn(): void { screen := render.init(true) sunset.server.start() loop if sunset.server.incoming() { + sunset.server.collect_frames() sunset.server.render_clients(screen) } } \ No newline at end of file From 907c0d0dd44cfe72846533a11a88ef3623afdc59 Mon Sep 17 00:00:00 2001 From: koniifer Date: Thu, 14 Nov 2024 21:28:21 +0000 Subject: [PATCH 10/14] multi-client support and demo --- Cargo.lock | 6 +- repbuild/src/dev.rs | 23 +++++- sysdata/libraries/sunset_proto/src/client.hb | 12 ++- sysdata/libraries/sunset_proto/src/lib.hb | 11 ++- sysdata/libraries/sunset_proto/src/server.hb | 82 ++++++++++++++------ sysdata/programs/sunset_client/src/main.hb | 11 ++- sysdata/programs/sunset_client_2/meta.toml | 11 +++ sysdata/programs/sunset_client_2/src/main.hb | 29 +++++++ sysdata/system_config.toml | 3 + 9 files changed, 140 insertions(+), 48 deletions(-) create mode 100644 sysdata/programs/sunset_client_2/meta.toml create mode 100644 sysdata/programs/sunset_client_2/src/main.hb diff --git a/Cargo.lock b/Cargo.lock index 5dc6c13..ddd7fea 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#d01e31b2034e53098f92dfb07b183a21857ded1e" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#81cf39b602a64242f2bfb22b0d18ef113e578dd8" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#d01e31b2034e53098f92dfb07b183a21857ded1e" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#81cf39b602a64242f2bfb22b0d18ef113e578dd8" 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#d01e31b2034e53098f92dfb07b183a21857ded1e" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#81cf39b602a64242f2bfb22b0d18ef113e578dd8" dependencies = [ "hbbytecode", ] diff --git a/repbuild/src/dev.rs b/repbuild/src/dev.rs index 91c4644..ab300ef 100644 --- a/repbuild/src/dev.rs +++ b/repbuild/src/dev.rs @@ -1,5 +1,6 @@ #![allow(unused)] use std::{ + collections::HashMap, fmt::format, fs::{read_to_string, File}, io::{BufWriter, Write}, @@ -13,6 +14,7 @@ pub struct Package { name: String, binaries: Vec, build_cmd: String, + args: HashMap, } impl Package { @@ -46,26 +48,36 @@ impl Package { let mut binaries = vec![]; for (count, (name, table)) in bin_table.into_iter().enumerate() { - // if count != 0 { binaries.push(name.clone()); - // } } let build_table = data.get("build").unwrap(); let mut build_cmd: String = build_table.get("command").unwrap().as_str().unwrap().into(); build_cmd.remove(0); - // build_cmd.pop(); + let mut args: HashMap = match build_table.get("args") { + None => HashMap::new(), + Some(v) => v + .as_table() + .unwrap() + .into_iter() + .map(|(k, v)| (k.clone(), v.to_string())) + .collect::>(), + }; Self { name, binaries, build_cmd, + args, } } pub fn build(&self, out: &mut Vec) -> std::io::Result<()> { if self.binaries.contains(&"hblang".to_string()) { let file = self.build_cmd.split_ascii_whitespace().last().unwrap(); - + let in_house_regalloc = self + .args + .get("use_new_regalloc") + .map_or(false, |str| str.parse().expect("must be a boolean")); let path = format!("sysdata/programs/{}/{}", self.name, file); // compile here @@ -73,6 +85,7 @@ impl Package { &path, Options { fmt: true, + in_house_regalloc, ..Default::default() }, out, @@ -87,6 +100,7 @@ impl Package { hblang::run_compiler( &path, Options { + in_house_regalloc, ..Default::default() }, out, @@ -98,6 +112,7 @@ impl Package { &path, Options { dump_asm: true, + in_house_regalloc, ..Default::default() }, out, diff --git a/sysdata/libraries/sunset_proto/src/client.hb b/sysdata/libraries/sunset_proto/src/client.hb index d47f5a8..01d5762 100644 --- a/sysdata/libraries/sunset_proto/src/client.hb +++ b/sysdata/libraries/sunset_proto/src/client.hb @@ -7,7 +7,7 @@ channel := Channel.(0, 0) find_server := fn(): void { log.info("client: locating server\0") - channel2 := await_channel(channel) + channel2 := await_channel() channel.server = channel2.server channel.client = channel2.client log.info("client: server located\0") @@ -51,15 +51,13 @@ update_permissions := fn(client: Window): bool { } send_frame := fn(client: Window): bool { - server_id := client.data.channel.server - client_id := client.data.channel.client - send_header(message.frame_ready, server_id) - response := await_message(uint, client_id) + send_header(message.frame_ready, client.data.channel.server) + response := await_message(uint, client.data.channel.client) if response.header.kind != message.ack { return false } // ! FOR NOW, server will ALWAYS be local, // ! so we can send pointer to surface. - send_message(^Color, message.ack, client.surface.buf, server_id) - return await_header(client_id).kind == message.ack + send_message(^Color, message.ack, client.surface.buf, client.data.channel.server) + return true } \ No newline at end of file diff --git a/sysdata/libraries/sunset_proto/src/lib.hb b/sysdata/libraries/sunset_proto/src/lib.hb index f5df7b6..f75dfb2 100644 --- a/sysdata/libraries/sunset_proto/src/lib.hb +++ b/sysdata/libraries/sunset_proto/src/lib.hb @@ -14,11 +14,11 @@ server := @use("./server.hb") message := @use("./message.hb") permissions := @use("./permissions.hb") -$send_message := fn($Expr: type, kind: uint, msg: Expr, buffer_id: uint): void { +$send_message := fn($Expr: type, kind: MessageKind, msg: Expr, buffer_id: uint): void { buffer.write(?Message(Expr), buffer_id, &@as(?Message(Expr), .(.(kind), msg))) } -$send_header := fn(kind: uint, buffer_id: uint): void { +$send_header := fn(kind: MessageKind, buffer_id: uint): void { buffer.write(?MessageHeader, buffer_id, &@as(?MessageHeader, .(kind))) } @@ -34,7 +34,8 @@ $recv_header := fn(buffer_id: uint): ?MessageHeader { return response } -await_channel := fn(channel: Channel): Channel { +await_channel := fn(): Channel { + channel := Channel.(0, 0) loop if channel.server != 0 break else { channel.server = buffer.search(BUFFER_SERVER) } @@ -64,8 +65,10 @@ await_header := fn(buffer_id: uint): MessageHeader { } } +MessageKind := u8 + MessageHeader := packed struct { - kind: uint, + kind: MessageKind, } Message := fn($Expr: type): type { diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index 6737a40..0b0319a 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -21,7 +21,12 @@ start := fn(): void { log.error("server: failed to load asset\0") return } - server = .(0, .{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)}, .(null, null, null, null, null, null, null, null, null, null), @as(text.Font, font)) + server = .( + 0, + .{client: buffer.create(BUFFER_CLIENT), server: buffer.create(BUFFER_SERVER)}, + .(null, null, null, null, null, null, null, null, null, null), + @as(text.Font, font), + ) log.info("server: started server\0") } @@ -43,9 +48,12 @@ incoming := fn(): bool { data := WindowData.(props.body, channel, permissions.default) send_message(WindowData, message.ack, data, channel.client) surface := new_window_decorations(data.props.dimensions) - put_filled_rect(surface, .(0, 0), data.props.dimensions + .(DECO_WIDTH, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM), DECO_COLOUR) - put_filled_rect(surface, .(0, 0), .(data.props.dimensions.x + DECO_WIDTH, DECO_HEIGHT_TOP), DECO_COLOUR) - put_text(surface, server.font, .(2, 1), .(0, 0, 0, 255), data.props.title) + // decorations + { + put_filled_rect(surface, .(0, 0), data.props.dimensions + .(DECO_WIDTH, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM), DECO_COLOUR) + put_filled_rect(surface, .(0, 0), .(data.props.dimensions.x + DECO_WIDTH, DECO_HEIGHT_TOP), DECO_COLOUR) + put_text(surface, server.font, .(2, 1), .(0, 0, 0, 255), data.props.title) + } server.windows[server.window_count] = .(data, surface) server.window_count += 1 } @@ -58,35 +66,61 @@ $DECO_HEIGHT_BOTTOM := 1 $DECO_COLOUR := Color.(100, 200, 255, 255) new_window_decorations := fn(dimensions: math.Vec2(uint)): Surface { - return new_surface(dimensions.x + DECO_WIDTH, dimensions.y + DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM) + return new_surface( + dimensions.x + DECO_WIDTH, + dimensions.y + DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM, + ) } // ! compositor code. this currently disallows tearing. collect_frames := fn(): void { - window := server.windows[0] - if window == null { - return + i := 0 + loop if i == 10 break else { + window := server.windows[i] + if window == null { + i += 1 + continue + } + header := recv_header(window.data.channel.server) + if header == null { + i += 1 + continue + } + if header.kind != message.frame_ready { + i += 1 + continue + } + send_header(message.ack, window.data.channel.client) + ptr := await_message(^Color, window.data.channel.server) + if ptr.header.kind != message.ack { + return + } + put_surface( + window.surface, + Surface.( + ptr.body, + window.data.props.dimensions.x, + window.data.props.dimensions.y, + window.data.props.dimensions.x * window.data.props.dimensions.y, + ), + .(DECO_WIDTH / 2, DECO_HEIGHT_TOP), + false, + ) + i += 1 } - header := recv_header(window.data.channel.server) - if header == null | @unwrap(header).kind != message.frame_ready { - return - } - send_header(message.ack, window.data.channel.client) - ptr := await_message(^Color, window.data.channel.server) - // ! weird compiler error - // if ptr.header.kind != message.ack { - // return - // } - put_surface(window.surface, Surface.(ptr.body, window.data.props.dimensions.x, window.data.props.dimensions.y, window.data.props.dimensions.x * window.data.props.dimensions.y), .(DECO_WIDTH / 2, DECO_HEIGHT_TOP), false) - send_header(message.ack, window.data.channel.client) } render_clients := fn(screen: Surface): void { - window := server.windows[0] - if window == null { - return + i := 0 + loop if i == 10 break else { + window := server.windows[i] + if window == null { + i += 1 + continue + } + put_surface(screen, window.surface, window.data.props.position, false) + i += 1 } - put_surface(screen, window.surface, window.data.props.position, false) sync(screen) } \ No newline at end of file diff --git a/sysdata/programs/sunset_client/src/main.hb b/sysdata/programs/sunset_client/src/main.hb index a4cb5f6..a52ee3f 100644 --- a/sysdata/programs/sunset_client/src/main.hb +++ b/sysdata/programs/sunset_client/src/main.hb @@ -7,24 +7,23 @@ bmp := @embed("../../../assets/mini.bmp") main := fn(): void { sunset.client.find_server() - image := render.image.from(@bitcast(&bmp)) + image := render.image.bmp.from(@bitcast(&bmp)) if image == null { log.error("got no image\0") return } - window := sunset.client.new(.(.(100, 100), .(480, 200), "sunset windowing demo paddingpaddingpadding\0")) + window := sunset.client.new(.(.(100, 100), .(200, 200), "Hello,\0")) + if window == null { log.error("got no window\0") return } x := 0 loop { - render.clear(window.surface, render.cyan) + render.clear(window.surface, render.black) render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 20), false) - if sunset.client.send_frame(window) == false { - log.error("did not send frame\0") - } + _ = sunset.client.send_frame(window) x += 1 } } \ No newline at end of file diff --git a/sysdata/programs/sunset_client_2/meta.toml b/sysdata/programs/sunset_client_2/meta.toml new file mode 100644 index 0000000..399214f --- /dev/null +++ b/sysdata/programs/sunset_client_2/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "sunset_client_2" +authors = ["koniifer"] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/sunset_client_2/src/main.hb b/sysdata/programs/sunset_client_2/src/main.hb new file mode 100644 index 0000000..3fcf1c1 --- /dev/null +++ b/sysdata/programs/sunset_client_2/src/main.hb @@ -0,0 +1,29 @@ +.{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, 300), .(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 + } +} \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index da9cbd0..b4fe670 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -37,5 +37,8 @@ resolution = "1024x768x24" [boot.limine.ableos.modules.sunset_client] path = "boot:///sunset_client.hbf" +[boot.limine.ableos.modules.sunset_client_2] +path = "boot:///sunset_client_2.hbf" + [boot.limine.ableos.modules.sunset_server] path = "boot:///sunset_server.hbf" From d5f4ce18a3a0468284bcbf64f885da6fc676416e Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 14 Nov 2024 18:09:54 -0600 Subject: [PATCH 11/14] push changes --- sysdata/libraries/sunset_proto/src/server.hb | 17 ++++-- sysdata/programs/sunset_server/src/main.hb | 64 +++++++++++++++++++- sysdata/system_config.toml | 4 +- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/sysdata/libraries/sunset_proto/src/server.hb b/sysdata/libraries/sunset_proto/src/server.hb index 0b0319a..4850ce6 100644 --- a/sysdata/libraries/sunset_proto/src/server.hb +++ b/sysdata/libraries/sunset_proto/src/server.hb @@ -1,5 +1,5 @@ .{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb"); -.{Color, Surface, new_surface, put_surface, sync, put_rect, put_filled_rect, text, put_text} := @use("../../render/src/lib.hb"); +.{Color, Surface, new_surface, put_surface, sync, put_rect, put_filled_rect, text, put_text, clear, white, black} := @use("../../render/src/lib.hb"); .{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("./lib.hb") WindowServer := struct { @@ -50,8 +50,17 @@ incoming := fn(): bool { surface := new_window_decorations(data.props.dimensions) // decorations { - put_filled_rect(surface, .(0, 0), data.props.dimensions + .(DECO_WIDTH, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM), DECO_COLOUR) - put_filled_rect(surface, .(0, 0), .(data.props.dimensions.x + DECO_WIDTH, DECO_HEIGHT_TOP), DECO_COLOUR) + title := data.props.title + title_length := string.length(title) + deco_length := title_length * 10 + // draw the window tab bar + put_filled_rect(surface, .(0, 0), .(data.props.dimensions.x + DECO_WIDTH + deco_length, DECO_HEIGHT_TOP), DECO_COLOUR) + // Draw the window tab + put_filled_rect(surface, .(0, 0), .(deco_length, DECO_HEIGHT_TOP - 1), DECO_COLOUR_DARKER) + + // Draw the outside box + put_rect(surface, .(0, 0), data.props.dimensions + .(DECO_WIDTH - 1, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM - 1), DECO_COLOUR) + put_text(surface, server.font, .(2, 1), .(0, 0, 0, 255), data.props.title) } server.windows[server.window_count] = .(data, surface) @@ -64,6 +73,7 @@ $DECO_WIDTH := 2 $DECO_HEIGHT_TOP := 20 $DECO_HEIGHT_BOTTOM := 1 $DECO_COLOUR := Color.(100, 200, 255, 255) +$DECO_COLOUR_DARKER := Color.(89, 57, 89, 255) new_window_decorations := fn(dimensions: math.Vec2(uint)): Surface { return new_surface( @@ -122,5 +132,4 @@ render_clients := fn(screen: Surface): void { put_surface(screen, window.surface, window.data.props.position, false) i += 1 } - sync(screen) } \ No newline at end of file diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index 96f749e..b0ad252 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -1,11 +1,69 @@ sunset := @use("../../../libraries/sunset_proto/src/lib.hb") render := @use("../../../libraries/render/src/lib.hb") +intouch := @use("../../../libraries/intouch/src/lib.hb") main := fn(): void { screen := render.init(true) sunset.server.start() - loop if sunset.server.incoming() { - sunset.server.collect_frames() - sunset.server.render_clients(screen) + render.clear(screen, render.black) + + mouse_x := 0 + mouse_y := 0 + + 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 + + if mouse_y < 0 { + mouse_y = 0 + } + if mouse_y >= screen.height - 20 { + mouse_y = @intcast(screen.height - 21) + } + mouse_y -= change_y + + if mouse_event.left { + // set_label_text(text_label, "LEFT CLICK\0") + } + if mouse_event.middle { + // set_label_text(text_label, "MIDDLE CLICK\0") + } + if mouse_event.right { + // set_label_text(text_label, "RIGHT CLICK\0") + } + } + { + // render.clear(screen, render.black) + } + + if sunset.server.incoming() { + // render.clear(screen, render.black) + // + sunset.server.collect_frames() + sunset.server.render_clients(screen) + } + + // Mouse cursor + { + 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) + } + + render.sync(screen) } } \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index b4fe670..5a32b3e 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,8 +28,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.horizon] # path = "boot:///horizon.hbf" -# [boot.limine.ableos.modules.ps2_mouse_driver] -# path = "boot:///ps2_mouse_driver.hbf" +[boot.limine.ableos.modules.ps2_mouse_driver] +path = "boot:///ps2_mouse_driver.hbf" # [boot.limine.ableos.modules.ps2_keyboard_driver] # path = "boot:///ps2_keyboard_driver.hbf" From b0f6aa53bd1befda24b01e191348d1f5195a5065 Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 14 Nov 2024 18:33:29 -0600 Subject: [PATCH 12/14] Mouse updates --- sysdata/programs/sunset_server/src/main.hb | 49 +++++++++++++++++----- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index b0ad252..5a64e66 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -2,13 +2,33 @@ sunset := @use("../../../libraries/sunset_proto/src/lib.hb") render := @use("../../../libraries/render/src/lib.hb") intouch := @use("../../../libraries/intouch/src/lib.hb") -main := fn(): void { - screen := render.init(true) +horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); +.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label + +stn := @use("../../../libraries/stn/src/lib.hb"); +.{Vec2} := stn.math + +psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf") +img := @embed("../../../assets/wallpaper.qoi") + +main := fn(): int { sunset.server.start() + + screen := render.init(true) render.clear(screen, render.black) - mouse_x := 0 - mouse_y := 0 + font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false)) + + wallpaper := render.image.from(@bitcast(&img)) + if wallpaper == null { + // stn.panic("Wallpaper not loaded\0") + return 1 + } + + mouse_x := 100 + mouse_y := 100 + + text_label := new_label("Hi\0") loop { mouse_event := intouch.recieve_mouse_event() @@ -38,26 +58,33 @@ main := fn(): void { mouse_y -= change_y if mouse_event.left { - // set_label_text(text_label, "LEFT CLICK\0") + set_label_text(text_label, "LEFT CLICK\0") } if mouse_event.middle { - // set_label_text(text_label, "MIDDLE CLICK\0") + set_label_text(text_label, "MIDDLE CLICK\0") } if mouse_event.right { - // set_label_text(text_label, "RIGHT CLICK\0") + set_label_text(text_label, "RIGHT CLICK\0") } } { - // render.clear(screen, render.black) + render.clear(screen, render.black) + render.put_surface(screen, wallpaper, .(0, 0), false) + + render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) } if sunset.server.incoming() { - // render.clear(screen, render.black) - // sunset.server.collect_frames() sunset.server.render_clients(screen) } + { + 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) + } + // Mouse cursor { render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.black) @@ -66,4 +93,6 @@ main := fn(): void { render.sync(screen) } + + return 0 } \ No newline at end of file From 614bef7ec59c8e1238629e493a61a24adaae3659 Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 14 Nov 2024 18:40:44 -0600 Subject: [PATCH 13/14] ok now there is colors --- sysdata/libraries/stn/src/sleep.hb | 6 ++++++ sysdata/programs/sunset_server/src/main.hb | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 sysdata/libraries/stn/src/sleep.hb diff --git a/sysdata/libraries/stn/src/sleep.hb b/sysdata/libraries/stn/src/sleep.hb new file mode 100644 index 0000000..d323267 --- /dev/null +++ b/sysdata/libraries/stn/src/sleep.hb @@ -0,0 +1,6 @@ +subscribe_to_interrupt := fn(interrupt_number: u8): bool { + return false +} +// Pauses execution until the interrupt occures +sleep_until_interrupt := fn(interrupt_number: u8): void { +} \ No newline at end of file diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index 5a64e66..bc28349 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -71,7 +71,7 @@ main := fn(): int { render.clear(screen, render.black) render.put_surface(screen, wallpaper, .(0, 0), false) - render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) + render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR) } if sunset.server.incoming() { @@ -82,13 +82,13 @@ main := fn(): int { { 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) + render.put_rect(screen, .(0, screen.height - 21), .(screen.width - 1, 20), sunset.server.DECO_COLOUR) } // Mouse cursor { - 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) + render.put_filled_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR_DARKER) + render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), sunset.server.DECO_COLOUR) } render.sync(screen) From cea7f1fa5c592c2405038f16c6ffc249c147c26c Mon Sep 17 00:00:00 2001 From: koniifer Date: Fri, 15 Nov 2024 19:46:36 +0000 Subject: [PATCH 14/14] use new register allocator by default --- Cargo.lock | 6 +++--- repbuild/src/dev.rs | 10 +++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ddd7fea..17a86d6 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#81cf39b602a64242f2bfb22b0d18ef113e578dd8" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#81cf39b602a64242f2bfb22b0d18ef113e578dd8" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" 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#81cf39b602a64242f2bfb22b0d18ef113e578dd8" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#7058efe75c7ad245db80986e77a97d426b9be8a4" dependencies = [ "hbbytecode", ] diff --git a/repbuild/src/dev.rs b/repbuild/src/dev.rs index ab300ef..c5d9723 100644 --- a/repbuild/src/dev.rs +++ b/repbuild/src/dev.rs @@ -74,10 +74,6 @@ impl Package { pub fn build(&self, out: &mut Vec) -> std::io::Result<()> { if self.binaries.contains(&"hblang".to_string()) { let file = self.build_cmd.split_ascii_whitespace().last().unwrap(); - let in_house_regalloc = self - .args - .get("use_new_regalloc") - .map_or(false, |str| str.parse().expect("must be a boolean")); let path = format!("sysdata/programs/{}/{}", self.name, file); // compile here @@ -85,7 +81,7 @@ impl Package { &path, Options { fmt: true, - in_house_regalloc, + in_house_regalloc: true, ..Default::default() }, out, @@ -100,7 +96,7 @@ impl Package { hblang::run_compiler( &path, Options { - in_house_regalloc, + in_house_regalloc: true, ..Default::default() }, out, @@ -112,7 +108,7 @@ impl Package { &path, Options { dump_asm: true, - in_house_regalloc, + in_house_regalloc: true, ..Default::default() }, out,