SDoom + pcspkr: Both prerelease

This commit is contained in:
Able 2024-11-26 07:39:16 -06:00
parent 9aa84a0f40
commit 1b3dc153e8
13 changed files with 170 additions and 44 deletions

View file

@ -460,6 +460,10 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
// "-serial", "stdio", // "-serial", "stdio",
"-m", "2G", "-m", "2G",
"-smp", "1", "-smp", "1",
"-audiodev",
"pa,id=speaker",
"-machine",
"pcspk-audiodev=speaker",
"-parallel", "none", "-parallel", "none",
"-monitor", "none", "-monitor", "none",
"-machine", accel, "-machine", accel,

View file

@ -26,12 +26,6 @@ create_window := fn(channel: int): ^render.Surface {
if windowing_system_buffer == 0 { if windowing_system_buffer == 0 {
return @as(^render.Surface, idk) return @as(^render.Surface, idk)
} else { } 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 x := 0
loop if x > 1000 break else x += 1 loop if x > 1000 break else x += 1

View file

@ -14,14 +14,27 @@ Label := struct {
text_length: uint, text_length: uint,
bg: Color, bg: Color,
fg: Color, fg: Color,
}
set_label_text := fn(label: Label, text: ^u8): void { new_label := fn(text: ^u8): Self {
text_length := string.length(text) 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 set_label_text := fn(self: Self, text: ^u8): void {
label.text = text text_length := string.length(text)
label.text_length = text_length
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 { 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_text(label.surface, font, .(0, 0), label.fg, label.text)
} }
render.put_surface(surface, label.surface, pos, false) 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
} }

View file

@ -0,0 +1 @@
# pcspkr

View file

@ -0,0 +1,11 @@
[package]
name = "pcspkr"
authors = [""]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -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
}

View file

@ -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.

View file

@ -0,0 +1,11 @@
[package]
name = "sdoom"
authors = [""]
[dependants.libraries]
[dependants.binaries]
hblang.version = "1.0.0"
[build]
command = "hblang src/main.hb"

View file

@ -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)
}
}

View file

View file

@ -13,7 +13,7 @@ main := fn(): void {
return return
} }
window := sunset.client.new(.(.(400, 300), .(400, 240), "Sunset!\0")) window := sunset.client.new(.(.(400, 100), .(400, 240), "Sunset!\0"))
if window == null { if window == null {
log.error("got no window\0") log.error("got no window\0")

View file

@ -3,7 +3,7 @@ render := @use("../../../libraries/render/src/lib.hb")
intouch := @use("../../../libraries/intouch/src/lib.hb") intouch := @use("../../../libraries/intouch/src/lib.hb")
horizon_api := @use("../../../libraries/horizon_api/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"); stn := @use("../../../libraries/stn/src/lib.hb");
.{Vec2} := stn.math .{Vec2} := stn.math
@ -31,8 +31,8 @@ main := fn(): int {
mouse_x := 100 mouse_x := 100
mouse_y := 100 mouse_y := 100
text_label := new_label("Hi\0") text_label := Label.new_label("Hi\0")
set_color(text_label, sunset.server.DECO_COLOUR, render.black) text_label.set_color(sunset.server.DECO_COLOUR, render.black)
loop { loop {
mouse_event := intouch.recieve_mouse_event() mouse_event := intouch.recieve_mouse_event()
@ -62,13 +62,13 @@ main := fn(): int {
} }
if mouse_event.left { if mouse_event.left {
set_label_text(text_label, "LEFT CLICK\0") text_label.set_label_text("LEFT CLICK\0")
} }
if mouse_event.middle { if mouse_event.middle {
set_label_text(text_label, "MIDDLE CLICK\0") text_label.set_label_text("MIDDLE CLICK\0")
} }
if mouse_event.right { if mouse_event.right {
set_label_text(text_label, "RIGHT CLICK\0") text_label.set_label_text("RIGHT CLICK\0")
} }
} }
{ {

View file

@ -28,26 +28,29 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.horizon] # [boot.limine.ableos.modules.horizon]
# path = "boot:///horizon.hbf" # path = "boot:///horizon.hbf"
# [boot.limine.ableos.modules.ps2_mouse_driver] [boot.limine.ableos.modules.ps2_mouse_driver]
# path = "boot:///ps2_mouse_driver.hbf" path = "boot:///ps2_mouse_driver.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] [boot.limine.ableos.modules.sunset_client]
# path = "boot:///sunset_client.hbf" path = "boot:///sunset_client.hbf"
# [boot.limine.ableos.modules.sunset_client_2] [boot.limine.ableos.modules.sunset_client_2]
# path = "boot:///sunset_client_2.hbf" path = "boot:///sunset_client_2.hbf"
# [boot.limine.ableos.modules.sunset_server] [boot.limine.ableos.modules.sdoom]
# path = "boot:///sunset_server.hbf" path = "boot:///sdoom.hbf"
# [boot.limine.ableos.modules.processes] [boot.limine.ableos.modules.sunset_server]
# path = "boot:///processes.hbf" path = "boot:///sunset_server.hbf"
# [boot.limine.ableos.modules.pcspkr]
# path = "boot:///pcspkr.hbf"
# [boot.limine.ableos.modules.alloc_test] # [boot.limine.ableos.modules.alloc_test]
# path = "boot:///alloc_test.hbf" # path = "boot:///alloc_test.hbf"
[boot.limine.ableos.modules.alloc_test] # [boot.limine.ableos.modules.hash_test]
path = "boot:///alloc_test.hbf" # path = "boot:///hash_test.hbf"