From 1b3dc153e8ccf8df961f32e9370e94f61029f77b Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 26 Nov 2024 07:39:16 -0600 Subject: [PATCH] SDoom + pcspkr: Both prerelease --- repbuild/src/main.rs | 4 ++ sysdata/libraries/horizon_api/src/lib.hb | 6 --- .../horizon_api/src/widgets/label.hb | 38 ++++++------- sysdata/programs/pcspkr/README.md | 1 + sysdata/programs/pcspkr/meta.toml | 11 ++++ sysdata/programs/pcspkr/src/main.hb | 45 ++++++++++++++++ sysdata/programs/sdoom/README.md | 4 ++ sysdata/programs/sdoom/meta.toml | 11 ++++ sysdata/programs/sdoom/src/main.hb | 53 +++++++++++++++++++ sysdata/programs/sdoom/src/player.hb | 0 sysdata/programs/sunset_client_2/src/main.hb | 2 +- sysdata/programs/sunset_server/src/main.hb | 12 ++--- sysdata/system_config.toml | 27 +++++----- 13 files changed, 170 insertions(+), 44 deletions(-) create mode 100644 sysdata/programs/pcspkr/README.md create mode 100644 sysdata/programs/pcspkr/meta.toml create mode 100644 sysdata/programs/pcspkr/src/main.hb create mode 100644 sysdata/programs/sdoom/README.md create mode 100644 sysdata/programs/sdoom/meta.toml create mode 100644 sysdata/programs/sdoom/src/main.hb create mode 100644 sysdata/programs/sdoom/src/player.hb diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 8d63c2dd..d361cbc1 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -460,6 +460,10 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> { // "-serial", "stdio", "-m", "2G", "-smp", "1", + "-audiodev", + "pa,id=speaker", + "-machine", + "pcspk-audiodev=speaker", "-parallel", "none", "-monitor", "none", "-machine", accel, diff --git a/sysdata/libraries/horizon_api/src/lib.hb b/sysdata/libraries/horizon_api/src/lib.hb index 112bbac3..bae1ba61 100644 --- a/sysdata/libraries/horizon_api/src/lib.hb +++ b/sysdata/libraries/horizon_api/src/lib.hb @@ -26,12 +26,6 @@ create_window := fn(channel: int): ^render.Surface { if windowing_system_buffer == 0 { return @as(^render.Surface, idk) } else { - // ! bad able, stop using string messages :ragey: - // msg := "\{01}\0" - // msg_length := 2 - - // @as(void, @eca(3, windowing_system_buffer, msg, msg_length)) - x := 0 loop if x > 1000 break else x += 1 diff --git a/sysdata/libraries/horizon_api/src/widgets/label.hb b/sysdata/libraries/horizon_api/src/widgets/label.hb index 5d1fb195..ce7e030a 100644 --- a/sysdata/libraries/horizon_api/src/widgets/label.hb +++ b/sysdata/libraries/horizon_api/src/widgets/label.hb @@ -14,14 +14,27 @@ Label := struct { text_length: uint, bg: Color, fg: Color, -} -set_label_text := fn(label: Label, text: ^u8): void { - text_length := string.length(text) + new_label := fn(text: ^u8): Self { + text_surface := render.new_surface(1024, 20) + text_length := string.length(text) + label := Self.(3, true, text_surface, text, text_length, render.black, render.white) + return label + } - label.is_dirty = true - label.text = text - label.text_length = text_length + set_label_text := fn(self: Self, text: ^u8): void { + text_length := string.length(text) + + self.is_dirty = true + self.text = text + self.text_length = text_length + } + + $set_color := fn(self: Self, bg: Color, fg: Color): void { + self.bg = bg + self.fg = fg + self.is_dirty = true + } } render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void { @@ -30,17 +43,4 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V render.put_text(label.surface, font, .(0, 0), label.fg, label.text) } render.put_surface(surface, label.surface, pos, false) -} - -new_label := fn(text: ^u8): Label { - text_surface := render.new_surface(1024, 20) - text_length := string.length(text) - label := Label.(3, true, text_surface, text, text_length, render.black, render.white) - return label -} - -$set_color := fn(label: Label, bg: Color, fg: Color): void { - label.bg = bg - label.fg = fg - label.is_dirty = true } \ No newline at end of file diff --git a/sysdata/programs/pcspkr/README.md b/sysdata/programs/pcspkr/README.md new file mode 100644 index 00000000..5a5f4b95 --- /dev/null +++ b/sysdata/programs/pcspkr/README.md @@ -0,0 +1 @@ +# pcspkr \ No newline at end of file diff --git a/sysdata/programs/pcspkr/meta.toml b/sysdata/programs/pcspkr/meta.toml new file mode 100644 index 00000000..d71a5f20 --- /dev/null +++ b/sysdata/programs/pcspkr/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "pcspkr" +authors = [""] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/pcspkr/src/main.hb b/sysdata/programs/pcspkr/src/main.hb new file mode 100644 index 00000000..5c5055cb --- /dev/null +++ b/sysdata/programs/pcspkr/src/main.hb @@ -0,0 +1,45 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +.{memory, buffer, log, string, math} := stn; +.{inb, outb} := memory + +$PIT_CLOCK := 1193180 + +play_sound := fn(frequency: u32): void { + div := 0 + + div = PIT_CLOCK / frequency + memory.outb(0x43, 0xB6) + memory.outb(0x42, @intcast(div)) + memory.outb(0x42, @intcast(div >> 8)) + + tmp := inb(0x61) + if tmp != (tmp | 3) { + outb(0x61, tmp | 3) + } +} + +no_sound := fn(): void { + tmp := memory.inb(0x61) & 0xFC + + memory.outb(0x61, tmp) +} + +beep := fn(): void { + play_sound(1000) + idx := 0 + loop { + if idx >= 1000000 { + idx += 1 + } else { + break + } + } + + no_sound() +} + +main := fn(): int { + no_sound() + beep() + return 0 +} \ No newline at end of file diff --git a/sysdata/programs/sdoom/README.md b/sysdata/programs/sdoom/README.md new file mode 100644 index 00000000..e752f1fa --- /dev/null +++ b/sysdata/programs/sdoom/README.md @@ -0,0 +1,4 @@ +# sdoom +SDoom stands for simple doom. + +This is not a full implementation of doom and is instead a doom style renderer. \ No newline at end of file diff --git a/sysdata/programs/sdoom/meta.toml b/sysdata/programs/sdoom/meta.toml new file mode 100644 index 00000000..b6e9cbde --- /dev/null +++ b/sysdata/programs/sdoom/meta.toml @@ -0,0 +1,11 @@ +[package] +name = "sdoom" +authors = [""] + +[dependants.libraries] + +[dependants.binaries] +hblang.version = "1.0.0" + +[build] +command = "hblang src/main.hb" diff --git a/sysdata/programs/sdoom/src/main.hb b/sysdata/programs/sdoom/src/main.hb new file mode 100644 index 00000000..22aebc7b --- /dev/null +++ b/sysdata/programs/sdoom/src/main.hb @@ -0,0 +1,53 @@ +sunset := @use("../../../libraries/sunset_proto/src/lib.hb") +render := @use("../../../libraries/render/src/lib.hb") + +stn := @use("../../../libraries/stn/src/lib.hb"); +.{log} := stn; +.{Vec2} := stn.math + +Player := struct { + x: i8, + y: i8, + + $new := fn(x: i8, y: i8): Self { + return Self.(x, y) + } +} + +GameState := struct { + player: Player, + + $new := fn(): Self { + p := Player.new(0, 0) + return Self.(p) + } +} + +main := fn(): void { + sunset.client.find_server() + + window := sunset.client.new(.(.(600, 400), .(200, 200), "SDoom\0")) + + if window == null { + log.error("got no window\0") + return + } + + game_state := GameState.new() + + loop { + render.clear(window.surface, render.black) + width := 100 + idx := 1 + + loop { + if idx >= width { + break + } + render.put_vline(window.surface, idx, 10, 100, render.white) + idx += 1 + } + + _ = sunset.client.send_frame(window) + } +} \ No newline at end of file diff --git a/sysdata/programs/sdoom/src/player.hb b/sysdata/programs/sdoom/src/player.hb new file mode 100644 index 00000000..e69de29b diff --git a/sysdata/programs/sunset_client_2/src/main.hb b/sysdata/programs/sunset_client_2/src/main.hb index 3fcf1c1a..2e547596 100644 --- a/sysdata/programs/sunset_client_2/src/main.hb +++ b/sysdata/programs/sunset_client_2/src/main.hb @@ -13,7 +13,7 @@ main := fn(): void { return } - window := sunset.client.new(.(.(400, 300), .(400, 240), "Sunset!\0")) + window := sunset.client.new(.(.(400, 100), .(400, 240), "Sunset!\0")) if window == null { log.error("got no window\0") diff --git a/sysdata/programs/sunset_server/src/main.hb b/sysdata/programs/sunset_server/src/main.hb index 1376ee51..fa109c6b 100644 --- a/sysdata/programs/sunset_server/src/main.hb +++ b/sysdata/programs/sunset_server/src/main.hb @@ -3,7 +3,7 @@ render := @use("../../../libraries/render/src/lib.hb") intouch := @use("../../../libraries/intouch/src/lib.hb") horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); -.{new_label, render_label_to_surface, set_label_text, set_color} := horizon_api.widgets.label +.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label stn := @use("../../../libraries/stn/src/lib.hb"); .{Vec2} := stn.math @@ -31,8 +31,8 @@ main := fn(): int { mouse_x := 100 mouse_y := 100 - text_label := new_label("Hi\0") - set_color(text_label, sunset.server.DECO_COLOUR, render.black) + text_label := Label.new_label("Hi\0") + text_label.set_color(sunset.server.DECO_COLOUR, render.black) loop { mouse_event := intouch.recieve_mouse_event() @@ -62,13 +62,13 @@ main := fn(): int { } if mouse_event.left { - set_label_text(text_label, "LEFT CLICK\0") + text_label.set_label_text("LEFT CLICK\0") } if mouse_event.middle { - set_label_text(text_label, "MIDDLE CLICK\0") + text_label.set_label_text("MIDDLE CLICK\0") } if mouse_event.right { - set_label_text(text_label, "RIGHT CLICK\0") + text_label.set_label_text("RIGHT CLICK\0") } } { diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index f6b8e039..a63f1704 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -28,26 +28,29 @@ 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" -# [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_client_2] -# path = "boot:///sunset_client_2.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" +[boot.limine.ableos.modules.sdoom] +path = "boot:///sdoom.hbf" -# [boot.limine.ableos.modules.processes] -# path = "boot:///processes.hbf" +[boot.limine.ableos.modules.sunset_server] +path = "boot:///sunset_server.hbf" + +# [boot.limine.ableos.modules.pcspkr] +# path = "boot:///pcspkr.hbf" # [boot.limine.ableos.modules.alloc_test] # path = "boot:///alloc_test.hbf" -[boot.limine.ableos.modules.alloc_test] -path = "boot:///alloc_test.hbf" +# [boot.limine.ableos.modules.hash_test] +# path = "boot:///hash_test.hbf"