sunrising sunset
This commit is contained in:
parent
3409f5051a
commit
77a708d41e
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -228,12 +228,12 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbbytecode"
|
name = "hbbytecode"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hblang"
|
name = "hblang"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown 0.15.1",
|
"hashbrown 0.15.1",
|
||||||
"hbbytecode",
|
"hbbytecode",
|
||||||
|
@ -245,7 +245,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hbvm"
|
name = "hbvm"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248"
|
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c61efc393361089f5217db9f4a9011ed0248b8db"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hbbytecode",
|
"hbbytecode",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
string := @use("string.hb")
|
string := @use("string.hb")
|
||||||
|
|
||||||
recv := fn($Expr: type, buffer_id: int, memory_map_location: ^u8): void {
|
recv := fn($Expr: type, buffer_id: uint, memory_map_location: ^u8): void {
|
||||||
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
|
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
write := fn($Expr: type, msg: ^Expr, buffer_id: int): void {
|
write := fn($Expr: type, msg: ^Expr, buffer_id: uint): void {
|
||||||
return @eca(3, buffer_id, msg, @sizeof(Expr))
|
return @eca(3, buffer_id, msg, @sizeof(Expr))
|
||||||
}
|
}
|
||||||
|
|
||||||
recv_length := fn(buffer_id: int, memory_map_location: ^u8, length: int): void {
|
recv_length := fn(buffer_id: uint, memory_map_location: ^u8, length: uint): void {
|
||||||
return @eca(4, buffer_id, memory_map_location, length)
|
return @eca(4, buffer_id, memory_map_location, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
write_length := fn(msg: ^u8, buffer_id: int, length: int): void {
|
write_length := fn(msg: ^u8, buffer_id: uint, length: uint): void {
|
||||||
return @eca(3, buffer_id, msg, length)
|
return @eca(3, buffer_id, msg, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}
|
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}
|
||||||
|
|
||||||
create := fn(msg: ^u8): int {
|
create := fn(msg: ^u8): uint {
|
||||||
return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
||||||
}
|
}
|
||||||
|
|
||||||
search := fn(msg: ^u8): int {
|
search := fn(msg: ^u8): uint {
|
||||||
return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
||||||
}
|
}
|
|
@ -2,6 +2,17 @@ PAGE_SIZE := 4096
|
||||||
MAX_ALLOC := 0xFF
|
MAX_ALLOC := 0xFF
|
||||||
MAX_FREE := 0xFF
|
MAX_FREE := 0xFF
|
||||||
|
|
||||||
|
is_uninit := fn($Expr: type, ptr: ^Expr): bool {
|
||||||
|
i := 0
|
||||||
|
loop if *(@as(^u8, @bitcast(ptr)) + i) != 0 return false else if i + 1 == @sizeof(Expr) return true else i += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
uninit := fn($Expr: type): Expr {
|
||||||
|
empty := @as(Expr, idk)
|
||||||
|
@inline(set, u8, &0, @bitcast(&empty), @sizeof(Expr))
|
||||||
|
return empty
|
||||||
|
}
|
||||||
|
|
||||||
dangling := fn($Expr: type): ^Expr {
|
dangling := fn($Expr: type): ^Expr {
|
||||||
return @bitcast(@alignof(Expr))
|
return @bitcast(@alignof(Expr))
|
||||||
}
|
}
|
||||||
|
|
62
sysdata/libraries/sunset_proto/src/client.hb
Normal file
62
sysdata/libraries/sunset_proto/src/client.hb
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
.{math: .{Vec2}, buffer, log, memory} := @use("../../stn/src/lib.hb");
|
||||||
|
.{Surface, new_surface} := @use("../../render/src/lib.hb");
|
||||||
|
.{WindowWrapper, WindowID, WindowProps, WindowMessage, message, BUFFER} := @use("./lib.hb")
|
||||||
|
|
||||||
|
buffer_id := @as(?uint, null)
|
||||||
|
|
||||||
|
new_window := fn(props: WindowProps): ?WindowWrapper {
|
||||||
|
if buffer_id == null {
|
||||||
|
log.error("client: (request_new) buffer id is null. did you init the client?\0")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
buf := memory.uninit(?WindowWrapper)
|
||||||
|
buffer.write(WindowMessage, &.(message.new, 0, @sizeof(WindowProps), @bitcast(&props), @bitcast(&buf)), @unwrap(buffer_id))
|
||||||
|
loop if memory.is_uninit(?WindowWrapper, &buf) == false break else {
|
||||||
|
}
|
||||||
|
// loop until i write a better socket
|
||||||
|
i := 0
|
||||||
|
loop if i >= 1000 break else i += 1
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
update_window_props := fn(wrapper: WindowWrapper): ?WindowProps {
|
||||||
|
log.error("todo: sunset_proto/src/client/update_window_props.hb\0")
|
||||||
|
if buffer_id == null {
|
||||||
|
log.error("client: (request_update_properties) buffer id is null. did you init the client?\0")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
// TODO: buffer.write(WINDOWING_BUFFER, update properties) request
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
request_shutdown := fn(): ?bool {
|
||||||
|
if buffer_id == null {
|
||||||
|
log.error("client: (request_shutdown) buffer id is null. did you init the client?\0")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
buf := memory.uninit(?u8)
|
||||||
|
buffer.write(WindowMessage, &.(message.shutdown, 0, 0, memory.dangling(u8), @bitcast(&buf)), @unwrap(buffer_id))
|
||||||
|
loop if memory.is_uninit(?u8, &buf) == false break else {
|
||||||
|
}
|
||||||
|
// loop until i write a better socket
|
||||||
|
i := 0
|
||||||
|
loop if i >= 1000 break else i += 1
|
||||||
|
// had to do ?u8 here, ?bool didnt work
|
||||||
|
if buf == null | @unwrap(buf) != 255 {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init := fn(): void {
|
||||||
|
log.info("client: waiting for server\0")
|
||||||
|
id := 0
|
||||||
|
loop if id != 0 {
|
||||||
|
buffer_id = id
|
||||||
|
log.info("client: done waiting\0")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
id = buffer.search(BUFFER)
|
||||||
|
}
|
||||||
|
}
|
36
sysdata/libraries/sunset_proto/src/lib.hb
Normal file
36
sysdata/libraries/sunset_proto/src/lib.hb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
.{math: .{Vec2}} := @use("../../stn/src/lib.hb");
|
||||||
|
.{Surface} := @use("../../render/src/lib.hb")
|
||||||
|
|
||||||
|
$BUFFER := "sunset\0"
|
||||||
|
|
||||||
|
client := @use("./client.hb")
|
||||||
|
server := @use("./server.hb")
|
||||||
|
message := @use("./message.hb")
|
||||||
|
|
||||||
|
WindowID := uint
|
||||||
|
MessageKind := uint
|
||||||
|
|
||||||
|
WindowMessage := packed struct {
|
||||||
|
kind: MessageKind,
|
||||||
|
id: WindowID,
|
||||||
|
length: uint,
|
||||||
|
data_ptr: ^u8,
|
||||||
|
// need to replace this with a buffer id
|
||||||
|
callback: ^u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowProps := struct {
|
||||||
|
position: Vec2(uint),
|
||||||
|
dimensions: Vec2(uint),
|
||||||
|
title: ^u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowWrapper := struct {
|
||||||
|
id: WindowID,
|
||||||
|
props: WindowProps,
|
||||||
|
}
|
||||||
|
|
||||||
|
Window := struct {
|
||||||
|
surface: Surface,
|
||||||
|
props: WindowProps,
|
||||||
|
}
|
4
sysdata/libraries/sunset_proto/src/message.hb
Normal file
4
sysdata/libraries/sunset_proto/src/message.hb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
$new := 0
|
||||||
|
$destroy := 1
|
||||||
|
$update_props := 2
|
||||||
|
$shutdown := 3
|
34
sysdata/libraries/sunset_proto/src/server.hb
Normal file
34
sysdata/libraries/sunset_proto/src/server.hb
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
.{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb");
|
||||||
|
.{Surface, new_surface} := @use("../../render/src/lib.hb");
|
||||||
|
.{WindowWrapper, WindowID, WindowProps, WindowMessage, BUFFER} := @use("./lib.hb")
|
||||||
|
|
||||||
|
WindowServer := struct {window_count: uint, buffer_id: uint}
|
||||||
|
|
||||||
|
server := @as(?WindowServer, null)
|
||||||
|
|
||||||
|
new_window_id := fn(): WindowID {
|
||||||
|
return random.any(uint)
|
||||||
|
}
|
||||||
|
|
||||||
|
init := fn(): bool {
|
||||||
|
log.info("server: starting server\0")
|
||||||
|
server = .(0, buffer.create(BUFFER))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
recieve := fn(): ?WindowMessage {
|
||||||
|
if server == null {
|
||||||
|
log.error("server: (request_new) server is null. did you init the client?\0")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
buf := memory.uninit(WindowMessage)
|
||||||
|
buffer.recv(WindowMessage, @unwrap(server).buffer_id, @bitcast(&buf))
|
||||||
|
if memory.is_uninit(WindowMessage, &buf) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return buf
|
||||||
|
}
|
||||||
|
|
||||||
|
should_shutdown := fn(): bool {
|
||||||
|
return false
|
||||||
|
}
|
|
@ -60,9 +60,9 @@ main := fn(): int {
|
||||||
|
|
||||||
// TODO: Read the window buffer here
|
// TODO: Read the window buffer here
|
||||||
{
|
{
|
||||||
// ret := buffer.recv([u8; 4096], win_buff, mem_buf)
|
// buffer.recv([u8; 4096], win_buff, mem_buf)
|
||||||
// for some reason this null check causes the compiler to spin forever
|
// // for some reason this null check causes the compiler to spin forever
|
||||||
// if ret == null {
|
// if *mem_buf == 0 {
|
||||||
// log.info("No messages\0")
|
// log.info("No messages\0")
|
||||||
// } else {
|
// } else {
|
||||||
// log.info("Handle Messages\0")
|
// log.info("Handle Messages\0")
|
||||||
|
|
11
sysdata/programs/sunset_client/meta.toml
Normal file
11
sysdata/programs/sunset_client/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "sunset_client"
|
||||||
|
authors = ["koniifer"]
|
||||||
|
|
||||||
|
[dependants.libraries]
|
||||||
|
|
||||||
|
[dependants.binaries]
|
||||||
|
hblang.version = "1.0.0"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
command = "hblang src/main.hb"
|
24
sysdata/programs/sunset_client/src/main.hb
Normal file
24
sysdata/programs/sunset_client/src/main.hb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
.{log, string} := @use("../../../libraries/stn/src/lib.hb")
|
||||||
|
sunset := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||||
|
|
||||||
|
main := fn(): void {
|
||||||
|
sunset.client.init()
|
||||||
|
log.info("client: request new window\0")
|
||||||
|
window := sunset.client.new_window(.(.(100, 100), .(150, 150), "Hello, World!\0"))
|
||||||
|
if window == null {
|
||||||
|
log.error("Could not create window\0")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.info("client: window created. title:\0")
|
||||||
|
log.info(window.props.title)
|
||||||
|
window.props.position = .(500, 500)
|
||||||
|
props := @unwrap(sunset.client.update_window_props(@unwrap(window)))
|
||||||
|
if props.position.x != @unwrap(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")
|
||||||
|
}
|
||||||
|
}
|
11
sysdata/programs/sunset_server/meta.toml
Normal file
11
sysdata/programs/sunset_server/meta.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "sunset_server"
|
||||||
|
authors = ["koniifer"]
|
||||||
|
|
||||||
|
[dependants.libraries]
|
||||||
|
|
||||||
|
[dependants.binaries]
|
||||||
|
hblang.version = "1.0.0"
|
||||||
|
|
||||||
|
[build]
|
||||||
|
command = "hblang src/main.hb"
|
36
sysdata/programs/sunset_server/src/main.hb
Normal file
36
sysdata/programs/sunset_server/src/main.hb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
.{log} := @use("../../../libraries/stn/src/lib.hb")
|
||||||
|
render := @use("../../../libraries/render/src/lib.hb");
|
||||||
|
.{server, message, WindowWrapper, WindowProps} := @use("../../../libraries/sunset_proto/src/lib.hb")
|
||||||
|
|
||||||
|
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
|
||||||
|
|
||||||
|
main := fn(): void {
|
||||||
|
screen := render.init(false)
|
||||||
|
font := render.text.font_from_psf2(@bitcast(&psf), false)
|
||||||
|
if font == null {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if server.init() == false {
|
||||||
|
log.error("Failed to create server\0")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loop if server.should_shutdown() break else {
|
||||||
|
recv := server.recieve()
|
||||||
|
if recv == null {
|
||||||
|
continue
|
||||||
|
} else if recv.kind == message.new {
|
||||||
|
props := *@as(^WindowProps, @bitcast(recv.data_ptr));
|
||||||
|
*@as(^?WindowWrapper, @bitcast(recv.callback)) = WindowWrapper.(0, props)
|
||||||
|
render.put_rect(screen, props.position, props.dimensions, render.white)
|
||||||
|
render.put_text(screen, font, props.position + .(1, 1), render.white, props.title)
|
||||||
|
render.put_hline(screen, props.position.y + font.height + 2, props.position.x, props.position.x + props.dimensions.x, render.white)
|
||||||
|
log.info("server: made a new window\0")
|
||||||
|
} else if recv.kind == message.shutdown {
|
||||||
|
*@as(^?u8, @bitcast(recv.callback)) = 255
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render.put_text(screen, font, .(0, 0), render.white, "Shutdown triggered\0")
|
||||||
|
log.info("Server shutdown\0")
|
||||||
|
}
|
|
@ -33,3 +33,9 @@ path = "boot:///render_example.hbf"
|
||||||
|
|
||||||
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
# [boot.limine.ableos.modules.ps2_keyboard_driver]
|
||||||
# path = "boot:///ps2_keyboard_driver.hbf"
|
# path = "boot:///ps2_keyboard_driver.hbf"
|
||||||
|
|
||||||
|
[boot.limine.ableos.modules.sunset_client]
|
||||||
|
path = "boot:///sunset_client.hbf"
|
||||||
|
|
||||||
|
[boot.limine.ableos.modules.sunset_server]
|
||||||
|
path = "boot:///sunset_server.hbf"
|
||||||
|
|
Loading…
Reference in a new issue