1
0
Fork 0
forked from AbleOS/ableos

make surface example cooler

This commit is contained in:
koniifer 2024-10-17 15:31:42 +01:00
parent 34101d2e8c
commit 7caa47b9fb
5 changed files with 58 additions and 49 deletions

View file

@ -1,4 +1,3 @@
.{memory} := @use("../../stn/src/lib.hb")
software := @use("software.hb")
image := @use("image.hb")
@ -7,34 +6,11 @@ mode := software
init := mode.init
doublebuffer := mode.doublebuffer
Surface := struct {
buf: ^Color,
width: int,
height: int,
}
new_surface := fn(width: int, height: int): Surface {
return .(
@inline(memory.alloc, Color, width * height * @bitcast(@sizeof(Color))),
width,
height,
)
}
surface_from_ptr := fn(ptr: ^Color, width: int, height: int): 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))
return new
}
Surface := mode.Surface
new_surface := mode.new_surface
surface_from_ptr := mode.surface_from_ptr
clone_surface := mode.clone_surface
free_surface := mode.free_surface
// Colours
Color := packed struct {b: u8, g: u8, r: u8, a: u8}
@ -68,10 +44,4 @@ put_vline := mode.put_vline
put_hline := mode.put_hline
// Display
// width := mode.width
// height := mode.height
// dimensions := mode.dimensions
// set_height := mode.set_height
// set_width := mode.set_width
// set_dimensions := mode.set_dimensions
sync := mode.sync

View file

@ -1,14 +1,47 @@
.{math, memory, dt} := @use("../../stn/src/lib.hb");
.{Color, Surface, new_surface} := @use("lib.hb");
.{Color} := @use("lib.hb");
.{Vec2} := math
Surface := struct {
buf: ^Color,
width: int,
height: int,
}
new_surface := fn(width: int, height: int): Surface {
return .(
@inline(memory.alloc, Color, width * height),
width,
height,
)
}
surface_from_ptr := fn(ptr: ^Color, width: int, height: int): 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))
return new
}
free_surface := fn(surface: ^Surface): void {
// todo
return
}
framebuffer := @as(^Color, idk)
init := fn(double_buffer: bool): Surface {
init := fn(doublebuffer: bool): Surface {
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
width := dt.get(int, "framebuffer/fb0/width\0")
height := dt.get(int, "framebuffer/fb0/height\0")
if double_buffer {
if doublebuffer {
return new_surface(width, height)
} else {
return .(framebuffer, width, height)

View file

@ -1,8 +1,8 @@
PAGE_SIZE := 4096
MAX_ALLOC := 0xFF
alloc := fn($Expr: type, bytes: int): ^Expr {
pages := 1 + bytes / PAGE_SIZE
alloc := fn($Expr: type, num: int): ^Expr {
pages := 1 + @bitcast(@sizeof(Expr)) * num / PAGE_SIZE
if pages <= MAX_ALLOC {
return @bitcast(@inline(request_page, pages))
}
@ -19,6 +19,11 @@ alloc := fn($Expr: type, bytes: int): ^Expr {
return @bitcast(ptr)
}
free := fn($Expr: type, ptr: ^Expr, num: int): void {
// todo
return
}
request_page := fn(page_count: u8): ^u8 {
msg := "\{00}\{01}xxxxxxxx\0"
msg_page_count := msg + 1;

View file

@ -16,13 +16,14 @@ example := fn(): void {
pos_inner := Vec2(int).((image.width - side) / 2, (image.height - side) / 2)
color := random.range(render.Color, render.black, render.white)
loop {
render.clear(image, render.black)
render.clear(screen, render.black)
// color += .(1, 1, 1, 1)
render.put_filled_rect(image, pos_inner, .(side, side), color)
render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), render.white)
render.put_rect(image, pos_inner, .(side, side), render.black)
render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), color)
render.put_surface(screen, image, pos)
render.put_rect(image, pos_inner, .(side, side), color)
render.sync(screen)
if pos_inner.x == 0 | pos_inner.x == image.width - side {

View file

@ -31,17 +31,17 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///diskio_driver.hbf"
# [boot.limine.ableos.modules.render_example]
# path = "boot:///render_example.hbf"
[boot.limine.ableos.modules.render_example]
path = "boot:///render_example.hbf"
# [boot.limine.ableos.modules.serial_driver_test]
# path = "boot:///serial_driver_test.hbf"
[boot.limine.ableos.modules.horizon]
path = "boot:///horizon.hbf"
# [boot.limine.ableos.modules.horizon]
# path = "boot:///horizon.hbf"
[boot.limine.ableos.modules.horizon_testing_program]
path = "boot:///horizon_testing_program.hbf"
# [boot.limine.ableos.modules.horizon_testing_program]
# path = "boot:///horizon_testing_program.hbf"
# [boot.limine.ableos.modules.dt_buffer_test]
# path = "boot:///dt_buffer_test.hbf"