1
0
Fork 0
forked from AbleOS/ableos

various stn & render-api changes

This commit is contained in:
koniifer 2024-10-12 21:39:09 +01:00
parent 7f4a040505
commit ea8eca1089
15 changed files with 91 additions and 76 deletions

6
Cargo.lock generated
View file

@ -350,12 +350,12 @@ checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
[[package]] [[package]]
name = "hbbytecode" name = "hbbytecode"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c4826d3bfdc2def022fc7e80c6d5fe86df4e1c95" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a"
[[package]] [[package]]
name = "hblang" name = "hblang"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#c4826d3bfdc2def022fc7e80c6d5fe86df4e1c95" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a"
dependencies = [ dependencies = [
"hashbrown 0.15.0", "hashbrown 0.15.0",
"hbbytecode", "hbbytecode",
@ -367,7 +367,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#c4826d3bfdc2def022fc7e80c6d5fe86df4e1c95" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#6d7e726066109e8b08f049bbc4684bba2a2eb88a"
dependencies = [ dependencies = [
"hbbytecode", "hbbytecode",
] ]

View file

@ -66,4 +66,4 @@
- Submit an issue [here](https://git.ablecorp.us/ableos/ableos/issues) or report it in the [discord](https://discord.gg/t5Wt3K4YNA) - Submit an issue [here](https://git.ablecorp.us/ableos/ableos/issues) or report it in the [discord](https://discord.gg/t5Wt3K4YNA)
### How do I report a compiler bug? ### How do I report a compiler bug?
- Submit an issue [here](https://git.ablecorp.us/ableos/holeybytes/issues) or report it in the [discord](https://discord.gg/t5Wt3K4YNA) - Submit an issue [here](https://git.ablecorp.us/ableos/holey-bytes/issues) or report it in the [discord](https://discord.gg/t5Wt3K4YNA)

View file

@ -13,14 +13,17 @@ use {
}; };
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[inline(always)]
unsafe fn x86_out<T: x86_64::instructions::port::PortWrite>(address: u16, value: T) { unsafe fn x86_out<T: x86_64::instructions::port::PortWrite>(address: u16, value: T) {
x86_64::instructions::port::Port::new(address).write(value); x86_64::instructions::port::Port::new(address).write(value);
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
#[inline(always)]
unsafe fn x86_in<T: x86_64::instructions::port::PortRead>(address: u16) -> T { unsafe fn x86_in<T: x86_64::instructions::port::PortRead>(address: u16) -> T {
x86_64::instructions::port::Port::new(address).read() x86_64::instructions::port::Port::new(address).read()
} }
#[inline(always)]
pub fn handler(vm: &mut Vm) { pub fn handler(vm: &mut Vm) {
let ecall_number = vm.registers[2].cast::<u64>(); let ecall_number = vm.registers[2].cast::<u64>();
// log::info!("eca called :pensive:"); // log::info!("eca called :pensive:");
@ -49,18 +52,15 @@ pub fn handler(vm: &mut Vm) {
let length = vm.registers[4].cast::<u64>(); let length = vm.registers[4].cast::<u64>();
let mut buffs = IPC_BUFFERS.lock(); let mut buffs = IPC_BUFFERS.lock();
let abc;
match bounded {
false => {
abc = IpcBuffer::new(false, 0);
}
true => {
abc = IpcBuffer::new(true, length);
}
};
let buff_id = arch::hardware_random_u64(); let buff_id = arch::hardware_random_u64();
buffs.insert(buff_id, abc); buffs.insert(
buff_id,
match bounded {
false => IpcBuffer::new(false, 0),
true => IpcBuffer::new(true, length),
},
);
info!("Buffer ID: {}", buff_id); info!("Buffer ID: {}", buff_id);
vm.registers[1] = hbvm::value::Value(buff_id); vm.registers[1] = hbvm::value::Value(buff_id);
} }
@ -145,15 +145,14 @@ pub fn handler(vm: &mut Vm) {
let mut buffs = IPC_BUFFERS.lock(); let mut buffs = IPC_BUFFERS.lock();
match buffs.get_mut(&buffer_id) { match buffs.get_mut(&buffer_id) {
Some(buff) => { Some(buff) => {
let msg_vec = block_read(mem_addr, length).to_vec(); let msg_vec = block_read(mem_addr, length);
debug!("Sending Message {:?} to Buffer({})", msg_vec, buffer_id); buff.push(msg_vec.to_vec());
buff.push(msg_vec); debug!("Sent Message {:?} to Buffer({})", msg_vec, buffer_id);
} }
None => { None => {
log::error!("Access of non-existent buffer {}", buffer_id) log::error!("Access of non-existent buffer {}", buffer_id)
} }
} }
drop(buffs);
} }
} }
} }

View file

@ -30,7 +30,7 @@ impl Memory {
} }
impl hbvm::mem::Memory for Memory { impl hbvm::mem::Memory for Memory {
#[inline] #[inline(always)]
unsafe fn load( unsafe fn load(
&mut self, &mut self,
addr: Address, addr: Address,
@ -42,7 +42,7 @@ impl hbvm::mem::Memory for Memory {
Ok(()) Ok(())
} }
#[inline] #[inline(always)]
unsafe fn store( unsafe fn store(
&mut self, &mut self,
addr: Address, addr: Address,
@ -53,7 +53,7 @@ impl hbvm::mem::Memory for Memory {
Ok(()) Ok(())
} }
#[inline] #[inline(always)]
unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T { unsafe fn prog_read<T: Copy>(&mut self, addr: Address) -> T {
(addr.get() as *const T).read() (addr.get() as *const T).read()
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 B

View file

@ -32,6 +32,7 @@ put_rect := mode.put_rect
put_filled_rect := mode.put_filled_rect put_filled_rect := mode.put_filled_rect
put_line := mode.put_line put_line := mode.put_line
clear := mode.clear clear := mode.clear
put_img := mode.put_img
// Display // Display
width := mode.width width := mode.width
@ -42,6 +43,8 @@ set_width := mode.set_width
set_dimensions := mode.set_dimensions set_dimensions := mode.set_dimensions
sync := mode.sync sync := mode.sync
// Math // Trash Image
UVec2 := struct {x: uint, y: uint} Image := struct {
IVec2 := struct {x: int, y: int} start: ^Color,
end: ^Color,
}

View file

@ -1,6 +1,7 @@
.{math, memory} := @use("../../stn/src/lib.hb"); .{math, memory} := @use("../../stn/src/lib.hb");
.{dt_get} := @use("../../dt_api/src/lib.hb"); .{dt_get} := @use("../../dt_api/src/lib.hb");
.{IVec2} := @use("lib.hb") .{Image} := @use("lib.hb");
.{Vec2} := math
Color := struct {b: u8, g: u8, r: u8, a: u8} Color := struct {b: u8, g: u8, r: u8, a: u8}
white := Color.(255, 255, 255, 255) white := Color.(255, 255, 255, 255)
@ -42,8 +43,6 @@ Context := struct {
init := fn(): void { init := fn(): void {
width := dt_get("framebuffer/fb0/width\0") width := dt_get("framebuffer/fb0/width\0")
height := dt_get("framebuffer/fb0/height\0") height := dt_get("framebuffer/fb0/height\0")
// width := 1024
// height := 768
pixels := width * height pixels := width * height
bytes := pixels << 2 bytes := pixels << 2
partitions := pixels / copy_pixels partitions := pixels / copy_pixels
@ -141,12 +140,12 @@ screenidx := fn(x: int, y: int): int {
return x + ctx.width * y return x + ctx.width * y
} }
put_pixel := fn(pos: IVec2, color: Color): void { put_pixel := fn(pos: Vec2(int), color: Color): void {
*(ctx.buf + @inline(screenidx, pos.x, pos.y)) = color *(ctx.buf + @inline(screenidx, pos.x, pos.y)) = color
return return
} }
put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
x := pos.x x := pos.x
y := pos.y y := pos.y
end := pos + tr end := pos + tr
@ -161,7 +160,7 @@ put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void {
return return
} }
put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
x := pos.x x := pos.x
y := pos.y y := pos.y
end := pos + tr end := pos + tr
@ -179,7 +178,7 @@ put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void {
return return
} }
put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void { put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
dx := p1.x - p0.x dx := p1.x - p0.x
dy := p1.y - p0.y dy := p1.y - p0.y
yi := 1 yi := 1
@ -203,7 +202,7 @@ put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void {
return return
} }
put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void { put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
dx := p1.x - p0.x dx := p1.x - p0.x
dy := p1.y - p0.y dy := p1.y - p0.y
xi := 1 xi := 1
@ -227,8 +226,8 @@ put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void {
return return
} }
put_line := fn(p0: IVec2, p1: IVec2, color: Color): void { put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
if @inline(math.abs, p1.y - p0.y) < @inline(math.abs, p1.x - p0.x) { if math.abs(int, p1.y - p0.y) < math.abs(int, p1.x - p0.x) {
if p0.x > p1.x { if p0.x > p1.x {
@inline(put_line_low, p1, p0, color) @inline(put_line_low, p1, p0, color)
} else { } else {
@ -252,10 +251,14 @@ set_width := fn(new: int): void {
return return
} }
dimensions := fn(): IVec2 { dimensions := fn(): Vec2(int) {
return .(ctx.width, ctx.height) return .(ctx.width, ctx.height)
} }
set_dimensions := fn(new: IVec2): void { set_dimensions := fn(new: Vec2(int)): void {
return
}
put_img := fn(img: Image, pos: Vec2(int)): void {
return return
} }

View file

@ -1,4 +1,4 @@
.{IVec2} := @use("lib.hb") .{Vec2, Image} := @use("lib.hb")
// .{pci, memory, string, log} := @use("../../stn/src/lib.hb"); // .{pci, memory, string, log} := @use("../../stn/src/lib.hb");
Color := struct {b: u8, g: u8, r: u8, a: u8} Color := struct {b: u8, g: u8, r: u8, a: u8}
@ -31,31 +31,31 @@ height := fn(): int {
return 0 return 0
} }
dimensions := fn(): IVec2 { dimensions := fn(): Vec2(int) {
return .(0, 0) return .(0, 0)
} }
put_pixel := fn(position: IVec2, color: Color): void { put_pixel := fn(position: Vec2(int), color: Color): void {
return return
} }
put_filled_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
return return
} }
put_rect := fn(pos: IVec2, tr: IVec2, color: Color): void { put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void {
return return
} }
put_line_low := fn(p0: IVec2, p1: IVec2, color: Color): void { put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return return
} }
// do not use, use line() instead // do not use, use line() instead
put_line_high := fn(p0: IVec2, p1: IVec2, color: Color): void { put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return return
} }
put_line := fn(p0: IVec2, p1: IVec2, color: Color): void { put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void {
return return
} }
@ -67,7 +67,7 @@ set_width := fn(new: int): void {
return return
} }
set_dimensions := fn(new: IVec2): void { set_dimensions := fn(new: Vec2(int)): void {
return return
} }
@ -78,3 +78,7 @@ sync := fn(): void {
init := fn(): void { init := fn(): void {
return return
} }
put_img := fn(img: Image, pos: Vec2(int)): void {
return
}

View file

@ -1,15 +1,16 @@
shift := 31 abs := fn($Expr: type, x: Expr): Expr {
mask := x >> @intcast(@sizeof(Expr) - 1)
// following only work for: int
abs := fn(x: int): int {
mask := x >> shift
return (x ^ mask) - mask return (x ^ mask) - mask
} }
min := fn(a: int, b: int): int { min := fn($Expr: type, a: Expr, b: Expr): Expr {
c := a - b c := a - b
return b + (c & c >> shift) return b + (c & c >> @intcast(@sizeof(Expr) - 1))
} }
max := fn(a: int, b: uint): int { max := fn($Expr: type, a: Expr, b: Expr): Expr {
c := a - b c := a - b
return a - (c & c >> shift) return a - (c & c >> @intcast(@sizeof(Expr) - 1))
}
Vec2 := fn($Expr: type): type {
return struct {x: Expr, y: Expr}
} }

View file

@ -1,7 +1,7 @@
integer := fn(): int { any := fn($Expr: type): Expr {
return @eca(3, 4) return @intcast(@eca(3, 4))
} }
integer_range := fn(min: int, max: int): int { range := fn($Expr: type, min: Expr, max: Expr): Expr {
return @eca(3, 4) % (max - min + 1) + min return @eca(3, 4) % (max - min + 1) + min
} }

View file

@ -1,3 +1,4 @@
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math
render := @use("../../../../libraries/render/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb")
/* expected result: /* expected result:
@ -9,8 +10,8 @@ example := fn(): void {
render.clear(.(100, 50, 0, 255)) render.clear(.(100, 50, 0, 255))
width := render.width() width := render.width()
height := render.height() height := render.height()
p0 := render.IVec2.(0, 0) p0 := Vec2(int).(0, 0)
p1 := render.IVec2.(0, height) p1 := Vec2(int).(0, height)
loop if p0.y >= height break else { loop if p0.y >= height break else {
render.put_line(p0, p1, .(255, 180, 100, 255)) render.put_line(p0, p1, .(255, 180, 100, 255))
render.put_line(.(width, height) - p0, .(width, height) - p1, .(255, 180, 100, 255)) render.put_line(.(width, height) - p0, .(width, height) - p1, .(255, 180, 100, 255))

View file

@ -6,11 +6,11 @@ example := fn(): void {
render.doublebuffer(false) render.doublebuffer(false)
render.clear(render.black) render.clear(render.black)
loop { loop {
x := random.integer_range(0, 1024) x := random.range(int, 0, 1024)
y := random.integer_range(0, 768) y := random.range(int, 0, 768)
r := random.integer_range(0, 255) r := random.range(int, 0, 255)
g := random.integer_range(0, 75) g := random.range(int, 0, 75)
b := random.integer_range(0, 155) b := random.range(int, 0, 155)
render.put_pixel(.(x, y), .(b, g, r, 255)) render.put_pixel(.(x, y), .(b, g, r, 255))
} }
return return

View file

@ -1,3 +1,4 @@
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math;
.{random} := @use("../../../../libraries/stn/src/lib.hb") .{random} := @use("../../../../libraries/stn/src/lib.hb")
render := @use("../../../../libraries/render/src/lib.hb") render := @use("../../../../libraries/render/src/lib.hb")
@ -6,11 +7,11 @@ render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void { example := fn(): void {
render.init() render.init()
vel := render.IVec2.(1, 1) vel := Vec2(int).(1, 1)
pos := render.IVec2.(100, 100) pos := Vec2(int).(100, 100)
width := render.width() width := render.width()
height := render.height() height := render.height()
color := @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
loop { loop {
render.put_filled_rect(pos, .(100, 100), color) render.put_filled_rect(pos, .(100, 100), color)
render.sync() render.sync()
@ -18,11 +19,11 @@ example := fn(): void {
if pos.x == 0 | pos.x == width - 100 { if pos.x == 0 | pos.x == width - 100 {
vel.x = -vel.x vel.x = -vel.x
color = @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
} }
if pos.y == 0 | pos.y == height - 100 { if pos.y == 0 | pos.y == height - 100 {
vel.y = -vel.y vel.y = -vel.y
color = @as(render.Color, @intcast(random.integer_range(0, 0xFFFFFF))) color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF)))
} }
pos += vel pos += vel

View file

@ -1,4 +1,4 @@
.{example} := @use("./examples/square.hb") .{example} := @use("./examples/amogus.hb")
main := fn(): void { main := fn(): void {
@inline(example) @inline(example)

View file

@ -4,8 +4,10 @@ default_entry = 1
timeout = 0 timeout = 0
verbose = false verbose = false
interface_resolution = "1024x768x24" interface_resolution = "1024x768x24"
# interface_resolution = "640x480x32"
# Terminal related settings # Terminal related settings
term_wallpaper = "boot:///background.bmp" term_wallpaper = "boot:///background.bmp"
# term_wallpaper = "boot:///empty-background.bmp"
term_background = "008080" term_background = "008080"
[boot.limine.ableos] [boot.limine.ableos]
@ -13,6 +15,7 @@ comment = "Default AbleOS boot entry."
protocol = "limine" protocol = "limine"
kernel_path = "boot:///kernel_${ARCH}" kernel_path = "boot:///kernel_${ARCH}"
kernel_cmdline = "" kernel_cmdline = ""
# resolution = "640x480x32"
resolution = "1024x768x24" resolution = "1024x768x24"
[boot.limine.ableos.modules] [boot.limine.ableos.modules]
@ -26,8 +29,8 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.diskio_driver] # [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///diskio_driver.hbf" # path = "boot:///diskio_driver.hbf"
# [boot.limine.ableos.modules.render_example] [boot.limine.ableos.modules.render_example]
# path = "boot:///render_example.hbf" path = "boot:///render_example.hbf"
# [boot.limine.ableos.modules.serial_driver_test] # [boot.limine.ableos.modules.serial_driver_test]
# path = "boot:///serial_driver_test.hbf" # path = "boot:///serial_driver_test.hbf"
@ -44,8 +47,8 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.svga_driver] # [boot.limine.ableos.modules.svga_driver]
# path = "boot:///svga_driver.hbf" # path = "boot:///svga_driver.hbf"
[boot.limine.ableos.modules.ps2_driver] # [boot.limine.ableos.modules.ps2_driver]
path = "boot:///ps2_driver.hbf" # path = "boot:///ps2_driver.hbf"
# [boot.limine.ableos.modules.filesystem_fat32] # [boot.limine.ableos.modules.filesystem_fat32]
# path = "boot:///filesystem_fat32.hbf" # path = "boot:///filesystem_fat32.hbf"
@ -53,5 +56,5 @@ path = "boot:///ps2_driver.hbf"
# [boot.limine.ableos.modules.pumpkin_print] # [boot.limine.ableos.modules.pumpkin_print]
# path = "boot:///pumpkin_print.hbf" # path = "boot:///pumpkin_print.hbf"
[boot.limine.ableos.modules.tetris] # [boot.limine.ableos.modules.tetris]
path = "boot:///tetris.hbf" # path = "boot:///tetris.hbf"