1
0
Fork 0
forked from AbleOS/ableos

Adit Commit

This commit is contained in:
Able 2025-02-17 15:29:45 -06:00
parent 1ea3257921
commit dac9e4d3f8
11 changed files with 455 additions and 12 deletions

View file

@ -0,0 +1 @@
# adit

View file

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

View file

@ -0,0 +1,15 @@
render := @use("lib:render")
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
Assets := struct {
font: render.text.Font
new := fn():Self {
font := render.text.font_from_psf2(@bitcast(&psf), false)
if font == null {
die
}
return Self.(font)
}
}

View file

@ -0,0 +1,65 @@
theme := @use("theme.hb")
render := @use("lib:render")
sunset := @use("lib:sunset_proto")
assets := @use("assets.hb")
Editor := struct {
msg: ?^u8,
// is_shift_pressed: bool = false,
// is_ctrl_pressed: bool = false,
// is_extended: bool = false,
assets: assets.Assets,
line_lines: bool = false,
theme: theme.Theme,
window: sunset.client.Window,
new := fn(): Self {
sunset.client.find_server()
window_width := 800
window_height := 400
window := sunset.client.new(.(.(60, 40), .(window_width, window_height), "Adit"))
if window == null {
// log.error("got no window")
die
}
return Self.(null, assets.Assets.new() true, .(.(0x88, 0xF4, 0xFC, 0x0), render.YELLOW, render.BLACK, 10), window)
}
clear := fn(self:Self):void{
self.window.surface.clear(self.theme.bg_color)
}
frame_sync := fn(self: Self):void {
// +++ Frame Sync +++
_ = sunset.client.send_frame(self.window)
}
theme_render := fn(self: Self): void {
window_width := 800
window_height := 400
line_end := 20
if self.line_lines {
line := 1
loop {
defer line += 1
if line == line_end break
// TODO: Handle line text lining up
self.window.surface.put_hline(20 * line, 10, window_width - self.theme.padding, self.theme.bg_line_color)
}
}
}
map_keys := fn(scancode: u8): u8 {
// if is_shift_pressed {
// return ps2_table[scancode + 0x40]
// }
return ps2_table[scancode]
}
}
ps2_table := u8.[0x0, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35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,71 @@
/*!! expected result: pretty decent notepad app
-----------------
features:
- basic keys
- holding support with DAS
- visible cursor
- l+r arrow key support
- proper insertion and deletion
- shift key support
*/
stn := @use("stn");
.{memory, log, string, math} := stn;
.{Vec2, clamp} := math
sunset := @use("lib:sunset_proto")
render := @use("lib:render")
horizon_api := @use("lib:horizon_api");
.{set_color, render_label_to_surface, Label} := horizon_api.widgets.label
rope := @use("rope.hb")
theme := @use("theme.hb");
.{Theme} := theme
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
img := @embed("sysdata:assets/wallpaper.qoi");
.{Editor} := @use("editor.hb")
main := fn(): void {
window_width := 800
window_height := 400
editor := Editor.new()
font := render.text.font_from_psf2(@bitcast(&psf), false)
if font == null {
return
}
text_1_label := Label.new_label("main := fn() : void {", window_width - editor.theme.padding)
text_2_label := Label.new_label(" log.error(\"print!\")", window_width - editor.theme.padding)
text_3_label := Label.new_label("}", window_width)
text_1_label.set_color(editor.theme.bg_color, editor.theme.fg_text_color)
text_2_label.set_color(editor.theme.bg_color, editor.theme.fg_text_color)
text_3_label.set_color(editor.theme.bg_color, editor.theme.fg_text_color)
pos_1 := Vec2(uint).(10, 1)
pos_2 := Vec2(uint).(10, 1 + 20)
pos_3 := Vec2(uint).(10, 1 + 40)
line_end := 20
editor.window.surface.clear(editor.theme.bg_color)
render_label_to_surface(editor.window.surface, text_1_label, font, pos_1)
render_label_to_surface(editor.window.surface, text_2_label, font, pos_2)
render_label_to_surface(editor.window.surface, text_3_label, font, pos_3)
loop {
// +++ Clear +++
editor.clear()
// +++ Input +++
input := memory.inb(96)
// +++ RENDER +++
if editor.line_lines editor.theme_render()
// window.surface.clear(bg_color)
editor.frame_sync()
}
}

View file

@ -0,0 +1,243 @@
.{memory, log, string, math} := @use("stn")
render := @use("lib:render")
/* expected result: pretty decent notepad app
slightly jank
-----------------
features:
- basic keys
- holding support with DAS
- visible cursor
- l+r arrow key support
- proper insertion and deletion
- shift key support
*/
psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
img := @embed("sysdata:assets/wallpaper.qoi")
is_shift_pressed := false
is_ctrl_pressed := false
is_extended := false
$initial_delay := 50
$repeat_delay := 7
$left_arrow := 0x4B
$right_arrow := 0x4D
$up_arrow := 0x48
$down_arrow := 0x50
example := fn(): void {
screen := render.init(true)
window := render.Surface.new(600, 300)
font := render.text.font_from_psf2(@bitcast(&psf), false)
wallpaper := render.image.from(@bitcast(&img))
if font == null {
return
}
if wallpaper == null {
return
}
msg := "sticky note:\n"
msg_len := string.length(msg)
buf := memory.alloc(u8, 4096)
bottom := buf + msg_len
memory.copy(u8, msg, buf, msg_len)
cursor := bottom
draw_window(window, font, buf, cursor)
draw_screen(screen, window, wallpaper)
memory.outb(96, 238)
memory.outb(96, 238)
memory.outb(96, 244)
prev_input := @as(u8, 0xFF)
current_key := @as(u8, 0)
holding_timer := 0
loop {
input := memory.inb(96)
if input != prev_input {
if input == 0xE0 {
is_extended = true
} else {
if (input & 0x80) != 0 {
if (input & 0x7F) == current_key {
current_key = 0
holding_timer = 0
} else if input == 0xAA | input == 0xB6 {
is_shift_pressed = false
} else if input == 0x9D {
is_ctrl_pressed = false
}
is_extended = false
} else {
if is_extended {
current_key = input
holding_timer = 1
cursor = handle_extended_key(input, cursor, bottom, font)
} else {
if input == 0x2A | input == 0x36 {
is_shift_pressed = true
} else if input == 0x1D {
is_ctrl_pressed = true
} else {
current_key = input
holding_timer = 1
cursor = handle_char(map_keys(current_key), cursor, bottom)
}
}
}
}
prev_input = input
}
if current_key != 0 & holding_timer > 0 {
holding_timer += 1
if holding_timer >= initial_delay {
if is_extended {
cursor = handle_extended_key(current_key, cursor, bottom, font)
} else {
cursor = handle_char(map_keys(current_key), cursor, bottom)
}
holding_timer = initial_delay - repeat_delay
}
}
draw_window(window, font, buf, cursor)
draw_screen(screen, window, wallpaper)
if holding_timer > 0 & current_key != 0 {
if (memory.inb(96) & 0x80) != 0 {
current_key = 0
holding_timer = 0
}
}
}
}
handle_extended_key := fn(scancode: u8, cursor: ^u8, bottom: ^u8, font: render.text.Font): ^u8 {
if scancode == left_arrow {
if cursor > bottom {
return cursor - 1
}
} else if scancode == right_arrow {
if *cursor != 0 {
return cursor + 1
}
}
return cursor
}
padding := 3 * @sizeof(render.Color)
draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8, cursor: ^u8): void {
window.clear(.(0x88, 0xF4, 0xFC, 0x0))
line := font.height + padding - 1
window.put_rect(.(0, 0), .(window.width - 1, window.height - 1), render.BLACK)
loop if line >= window.height break else {
window.put_hline(line, padding, window.width - padding, render.YELLOW)
line += font.height
}
window.put_text(font, .(padding, padding), render.BLACK, buf)
cursor_offset := cursor - buf
y_pos := padding
x_pos := padding
i := 0
loop if i >= cursor_offset break else {
if *(buf + i) == 10 {
y_pos += font.height + font.line_gap
x_pos = padding
} else {
if x_pos + font.width >= window.width - padding {
y_pos += font.height + font.line_gap
x_pos = padding - font.width
}
x_pos += font.width
}
i += 1
}
window.put_rect(.(x_pos, y_pos), .(1, font.height - 1), render.BLACK)
}
draw_screen := fn(screen: render.Surface, window: render.Surface, wallpaper: render.Surface): void {
screen.put_surface(wallpaper, .(0, 0), false)
screen.put_surface(window, .(100, 100), false)
screen.sync()
}
handle_char := fn(char: u8, cursor: ^u8, bottom: ^u8): ^u8 {
if char == 0 {
return cursor
}
if is_ctrl_pressed & char == 48 {
cursor = bottom
} else if char != 0x8 {
end := cursor
loop if *end == 0 break else {
end += 1
}
if cursor < end {
src := end
dst := end + 1
loop if src < cursor break else {
*dst = *src
dst -= 1
src -= 1
}
};
*cursor = char
return cursor + 1
} else if char == 0xA {
*cursor = 32
cursor += 1;
*cursor = 92
return cursor + 1
} else if cursor > bottom {
if cursor == bottom {
return cursor
}
end := cursor
loop if *end == 0 break else {
end += 1
}
if cursor < end {
src := cursor
dst := cursor - 1
loop if src > end break else {
*dst = *src
dst += 1
src += 1
}
return cursor - 1
} else {
cursor -= 1;
*cursor = 32
return cursor
}
}
return cursor
}
map_keys := fn(scancode: u8): u8 {
if is_shift_pressed {
return ps2_table[scancode + 0x40]
}
return ps2_table[scancode]
}
ps2_table := u8.[0x0, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x8, 0x9, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0xA, 0x0, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B, 0x27, 0x60, 0x0, 0x5C, 0x7A, 0x78, 0x63, 0x76, 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x0, 0x2A, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x8, 0x9, 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0xA, 0x0, 0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A, 0x22, 0x7E, 0x0, 0x7C, 0x5A, 0x58, 0x43, 0x56, 0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x0, 0x0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

View file

@ -0,0 +1,29 @@
Node := struct {
weight: uint,
left: ?^Leaf,
right: ?^Leaf,
}
Leaf := struct {
buf: []u8,
start: uint,
end: uint,
new := fn(str: []u8): Self {
return Self.(str, 0, str.len)
}
weight := fn(self: Self): uint {
return self.end - self.start + 1
}
}
Rope := struct {
node: ?^Node,
leaf: ?^Leaf,
new := fn(str: []u8): Self {
leaf := Leaf.new(str)
return Self.(null, &leaf)
}
}

View file

@ -0,0 +1,8 @@
render := @use("lib:render")
Theme := struct {
bg_color: render.Color = render.Color.(0x88, 0xF4, 0xFC, 0x0),
bg_line_color: render.Color = render.YELLOW,
fg_text_color: render.Color = render.BLACK,
padding: uint = 10,
}

View file

@ -1 +1 @@
.{example: main} := @use("./examples/drag-and-drop.hb")
.{example: main} := @use("./examples/intouch.hb")

View file

@ -26,13 +26,13 @@ Mouse := struct {
return Self.(@bitcast(center_x), @bitcast(center_y), 3, max_x, max_y)
}
/*
center := fn(self: Self){
center_x := max_x / 2
center_y := max_y / 2
return Self.(center_x, center_y, 3, max_x, max_y)
}*/
// center := fn(self: Self): Self {
// center_x := self.max_x / 2
// center_y := self.max_y / 2
// return Self.(center_x, center_y, 3, self.max_x, self.max_y)
// }
}
main := fn(): int {
@ -55,7 +55,7 @@ main := fn(): int {
// mouse_y := 100
mouse := Mouse.new(screen.width, screen.height)
//mouse.center()
// mouse.center()
text_label := Label.new_label("", 1024)
text_label.set_color(sunset.server.DECO_COLOUR, render.BLACK)

View file

@ -41,11 +41,11 @@ path = "boot:///ps2_mouse_driver.hbf"
# [boot.limine.ableos.modules.sunset_client]
# path = "boot:///sunset_client.hbf"
# [boot.limine.ableos.modules.sdoom]
# path = "boot:///sdoom.hbf"
[boot.limine.ableos.modules.adit]
path = "boot:///adit.hbf"
[boot.limine.ableos.modules.sketchpad]
path = "boot:///sketchpad.hbf"
# [boot.limine.ableos.modules.sketchpad]
# path = "boot:///sketchpad.hbf"
# [boot.limine.ableos.modules.angels_halo]
# path = "boot:///angels_halo.hbf"