1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
koniifer 2024-11-10 10:09:02 +00:00
parent eea23d967b
commit 68d3236cc0
6 changed files with 42 additions and 44 deletions

6
Cargo.lock generated
View file

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

View file

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

File diff suppressed because one or more lines are too long

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

View file

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