1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
peony 2024-11-04 02:58:58 +01:00
commit d0f078cf10
29 changed files with 478 additions and 168 deletions

6
Cargo.lock generated
View file

@ -253,12 +253,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#44fc9c3e2e0aa32b92a4a9a20e4eadbf354d7b6c" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e8f1d2af8ca7520bbb695dcaf1029a348f29592e"
[[package]] [[package]]
name = "hblang" name = "hblang"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#44fc9c3e2e0aa32b92a4a9a20e4eadbf354d7b6c" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e8f1d2af8ca7520bbb695dcaf1029a348f29592e"
dependencies = [ dependencies = [
"hashbrown 0.15.0", "hashbrown 0.15.0",
"hbbytecode", "hbbytecode",
@ -270,7 +270,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#44fc9c3e2e0aa32b92a4a9a20e4eadbf354d7b6c" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#e8f1d2af8ca7520bbb695dcaf1029a348f29592e"
dependencies = [ dependencies = [
"hbbytecode", "hbbytecode",
] ]

View file

@ -35,7 +35,7 @@ create_window := fn(channel: int): ^render.Surface {
loop if x > 1000 break else x += 1 loop if x > 1000 break else x += 1
ret := buffer.recv([u8; 4096], windowing_system_buffer, mem_buf) ret := buffer.recv([u8; 4096], windowing_system_buffer, mem_buf)
if ret == 0 { if ret == null {
log.info("No messages\0") log.info("No messages\0")
} }

View file

@ -0,0 +1,22 @@
keycodes := @use("keycodes.hb");
.{KeyCode} := keycodes
KeyEvent := struct {
// 0 if down
// 1 if up
up: u8,
// 0 if not just triggered
// 1 if just triggered
just_triggered: u8,
key: KeyCode,
}
MouseEvent := struct {
x_change: u8,
y_change: u8,
left: u8,
middle: u8,
right: u8,
}
GamepadEvent := struct {}

View file

@ -1,67 +1,121 @@
/*
Originally I was modelling this after the following(1). I have since changed my mind.
I am now modelling it as I see fit. This is likely not the final version.
1) https://www.libsdl.org/release/SDL-1.2.15/include/SDL_keysym.h
*/
KeyCode := u32 KeyCode := u32
// https://www.libsdl.org/release/SDL-1.2.15/include/SDL_keysym.h // Typically this is not a keycode you will ever recieve.
Backspace := KeyCode.(8) None := KeyCode.(0)
Tab := KeyCode.(9)
Clear := KeyCode.(12)
Return := KeyCode.(13)
Pause := KeyCode.(19)
Escape := KeyCode.(27)
Space := KeyCode.(32)
A := KeyCode.(97) Escape := KeyCode.(1)
/* /* Alphabet keycodes */
ETC
*/
Z := KeyCode.(122)
Delete := KeyCode.(127) A := KeyCode.(2)
B := KeyCode.(3)
C := KeyCode.(4)
D := KeyCode.(5)
E := KeyCode.(6)
F := KeyCode.(7)
G := KeyCode.(8)
H := KeyCode.(9)
I := KeyCode.(10)
J := KeyCode.(11)
K := KeyCode.(12)
L := KeyCode.(13)
M := KeyCode.(14)
N := KeyCode.(15)
O := KeyCode.(16)
P := KeyCode.(17)
Q := KeyCode.(18)
R := KeyCode.(19)
S := KeyCode.(20)
T := KeyCode.(21)
U := KeyCode.(22)
V := KeyCode.(23)
W := KeyCode.(24)
X := KeyCode.(25)
Y := KeyCode.(26)
Z := KeyCode.(27)
/* /* Numeric keycodes*/
ETC
*/
KeypadNumber0 := KeyCode.(256) Number0 := KeyCode.(28)
KeypadNumber1 := KeyCode.(257) Number1 := KeyCode.(29)
KeypadNumber2 := KeyCode.(258) Number2 := KeyCode.(30)
KeypadNumber3 := KeyCode.(259) Number3 := KeyCode.(31)
KeypadNumber4 := KeyCode.(260) Number4 := KeyCode.(32)
KeypadNumber5 := KeyCode.(261) Number5 := KeyCode.(33)
KeypadNumber6 := KeyCode.(262) Number6 := KeyCode.(34)
KeypadNumber7 := KeyCode.(263) Number7 := KeyCode.(35)
KeypadNumber8 := KeyCode.(264) Number8 := KeyCode.(36)
KeypadNumber9 := KeyCode.(265) Number9 := KeyCode.(37)
KeypadPeriod := KeyCode.(266) KeypadNumber0 := KeyCode.(38)
KeypadDivide := KeyCode.(267) KeypadNumber1 := KeyCode.(39)
KeypadMultiply := KeyCode.(268) KeypadNumber2 := KeyCode.(40)
KeypadMinus := KeyCode.(269) KeypadNumber3 := KeyCode.(41)
KeypadPlus := KeyCode.(270) KeypadNumber4 := KeyCode.(42)
KeypadEnter := KeyCode.(271) KeypadNumber5 := KeyCode.(43)
KeypadEquals := KeyCode.(272) KeypadNumber6 := KeyCode.(44)
KeypadNumber7 := KeyCode.(45)
KeypadNumber8 := KeyCode.(46)
KeypadNumber9 := KeyCode.(47)
NumLock := KeyCode.(300) KeypadPeriod := KeyCode.(48)
CapsLock := KeyCode.(301) KeypadDivide := KeyCode.(49)
ScrollLock := KeyCode.(302) KeypadMultiply := KeyCode.(50)
KeypadMinus := KeyCode.(51)
KeypadPlus := KeyCode.(52)
KeypadEnter := KeyCode.(53)
KeypadEquals := KeyCode.(54)
RightShift := KeyCode.(303) Delete := KeyCode.(55)
LeftShift := KeyCode.(304) /* Locking Keys */
NumLock := KeyCode.(56)
RightControl := KeyCode.(305) CapsLock := KeyCode.(57)
LeftControl := KeyCode.(306) ScrollLock := KeyCode.(58)
RightAlt := KeyCode.(307)
LeftAlt := KeyCode.(308)
RightMeta := KeyCode.(309)
LeftMeta := KeyCode.(310)
/* Left "Windows" key */
LeftSuper := KeyCode.(311)
/* Right "Windows" key */
RightSuper := KeyCode.(312)
/* "Alt Gr" key */ /* "Alt Gr" key */
Mode := KeyCode.(313) Mode := KeyCode.(59)
/* Multi-key compose key */ /* Multi-key compose key */
Compose := KeyCode.(314) Compose := KeyCode.(60)
LeftAlt := KeyCode.(61)
LeftControl := KeyCode.(62)
LeftMeta := KeyCode.(63)
LeftShift := KeyCode.(64)
/* Left "Windows" key */
LeftSuper := KeyCode.(65)
RightAlt := KeyCode.(66)
RightControl := KeyCode.(67)
RightMeta := KeyCode.(68)
RightShift := KeyCode.(69)
/* Right "Windows" key */
RightSuper := KeyCode.(70)
/*
This block of any triggers on any press of any of the keys.
Typically this is the event to care about.
*/
AnyNumber0 := KeyCode.(71)
AnyNumber1 := KeyCode.(72)
AnyNumber2 := KeyCode.(73)
AnyNumber3 := KeyCode.(74)
AnyNumber4 := KeyCode.(75)
AnyNumber5 := KeyCode.(76)
AnyNumber6 := KeyCode.(77)
AnyNumber7 := KeyCode.(78)
AnyNumber8 := KeyCode.(79)
AnyNumber9 := KeyCode.(80)
AnyAlt := KeyCode.(81)
AnyControl := KeyCode.(82)
AnyMeta := KeyCode.(83)
AnyShift := KeyCode.(84)
/* Any "Windows" key */
AnySuper := KeyCode.(85)

View file

@ -1,22 +1,15 @@
keycodes := @use("keycodes.hb"); stn := @use("../../stn/src/lib.hb");
.{KeyCode} := keycodes .{log, buffer} := stn
events := @use("events.hb");
.{KeyEvent, MouseEvent} := events
MouseEvent := struct { recieve_key_event := fn(): ?KeyEvent {
x_change: u8, buf := buffer.search("PS/2 Keyboard\0")
y_change: u8, // Read out of the keyboard buffer here
left: u8,
middle: u8, return null
right: u8,
} }
KeyEvent := struct { recieve_mouse_event := fn(): ?MouseEvent {
// 0 if down return null
// 1 if up
up: u8,
// 0 if not just triggered
// 1 if just triggered
just_triggered: u8,
key: KeyCode,
} }
GamepadEvent := struct {}

View file

@ -32,11 +32,11 @@ BitmapColorHeader := packed struct {
unused: u32, unused: u32,
} }
surface_from_bmp := fn(bmp: ^u8): Surface { surface_from_bmp := fn(bmp: ^u8): ?Surface {
file_header := @as(^BitmapFileHeader, @bitcast(bmp)) file_header := @as(^BitmapFileHeader, @bitcast(bmp))
if file_header.img_type != 0x4D42 { if file_header.img_type != 0x4D42 {
log.error("failed to load bmp image: not a bmp image, idiot\0") log.error("failed to load bmp image: not a bmp image, idiot\0")
return idk return null
} }
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader))) info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
bmp += file_header.offset bmp += file_header.offset
@ -64,11 +64,11 @@ surface_from_bmp := fn(bmp: ^u8): Surface {
return .(@bitcast(bmp), info_header.width, info_header.height) return .(@bitcast(bmp), info_header.width, info_header.height)
} }
new_surface_from_bmp := fn(bmp: ^u8): Surface { new_surface_from_bmp := fn(bmp: ^u8): ?Surface {
file_header := @as(^BitmapFileHeader, @bitcast(bmp)) file_header := @as(^BitmapFileHeader, @bitcast(bmp))
if file_header.img_type != 0x4D42 { if file_header.img_type != 0x4D42 {
log.error("failed to load bmp image: not a bmp image, idiot\0") log.error("failed to load bmp image: not a bmp image, idiot\0")
return idk return null
} }
info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader))) info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader)))
bmp += file_header.offset bmp += file_header.offset

View file

@ -3,6 +3,9 @@
.{get_glyph, Font} := text; .{get_glyph, Font} := text;
.{Vec2} := math .{Vec2} := math
// safety: don't use before init() or you will get a memory access violation
framebuffer := memory.dangling(^Color)
Surface := struct { Surface := struct {
buf: ^Color, buf: ^Color,
width: uint, width: uint,
@ -100,8 +103,9 @@ put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color:
rows_to_fill := tr.y rows_to_fill := tr.y
loop if rows_to_fill <= 1 break else { loop if rows_to_fill <= 1 break else {
@inline(memory.set, Color, &color, top_start_idx, @bitcast(tr.x)) // inline is broked
@inline(memory.set, Color, &color, bottom_start_idx, @bitcast(tr.x)) memory.set(Color, &color, top_start_idx, @bitcast(tr.x))
memory.set(Color, &color, bottom_start_idx, @bitcast(tr.x))
top_start_idx += surface.width top_start_idx += surface.width
bottom_start_idx -= surface.width bottom_start_idx -= surface.width
@ -446,10 +450,12 @@ put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str:
} }
glyph_data := @inline(get_glyph, font, @intcast(*current_char)) glyph_data := @inline(get_glyph, font, @intcast(*current_char))
if glyph_data == idk { // ! cool null check don't disable :dead:
current_char += 1 // !! i disabled the cool null check because compiler
continue // if glyph_data == null {
} // current_char += 1
// continue
// }
if cursor.x % surface.width + font.width >= surface.width { if cursor.x % surface.width + font.width >= surface.width {
cursor.x = pos.x cursor.x = pos.x

View file

@ -28,11 +28,11 @@ Font := struct {
char_gap: uint, char_gap: uint,
} }
font_from_psf1 := fn(psf: ^u8): Font { font_from_psf1 := fn(psf: ^u8): ?Font {
header := @as(^PSF1Header, @bitcast(psf)) header := @as(^PSF1Header, @bitcast(psf))
if header.magic != 0x436 { if header.magic != 0x436 {
log.error("failed to load psf font: not a psf1 font, idiot\0") log.error("failed to load psf font: not a psf1 font, idiot\0")
return idk return null
} }
psf += @sizeof(PSF1Header) psf += @sizeof(PSF1Header)
@ -40,30 +40,30 @@ font_from_psf1 := fn(psf: ^u8): Font {
return .( return .(
psf, psf,
8, 8,
@intcast(header.character_size), header.character_size,
256, 256,
@intcast(header.character_size), header.character_size,
false, false,
0, 0,
0, 0,
) )
} }
font_from_psf2 := fn(psf: ^u8): Font { font_from_psf2 := fn(psf: ^u8): ?Font {
header := @as(^PSF2Header, @bitcast(psf)) header := @as(^PSF2Header, @bitcast(psf))
if header.magic != 0x864AB572 { if header.magic != 0x864AB572 {
log.error("failed to load psf font: not a psf2 font, idiot\0") log.error("failed to load psf font: not a psf2 font, idiot\0")
return idk return null
} }
psf += header.header_size psf += header.header_size
return .( return .(
psf, psf,
@intcast(header.width), header.width,
@intcast(header.height), header.height,
@intcast(header.num_glyph), header.num_glyph,
@intcast(header.bytes_per_glyph), header.bytes_per_glyph,
(header.flags & 1) != 0, (header.flags & 1) != 0,
0, 0,
0, 0,

View file

@ -1,6 +1,6 @@
string := @use("string.hb") string := @use("string.hb")
recv := fn($Expr: type, buffer_id: int, memory_map_location: ^u8): ^Expr { recv := fn($Expr: type, buffer_id: int, memory_map_location: ^u8): ?^Expr {
return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) return @eca(4, buffer_id, memory_map_location, @sizeof(Expr))
} }

View file

@ -7,3 +7,13 @@ math := @use("math.hb")
random := @use("random.hb") random := @use("random.hb")
file := @use("file_io.hb") file := @use("file_io.hb")
dt := @use("dt.hb") dt := @use("dt.hb")
panic := fn(message: ?^u8): never {
log.error("Error: Panic Called, Message:\0")
if message == null {
log.error("None\0")
} else {
log.error(message)
}
die
}

View file

@ -2,6 +2,10 @@ PAGE_SIZE := 4096
MAX_ALLOC := 0xFF MAX_ALLOC := 0xFF
MAX_FREE := 0xFF MAX_FREE := 0xFF
dangling := fn($Expr: type): Expr {
return @bitcast(@sizeof(Expr))
}
calc_pages := fn($Expr: type, num: uint): uint { calc_pages := fn($Expr: type, num: uint): uint {
return 1 + @sizeof(Expr) * num / PAGE_SIZE return 1 + @sizeof(Expr) * num / PAGE_SIZE
} }
@ -14,10 +18,10 @@ alloc := fn($Expr: type, num: uint): ^Expr {
ptr := request_page(0xFF) ptr := request_page(0xFF)
remaining := pages - MAX_ALLOC remaining := pages - MAX_ALLOC
loop if remaining < MAX_ALLOC break else { loop if remaining < MAX_ALLOC break else {
_ := request_page(@intcast(MAX_ALLOC)) _ = request_page(@intcast(MAX_ALLOC))
remaining -= MAX_ALLOC remaining -= MAX_ALLOC
} }
_ := request_page(@intcast(remaining)) _ = request_page(@intcast(remaining))
return @bitcast(ptr) return @bitcast(ptr)
} }

View file

@ -1,8 +0,0 @@
panic := fn(message: ?^u8): void {
if message != null {
log.error(message)
}
// TODO: replace with die keyword when it gets pushed
loop {
}
}

View file

@ -1,8 +1,7 @@
length := fn(ptr: ^u8): uint { length := fn(ptr: ^u8): uint {
len := @as(uint, 0) len := 0
// loop if *(ptr + len) == 0 return len else len += 1 loop if *(ptr + len) == 0 return len else len += 1
loop if *(ptr + len) == 0 break else len += 1
return len
} }
display_int := fn(num: int, p: ^u8, radix: uint): ^u8 { display_int := fn(num: int, p: ^u8, radix: uint): ^u8 {
@ -58,7 +57,7 @@ display_int := fn(num: int, p: ^u8, radix: uint): ^u8 {
} }
reverse := fn(s: ^u8): void { reverse := fn(s: ^u8): void {
i := @as(uint, 0) i := 0
j := @inline(length, s) - 1 j := @inline(length, s) - 1
temp := @as(u8, 0) temp := @as(u8, 0)
loop if i >= j break else { loop if i >= j break else {

View file

@ -0,0 +1,2 @@
# app bar
The app bar is a mini-bar meant to launch applications.

View file

@ -1,6 +1,6 @@
[package] [package]
name = "mouse_driver" name = "app_bar"
authors = ["peony"] authors = ["able"]
[dependants.libraries] [dependants.libraries]

View file

@ -0,0 +1,35 @@
stn := @use("../../../libraries/stn/src/lib.hb");
.{string, memory, buffer, random, log} := stn;
.{Vec2} := stn.math
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb")
render := @use("../../../libraries/render/src/lib.hb")
psf := @embed("../../../consolefonts/tamsyn/10x20r.psf")
main := fn(): int {
screen := render.init(true)
// Clear the screen to black.
render.clear(screen, render.black)
x := 0
mem_buf := memory.request_page(1)
color := random.any(render.Color)
str := "Window Title Bar\0"
font := render.text.font_from_psf2(@bitcast(&psf))
loop {
// Clear the screen
render.clear(screen, render.black)
render.put_rect(screen, .(0, 0), .(screen.width - 1, 26), render.white)
// Sync the screen
render.sync(screen)
}
return 0
}

View file

@ -9,8 +9,7 @@ OemIdent := struct {
} }
new_oem_ident := fn(major: int, minor: int): OemIdent { new_oem_ident := fn(major: int, minor: int): OemIdent {
ver := [u8].(0, 0, 0, 0, 0, 0, 0, 0) return .(.(0, 0, 0, 0, 0, 0, 0, 0), .(0, 0, 0, 0, 0, 0, 0, 0))
return OemIdent.(ver, ver)
} }
BiosParameterBlock := struct { BiosParameterBlock := struct {
@ -38,9 +37,7 @@ bpb_sanity_check := fn(bpb: BiosParameterBlock): int {
} }
new_bpb := fn(): BiosParameterBlock { new_bpb := fn(): BiosParameterBlock {
oem := new_oem_ident(0, 0) return .(VALID_JUMP_BYTES, new_oem_ident(0, 0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
return BiosParameterBlock.(VALID_JUMP_BYTES, oem, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
} }
sector_count := fn(bpb: BiosParameterBlock): u32 { sector_count := fn(bpb: BiosParameterBlock): u32 {

View file

@ -5,6 +5,7 @@ stn := @use("../../../libraries/stn/src/lib.hb");
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb") horizon_api := @use("../../../libraries/horizon_api/src/lib.hb")
render := @use("../../../libraries/render/src/lib.hb") render := @use("../../../libraries/render/src/lib.hb")
intouch := @use("../../../libraries/intouch/src/lib.hb")
Window := struct { Window := struct {
// TODO: Replace this with widgets // TODO: Replace this with widgets
@ -36,7 +37,11 @@ main := fn(): int {
vel_inner := Vec2(int).(1, 1) vel_inner := Vec2(int).(1, 1)
pos_inner := Vec2(uint).((window.width - side) / 2, (window.height - side) / 2) pos_inner := Vec2(uint).((window.width - side) / 2, (window.height - side) / 2)
str := "Window Title Bar\0" str := "Window Title Bar\0"
font := render.text.font_from_psf2(@bitcast(&psf)) // really we should null check but it is a bit broked
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf)))
mouse_x := 0
mouse_y := 0
loop { loop {
// Clear the screen // Clear the screen
@ -45,11 +50,22 @@ main := fn(): int {
// TODO: Read the window buffer here // TODO: Read the window buffer here
{ {
ret := buffer.recv([u8; 4096], win_buff, mem_buf) ret := buffer.recv([u8; 4096], win_buff, mem_buf)
if ret == 0 { // for some reason this null check causes the compiler to spin forever
log.info("No messages\0") // if ret == null {
} else { // log.info("No messages\0")
log.info("Handle Messages\0") // } else {
// log.info("Handle Messages\0")
// }
} }
{
// get input events from drivers via intouch
key_event := intouch.recieve_key_event()
mouse_event := intouch.recieve_mouse_event()
// render mouse
render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white)
// Send events to focused window
} }
if pos_inner.x == 0 | pos_inner.x == window.width - side { if pos_inner.x == 0 | pos_inner.x == window.width - side {
@ -63,29 +79,29 @@ main := fn(): int {
// TODO: Get windows out of a collection and iter through // TODO: Get windows out of a collection and iter through
window_count := 0 window_count := 0
loop {
render.clear(window, render.black)
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white)
// loop {
// render.clear(window, render.black)
// Draw the decorators // // Draw the decorators
{ // {
render.put_rect(window, .(0, 0), .(window.width - 1, window.height - 1), render.white) // render.put_rect(window, .(0, 0), .(window.width - 1, window.height - 1), render.white)
render.put_rect(window, .(0, 0), .(window.width - 1, 20), render.white) // render.put_rect(window, .(0, 0), .(window.width - 1, 20), render.white)
render.put_text(window, font, .(window.width / 2, 1), render.white, str) // render.put_text(window, font, .(window.width / 2, 1), render.white, str)
} // }
render.put_filled_rect(window, pos_inner, .(side, side), color) // render.put_filled_rect(window, pos_inner, .(side, side), color)
// Apply the image to the screen // // Apply the image to the screen
pos := Vec2(uint).(x, 100) // pos := Vec2(uint).(x, 100)
render.put_surface(screen, window, pos, false) // render.put_surface(screen, window, pos, false)
if window_count >= 1 { // if window_count >= 1 {
x = 0 // x = 0
break // break
} // }
window_count += 1 // window_count += 1
x += screen.width / 2 // x += screen.width / 2
} // }
pos_inner += @bitcast(vel_inner) pos_inner += @bitcast(vel_inner)
// Sync the screen // Sync the screen

View file

@ -1 +0,0 @@
# mouse_driver

View file

@ -1,5 +1,5 @@
[package] [package]
name = "ps2_driver" name = "ps2_keyboard_driver"
authors = ["Talha Qamar"] authors = ["Talha Qamar"]
[dependants.libraries] [dependants.libraries]

View file

@ -7,7 +7,7 @@ send_byte := fn(byte: u8): u8 {
main := fn(): int { main := fn(): int {
buf := buffer.create("XKeyboard\0") buf := buffer.create("XKeyboard\0")
_ := send_byte(238) _ = send_byte(238)
log.info("PS/2 Driver Loaded\0") log.info("PS/2 Driver Loaded\0")
if send_byte(238) == 238 { if send_byte(238) == 238 {
log.info("PS/2 Keyboard Echoed\0") log.info("PS/2 Keyboard Echoed\0")

View file

@ -0,0 +1,2 @@
# ps2_mouse_driver
A small PS/2 mouse driver. This driver pushes changes to the input service in ableOS.

View file

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

View file

@ -0,0 +1,150 @@
.{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb")
Vec2 := math.Vec2
i9 := packed struct {sign: bool, value: u8}
Button := struct {id: u8}
LeftButton := Button.(1)
RightButton := Button.(2)
MiddleButton := Button.(4)
Button4 := Button.(8)
Button5 := Button.(16)
mouse_moved := fn(delta: Vec2(i9)): void {
log.info("Mouse movement.\0")
}
button_event := fn(button: Button, pressed: bool): void {
if pressed {
log.info("Mouse-button pressed.\0")
} else {
log.info("Mouse-button released.\0")
}
}
send_byte := fn(target: u8, data: u8): void {
loop if (memory.inb(0x64) & 2) == 0 break
memory.outb(target, data)
}
reset_mouse := fn(): void {
@inline(send_byte, 0x64, 0xD4)
@inline(send_byte, 0x60, 0xFF)
loop if memory.inb(0x60) == 0xAA {
log.info("Self check passed.\0")
return
}
}
send_command_byte := fn(byte: u8): void {
@inline(send_byte, 0x64, 0xD4)
@inline(send_byte, 0x60, byte)
loop if memory.inb(0x60) == 0xFA {
log.info("ACK\0")
return
}
}
set_defaults := fn(): void @inline(send_command_byte, 0xF6)
disable_streaming := fn(): void @inline(send_command_byte, 0xF5)
enable_streaming := fn(): void @inline(send_command_byte, 0xF4)
set_remote_mode := fn(): void @inline(send_command_byte, 0xF0)
set_warp_mode := fn(): void @inline(send_command_byte, 0xEE)
reset_warp_mode := fn(): void @inline(send_command_byte, 0xEC)
set_stream_mode := fn(): void @inline(send_command_byte, 0xEA)
set_non_linear_scaling := fn(): void @inline(send_command_byte, 0xE7)
set_linear_scaling := fn(): void @inline(send_command_byte, 0xE6)
resend_packet := fn(): void @inline(send_command_byte, 0xFE)
SampleRate := struct {value: u8}
sr10 := SampleRate.(10)
sr20 := SampleRate.(20)
sr40 := SampleRate.(40)
sr60 := SampleRate.(60)
sr80 := SampleRate.(80)
sr100 := SampleRate.(100)
sr200 := SampleRate.(200)
set_sample_rate := fn(sample_rate: SampleRate): void {
@inline(send_command_byte, 0xE6)
@inline(send_command_byte, sample_rate.value)
}
Resolution := struct {value: u8}
res_1count_per_mm := Resolution.(0)
res_2count_per_mm := Resolution.(1)
res_4count_per_mm := Resolution.(2)
res_8count_per_mm := Resolution.(3)
set_resolution := fn(resolution: Resolution): void {
@inline(send_command_byte, 0xE6)
@inline(send_command_byte, resolution.value)
}
set_up_mouse := fn(): void {
@inline(reset_mouse)
@inline(set_resolution, res_8count_per_mm)
@inline(enable_streaming)
}
button_states := @as(u8, 0)
main := fn(): int {
format_page := memory.alloc(u8, 1024)
mouse_buffer := buffer.create("Mouse\0")
send_byte(0x64, 0xA8)
log.info("Aux mouse device enabled.\0")
set_up_mouse()
set_resolution(res_8count_per_mm)
x := @as(u8, 0)
y := @as(u8, 0)
loop {
loop if (memory.inb(0x64) & 0x20) == 0x20 break
status := memory.inb(0x60)
if status == 0xAA {
loop if memory.inb(0x60) == 0 break
log.info("Mouse plugged in!\0")
set_up_mouse()
continue
}
changes := button_states ^ status & 7
if (changes & LeftButton.id) != 0 {
button_event(LeftButton, (status & LeftButton.id) != 0)
}
if (changes & RightButton.id) != 0 {
button_event(RightButton, (status & RightButton.id) != 0)
}
if (changes & MiddleButton.id) != 0 {
button_event(MiddleButton, (status & MiddleButton.id) != 0)
}
button_states ^= changes
log.info(string.display_int(status, format_page, 10))
dx := i9.(false, 0)
dy := i9.(false, 0)
dx.value = memory.inb(0x60)
dx.sign = (status & 0x10) > 0
dy.value = -memory.inb(0x60)
dy.sign = (status & 0x20) == 0
if dy.value != 0 & dx.value != 0 {
mouse_moved(.(dx, dy))
}
}
return 0
}

View file

@ -8,9 +8,10 @@ bmp_1 := @embed("./assets/able.bmp")
bmp_2 := @embed("./assets/mini.bmp") bmp_2 := @embed("./assets/mini.bmp")
example := fn(): void { example := fn(): void {
// strictly we should be null checking here but i am lazy
images := [render.Surface].( images := [render.Surface].(
render.image.surface_from_bmp(@bitcast(&bmp_1)), @unwrap(render.image.surface_from_bmp(@bitcast(&bmp_1))),
render.image.surface_from_bmp(@bitcast(&bmp_2)), @unwrap(render.image.surface_from_bmp(@bitcast(&bmp_2))),
) )
screen := render.init(true) screen := render.init(true)
vel := Vec2(int).(1, 1) vel := Vec2(int).(1, 1)

View file

@ -1,22 +1,37 @@
.{Vec2, sin, cos} := @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:
words */ extended unicode test */
psf := @embed("../../../../consolefonts/tamsyn/10x20r.psf") psf := @embed("../../../../consolefonts/tamsyn/10x20r.psf")
example := fn(): void { example := fn(): void {
screen := render.init(true) screen := render.init(false)
font := render.text.font_from_psf2(@bitcast(&psf)) font := render.text.font_from_psf2(@bitcast(&psf))
t := 0
str := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX\0"
loop { str := "Extended unicode test:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
0123456789
!\"#$%&'()*+,-./:;<=>?@[]^_`{|}~
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞß
àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ
ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğ
ĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿ
„‟†‡•‣․‥…‧
₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽₾₿
∀∁∂∃∄∅∆∇∈∉∊∋∌∍∎∏∐∑−∓∔∕∖∗∘∙√∛∜∝∞∟
─│┌┐└┘├┤┬┴┼╋╭╮╯╰╱╲╳╴╵╶╷╸╹╺╻╼╽╾╿
▀▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▐░▒▓▔▕▖▗▘▙▚▛▜▝▞▟
■□▢▣▤▥▦▧▨▩▪▫▬▭▮▯▰▱▲△▴▵▶▷▸▹►▻▼▽▾▿◀◁◂◃◄◅◆◇◈◉◊○
←↑→↓↔↕↖↗↘↙↚↛↜↝↞↟↠↡↢↣↤↥↦↧↨↩↪↫↬↭↮↯↰↱↲↳↴↵↶↷↸↹↺↻
 、。〃〄々〆〇〈〉《》「」『』【】〒〓〔〕〖〗〘〙〚〛〜〝〞〟
✀✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞✟
✠✡✢✣✤✥✦✧✨✩✪✫✬✭✮✯✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿\0"
render.clear(screen, render.black) render.clear(screen, render.black)
render.put_text(screen, font, .(t, t % screen.height), render.red, str) render.put_text(screen, @unwrap(font), .(0, 0), render.white, str)
render.sync(screen) render.sync(screen)
// t += 1
}
return return
} }

View file

@ -5,7 +5,9 @@ log_info := fn(): void {
if a == 0 { if a == 0 {
} else { } else {
msg := "XABC\0" msg := "XABC\0"
msg_length := @inline(string.length, msg) // inline is broked
// msg_length := @inline(string.length, msg)
msg_length := 5
@as(void, @eca(3, a, msg, msg_length)) @as(void, @eca(3, a, msg, msg_length))
} }

View file

@ -38,8 +38,8 @@ path = "boot:///mouse_driver.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"
# [boot.limine.ableos.modules.horizon] [boot.limine.ableos.modules.horizon]
# path = "boot:///horizon.hbf" path = "boot:///horizon.hbf"
# [boot.limine.ableos.modules.horizon_testing_program] # [boot.limine.ableos.modules.horizon_testing_program]
# path = "boot:///horizon_testing_program.hbf" # path = "boot:///horizon_testing_program.hbf"
@ -50,8 +50,8 @@ path = "boot:///mouse_driver.hbf"
# [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_keyboard_driver]
# path = "boot:///ps2_driver.hbf" path = "boot:///ps2_keyboard_driver.hbf"
# [boot.limine.ableos.modules.filesystem_fat32] # [boot.limine.ableos.modules.filesystem_fat32]
# path = "boot:///filesystem_fat32.hbf" # path = "boot:///filesystem_fat32.hbf"