diff --git a/.cargo/config.toml b/.cargo/config.toml index b3353930f..e85de27fa 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -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 --" diff --git a/Cargo.lock b/Cargo.lock index c7b27228e..56dc2fc0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,59 +11,17 @@ dependencies = [ "tock-registers", ] -[[package]] -name = "addr2line" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler2" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" - -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "allocator-api2" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" - -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] +checksum = "611cc2ae7d2e242c457e4be7f97036b8ad9ca152b499f53faf99b1ed8fc2553f" [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "autocfg" @@ -71,21 +29,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "backtrace" -version = "0.3.74" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", - "windows-targets", -] - [[package]] name = "base64" version = "0.22.1" @@ -137,17 +80,11 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" -[[package]] -name = "bytes" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" - [[package]] name = "cc" -version = "1.1.30" +version = "1.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" dependencies = [ "shlex", ] @@ -158,26 +95,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-targets", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "crossbeam-queue" version = "0.3.11" @@ -221,6 +138,17 @@ dependencies = [ "logos", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -245,7 +173,6 @@ checksum = "05669f8e7e2d7badc545c513710f0eba09c2fbef683eb859fd79c46c355048e0" dependencies = [ "bitflags 1.3.2", "byteorder", - "chrono", "log", ] @@ -255,6 +182,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -264,56 +197,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures-channel" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-sink" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" - -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "getrandom" version = "0.2.15" @@ -325,39 +208,34 @@ dependencies = [ "wasi", ] -[[package]] -name = "gimli" -version = "0.31.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" - [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] [[package]] name = "hbbytecode" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc2e0cc5b36f84f9d5bb82b6f48e6b29869746d5" +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#dc2e0cc5b36f84f9d5bb82b6f48e6b29869746d5" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248" dependencies = [ - "hashbrown 0.15.0", + "hashbrown 0.15.1", "hbbytecode", "hbvm", "log", @@ -367,144 +245,148 @@ dependencies = [ [[package]] name = "hbvm" version = "0.1.0" -source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#dc2e0cc5b36f84f9d5bb82b6f48e6b29869746d5" +source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#8b98c2ed1becb92046bb7b687ca00813da441248" dependencies = [ "hbbytecode", ] [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "icu_collections" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "http" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" dependencies = [ - "bytes", - "fnv", - "itoa", + "displaydoc", + "yoke", + "zerofrom", + "zerovec", ] [[package]] -name = "http-body" -version = "1.0.1" +name = "icu_locid" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" dependencies = [ - "bytes", - "http", + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", ] [[package]] -name = "http-body-util" -version = "0.1.2" +name = "icu_locid_transform" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" dependencies = [ - "bytes", - "futures-util", - "http", - "http-body", - "pin-project-lite", + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", ] [[package]] -name = "httparse" -version = "1.9.5" +name = "icu_locid_transform_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" [[package]] -name = "hyper" -version = "1.4.1" +name = "icu_normalizer" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", "smallvec", - "tokio", - "want", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", ] [[package]] -name = "hyper-rustls" -version = "0.27.3" +name = "icu_normalizer_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" dependencies = [ - "futures-util", - "http", - "hyper", - "hyper-util", - "rustls", - "rustls-pki-types", - "tokio", - "tokio-rustls", - "tower-service", - "webpki-roots", + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", ] [[package]] -name = "hyper-util" -version = "0.1.9" +name = "icu_properties_data" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", ] [[package]] -name = "iana-time-zone" -version = "0.1.61" +name = "icu_provider_macros" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", + "proc-macro2", + "quote", + "syn", ] [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -514,28 +396,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", -] - -[[package]] -name = "ipnet" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" - -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" -dependencies = [ - "wasm-bindgen", + "hashbrown 0.15.1", ] [[package]] @@ -545,7 +406,7 @@ dependencies = [ "aarch64-cpu", "crossbeam-queue", "derive_more", - "hashbrown 0.14.5", + "hashbrown 0.15.1", "hbvm", "limine", "log", @@ -567,9 +428,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.159" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "limine" @@ -577,6 +438,12 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02034f8f6b3e7bf050f310fbaf6db0018b8e54b75598d0a4c97172054752fede" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" version = "0.4.12" @@ -632,51 +499,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mime" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" - -[[package]] -name = "miniz_oxide" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" -dependencies = [ - "adler2", -] - -[[package]] -name = "mio" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" -dependencies = [ - "hermit-abi", - "libc", - "wasi", - "windows-sys 0.52.0", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "object" -version = "0.36.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.20.2" @@ -695,84 +517,15 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "ppv-lite86" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" -dependencies = [ - "zerocopy", -] - [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] -[[package]] -name = "quinn" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" -dependencies = [ - "bytes", - "pin-project-lite", - "quinn-proto", - "quinn-udp", - "rustc-hash", - "rustls", - "socket2", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "quinn-proto" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" -dependencies = [ - "bytes", - "rand", - "ring", - "rustc-hash", - "rustls", - "slab", - "thiserror", - "tinyvec", - "tracing", -] - -[[package]] -name = "quinn-udp" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fe68c2e9e1a1234e218683dbdf9f9dfcb094113c5ac2b938dfcb9bab4c4140b" -dependencies = [ - "libc", - "once_cell", - "socket2", - "tracing", - "windows-sys 0.59.0", -] - [[package]] name = "quote" version = "1.0.37" @@ -782,36 +535,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "raw-cpuid" version = "10.7.0" @@ -859,52 +582,9 @@ dependencies = [ "hblang", "log", "raw-cpuid 11.2.0", - "reqwest", "str-reader", "toml", -] - -[[package]] -name = "reqwest" -version = "0.12.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" -dependencies = [ - "base64", - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-rustls", - "hyper-util", - "ipnet", - "js-sys", - "log", - "mime", - "once_cell", - "percent-encoding", - "pin-project-lite", - "quinn", - "rustls", - "rustls-pemfile", - "rustls-pki-types", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "tokio", - "tokio-rustls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "webpki-roots", - "windows-registry", + "ureq", ] [[package]] @@ -919,15 +599,9 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - [[package]] name = "rustc-hash" version = "2.0.0" @@ -945,10 +619,11 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.14" +version = "0.23.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" dependencies = [ + "log", "once_cell", "ring", "rustls-pki-types", @@ -957,20 +632,11 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-pemfile" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" -dependencies = [ - "rustls-pki-types", -] - [[package]] name = "rustls-pki-types" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" [[package]] name = "rustls-webpki" @@ -985,15 +651,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" - -[[package]] -name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "sbi" @@ -1015,36 +675,24 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "serde_json" -version = "1.0.128" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "serde_spanned" version = "0.6.8" @@ -1054,18 +702,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "shlex" version = "1.3.0" @@ -1087,16 +723,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "socket2" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "spin" version = "0.9.8" @@ -1106,6 +732,12 @@ dependencies = [ "lock_api", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "str-reader" version = "0.1.2" @@ -1120,9 +752,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.79" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -1130,28 +762,10 @@ dependencies = [ ] [[package]] -name = "sync_wrapper" -version = "1.0.1" +name = "synstructure" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" -dependencies = [ - "futures-core", -] - -[[package]] -name = "thiserror" -version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", @@ -1159,52 +773,21 @@ dependencies = [ ] [[package]] -name = "tinyvec" -version = "1.8.0" +name = "tinystr" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" dependencies = [ - "tinyvec_macros", + "displaydoc", + "zerovec", ] -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "tock-registers" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "696941a0aee7e276a165a978b37918fd5d22c55c3d6bda197813070ca9c0f21c" -[[package]] -name = "tokio" -version = "1.40.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" -dependencies = [ - "backtrace", - "bytes", - "libc", - "mio", - "pin-project-lite", - "socket2", - "windows-sys 0.52.0", -] - -[[package]] -name = "tokio-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" -dependencies = [ - "rustls", - "rustls-pki-types", - "tokio", -] - [[package]] name = "toml" version = "0.8.19" @@ -1239,37 +822,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "tower-service" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", -] - -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - [[package]] name = "uart_16550" version = "0.3.1" @@ -1281,27 +833,12 @@ dependencies = [ "x86", ] -[[package]] -name = "unicode-bidi" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" - [[package]] name = "unicode-ident" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" -[[package]] -name = "unicode-normalization" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-xid" version = "0.2.6" @@ -1315,10 +852,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] -name = "url" -version = "2.5.2" +name = "ureq" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" +dependencies = [ + "base64", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "url", + "webpki-roots", +] + +[[package]] +name = "url" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", "idna", @@ -1326,10 +878,16 @@ dependencies = [ ] [[package]] -name = "version_check" -version = "0.9.5" +name = "utf16_iter" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "versioning" @@ -1345,98 +903,12 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" -dependencies = [ - "cfg-if", - "once_cell", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" - -[[package]] -name = "web-sys" -version = "0.3.72" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "webpki-roots" version = "0.26.6" @@ -1446,45 +918,6 @@ dependencies = [ "rustls-pki-types", ] -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-registry" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" -dependencies = [ - "windows-result", - "windows-strings", - "windows-targets", -] - -[[package]] -name = "windows-result" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-strings" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" -dependencies = [ - "windows-result", - "windows-targets", -] - [[package]] name = "windows-sys" version = "0.52.0" @@ -1494,15 +927,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - [[package]] name = "windows-targets" version = "0.52.6" @@ -1576,6 +1000,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "x2apic" version = "0.4.3" @@ -1633,24 +1069,48 @@ dependencies = [ ] [[package]] -name = "zerocopy" -version = "0.7.35" +name = "yoke" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" dependencies = [ - "byteorder", - "zerocopy-derive", + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", ] [[package]] -name = "zerocopy-derive" -version = "0.7.35" +name = "yoke-derive" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" dependencies = [ "proc-macro2", "quote", "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", ] [[package]] @@ -1658,3 +1118,25 @@ name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/dev/src/main.rs b/dev/src/main.rs index c71282214..488c63bd5 100644 --- a/dev/src/main.rs +++ b/dev/src/main.rs @@ -138,8 +138,8 @@ fn build(name: String) { } } -pub fn build_program(name: String) {} -pub fn build_library(name: String) {} +pub fn build_program(_name: String) {} +pub fn build_library(_name: String) {} fn help() { println!( diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml index dc3c3df29..e05259036 100644 --- a/kernel/.cargo/config.toml +++ b/kernel/.cargo/config.toml @@ -4,9 +4,3 @@ build-std-features = ["compiler-builtins-mem"] [build] target = "./targets/x86_64-ableos.json" - -# [target.'cfg(target_arch = "x86_64")'] -# rustflags = [ -# "-C", -#"target-feature=+sse4.1,+avx,+aes,+fma,+popcnt,+bmi2,+avx2,+lzcnt,+xsave", -# ] diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index ff6604b0c..9cbe89565 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -16,7 +16,7 @@ uart_16550 = { version = "0.3", features = ["nightly"] } xml.git = "https://git.ablecorp.us/ableos/ableos_userland" versioning.git = "https://git.ablecorp.us/ableos/ableos_userland" # able_graphics_library.git = "https://git.ablecorp.us/ableos/ableos_userland" -hashbrown = { version = "0.14", features = ["nightly"] } +hashbrown = { version = "0.15", features = ["nightly"] } limine = "0.1" [dependencies.crossbeam-queue] @@ -24,10 +24,6 @@ version = "0.3" default-features = false features = ["alloc", "nightly"] -# [dependencies.clparse] -# git = "https://git.ablecorp.us/ableos/ableos_userland" -# default-features = false - [dependencies.derive_more] version = "1" default-features = false diff --git a/kernel/src/arch/aarch64/logging.rs b/kernel/src/arch/aarch64/logging.rs index 231cf3978..bdf55f587 100644 --- a/kernel/src/arch/aarch64/logging.rs +++ b/kernel/src/arch/aarch64/logging.rs @@ -3,7 +3,7 @@ pub static SERIAL_CONSOLE: Mutex = Mutex::new(SerialConsole { uart: 0x09000000 as *mut u8, }); -struct SerialConsole { +pub struct SerialConsole { uart: *mut u8, } diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 413bde690..d0270ff9b 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -30,6 +30,7 @@ const INITIAL_KERNEL_HEAP_SIZE: *const () = _initial_kernel_heap_size as _; #[no_mangle] #[naked] +#[cfg(not(target_feature = "avx2"))] unsafe extern "C" fn _kernel_start() -> ! { // Initialise SSE, then jump to kernel entrypoint core::arch::asm!( @@ -49,58 +50,59 @@ unsafe extern "C" fn _kernel_start() -> ! { ) } -// #[no_mangle] -// #[naked] -// unsafe extern "C" fn _kernel_start() -> ! { -// core::arch::asm!( -// // Enable protected mode and configure control registers -// "mov rax, cr0", -// "and ax, 0xFFFB", // Clear CR0.EM (bit 2) for coprocessor emulation -// "or ax, 0x2", // Set CR0.MP (bit 1) for coprocessor monitoring -// "mov cr0, rax", +#[no_mangle] +#[naked] +#[cfg(target_feature = "avx2")] +unsafe extern "C" fn _kernel_start() -> ! { + core::arch::asm!( + // Enable protected mode and configure control registers + "mov rax, cr0", + "and ax, 0xFFFB", // Clear CR0.EM (bit 2) for coprocessor emulation + "or ax, 0x2", // Set CR0.MP (bit 1) for coprocessor monitoring + "mov cr0, rax", -// "mov rax, cr4", -// "or ax, (1 << 9) | (1 << 10)", // Set CR4.OSFXSR (bit 9) and CR4.OSXMMEXCPT (bit 10) -// "mov cr4, rax", + "mov rax, cr4", + "or ax, (1 << 9) | (1 << 10)", // Set CR4.OSFXSR (bit 9) and CR4.OSXMMEXCPT (bit 10) + "mov cr4, rax", -// // Enable OSXSAVE (required for AVX, AVX2, and XSAVE) -// "mov rax, cr4", -// "or eax, 1 << 18", // Set CR4.OSXSAVE (bit 18) -// "mov cr4, rax", + // Enable OSXSAVE (required for AVX, AVX2, and XSAVE) + "mov rax, cr4", + "or eax, 1 << 18", // Set CR4.OSXSAVE (bit 18) + "mov cr4, rax", -// // Enable AVX and AVX2 state saving -// "xor rcx, rcx", -// "xgetbv", -// "or eax, 7", // Enable SSE, AVX, and AVX2 state saving -// "xsetbv", + // Enable AVX and AVX2 state saving + "xor rcx, rcx", + "xgetbv", + "or eax, 7", // Enable SSE, AVX, and AVX2 state saving + "xsetbv", -// // Check for AVX and XSAVE support -// "mov eax, 1", -// "cpuid", -// "and ecx, 0x18000000", -// "cmp ecx, 0x18000000", -// "jne {1}", // Jump if AVX/OSXSAVE is not supported + // Check for AVX and XSAVE support + "mov eax, 1", + "cpuid", + "and ecx, 0x18000000", + "cmp ecx, 0x18000000", + "jne {1}", // Jump if AVX/OSXSAVE is not supported -// // Check for BMI2 and AVX2 support -// "mov eax, 7", -// "xor ecx, ecx", -// "cpuid", -// "and ebx, (1 << 8) | (1 << 5)", // Check BMI2 (bit 8) and AVX2 (bit 5) -// "cmp ebx, (1 << 8) | (1 << 5)", // Compare to ensure both are supported + // Check for BMI2 and AVX2 support + "mov eax, 7", + "xor ecx, ecx", + "cpuid", + "and ebx, (1 << 8) | (1 << 5)", // Check BMI2 (bit 8) and AVX2 (bit 5) + "cmp ebx, (1 << 8) | (1 << 5)", // Compare to ensure both are supported -// // Check for LZCNT and POPCNT support -// "mov eax, 1", -// "cpuid", -// "and ecx, (1 << 5) | (1 << 23)", // Check LZCNT (bit 5) and POPCNT (bit 23) -// "cmp ecx, (1 << 5) | (1 << 23)", // Compare to ensure both are supported + // Check for LZCNT and POPCNT support + "mov eax, 1", + "cpuid", + "and ecx, (1 << 5) | (1 << 23)", // Check LZCNT (bit 5) and POPCNT (bit 23) + "cmp ecx, (1 << 5) | (1 << 23)", // Compare to ensure both are supported -// // Jump to the kernel entry point -// "jmp {0}", -// sym start, -// sym oops, -// options(noreturn), -// ) -// } + // Jump to the kernel entry point + "jmp {0}", + sym start, + sym oops, + options(noreturn), + ) +} unsafe extern "C" fn oops() -> ! { panic!("your cpu is ancient >:(") @@ -249,6 +251,7 @@ unsafe extern "C" fn start() -> ! { /// Spin loop pub fn spin_loop() -> ! { loop { + core::hint::spin_loop(); x86_64::instructions::hlt() } } diff --git a/kernel/src/holeybytes/ecah.rs b/kernel/src/holeybytes/ecah.rs index 8d6769272..ab45e643c 100644 --- a/kernel/src/holeybytes/ecah.rs +++ b/kernel/src/holeybytes/ecah.rs @@ -26,9 +26,6 @@ unsafe fn x86_in(address: u16) -> T { #[inline(always)] pub fn handler(vm: &mut Vm) { let ecall_number = vm.registers[2].cast::(); - // log::info!("eca called :pensive:"); - // debug!("Ecall number {:?}", ecall_number); - //info!("Register dump: {:?}", vm.registers); match ecall_number { 0 => { @@ -97,7 +94,8 @@ pub fn handler(vm: &mut Vm) { match msg_type { 0 => unsafe { let size = msg_vec[1]; - let addr = u16::from_le_bytes(msg_vec[2..4].try_into().unwrap()); + let addr = + u16::from_le_bytes(msg_vec[2..4].try_into().unwrap_unchecked()); let value = match size { 0 => x86_in::(addr) as u64, 1 => x86_in::(addr) as u64, @@ -109,7 +107,8 @@ pub fn handler(vm: &mut Vm) { }, 1 => unsafe { let size = msg_vec[1]; - let addr = u16::from_le_bytes(msg_vec[2..4].try_into().unwrap()); + let addr = + u16::from_le_bytes(msg_vec[2..4].try_into().unwrap_unchecked()); // info!("Setting address {}", addr); match size { @@ -132,9 +131,13 @@ pub fn handler(vm: &mut Vm) { 3 => unimplemented!("TODO: implement whatever buffer 3 does for no x86_64"), // source of rng 4 => { - // limit to last 32 bits - vm.registers[1] = - hbvm::value::Value(crate::arch::hardware_random_u64() & 0xFFFFFFFF); + let block = block_read(mem_addr, length); + block.chunks_mut(8.min(length)).for_each(|chunk| { + chunk.clone_from_slice( + &crate::arch::hardware_random_u64().to_le_bytes()[..chunk.len()], + ); + }); + vm.registers[1] = hbvm::value::Value(mem_addr); } 5 => match dt_msg_handler(vm, mem_addr, length) { Ok(()) => {} @@ -173,7 +176,7 @@ pub fn handler(vm: &mut Vm) { Ok(msg) => msg, Err(_) => return, }; - if msg.len() > max_length.try_into().unwrap() { + if msg.len() > unsafe { max_length.try_into().unwrap_unchecked() } { info!("{}", max_length); error!("Message is too long to map in."); } else { @@ -205,15 +208,3 @@ pub enum LogError { NoMessages, InvalidLogFormat, } - -// use {alloc::vec, log::Record}; -// fn memory_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> { -// let mut val = alloc::vec::Vec::new(); -// for _ in 0..4096 { -// val.push(0); -// } -// info!("Block address: {:?}", val.as_ptr()); -// vm.registers[1] = hbvm::value::Value(val.as_ptr() as u64); -// vm.registers[2] = hbvm::value::Value(4096); -// Ok(()) -// } diff --git a/kernel/src/holeybytes/kernel_services/logging_service.rs b/kernel/src/holeybytes/kernel_services/logging_service.rs index a0b461f91..b1fbf4ae6 100644 --- a/kernel/src/holeybytes/kernel_services/logging_service.rs +++ b/kernel/src/holeybytes/kernel_services/logging_service.rs @@ -9,12 +9,16 @@ use log::Record; pub fn log_msg_handler(_vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> { let msg_vec = block_read(mem_addr, length); - let log_level = msg_vec.last().unwrap(); + let log_level = msg_vec[0]; + let strptr = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()); + let strlen = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as usize; + + let str = block_read(strptr, strlen); let file_name = "None"; let line_number = 0; - match core::str::from_utf8(&msg_vec[..msg_vec.len()]) { + match core::str::from_utf8(&str) { Ok(strr) => { use log::Level::*; let log_level = match log_level { diff --git a/kernel/src/holeybytes/kernel_services/mem_serve.rs b/kernel/src/holeybytes/kernel_services/mem_serve.rs index 935ca9ba3..b7693907a 100644 --- a/kernel/src/holeybytes/kernel_services/mem_serve.rs +++ b/kernel/src/holeybytes/kernel_services/mem_serve.rs @@ -17,13 +17,54 @@ pub enum MemoryQuotaType { } fn alloc_page(vm: &mut Vm, _mem_addr: u64, _length: usize) -> Result<(), MemoryServiceError> { - let ptr = unsafe { alloc(Layout::from_size_align_unchecked(4096, 4096)) }; + let ptr = unsafe { alloc(Layout::from_size_align_unchecked(4096, 8)) }; info!("Block address: {:?}", ptr); vm.registers[1] = hbvm::value::Value(ptr as u64); vm.registers[2] = hbvm::value::Value(4096); Ok(()) } +#[inline(always)] +unsafe fn memset(mut dest: *mut u8, src: *const u8, count: usize, size: usize) { + const BLOCK_SIZE: usize = 64; + let mut remaining = count * size; + + if remaining < 16 { + src.copy_to_nonoverlapping(dest, remaining); + return; + } + + let mut buffer = [0u8; BLOCK_SIZE]; + let mut buffer_size = size; + src.copy_to_nonoverlapping(buffer.as_mut_ptr(), size); + + while core::intrinsics::likely(buffer_size * 2 <= BLOCK_SIZE) { + buffer + .as_mut_ptr() + .copy_to_nonoverlapping(buffer.as_mut_ptr().add(buffer_size), buffer_size); + buffer_size *= 2; + } + + let buffer_ptr = buffer.as_ptr() as *const u64; + + while (dest as usize) & 7 != 0 && remaining >= 8 { + buffer.as_ptr().copy_to_nonoverlapping(dest, 1); + dest = dest.add(1); + remaining -= 1; + } + + while core::intrinsics::likely(remaining >= 8) { + *(dest as *mut u64) = *buffer_ptr; + dest = dest.add(8); + remaining -= 8; + } + + if remaining > 0 { + buffer.as_ptr().copy_to_nonoverlapping(dest, remaining); + } +} + +#[inline(always)] pub fn memory_msg_handler( vm: &mut Vm, mem_addr: u64, @@ -32,40 +73,35 @@ pub fn memory_msg_handler( let msg_vec = block_read(mem_addr, length); let msg_type = msg_vec[0]; match msg_type { - 0 => { + 0 => unsafe { let page_count = msg_vec[1]; - let mptr_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap(); - let mptr: u64 = u64::from_le_bytes(mptr_raw); - log::debug!("Allocating {} pages @ {:x}", page_count, mptr); + let ptr = alloc(Layout::from_size_align_unchecked( + page_count as usize * 4096, + 8, + )); - let ptr = unsafe { - alloc(Layout::from_size_align_unchecked( - page_count as usize * 4096, - 4096, - )) - }; + log::debug!("Allocating {} pages @ {:x}", page_count, ptr as u64); vm.registers[1] = hbvm::value::Value(ptr as u64); log::debug!("Kernel ptr: {:x}", ptr as u64); - } + }, - 1 => { + 1 => unsafe { let page_count = msg_vec[1]; let mptr_raw: [u8; 8] = msg_vec[2..10].try_into().unwrap(); let mptr: u64 = u64::from_le_bytes(mptr_raw); log::debug!("Deallocating {} pages @ {:x}", page_count, mptr); - unsafe { - dealloc( - mptr as *mut u8, - Layout::from_size_align_unchecked(page_count as usize * 4096, 4096), - ) - } - } + + dealloc( + mptr as *mut u8, + Layout::from_size_align_unchecked(page_count as usize * 4096, 8), + ) + }, 2 => { use MemoryQuotaType::*; - let quota_type = match msg_vec[0] { + let quota_type = match msg_vec[1] { 0 => NoQuota, 1 => SoftQuota, 2 => HardQuota, @@ -82,10 +118,24 @@ pub fn memory_msg_handler( ) } 3 => { - let page_count = msg_vec[0]; + let page_count = msg_vec[1]; log::debug!(" {} pages", page_count); } + 4 => unsafe { + let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize; + let src = u64::from_le_bytes(msg_vec[5..13].try_into().unwrap_unchecked()) as *const u8; + let dest = u64::from_le_bytes(msg_vec[13..21].try_into().unwrap_unchecked()) as *mut u8; + src.copy_to_nonoverlapping(dest, count); + }, + 5 => unsafe { + let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize; + let size = u32::from_le_bytes(msg_vec[5..9].try_into().unwrap_unchecked()) as usize; + let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8; + let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8; + + memset(dest, src, count, size); + }, _ => { log::debug!("Unknown memory service message type: {}", msg_type); } diff --git a/kernel/src/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs index 52f37ad69..7cf03ecc2 100644 --- a/kernel/src/holeybytes/kernel_services/service_definition_service.rs +++ b/kernel/src/holeybytes/kernel_services/service_definition_service.rs @@ -22,21 +22,19 @@ pub enum ServiceError { pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), ServiceError> { let msg_vec = block_read(mem_addr, length); let sds_event_type: ServiceEventType = msg_vec[0].into(); - - // info!("Length {}", msg_vec.len()); + let strptr = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()); + let strlen = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as usize; + let string_vec = block_read(strptr, strlen); + let string = core::str::from_utf8(string_vec).expect("Our bytes should be valid utf8"); use ServiceEventType::*; match sds_event_type { CreateService => { - let string = - core::str::from_utf8(&msg_vec[1..]).expect("Our bytes should be valid utf8"); let ret = sds_create_service(string); vm.registers[1] = hbvm::value::Value(ret as u64); } DeleteService => todo!(), SearchServices => { - let string = - core::str::from_utf8(&msg_vec[1..]).expect("Our bytes should be valid utf8"); let ret = sds_search_service(string); vm.registers[1] = hbvm::value::Value(ret as u64); } diff --git a/kernel/src/holeybytes/mem.rs b/kernel/src/holeybytes/mem.rs index 79a361491..94d65833f 100644 --- a/kernel/src/holeybytes/mem.rs +++ b/kernel/src/holeybytes/mem.rs @@ -37,7 +37,6 @@ impl hbvm::mem::Memory for Memory { target: *mut u8, count: usize, ) -> Result<(), hbvm::mem::LoadError> { - // if addr.get() % 4096 == 0 {} core::ptr::copy_nonoverlapping(addr.get() as *const u8, target, count); Ok(()) } diff --git a/kernel/src/holeybytes/mod.rs b/kernel/src/holeybytes/mod.rs index 9b9a1d27d..42e4812db 100644 --- a/kernel/src/holeybytes/mod.rs +++ b/kernel/src/holeybytes/mod.rs @@ -97,7 +97,7 @@ impl HandlePageFault for PageFaultHandler { #[inline(always)] const fn stack_layout() -> Layout { - unsafe { Layout::from_size_align_unchecked(STACK_SIZE, 4096) } + unsafe { Layout::from_size_align_unchecked(STACK_SIZE, 8) } } #[inline(always)] diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 9a8060bce..a94f94b11 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -6,6 +6,7 @@ slice_split_once, exclusive_wrapper, new_uninit, + core_intrinsics, abi_x86_interrupt, alloc_error_handler, ptr_sub_ptr, @@ -14,8 +15,7 @@ pointer_is_aligned_to )] #![test_runner(crate::test_runner)] -#![cfg_attr(not(debug_assertions), allow(unused, deprecated))] -#![allow(dead_code)] +#![allow(dead_code, internal_features)] extern crate alloc; mod allocator; diff --git a/kernel/src/logger.rs b/kernel/src/logger.rs index fd9cc4a5c..d1bd6e1c2 100644 --- a/kernel/src/logger.rs +++ b/kernel/src/logger.rs @@ -36,13 +36,26 @@ impl log::Log for Logger { Level::Debug => "25", Level::Trace => "103", }; - let module = record.module_path().unwrap_or_default(); - let line = record.line().unwrap_or_default(); - crate::arch::log(format_args!( - "\x1b[38;5;{lvl_color}m{lvl}\x1b[0m [{module}:{line}]: {}\r\n", - record.args(), - )) - .expect("write to serial console"); + let module = record + .module_path() + .unwrap_or_default() + .rsplit_once(':') + .unwrap_or_default() + .1; + if module == "" { + crate::arch::log(format_args!( + "\x1b[38;5;{lvl_color}m{lvl}\x1b[0m: {}\r\n", + record.args(), + )) + .expect("write to serial console"); + } else { + let line = record.line().unwrap_or_default(); + crate::arch::log(format_args!( + "\x1b[38;5;{lvl_color}m{lvl}\x1b[0m [{module}:{line}]: {}\r\n", + record.args(), + )) + .expect("write to serial console"); + } } fn flush(&self) {} diff --git a/kernel/targets/x86_64-v3-ableos.json b/kernel/targets/x86_64_v3-ableos.json similarity index 100% rename from kernel/targets/x86_64-v3-ableos.json rename to kernel/targets/x86_64_v3-ableos.json diff --git a/known_bugs.md b/known_bugs.md new file mode 100644 index 000000000..bdb8fca0f --- /dev/null +++ b/known_bugs.md @@ -0,0 +1,2 @@ +# i did not know where to put this +- memcpy / memset cause crash on debug builds due to ptr misalignment that is not present on release builds \ No newline at end of file diff --git a/repbuild/Cargo.toml b/repbuild/Cargo.toml index 4d7abaada..2b7fc845f 100644 --- a/repbuild/Cargo.toml +++ b/repbuild/Cargo.toml @@ -6,26 +6,15 @@ edition = "2021" [dependencies] str-reader = "0.1" derive_more = { version = "1", default-features = false, features = [ - "add", - "add_assign", - "constructor", "display", - "from", - "into", - "mul", - "mul_assign", - "not", - "sum", ] } error-stack = "0.5" -fatfs = "0.3" +fatfs = { version = "0.3", default-features = false, features = [ + "std", + "alloc", +] } toml = "0.8" -# hbasm.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git" hblang.git = "https://git.ablecorp.us/AbleOS/holey-bytes.git" log = "0.4" raw-cpuid = "11" - -[dependencies.reqwest] -version = "0.12" -default-features = false -features = ["rustls-tls", "blocking"] +ureq = { version = "2", default-features = false, features = ["tls"] } diff --git a/repbuild/src/dev.rs b/repbuild/src/dev.rs index 2e8122889..91c464477 100644 --- a/repbuild/src/dev.rs +++ b/repbuild/src/dev.rs @@ -47,7 +47,6 @@ impl Package { for (count, (name, table)) in bin_table.into_iter().enumerate() { // if count != 0 { - println!("{}", name); binaries.push(name.clone()); // } } @@ -63,40 +62,49 @@ impl Package { build_cmd, } } - pub fn build(&self) { + pub fn build(&self, out: &mut Vec) -> std::io::Result<()> { if self.binaries.contains(&"hblang".to_string()) { let file = self.build_cmd.split_ascii_whitespace().last().unwrap(); let path = format!("sysdata/programs/{}/{}", self.name, file); - let mut bytes = Vec::new(); // compile here - let _ = hblang::run_compiler( + hblang::run_compiler( &path, Options { fmt: true, ..Default::default() }, - &mut bytes, - ); - let _ = hblang::run_compiler(&path, Default::default(), &mut bytes); + out, + )?; match std::fs::create_dir("target/programs") { Ok(_) => (), Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => (), Err(e) => panic!("{}", e), } - std::fs::write(format!("target/programs/{}.hbf", self.name), &bytes).unwrap(); - bytes.clear(); - let _ = hblang::run_compiler( + + hblang::run_compiler( + &path, + Options { + ..Default::default() + }, + out, + )?; + std::fs::write(format!("target/programs/{}.hbf", self.name), &out)?; + out.clear(); + + hblang::run_compiler( &path, Options { dump_asm: true, ..Default::default() }, - &mut bytes, - ); - std::fs::write(format!("target/programs/{}.hba", self.name), &bytes).unwrap(); + out, + )?; + std::fs::write(format!("target/programs/{}.hba", self.name), &out)?; + out.clear(); } + Ok(()) } } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 4420c29e2..39569a92d 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -1,14 +1,12 @@ -// #![allow(unused)] - mod dev; use { + core::fmt::Write as _, derive_more::Display, dev::Package, error_stack::{bail, report, Context, Report, Result, ResultExt}, fatfs::{FileSystem, FormatVolumeOptions, FsOptions, ReadWriteSeek}, std::{ - // fmt::Display, fs::{self, File}, io::{self, Write}, path::Path, @@ -38,6 +36,8 @@ fn main() -> Result<(), Error> { target = Target::Riscv64Virt; } else if arg == "arm64" || arg == "aarch64" || arg == "aarch64-virt" { target = Target::Aarch64; + } else if arg == "avx2" { + target = Target::X86_64Avx2; } else { return Err(report!(Error::InvalidSubCom)); } @@ -61,6 +61,8 @@ fn main() -> Result<(), Error> { target = Target::Aarch64; } else if arg == "--noaccel" { do_accel = false; + } else if arg == "avx2" { + target = Target::X86_64Avx2; } else { return Err(report!(Error::InvalidSubCom)); } @@ -80,7 +82,7 @@ fn main() -> Result<(), Error> { " -r / --release: build in release mode\n", " -d / --debuginfo: build with debug info\n", " --noaccel: run without acceleration (e.g, no kvm)\n", - "[ rv64 / riscv64 / riscv64-virt / aarch64 / arm64 / aarch64-virt ]: sets target" + "[ rv64 / riscv64 / riscv64-virt / aarch64 / arm64 / aarch64-virt / avx2 ]: sets target" ),); Ok(()) } @@ -203,21 +205,43 @@ TERM_BACKDROP={} let modules = value.get_mut("modules").unwrap().as_table_mut().unwrap(); // let mut real_modules = modules.clone(); - modules.into_iter().for_each(|(_, value)| { - if value.is_table() { - let path = get_path_without_boot_prefix( - value.get("path").expect("You must have `path` as a value"), - ) - .unwrap() - .split(".") - .next() - .unwrap(); - let p = Package::load_from_file( - format!("sysdata/programs/{}/meta.toml", path).to_owned(), - ); - p.build(); - } - }); + let mut errors = String::new(); + let mut out = Vec::new(); + + modules + .into_iter() + .map(|(_, value)| -> Result<(), io::Error> { + if value.is_table() { + let path = get_path_without_boot_prefix( + value.get("path").expect("You must have `path` as a value"), + ) + .unwrap() + .split(".") + .next() + .unwrap(); + let p = Package::load_from_file( + format!("sysdata/programs/{}/meta.toml", path).to_owned(), + ); + match p.build(&mut out) { + Ok(()) => {} + Err(_) => { + writeln!(errors, "========= while compiling {} =========", path) + .unwrap(); + errors.push_str(core::str::from_utf8(&out).expect("no")); + out.clear(); + } + } + } + Ok(()) + }) + .for_each(drop); + + if !errors.is_empty() { + let _ = writeln!(errors, "!!! STOPPING DUE TO PREVIOUS ERRORS !!!"); + std::eprint!("{errors}"); + continue; + } + modules.into_iter().for_each(|(_key, value)| { if value.is_table() { let path = value.get("path").expect("You must have `path` as a value"); @@ -304,6 +328,9 @@ fn build(release: bool, target: Target, debuginfo: bool) -> Result<(), Error> { if target == Target::Aarch64 { com.args(["--target", "targets/aarch64-virt-ableos.json"]); } + if target == Target::X86_64Avx2 { + com.args(["--target", "targets/x86_64_v3-ableos.json"]); + } match com.status() { Ok(s) if s.code() != Some(0) => bail!(Error::Build), @@ -317,6 +344,10 @@ fn build(release: bool, target: Target, debuginfo: bool) -> Result<(), Error> { path.push_str("_x86-64"); "target/x86_64-ableos" } + Target::X86_64Avx2 => { + path.push_str("_x86-64"); + "target/x86_64_v3-ableos" + } Target::Riscv64Virt => "target/riscv64-virt-ableos", Target::Aarch64 => { path.push_str("_aarch64"); @@ -341,7 +372,7 @@ fn build(release: bool, target: Target, debuginfo: bool) -> Result<(), Error> { fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> { let target_str = match target { - Target::X86_64 => "qemu-system-x86_64", + Target::X86_64 | Target::X86_64Avx2 => "qemu-system-x86_64", Target::Riscv64Virt => "qemu-system-riscv64", Target::Aarch64 => "qemu-system-aarch64", }; @@ -384,23 +415,19 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> { }; match target { - Target::X86_64 => { + Target::X86_64 | Target::X86_64Avx2 => { #[rustfmt::skip] com.args([ "-bios", &ovmf_path.change_context(Error::OvmfFetch)?, "-drive", "file=target/disk.img,format=raw", "-device", "vmware-svga", + // "-serial", "stdio", "-m", "2G", "-smp", "1", "-parallel", "none", "-monitor", "none", "-machine", accel, - "-cpu", - if accel != "accel=tcg" { - "host" - } else { - "Broadwell-v4" - }, + "-cpu", "max", "-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", ]); } @@ -445,7 +472,7 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> { fn fetch_ovmf(target: Target) -> Result { let (ovmf_url, ovmf_path) = match target { - Target::X86_64 => ( + Target::X86_64 | Target::X86_64Avx2 => ( "https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd", "target/RELEASEX64_OVMF.fd", ), @@ -467,12 +494,12 @@ fn fetch_ovmf(target: Target) -> Result { Ok(_) => return Ok(ovmf_path.to_owned()), Err(e) => return Err(report!(e).change_context(OvmfFetchError::Io)), }; - let mut bytes = reqwest::blocking::get(ovmf_url) + let req = ureq::get(ovmf_url) + .call() .map_err(Report::from) .change_context(OvmfFetchError::Fetch)?; - bytes - .copy_to(&mut file) + std::io::copy(&mut req.into_reader(), &mut file) .map_err(Report::from) .change_context(OvmfFetchError::Io)?; @@ -494,6 +521,7 @@ impl Context for OvmfFetchError {} #[derive(Clone, Copy, PartialEq, Eq)] enum Target { X86_64, + X86_64Avx2, Riscv64Virt, Aarch64, } diff --git a/sysdata/assets/able.bmp b/sysdata/assets/able.bmp new file mode 100644 index 000000000..059086b3f Binary files /dev/null and b/sysdata/assets/able.bmp differ diff --git a/sysdata/assets/consolefonts/tamsyn/10x20b.psf b/sysdata/assets/consolefonts/tamsyn/10x20b.psf new file mode 100644 index 000000000..4a582d9ed Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/10x20b.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/10x20r.psf b/sysdata/assets/consolefonts/tamsyn/10x20r.psf new file mode 100644 index 000000000..e9222b77d Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/10x20r.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/5x9b.psf b/sysdata/assets/consolefonts/tamsyn/5x9b.psf new file mode 100644 index 000000000..cc3ade7b8 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/5x9b.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/5x9r.psf b/sysdata/assets/consolefonts/tamsyn/5x9r.psf new file mode 100644 index 000000000..185806c55 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/5x9r.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/6x12b.psf b/sysdata/assets/consolefonts/tamsyn/6x12b.psf new file mode 100644 index 000000000..4ae9d6a44 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/6x12b.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/6x12r.psf b/sysdata/assets/consolefonts/tamsyn/6x12r.psf new file mode 100644 index 000000000..1373ec252 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/6x12r.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/7x13b.psf b/sysdata/assets/consolefonts/tamsyn/7x13b.psf new file mode 100644 index 000000000..4ec3ee59e Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/7x13b.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/7x13r.psf b/sysdata/assets/consolefonts/tamsyn/7x13r.psf new file mode 100644 index 000000000..380702de2 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/7x13r.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/7x14b.psf b/sysdata/assets/consolefonts/tamsyn/7x14b.psf new file mode 100644 index 000000000..a473750d7 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/7x14b.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/7x14r.psf b/sysdata/assets/consolefonts/tamsyn/7x14r.psf new file mode 100644 index 000000000..1ce5d8e9c Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/7x14r.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/8x15b.psf b/sysdata/assets/consolefonts/tamsyn/8x15b.psf new file mode 100644 index 000000000..6219e9958 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/8x15b.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/8x15r.psf b/sysdata/assets/consolefonts/tamsyn/8x15r.psf new file mode 100644 index 000000000..0054a2b4f Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/8x15r.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/8x16b.psf b/sysdata/assets/consolefonts/tamsyn/8x16b.psf new file mode 100644 index 000000000..4eb9107d3 Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/8x16b.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/8x16r.psf b/sysdata/assets/consolefonts/tamsyn/8x16r.psf new file mode 100644 index 000000000..6fd82c17f Binary files /dev/null and b/sysdata/assets/consolefonts/tamsyn/8x16r.psf differ diff --git a/sysdata/assets/consolefonts/tamsyn/LICENSE b/sysdata/assets/consolefonts/tamsyn/LICENSE new file mode 100644 index 000000000..8fc49609d --- /dev/null +++ b/sysdata/assets/consolefonts/tamsyn/LICENSE @@ -0,0 +1,10 @@ +Tamsyn font is free. You are hereby granted permission to use, copy, modify, +and distribute it as you see fit. + +Tamsyn font is provided "as is" without any express or implied warranty. + +The author makes no representations about the suitability of this font for +a particular purpose. + +In no event will the author be held liable for damages arising from the use +of this font. diff --git a/sysdata/assets/mini.bmp b/sysdata/assets/mini.bmp new file mode 100644 index 000000000..49cfcd268 Binary files /dev/null and b/sysdata/assets/mini.bmp differ diff --git a/sysdata/assets/mini.qoi b/sysdata/assets/mini.qoi new file mode 100644 index 000000000..3e42d0237 Binary files /dev/null and b/sysdata/assets/mini.qoi differ diff --git a/sysdata/assets/wallpaper.qoi b/sysdata/assets/wallpaper.qoi new file mode 100644 index 000000000..76dc853ba Binary files /dev/null and b/sysdata/assets/wallpaper.qoi differ diff --git a/sysdata/libraries/dt_api/README.md b/sysdata/libraries/dt_api/README.md deleted file mode 100644 index 61d4547fe..000000000 --- a/sysdata/libraries/dt_api/README.md +++ /dev/null @@ -1 +0,0 @@ -# dt_api \ No newline at end of file diff --git a/sysdata/libraries/dt_api/src/lib.hb b/sysdata/libraries/dt_api/src/lib.hb deleted file mode 100644 index 8f2dffe38..000000000 --- a/sysdata/libraries/dt_api/src/lib.hb +++ /dev/null @@ -1,6 +0,0 @@ -.{string} := @use("../../stn/src/lib.hb") - -dt_get := fn(query: ^u8): int { - length := string.length(query) - return @eca(3, 5, query, length) -} \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/examples/horizontal.lui b/sysdata/libraries/horizon_api/examples/horizontal.lui new file mode 100644 index 000000000..895478097 --- /dev/null +++ b/sysdata/libraries/horizon_api/examples/horizontal.lui @@ -0,0 +1,4 @@ +(horizontal + spacing : 10 + (label "hi") + (label "goodbye")) \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/examples/label.lui b/sysdata/libraries/horizon_api/examples/label.lui new file mode 100644 index 000000000..6db625c9e --- /dev/null +++ b/sysdata/libraries/horizon_api/examples/label.lui @@ -0,0 +1 @@ +(label "hello") diff --git a/sysdata/libraries/horizon_api/examples/vertical.lui b/sysdata/libraries/horizon_api/examples/vertical.lui new file mode 100644 index 000000000..ee6a40138 --- /dev/null +++ b/sysdata/libraries/horizon_api/examples/vertical.lui @@ -0,0 +1,3 @@ +(vertical + (label "hello") + (label "hello" color:red)) \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/lib.hb b/sysdata/libraries/horizon_api/src/lib.hb index c3a53ff60..112bbac3a 100644 --- a/sysdata/libraries/horizon_api/src/lib.hb +++ b/sysdata/libraries/horizon_api/src/lib.hb @@ -1,25 +1,49 @@ stn := @use("../../stn/src/lib.hb"); -.{string, memory, buffer} := stn +.{string, memory, buffer, log} := stn + +render := @use("../../../libraries/render/src/lib.hb") input := @use("../../intouch/src/lib.hb") +widgets := @use("widgets/widgets.hb") +ui := @use("ui.hb") + WindowID := struct { host_id: int, window_id: int, } -create_window := fn(channel: int): void { +VoidWindowID := WindowID.(0, 0) + +create_window := fn(channel: int): ^render.Surface { // get the horizon buffer // request a new window and provide the callback buffer // wait to recieve a message windowing_system_buffer := buffer.search("XHorizon\0") + mem_buf := memory.request_page(1) if windowing_system_buffer == 0 { - return + return @as(^render.Surface, idk) } else { - msg := "\{01}\0" - msg_length := 2 - return @eca(3, windowing_system_buffer, msg, msg_length) + // ! bad able, stop using string messages :ragey: + // msg := "\{01}\0" + // msg_length := 2 + + // @as(void, @eca(3, windowing_system_buffer, msg, msg_length)) + + x := 0 + loop if x > 1000 break else x += 1 + + ret := buffer.recv([u8; 4096], windowing_system_buffer, mem_buf) + if ret == null { + log.info("No messages\0") + } + + if *mem_buf == 0 { + log.info("No messages\0") + } + + return @as(^render.Surface, idk) } } \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/ui.hb b/sysdata/libraries/horizon_api/src/ui.hb new file mode 100644 index 000000000..e6512a1d3 --- /dev/null +++ b/sysdata/libraries/horizon_api/src/ui.hb @@ -0,0 +1,47 @@ +stn := @use("../../../libraries/stn/src/lib.hb"); +.{string, log} := stn; +.{Vec2} := stn.math + +render := @use("../../../libraries/render/src/lib.hb"); +.{Surface} := render; +.{Font} := render.text + +UI := struct {raw: ^u8, raw_length: uint, is_dirty: bool, surface: Surface, // Each child has their WidgetType as their first byte +// children: ^^u8, +} + +render_ui := fn(surface: Surface, ui: UI): void { + if ui.is_dirty { + render.clear(ui.surface, render.black) + ui.is_dirty = false + } + pos := Vec2(uint).(0, 0) + render.put_surface(surface, ui.surface, pos, false) +} + +sexpr_parser := fn(sexpr: ^u8): UI { + cursor := sexpr + paren_balance := 0 + loop { + if *cursor == 0 { + if paren_balance != 0 { + log.error("Unbalanced Parens\0") + } + break + } else if *cursor == 40 { + log.info("Open paren\0") + paren_balance += 1 + } else if *cursor == 41 { + log.info("Closed paren\0") + paren_balance -= 1 + } + + cursor += 1 + } + + length := string.length(sexpr) + + ui_surface := render.new_surface(100, 100) + + return UI.(sexpr, length, true, ui_surface) +} \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/widgets/image.hb b/sysdata/libraries/horizon_api/src/widgets/image.hb new file mode 100644 index 000000000..b686aa8ea --- /dev/null +++ b/sysdata/libraries/horizon_api/src/widgets/image.hb @@ -0,0 +1,13 @@ +render := @use("../../../../libraries/render/src/lib.hb"); +.{Surface} := render + +Image := struct { + magic: uint, + is_dirty: bool, + surface: Surface, +} + +image_from_surface := fn(surface: Surface): Image { + img := Image.(4, true, surface) + return img +} \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/widgets/label.hb b/sysdata/libraries/horizon_api/src/widgets/label.hb new file mode 100644 index 000000000..106e452c2 --- /dev/null +++ b/sysdata/libraries/horizon_api/src/widgets/label.hb @@ -0,0 +1,38 @@ +stn := @use("../../../../libraries/stn/src/lib.hb"); +.{string, log} := stn; +.{Vec2} := stn.math + +render := @use("../../../../libraries/render/src/lib.hb"); +.{Surface} := render; +.{Font} := render.text + +Label := struct { + magic: uint, + is_dirty: bool, + surface: Surface, + text: ^u8, + text_length: uint, +} + +set_label_text := fn(label: Label, text: ^u8): void { + text_length := string.length(text) + + label.is_dirty = true + label.text = text + label.text_length = text_length +} + +render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void { + if label.is_dirty { + render.clear(label.surface, render.black) + render.put_text(label.surface, font, .(0, 0), render.white, label.text) + } + render.put_surface(surface, label.surface, pos, false) +} + +new_label := fn(text: ^u8): Label { + text_surface := render.new_surface(1024, 20) + text_length := string.length(text) + label := Label.(3, true, text_surface, text, text_length) + return label +} \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/widgets/widget_types.hb b/sysdata/libraries/horizon_api/src/widgets/widget_types.hb new file mode 100644 index 000000000..97ddcb80c --- /dev/null +++ b/sysdata/libraries/horizon_api/src/widgets/widget_types.hb @@ -0,0 +1,7 @@ +NoWidget := 0 + +VerticalWidgetType := 1 +HorizontalWidgetType := 2 + +LabelWidgetType := 3 +ImageWidgetType := 4 \ No newline at end of file diff --git a/sysdata/libraries/horizon_api/src/widgets/widgets.hb b/sysdata/libraries/horizon_api/src/widgets/widgets.hb new file mode 100644 index 000000000..cb15cbbb3 --- /dev/null +++ b/sysdata/libraries/horizon_api/src/widgets/widgets.hb @@ -0,0 +1,36 @@ +// Widget types + +// End types +stn := @use("../../../../libraries/stn/src/lib.hb"); +.{string, log} := stn; +.{Vec2} := stn.math + +render := @use("../../../../libraries/render/src/lib.hb"); +.{Surface} := render; +.{Font} := render.text + +widget_types := @use("widget_types.hb") +label := @use("label.hb") +image := @use("image.hb") + +Size := struct { + min_width: int, + max_width: int, + min_height: int, + max_height: int, +} + +Vertical := packed struct { + magic: uint, + // array of children, idk + // use a vec or linked list or whatever + + children: ^^u8, +} + +Horizontal := packed struct { + magic: uint, + // array of children, idk + // use a vec or linked list or whatever + children: ^^u8, +} \ No newline at end of file diff --git a/sysdata/libraries/ignim/src/application.hb b/sysdata/libraries/ignim/src/application.hb index f3f22d837..4837740dd 100644 --- a/sysdata/libraries/ignim/src/application.hb +++ b/sysdata/libraries/ignim/src/application.hb @@ -7,7 +7,7 @@ ApplicationInfo := struct { pNext: ^int, application_name: ^u8, application_version: int, - engine_name: int, + engine_name: ^u8, engine_version: int, api_version: int, } diff --git a/sysdata/libraries/intouch/src/events.hb b/sysdata/libraries/intouch/src/events.hb new file mode 100644 index 000000000..c26fb958a --- /dev/null +++ b/sysdata/libraries/intouch/src/events.hb @@ -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 := packed struct { + x_change: i8, + y_change: i8, + left: bool, + middle: bool, + right: bool, +} + +GamepadEvent := struct {} \ No newline at end of file diff --git a/sysdata/libraries/intouch/src/keycodes.hb b/sysdata/libraries/intouch/src/keycodes.hb index b5fbc3dca..cdab92f1a 100644 --- a/sysdata/libraries/intouch/src/keycodes.hb +++ b/sysdata/libraries/intouch/src/keycodes.hb @@ -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 -// https://www.libsdl.org/release/SDL-1.2.15/include/SDL_keysym.h -Backspace := KeyCode.(8) -Tab := KeyCode.(9) -Clear := KeyCode.(12) -Return := KeyCode.(13) -Pause := KeyCode.(19) -Escape := KeyCode.(27) -Space := KeyCode.(32) +// Typically this is not a keycode you will ever recieve. +None := KeyCode.(0) -A := KeyCode.(97) -/* -ETC -*/ -Z := KeyCode.(122) +Escape := KeyCode.(1) +/* Alphabet keycodes */ -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) -/* -ETC -*/ +/* Numeric keycodes*/ -KeypadNumber0 := KeyCode.(256) -KeypadNumber1 := KeyCode.(257) -KeypadNumber2 := KeyCode.(258) -KeypadNumber3 := KeyCode.(259) -KeypadNumber4 := KeyCode.(260) -KeypadNumber5 := KeyCode.(261) -KeypadNumber6 := KeyCode.(262) -KeypadNumber7 := KeyCode.(263) -KeypadNumber8 := KeyCode.(264) -KeypadNumber9 := KeyCode.(265) +Number0 := KeyCode.(28) +Number1 := KeyCode.(29) +Number2 := KeyCode.(30) +Number3 := KeyCode.(31) +Number4 := KeyCode.(32) +Number5 := KeyCode.(33) +Number6 := KeyCode.(34) +Number7 := KeyCode.(35) +Number8 := KeyCode.(36) +Number9 := KeyCode.(37) -KeypadPeriod := KeyCode.(266) -KeypadDivide := KeyCode.(267) -KeypadMultiply := KeyCode.(268) -KeypadMinus := KeyCode.(269) -KeypadPlus := KeyCode.(270) -KeypadEnter := KeyCode.(271) -KeypadEquals := KeyCode.(272) +KeypadNumber0 := KeyCode.(38) +KeypadNumber1 := KeyCode.(39) +KeypadNumber2 := KeyCode.(40) +KeypadNumber3 := KeyCode.(41) +KeypadNumber4 := KeyCode.(42) +KeypadNumber5 := KeyCode.(43) +KeypadNumber6 := KeyCode.(44) +KeypadNumber7 := KeyCode.(45) +KeypadNumber8 := KeyCode.(46) +KeypadNumber9 := KeyCode.(47) -NumLock := KeyCode.(300) -CapsLock := KeyCode.(301) -ScrollLock := KeyCode.(302) +KeypadPeriod := KeyCode.(48) +KeypadDivide := KeyCode.(49) +KeypadMultiply := KeyCode.(50) +KeypadMinus := KeyCode.(51) +KeypadPlus := KeyCode.(52) +KeypadEnter := KeyCode.(53) +KeypadEquals := KeyCode.(54) -RightShift := KeyCode.(303) -LeftShift := KeyCode.(304) - -RightControl := KeyCode.(305) -LeftControl := KeyCode.(306) -RightAlt := KeyCode.(307) -LeftAlt := KeyCode.(308) -RightMeta := KeyCode.(309) -LeftMeta := KeyCode.(310) - -/* Left "Windows" key */ -LeftSuper := KeyCode.(311) - -/* Right "Windows" key */ -RightSuper := KeyCode.(312) +Delete := KeyCode.(55) +/* Locking Keys */ +NumLock := KeyCode.(56) +CapsLock := KeyCode.(57) +ScrollLock := KeyCode.(58) /* "Alt Gr" key */ -Mode := KeyCode.(313) +Mode := KeyCode.(59) /* 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) \ No newline at end of file diff --git a/sysdata/libraries/intouch/src/lib.hb b/sysdata/libraries/intouch/src/lib.hb index 86175a6c0..dca49d408 100644 --- a/sysdata/libraries/intouch/src/lib.hb +++ b/sysdata/libraries/intouch/src/lib.hb @@ -1,22 +1,25 @@ -keycodes := @use("keycodes.hb"); -.{KeyCode} := keycodes +stn := @use("../../stn/src/lib.hb"); +.{log, buffer, memory} := stn +keycodes := @use("keycodes.hb") -MouseEvent := struct { - x_change: u8, - y_change: u8, - left: u8, - middle: u8, - right: u8, +events := @use("events.hb"); +.{KeyEvent, MouseEvent} := events + +recieve_key_event := fn(): ?KeyEvent { + return null } -KeyEvent := struct { - // 0 if down - // 1 if up - up: u8, - // 0 if not just triggered - // 1 if just triggered - just_triggered: u8, - key: KeyCode, -} +recieve_mouse_event := fn(): ?MouseEvent { + mevent := MouseEvent.(0, 0, false, false, false) -GamepadEvent := struct {} \ No newline at end of file + buf_id := buffer.search("PS/2 Mouse\0") + + // Read out of the Mouse buffer here + buffer.recv(MouseEvent, buf_id, @bitcast(&mevent)) + + if mevent.x_change != 0 | mevent.y_change != 0 | mevent.left | mevent.middle | mevent.right { + return mevent + } + + return null +} \ No newline at end of file diff --git a/sysdata/libraries/render/TODO.md b/sysdata/libraries/render/TODO.md new file mode 100644 index 000000000..c17ae888f --- /dev/null +++ b/sysdata/libraries/render/TODO.md @@ -0,0 +1,30 @@ +# Images +- General over image format +- Support formats: + - PNG +- Animation + +# API +- Colour operations: + - Alpha Composite + - Invert +- Surface Operations: + - FlipH + - Resize + - Wrap the colour operations + - Tile + - Gradient overlay +- Draw operations: + - Curve raster algorithm + - VGA font fast blit + - Polygon + - Rounded rects + +# Backend +- SVGA Driver +- Support whatever vulkan stuff able is cooking + +# Bits and bobs on the table +- Funny 3D Renderer +- stn.memory.swap & kernel message +- Make memory.{copy, set} smart \ No newline at end of file diff --git a/sysdata/libraries/render/src/image/bmp.hb b/sysdata/libraries/render/src/image/bmp.hb new file mode 100644 index 000000000..d9950c62b --- /dev/null +++ b/sysdata/libraries/render/src/image/bmp.hb @@ -0,0 +1,49 @@ +.{Color, Surface, new_surface, put_surface} := @use("../lib.hb"); +.{log, memory} := @use("../../../stn/src/lib.hb") + +BitmapFileHeader := packed struct { + magic: u16, + size: u32, + reserved_1: u16, + reserved_2: u16, + offset: u32, +} + +BitmapInfoHeader := packed struct { + size: u32, + width: i32, + height: i32, + planes: u16, + bits: u16, + compression: u32, + image_size: u32, + x_resolution: i32, + y_resolution: i32, + n_colours: u32, + important_colours: u32, +} + +BitmapColorHeader := packed struct { + red_mask: u32, + green_mask: u32, + blue_mask: u32, + alpha_mask: u32, + color_space_type: u32, + unused: u32, +} + +from := fn(bmp: ^u8): ?Surface { + file_header := @as(^BitmapFileHeader, @bitcast(bmp)) + info_header := @as(^BitmapInfoHeader, @bitcast(bmp + @sizeof(BitmapFileHeader))) + + if file_header.magic != 0x4D42 | info_header.width == 0 | info_header.height == 0 { + log.error("Invalid BMP image.\0") + return null + } + + 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 +} \ No newline at end of file diff --git a/sysdata/libraries/render/src/image/lib.hb b/sysdata/libraries/render/src/image/lib.hb new file mode 100644 index 000000000..eecf6d87b --- /dev/null +++ b/sysdata/libraries/render/src/image/lib.hb @@ -0,0 +1,31 @@ +.{log} := @use("../../../stn/src/lib.hb"); +.{Surface} := @use("../lib.hb") +bmp := @use("bmp.hb") +qoi := @use("qoi.hb") +$BMP := 0x4D42 +$QOI := 0x66696F71 + +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 null + } +} + +from := fn(file: ^u8): ?Surface { + format := get_format(file) + + if format == null { + log.error("Could not detect image format.\0") + return null + } else if format == BMP { + return bmp.from(file) + } else if format == QOI { + return qoi.from(file) + } + + return null +} \ No newline at end of file diff --git a/sysdata/libraries/render/src/image/qoi.hb b/sysdata/libraries/render/src/image/qoi.hb new file mode 100644 index 000000000..2f4c88827 --- /dev/null +++ b/sysdata/libraries/render/src/image/qoi.hb @@ -0,0 +1,101 @@ +.{Color, Surface, new_surface} := @use("../lib.hb"); +.{log, memory} := @use("../../../stn/src/lib.hb") + +/* source: + https://github.com/phoboslab/qoi/blob/master/qoi.h */ + +$QOI_SRGB := 0 +$QOI_LINEAR := 1 +$QOI_OP_INDEX := 0x0 +$QOI_OP_DIFF := 0x40 +$QOI_OP_LUMA := 0x80 +$QOI_OP_RUN := 0xC0 +$QOI_OP_RGB := 0xFE +$QOI_OP_RGBA := 0xFF +$QOI_MASK_2 := 0xC0 +QOI_COLOR_HASH := fn(c: Color): u8 { + return (c.r * 3 + c.g * 5 + c.b * 7 + c.a * 11) % 64 +} +$QOI_MAGIC := 0x716F6966 +$QOI_PIXELS_MAX := 400000000 + +QuiteOkayHeader := packed struct { + magic: u32, + width: u32, + height: u32, + channels: u8, + colorspace: u8, +} + +be_to_le := fn(big: u32): u32 { + return big >> 24 | big >> 8 & 0xFF00 | big << 8 & 0xFF0000 | big << 24 +} + +from := fn(qoi: ^u8): ?Surface { + header := @as(^QuiteOkayHeader, @bitcast(qoi)) + + qoi += @sizeof(QuiteOkayHeader) + + width := be_to_le(header.width) + height := be_to_le(header.height) + + if be_to_le(header.magic) != QOI_MAGIC | width == 0 | height == 0 | header.channels < 3 | header.channels > 4 { + log.error("Invalid QOI image.\0") + return null + } + + surface := new_surface(width, height) + index := @as([Color; 64], idk) + + run := 0 + px := Color.(0, 0, 0, 255) + px_pos := 0 + + total_pixels := width * height + + loop if px_pos >= total_pixels break else { + if run > 0 { + run -= 1 + } else { + b1 := *qoi + qoi += 1 + + if b1 == QOI_OP_RGB { + px.r = *qoi + px.g = *(qoi + 1) + px.b = *(qoi + 2) + qoi += 3 + } else if b1 == QOI_OP_RGBA { + px.r = *qoi + px.g = *(qoi + 1) + px.b = *(qoi + 2) + px.a = *(qoi + 3) + qoi += 4 + } else if (b1 & QOI_MASK_2) == QOI_OP_INDEX { + px = index[b1 & 0x3F] + } else if (b1 & QOI_MASK_2) == QOI_OP_DIFF { + px.r = px.r + (b1 >> 4 & 0x3) - 2 & 0xFF + px.g = px.g + (b1 >> 2 & 0x3) - 2 & 0xFF + px.b = px.b + (b1 & 0x3) - 2 & 0xFF + } else if (b1 & QOI_MASK_2) == QOI_OP_LUMA { + b2 := *qoi + vg := (b1 & 0x3F) - 32 + + px.r = px.r + vg - 8 + (b2 >> 4 & 0xF) & 0xFF + px.g = px.g + vg & 0xFF + px.b = px.b + vg - 8 + (b2 & 0xF) & 0xFF + qoi += 1 + } else if (b1 & QOI_MASK_2) == QOI_OP_RUN { + run = b1 & 0x3F + } + + index[@inline(QOI_COLOR_HASH, px)] = px + }; + + *(surface.buf + px_pos) = px + + px_pos += 1 + } + + return surface +} \ No newline at end of file diff --git a/sysdata/libraries/render/src/lib.hb b/sysdata/libraries/render/src/lib.hb index 7300319df..dd8a3f1a0 100644 --- a/sysdata/libraries/render/src/lib.hb +++ b/sysdata/libraries/render/src/lib.hb @@ -1,30 +1,38 @@ -svga := @use("svga.hb") software := @use("software.hb") +image := @use("image/lib.hb") +text := @use("text.hb") // default mode mode := software init := mode.init doublebuffer := mode.doublebuffer +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 +index := mode.index +indexptr := mode.indexptr // Colours -Color := mode.Color -white := mode.white -black := mode.black -gray := mode.gray -red := mode.red -green := mode.green -yellow := mode.yellow -blue := mode.blue -magenta := mode.magenta -cyan := mode.cyan -light_gray := mode.light_gray -light_red := mode.light_red -light_green := mode.light_green -light_yellow := mode.light_yellow -light_blue := mode.light_blue -light_magenta := mode.light_magenta -light_cyan := mode.light_cyan +Color := packed struct {b: u8, g: u8, r: u8, a: u8} +$white := Color.(255, 255, 255, 255) +$black := Color.(0, 0, 0, 255) +$gray := Color.(127, 127, 127, 255) +$red := Color.(0, 0, 205, 255) +$green := Color.(0, 205, 0, 255) +$yellow := Color.(0, 205, 205, 255) +$blue := Color.(205, 0, 0, 255) +$magenta := Color.(205, 0, 205, 255) +$cyan := Color.(205, 205, 0, 255) +$light_gray := Color.(229, 229, 229, 255) +$light_red := Color.(0, 0, 255, 255) +$light_green := Color.(0, 255, 0, 255) +$light_yellow := Color.(0, 255, 255, 255) +$light_blue := Color.(255, 0, 0, 255) +$light_magenta := Color.(255, 0, 255, 255) +$light_cyan := Color.(255, 255, 0, 255) // Drawing put_pixel := mode.put_pixel @@ -35,19 +43,12 @@ put_line := mode.put_line put_vline := mode.put_vline put_hline := mode.put_hline clear := mode.clear -put_img := mode.put_img +put_surface := mode.put_surface +put_text := mode.put_text +// thanks peony for these three! +put_trirect := mode.put_trirect +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 - -// Trash Image -Image := struct { - start: ^Color, - end: ^Color, -} \ No newline at end of file +sync := mode.sync \ No newline at end of file diff --git a/sysdata/libraries/render/src/software.hb b/sysdata/libraries/render/src/software.hb index 87b1bdbd9..efc8d92eb 100644 --- a/sysdata/libraries/render/src/software.hb +++ b/sysdata/libraries/render/src/software.hb @@ -1,220 +1,118 @@ -.{math, memory} := @use("../../stn/src/lib.hb"); -.{dt_get} := @use("../../dt_api/src/lib.hb"); -.{Image} := @use("lib.hb"); +.{math, memory, dt} := @use("../../stn/src/lib.hb"); +.{Color, text} := @use("lib.hb"); +.{get_glyph, get_glyph_unicode, Font, UNC_TABLE_SIZE} := text; .{Vec2} := math -Color := struct {b: u8, g: u8, r: u8, a: u8} -white := Color.(255, 255, 255, 255) -black := Color.(0, 0, 0, 255) -gray := Color.(127, 127, 127, 255) -red := Color.(0, 0, 205, 255) -green := Color.(0, 205, 0, 255) -yellow := Color.(0, 205, 205, 255) -blue := Color.(205, 0, 0, 255) -magenta := Color.(205, 0, 205, 255) -cyan := Color.(205, 205, 0, 255) -light_gray := Color.(229, 229, 229, 255) -light_red := Color.(0, 0, 255, 255) -light_green := Color.(0, 255, 0, 255) -light_yellow := Color.(0, 255, 255, 255) -light_blue := Color.(255, 0, 0, 255) -light_magenta := Color.(255, 0, 255, 255) -light_cyan := Color.(255, 255, 0, 255) +// safety: don't use before init() or you will get a memory access violation +framebuffer := memory.dangling(Color) -// might not work for some resolutions, but needs to be comptime because... -copy_pixels := 0xC000 >> 2 - -ctx := @as(Context, idk) - -// some of these are redudant holdovers from fb_driver -// will keep them for future work if necessary -Context := struct { - fb: ^Color, - bb: ^Color, +Surface := struct { buf: ^Color, - width: int, - height: int, - partitions: int, - pixels: int, - bb_pages: int, - double_buffer: bool, + width: uint, + height: uint, } -init := fn(): void { - width := dt_get("framebuffer/fb0/width\0") - height := dt_get("framebuffer/fb0/height\0") - pixels := width * height - bytes := pixels << 2 - partitions := pixels / copy_pixels - pages := 1 + bytes >> 12 - back_buffer := create_back_buffer(pages) - ctx = Context.{ - fb: dt_get("framebuffer/fb0/ptr\0"), - bb: back_buffer, - buf: back_buffer, +new_surface := fn(width: uint, height: uint): Surface { + return .( + @inline(memory.alloc, Color, width * height), width, height, - partitions, - pixels, - bb_pages: pages, - double_buffer: true, - } - return + ) } -doublebuffer := fn(enable: bool): void { - if enable { - ctx.buf = ctx.bb +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 +} + +init := fn(doublebuffer: bool): Surface { + framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0") + width := dt.get(uint, "framebuffer/fb0/width\0") + height := dt.get(uint, "framebuffer/fb0/height\0") + if doublebuffer { + return new_surface(width, height) } else { - ctx.buf = ctx.fb + return .(framebuffer, width, height) } - ctx.double_buffer = enable +} + +clear := fn(surface: Surface, color: Color): void { + return @inline(memory.set, Color, &color, surface.buf, surface.width * surface.height) +} + +sync := fn(surface: Surface): void { + if surface.buf == framebuffer { + return + } + return @inline(memory.copy, Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height)) +} + +index := fn(surface: Surface, x: uint, y: uint): uint { + return x + surface.width * y +} + +indexptr := fn(surface: Surface, x: uint, y: uint): ^Color { + return surface.buf + @inline(index, surface, x, y) +} + +put_pixel := fn(surface: Surface, pos: Vec2(uint), color: Color): void { + *@inline(indexptr, surface, pos.x, pos.y) = color return } -create_back_buffer := fn(pages: int): ^Color { - if pages <= 0xFF { - return @bitcast(@inline(memory.request_page, pages)) - } - ptr := @inline(memory.request_page, 255) - remaining := pages - 0xFF - loop if remaining <= 0 break else { - if remaining < 0xFF { - memory.request_page(remaining) - } else { - memory.request_page(0xFF) - } - remaining -= 0xFF - } - return @bitcast(ptr) -} +put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void { + top_start_idx := @inline(indexptr, surface, pos.x, pos.y) + bottom_start_idx := @inline(indexptr, surface, pos.x, pos.y + tr.y - 1) + rows_to_fill := tr.y -clear := fn(color: Color): void { - cursor := ctx.buf - boundary := cursor + 512 - loop if cursor == boundary break else { - *cursor = color - cursor += 1 - } - boundary += 512 * 7 - loop if cursor == boundary break else { - *@as(^[Color; 512], @bitcast(cursor)) = *@as(^[Color; 512], @bitcast(ctx.buf)) - cursor += 512 - } - boundary += copy_pixels - 4096 - loop if cursor == boundary break else { - *@as(^[Color; 4096], @bitcast(cursor)) = *@as(^[Color; 4096], @bitcast(ctx.buf)) - cursor += 4096 - } - boundary += (ctx.partitions - 1) * copy_pixels - loop if cursor == boundary break else { - *@as(^[Color; copy_pixels], @bitcast(cursor)) = *@as(^[Color; copy_pixels], @bitcast(ctx.buf)) - cursor += @sizeof([u8; copy_pixels]) - } - return -} + loop if rows_to_fill <= 1 break else { + @inline(memory.set, Color, &color, top_start_idx, tr.x) + @inline(memory.set, Color, &color, bottom_start_idx, tr.x) -sync := fn(): void { - if ctx.double_buffer { - bb := ctx.buf - fb := ctx.fb - boundary := bb + ctx.pixels - loop if bb >= boundary break else { - *@as(^[Color; copy_pixels], @bitcast(fb)) = *@as(^[Color; copy_pixels], @bitcast(bb)) - bb += copy_pixels - fb += copy_pixels - } - } - return -} - -width := fn(): int { - return ctx.width -} - -height := fn(): int { - return ctx.height -} - -screenidx := fn(x: int, y: int): int { - /*if x < 0 || y < 0 || x >= ctx.width || y >= ctx.height { - return -1 - }*/ - return x + ctx.width * y -} - -put_pixel := fn(pos: Vec2(int), color: Color): void { - *(ctx.buf + @inline(screenidx, pos.x, pos.y)) = color - return -} - -put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { - x := pos.x - y := pos.y - end := pos + tr - loop if x == end.x break else { - loop if y == end.y break else { - *(ctx.buf + @inline(screenidx, x, y)) = color - y += 1 - } - x += 1 - y = pos.y - } - return -} - -put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { - x := pos.x - y := pos.y - end := pos + tr - loop if y == end.y break else { - *(ctx.buf + @inline(screenidx, x, y)) = color; - *(ctx.buf + @inline(screenidx, x + tr.x, y)) = color - y += 1 - } - y = pos.y - loop if x == end.x break else { - *(ctx.buf + @inline(screenidx, x, y)) = color; - *(ctx.buf + @inline(screenidx, x, y + tr.y)) = color - x += 1 - } - return -} - -put_trirect := fn(pos: Vec2(int), size: Vec2(int), color0: Color, color1: Color): void { - step := Vec2(int).(1, 1) - if size.x < 0 { - step.x = -1 - } - if size.y < 0 { - step.y = size.y / size.x + top_start_idx += surface.width + bottom_start_idx -= surface.width + rows_to_fill -= 2 } - start_y := pos.y - target := pos + size - - loop if pos.x == target.x break else { - put_vline(pos.x, pos.y, target.y, color0) - put_vline(pos.x, pos.y, start_y, color1) - pos += step + if rows_to_fill == 1 { + @inline(memory.set, Color, &color, top_start_idx, tr.x) } return } -put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { - dx := p1.x - p0.x - dy := p1.y - p0.y +put_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void { + start_idx := @inline(indexptr, surface, pos.x, pos.y) + end_idx := @inline(indexptr, surface, pos.x, pos.y + tr.y) + right_start_idx := @inline(indexptr, surface, pos.x + tr.x, pos.y) + + loop if start_idx > end_idx break else { + *start_idx = color; + *right_start_idx = color + start_idx += surface.width + right_start_idx += surface.width + } + + @inline(memory.set, Color, &color, @inline(indexptr, surface, pos.x, pos.y), @bitcast(tr.x + 1)) + @inline(memory.set, Color, &color, @inline(indexptr, surface, pos.x, pos.y + tr.y), @bitcast(tr.x + 1)) + + return +} + +put_line_low := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void { + dx := @as(int, @bitcast(p1.x - p0.x)) + dy := @as(int, @bitcast(p1.y - p0.y)) yi := 1 if dy < 0 { yi = -1 dy = -dy } - D := 2 * dy - dx + D := @as(int, 2) * dy - dx y := p0.y x := p0.x loop if x == p1.x break else { - *(ctx.buf + @inline(screenidx, x, y)) = color + *@inline(indexptr, surface, x, y) = color if D > 0 { y += yi D += 2 * (dy - dx) @@ -226,19 +124,19 @@ put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { return } -put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { - dx := p1.x - p0.x - dy := p1.y - p0.y +put_line_high := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void { + dx := @as(int, @bitcast(p1.x - p0.x)) + dy := @as(int, @bitcast(p1.y - p0.y)) xi := 1 if dy < 0 { xi = -1 dx = -dx } - D := 2 * dx - dy + D := @as(int, 2) * dx - dy x := p0.x y := p0.y loop if y == p1.y break else { - *(ctx.buf + @inline(screenidx, x, y)) = color + *@inline(indexptr, surface, x, y) = color if D > 0 { x += xi D += 2 * (dx - dy) @@ -250,24 +148,83 @@ put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { return } -put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { - if math.abs(int, p1.y - p0.y) < math.abs(int, p1.x - p0.x) { +put_line := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void { + if math.abs(uint, p1.y - p0.y) < math.abs(uint, p1.x - p0.x) { if p0.x > p1.x { - @inline(put_line_low, p1, p0, color) + @inline(put_line_low, surface, p1, p0, color) } else { - @inline(put_line_low, p0, p1, color) + @inline(put_line_low, surface, p0, p1, color) } } else { if p0.y > p1.y { - @inline(put_line_high, p1, p0, color) + @inline(put_line_high, surface, p1, p0, color) } else { - @inline(put_line_high, p0, p1, color) + @inline(put_line_high, surface, p0, p1, color) } } return } -put_vline := fn(x: int, y0: int, y1: int, color: Color): void { +put_surface := fn(surface: Surface, top: Surface, pos: Vec2(uint), flip_v: bool): void { + 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 + + if flip_v { + dst_increment = -dst_increment + tmp := dst_top_idx + dst_top_idx = dst_bottom_idx + dst_bottom_idx = tmp + } + + 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 + } + + if rows_to_copy == 1 { + @inline(memory.copy, Color, src_top_cursor, dst_top_idx, top.width) + } + + return +} + +// peony-made +put_trirect := fn(surface: Surface, pos: Vec2(uint), size: Vec2(int), color0: Color, color1: Color): void { + step := Vec2(int).(1, 1) + if size.x < 0 { + step.x = -1 + } + if size.y < 0 { + step.y /= @bitcast(size.x) + } + + start_y := pos.y + target := pos + @bitcast(size) + + loop if pos.x == target.x break else { + @inline(put_vline, surface, pos.x, pos.y, target.y, color0) + @inline(put_vline, surface, pos.x, pos.y, start_y, color1) + pos += @bitcast(step) + } + + return +} + +// peony-made +put_vline := fn(surface: Surface, x: uint, y0: uint, y1: uint, color: Color): void { if y1 < y0 { tmp := y0 y0 = y1 @@ -276,45 +233,157 @@ put_vline := fn(x: int, y0: int, y1: int, color: Color): void { y := y0 loop if y == y1 break else { - *(ctx.buf + @inline(screenidx, x, y)) = color + *@inline(indexptr, surface, x, y) = color y += 1 } return } -put_hline := fn(y: int, x0: int, x1: int, color: Color): void { +// peony-made +put_hline := fn(surface: Surface, y: uint, x0: uint, x1: uint, color: Color): void { if x1 < x0 { tmp := x0 x0 = x1 x1 = tmp } - x := x0 + @inline(memory.set, Color, &color, @inline(indexptr, surface, x0, y), @bitcast(x1 - x0 - 1)) - loop if x == x1 break else { - *(ctx.buf + @inline(screenidx, x, y)) = color - x += 1 + return +} +utf8_len_table := [u8].(0, 0, 2, 3) + +put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str: ^u8): void { + cursor := Vec2(uint).(pos.x, pos.y) + + 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 + + loop if *str == 0 break else { + if cursor.y > max_y break + + glyph_data := @as(^u8, idk) + code_point := @as(uint, 0) + + 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 + 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 | *str & 0x3F + bytes_processed += 1 + } + + if valid_sequence == false { + str += 1 + continue + } + + str += 1 + + if code_point == 10 { + cursor.x = pos.x + cursor.y += next_line_y + continue + } + + 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 + } + + if cursor.x + font.width >= surface_width { + cursor.x = pos.x + cursor.y += next_line_y + } + + dest := @inline(indexptr, surface, cursor.x, cursor.y) + rows := font.height + + loop if rows == 0 break else { + byte := *glyph_data + pixel_dest := dest + mask := @as(u8, 0x80) + bits := font.width + + loop if bits == 0 break else { + if (byte & mask) != 0 { + *pixel_dest = color + } + pixel_dest += 1 + mask >>= 1 + if mask == 0 & bits > 0 { + glyph_data += 1 + byte = *glyph_data + mask = 0x80 + } + bits -= 1 + } + + if mask != 0x80 { + glyph_data += 1 + } + dest += surface_width + rows -= 1 + } + + cursor.x += char_advance } - return -} - -set_height := fn(new: int): void { - return -} - -set_width := fn(new: int): void { - return -} - -dimensions := fn(): Vec2(int) { - return .(ctx.width, ctx.height) -} - -set_dimensions := fn(new: Vec2(int)): void { - return -} - -put_img := fn(img: Image, pos: Vec2(int)): void { return } \ No newline at end of file diff --git a/sysdata/libraries/render/src/svga.hb b/sysdata/libraries/render/src/svga.hb deleted file mode 100644 index 0790198ef..000000000 --- a/sysdata/libraries/render/src/svga.hb +++ /dev/null @@ -1,84 +0,0 @@ -.{Vec2, Image} := @use("lib.hb") -// .{pci, memory, string, log} := @use("../../stn/src/lib.hb"); - -Color := struct {b: u8, g: u8, r: u8, a: u8} -white := Color.(255, 255, 255, 255) -black := Color.(0, 0, 0, 255) -gray := Color.(127, 127, 127, 255) -red := Color.(0, 0, 205, 255) -green := Color.(0, 205, 0, 255) -yellow := Color.(0, 205, 205, 255) -blue := Color.(205, 0, 0, 255) -magenta := Color.(205, 0, 205, 255) -cyan := Color.(205, 205, 0, 255) -light_gray := Color.(229, 229, 229, 255) -light_red := Color.(0, 0, 255, 255) -light_green := Color.(0, 255, 0, 255) -light_yellow := Color.(0, 255, 255, 255) -light_blue := Color.(255, 0, 0, 255) -light_magenta := Color.(255, 0, 255, 255) -light_cyan := Color.(255, 255, 0, 255) - -clear := fn(color: Color): void { - return -} - -width := fn(): int { - return 0 -} - -height := fn(): int { - return 0 -} - -dimensions := fn(): Vec2(int) { - return .(0, 0) -} - -put_pixel := fn(position: Vec2(int), color: Color): void { - return -} - -put_filled_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { - return -} - -put_rect := fn(pos: Vec2(int), tr: Vec2(int), color: Color): void { - return -} - -put_line_low := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { - return -} -// do not use, use line() instead -put_line_high := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { - return -} - -put_line := fn(p0: Vec2(int), p1: Vec2(int), color: Color): void { - return -} - -set_height := fn(new: int): void { - return -} - -set_width := fn(new: int): void { - return -} - -set_dimensions := fn(new: Vec2(int)): void { - return -} - -sync := fn(): void { - return -} - -init := fn(): void { - return -} - -put_img := fn(img: Image, pos: Vec2(int)): void { - return -} \ No newline at end of file diff --git a/sysdata/libraries/render/src/text.hb b/sysdata/libraries/render/src/text.hb new file mode 100644 index 000000000..5a70a072b --- /dev/null +++ b/sysdata/libraries/render/src/text.hb @@ -0,0 +1,162 @@ +.{log, memory} := @use("../../stn/src/lib.hb") + +PSF1Header := packed struct { + magic: u16, + font_mode: u8, + character_size: u8, +} + +PSF2Header := packed struct { + magic: u32, + version: u32, + header_size: u32, + flags: u32, + num_glyph: u32, + bytes_per_glyph: u32, + height: u32, + width: u32, +} + +Font := struct { + data: ^u8, + width: uint, + height: uint, + num_glyphs: uint, + bytes_per_glyph: uint, + line_gap: uint, + char_gap: uint, + unicode: ?^u16, +} + +font_from_psf1 := fn(psf: ^u8): ?Font { + header := @as(^PSF1Header, @bitcast(psf)) + if header.magic != 0x436 { + log.error("failed to load psf font: not a psf1 font, idiot\0") + return null + } + + psf += @sizeof(PSF1Header) + + return .( + psf, + 8, + header.character_size, + 256, + header.character_size, + 0, + 0, + null, + ) +} + +font_from_psf2 := fn(psf: ^u8, unicode: bool): ?Font { + header := @as(^PSF2Header, @bitcast(psf)) + if header.magic != 0x864AB572 { + log.error("failed to load psf font: not a psf2 font, idiot\0") + return null + } + + psf += header.header_size + + font := Font.( + psf, + header.width, + header.height, + header.num_glyph, + header.bytes_per_glyph, + 0, + 0, + null, + ) + if (header.flags & 1) != 0 & unicode { + init_unicode(&font) + } + return font +} + +get_glyph := fn(font: Font, index: u8): ^u8 { + return font.data + @as(uint, index) * font.bytes_per_glyph +} + +UNC_TABLE_SIZE := 1 << 16 + +init_unicode := fn(font: ^Font): void { + font.unicode = memory.alloc(u16, UNC_TABLE_SIZE) + + @inline(memory.set, u16, &0xFFFF, font.unicode, UNC_TABLE_SIZE) + + table := font.data + font.num_glyphs * font.bytes_per_glyph + curr_glyph := @as(u16, 0) + + loop if curr_glyph >= font.num_glyphs break else { + loop { + byte := *table + table += 1 + + if byte == 0xFF break + if byte == 0xFE { + continue + } + + unicode := @as(uint, 0) + bytes_to_read := @as(uint, 1) + + if (byte & 0x80) == 0 { + unicode = byte + } else if (byte & 0xE0) == 0xC0 { + unicode = byte & 0x1F + bytes_to_read = 2 + } else if (byte & 0xF0) == 0xE0 { + unicode = byte & 0xF + bytes_to_read = 3 + } else if (byte & 0xF8) == 0xF0 { + unicode = byte & 0x7 + bytes_to_read = 4 + } else { + continue + } + + valid := true + loop if bytes_to_read <= 1 break else { + next_byte := *table + if (next_byte & 0xC0) != 0x80 { + valid = false + } + if valid == false { + break + } + unicode = unicode << 6 | next_byte & 0x3F + table += 1 + bytes_to_read -= 1 + } + + if valid == false continue + + if bytes_to_read == 4 { + if unicode < 0x10000 | unicode > 0x10FFFF continue + + if unicode <= 0xFFFF { + if unicode < UNC_TABLE_SIZE { + *(@unwrap(font.unicode) + unicode) = curr_glyph + } + } else { + unicode -= 0x10000 + high_surrogate := 0xD800 | unicode >> 10 & 0x3FF + low_surrogate := 0xDC00 | unicode & 0x3FF + + if high_surrogate < UNC_TABLE_SIZE { + *(@unwrap(font.unicode) + high_surrogate) = curr_glyph + } + if low_surrogate < UNC_TABLE_SIZE { + *(@unwrap(font.unicode) + low_surrogate) = curr_glyph + } + } + } else { + if unicode < UNC_TABLE_SIZE { + *(@unwrap(font.unicode) + unicode) = curr_glyph + } + } + } + curr_glyph += 1 + } +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 554783b17..680aec890 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -1,22 +1,27 @@ string := @use("string.hb") -recv := fn(buffer_id: int, memory_map_location: ^u8, length: int): ^u8 { +recv := fn($Expr: type, buffer_id: int, memory_map_location: ^u8): void { + return @eca(4, buffer_id, memory_map_location, @sizeof(Expr)) +} + +write := fn($Expr: type, msg: ^Expr, buffer_id: int): void { + return @eca(3, buffer_id, msg, @sizeof(Expr)) +} + +recv_length := fn(buffer_id: int, memory_map_location: ^u8, length: int): void { return @eca(4, buffer_id, memory_map_location, length) } -write := fn(msg: ^u8, buffer_id: int, length: int): void { +write_length := fn(msg: ^u8, buffer_id: int, length: int): void { return @eca(3, buffer_id, msg, length) } +BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint} + create := fn(msg: ^u8): int { - msg_length := @inline(string.length, msg); - *msg = 0 - return @eca(3, 0, msg, msg_length) + return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } search := fn(msg: ^u8): int { - msg_length := @inline(string.length, msg); - *msg = 3 - - return @eca(3, 0, msg, msg_length) + return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/dt.hb b/sysdata/libraries/stn/src/dt.hb new file mode 100644 index 000000000..160d5376c --- /dev/null +++ b/sysdata/libraries/stn/src/dt.hb @@ -0,0 +1,5 @@ +.{string} := @use("../../stn/src/lib.hb") + +get := fn($Expr: type, query: ^u8): Expr { + return @eca(3, 5, query, @inline(string.length, query)) +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/lib.hb b/sysdata/libraries/stn/src/lib.hb index 09ff85dd0..8c6fabc99 100644 --- a/sysdata/libraries/stn/src/lib.hb +++ b/sysdata/libraries/stn/src/lib.hb @@ -1,9 +1,19 @@ acs := @use("acs.hb") - string := @use("string.hb") log := @use("log.hb") memory := @use("memory.hb") buffer := @use("buffer.hb") math := @use("math.hb") random := @use("random.hb") -file := @use("file_io.hb") \ No newline at end of file +file := @use("file_io.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 +} \ No newline at end of file diff --git a/sysdata/libraries/stn/src/log.hb b/sysdata/libraries/stn/src/log.hb index 14639df82..bd7d6256f 100644 --- a/sysdata/libraries/stn/src/log.hb +++ b/sysdata/libraries/stn/src/log.hb @@ -1,15 +1,13 @@ string := @use("string.hb") -buffer := @use("buffer.hb") -log := fn(message: ^u8, level: u8): void { - message_length := @inline(string.length, message); - *(message + message_length) = level +LogMsg := packed struct {level: u8, string: ^u8, strlen: uint} - return @eca(3, 1, message, message_length + 1) +log := fn(level: u8, message: ^u8): void { + return @eca(3, 1, LogMsg.(level, message, @inline(string.length, message)), @sizeof(LogMsg)) } -error := fn(message: ^u8): void return log(message, 0) -warn := fn(message: ^u8): void return log(message, 1) -info := fn(message: ^u8): void return log(message, 2) -debug := fn(message: ^u8): void return log(message, 3) -trace := fn(message: ^u8): void return log(message, 4) \ No newline at end of file +error := fn(message: ^u8): void return @inline(log, 0, message) +warn := fn(message: ^u8): void return @inline(log, 1, message) +info := fn(message: ^u8): void return @inline(log, 2, message) +debug := fn(message: ^u8): void return @inline(log, 3, message) +trace := fn(message: ^u8): void return @inline(log, 4, message) \ No newline at end of file diff --git a/sysdata/libraries/stn/src/math.hb b/sysdata/libraries/stn/src/math.hb index f4e0c8473..f22e17fb9 100644 --- a/sysdata/libraries/stn/src/math.hb +++ b/sysdata/libraries/stn/src/math.hb @@ -1,16 +1,63 @@ abs := fn($Expr: type, x: Expr): Expr { - mask := x >> @intcast(@sizeof(Expr) - 1) + mask := x >> @bitcast(@sizeof(Expr) - 1) return (x ^ mask) - mask } min := fn($Expr: type, a: Expr, b: Expr): Expr { c := a - b - return b + (c & c >> @intcast(@sizeof(Expr) - 1)) + return b + (c & c >> @bitcast(@sizeof(Expr) - 1)) } max := fn($Expr: type, a: Expr, b: Expr): Expr { c := a - b - return a - (c & c >> @intcast(@sizeof(Expr) - 1)) + return a - (c & c >> @bitcast(@sizeof(Expr) - 1)) +} +signum := fn($Expr: type, x: Expr): int { + if x > @as(Expr, @intcast(0)) { + return 1 + } else if x < @as(Expr, @intcast(0)) { + return -1 + } else { + return 0 + } +} +signincl := fn($Expr: type, x: Expr): int { + if x > @as(Expr, @intcast(0)) { + return 1 + } + return -1 } Vec2 := fn($Expr: type): type { return struct {x: Expr, y: Expr} +} + +/* source: + https://github.com/baker-Xie/FastMath/blob/master/include/fast_math.h */ +$PI := 3.14159265358979323846 + +SIN_TABLE := [f32].(0.0, 0.02454122852291229, 0.04906767432741801, 0.07356456359966743, 0.0980171403295606, 0.1224106751992162, 0.1467304744553617, 0.1709618887603012, 0.1950903220161282, 0.2191012401568698, 0.2429801799032639, 0.2667127574748984, 0.2902846772544623, 0.3136817403988915, 0.3368898533922201, 0.3598950365349881, 0.3826834323650898, 0.4052413140049899, 0.4275550934302821, 0.4496113296546065, 0.4713967368259976, 0.492898192229784, 0.5141027441932217, 0.5349976198870972, 0.5555702330196022, 0.5758081914178453, 0.5956993044924334, 0.6152315905806268, 0.6343932841636455, 0.6531728429537768, 0.6715589548470183, 0.6895405447370668, 0.7071067811865475, 0.7242470829514669, 0.7409511253549591, 0.7572088465064845, 0.773010453362737, 0.7883464276266062, 0.8032075314806448, 0.8175848131515837, 0.8314696123025452, 0.844853565249707, 0.8577286100002721, 0.8700869911087113, 0.8819212643483549, 0.8932243011955153, 0.9039892931234433, 0.9142097557035307, 0.9238795325112867, 0.9329927988347388, 0.9415440651830208, 0.9495281805930367, 0.9569403357322089, 0.9637760657954398, 0.970031253194544, 0.9757021300385286, 0.9807852804032304, 0.9852776423889412, 0.989176509964781, 0.99247953459871, 0.9951847266721968, 0.9972904566786902, 0.9987954562051724, 0.9996988186962042, 1.0, 0.9996988186962042, 0.9987954562051724, 0.9972904566786902, 0.9951847266721969, 0.99247953459871, 0.989176509964781, 0.9852776423889412, 0.9807852804032304, 0.9757021300385286, 0.970031253194544, 0.9637760657954398, 0.9569403357322089, 0.9495281805930367, 0.9415440651830208, 0.9329927988347388, 0.9238795325112867, 0.9142097557035307, 0.9039892931234434, 0.8932243011955152, 0.881921264348355, 0.8700869911087115, 0.8577286100002721, 0.8448535652497072, 0.8314696123025455, 0.8175848131515837, 0.8032075314806449, 0.7883464276266063, 0.7730104533627371, 0.7572088465064847, 0.740951125354959, 0.7242470829514669, 0.7071067811865476, 0.6895405447370671, 0.6715589548470186, 0.6531728429537766, 0.6343932841636455, 0.6152315905806269, 0.5956993044924335, 0.5758081914178454, 0.5555702330196022, 0.5349976198870972, 0.5141027441932218, 0.4928981922297841, 0.4713967368259979, 0.4496113296546069, 0.427555093430282, 0.4052413140049899, 0.3826834323650899, 0.3598950365349883, 0.3368898533922203, 0.3136817403988914, 0.2902846772544624, 0.2667127574748985, 0.2429801799032641, 0.21910124015687, 0.1950903220161286, 0.1709618887603012, 0.1467304744553618, 0.1224106751992163, 0.09801714032956083, 0.07356456359966773, 0.04906767432741797, 0.02454122852291233, 0.0, -0.02454122852291208, -0.04906767432741772, -0.0735645635996675, -0.09801714032956059, -0.1224106751992161, -0.1467304744553616, -0.170961888760301, -0.1950903220161284, -0.2191012401568698, -0.2429801799032638, -0.2667127574748983, -0.2902846772544621, -0.3136817403988912, -0.3368898533922201, -0.3598950365349881, -0.3826834323650897, -0.4052413140049897, -0.4275550934302818, -0.4496113296546067, -0.4713967368259976, -0.4928981922297839, -0.5141027441932216, -0.5349976198870969, -0.555570233019602, -0.5758081914178453, -0.5956993044924332, -0.6152315905806267, -0.6343932841636453, -0.6531728429537765, -0.6715589548470184, -0.6895405447370668, -0.7071067811865475, -0.7242470829514668, -0.7409511253549589, -0.7572088465064842, -0.7730104533627367, -0.7883464276266059, -0.8032075314806451, -0.8175848131515838, -0.8314696123025452, -0.844853565249707, -0.857728610000272, -0.8700869911087113, -0.8819212643483549, -0.8932243011955152, -0.9039892931234431, -0.9142097557035305, -0.9238795325112865, -0.932992798834739, -0.9415440651830208, -0.9495281805930367, -0.9569403357322088, -0.9637760657954398, -0.970031253194544, -0.9757021300385285, -0.9807852804032303, -0.9852776423889411, -0.9891765099647809, -0.9924795345987101, -0.9951847266721969, -0.9972904566786902, -0.9987954562051724, -0.9996988186962042, -1.0, -0.9996988186962042, -0.9987954562051724, -0.9972904566786902, -0.9951847266721969, -0.9924795345987101, -0.9891765099647809, -0.9852776423889412, -0.9807852804032304, -0.9757021300385286, -0.970031253194544, -0.96377606579544, -0.9569403357322089, -0.9495281805930368, -0.9415440651830209, -0.9329927988347391, -0.9238795325112866, -0.9142097557035306, -0.9039892931234433, -0.8932243011955153, -0.881921264348355, -0.8700869911087115, -0.8577286100002722, -0.8448535652497072, -0.8314696123025455, -0.817584813151584, -0.8032075314806453, -0.7883464276266061, -0.7730104533627369, -0.7572088465064846, -0.7409511253549591, -0.724247082951467, -0.7071067811865477, -0.6895405447370672, -0.6715589548470187, -0.6531728429537771, -0.6343932841636459, -0.6152315905806274, -0.5956993044924332, -0.5758081914178452, -0.5555702330196022, -0.5349976198870973, -0.5141027441932219, -0.4928981922297843, -0.4713967368259979, -0.449611329654607, -0.4275550934302825, -0.4052413140049904, -0.3826834323650904, -0.359895036534988, -0.33688985339222, -0.3136817403988915, -0.2902846772544625, -0.2667127574748986, -0.2429801799032642, -0.2191012401568702, -0.1950903220161287, -0.1709618887603018, -0.1467304744553624, -0.122410675199216, -0.09801714032956051, -0.07356456359966741, -0.04906767432741809, -0.02454122852291245) +TAN_TABLE := [f32].(0.0, 0.01227246237956628, 0.02454862210892544, 0.03683218099484564, 0.04912684976946725, 0.06143635258159376, 0.07376443152244928, 0.08611485119762791, 0.09849140335716425, 0.110897911595913, 0.1233382361367387, 0.1358162787093877, 0.1483359875383474, 0.1609013624534892, 0.1735164601378558, 0.1861853995275837, 0.198912367379658, 0.2117016240239833, 0.2245575093171293, 0.2374844488160702, 0.2504869601913055, 0.263569659899918, 0.2767372701404143, 0.2899946261126061, 0.3033466836073424, 0.3167985269526038, 0.330355377344334, 0.3440226015924263, 0.3578057213145241, 0.3717104226127435, 0.3857425662711212, 0.3999081985145372, 0.414213562373095, 0.4286651096994995, 0.4432695138908643, 0.4580336833706724, 0.4729647758913199, 0.4880702137228629, 0.5033576997992942, 0.5188352348999757, 0.5345111359507916, 0.5503940555372639, 0.566493002730344, 0.5828173653349761, 0.5993769336819237, 0.616181926094866, 0.6332430161775691, 0.6505713620801533, 0.6681786379192989, 0.6860770675448629, 0.7042794608650442, 0.7227992529642059, 0.7416505462720354, 0.7608481560702512, 0.7804076596539435, 0.8003454494993202, 0.8206787908286602, 0.8414258840072547, 0.8626059322567399, 0.8842392152253498, 0.906347169019147, 0.9289524733703675, 0.9520791467009252, 0.9757526499323765, 0.9999999999999999, 1.024849894150227, 1.05033284623986, 1.076481336415266, 1.103329975733476, 1.130915687498827, 1.159277907333434, 1.188458804282966, 1.218503525587976, 1.249460468133579, 1.281381580036554, 1.31432269635108, 1.34834391348672, 1.383510007652874, 1.419890903494092, 1.457562200087105, 1.496605762665489, 1.537110389861882, 1.579172567960209, 1.622897325693455, 1.668399205583507, 1.715803370795664, 1.765246870094191, 1.816880087892402, 1.870868411789389, 1.927394156630064, 1.986658792343365, 2.04888553303075, 2.11432235754864, 2.183245547884151, 2.255963851929159, 2.33282340310135, 2.414213562373095, 2.500573890994256, 2.592402517738071, 2.690266237279613, 2.794812772490477, 2.906785761665535, 3.027043204317773, 3.156580333940787, 3.296558208938321, 3.448339762033025, 3.613535681307428, 3.7940634000883, 3.992223783770083, 4.210802033502797, 4.453202224414411, 4.723629327882301, 5.027339492125846, 5.370990435003726, 5.763142005118804, 6.21498777108904, 6.741452405414988, 7.362887641324242, 8.107785803676903, 9.017302360424724, 10.15317038760884, 11.61239886143525, 13.55666924235242, 16.27700795993539, 20.35546762498714, 27.15017066569958, 40.73548387208334, 81.48324020654604, 1633123935319537.0, -81.48324020654685, -40.73548387208354, -27.15017066569967, -20.35546762498719, -16.27700795993542, -13.55666924235244, -11.61239886143527, -10.15317038760886, -9.017302360424734, -8.10778580367691, -7.362887641324249, -6.741452405414994, -6.214987771089044, -5.763142005118809, -5.37099043500373, -5.02733949212585, -4.723629327882303, -4.453202224414413, -4.2108020335028, -3.992223783770084, -3.794063400088302, -3.61353568130743, -3.448339762033026, -3.296558208938323, -3.156580333940789, -3.027043204317775, -2.906785761665536, -2.794812772490478, -2.690266237279614, -2.592402517738072, -2.500573890994257, -2.414213562373095, -2.332823403101351, -2.25596385192916, -2.183245547884153, -2.114322357548642, -2.048885533030752, -1.986658792343365, -1.927394156630064, -1.870868411789389, -1.816880087892402, -1.765246870094192, -1.715803370795664, -1.668399205583508, -1.622897325693455, -1.57917256796021, -1.537110389861883, -1.49660576266549, -1.457562200087105, -1.419890903494092, -1.383510007652874, -1.34834391348672, -1.31432269635108, -1.281381580036555, -1.249460468133579, -1.218503525587977, -1.188458804282967, -1.159277907333435, -1.130915687498827, -1.103329975733476, -1.076481336415266, -1.05033284623986, -1.024849894150228, -1.0, -0.9757526499323768, -0.9520791467009256, -0.9289524733703679, -0.9063471690191476, -0.8842392152253504, -0.8626059322567398, -0.8414258840072547, -0.8206787908286604, -0.8003454494993202, -0.7804076596539438, -0.7608481560702515, -0.7416505462720356, -0.7227992529642062, -0.7042794608650446, -0.6860770675448633, -0.6681786379192988, -0.6505713620801532, -0.6332430161775691, -0.6161819260948661, -0.5993769336819238, -0.5828173653349762, -0.5664930027303442, -0.5503940555372643, -0.5345111359507919, -0.5188352348999761, -0.5033576997992947, -0.4880702137228627, -0.4729647758913199, -0.4580336833706724, -0.4432695138908644, -0.4286651096994996, -0.4142135623730952, -0.3999081985145373, -0.3857425662711215, -0.3717104226127437, -0.3578057213145244, -0.3440226015924267, -0.3303553773443338, -0.3167985269526037, -0.3033466836073424, -0.2899946261126062, -0.2767372701404144, -0.2635696598999182, -0.2504869601913056, -0.2374844488160704, -0.2245575093171296, -0.2117016240239837, -0.1989123673796584, -0.1861853995275837, -0.1735164601378557, -0.1609013624534892, -0.1483359875383475, -0.1358162787093878, -0.1233382361367388, -0.1108979115959132, -0.09849140335716448, -0.08611485119762818, -0.0737644315224496, -0.06143635258159368, -0.04912684976946721, -0.03683218099484564, -0.02454862210892548, -0.01227246237956636) +$TABLE_SIZE := @as(i32, 256) + +sin := fn(theta: f32): f32 { + si := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) + d := theta - @floatcast(@itf(si)) * 2.0 * PI / @itf(TABLE_SIZE) + ci := si + TABLE_SIZE / 4 & TABLE_SIZE - 1 + si &= TABLE_SIZE - 1 + return SIN_TABLE[@bitcast(si)] + (SIN_TABLE[@bitcast(ci)] - 0.5 * SIN_TABLE[@bitcast(si)] * d) * d +} + +cos := fn(theta: f32): f32 { + ci := @fti(theta * 0.5 * @itf(TABLE_SIZE) / PI) + d := theta - @floatcast(@itf(ci)) * 2.0 * PI / @itf(TABLE_SIZE) + si := ci + TABLE_SIZE / 4 & TABLE_SIZE - 1 + ci &= TABLE_SIZE - 1 + return SIN_TABLE[@bitcast(si)] + (SIN_TABLE[@bitcast(ci)] - 0.5 * SIN_TABLE[@bitcast(si)] * d) * d +} + +tan := fn(theta: f32): f32 { + a := @fti(theta * @itf(TABLE_SIZE) / PI) + d := theta - @floatcast(@itf(a)) * PI / @itf(TABLE_SIZE) + d = d + 1.0 / 3.0 * d * d * d + a &= TABLE_SIZE - 1 + return (TAN_TABLE[@bitcast(a)] + d) / (1.0 - TAN_TABLE[@bitcast(a)] * d) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/memory.hb b/sysdata/libraries/stn/src/memory.hb index 4cbdd6d8c..f0b951ab1 100644 --- a/sysdata/libraries/stn/src/memory.hb +++ b/sysdata/libraries/stn/src/memory.hb @@ -1,39 +1,71 @@ -request_page := fn(page_count: u8): ^u8 { - msg := "\{00}\{01}xxxxxxxx\0" - msg_page_count := msg + 1; - *msg_page_count = page_count - return @eca(3, 2, msg, 12) +PAGE_SIZE := 4096 +MAX_ALLOC := 0xFF +MAX_FREE := 0xFF + +dangling := fn($Expr: type): ^Expr { + return @bitcast(@alignof(Expr)) } -release_page := fn(ptr: ^u8, page_count: u8): void { - msg := "\{01}\{00}xxxxxxxx\0" +calc_pages := fn($Expr: type, num: uint): uint { + return 1 + @sizeof(Expr) * num / PAGE_SIZE +} - msg_page_count := msg + 1; - *msg_page_count = page_count +alloc := fn($Expr: type, num: uint): ^Expr { + pages := @inline(calc_pages, Expr, num) + if pages <= MAX_ALLOC { + return @bitcast(request_page(@intcast(pages))) + } + ptr := request_page(0xFF) + remaining := pages - MAX_ALLOC + loop if remaining < MAX_ALLOC break else { + _ = request_page(@intcast(MAX_ALLOC)) + remaining -= MAX_ALLOC + } + _ = request_page(@intcast(remaining)) + return @bitcast(ptr) +} - msg_ptr := @as(^^u8, @bitcast(msg + 2)); - *msg_ptr = ptr +// ! stub +free := fn($Expr: type, ptr: ^Expr, num: uint, nullify: bool): void { + return +} - return @eca(3, 2, msg, 12) +RqPageMsg := packed struct {a: u8, count: u8} +request_page := fn(count: u8): ^u8 { + return @eca(3, 2, &RqPageMsg.(0, count), @sizeof(RqPageMsg)) +} + +RlPageMsg := packed struct {a: u8, count: u8, ptr: ^u8} +release_page := fn(ptr: ^u8, count: u8): void { + return @eca(3, 2, &RlPageMsg.(1, count, ptr), @sizeof(RlPageMsg)) } OutbMsg := packed struct {a: u8, b: u8, addr: u16, value: u8} -InbMsg := packed struct {a: u8, b: u8, addr: u16} -OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32} -InlMsg := packed struct {a: u8, b: u8, addr: u16} - outb := fn(addr: u16, value: u8): void { return @eca(3, 3, &OutbMsg.(1, 0, addr, value), @sizeof(OutbMsg)) } +InbMsg := packed struct {a: u8, b: u8, addr: u16} inb := fn(addr: u16): u8 { return @eca(3, 3, &InbMsg.(0, 0, addr), @sizeof(InbMsg)) } +OutlMsg := packed struct {a: u8, b: u8, addr: u16, value: u32} outl := fn(addr: u16, value: u32): void { return @eca(3, 3, &OutlMsg.(1, 2, addr, value), @sizeof(OutlMsg)) } +InlMsg := packed struct {a: u8, b: u8, addr: u16} inl := fn(addr: u16): u32 { return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg)) +} + +CopyMsg := packed struct {a: u8, count: u32, src: ^u8, dest: ^u8} +copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { + return @eca(3, 2, &CopyMsg.(4, @intcast(count * @sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg)) +} + +SetMsg := packed struct {a: u8, count: u32, size: u32, src: ^u8, dest: ^u8} +set := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { + return @eca(3, 2, &SetMsg.(5, @intcast(count), @intcast(@sizeof(Expr)), @bitcast(src), @bitcast(dest)), @sizeof(SetMsg)) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/random.hb b/sysdata/libraries/stn/src/random.hb index 1e625602e..4fb7b3ff6 100644 --- a/sysdata/libraries/stn/src/random.hb +++ b/sysdata/libraries/stn/src/random.hb @@ -1,7 +1,7 @@ any := fn($Expr: type): Expr { - return @intcast(@eca(3, 4)) + return *@eca(3, 4, &@as(Expr, idk), @sizeof(Expr)) } range := fn($Expr: type, min: Expr, max: Expr): Expr { - return @eca(3, 4) % (max - min + 1) + min + return @inline(any, Expr) % (max - min) + @intcast(1) + min } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb index 042de0254..efea8702c 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -1,42 +1,64 @@ -length := fn(ptr: ^u8): int { +length := fn(ptr: ^u8): uint { len := 0 - loop if *(ptr + len) == 0 break else len += 1 - return len + loop if *(ptr + len) == 0 return len else len += 1 } -// WTFFF is wrong with display_int -display_int := fn(num: int, p: ^u8): ^u8 { +display_int := fn(num: int, p: ^u8, radix: uint): ^u8 { ptr := p negative := num < 0 if negative { num = -num } + + if radix == 2 { + *ptr = 48 + ptr += 1; + *ptr = 98 + ptr += 1 + } else if radix == 16 { + *ptr = 48 + ptr += 1; + *ptr = 120 + ptr += 1 + } else if radix == 8 { + *ptr = 48 + ptr += 1; + *ptr = 111 + ptr += 1 + } + digits_start := ptr if num == 0 { *ptr = 48 ptr += 1 } else { loop if num == 0 break else { - *ptr = num % 10 + 48 + digit := num % @bitcast(radix) + if digit < 10 { + *ptr = @intcast(digit) + 48 + } else { + *ptr = @intcast(digit) + 55 + } ptr += 1 - num /= 10 + num /= @bitcast(radix) } } + if negative { *ptr = 45 ptr += 1 }; + *ptr = 0 - @inline(reverse, p) + + @inline(reverse, digits_start) + return p } reverse := fn(s: ^u8): void { - //reverse a string, don't remove digits - len := 0 - loop if *(s + len) == 0 break else len += 1 i := 0 - j := len - 1 - temp := 0 + j := @inline(length, s) - 1 + temp := @as(u8, 0) loop if i >= j break else { temp = *(s + i); *(s + i) = *(s + j); @@ -45,4 +67,55 @@ reverse := fn(s: ^u8): void { j -= 1 } return +} + +equals := fn(lhs: ^u8, rhs: ^u8): bool { + if lhs == rhs { + return true + } + i := 0 + loop if *(lhs + i) != *(rhs + i) { + return false + } else if *lhs == 0 { + return true + } else { + i += 1 + } +} + +contains := fn(haystack: ^u8, needle: ^u8): bool { + haystack_len := @inline(length, haystack) + needle_len := @inline(length, needle) + + if needle_len == 0 { + return true + } + if haystack_len < needle_len { + return false + } + + max_start := haystack_len - needle_len + + pos := 0 + loop if pos > max_start break else { + is_match := true + offset := 0 + + loop if offset >= needle_len break else { + if *(haystack + pos + offset) != *(needle + offset) { + is_match = false + } + if is_match == false { + break + } + offset += 1 + } + + if is_match { + return true + } + pos += 1 + } + + return false } \ No newline at end of file diff --git a/sysdata/programs/dt_buffer_test/src/main.hb b/sysdata/programs/dt_buffer_test/src/main.hb index 4d4d14c43..7d37f6ad1 100644 --- a/sysdata/programs/dt_buffer_test/src/main.hb +++ b/sysdata/programs/dt_buffer_test/src/main.hb @@ -1,14 +1,13 @@ -dt_api := @use("../../../libraries/dt_api/src/lib.hb"); -.{dt_get} := dt_api +.{dt} := @use("../../../libraries/stn/src/lib.hb") -main := fn(): int { - dt_api.dt_get("framebuffer/fb0/width\0") - dt_api.dt_get("cpu/cpu0/architecture\0") +main := fn(): void { + dt.get(void, "framebuffer/fb0/width\0") + dt.get(void, "cpu/cpu0/architecture\0") // Checking if the first detected serial port is memory mapped or port mapped // 0 -> memory mapped // 1 -> port mapped - dt_get("serial_ports/sp0/mapping\0") + dt.get(void, "serial_ports/sp0/mapping\0") - return 0 + return } \ No newline at end of file diff --git a/sysdata/programs/filesystem_fat32/src/attributes.hb b/sysdata/programs/filesystem_fat32/src/attributes.hb index 2c5c3ca08..cd9dac66a 100644 --- a/sysdata/programs/filesystem_fat32/src/attributes.hb +++ b/sysdata/programs/filesystem_fat32/src/attributes.hb @@ -1,7 +1,7 @@ -READ_ONLY := 0x1 -HIDDEN := 0x2 -SYSTEM := 0x4 -VOLUME_ID := 0x8 -DIRECTORY := 0x10 -ARCHIVE := 0x20 +READ_ONLY := @as(u32, 0x1) +HIDDEN := @as(u32, 0x2) +SYSTEM := @as(u32, 0x4) +VOLUME_ID := @as(u32, 0x8) +DIRECTORY := @as(u32, 0x10) +ARCHIVE := @as(u32, 0x20) LFN := READ_ONLY | HIDDEN | SYSTEM | VOLUME_ID \ No newline at end of file diff --git a/sysdata/programs/filesystem_fat32/src/bios_parameter_block.hb b/sysdata/programs/filesystem_fat32/src/bios_parameter_block.hb index fa9d8ca1a..d6774c1ac 100644 --- a/sysdata/programs/filesystem_fat32/src/bios_parameter_block.hb +++ b/sysdata/programs/filesystem_fat32/src/bios_parameter_block.hb @@ -9,8 +9,7 @@ OemIdent := struct { } new_oem_ident := fn(major: int, minor: int): OemIdent { - ver := [u8].(0, 0, 0, 0, 0, 0, 0, 0) - return OemIdent.(ver, ver) + return .(.(0, 0, 0, 0, 0, 0, 0, 0), .(0, 0, 0, 0, 0, 0, 0, 0)) } BiosParameterBlock := struct { @@ -38,9 +37,7 @@ bpb_sanity_check := fn(bpb: BiosParameterBlock): int { } new_bpb := fn(): BiosParameterBlock { - oem := new_oem_ident(0, 0) - - return BiosParameterBlock.(VALID_JUMP_BYTES, oem, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + return .(VALID_JUMP_BYTES, new_oem_ident(0, 0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) } sector_count := fn(bpb: BiosParameterBlock): u32 { @@ -63,7 +60,7 @@ VolumeName := [u8; 11] SystemIdentifierString := [u8; 8] VALID_SYSTEM_IDENTIFIER_STRING := [u8].(46, 41, 54, 33, 32, 20, 20, 20) -BOOTABLE_PARTITION_SIGNATURE := 0xAA55 +BOOTABLE_PARTITION_SIGNATURE := @as(u32, 0xAA55) BootCode := [u8; 420] @@ -100,9 +97,10 @@ ebr_sanity_check := fn(ebr: ExtendedBootRecord): int { log.warn("EBR-Signature sanity check failed\0") } - if ebr.system_identifier_string != VALID_SYSTEM_IDENTIFIER_STRING { - log.warn("EBR-Signature-Identifier-String sanity check failed\0") - } + // ! comparison between [u8] is not supported in hblang + // if ebr.system_identifier_string != VALID_SYSTEM_IDENTIFIER_STRING { + // log.warn("EBR-Signature-Identifier-String sanity check failed\0") + // } return 0 } @@ -131,21 +129,21 @@ new_ebr := fn(): ExtendedBootRecord { ) } -VALID_LEAD_FS_INFO := 0x41615252 -VALID_TRAIL_FS_INFO := 0xAA550000 +VALID_LEAD_FS_INFO := @as(u32, 0x41615252) +VALID_TRAIL_FS_INFO := @as(u32, 0xAA550000) FSInfo := struct { // Must be 0x41615252 to indicate a valid FSInfo structure lead_signature: u32, lead_reserved: [u8; 480], - // If the value is 0xFFFFFFFF, then the free count is unknown and must be computed. However, this value might be incorrect and should at least be range checked (<= volume cluster count) + // If the value is 0xFFFFFFFF, then the free count is unknown and must be computed. However, this value might be incorrect and should at least be range checked (<= volume cluster count) last_known_free_cluster_count: u32, last_known_avalible_cluster: u32, trail_reserved: [u8; 12], trail_signature: u32, } -fs_info_sanity_check := fn(fs_info: FSInfo): int { +fs_info_sanity_check := fn(fs_info: FSInfo): uint { ret := 0 if fs_info.lead_signature != VALID_LEAD_FS_INFO { ret &= 1 diff --git a/sysdata/programs/filesystem_fat32/src/file.hb b/sysdata/programs/filesystem_fat32/src/file.hb index c75484557..175bff093 100644 --- a/sysdata/programs/filesystem_fat32/src/file.hb +++ b/sysdata/programs/filesystem_fat32/src/file.hb @@ -7,7 +7,7 @@ FileName := [u8; 11] FileEntry := struct { file_name: FileName, attributes: u8, - // We could use this byte for something but we likely will not + // We could use this byte for something but we likely will not nt_reserved: u8, hundredths_seconds_creation: u8, creation_time: datetime.time, diff --git a/sysdata/programs/filesystem_fat32/src/main.hb b/sysdata/programs/filesystem_fat32/src/main.hb index 6e88cbbc7..e15a16cf9 100644 --- a/sysdata/programs/filesystem_fat32/src/main.hb +++ b/sysdata/programs/filesystem_fat32/src/main.hb @@ -16,7 +16,7 @@ FAT12 := 1 FAT16 := 2 FAT32 := 3 -calculate_fat_type := fn(sector_size: int, total_clusters: int): int { +calculate_fat_type := fn(sector_size: uint, total_clusters: uint): uint { if sector_size == 0 { return ExFAT } else if total_clusters < 4085 { diff --git a/sysdata/programs/horizon/src/main.hb b/sysdata/programs/horizon/src/main.hb index 3c7c63179..1b7ac838e 100644 --- a/sysdata/programs/horizon/src/main.hb +++ b/sysdata/programs/horizon/src/main.hb @@ -1,11 +1,152 @@ stn := @use("../../../libraries/stn/src/lib.hb"); -.{string, memory, buffer} := stn +.{string, memory, buffer, random, log} := stn; +.{Vec2} := stn.math -horizon_api := @use("../../../libraries/horizon_api/src/lib.hb") +horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); +.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label; +.{sexpr_parser, render_ui} := horizon_api.ui + +render := @use("../../../libraries/render/src/lib.hb"); +.{Surface} := render; +.{Font} := render.text + +intouch := @use("../../../libraries/intouch/src/lib.hb") + +Window := struct { + // TODO: Replace this with widgets + implicit_framebuffer: render.Surface, + width: int, + height: int, + x: int, + y: int, +} + +psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf") +img := @embed("../../../assets/wallpaper.qoi") main := fn(): int { - a := buffer.create("XHorizon\0") + win_buff := buffer.create("XHorizon\0") + + screen := render.init(true) + + // Clear the screen to black. + render.clear(screen, render.black) + + wallpaper := render.image.from(@bitcast(&img)) + if wallpaper == null { + return 1 + } + + window := render.new_surface(screen.width / 3, screen.height / 3) + + mem_buf := memory.request_page(1) + color := random.any(render.Color) + side := window.width / 8 + + // really we should null check but it is a bit broked + font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false)) + + mouse_x := @as(i16, 0) + mouse_y := @as(i16, 0) + text_label := new_label("Hi\0") + + // widgets := "()\0" + // ui := sexpr_parser(widgets) + loop { + // Clear the screen + render.clear(screen, render.black) + render.put_surface(screen, wallpaper, .(0, 0), false) + + // TODO: Read the window buffer here + { + // ret := buffer.recv([u8; 4096], win_buff, mem_buf) + // for some reason this null check causes the compiler to spin forever + // if ret == null { + // log.info("No messages\0") + // } else { + // log.info("Handle Messages\0") + // } + } + + // get input events from drivers via intouch + // key_event := intouch.recieve_key_event(); + // log.info("before mouse event check\0"); + + 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) + + render.put_rect(screen, .(90, 110), .(10, 100), render.white) + render.put_filled_rect(screen, .(90, 120), .(10, 20), render.white) + } + + { + 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, 20), render.white) + } + + // Screen border + render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), render.white) + + { + mouse_event := intouch.recieve_mouse_event() + // + + if mouse_event != null { + // log.warn("Mouse event recieved\0") + + change_x := @as(i16, mouse_event.x_change) + change_x = change_x << 8 + change_x = change_x >> 8 + + mouse_x += change_x + if mouse_x < 0 { + mouse_x = 0 + } + if mouse_x >= screen.width - 20 { + mouse_x = @intcast(screen.width - 21) + } + + change_y := @as(i16, mouse_event.y_change) + change_y = change_y << 8 + change_y = change_y >> 8 + + if mouse_y < 0 { + mouse_y = 0 + } + if mouse_y >= screen.height - 20 { + mouse_y = @intcast(screen.height - 21) + } + mouse_y -= change_y + + if mouse_event.left { + set_label_text(text_label, "LEFT CLICK\0") + } + if mouse_event.middle { + set_label_text(text_label, "MIDDLE CLICK\0") + } + if mouse_event.right { + set_label_text(text_label, "RIGHT CLICK\0") + } + } + + // render mouse + lum := render.indexptr(screen, mouse_x, mouse_y) + if lum.r / 3 + lum.g / 3 + lum.b / 3 < 128 { + render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.white) + } else { + render.put_rect(screen, .(mouse_x, mouse_y), .(20, 20), render.black) + } + // Send events to focused window + } + + // TODO: Get windows out of a collection and iter through + + // Sync the screen + render.sync(screen) } return 0 diff --git a/sysdata/programs/horizon_testing_program/src/main.hb b/sysdata/programs/horizon_testing_program/src/main.hb index 01d57a3cc..d5b6362d6 100644 --- a/sysdata/programs/horizon_testing_program/src/main.hb +++ b/sysdata/programs/horizon_testing_program/src/main.hb @@ -7,29 +7,36 @@ horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); ignim := @use("../../../libraries/ignim/src/lib.hb"); .{errors} := ignim +psf := @embed("../../../consolefonts/tamsyn/10x20r.psf") + main := fn(): int { - windowing_system_buffer := buffer.create("XHorizon\0") + x := 0 + // loop if x > 10000 break else x += 1 + windowing_system_buffer := buffer.search("XHorizon\0") // TODO: get WindowID - create_window(windowing_system_buffer) + wid := create_window(windowing_system_buffer) + if false { + program_name := "Horizon Testing Program\0" + program_version := ignim.version.make_version(0, 1, 0) + engine_name := "None\0" + engine_version := ignim.version.make_version(0, 0, 0) + api_version := ignim.version.make_api_version(0, 1, 0, 0) - program_name := "Horizon Testing Program\0" - program_version := ignim.version.make_version(0, 1, 0) - engine_name := "None\0" - engine_version := ignim.version.make_version(0, 0, 0) - api_version := ignim.version.make_api_version(0, 1, 0, 0) + app_info := ignim.application.new_application_info(program_name, program_version, engine_name, engine_version, api_version) - app_info := ignim.application.new_application_info(program_name, program_version, engine_name, engine_version, api_version) + create_info := ignim.instance.new_create_info(&app_info) - create_info := ignim.instance.new_create_info(&app_info) + instance := ignim.instance.void_instance() - instance := ignim.instance.void_instance() - - // TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance - ret := ignim.instance.create_instance(&create_info, 0, &instance) - if ret == errors.IncompatibleDriver { - log.error("Driver Incompatible with Vulkan\0") + // // TODO: recursively follow this https://vulkan-tutorial.com/Drawing_a_triangle/Setup/Instance + ret := ignim.instance.create_instance(&create_info, 0, &instance) + if ret == errors.IncompatibleDriver { + log.error("Driver Incompatible with Vulkan\0") + } } + // TODO: get window from the window system and draw to the surface + return 0 } \ No newline at end of file diff --git a/sysdata/programs/ps2_driver/README.md b/sysdata/programs/ps2_keyboard_driver/README.md similarity index 100% rename from sysdata/programs/ps2_driver/README.md rename to sysdata/programs/ps2_keyboard_driver/README.md diff --git a/sysdata/programs/ps2_driver/meta.toml b/sysdata/programs/ps2_keyboard_driver/meta.toml similarity index 83% rename from sysdata/programs/ps2_driver/meta.toml rename to sysdata/programs/ps2_keyboard_driver/meta.toml index 0a2d770c9..804602bd9 100644 --- a/sysdata/programs/ps2_driver/meta.toml +++ b/sysdata/programs/ps2_keyboard_driver/meta.toml @@ -1,5 +1,5 @@ [package] -name = "ps2_driver" +name = "ps2_keyboard_driver" authors = ["Talha Qamar"] [dependants.libraries] diff --git a/sysdata/programs/ps2_driver/src/main.hb b/sysdata/programs/ps2_keyboard_driver/src/main.hb similarity index 73% rename from sysdata/programs/ps2_driver/src/main.hb rename to sysdata/programs/ps2_keyboard_driver/src/main.hb index 26be5025d..150d3b061 100644 --- a/sysdata/programs/ps2_driver/src/main.hb +++ b/sysdata/programs/ps2_keyboard_driver/src/main.hb @@ -1,4 +1,4 @@ -.{memory, log, string, buffer} := @use("../../../libraries/stn/src/lib.hb") +.{memory, log, buffer} := @use("../../../libraries/stn/src/lib.hb") send_byte := fn(byte: u8): u8 { memory.outb(96, byte) @@ -7,7 +7,7 @@ send_byte := fn(byte: u8): u8 { main := fn(): int { buf := buffer.create("XKeyboard\0") - send_byte(238) + _ = send_byte(238) log.info("PS/2 Driver Loaded\0") if send_byte(238) == 238 { log.info("PS/2 Keyboard Echoed\0") @@ -15,7 +15,6 @@ main := fn(): int { if send_byte(244) == 250 { log.info("Enabled scanning\0") } - ptr := memory.request_page(1) prev_input := 250 loop { input := memory.inb(96) @@ -23,7 +22,7 @@ main := fn(): int { continue } prev_input = input - buffer.write(&input, buf, 1) + buffer.write(u8, &input, buf) } return 0 } \ No newline at end of file diff --git a/sysdata/programs/ps2_mouse_driver/README.md b/sysdata/programs/ps2_mouse_driver/README.md new file mode 100644 index 000000000..4c17847b5 --- /dev/null +++ b/sysdata/programs/ps2_mouse_driver/README.md @@ -0,0 +1,2 @@ +# ps2_mouse_driver +A small PS/2 mouse driver. This driver pushes changes to the input service in ableOS. \ No newline at end of file diff --git a/sysdata/programs/tests/meta.toml b/sysdata/programs/ps2_mouse_driver/meta.toml similarity index 69% rename from sysdata/programs/tests/meta.toml rename to sysdata/programs/ps2_mouse_driver/meta.toml index a94c6669a..e3bfc9a37 100644 --- a/sysdata/programs/tests/meta.toml +++ b/sysdata/programs/ps2_mouse_driver/meta.toml @@ -1,6 +1,6 @@ [package] -name = "tests" -authors = ["able"] +name = "ps2_mouse_driver" +authors = ["able", "peony"] [dependants.libraries] diff --git a/sysdata/programs/ps2_mouse_driver/src/main.hb b/sysdata/programs/ps2_mouse_driver/src/main.hb new file mode 100644 index 000000000..546801786 --- /dev/null +++ b/sysdata/programs/ps2_mouse_driver/src/main.hb @@ -0,0 +1,152 @@ +.{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb") +Vec2 := math.Vec2 + +intouch := @use("../../../libraries/intouch/src/lib.hb"); +.{MouseEvent} := intouch.events + +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) + +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 { + 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 { + mouse_buffer := buffer.create("PS/2 Mouse\0") + format_page := memory.alloc(u8, 1024) + + 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 + } + event := MouseEvent.(0, 0, false, false, false) + + changes := button_states ^ status & 7 + + if (changes & LeftButton.id) != 0 | (status & LeftButton.id) != 0 { + event.left = true + } else { + event.left = false + } + + if (changes & MiddleButton.id) != 0 | (status & MiddleButton.id) != 0 { + event.middle = true + } else { + event.middle = false + } + + if (changes & RightButton.id) != 0 | (status & RightButton.id) != 0 { + event.right = true + } else { + event.right = false + } + + button_states ^= changes + + 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 + + y_change := @as(i8, @bitcast(dy.value)) + x_change := @as(i8, @bitcast(dx.value)) + + event.x_change = x_change + event.y_change = y_change + + buffer.write(MouseEvent, &event, mouse_buffer) + } + + return 0 +} \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/amogus.hb b/sysdata/programs/render_example/src/examples/amogus.hb index eca4e4858..eb68a1000 100644 --- a/sysdata/programs/render_example/src/examples/amogus.hb +++ b/sysdata/programs/render_example/src/examples/amogus.hb @@ -4,16 +4,16 @@ render := @use("../../../../libraries/render/src/lib.hb") the impostor travels left and loops around the screen */ example := fn(): void { - render.init() + screen := render.init(true) x := 0 loop { - render.put_rect(.(200 - x, 80), .(430, 380), render.red) - render.put_rect(.(630 - x, 120), .(120, 300), render.red) - render.put_rect(.(200 - x, 460), .(160, 270), render.red) - render.put_rect(.(470 - x, 460), .(160, 270), render.red) - render.put_rect(.(140 - x, 140), .(340, 250), render.cyan) - render.sync() - render.clear(render.black) + render.put_rect(screen, .(200 - x, 80), .(430, 380), render.red) + render.put_rect(screen, .(630 - x, 120), .(120, 300), render.red) + render.put_rect(screen, .(200 - x, 460), .(160, 270), render.red) + render.put_rect(screen, .(470 - x, 460), .(160, 270), render.red) + render.put_rect(screen, .(140 - x, 140), .(340, 250), render.cyan) + render.sync(screen) + render.clear(screen, render.black) x += 1 } return diff --git a/sysdata/programs/render_example/src/examples/colors.hb b/sysdata/programs/render_example/src/examples/colors.hb index 9f8bbd7db..bb23933f5 100644 --- a/sysdata/programs/render_example/src/examples/colors.hb +++ b/sysdata/programs/render_example/src/examples/colors.hb @@ -6,12 +6,12 @@ render := @use("../../../../libraries/render/src/lib.hb") note that this may happen too fast for you to notice... */ example := fn(): void { - render.init() + screen := render.init(true) color := render.light_cyan n := @as(u8, 1) loop { - render.clear(color) - render.sync() + render.clear(screen, color) + render.sync(screen) if (color.b & 255) == 255 | (color.b & 255) == 0 { n = -n } diff --git a/sysdata/programs/render_example/src/examples/image.hb b/sysdata/programs/render_example/src/examples/image.hb new file mode 100644 index 000000000..d9f58e5ab --- /dev/null +++ b/sysdata/programs/render_example/src/examples/image.hb @@ -0,0 +1,26 @@ +.{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 */ + +example := fn(): void { + screen := render.init(true) + image_qoi := render.image.from(@bitcast(&@embed("../../../../assets/mini.qoi"))) + image_bmp := render.image.from(@bitcast(&@embed("../../../../assets/mini.bmp"))) + + 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, .(@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 +} \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/lines.hb b/sysdata/programs/render_example/src/examples/lines.hb index be4a536c1..346ca9e9a 100644 --- a/sysdata/programs/render_example/src/examples/lines.hb +++ b/sysdata/programs/render_example/src/examples/lines.hb @@ -6,18 +6,16 @@ render := @use("../../../../libraries/render/src/lib.hb") created on a blue background */ example := fn(): void { - render.init() - render.clear(.(100, 50, 0, 255)) - width := render.width() - height := render.height() - p0 := Vec2(int).(0, 0) - p1 := Vec2(int).(0, height) - loop if p0.y >= height break else { - render.put_line(p0, p1, .(255, 180, 100, 255)) - render.put_line(.(width, height) - p0, .(width, height) - p1, .(255, 180, 100, 255)) - p0.y += height >> 6 - p1.x += width >> 6 + screen := render.init(true) + render.clear(screen, .(100, 50, 0, 255)) + p0 := Vec2(uint).(0, 0) + p1 := Vec2(uint).(0, screen.height) + loop if p0.y >= screen.height break else { + render.put_line(screen, p0, p1, .(255, 180, 100, 255)) + render.put_line(screen, .(screen.width, screen.height) - p0, .(screen.width, screen.height) - p1, .(255, 180, 100, 255)) + p0.y += screen.height >> 6 + p1.x += screen.width >> 6 } - render.sync() + render.sync(screen) return } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/random.hb b/sysdata/programs/render_example/src/examples/random.hb index 7c68c5e11..6710c1073 100644 --- a/sysdata/programs/render_example/src/examples/random.hb +++ b/sysdata/programs/render_example/src/examples/random.hb @@ -2,16 +2,15 @@ render := @use("../../../../libraries/render/src/lib.hb") example := fn(): void { - render.init() - render.doublebuffer(false) - render.clear(render.black) + screen := render.init(false) + render.clear(screen, render.black) loop { - x := random.range(int, 0, 1024) - y := random.range(int, 0, 768) - r := random.range(int, 0, 255) - g := random.range(int, 0, 75) - b := random.range(int, 0, 155) - render.put_pixel(.(x, y), .(b, g, r, 255)) + x := random.range(uint, 0, screen.width) + y := random.range(uint, 0, screen.height) + r := random.range(u8, 0, 255) + g := random.range(u8, 0, 75) + b := random.range(u8, 0, 155) + render.put_pixel(screen, .(x, y), .(b, g, r, 255)) } return } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/square.hb b/sysdata/programs/render_example/src/examples/square.hb index 46ee81096..b66723d77 100644 --- a/sysdata/programs/render_example/src/examples/square.hb +++ b/sysdata/programs/render_example/src/examples/square.hb @@ -6,27 +6,26 @@ render := @use("../../../../libraries/render/src/lib.hb") a square that changes colour bounces around the screen */ example := fn(): void { - render.init() + screen := render.init(true) vel := Vec2(int).(1, 1) - pos := Vec2(int).(100, 100) - width := render.width() - height := render.height() - color := @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + side := screen.width / 8 + pos := Vec2(uint).((screen.width - side) / 2, (screen.height - side) / 2) + color := random.any(render.Color) loop { - render.put_filled_rect(pos, .(100, 100), color) - render.sync() - render.clear(render.black) + render.put_filled_rect(screen, pos, .(side, side), color) + render.sync(screen) + render.clear(screen, render.black) - if pos.x == 0 | pos.x == width - 100 { + if pos.x == 0 | pos.x == screen.width - side { vel.x = -vel.x - color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + color = random.any(render.Color) } - if pos.y == 0 | pos.y == height - 100 { + if pos.y == 0 | pos.y == screen.height - side { vel.y = -vel.y - color = @as(render.Color, @intcast(random.range(int, 0, 0xFFFFFF))) + color = random.any(render.Color) } - pos += vel + pos += @bitcast(vel) } return } \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/strobe.hb b/sysdata/programs/render_example/src/examples/strobe.hb deleted file mode 100644 index 4681cc5e1..000000000 --- a/sysdata/programs/render_example/src/examples/strobe.hb +++ /dev/null @@ -1,15 +0,0 @@ -render := @use("../../../../libraries/render/src/lib.hb") - -/* expected result: (EPILEPSY WARNING) - the screen rapidly flashes red then black */ - -example := fn(): void { - render.init() - loop { - render.clear(render.red) - render.sync() - render.clear(render.yellow) - render.sync() - } - return -} \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/surface.hb b/sysdata/programs/render_example/src/examples/surface.hb new file mode 100644 index 000000000..5a3eefc79 --- /dev/null +++ b/sysdata/programs/render_example/src/examples/surface.hb @@ -0,0 +1,55 @@ +.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math; +.{random} := @use("../../../../libraries/stn/src/lib.hb") +render := @use("../../../../libraries/render/src/lib.hb") + +/* expected result: + bouncing gradient square inside coloured bouncing box inside black screen */ + +example := fn(): void { + screen := render.init(true) + + image := render.new_surface(screen.width / 3, screen.height / 3) + vel := Vec2(int).(-1, -1) + pos := Vec2(uint).(100, 100) + side := image.width / 8 + vel_inner := Vec2(int).(1, 1) + pos_inner := Vec2(uint).((image.width - side) / 2, (image.height - side) / 2) + color := random.any(render.Color) + target_color := random.any(render.Color) + loop { + render.clear(screen, render.black) + render.put_filled_rect(image, pos_inner, .(side, side), color) + 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, false) + render.put_rect(image, pos_inner, .(side, side), color) + render.sync(screen) + + if pos_inner.x == 0 | pos_inner.x == image.width - side { + vel_inner.x = -vel_inner.x + target_color = random.any(render.Color) + } + if pos_inner.y == 0 | pos_inner.y == image.height - side { + vel_inner.y = -vel_inner.y + target_color = random.any(render.Color) + } + + if pos.x == 0 | pos.x == screen.width - image.width { + vel.x = -vel.x + } + if pos.y == 0 | pos.y == screen.height - image.height { + vel.y = -vel.y + } + + color += .( + @bitcast(color.b < target_color.b) - @bitcast(color.b > target_color.b), + @bitcast(color.g < target_color.g) - @bitcast(color.g > target_color.g), + @bitcast(color.r < target_color.r) - @bitcast(color.r > target_color.r), + 0, + ) + pos += @bitcast(vel) + pos_inner += @bitcast(vel_inner) + } + return +} \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/svga.hb b/sysdata/programs/render_example/src/examples/svga.hb deleted file mode 100644 index 101aa6fb5..000000000 --- a/sysdata/programs/render_example/src/examples/svga.hb +++ /dev/null @@ -1,8 +0,0 @@ -render := @use("../../../../libraries/render/src/lib.hb") - -render.mode = render.svga - -example := fn(): void { - render.init() - return -} \ No newline at end of file diff --git a/sysdata/programs/render_example/src/examples/tactical_screen.hb b/sysdata/programs/render_example/src/examples/tactical_screen.hb index 4f227de27..b15792a6e 100644 --- a/sysdata/programs/render_example/src/examples/tactical_screen.hb +++ b/sysdata/programs/render_example/src/examples/tactical_screen.hb @@ -4,15 +4,15 @@ Vec2 := math.Vec2 /* expected result: a grid of green lines scrolling from the left top corner to the right bottom one - with a "target" randomly apperaing in one of them and a "seeker" "catching" it*/ + with a "target" randomly apperaing in one of them and a "seeker" "catching" it */ example := fn(): void { - render.init() + screen := render.init(true) - width := render.width() - height := render.height() + width := screen.width + height := screen.height cell_size := 0 - range := Vec2(int).(0, 0) + range := Vec2(uint).(0, 0) if width > height { cell_size = width / 40 range = .(39, height / cell_size - 1) @@ -24,41 +24,41 @@ example := fn(): void { height -= 1 scroll := 0 - target := Vec2(int).(random.range(int, 0, range.x), random.range(int, 0, range.y)) + target := Vec2(uint).(random.range(uint, 0, range.x), random.range(uint, 0, range.y)) halfcell := cell_size / 2 octcell := cell_size / 8 sevenoctcell := cell_size - octcell - seeker := Vec2(int).(random.range(int, 0, range.x), random.range(int, 0, range.y)) + seeker := Vec2(uint).(random.range(uint, 0, range.x), random.range(uint, 0, range.y)) loop { - render.clear(render.black) + render.clear(screen, render.black) - target_pixel_coord := target * .(cell_size, cell_size) + .(scroll, scroll) - render.put_trirect(target_pixel_coord, .(cell_size, cell_size), render.red, render.light_red) + target_pixel_coord := target * .(@bitcast(cell_size), @bitcast(cell_size)) + .(scroll, scroll) + render.put_trirect(screen, target_pixel_coord, .(@bitcast(cell_size), @bitcast(cell_size)), render.red, render.light_red) - render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red) - render.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red) - render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red) - render.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red) + render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red) + render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red) + render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red) + render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red) x := scroll loop if x > width break else { - render.put_vline(x, 0, height, .(0, 127, 0, 127)) + render.put_vline(screen, x, 0, height, .(0, 127, 0, 127)) x += cell_size } y := scroll loop if y > height break else { - render.put_hline(y, 0, width, .(0, 127, 0, 127)) + render.put_hline(screen, y, 0, width, .(0, 127, 0, 127)) y += cell_size } - render.put_hline(seeker.y * cell_size + halfcell + scroll, 0, width, render.light_green) - render.put_vline(seeker.x * cell_size + halfcell + scroll, 0, height, render.light_green) + render.put_hline(screen, seeker.y * cell_size + halfcell + scroll, 0, width, render.blue) + render.put_vline(screen, seeker.x * cell_size + halfcell + scroll, 0, height, render.blue) - render.sync() + render.sync(screen) if seeker.x < target.x { seeker.x += 1 @@ -69,7 +69,7 @@ example := fn(): void { } else if seeker.y > target.y { seeker.y -= 1 } else { - target = .(random.range(int, 0, range.x), random.range(int, 0, range.y)) + target = .(random.range(uint, 0, range.x), random.range(uint, 0, range.y)) } scroll += 1 diff --git a/sysdata/programs/render_example/src/examples/text.hb b/sysdata/programs/render_example/src/examples/text.hb new file mode 100644 index 000000000..74ae601d1 --- /dev/null +++ b/sysdata/programs/render_example/src/examples/text.hb @@ -0,0 +1,243 @@ +.{memory, log, string, math} := @use("../../../../libraries/stn/src/lib.hb") +render := @use("../../../../libraries/render/src/lib.hb") + +/* expected result: pretty decent notepad app + slightly jank + ----------------- + features: + - basic keys + - holding support with DAS + - visible cursor + - l+r arrow key support + - proper insertion and deletion + - shift key support +*/ + +psf := @embed("../../../../assets/consolefonts/tamsyn/10x20r.psf") +img := @embed("../../../../assets/wallpaper.qoi") + +is_shift_pressed := false +is_ctrl_pressed := false +is_extended := false +$initial_delay := 50 +$repeat_delay := 7 +$left_arrow := 0x4B +$right_arrow := 0x4D +$up_arrow := 0x48 +$down_arrow := 0x50 + +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) + + buf := memory.alloc(u8, 4096) + + bottom := buf + msg_len + + @inline(memory.copy, u8, msg, buf, msg_len) + cursor := bottom + + draw_window(window, font, buf, cursor) + draw_screen(screen, window, wallpaper) + + memory.outb(96, 238) + memory.outb(96, 238) + memory.outb(96, 244) + + prev_input := @as(u8, 0xFF) + current_key := @as(u8, 0) + holding_timer := 0 + + loop { + input := memory.inb(96) + if input != prev_input { + if input == 0xE0 { + is_extended = true + } else { + if (input & 0x80) != 0 { + if (input & 0x7F) == current_key { + current_key = 0 + holding_timer = 0 + } else if input == 0xAA | input == 0xB6 { + is_shift_pressed = false + } else if input == 0x9D { + is_ctrl_pressed = false + } + is_extended = false + } else { + if is_extended { + current_key = input + holding_timer = 1 + cursor = handle_extended_key(input, cursor, bottom, font) + } else { + if input == 0x2A | input == 0x36 { + is_shift_pressed = true + } else if input == 0x1D { + is_ctrl_pressed = true + } else { + current_key = input + holding_timer = 1 + cursor = handle_char(map_keys(current_key), cursor, bottom) + } + } + } + } + prev_input = input + } + + if current_key != 0 & holding_timer > 0 { + holding_timer += 1 + + if holding_timer >= initial_delay { + if is_extended { + cursor = handle_extended_key(current_key, cursor, bottom, font) + } else { + cursor = handle_char(map_keys(current_key), cursor, bottom) + } + holding_timer = initial_delay - repeat_delay + } + } + draw_window(window, font, buf, cursor) + draw_screen(screen, window, wallpaper) + + if holding_timer > 0 & current_key != 0 { + if (memory.inb(96) & 0x80) != 0 { + current_key = 0 + holding_timer = 0 + } + } + } +} + +handle_extended_key := fn(scancode: u8, cursor: ^u8, bottom: ^u8, font: render.text.Font): ^u8 { + if scancode == left_arrow { + if cursor > bottom { + return cursor - 1 + } + } else if scancode == right_arrow { + if *cursor != 0 { + return cursor + 1 + } + } + return cursor +} + +padding := 3 * @sizeof(render.Color) + +draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8, cursor: ^u8): void { + 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) + + loop if line >= window.height break else { + render.put_hline(window, line, padding, window.width - padding, render.yellow) + line += font.height + } + + render.put_text(window, font, .(padding, padding), render.black, buf) + + cursor_offset := cursor - buf + + y_pos := padding + x_pos := padding + i := 0 + + loop if i >= cursor_offset break else { + if *(buf + i) == 10 { + y_pos += font.height + font.line_gap + x_pos = padding + } else { + if x_pos + font.width >= window.width - padding { + y_pos += font.height + font.line_gap + x_pos = padding - font.width + } + x_pos += font.width + } + i += 1 + } + + render.put_rect(window, .(x_pos, y_pos), .(1, font.height - 1), render.black) +} + +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) +} + +handle_char := fn(char: u8, cursor: ^u8, bottom: ^u8): ^u8 { + if char == 0 { + return cursor + } + + if is_ctrl_pressed & char == 48 { + cursor = bottom + } else if char != 0x8 { + end := cursor + loop if *end == 0 break else { + end += 1 + } + + if cursor < end { + src := end + dst := end + 1 + loop if src < cursor break else { + *dst = *src + dst -= 1 + src -= 1 + } + }; + + *cursor = char + return cursor + 1 + } else if char == 0xA { + *cursor = 32 + cursor += 1; + *cursor = 92 + return cursor + 1 + } else if cursor > bottom { + if cursor == bottom { + return cursor + } + + end := cursor + loop if *end == 0 break else { + end += 1 + } + + if cursor < end { + src := cursor + dst := cursor - 1 + loop if src > end break else { + *dst = *src + dst += 1 + src += 1 + } + return cursor - 1 + } else { + cursor -= 1; + *cursor = 32 + return cursor + } + } + return cursor +} +map_keys := fn(scancode: u8): u8 { + if is_shift_pressed { + return ps2_table[scancode + 0x40] + } + return ps2_table[scancode] +} +ps2_table := [u8].(0x0, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x8, 0x9, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0xA, 0x0, 0x61, 0x73, 0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B, 0x27, 0x60, 0x0, 0x5C, 0x7A, 0x78, 0x63, 0x76, 0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x0, 0x2A, 0x0, 0x20, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x8, 0x9, 0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0xA, 0x0, 0x41, 0x53, 0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A, 0x22, 0x7E, 0x0, 0x7C, 0x5A, 0x58, 0x43, 0x56, 0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x0, 0x0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) \ No newline at end of file diff --git a/sysdata/programs/render_example/src/main.hb b/sysdata/programs/render_example/src/main.hb index 5d15c24c8..77cb04c04 100644 --- a/sysdata/programs/render_example/src/main.hb +++ b/sysdata/programs/render_example/src/main.hb @@ -1,6 +1 @@ -.{example} := @use("./examples/tactical_screen.hb") - -main := fn(): void { - @inline(example) - return -} \ No newline at end of file +.{example: main} := @use("./examples/text.hb") \ No newline at end of file diff --git a/sysdata/programs/serial_driver/src/main.hb b/sysdata/programs/serial_driver/src/main.hb index 9270463f5..513436349 100644 --- a/sysdata/programs/serial_driver/src/main.hb +++ b/sysdata/programs/serial_driver/src/main.hb @@ -1,7 +1,7 @@ .{memory, buffer} := @use("../../../libraries/stn/src/lib.hb") serial_print := fn(ptr: ^u8): void { - letter := 0 + letter := @as(u8, 0) loop if *ptr == 0 break else { letter = *ptr memory.outb(0xF803, letter) @@ -25,7 +25,7 @@ main := fn(): int { mem := memory.request_page(1) loop { - ptr := @eca(4, a, mem, 0x1000) + ptr := @as(^u8, @eca(4, a, mem, 0x1000)) if ptr == 0 { serial_println("No message\0") } diff --git a/sysdata/programs/serial_driver_test/src/main.hb b/sysdata/programs/serial_driver_test/src/main.hb index d0998bcf7..19ad6c153 100644 --- a/sysdata/programs/serial_driver_test/src/main.hb +++ b/sysdata/programs/serial_driver_test/src/main.hb @@ -5,8 +5,10 @@ log_info := fn(): void { if a == 0 { } else { msg := "XABC\0" - msg_length := @inline(string.length, msg) - @eca(3, a, msg, msg_length) + // inline is broked + // msg_length := @inline(string.length, msg) + msg_length := 5 + @as(void, @eca(3, a, msg, msg_length)) } return diff --git a/sysdata/programs/svga_driver/src/device.hb b/sysdata/programs/svga_driver/src/device.hb index daf98e46e..741d9e4a5 100644 --- a/sysdata/programs/svga_driver/src/device.hb +++ b/sysdata/programs/svga_driver/src/device.hb @@ -2,9 +2,7 @@ stn := @use("../../../libraries/stn/src/lib.hb"); .{string, memory, buffer, log} := stn pci := @use("../../../libraries/pci/src/lib.hb"); -.{PCIAddress, get_ids, config_read32} := pci; - -.{dt_get} := @use("../../../libraries/dt_api/src/lib.hb") +.{PCIAddress, get_ids, config_read32} := pci reg := @use("./reg.hb") diff --git a/sysdata/programs/tests/src/main.hb b/sysdata/programs/tests/src/main.hb deleted file mode 100644 index be45842ab..000000000 --- a/sysdata/programs/tests/src/main.hb +++ /dev/null @@ -1,13 +0,0 @@ -.{log, string, memory, buffer} := @use("../../../libraries/stn/src/lib.hb") - -service_search := fn(): void { - a := "\{01}\0" - @eca(3, 0, a, 2) - - return -} - -main := fn(): int { - //service_search() - return 0 -} \ No newline at end of file diff --git a/sysdata/programs/tetris/meta.toml b/sysdata/programs/tetris/meta.toml deleted file mode 100644 index d2a5f974c..000000000 --- a/sysdata/programs/tetris/meta.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "tetris" -authors = ["peony"] - -[dependants.libraries] - -[dependants.binaries] -hblang.version = "1.0.0" - -[build] -command = "hblang src/main.hb" diff --git a/sysdata/programs/tetris/src/main.hb b/sysdata/programs/tetris/src/main.hb index 65aebf3bd..f4eaa3bb4 100644 --- a/sysdata/programs/tetris/src/main.hb +++ b/sysdata/programs/tetris/src/main.hb @@ -25,4 +25,4 @@ main := fn(): void { } } return -} \ No newline at end of file +} diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index 48aa10538..1992a8004 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -3,11 +3,12 @@ default_entry = 1 timeout = 0 verbose = false -interface_resolution = "1600x900x24" -# interface_resolution = "640x480x32" +# interface_resolution = "1920x1080x24" +interface_resolution = "1024x768x24" +# interface_resolution = "640x480x24" # Terminal related settings -term_wallpaper = "boot:///background.bmp" -# term_wallpaper = "boot:///empty-background.bmp" +# term_wallpaper = "boot:///background.bmp" +term_wallpaper = "boot:///empty-background.bmp" term_background = "008080" [boot.limine.ableos] @@ -15,46 +16,20 @@ comment = "Default AbleOS boot entry." protocol = "limine" kernel_path = "boot:///kernel_${ARCH}" kernel_cmdline = "" -# resolution = "640x480x32" -resolution = "1600x900x24" +# resolution = "1920x1080x24" +resolution = "1024x768x24" +# resolution = "640x480x24" [boot.limine.ableos.modules] -# [boot.limine.ableos.modules.tests] -# path = "boot:///tests.hbf" +# [boot.limine.ableos.modules.render_example] +# path = "boot:///render_example.hbf" -# [boot.limine.ableos.modules.serial_driver] -# path = "boot:///serial_driver.hbf" +[boot.limine.ableos.modules.horizon] +path = "boot:///horizon.hbf" -# [boot.limine.ableos.modules.diskio_driver] -# path = "boot:///diskio_driver.hbf" +[boot.limine.ableos.modules.ps2_mouse_driver] +path = "boot:///ps2_mouse_driver.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_testing_program] -# path = "boot:///horizon_testing_program.hbf" - -# [boot.limine.ableos.modules.dt_buffer_test] -# path = "boot:///dt_buffer_test.hbf" - -# [boot.limine.ableos.modules.svga_driver] -# path = "boot:///svga_driver.hbf" - -# [boot.limine.ableos.modules.ps2_driver] -# path = "boot:///ps2_driver.hbf" - -# [boot.limine.ableos.modules.filesystem_fat32] -# path = "boot:///filesystem_fat32.hbf" - -# [boot.limine.ableos.modules.pumpkin_print] -# path = "boot:///pumpkin_print.hbf" - -# [boot.limine.ableos.modules.tetris] -# path = "boot:///tetris.hbf" +# [boot.limine.ableos.modules.ps2_keyboard_driver] +# path = "boot:///ps2_keyboard_driver.hbf"