From ea8eca108994851ea86c021612af2dc7e4dd67b5 Mon Sep 17 00:00:00 2001 From: koniifer Date: Sat, 12 Oct 2024 21:39:09 +0100 Subject: [PATCH] various stn & render-api changes --- Cargo.lock | 6 ++-- HELP.md | 2 +- kernel/src/holeybytes/ecah.rs | 27 +++++++++--------- kernel/src/holeybytes/mem.rs | 6 ++-- sysdata/empty-background.bmp | Bin 0 -> 66 bytes sysdata/libraries/render/src/lib.hb | 9 ++++-- sysdata/libraries/render/src/software.hb | 27 ++++++++++-------- sysdata/libraries/render/src/svga.hb | 22 ++++++++------ sysdata/libraries/stn/src/math.hb | 19 ++++++------ sysdata/libraries/stn/src/random.hb | 6 ++-- .../render_example/src/examples/lines.hb | 5 ++-- .../render_example/src/examples/random.hb | 10 +++---- .../render_example/src/examples/square.hb | 11 +++---- sysdata/programs/render_example/src/main.hb | 2 +- sysdata/system_config.toml | 15 ++++++---- 15 files changed, 91 insertions(+), 76 deletions(-) create mode 100644 sysdata/empty-background.bmp diff --git a/Cargo.lock b/Cargo.lock index a5b6b05..bfd0b3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,12 +350,12 @@ checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c4826d3bfdc2def022fc7e80c6d5fe86df4e1c95" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a" [[package]] name = "hblang" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c4826d3bfdc2def022fc7e80c6d5fe86df4e1c95" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a" dependencies = [ "hashbrown 0.15.0", "hbbytecode", @@ -367,7 +367,7 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c4826d3bfdc2def022fc7e80c6d5fe86df4e1c95" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a" dependencies = [ "hbbytecode", ] diff --git a/HELP.md b/HELP.md index 47a0f17..8558977 100644 --- a/HELP.md +++ b/HELP.md @@ -66,4 +66,4 @@ - Submit an issue [here](https://git.ablecorp.us/ableos/ableos/issues) or report it in the [discord](https://discord.gg/t5Wt3K4YNA) ### How do I report a compiler bug? -- Submit an issue [here](https://git.ablecorp.us/ableos/holeybytes/issues) or report it in the [discord](https://discord.gg/t5Wt3K4YNA) \ No newline at end of file +- Submit an issue [here](https://git.ablecorp.us/ableos/holey-bytes/issues) or report it in the [discord](https://discord.gg/t5Wt3K4YNA) \ No newline at end of file diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 0a1f898..8d67692 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -13,14 +13,17 @@ use { }; #[cfg(target_arch = "x86_64")] +#[inline(always)] unsafe fn x86_out(address: u16, value: T) { x86_64::instructions::port::Port::new(address).write(value); } #[cfg(target_arch = "x86_64")] +#[inline(always)] unsafe fn x86_in(address: u16) -> T { x86_64::instructions::port::Port::new(address).read() } +#[inline(always)] pub fn handler(vm: &mut Vm) { let ecall_number = vm.registers[2].cast::(); // log::info!("eca called :pensive:"); @@ -49,18 +52,15 @@ pub fn handler(vm: &mut Vm) { let length = vm.registers[4].cast::(); let mut buffs = IPC_BUFFERS.lock(); - let abc; - match bounded { - false => { - abc = IpcBuffer::new(false, 0); - } - true => { - abc = IpcBuffer::new(true, length); - } - }; let buff_id = arch::hardware_random_u64(); - buffs.insert(buff_id, abc); + buffs.insert( + buff_id, + match bounded { + false => IpcBuffer::new(false, 0), + true => IpcBuffer::new(true, length), + }, + ); info!("Buffer ID: {}", buff_id); vm.registers[1] = hbvm::value::Value(buff_id); } @@ -145,15 +145,14 @@ pub fn handler(vm: &mut Vm) { let mut buffs = IPC_BUFFERS.lock(); match buffs.get_mut(&buffer_id) { Some(buff) => { - let msg_vec = block_read(mem_addr, length).to_vec(); - debug!("Sending Message {:?} to Buffer({})", msg_vec, buffer_id); - buff.push(msg_vec); + let msg_vec = block_read(mem_addr, length); + buff.push(msg_vec.to_vec()); + debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer_id); } None => { log::error!("Access of non-existent buffer {}", buffer_id) } } - drop(buffs); } } } diff --git a/kernel/src/holeybytes/mem.rs b/kernel/src/holeybytes/mem.rs index 6b58290..79a3614 100644 --- a/kernel/src/holeybytes/mem.rs +++ b/kernel/src/holeybytes/mem.rs @@ -30,7 +30,7 @@ impl Memory { } impl hbvm::mem::Memory for Memory { - #[inline] + #[inline(always)] unsafe fn load( &mut self, addr: Address, @@ -42,7 +42,7 @@ impl hbvm::mem::Memory for Memory { Ok(()) } - #[inline] + #[inline(always)] unsafe fn store( &mut self, addr: Address, @@ -53,7 +53,7 @@ impl hbvm::mem::Memory for Memory { Ok(()) } - #[inline] + #[inline(always)] unsafe fn prog_read(&mut self, addr: Address) -> T { (addr.get() as *const T).read() } diff --git a/sysdata/empty-background.bmp b/sysdata/empty-background.bmp new file mode 100644 index 0000000000000000000000000000000000000000..ae5f93c5d55f84431a9836f011c5023723c3e6cf GIT binary patch literal 66 ocmZ?rbz*=3J0PV2#EftZVlgnV0Pzt%2xbDZK^O+2{)pKF0DH&;lK=n! literal 0 HcmV?d00001 diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index fdd5bb3..5c0baed 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -32,6 +32,7 @@ put_rect := mode.put_rect put_filled_rect := mode.put_filled_rect put_line := mode.put_line clear := mode.clear +put_img := mode.put_img // Display width := mode.width @@ -42,6 +43,8 @@ set_width := mode.set_width set_dimensions := mode.set_dimensions sync := mode.sync -// Math -UVec2 := struct {x: uint, y: uint} -IVec2 := struct {x: int, y: int} \ No newline at end of file +// Trash Image +Image := struct { + start: ^Color, + end: ^Color, +} \ No newline at end of file diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index 80c4ed4..a89057b 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -1,6 +1,7 @@ .{math, memory} := @use("../../stn/src/lib.hb"); .{dt_get} := @use("../../dt_api/src/lib.hb"); -.{IVec2} := @use("lib.hb") +.{Image} := @use("lib.hb"); +.{Vec2} := math Color := struct {b: u8, g: u8, r: u8, a: u8} white := Color.(255, 255, 255, 255) @@ -42,8 +43,6 @@ Context := struct { init := fn(): void { width := dt_get("framebuffer/fb0/width\0") height := dt_get("framebuffer/fb0/height\0") - // width := 1024 - // height := 768 pixels := width * height bytes := pixels << 2 partitions := pixels / copy_pixels @@ -141,12 +140,12 @@ screenidx := fn(x: int, y: int): int { return x + ctx.width * y } -put_pixel := fn(pos: IVec2, color: Color): void { +put_pixel := fn(pos: Vec2(int), color: Color): void { *(ctx.buf + @inline(screenidx, pos.x, pos.y)) = color return } -put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { +put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { x := pos.x y := pos.y end := pos + tr @@ -161,7 +160,7 @@ put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { return } -put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { +put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { x := pos.x y := pos.y end := pos + tr @@ -179,7 +178,7 @@ put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { return } -put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void { +put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { dx := p1.x - p0.x dy := p1.y - p0.y yi := 1 @@ -203,7 +202,7 @@ put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void { return } -put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void { +put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { dx := p1.x - p0.x dy := p1.y - p0.y xi := 1 @@ -227,8 +226,8 @@ put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void { return } -put_line := fn(p0: IVec2, p1: IVec2, color: Color): void { - if @inline(math.abs, p1.y - p0.y) < @inline(math.abs, p1.x - p0.x) { +put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { + if math.abs(int, p1.y - p0.y) < math.abs(int, p1.x - p0.x) { if p0.x > p1.x { @inline(put_line_low, p1, p0, color) } else { @@ -252,10 +251,14 @@ set_width := fn(new: int): void { return } -dimensions := fn(): IVec2 { +dimensions := fn(): Vec2(int) { return .(ctx.width, ctx.height) } -set_dimensions := fn(new: IVec2): void { +set_dimensions := fn(new: Vec2(int)): void { + return +} + +put_img := fn(img: Image, pos: Vec2(int)): void { return } \ No newline at end of file diff --git a/sysdata/libraries/render/src/svga.hb b/sysdata/libraries/render/src/svga.hb index e88d008..0790198 100644 --- a/sysdata/libraries/render/src/svga.hb +++ b/sysdata/libraries/render/src/svga.hb @@ -1,4 +1,4 @@ -.{IVec2} := @use("lib.hb") +.{Vec2, Image} := @use("lib.hb") // .{pci, memory, string, log} := @use("../../stn/src/lib.hb"); Color := struct {b: u8, g: u8, r: u8, a: u8} @@ -31,31 +31,31 @@ height := fn(): int { return 0 } -dimensions := fn(): IVec2 { +dimensions := fn(): Vec2(int) { return .(0, 0) } -put_pixel := fn(position: IVec2, color: Color): void { +put_pixel := fn(position: Vec2(int), color: Color): void { return } -put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { +put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { return } -put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { +put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { return } -put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void { +put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { return } // do not use, use line() instead -put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void { +put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { return } -put_line := fn(p0: IVec2, p1: IVec2, color: Color): void { +put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { return } @@ -67,7 +67,7 @@ set_width := fn(new: int): void { return } -set_dimensions := fn(new: IVec2): void { +set_dimensions := fn(new: Vec2(int)): void { return } @@ -77,4 +77,8 @@ sync := fn(): void { init := fn(): void { return +} + +put_img := fn(img: Image, pos: Vec2(int)): void { + return } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/math.hb b/sysdata/libraries/stn/src/math.hb index 4c4f87e..f4e0c84 100644 --- a/sysdata/libraries/stn/src/math.hb +++ b/sysdata/libraries/stn/src/math.hb @@ -1,15 +1,16 @@ -shift := 31 - -// following only work for: int -abs := fn(x: int): int { - mask := x >> shift +abs := fn($Expr: type, x: Expr): Expr { + mask := x >> @intcast(@sizeof(Expr) - 1) return (x ^ mask) - mask } -min := fn(a: int, b: int): int { +min := fn($Expr: type, a: Expr, b: Expr): Expr { c := a - b - return b + (c & c >> shift) + return b + (c & c >> @intcast(@sizeof(Expr) - 1)) } -max := fn(a: int, b: uint): int { +max := fn($Expr: type, a: Expr, b: Expr): Expr { c := a - b - return a - (c & c >> shift) + return a - (c & c >> @intcast(@sizeof(Expr) - 1)) +} + +Vec2 := fn($Expr: type): type { + return struct {x: Expr, y: Expr} } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/random.hb b/sysdata/libraries/stn/src/random.hb index d9d1d04..1e62560 100644 --- a/sysdata/libraries/stn/src/random.hb +++ b/sysdata/libraries/stn/src/random.hb @@ -1,7 +1,7 @@ -integer := fn(): int { - return @eca(3, 4) +any := fn($Expr: type): Expr { + return @intcast(@eca(3, 4)) } -integer_range := fn(min: int, max: int): int { +range := fn($Expr: type, min: Expr, max: Expr): Expr { return @eca(3, 4) % (max - min + 1) + min } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/lines.hb b/sysdata/programs/render_example/src/examples/lines.hb index 5a41609..be4a536 100644 --- a/sysdata/programs/render_example/src/examples/lines.hb +++ b/sysdata/programs/render_example/src/examples/lines.hb @@ -1,3 +1,4 @@ +.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math render := @use("../../../../libraries/render/src/lib.hb") /* expected result: @@ -9,8 +10,8 @@ example := fn(): void { render.clear(.(100, 50, 0, 255)) width := render.width() height := render.height() - p0 := render.IVec2.(0, 0) - p1 := render.IVec2.(0, height) + p0 := Vec2(int).(0, 0) + p1 := Vec2(int).(0, height) loop if p0.y >= height break else { render.put_line(p0, p1, .(255, 180, 100, 255)) render.put_line(.(width, height) - p0, .(width, height) - p1, .(255, 180, 100, 255)) diff --git a/sysdata/programs/render_example/src/examples/random.hb b/sysdata/programs/render_example/src/examples/random.hb index 7b0fbbb..7c68c5e 100644 --- a/sysdata/programs/render_example/src/examples/random.hb +++ b/sysdata/programs/render_example/src/examples/random.hb @@ -6,11 +6,11 @@ example := fn(): void { render.doublebuffer(false) render.clear(render.black) loop { - x := random.integer_range(0, 1024) - y := random.integer_range(0, 768) - r := random.integer_range(0, 255) - g := random.integer_range(0, 75) - b := random.integer_range(0, 155) + x := random.range(int, 0, 1024) + y := random.range(int, 0, 768) + r := random.range(int, 0, 255) + g := random.range(int, 0, 75) + b := random.range(int, 0, 155) render.put_pixel(.(x, y), .(b, g, r, 255)) } return diff --git a/sysdata/programs/render_example/src/examples/square.hb b/sysdata/programs/render_example/src/examples/square.hb index 84b013b..46ee810 100644 --- a/sysdata/programs/render_example/src/examples/square.hb +++ b/sysdata/programs/render_example/src/examples/square.hb @@ -1,3 +1,4 @@ +.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math; .{random} := @use("../../../../libraries/stn/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb") @@ -6,11 +7,11 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { render.init() - vel := render.IVec2.(1, 1) - pos := render.IVec2.(100, 100) + vel := Vec2(int).(1, 1) + pos := Vec2(int).(100, 100) width := render.width() height := render.height() - color := @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) + color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) loop { render.put_filled_rect(pos, .(100, 100), color) render.sync() @@ -18,11 +19,11 @@ example := fn(): void { if pos.x == 0 | pos.x == width - 100 { vel.x = -vel.x - color = @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) + color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) } if pos.y == 0 | pos.y == height - 100 { vel.y = -vel.y - color = @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) + color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) } pos += vel diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 052e1cf..35b2706 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1,4 +1,4 @@ -.{example} := @use("./examples/square.hb") +.{example} := @use("./examples/amogus.hb") main := fn(): void { @inline(example) diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 76c2ccc..e4bd86f 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -4,8 +4,10 @@ default_entry = 1 timeout = 0 verbose = false interface_resolution = "1024x768x24" +# interface_resolution = "640x480x32" # Terminal related settings term_wallpaper = "boot:///background.bmp" +# term_wallpaper = "boot:///empty-background.bmp" term_background = "008080" [boot.limine.ableos] @@ -13,6 +15,7 @@ comment = "Default AbleOS boot entry." protocol = "limine" kernel_path = "boot:///kernel_${ARCH}" kernel_cmdline = "" +# resolution = "640x480x32" resolution = "1024x768x24" [boot.limine.ableos.modules] @@ -26,8 +29,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.diskio_driver] # path = "boot:///diskio_driver.hbf" -# [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.serial_driver_test] # path = "boot:///serial_driver_test.hbf" @@ -44,8 +47,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.svga_driver] # path = "boot:///svga_driver.hbf" -[boot.limine.ableos.modules.ps2_driver] -path = "boot:///ps2_driver.hbf" +# [boot.limine.ableos.modules.ps2_driver] +# path = "boot:///ps2_driver.hbf" # [boot.limine.ableos.modules.filesystem_fat32] # path = "boot:///filesystem_fat32.hbf" @@ -53,5 +56,5 @@ path = "boot:///ps2_driver.hbf" # [boot.limine.ableos.modules.pumpkin_print] # path = "boot:///pumpkin_print.hbf" -[boot.limine.ableos.modules.tetris] -path = "boot:///tetris.hbf" +# [boot.limine.ableos.modules.tetris] +# path = "boot:///tetris.hbf"