1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
peony 2024-11-10 12:54:02 +01:00
commit 388d8c8c20
15 changed files with 187 additions and 175 deletions

View file

@ -1,3 +1,3 @@
[alias]
repbuild = "run --manifest-path ./repbuild/Cargo.toml -r -- "
repbuild = "run --manifest-path ./repbuild/Cargo.toml -- "
dev = "run --manifest-path ./dev/Cargo.toml -r --"

6
Cargo.lock generated
View file

@ -228,12 +228,12 @@ dependencies = [
[[package]]
name = "hbbytecode"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#29a23cec0c831f9ace29d847b5356b932868508c"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248"
[[package]]
name = "hblang"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#29a23cec0c831f9ace29d847b5356b932868508c"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248"
dependencies = [
"hashbrown 0.15.1",
"hbbytecode",
@ -245,7 +245,7 @@ dependencies = [
[[package]]
name = "hbvm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#29a23cec0c831f9ace29d847b5356b932868508c"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248"
dependencies = [
"hbbytecode",
]

View file

@ -31,7 +31,7 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V
}
new_label := fn(text: ^u8): Label {
text_surface := render.new_surface(1000, 20)
text_surface := render.new_surface(1024, 20)
text_length := string.length(text)
label := Label.(3, true, text_surface, text, text_length)
return label

View file

@ -11,12 +11,12 @@ KeyEvent := struct {
key: KeyCode,
}
MouseEvent := struct {
MouseEvent := packed struct {
x_change: i8,
y_change: i8,
left: u8,
middle: u8,
right: u8,
left: bool,
middle: bool,
right: bool,
}
GamepadEvent := struct {}

View file

@ -6,34 +6,20 @@ events := @use("events.hb");
.{KeyEvent, MouseEvent} := events
recieve_key_event := fn(): ?KeyEvent {
mem_page := memory.request_page(1)
buf_id := buffer.search("PS/2 Keyboard\0")
// Read out of the keyboard buffer here
buffer.recv(KeyEvent, buf_id, mem_page)
key_event := KeyEvent.(0, 0, 2)
// return key_event
// return null
return null
}
recieve_mouse_event := fn(): ?MouseEvent {
mem_page := memory.request_page(1)
mevent := MouseEvent.(0, 0, false, false, false)
buf_id := buffer.search("PS/2 Mouse\0")
// Read out of the Mouse buffer here
buffer.recv(MouseEvent, buf_id, mem_page)
if *mem_page != 0 {
log.info("Mouse events\0")
dx := @as(i8, @bitcast(*mem_page))
dy := @as(i8, @bitcast(*(mem_page + 1)))
mevent := MouseEvent.(dx, dy, 0, 0, 0)
buffer.recv(MouseEvent, buf_id, @bitcast(&mevent))
if mevent.x_change != 0 | mevent.y_change != 0 | mevent.left | mevent.middle | mevent.right {
return mevent
}
// log.error("No mouse events\0")
return MouseEvent.(0, 0, 0, 0, 0)
return null
}

View file

@ -35,17 +35,14 @@ BitmapColorHeader := packed struct {
from := fn(bmp: ^u8): ?Surface {
file_header := @as(^BitmapFileHeader, @bitcast(bmp))
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
bmp += file_header.offset
if file_header.magic != 0x4D42 | info_header.width == 0 | info_header.height == 0 {
log.error("Invalid BMP image.\0")
return null
}
width := @as(uint, info_header.width)
height := @as(uint, info_header.height)
lhs := Surface.(@bitcast(bmp), width, height)
rhs := new_surface(width, height)
lhs := Surface.(@bitcast(bmp + file_header.offset), info_header.width, info_header.height)
rhs := new_surface(info_header.width, info_header.height)
put_surface(rhs, lhs, .(0, 0), true)
return rhs

View file

@ -2,26 +2,23 @@
.{Surface} := @use("../lib.hb")
bmp := @use("bmp.hb")
qoi := @use("qoi.hb")
$BMP := 0x4D42
$QOI := 0x66696F71
BMP := 0x4D42
QOI := 0x66696F71
// stand-in for null until bugfix
DOES_NOT_EXIST := 1 << 32
get_format := fn(file: ^u8): uint {
get_format := fn(file: ^u8): ?uint {
if *@as(^u16, @bitcast(file)) == BMP {
return BMP
} else if *@as(^u32, @bitcast(file)) == QOI {
return QOI
} else {
return DOES_NOT_EXIST
return null
}
}
from := fn(file: ^u8): ?Surface {
format := get_format(file)
if format == DOES_NOT_EXIST {
if format == null {
log.error("Could not detect image format.\0")
return null
} else if format == BMP {

View file

@ -28,7 +28,7 @@ QuiteOkayHeader := packed struct {
}
be_to_le := fn(big: u32): u32 {
return (big & 0xFF000000) >> 24 | (big & 0xFF0000) >> 8 | (big & 0xFF00) << 8 | (big & 0xFF) << 24
return big >> 24 | big >> 8 & 0xFF00 | big << 8 & 0xFF0000 | big << 24
}
from := fn(qoi: ^u8): ?Surface {

View file

@ -20,14 +20,6 @@ new_surface := fn(width: uint, height: uint): Surface {
)
}
surface_from_ptr := fn(ptr: ^Color, width: uint, height: uint): Surface {
return .(
ptr,
width,
height,
)
}
clone_surface := fn(surface: ^Surface): Surface {
new := new_surface(surface.width, surface.height)
@inline(memory.copy, Color, surface.buf, new.buf, @intcast(surface.width * surface.height))
@ -103,9 +95,8 @@ put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color:
rows_to_fill := tr.y
loop if rows_to_fill <= 1 break else {
// inline is broked
memory.set(Color, &color, top_start_idx, @bitcast(tr.x))
memory.set(Color, &color, bottom_start_idx, @bitcast(tr.x))
@inline(memory.set, Color, &color, top_start_idx, tr.x)
@inline(memory.set, Color, &color, bottom_start_idx, tr.x)
top_start_idx += surface.width
bottom_start_idx -= surface.width
@ -113,7 +104,7 @@ put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color:
}
if rows_to_fill == 1 {
@inline(memory.set, Color, &color, top_start_idx, @bitcast(tr.x))
@inline(memory.set, Color, &color, top_start_idx, tr.x)
}
return
@ -203,25 +194,31 @@ put_line := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color):
}
put_surface := fn(surface: Surface, top: Surface, pos: Vec2(uint), flip_v: bool): void {
top_start_idx := @inline(indexptr, surface, pos.x, pos.y)
bottom_start_idx := @inline(indexptr, surface, pos.x, pos.y + top.height - 1)
rows_to_copy := top.height
top_cursor := top.buf
bottom_cursor := top.buf + top.width * (top.height - 1)
src_top_cursor := top.buf
src_bottom_cursor := top.buf + top.width * (top.height - 1)
dst_top_idx := @inline(indexptr, surface, pos.x, pos.y)
dst_bottom_idx := @inline(indexptr, surface, pos.x, pos.y + top.height - 1)
dst_increment := surface.width
loop if rows_to_copy <= 1 break else {
if flip_v {
@inline(memory.copy, Color, top_cursor, bottom_start_idx, @bitcast(top.width))
@inline(memory.copy, Color, bottom_cursor, top_start_idx, @bitcast(top.width))
} else {
@inline(memory.copy, Color, top_cursor, top_start_idx, @bitcast(top.width))
@inline(memory.copy, Color, bottom_cursor, bottom_start_idx, @bitcast(top.width))
dst_increment = -dst_increment
tmp := dst_top_idx
dst_top_idx = dst_bottom_idx
dst_bottom_idx = tmp
}
top_start_idx += surface.width
bottom_start_idx -= surface.width
top_cursor += top.width
bottom_cursor -= top.width
rows_to_copy := top.height
loop if rows_to_copy <= 1 break else {
@inline(memory.copy, Color, src_top_cursor, dst_top_idx, top.width)
@inline(memory.copy, Color, src_bottom_cursor, dst_bottom_idx, top.width)
dst_top_idx += dst_increment
dst_bottom_idx -= dst_increment
src_top_cursor += top.width
src_bottom_cursor -= top.width
rows_to_copy -= 2
}
@ -439,123 +436,134 @@ put_textured_circle := fn(surface: Surface, source: Surface, source_pos: Vec2(ui
put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str: ^u8): void {
cursor := Vec2(uint).(pos.x, pos.y)
current_char := str
loop if *current_char == 0 break else {
glyph_data := memory.dangling(u8)
max_y := surface.height - font.height
next_line_y := font.height + font.line_gap
char_advance := font.width + font.char_gap
surface_width := surface.width
if font.unicode != null {
loop if *str == 0 break else {
if cursor.y > max_y break
glyph_data := @as(^u8, idk)
code_point := @as(uint, 0)
first_byte := *current_char
num_bytes := 1
if (first_byte & 0x80) == 0 {
code_point = first_byte
} else if (first_byte & 0xE0) == 0xC0 {
num_bytes = 2
code_point = first_byte & 0x1F
} else if (first_byte & 0xF0) == 0xE0 {
num_bytes = 3
code_point = first_byte & 0xF
} else if (first_byte & 0xF8) == 0xF0 {
// handle later
current_char += 1
continue
} else {
current_char += 1
if (*str & 0x80) == 0 {
if *str == 10 {
cursor.x = pos.x
cursor.y += next_line_y
str += 1
continue
}
if font.unicode == null {
if *str > font.num_glyphs {
str += 1
continue
}
glyph_data = @inline(get_glyph, font, *str)
} else {
if *str < UNC_TABLE_SIZE {
glyph_index := *(font.unicode + *str)
if glyph_index == 0xFFFF {
str += 1
continue
}
glyph_data = font.data + glyph_index * font.bytes_per_glyph
} else {
str += 1
continue
}
}
str += 1
} else if font.unicode != null {
first_byte := *str
num_bytes := @as(uint, 0)
num_bytes = utf8_len_table[first_byte >> 5 & 0x3]
if num_bytes == 0 {
str += 1
continue
}
code_point = first_byte & (0x7F >> num_bytes | 0x1F)
valid_sequence := true
i := 1
loop if i >= num_bytes break else {
current_char += 1
// have to check twice due to odd compiler bug...?
if *current_char == 0 | (*current_char & 0xC0) != 0x80 {
bytes_processed := 1
loop if bytes_processed >= num_bytes break else {
str += 1
if *str == 0 | (*str & 0xC0) != 0x80 {
valid_sequence = false
}
if valid_sequence == false {
break
}
code_point = code_point << 6 | *current_char & 0x3F
i += 1
code_point = code_point << 6 | *str & 0x3F
bytes_processed += 1
}
if valid_sequence == false {
current_char += 1
str += 1
continue
}
current_char += 1
str += 1
if code_point == 10 {
cursor.x = pos.x
cursor.y += font.height + font.line_gap
cursor.y += next_line_y
continue
}
if code_point < UNC_TABLE_SIZE {
glyph_index := *(font.unicode + code_point)
if code_point >= UNC_TABLE_SIZE {
continue
}
glyph_index := *(font.unicode + code_point)
if glyph_index == 0xFFFF {
continue
}
glyph_data = font.data + glyph_index * font.bytes_per_glyph
} else {
continue
}
} else {
if *current_char > font.num_glyphs {
continue
}
glyph_data = @inline(get_glyph, font, *current_char)
if *current_char == 10 {
cursor.x = pos.x
cursor.y += font.height + font.line_gap
current_char += 1
continue
}
current_char += 1
}
if cursor.y + font.height > surface.height break
if cursor.x % surface.width + font.width >= surface.width {
if cursor.x + font.width >= surface_width {
cursor.x = pos.x
cursor.y += font.height + font.line_gap
cursor.y += next_line_y
}
dest := @inline(indexptr, surface, cursor.x, cursor.y)
rows_remaining := font.height
rows := font.height
loop if rows_remaining == 0 break else {
loop if rows == 0 break else {
byte := *glyph_data
pixel_dest := dest
mask := @as(u8, 0x80)
bits_remaining := font.width
bits := font.width
loop if bits_remaining == 0 break else {
loop if bits == 0 break else {
if (byte & mask) != 0 {
*pixel_dest = color
}
pixel_dest += 1
mask >>= 1
if mask == 0 & bits_remaining > 0 {
if mask == 0 & bits > 0 {
glyph_data += 1
byte = *glyph_data
mask = 0x80
}
bits_remaining -= 1
bits -= 1
}
if mask != 0x80 {
glyph_data += 1
}
dest += surface.width
rows_remaining -= 1
dest += surface_width
rows -= 1
}
cursor.x += font.width + font.char_gap
cursor.x += char_advance
}
return

File diff suppressed because one or more lines are too long

View file

@ -89,8 +89,7 @@ main := fn(): int {
// TODO: Get windows out of a collection and iter through
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
{
if false {
// Scroll bar :ThumbsUp:
render.put_rect(screen, .(100, 100), .(100, 10), render.white)
render.put_filled_rect(screen, .(110, 100), .(20, 10), render.white)
@ -102,6 +101,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)
}
{
@ -135,8 +135,17 @@ main := fn(): int {
}
mouse_y -= change_y
set_label_text(text_label, "Mouse Moved\0")
if mouse_event.left {
set_label_text(text_label, "LEFT CLICK\0")
} else if mouse_event.middle {
set_label_text(text_label, "MIDDLE CLICK\0")
} else if mouse_event.right {
set_label_text(text_label, "RIGHT CLICK\0")
}
}
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
// render mouse
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white)
// Send events to focused window

View file

@ -118,17 +118,32 @@ main := fn(): int {
set_up_mouse()
continue
}
event := MouseEvent.(0, 0, false, false, false)
changes := button_states ^ status & 7
if (changes & LeftButton.id) != 0 {
button_event(LeftButton, (status & LeftButton.id) != 0)
if (status & LeftButton.id) != 0 {
event.left = true
} else {
event.left = false
}
if (changes & RightButton.id) != 0 {
button_event(RightButton, (status & RightButton.id) != 0)
}
if (changes & MiddleButton.id) != 0 {
button_event(MiddleButton, (status & MiddleButton.id) != 0)
if (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
}
}
button_states ^= changes
@ -145,7 +160,6 @@ main := fn(): int {
y_change := @as(i8, @bitcast(dy.value))
x_change := @as(i8, @bitcast(dx.value))
event := MouseEvent.(0, 0, 0, 0, 0)
event.x_change = x_change
event.y_change = y_change

View file

@ -1,29 +1,26 @@
.{log} := @use("../../../../libraries/stn/src/lib.hb")
.{log, math, string} := @use("../../../../libraries/stn/src/lib.hb")
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result:
a cute qoi image and a cute bmp image */
qoi := @embed("./assets/mini.qoi")
bmp := @embed("./assets/mini.bmp")
example := fn(): void {
screen := render.init(true)
image_qoi := render.image.from(@bitcast(&qoi))
image_bmp := render.image.from(@bitcast(&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 {
log.error("failed to load qoi image for whatever reason\0")
return
}
if image_bmp == null {
log.error("failed to load bmp image for whatever reason\0")
if image_qoi == null | image_bmp == null {
log.error("failed to load images for whatever reason\0")
return
}
t := 0.0
loop {
render.clear(screen, render.black)
render.put_surface(screen, image_bmp, .((screen.width - image_bmp.width * 3) / 2, (screen.height - image_bmp.height) / 2), false)
render.put_surface(screen, image_qoi, .((screen.width + image_qoi.width) / 2, (screen.height - image_qoi.height) / 2), false)
render.put_surface(screen, image_bmp, .(@bitcast(@fti(math.cos(t) * 100.0)) + (screen.width - image_bmp.width * 3) / 2, (screen.height - image_bmp.height) / 2), false)
render.put_surface(screen, image_qoi, .((screen.width + image_qoi.width) / 2, @bitcast(@fti(math.sin(t) * 100.0)) + (screen.height - image_qoi.height) / 2), false)
render.sync(screen)
t += 0.02
}
return
}

View file

@ -14,6 +14,7 @@ render := @use("../../../../libraries/render/src/lib.hb")
*/
psf := @embed("../../../../consolefonts/tamsyn/10x20r.psf")
img := @embed("./assets/wallpaper.qoi")
is_shift_pressed := false
is_ctrl_pressed := false
@ -29,10 +30,14 @@ example := fn(): void {
screen := render.init(true)
window := render.new_surface(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\0"
msg_len := string.length(msg)
@ -45,7 +50,7 @@ example := fn(): void {
cursor := bottom
draw_window(window, font, buf, cursor)
draw_screen(screen, window)
draw_screen(screen, window, wallpaper)
memory.outb(96, 238)
memory.outb(96, 238)
@ -105,7 +110,7 @@ example := fn(): void {
}
}
draw_window(window, font, buf, cursor)
draw_screen(screen, window)
draw_screen(screen, window, wallpaper)
if holding_timer > 0 & current_key != 0 {
if (memory.inb(96) & 0x80) != 0 {
@ -132,7 +137,7 @@ handle_extended_key := fn(scancode: u8, cursor: ^u8, bottom: ^u8, font: render.t
padding := 3 * @sizeof(render.Color)
draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8, cursor: ^u8): void {
render.clear(window, render.light_yellow)
render.clear(window, .(0x88, 0xF4, 0xFC, 0x0))
line := font.height + padding - 1
render.put_rect(window, .(0, 0), .(window.width - 1, window.height - 1), render.black)
@ -166,8 +171,8 @@ draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8, curs
render.put_rect(window, .(x_pos, y_pos), .(1, font.height - 1), render.black)
}
draw_screen := fn(screen: render.Surface, window: render.Surface): void {
render.clear(screen, render.light_blue)
draw_screen := fn(screen: render.Surface, window: render.Surface, wallpaper: render.Surface): void {
render.put_surface(screen, wallpaper, .(0, 0), false)
render.put_surface(screen, window, .(100, 100), false)
render.sync(screen)
}