From 2439722c88515598472375c0c1e32740673e21d0 Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 10 Nov 2024 05:52:47 -0600 Subject: [PATCH] misc --- .../src/examples => }/assets/able.bmp | Bin .../consolefonts/tamsyn/10x20b.psf | Bin .../consolefonts/tamsyn/10x20r.psf | Bin .../{ => assets}/consolefonts/tamsyn/5x9b.psf | Bin .../{ => assets}/consolefonts/tamsyn/5x9r.psf | Bin .../consolefonts/tamsyn/6x12b.psf | Bin .../consolefonts/tamsyn/6x12r.psf | Bin .../consolefonts/tamsyn/7x13b.psf | Bin .../consolefonts/tamsyn/7x13r.psf | Bin .../consolefonts/tamsyn/7x14b.psf | Bin .../consolefonts/tamsyn/7x14r.psf | Bin .../consolefonts/tamsyn/8x15b.psf | Bin .../consolefonts/tamsyn/8x15r.psf | Bin .../consolefonts/tamsyn/8x16b.psf | Bin .../consolefonts/tamsyn/8x16r.psf | Bin .../{ => assets}/consolefonts/tamsyn/LICENSE | 0 .../src/examples => }/assets/mini.bmp | Bin .../src/examples => }/assets/mini.qoi | Bin .../src/examples => }/assets/wallpaper.qoi | Bin .../horizon_api/src/widgets/image.hb | 18 +++-- sysdata/libraries/render/src/image/qoi.hb | 22 +++--- sysdata/libraries/render/src/lib.hb | 32 ++++---- sysdata/programs/app_bar/README.md | 2 - sysdata/programs/app_bar/meta.toml | 11 --- sysdata/programs/app_bar/src/main.hb | 35 --------- sysdata/programs/horizon/src/main.hb | 18 ++++- sysdata/programs/ps2_mouse_driver/src/main.hb | 74 +++++++----------- .../render_example/src/examples/image.hb | 4 +- .../render_example/src/examples/text.hb | 4 +- 29 files changed, 86 insertions(+), 134 deletions(-) rename sysdata/{programs/render_example/src/examples => }/assets/able.bmp (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/10x20b.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/10x20r.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/5x9b.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/5x9r.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/6x12b.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/6x12r.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/7x13b.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/7x13r.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/7x14b.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/7x14r.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/8x15b.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/8x15r.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/8x16b.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/8x16r.psf (100%) rename sysdata/{ => assets}/consolefonts/tamsyn/LICENSE (100%) rename sysdata/{programs/render_example/src/examples => }/assets/mini.bmp (100%) rename sysdata/{programs/render_example/src/examples => }/assets/mini.qoi (100%) rename sysdata/{programs/render_example/src/examples => }/assets/wallpaper.qoi (100%) delete mode 100644 sysdata/programs/app_bar/README.md delete mode 100644 sysdata/programs/app_bar/meta.toml delete mode 100644 sysdata/programs/app_bar/src/main.hb diff --git a/sysdata/programs/render_example/src/examples/assets/able.bmp b/sysdata/assets/able.bmp similarity index 100% rename from sysdata/programs/render_example/src/examples/assets/able.bmp rename to sysdata/assets/able.bmp diff --git a/sysdata/consolefonts/tamsyn/10x20b.psf b/sysdata/assets/consolefonts/tamsyn/10x20b.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/10x20b.psf rename to sysdata/assets/consolefonts/tamsyn/10x20b.psf diff --git a/sysdata/consolefonts/tamsyn/10x20r.psf b/sysdata/assets/consolefonts/tamsyn/10x20r.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/10x20r.psf rename to sysdata/assets/consolefonts/tamsyn/10x20r.psf diff --git a/sysdata/consolefonts/tamsyn/5x9b.psf b/sysdata/assets/consolefonts/tamsyn/5x9b.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/5x9b.psf rename to sysdata/assets/consolefonts/tamsyn/5x9b.psf diff --git a/sysdata/consolefonts/tamsyn/5x9r.psf b/sysdata/assets/consolefonts/tamsyn/5x9r.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/5x9r.psf rename to sysdata/assets/consolefonts/tamsyn/5x9r.psf diff --git a/sysdata/consolefonts/tamsyn/6x12b.psf b/sysdata/assets/consolefonts/tamsyn/6x12b.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/6x12b.psf rename to sysdata/assets/consolefonts/tamsyn/6x12b.psf diff --git a/sysdata/consolefonts/tamsyn/6x12r.psf b/sysdata/assets/consolefonts/tamsyn/6x12r.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/6x12r.psf rename to sysdata/assets/consolefonts/tamsyn/6x12r.psf diff --git a/sysdata/consolefonts/tamsyn/7x13b.psf b/sysdata/assets/consolefonts/tamsyn/7x13b.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/7x13b.psf rename to sysdata/assets/consolefonts/tamsyn/7x13b.psf diff --git a/sysdata/consolefonts/tamsyn/7x13r.psf b/sysdata/assets/consolefonts/tamsyn/7x13r.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/7x13r.psf rename to sysdata/assets/consolefonts/tamsyn/7x13r.psf diff --git a/sysdata/consolefonts/tamsyn/7x14b.psf b/sysdata/assets/consolefonts/tamsyn/7x14b.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/7x14b.psf rename to sysdata/assets/consolefonts/tamsyn/7x14b.psf diff --git a/sysdata/consolefonts/tamsyn/7x14r.psf b/sysdata/assets/consolefonts/tamsyn/7x14r.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/7x14r.psf rename to sysdata/assets/consolefonts/tamsyn/7x14r.psf diff --git a/sysdata/consolefonts/tamsyn/8x15b.psf b/sysdata/assets/consolefonts/tamsyn/8x15b.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/8x15b.psf rename to sysdata/assets/consolefonts/tamsyn/8x15b.psf diff --git a/sysdata/consolefonts/tamsyn/8x15r.psf b/sysdata/assets/consolefonts/tamsyn/8x15r.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/8x15r.psf rename to sysdata/assets/consolefonts/tamsyn/8x15r.psf diff --git a/sysdata/consolefonts/tamsyn/8x16b.psf b/sysdata/assets/consolefonts/tamsyn/8x16b.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/8x16b.psf rename to sysdata/assets/consolefonts/tamsyn/8x16b.psf diff --git a/sysdata/consolefonts/tamsyn/8x16r.psf b/sysdata/assets/consolefonts/tamsyn/8x16r.psf similarity index 100% rename from sysdata/consolefonts/tamsyn/8x16r.psf rename to sysdata/assets/consolefonts/tamsyn/8x16r.psf diff --git a/sysdata/consolefonts/tamsyn/LICENSE b/sysdata/assets/consolefonts/tamsyn/LICENSE similarity index 100% rename from sysdata/consolefonts/tamsyn/LICENSE rename to sysdata/assets/consolefonts/tamsyn/LICENSE diff --git a/sysdata/programs/render_example/src/examples/assets/mini.bmp b/sysdata/assets/mini.bmp similarity index 100% rename from sysdata/programs/render_example/src/examples/assets/mini.bmp rename to sysdata/assets/mini.bmp diff --git a/sysdata/programs/render_example/src/examples/assets/mini.qoi b/sysdata/assets/mini.qoi similarity index 100% rename from sysdata/programs/render_example/src/examples/assets/mini.qoi rename to sysdata/assets/mini.qoi diff --git a/sysdata/programs/render_example/src/examples/assets/wallpaper.qoi b/sysdata/assets/wallpaper.qoi similarity index 100% rename from sysdata/programs/render_example/src/examples/assets/wallpaper.qoi rename to sysdata/assets/wallpaper.qoi diff --git a/sysdata/libraries/horizon_api/src/widgets/image.hb b/sysdata/libraries/horizon_api/src/widgets/image.hb index 67e5391..b686aa8 100644 --- a/sysdata/libraries/horizon_api/src/widgets/image.hb +++ b/sysdata/libraries/horizon_api/src/widgets/image.hb @@ -1,5 +1,13 @@ -// Image := struct { -// magic: uint, -// is_dirty: bool, -// surface: Surface, -// } \ No newline at end of file +render := @use("../../../../libraries/render/src/lib.hb"); +.{Surface} := render + +Image := struct { + magic: uint, + is_dirty: bool, + surface: Surface, +} + +image_from_surface := fn(surface: Surface): Image { + img := Image.(4, true, surface) + return img +} \ No newline at end of file diff --git a/sysdata/libraries/render/src/image/qoi.hb b/sysdata/libraries/render/src/image/qoi.hb index 23a4907..2f4c888 100644 --- a/sysdata/libraries/render/src/image/qoi.hb +++ b/sysdata/libraries/render/src/image/qoi.hb @@ -4,20 +4,20 @@ /* source: https://github.com/phoboslab/qoi/blob/master/qoi.h */ -QOI_SRGB := 0 -QOI_LINEAR := 1 -QOI_OP_INDEX := 0x0 -QOI_OP_DIFF := 0x40 -QOI_OP_LUMA := 0x80 -QOI_OP_RUN := 0xC0 -QOI_OP_RGB := 0xFE -QOI_OP_RGBA := 0xFF -QOI_MASK_2 := 0xC0 +$QOI_SRGB := 0 +$QOI_LINEAR := 1 +$QOI_OP_INDEX := 0x0 +$QOI_OP_DIFF := 0x40 +$QOI_OP_LUMA := 0x80 +$QOI_OP_RUN := 0xC0 +$QOI_OP_RGB := 0xFE +$QOI_OP_RGBA := 0xFF +$QOI_MASK_2 := 0xC0 QOI_COLOR_HASH := fn(c: Color): u8 { return (c.r * 3 + c.g * 5 + c.b * 7 + c.a * 11) % 64 } -QOI_MAGIC := 0x716F6966 -QOI_PIXELS_MAX := 400000000 +$QOI_MAGIC := 0x716F6966 +$QOI_PIXELS_MAX := 400000000 QuiteOkayHeader := packed struct { magic: u32, diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 465a004..c72b8cd 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -17,22 +17,22 @@ indexptr := mode.indexptr // Colours Color := packed struct {b: u8, g: u8, r: u8, a: u8} -white := Color.(255, 255, 255, 255) -black := Color.(0, 0, 0, 255) -gray := Color.(127, 127, 127, 255) -red := Color.(0, 0, 205, 255) -green := Color.(0, 205, 0, 255) -yellow := Color.(0, 205, 205, 255) -blue := Color.(205, 0, 0, 255) -magenta := Color.(205, 0, 205, 255) -cyan := Color.(205, 205, 0, 255) -light_gray := Color.(229, 229, 229, 255) -light_red := Color.(0, 0, 255, 255) -light_green := Color.(0, 255, 0, 255) -light_yellow := Color.(0, 255, 255, 255) -light_blue := Color.(255, 0, 0, 255) -light_magenta := Color.(255, 0, 255, 255) -light_cyan := Color.(255, 255, 0, 255) +$white := Color.(255, 255, 255, 255) +$black := Color.(0, 0, 0, 255) +$gray := Color.(127, 127, 127, 255) +$red := Color.(0, 0, 205, 255) +$green := Color.(0, 205, 0, 255) +$yellow := Color.(0, 205, 205, 255) +$blue := Color.(205, 0, 0, 255) +$magenta := Color.(205, 0, 205, 255) +$cyan := Color.(205, 205, 0, 255) +$light_gray := Color.(229, 229, 229, 255) +$light_red := Color.(0, 0, 255, 255) +$light_green := Color.(0, 255, 0, 255) +$light_yellow := Color.(0, 255, 255, 255) +$light_blue := Color.(255, 0, 0, 255) +$light_magenta := Color.(255, 0, 255, 255) +$light_cyan := Color.(255, 255, 0, 255) // Drawing put_pixel := mode.put_pixel diff --git a/sysdata/programs/app_bar/README.md b/sysdata/programs/app_bar/README.md deleted file mode 100644 index 78d8cc6..0000000 --- a/sysdata/programs/app_bar/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# app bar -The app bar is a mini-bar meant to launch applications. \ No newline at end of file diff --git a/sysdata/programs/app_bar/meta.toml b/sysdata/programs/app_bar/meta.toml deleted file mode 100644 index 80e868e..0000000 --- a/sysdata/programs/app_bar/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "app_bar" -authors = ["able"] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/app_bar/src/main.hb b/sysdata/programs/app_bar/src/main.hb deleted file mode 100644 index 68f601d..0000000 --- a/sysdata/programs/app_bar/src/main.hb +++ /dev/null @@ -1,35 +0,0 @@ -stn := @use("../../../libraries/stn/src/lib.hb"); -.{string, memory, buffer, random, log} := stn; -.{Vec2} := stn.math - -horizon_api := @use("../../../libraries/horizon_api/src/lib.hb") - -render := @use("../../../libraries/render/src/lib.hb") - -psf := @embed("../../../consolefonts/tamsyn/10x20r.psf") - -main := fn(): int { - screen := render.init(true) - - // Clear the screen to black. - render.clear(screen, render.black) - - x := 0 - - mem_buf := memory.request_page(1) - color := random.any(render.Color) - - str := "Window Title Bar\0" - font := render.text.font_from_psf2(@bitcast(&psf)) - - loop { - // Clear the screen - render.clear(screen, render.black) - - render.put_rect(screen, .(0, 0), .(screen.width - 1, 26), render.white) - // Sync the screen - render.sync(screen) - } - - return 0 -} \ No newline at end of file diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index b146c96..37cad69 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -21,7 +21,8 @@ Window := struct { y: int, } -psf := @embed("../../../consolefonts/tamsyn/10x20r.psf") +psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf") +img := @embed("../../../assets/wallpaper.qoi") main := fn(): int { win_buff := buffer.create("XHorizon\0") @@ -31,6 +32,11 @@ main := fn(): int { // Clear the screen to black. render.clear(screen, render.black) + wallpaper := render.image.from(@bitcast(&img)) + if wallpaper == null { + return 1 + } + window := render.new_surface(screen.width / 3, screen.height / 3) mem_buf := memory.request_page(1) @@ -43,12 +49,14 @@ main := fn(): int { mouse_x := @as(i16, 0) mouse_y := @as(i16, 0) text_label := new_label("Hi\0") + // widgets := "()\0" // ui := sexpr_parser(widgets) loop { // Clear the screen render.clear(screen, render.black) + render.put_surface(screen, wallpaper, .(0, 0), false) // TODO: Read the window buffer here { @@ -77,7 +85,7 @@ 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, screen.height - 1), render.white) + render.put_rect(screen, .(0, screen.height - 21), .(screen.width - 1, 20), render.white) } { @@ -113,9 +121,11 @@ main := fn(): int { if mouse_event.left { set_label_text(text_label, "LEFT CLICK\0") - } else if mouse_event.middle { + } + if mouse_event.middle { set_label_text(text_label, "MIDDLE CLICK\0") - } else if mouse_event.right { + } + if mouse_event.right { set_label_text(text_label, "RIGHT CLICK\0") } } diff --git a/sysdata/programs/ps2_mouse_driver/src/main.hb b/sysdata/programs/ps2_mouse_driver/src/main.hb index 43544fa..5468017 100644 --- a/sysdata/programs/ps2_mouse_driver/src/main.hb +++ b/sysdata/programs/ps2_mouse_driver/src/main.hb @@ -6,22 +6,11 @@ intouch := @use("../../../libraries/intouch/src/lib.hb"); i9 := packed struct {sign: bool, value: u8} Button := struct {id: u8} -LeftButton := Button.(1) -RightButton := Button.(2) -MiddleButton := Button.(4) -Button4 := Button.(8) -Button5 := Button.(16) - -mouse_moved := fn(delta: Vec2(i9)): void { - // log.info("Mouse movement.\0") -} -button_event := fn(button: Button, pressed: bool): void { - if pressed { - // log.info("Mouse-button pressed.\0") - } else { - // log.info("Mouse-button released.\0") - } -} +$LeftButton := Button.(1) +$RightButton := Button.(2) +$MiddleButton := Button.(4) +$Button4 := Button.(8) +$Button5 := Button.(16) send_byte := fn(target: u8, data: u8): void { loop if (memory.inb(0x64) & 2) == 0 break @@ -41,7 +30,6 @@ send_command_byte := fn(byte: u8): void { @inline(send_byte, 0x64, 0xD4) @inline(send_byte, 0x60, byte) loop if memory.inb(0x60) == 0xFA { - log.info("ACK\0") return } } @@ -61,13 +49,13 @@ set_linear_scaling := fn(): void @inline(send_command_byte, 0xE6) resend_packet := fn(): void @inline(send_command_byte, 0xFE) SampleRate := struct {value: u8} -sr10 := SampleRate.(10) -sr20 := SampleRate.(20) -sr40 := SampleRate.(40) -sr60 := SampleRate.(60) -sr80 := SampleRate.(80) -sr100 := SampleRate.(100) -sr200 := SampleRate.(200) +$sr10 := SampleRate.(10) +$sr20 := SampleRate.(20) +$sr40 := SampleRate.(40) +$sr60 := SampleRate.(60) +$sr80 := SampleRate.(80) +$sr100 := SampleRate.(100) +$sr200 := SampleRate.(200) set_sample_rate := fn(sample_rate: SampleRate): void { @inline(send_command_byte, 0xE6) @@ -75,10 +63,10 @@ set_sample_rate := fn(sample_rate: SampleRate): void { } Resolution := struct {value: u8} -res_1count_per_mm := Resolution.(0) -res_2count_per_mm := Resolution.(1) -res_4count_per_mm := Resolution.(2) -res_8count_per_mm := Resolution.(3) +$res_1count_per_mm := Resolution.(0) +$res_2count_per_mm := Resolution.(1) +$res_4count_per_mm := Resolution.(2) +$res_8count_per_mm := Resolution.(3) set_resolution := fn(resolution: Resolution): void { @inline(send_command_byte, 0xE6) @@ -122,28 +110,22 @@ main := fn(): int { changes := button_states ^ status & 7 - if (changes & LeftButton.id) != 0 { - if (status & LeftButton.id) != 0 { - event.left = true - } else { - event.left = false - } + if (changes & LeftButton.id) != 0 | (status & LeftButton.id) != 0 { + event.left = true + } else { + event.left = false } - if (changes & MiddleButton.id) != 0 { - if (status & MiddleButton.id) != 0 { - event.middle = true - } else { - event.middle = false - } + if (changes & MiddleButton.id) != 0 | (status & MiddleButton.id) != 0 { + event.middle = true + } else { + event.middle = false } - if (changes & RightButton.id) != 0 { - if (status & RightButton.id) != 0 { - event.right = true - } else { - event.right = false - } + if (changes & RightButton.id) != 0 | (status & RightButton.id) != 0 { + event.right = true + } else { + event.right = false } button_states ^= changes diff --git a/sysdata/programs/render_example/src/examples/image.hb b/sysdata/programs/render_example/src/examples/image.hb index 621e6fa..d9f58e5 100644 --- a/sysdata/programs/render_example/src/examples/image.hb +++ b/sysdata/programs/render_example/src/examples/image.hb @@ -6,8 +6,8 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { screen := render.init(true) - image_qoi := render.image.from(@bitcast(&@embed("./assets/mini.qoi"))) - image_bmp := render.image.from(@bitcast(&@embed("./assets/mini.bmp"))) + image_qoi := render.image.from(@bitcast(&@embed("../../../../assets/mini.qoi"))) + image_bmp := render.image.from(@bitcast(&@embed("../../../../assets/mini.bmp"))) if image_qoi == null | image_bmp == null { log.error("failed to load images for whatever reason\0") diff --git a/sysdata/programs/render_example/src/examples/text.hb b/sysdata/programs/render_example/src/examples/text.hb index f9e0a5e..74ae601 100644 --- a/sysdata/programs/render_example/src/examples/text.hb +++ b/sysdata/programs/render_example/src/examples/text.hb @@ -13,8 +13,8 @@ render := @use("../../../../libraries/render/src/lib.hb") - shift key support */ -psf := @embed("../../../../consolefonts/tamsyn/10x20r.psf") -img := @embed("./assets/wallpaper.qoi") +psf := @embed("../../../../assets/consolefonts/tamsyn/10x20r.psf") +img := @embed("../../../../assets/wallpaper.qoi") is_shift_pressed := false is_ctrl_pressed := false