diff --git a/.dockerignore b/.dockerignore index 3c6952c..a3650aa 100644 --- a/.dockerignore +++ b/.dockerignore @@ -19,3 +19,6 @@ target/ # Local maps / logs *.map + +# Node (ts-builder runs npm ci fresh) +**/node_modules/ diff --git a/.gitignore b/.gitignore index b023775..338e6f2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,14 @@ target/ lcov.info docs/dkl2-sprite-investigation.md *_PLAN.md + +# Tooling state (local) +.beads/ +.claude/ + +# Title-screen source media & experiments (kept locally, not committed) +gemini_* +Madagascar* +ferris.png +331269-* +index.html?* diff --git a/Cargo.lock b/Cargo.lock index 4b7a243..0dc3677 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,9 +261,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.11.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" dependencies = [ "serde_core", ] @@ -289,7 +289,7 @@ dependencies = [ "embedded-io 0.7.1", "embedded-io-async 0.7.0", "futures-intrusive", - "heapless 0.8.0", + "heapless 0.9.3", ] [[package]] @@ -331,6 +331,15 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" +[[package]] +name = "castaway" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.2.58" @@ -411,7 +420,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" dependencies = [ "termcolor", - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -420,6 +429,20 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "compact_str" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dfdd1c2274d9aa354115b09dc9a901d6c5576818cdf70d14cae2bdb47df00ab" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "rustversion", + "ryu", + "static_assertions", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -645,8 +668,18 @@ version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.20.11", + "darling_macro 0.20.11", +] + +[[package]] +name = "darling" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" +dependencies = [ + "darling_core 0.23.0", + "darling_macro 0.23.0", ] [[package]] @@ -663,13 +696,37 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "darling_core" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.117", +] + [[package]] name = "darling_macro" version = "0.20.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ - "darling_core", + "darling_core 0.20.11", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "darling_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" +dependencies = [ + "darling_core 0.23.0", "quote", "syn 2.0.117", ] @@ -917,7 +974,7 @@ name = "embassy-executor-macros" version = "0.8.0" source = "git+https://github.com/embassy-rs/embassy#c722d94fd2a4a856fbd771d177ff34100674c7cd" dependencies = [ - "darling", + "darling 0.20.11", "proc-macro2", "quote", "syn 2.0.117", @@ -1396,6 +1453,18 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "font8x8" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875488b8711a968268c7cf5d139578713097ca4635a76044e8fe8eedf831d07e" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -1607,7 +1676,7 @@ checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "allocator-api2", "equivalent", - "foldhash", + "foldhash 0.1.5", ] [[package]] @@ -1615,6 +1684,22 @@ name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] [[package]] name = "hashlink" @@ -1923,6 +2008,28 @@ dependencies = [ "serde_core", ] +[[package]] +name = "indoc" +version = "2.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706" +dependencies = [ + "rustversion", +] + +[[package]] +name = "instability" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eb2d60ef19920a3a9193c3e371f726ec1dafc045dac788d0fb3704272458971" +dependencies = [ + "darling 0.23.0", + "indoc", + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "ipnet" version = "2.12.0" @@ -1985,6 +2092,16 @@ dependencies = [ "simple_asn1", ] +[[package]] +name = "kasuari" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bde5057d6143cc94e861d90f591b9303d6716c6b9602309150bd068853c10899" +dependencies = [ + "hashbrown 0.16.1", + "thiserror", +] + [[package]] name = "keccak" version = "0.1.6" @@ -2059,7 +2176,7 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ddbf48fd451246b1f8c2610bd3b4ac0cc6e149d89832867093ab69a17194f08" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", "libc", "plain", "redox_syscall 0.7.3", @@ -2076,6 +2193,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "line-clipping" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f50e8f47623268b5407192d26876c4d7f89d686ca130fdc53bced4814cd29f8" +dependencies = [ + "bitflags 2.13.0", +] + [[package]] name = "linked_list_allocator" version = "0.10.6" @@ -2128,6 +2254,15 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "lru" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9" +dependencies = [ + "hashbrown 0.17.1", +] + [[package]] name = "lru-slab" version = "0.1.2" @@ -2834,13 +2969,61 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" +[[package]] +name = "ratatui" +version = "0.30.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3274ba0a2c5e1bcad2a2005d20f4dc59dad26b2eb0940fb094500dba4099d57d" +dependencies = [ + "instability", + "ratatui-core", + "ratatui-widgets", +] + +[[package]] +name = "ratatui-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbb175c433c8e28a809d1f5773a2ae96e68c0ce40db865cbab1020bf33ae479c" +dependencies = [ + "bitflags 2.13.0", + "compact_str", + "hashbrown 0.17.1", + "itertools", + "kasuari", + "lru", + "strum", + "thiserror", + "unicode-segmentation", + "unicode-truncate", + "unicode-width 0.2.2", +] + +[[package]] +name = "ratatui-widgets" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66e3d19bcc9130ca376277d93b60767ff121ace3be06f5f95f81dd68956407d1" +dependencies = [ + "bitflags 2.13.0", + "hashbrown 0.17.1", + "indoc", + "instability", + "itertools", + "line-clipping", + "ratatui-core", + "strum", + "unicode-segmentation", + "unicode-width 0.2.2", +] + [[package]] name = "redox_syscall" version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", ] [[package]] @@ -2849,7 +3032,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce70a74e890531977d37e532c34d45e9055d2409ed08ddba14529471ed0be16" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", ] [[package]] @@ -3024,7 +3207,7 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", "errno", "libc", "linux-raw-sys", @@ -3076,7 +3259,7 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" name = "rustyboy-core" version = "0.1.0" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", "bytemuck", "heapless 0.9.3", "png", @@ -3120,6 +3303,9 @@ dependencies = [ name = "rustyboy-web-client" version = "0.1.0" dependencies = [ + "font8x8", + "js-sys", + "ratatui", "rustyboy-core", "wasm-bindgen", ] @@ -3551,7 +3737,7 @@ checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526" dependencies = [ "atoi", "base64", - "bitflags 2.11.1", + "bitflags 2.13.0", "byteorder", "bytes", "crc", @@ -3593,7 +3779,7 @@ checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46" dependencies = [ "atoi", "base64", - "bitflags 2.11.1", + "bitflags 2.13.0", "byteorder", "crc", "dotenvy", @@ -3696,6 +3882,27 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "subtle" version = "2.6.1" @@ -3959,7 +4166,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", "bytes", "futures-util", "http", @@ -3984,7 +4191,7 @@ version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", "bytes", "futures-util", "http", @@ -4136,12 +4343,35 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" +[[package]] +name = "unicode-segmentation" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" + +[[package]] +name = "unicode-truncate" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b380a1238663e5f8a691f9039c73e1cdae598a30e9855f541d29b08b53e9a5" +dependencies = [ + "itertools", + "unicode-segmentation", + "unicode-width 0.2.2", +] + [[package]] name = "unicode-width" version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + [[package]] name = "unicode-xid" version = "0.2.6" @@ -4360,7 +4590,7 @@ version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.13.0", "hashbrown 0.15.5", "indexmap", "semver 1.0.27", @@ -4635,7 +4865,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" dependencies = [ "anyhow", - "bitflags 2.11.1", + "bitflags 2.13.0", "indexmap", "log", "serde", diff --git a/core/src/cpu/instructions/adc/opcode.rs b/core/src/cpu/instructions/adc/opcode.rs index ad1c87c..61fb14b 100644 --- a/core/src/cpu/instructions/adc/opcode.rs +++ b/core/src/cpu/instructions/adc/opcode.rs @@ -10,7 +10,7 @@ pub struct Adc { } impl OpCode for Adc { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute( &self, instruction: &mut dyn Instructions, diff --git a/core/src/cpu/instructions/add/opcode.rs b/core/src/cpu/instructions/add/opcode.rs index f23242f..684b017 100644 --- a/core/src/cpu/instructions/add/opcode.rs +++ b/core/src/cpu/instructions/add/opcode.rs @@ -10,7 +10,7 @@ pub struct Add8 { } impl OpCode for Add8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.add8(&self, memory) } @@ -23,7 +23,7 @@ pub struct Add16 { } impl OpCode for Add16 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute( &self, cpu: &mut dyn Instructions, @@ -40,7 +40,7 @@ pub struct AddSP16 { } impl OpCode for AddSP16 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.add_sp16(&self, memory) } diff --git a/core/src/cpu/instructions/call/opcode.rs b/core/src/cpu/instructions/call/opcode.rs index 25674fc..9d13376 100644 --- a/core/src/cpu/instructions/call/opcode.rs +++ b/core/src/cpu/instructions/call/opcode.rs @@ -17,7 +17,7 @@ pub struct Call { } impl OpCode for Call { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.call(self, memory) } diff --git a/core/src/cpu/instructions/cb/opcode.rs b/core/src/cpu/instructions/cb/opcode.rs index 8db7e63..1200a5c 100644 --- a/core/src/cpu/instructions/cb/opcode.rs +++ b/core/src/cpu/instructions/cb/opcode.rs @@ -33,7 +33,7 @@ pub struct CbInstruction { } impl OpCode for CbInstruction { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.cb(self, memory) } diff --git a/core/src/cpu/instructions/cp/opcode.rs b/core/src/cpu/instructions/cp/opcode.rs index 1386438..f8d5050 100644 --- a/core/src/cpu/instructions/cp/opcode.rs +++ b/core/src/cpu/instructions/cp/opcode.rs @@ -11,7 +11,7 @@ pub struct Cp8 { } impl OpCode for Cp8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.cp8(&self, memory) } diff --git a/core/src/cpu/instructions/inc_dec/opcode.rs b/core/src/cpu/instructions/inc_dec/opcode.rs index 5b401e6..a5389a3 100644 --- a/core/src/cpu/instructions/inc_dec/opcode.rs +++ b/core/src/cpu/instructions/inc_dec/opcode.rs @@ -11,7 +11,7 @@ pub struct Inc8 { } impl OpCode for Inc8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.inc8(self, memory) } @@ -25,7 +25,7 @@ pub struct Dec8 { } impl OpCode for Dec8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.dec8(self, memory) } @@ -38,7 +38,7 @@ pub struct Inc16 { } impl OpCode for Inc16 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute( &self, cpu: &mut dyn Instructions, @@ -55,7 +55,7 @@ pub struct Dec16 { } impl OpCode for Dec16 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute( &self, cpu: &mut dyn Instructions, diff --git a/core/src/cpu/instructions/jump/opcode.rs b/core/src/cpu/instructions/jump/opcode.rs index c7d160d..c56ab91 100644 --- a/core/src/cpu/instructions/jump/opcode.rs +++ b/core/src/cpu/instructions/jump/opcode.rs @@ -31,7 +31,7 @@ pub struct Jump { } impl OpCode for Jump { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.jump(&self, memory) } diff --git a/core/src/cpu/instructions/ld/opcode.rs b/core/src/cpu/instructions/ld/opcode.rs index 66ab0f6..b338617 100644 --- a/core/src/cpu/instructions/ld/opcode.rs +++ b/core/src/cpu/instructions/ld/opcode.rs @@ -11,7 +11,7 @@ pub struct Ld8 { } impl OpCode for Ld8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.ld8(&self, memory) } diff --git a/core/src/cpu/instructions/ld16/opcode.rs b/core/src/cpu/instructions/ld16/opcode.rs index 8de35e5..c576ea8 100644 --- a/core/src/cpu/instructions/ld16/opcode.rs +++ b/core/src/cpu/instructions/ld16/opcode.rs @@ -30,7 +30,7 @@ pub struct Ld16 { } impl OpCode for Ld16 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.ld16(&self, memory) } diff --git a/core/src/cpu/instructions/logic/opcode.rs b/core/src/cpu/instructions/logic/opcode.rs index 6de2c19..21d97bd 100644 --- a/core/src/cpu/instructions/logic/opcode.rs +++ b/core/src/cpu/instructions/logic/opcode.rs @@ -11,7 +11,7 @@ pub struct And8 { } impl OpCode for And8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.and8(&self, memory) } @@ -25,7 +25,7 @@ pub struct Or8 { } impl OpCode for Or8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.or8(&self, memory) } @@ -39,7 +39,7 @@ pub struct Xor8 { } impl OpCode for Xor8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.xor8(&self, memory) } diff --git a/core/src/cpu/instructions/misc/opcode.rs b/core/src/cpu/instructions/misc/opcode.rs index 873250d..a93dd1a 100644 --- a/core/src/cpu/instructions/misc/opcode.rs +++ b/core/src/cpu/instructions/misc/opcode.rs @@ -21,7 +21,7 @@ pub struct Misc { } impl OpCode for Misc { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute( &self, cpu: &mut dyn Instructions, diff --git a/core/src/cpu/instructions/ret/opcode.rs b/core/src/cpu/instructions/ret/opcode.rs index f5378cd..5b566f5 100644 --- a/core/src/cpu/instructions/ret/opcode.rs +++ b/core/src/cpu/instructions/ret/opcode.rs @@ -19,7 +19,7 @@ pub struct Ret { } impl OpCode for Ret { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.ret(self, memory) } diff --git a/core/src/cpu/instructions/rotate/opcode.rs b/core/src/cpu/instructions/rotate/opcode.rs index c50145b..016de12 100644 --- a/core/src/cpu/instructions/rotate/opcode.rs +++ b/core/src/cpu/instructions/rotate/opcode.rs @@ -16,7 +16,7 @@ pub struct Rotate { } impl OpCode for Rotate { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute( &self, cpu: &mut dyn Instructions, diff --git a/core/src/cpu/instructions/rst/opcode.rs b/core/src/cpu/instructions/rst/opcode.rs index 0d0f4f6..a2bf0dc 100644 --- a/core/src/cpu/instructions/rst/opcode.rs +++ b/core/src/cpu/instructions/rst/opcode.rs @@ -8,7 +8,7 @@ pub struct Rst { } impl OpCode for Rst { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.rst(self, memory) } diff --git a/core/src/cpu/instructions/sbc/opcode.rs b/core/src/cpu/instructions/sbc/opcode.rs index 9d39b82..6aa4654 100644 --- a/core/src/cpu/instructions/sbc/opcode.rs +++ b/core/src/cpu/instructions/sbc/opcode.rs @@ -10,7 +10,7 @@ pub struct Sbc8 { } impl OpCode for Sbc8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.sbc8(&self, memory) } diff --git a/core/src/cpu/instructions/stack/opcode.rs b/core/src/cpu/instructions/stack/opcode.rs index 2f8c3d1..8190ce5 100644 --- a/core/src/cpu/instructions/stack/opcode.rs +++ b/core/src/cpu/instructions/stack/opcode.rs @@ -9,7 +9,7 @@ pub struct Push16 { } impl OpCode for Push16 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.push16(self, memory) } @@ -21,7 +21,7 @@ pub struct Pop16 { } impl OpCode for Pop16 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.pop16(self, memory) } diff --git a/core/src/cpu/instructions/sub/opcode.rs b/core/src/cpu/instructions/sub/opcode.rs index 223d803..cd9ac1c 100644 --- a/core/src/cpu/instructions/sub/opcode.rs +++ b/core/src/cpu/instructions/sub/opcode.rs @@ -10,7 +10,7 @@ pub struct Sub8 { } impl OpCode for Sub8 { -#[cfg_attr(target_arch = "arm", link_section = ".data")] + #[cfg_attr(target_arch = "arm", link_section = ".data")] fn execute(&self, cpu: &mut dyn Instructions, memory: &mut GameBoyMemory) -> Result { cpu.sub8(&self, memory) } diff --git a/core/src/cpu/save_state.rs b/core/src/cpu/save_state.rs index cbda64b..8e6c7dc 100644 --- a/core/src/cpu/save_state.rs +++ b/core/src/cpu/save_state.rs @@ -344,8 +344,13 @@ impl SaveState { // (MBC3+RTC = 18 bytes + 8-byte header) + cart RAM section if present. let cart_ram_len = memory.external_ram().map_or(0, |r| r.len()); let capacity = MIN_BLOB_SIZE - + SECTION_HEADER_SIZE + 18 - + if cart_ram_len > 0 { SECTION_HEADER_SIZE + cart_ram_len } else { 0 }; + + SECTION_HEADER_SIZE + + 18 + + if cart_ram_len > 0 { + SECTION_HEADER_SIZE + cart_ram_len + } else { + 0 + }; let mut out = Vec::with_capacity(capacity); out.extend_from_slice(MAGIC); out.extend_from_slice(&VERSION_V2.to_le_bytes()); diff --git a/core/src/memory/memory.rs b/core/src/memory/memory.rs index 5b87a4d..cb1eeeb 100644 --- a/core/src/memory/memory.rs +++ b/core/src/memory/memory.rs @@ -641,7 +641,9 @@ impl GameBoyMemory { /// memory through a direct fast path. #[inline(always)] pub fn enqueue_bus_event(&mut self, address: u16, value: u8) { - self.events.push(BusEvent { address, value }).expect("bus event queue overflow"); + self.events + .push(BusEvent { address, value }) + .expect("bus event queue overflow"); } /// Returns a read-only view of the IO register array (0xFF00–0xFF7F). @@ -700,7 +702,9 @@ impl Memory for GameBoyMemory { } RegionMapping::Vram(offset) => { self.vram[offset as usize] = value; - self.events.push(BusEvent { address, value }).expect("bus event queue overflow"); + self.events + .push(BusEvent { address, value }) + .expect("bus event queue overflow"); Ok(()) } RegionMapping::Wram(offset) => { @@ -710,12 +714,16 @@ impl Memory for GameBoyMemory { RegionMapping::EchoRam(_) => Err(Error::ReadOnly(address)), RegionMapping::Oam(offset) => { self.oam[offset as usize] = value; - self.events.push(BusEvent { address, value }).expect("bus event queue overflow"); + self.events + .push(BusEvent { address, value }) + .expect("bus event queue overflow"); Ok(()) } RegionMapping::Io(offset) => { self.io[offset as usize] = value; - self.events.push(BusEvent { address, value }).expect("bus event queue overflow"); + self.events + .push(BusEvent { address, value }) + .expect("bus event queue overflow"); Ok(()) } RegionMapping::Hram(offset) => { @@ -724,7 +732,9 @@ impl Memory for GameBoyMemory { } RegionMapping::InterruptEnable => { self.ie = value; - self.events.push(BusEvent { address, value }).expect("bus event queue overflow"); + self.events + .push(BusEvent { address, value }) + .expect("bus event queue overflow"); Ok(()) } RegionMapping::Unmapped => Ok(()), diff --git a/platform/pico2w/src/crash/handler.rs b/platform/pico2w/src/crash/handler.rs index 2df4a51..205bbd1 100644 --- a/platform/pico2w/src/crash/handler.rs +++ b/platform/pico2w/src/crash/handler.rs @@ -287,12 +287,14 @@ fn commit_crash_and_reset( // Common flag bits: emulator state availability, stack overflow, core ID. let common_flags = if ctx.is_some() { - flags::HAS_GB_STATE | flags::HAS_ROM_INFO - } else { - 0 - } - | if overflowed { flags::HAS_STACK_OVERFLOW } else { 0 } - | if core == 1 { flags::FAULT_ON_CORE1 } else { 0 }; + flags::HAS_GB_STATE | flags::HAS_ROM_INFO + } else { + 0 + } | if overflowed { + flags::HAS_STACK_OVERFLOW + } else { + 0 + } | if core == 1 { flags::FAULT_ON_CORE1 } else { 0 }; let f = kind_flags | common_flags; @@ -305,7 +307,15 @@ fn commit_crash_and_reset( let gb_pc = ctx.as_ref().map(|c| c.gb_pc).unwrap_or(0); let packed7 = ((rom_bank as u32) << 16) | (gb_pc as u32); - write_watchdog_scratch(arm_pc, arm_lr, arm_cfsr, arm_hfsr, arm_fault_addr, packed6, packed7); + write_watchdog_scratch( + arm_pc, + arm_lr, + arm_cfsr, + arm_hfsr, + arm_fault_addr, + packed6, + packed7, + ); write_powman_scratch_from_context( ctx.as_ref(), panic_file, diff --git a/platform/pico2w/src/crash/mod.rs b/platform/pico2w/src/crash/mod.rs index 52b9771..fd0974d 100644 --- a/platform/pico2w/src/crash/mod.rs +++ b/platform/pico2w/src/crash/mod.rs @@ -79,9 +79,7 @@ pub use record::{ pub use sector::{find_next_empty_slot, SectorDecodeError, SectorHeader, SECTOR_FULL}; -pub use context::{ - ScratchRegs, TransportSmashDiag, TransportSmashSnapshot, TRANSPORT_SMASH_DIAG, -}; +pub use context::{ScratchRegs, TransportSmashDiag, TransportSmashSnapshot, TRANSPORT_SMASH_DIAG}; #[cfg(target_arch = "arm")] pub use context::{CrashContext, CrashContextSnapshot, CRASH_CONTEXT}; diff --git a/platform/pico2w/src/crash/sector.rs b/platform/pico2w/src/crash/sector.rs index cb21490..b8f6877 100644 --- a/platform/pico2w/src/crash/sector.rs +++ b/platform/pico2w/src/crash/sector.rs @@ -1,7 +1,7 @@ //! On-flash sector header: [`SectorHeader`], [`SectorDecodeError`], slot discovery. -use super::{RECORD_SIZE, SECTOR_MAGIC}; use super::record::MAX_RECORDS_PER_SECTOR; +use super::{RECORD_SIZE, SECTOR_MAGIC}; // --------------------------------------------------------------------------- // Sector-level constants diff --git a/platform/pico2w/src/lib.rs b/platform/pico2w/src/lib.rs index 2cc315d..bdcf2b6 100644 --- a/platform/pico2w/src/lib.rs +++ b/platform/pico2w/src/lib.rs @@ -5,16 +5,16 @@ extern crate alloc; #[cfg(target_arch = "arm")] pub mod audio; pub mod crash; -#[cfg(target_arch = "arm")] -pub mod integrity; -#[cfg(target_arch = "arm")] -pub mod mpu; pub mod display; #[cfg(target_arch = "arm")] pub mod flash_rom; pub mod input; +#[cfg(target_arch = "arm")] +pub mod integrity; pub mod menu; #[cfg(target_arch = "arm")] +pub mod mpu; +#[cfg(target_arch = "arm")] pub mod multicore; pub mod save_storage; #[cfg(target_arch = "arm")] diff --git a/platform/pico2w/src/main.rs b/platform/pico2w/src/main.rs index 7bfae88..8685916 100644 --- a/platform/pico2w/src/main.rs +++ b/platform/pico2w/src/main.rs @@ -631,4 +631,3 @@ async fn main(spawner: Spawner) { app.state = app.next_state.take().unwrap_or(state); } } - diff --git a/platform/pico2w/src/mpu.rs b/platform/pico2w/src/mpu.rs index fcd34a8..be5651f 100644 --- a/platform/pico2w/src/mpu.rs +++ b/platform/pico2w/src/mpu.rs @@ -110,12 +110,15 @@ pub unsafe fn setup_core1_mpu() { } let stack_bottom = core::ptr::addr_of!(_stack_end) as u32; let base = stack_bottom & !0x1F; // 32-byte aligned MPU region base - // RBAR: BASE | SH=11(b4:3) | AP=10(b2:1) | XN=1(b0) = base | 0x1D - // RLAR: LIMIT=0x2007FFE0 | AttrIndx=0(b3:1) | EN=1(b0) = 0x2007FFE1 + // RBAR: BASE | SH=11(b4:3) | AP=10(b2:1) | XN=1(b0) = base | 0x1D + // RLAR: LIMIT=0x2007FFE0 | AttrIndx=0(b3:1) | EN=1(b0) = 0x2007FFE1 MPU_RNR.write_volatile(0); MPU_RBAR.write_volatile(base | 0x1D); MPU_RLAR.write_volatile(0x2007_FFE1); - defmt::info!("core1 MPU region 0 base (from _stack_end) = 0x{=u32:08x}", base); + defmt::info!( + "core1 MPU region 0 base (from _stack_end) = 0x{=u32:08x}", + base + ); cortex_m::asm::dsb(); cortex_m::asm::isb(); diff --git a/platform/pico2w/src/wifi_codec.rs b/platform/pico2w/src/wifi_codec.rs index 08a66fc..cd03013 100644 --- a/platform/pico2w/src/wifi_codec.rs +++ b/platform/pico2w/src/wifi_codec.rs @@ -747,5 +747,4 @@ mod tests { build_dns_response(&query, AP_IP, &mut out).unwrap(); assert_eq!(&out[12..12 + q_section_len], &query[12..]); } - } diff --git a/platform/web/Dockerfile b/platform/web/Dockerfile index e42ea5e..107b404 100644 --- a/platform/web/Dockerfile +++ b/platform/web/Dockerfile @@ -36,7 +36,24 @@ RUN if [ "$DEBUG_OVERLAY" = "1" ]; then \ --release; \ fi -# ── Stage 2: Build the Axum server ───────────────────────────────────────── +# ── Stage 2: Build TypeScript frontend ───────────────────────────────────── +FROM node:20-slim AS ts-builder + +WORKDIR /build + +# Install deps first (layer cached until package.json changes) +COPY platform/web/client/package.json platform/web/client/package-lock.json ./ +RUN npm ci + +# Copy TS sources and build script (type-checking is skipped in CI; +# esbuild transpiles without tsc so no .d.ts files are needed here) +COPY platform/web/client/build.mjs ./ +COPY platform/web/client/src-ts ./src-ts + +RUN npm run build +# Output: ./static/app.js, ./static/menu.js, ./static/audio-processor.js + +# ── Stage 3: Build the Axum server ───────────────────────────────────────── FROM rust:1.88-slim AS server-builder WORKDIR /build @@ -45,7 +62,7 @@ COPY . . RUN cargo build --release -p rustyboy-web-server -# ── Stage 3: Runtime image ────────────────────────────────────────────────── +# ── Stage 4: Runtime image ────────────────────────────────────────────────── FROM debian:bookworm-slim RUN apt-get update && apt-get install -y \ @@ -58,9 +75,13 @@ COPY --from=server-builder \ /build/target/release/rustyboy-server \ /usr/local/bin/rustyboy-server -# Copy static assets: HTML/CSS/JS + WASM pkg +# Copy static assets: HTML/CSS + WASM pkg COPY platform/web/client/static /static COPY --from=wasm-builder /build/platform/web/client/pkg /static +# Overlay compiled TypeScript (replaces the hand-written JS in the static COPY above) +COPY --from=ts-builder /build/static/app.js /static/app.js +COPY --from=ts-builder /build/static/menu.js /static/menu.js +COPY --from=ts-builder /build/static/audio-processor.js /static/audio-processor.js # Expose port and set defaults EXPOSE 8080 diff --git a/platform/web/client/.gitignore b/platform/web/client/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/platform/web/client/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/platform/web/client/Cargo.toml b/platform/web/client/Cargo.toml index 555f538..7102e52 100644 --- a/platform/web/client/Cargo.toml +++ b/platform/web/client/Cargo.toml @@ -11,5 +11,7 @@ debug-overlay = [] [dependencies] rustyboy-core = { path = "../../../core" } +font8x8 = "0.3" +js-sys = "0.3" +ratatui = { version = "0.30", default-features = false } wasm-bindgen = "0.2" - diff --git a/platform/web/client/build.mjs b/platform/web/client/build.mjs new file mode 100644 index 0000000..98e2f5b --- /dev/null +++ b/platform/web/client/build.mjs @@ -0,0 +1,79 @@ +/** + * esbuild build script for the rustyboy web-client TypeScript frontend. + * + * Three entry points, three different output formats: + * app.ts → static/app.js (ESM; wasm import kept as external URL) + * menu.ts → static/menu.js (IIFE; sets window.MenuRenderer) + * audio-processor.ts→ static/audio-processor.js (IIFE; AudioWorklet classic script) + * + * Run: node build.mjs + */ + +import * as esbuild from 'esbuild'; +import { fileURLToPath } from 'url'; +import path from 'path'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const srcDir = path.join(__dirname, 'src-ts'); +const outDir = path.join(__dirname, 'static'); + +// Version tag used in the wasm-pack output filename. +// Must match the ?v= query string on the - + + diff --git a/platform/web/client/static/menu.js b/platform/web/client/static/menu.js deleted file mode 100644 index 72d93a8..0000000 --- a/platform/web/client/static/menu.js +++ /dev/null @@ -1,382 +0,0 @@ -/** - * MenuRenderer — draws GB-aesthetic menus directly onto the 160x144 game canvas. - * - * Usage: - * const menu = new MenuRenderer(canvas); - * menu.show({ - * title: 'SELECT GAME', - * items: [{ label: 'Tetris', value: 'tetris.gb' }, ...], - * footer: '▲▼ MOVE A SELECT B BACK', // optional, has default - * onSelect: (item) => { ... }, - * onBack: () => { ... }, // optional - * }); - */ - -(function () { - 'use strict'; - - // GB phosphor palette (dark → light) - const C0 = '#0F380F'; // darkest (background) - const C1 = '#306230'; // dark (header/footer fill, selection bg) - const C2 = '#8BAC0F'; // medium (unselected text) - const C3 = '#9BBC0F'; // lightest (selected text, header text) - - const W = 160; - const H = 144; - - const HEADER_H = 14; - const FOOTER_H = 14; - const ITEM_H = 14; - const LIST_TOP = HEADER_H + 2; - const LIST_BOTTOM = H - FOOTER_H - 2; - const MAX_VISIBLE = Math.floor((LIST_BOTTOM - LIST_TOP) / ITEM_H); // ≈ 8 - const TEXT_PAD = 6; - - class MenuRenderer { - constructor(canvas) { - this._canvas = canvas; - this._ctx = canvas.getContext('2d'); - this._active = false; - this._opts = null; - this._selIdx = 0; - this._scrollY = 0; // index of first visible item - this._touchStartY = null; - this._scale = 1; // physical-to-logical scale factor - // Marquee state - this._marqueeOffset = 0; // px scrolled left so far - this._marqueePhase = 'pause'; // 'pause' | 'scroll' - this._marqueePhaseAt = 0; // timestamp when current phase started - this._marqueeRafId = null; - this._marqueeOverflow = 0; // how many px the title overflows the header - this._marqueeScrollMax = 0; // total px to scroll before reset (title fully off-screen) - } - - // Compute the scale factor from the canvas's current physical buffer size. - // The canvas buffer is kept at physical resolution by a ResizeObserver in app.js, - // so we just read the current width rather than mutating canvas dimensions. - _scaleCanvas() { - this._scale = this._canvas.width / W; - } - - _restoreCanvas() { - this._scale = 1; - } - - // ── Public API ────────────────────────────────────────────────────────── - - show(options) { - this._opts = options; - this._selIdx = 0; - this._scrollY = 0; - this._marqueeOffset = 0; - this._marqueePhase = 'pause'; - this._marqueePhaseAt = performance.now(); - this._active = true; - this._scaleCanvas(); - // Measure title overflow (needs font set first, using logical scale) - this._ctx.save(); - this._ctx.scale(this._scale, this._scale); - this._ctx.font = 'bold 8px monospace'; - const titleW = this._ctx.measureText(options.title || '').width; - this._ctx.restore(); - const available = W - TEXT_PAD * 2; - this._marqueeOverflow = Math.max(0, Math.ceil(titleW - available)); - this._marqueeScrollMax = Math.ceil(TEXT_PAD + titleW); // scroll until fully off-screen - this.render(); - this._attachTouchListeners(); - if (this._marqueeOverflow > 0) this._startMarquee(); - } - - hide() { - this._active = false; - this._opts = null; - this._detachTouchListeners(); - this._stopMarquee(); - this._restoreCanvas(); - } - - isActive() { - return this._active; - } - - handleInput(key) { - if (!this._active || !this._opts) return; - const items = this._opts.items || []; - - switch (key) { - case 'ArrowUp': - case 'w': - this._selIdx = (this._selIdx - 1 + items.length) % items.length; - this._clampScroll(); - this.render(); - break; - - case 'ArrowDown': - case 's': - this._selIdx = (this._selIdx + 1) % items.length; - this._clampScroll(); - this.render(); - break; - - case 'Enter': - case 'a': - if (items.length > 0 && this._opts.onSelect) { - const item = items[this._selIdx]; - const cb = this._opts.onSelect; - this.hide(); - cb(item); - } - break; - - case 'Escape': - case 'b': - if (this._opts.onBack) { - const selIdx = this._selIdx; - const cb = this._opts.onBack; - this.hide(); - cb(selIdx); - } else { - this.hide(); - } - break; - - case 'Select': - if (this._opts.onSelectBtn) { - const selIdx = this._selIdx; - const cb = this._opts.onSelectBtn; - this.hide(); - cb(selIdx); - } - break; - } - } - - handleTap(x, y) { - if (!this._active || !this._opts) return; - const items = this._opts.items || []; - - // Check if tap is in the list area - if (y < LIST_TOP || y > LIST_BOTTOM) return; - - const row = Math.floor((y - LIST_TOP) / ITEM_H); - const itemIdx = this._scrollY + row; - if (itemIdx < 0 || itemIdx >= items.length) return; - - if (this._opts.onSelect) { - const item = items[itemIdx]; - const cb = this._opts.onSelect; - this.hide(); - cb(item); - } - } - - render() { - if (!this._active || !this._opts) return; - const ctx = this._ctx; - const items = this._opts.items || []; - - ctx.imageSmoothingEnabled = false; - ctx.save(); - ctx.scale(this._scale, this._scale); - - // ── Background ──────────────────────────────────────────────────────── - ctx.fillStyle = C0; - ctx.fillRect(0, 0, W, H); - - // ── Header ──────────────────────────────────────────────────────────── - ctx.fillStyle = C1; - ctx.fillRect(0, 0, W, HEADER_H); - ctx.fillStyle = C3; - ctx.font = 'bold 8px monospace'; - ctx.textBaseline = 'middle'; - const title = this._opts.title || ''; - if (this._marqueeOverflow > 0) { - // Scrolling title: clip to header, draw left-aligned minus scroll offset - ctx.save(); - ctx.rect(TEXT_PAD, 0, W - TEXT_PAD * 2, HEADER_H); - ctx.clip(); - ctx.textAlign = 'left'; - ctx.fillText(title, TEXT_PAD - this._marqueeOffset, HEADER_H / 2); - ctx.restore(); - } else { - ctx.textAlign = 'center'; - ctx.fillText(title, W / 2, HEADER_H / 2); - } - - // ── Footer ──────────────────────────────────────────────────────────── - const footerY = H - FOOTER_H; - ctx.fillStyle = C1; - ctx.fillRect(0, footerY, W, FOOTER_H); - ctx.fillStyle = C3; - ctx.font = 'bold 7px monospace'; - ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; - const footer = this._opts.footer || '\u25b2\u25bc MOVE A SELECT B BACK'; - ctx.fillText(footer, W / 2, footerY + FOOTER_H / 2); - - // ── Item list ───────────────────────────────────────────────────────── - ctx.font = 'bold 8px monospace'; - ctx.textAlign = 'left'; - ctx.textBaseline = 'middle'; - - const visible = Math.min(MAX_VISIBLE, items.length); - for (let i = 0; i < visible; i++) { - const itemIdx = this._scrollY + i; - if (itemIdx >= items.length) break; - const item = items[itemIdx]; - const rowTop = LIST_TOP + i * ITEM_H; - const rowMidY = rowTop + ITEM_H / 2; - const selected = itemIdx === this._selIdx; - - if (selected) { - ctx.fillStyle = C1; - ctx.fillRect(0, rowTop, W, ITEM_H); - ctx.fillStyle = C3; - ctx.fillText('\u25b6 ' + item.label, TEXT_PAD, rowMidY); - } else { - ctx.fillStyle = C2; - ctx.fillText(' ' + item.label, TEXT_PAD, rowMidY); - } - } - - // ── Scroll indicators ───────────────────────────────────────────────── - if (this._scrollY > 0) { - ctx.fillStyle = C3; - ctx.font = '7px monospace'; - ctx.textAlign = 'right'; - ctx.fillText('\u25b2', W - 2, LIST_TOP + 4); - } - if (this._scrollY + MAX_VISIBLE < items.length) { - ctx.fillStyle = C3; - ctx.font = '7px monospace'; - ctx.textAlign = 'right'; - ctx.fillText('\u25bc', W - 2, LIST_BOTTOM - 4); - } - - ctx.restore(); - } - - // ── Private ───────────────────────────────────────────────────────────── - - _startMarquee() { - if (this._marqueeRafId !== null) return; - const tick = (now) => { - if (!this._active) { this._marqueeRafId = null; return; } - this._tickMarquee(now); - this.render(); - this._marqueeRafId = requestAnimationFrame(tick); - }; - this._marqueeRafId = requestAnimationFrame(tick); - } - - _stopMarquee() { - if (this._marqueeRafId !== null) { - cancelAnimationFrame(this._marqueeRafId); - this._marqueeRafId = null; - } - } - - _tickMarquee(now) { - const PAUSE_MS = 1000; - const SCROLL_PX_PER_MS = 0.03; // ~30px/s - - const elapsed = now - this._marqueePhaseAt; - - if (this._marqueePhase === 'pause') { - if (elapsed >= PAUSE_MS) { - this._marqueePhase = 'scroll'; - this._marqueePhaseAt = now; - } - } else { - this._marqueeOffset = elapsed * SCROLL_PX_PER_MS; - if (this._marqueeOffset >= this._marqueeScrollMax) { - // Title fully off-screen — reset and pause again - this._marqueeOffset = 0; - this._marqueePhase = 'pause'; - this._marqueePhaseAt = now; - } - } - } - - _clampScroll() { - const items = (this._opts && this._opts.items) || []; - // Keep selected item visible - if (this._selIdx < this._scrollY) { - this._scrollY = this._selIdx; - } else if (this._selIdx >= this._scrollY + MAX_VISIBLE) { - this._scrollY = this._selIdx - MAX_VISIBLE + 1; - } - // Clamp to valid range - const maxScroll = Math.max(0, items.length - MAX_VISIBLE); - this._scrollY = Math.max(0, Math.min(this._scrollY, maxScroll)); - } - - _canvasCoords(clientX, clientY) { - const rect = this._canvas.getBoundingClientRect(); - const scaleX = W / rect.width; - const scaleY = H / rect.height; - return { - x: (clientX - rect.left) * scaleX, - y: (clientY - rect.top) * scaleY, - }; - } - - _onTouchStart(e) { - if (!this._active) return; - const t = e.changedTouches[0]; - this._touchStartY = t.clientY; - } - - _onTouchEnd(e) { - if (!this._active) return; - const t = e.changedTouches[0]; - const dy = t.clientY - (this._touchStartY || t.clientY); - this._touchStartY = null; - - // Ignore touches that ended outside the canvas bounds — this prevents - // d-pad button presses (which share touch coordinates with the canvas - // area on mobile) from accidentally triggering menu taps. - const rect = this._canvas.getBoundingClientRect(); - const outside = t.clientX < rect.left || t.clientX > rect.right || - t.clientY < rect.top || t.clientY > rect.bottom; - const msg = `MenuRenderer._onTouchEnd dy=${dy.toFixed(1)} outside=${outside} title=${this._opts?.title}`; - console.debug('[rustyboy:menu]', msg); - fetch('/dev/log', { method: 'POST', body: msg }).catch(() => {}); - if (outside) return; - - const items = (this._opts && this._opts.items) || []; - - if (Math.abs(dy) > 12) { - // Swipe: scroll - const delta = dy < 0 ? 1 : -1; - this._scrollY = Math.max(0, Math.min( - this._scrollY + delta, - Math.max(0, items.length - MAX_VISIBLE) - )); - this.render(); - } else { - // Tap: select item - const coords = this._canvasCoords(t.clientX, t.clientY); - this.handleTap(coords.x, coords.y); - } - } - - _attachTouchListeners() { - this._boundTouchStart = this._onTouchStart.bind(this); - this._boundTouchEnd = this._onTouchEnd.bind(this); - this._canvas.addEventListener('touchstart', this._boundTouchStart, { passive: true }); - this._canvas.addEventListener('touchend', this._boundTouchEnd, { passive: true }); - } - - _detachTouchListeners() { - if (this._boundTouchStart) { - this._canvas.removeEventListener('touchstart', this._boundTouchStart); - this._canvas.removeEventListener('touchend', this._boundTouchEnd); - this._boundTouchStart = null; - this._boundTouchEnd = null; - } - } - } - - window.MenuRenderer = MenuRenderer; -})(); diff --git a/platform/web/client/static/style.css b/platform/web/client/static/style.css index 9d7ee43..24e21dc 100644 --- a/platform/web/client/static/style.css +++ b/platform/web/client/static/style.css @@ -4,8 +4,6 @@ Mobile-first, tuned for iPhone 14+ viewport ============================================================ */ -@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Nunito:wght@400;700&display=swap'); - /* ── Reset & base ─────────────────────────────────────── */ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; } @@ -41,10 +39,20 @@ --btn-mid-hi: #B4B2AC; --btn-mid-shadow: #6A6860; - --gb-w: min(370px, 92vw, 54vh); + --screen-scale: 2; + --screen-w: calc(160px * var(--screen-scale)); + --screen-h: calc(144px * var(--screen-scale)); + --screen-shell-extra-w: 76px; + --gb-w: calc(var(--screen-w) + var(--screen-shell-extra-w)); --pixel: 'Press Start 2P', monospace; } +@media (max-width: 395px) { + :root { + --gb-w: 92vw; + } +} + html { background: #111; -webkit-tap-highlight-color: transparent; @@ -285,13 +293,22 @@ body { .screen-inner { position: relative; - width: 100%; - aspect-ratio: 160 / 144; + width: var(--screen-w); + height: var(--screen-h); + margin: 0 auto; background: var(--screen-bg); border-radius: 1px; overflow: hidden; } +@media (max-width: 395px) { + .screen-inner { + width: 100%; + height: auto; + aspect-ratio: 160 / 144; + } +} + #gameCanvas { position: absolute; inset: 0; @@ -666,10 +683,9 @@ button:focus-visible { /* ── Responsive ───────────────────────────────────────── */ @media (min-width: 430px) { - :root { --gb-w: min(420px, 88vw, 56vh); } + :root { --gb-w: calc(var(--screen-w) + var(--screen-shell-extra-w)); } } @media (min-width: 600px) { - :root { --gb-w: min(420px, 60vh); } .scene { padding: 20px 0; } } diff --git a/platform/web/client/tools/encode_landscape.py b/platform/web/client/tools/encode_landscape.py new file mode 100644 index 0000000..8765efd --- /dev/null +++ b/platform/web/client/tools/encode_landscape.py @@ -0,0 +1,226 @@ +#!/usr/bin/env -S uv run --with numpy +# /// script +# requires-python = ">=3.10" +# dependencies = ["numpy"] +# /// +""" +encode_landscape.py — Re-encode landscape_bg.bin into the compact RBG1 format. + +Old format +---------- + offset 0 : 256 bytes — palette, 64 RGBA entries (palette_len=64) + offset 256 : 120 × 23040 bytes — per-frame palette indices (1 byte / pixel, + 160×144 pixels per frame, row-major left-to-right top-to-bottom) + total : 2 765 056 bytes + +New format (RBG1, little-endian throughout) +------------------------------------------- + Header (14 bytes): + bytes 0– 3 : magic "RBG1" + bytes 4– 5 : width u16 (160) + bytes 6– 7 : height u16 (144) + bytes 8– 9 : frame_count u16 (120) + byte 10 : palette_len u8 (64) + byte 11 : bits_per_index u8 (3) + bytes 12–13 : static_rows u16 (number of top rows identical across all frames) + + Palette (palette_len × 4 bytes): + bytes 14 .. 14+palette_len*4 — RGBA bytes, indexed 0..palette_len-1 + + Static region (one copy of the frozen top rows, 3-bit-packed): + ceil(static_rows * width * 3 / 8) bytes + Bit layout: indices are concatenated LSB-first into a flat bit stream. + Pixel p's index occupies bits [p*3 .. p*3+2] in the stream, where + bit i is stored as (stream[i//8] >> (i%8)) & 1. + + Animated region (frame_count frames, each 3-bit-packed): + frame_count × ceil(anim_rows * width * 3 / 8) bytes + Each frame stores only the bottom anim_rows = height - static_rows rows, + using the same LSB-first 3-bit packing. + +Usage: + uv run --with numpy tools/encode_landscape.py + (run from the platform/web/client/ directory, or edit the paths below) +""" +import struct +import sys +from pathlib import Path + +import numpy as np + +# --------------------------------------------------------------------------- +# Paths — adjust if running from a different cwd +# --------------------------------------------------------------------------- +REPO_BASE = Path(__file__).resolve().parent.parent # platform/web/client/ +OLD_BIN = REPO_BASE / "src" / "landscape_bg.bin" +NEW_BIN = REPO_BASE / "src" / "landscape_bg.bin" # overwrite in-place + +WIDTH = 160 +HEIGHT = 144 +FRAME_COUNT = 120 +PALETTE_COLORS = 64 +PALETTE_BYTES = PALETTE_COLORS * 4 +FRAME_SIZE = WIDTH * HEIGHT # pixels (old: 1 byte each) +BITS_PER_INDEX = 3 + +def pack_indices_3bit(indices: np.ndarray) -> bytes: + """Pack a flat array of 3-bit indices (values 0..7) into an LSB-first bit stream.""" + n = len(indices) + out_bytes = (n * 3 + 7) // 8 + buf = bytearray(out_bytes) + for i, val in enumerate(indices): + bit_pos = i * 3 + byte_idx = bit_pos >> 3 + bit_off = bit_pos & 7 + # Write 3 bits across at most 2 bytes + val = int(val) & 0x7 + buf[byte_idx] |= (val << bit_off) & 0xFF + carry = val >> (8 - bit_off) + if carry and byte_idx + 1 < out_bytes: + buf[byte_idx + 1] |= carry + return bytes(buf) + +def unpack_indices_3bit(data: bytes, n_pixels: int) -> np.ndarray: + """Unpack n_pixels 3-bit indices from an LSB-first bit stream.""" + out = np.empty(n_pixels, dtype=np.uint8) + for i in range(n_pixels): + bit_pos = i * 3 + byte_idx = bit_pos >> 3 + bit_off = bit_pos & 7 + lo = (data[byte_idx] >> bit_off) & 0xFF + if bit_off <= 5: + val = lo & 0x7 + else: + # spans two bytes + hi = data[byte_idx + 1] if byte_idx + 1 < len(data) else 0 + val = (lo | (hi << (8 - bit_off))) & 0x7 + out[i] = val + return out + +def main(): + print(f"Reading {OLD_BIN} ...") + raw = OLD_BIN.read_bytes() + old_size = len(raw) + print(f" Old size: {old_size:,} bytes") + + # ----------------------------------------------------------------------- + # Parse old format + # ----------------------------------------------------------------------- + expected_size = PALETTE_BYTES + FRAME_COUNT * FRAME_SIZE + assert len(raw) == expected_size, ( + f"Unexpected size: got {len(raw)}, expected {expected_size}" + ) + + palette = raw[:PALETTE_BYTES] + + # frames[f, row, col] = palette index (uint8) + frames_flat = np.frombuffer(raw[PALETTE_BYTES:], dtype=np.uint8) + frames = frames_flat.reshape(FRAME_COUNT, HEIGHT, WIDTH) + + # ----------------------------------------------------------------------- + # Assert ≤ 8 distinct indices + # ----------------------------------------------------------------------- + distinct = np.unique(frames_flat) + print(f" Distinct palette indices used: {distinct.tolist()}") + assert len(distinct) <= 8, f"More than 8 distinct indices: {len(distinct)}" + assert all(v < 8 for v in distinct), f"Index ≥ 8 found: {distinct}" + print(f" OK — fits in {BITS_PER_INDEX} bits") + + # ----------------------------------------------------------------------- + # Find static_rows: largest prefix of rows identical across all frames + # ----------------------------------------------------------------------- + static_rows = 0 + for row in range(HEIGHT): + row_data = frames[:, row, :] # shape (FRAME_COUNT, WIDTH) + if np.all(row_data == row_data[0]): + static_rows += 1 + else: + break + + print(f" Static (frozen) top rows: {static_rows}") + assert static_rows > 0, "No static rows found!" + + anim_rows = HEIGHT - static_rows + + # ----------------------------------------------------------------------- + # Encode new format + # ----------------------------------------------------------------------- + # Header + magic = b"RBG1" + header = magic + header += struct.pack("10,} bytes ({old_size/1024/1024:.2f} MB)") + print(f" New size : {new_size:>10,} bytes ({new_size/1024/1024:.2f} MB)") + print(f" Reduction: {100*(1 - new_size/old_size):.1f}%") + print(f" static_rows={static_rows}, anim_rows={anim_rows}") + print(f" static packed: {len(static_packed):,} bytes") + print(f" anim per frame: {anim_bytes_per_frame:,} bytes × {FRAME_COUNT} = {anim_bytes_per_frame*FRAME_COUNT:,} bytes") + +if __name__ == "__main__": + main() diff --git a/platform/web/client/tsconfig.json b/platform/web/client/tsconfig.json new file mode 100644 index 0000000..caa894c --- /dev/null +++ b/platform/web/client/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "noEmit": true, + "skipLibCheck": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "baseUrl": ".", + "paths": { + "rustyboy-wasm": ["./static/rustyboy_web_client.d.ts"] + } + }, + "include": ["src-ts/app.ts", "src-ts/menu.ts", "src-ts/types.ts"] +} diff --git a/platform/web/client/tsconfig.worklet.json b/platform/web/client/tsconfig.worklet.json new file mode 100644 index 0000000..3fa6024 --- /dev/null +++ b/platform/web/client/tsconfig.worklet.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "ES2020", + "lib": ["ES2020"], + "strict": true, + "noEmit": true, + "skipLibCheck": true + }, + "include": ["src-ts/audio-processor.ts", "src-ts/audioworklet.d.ts"] +} diff --git a/platform/web/e2e/fixtures/rustyboy_web_client_stub.js b/platform/web/e2e/fixtures/rustyboy_web_client_stub.js index c2199a8..6d8244a 100644 --- a/platform/web/e2e/fixtures/rustyboy_web_client_stub.js +++ b/platform/web/e2e/fixtures/rustyboy_web_client_stub.js @@ -1,4 +1,84 @@ export default async function init() { return {}; } + +export class WasmMenuRenderer { + constructor() { + this.title = ''; + this.labels = []; + this.footer = ''; + this.selected = 0; + this.scrollY = 0; + } + + show(title, labels, footer) { + this.title = String(title || ''); + this.labels = Array.from(labels || [], label => String(label || '')); + this.footer = String(footer || ''); + this.selected = 0; + this.scrollY = 0; + } + + selected_index() { return this.selected; } + scroll_y() { return this.scrollY; } + title_width_px() { return this.title.length * 8; } + free() {} + + set_selected(index) { + if (this.labels.length === 0) { + this.selected = 0; + this.scrollY = 0; + return; + } + this.selected = Math.max(0, Math.min(index, this.labels.length - 1)); + this.#clampScroll(); + } + + move_selection(delta) { + if (this.labels.length === 0) return; + this.selected = (this.selected + delta + this.labels.length) % this.labels.length; + this.#clampScroll(); + } + + scroll_by(delta) { + const maxScroll = Math.max(0, this.labels.length - 14); + this.scrollY = Math.max(0, Math.min(this.scrollY + delta, maxScroll)); + } + + item_at(x, y) { + if (x < 0 || x >= 160 || y < 16 || y >= 128) return -1; + const idx = this.scrollY + Math.floor((y - 16) / 8); + return idx >= 0 && idx < this.labels.length ? idx : -1; + } + + render_rgba() { + const out = new Uint8Array(160 * 144 * 4); + const fill = (x0, y0, w, h, color) => { + for (let y = y0; y < y0 + h; y++) { + for (let x = x0; x < x0 + w; x++) { + const i = (y * 160 + x) * 4; + out.set(color, i); + } + } + }; + const C0 = [0x0F, 0x38, 0x0F, 0xFF]; + const C1 = [0x30, 0x62, 0x30, 0xFF]; + fill(0, 0, 160, 144, C0); + fill(0, 0, 160, 16, C1); + fill(0, 128, 160, 16, C1); + const selectedY = 16 + (this.selected - this.scrollY) * 8; + if (selectedY >= 16 && selectedY < 128) fill(0, selectedY, 160, 8, C1); + return out; + } + + #clampScroll() { + if (this.selected < this.scrollY) { + this.scrollY = this.selected; + } else if (this.selected >= this.scrollY + 14) { + this.scrollY = this.selected - 13; + } + this.scrollY = Math.max(0, Math.min(this.scrollY, Math.max(0, this.labels.length - 14))); + } +} + export class EmulatorHandle { constructor(rom) {} run_frame() {} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 9711f05..d149a25 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -144,7 +144,13 @@ fn build_web(root: &Path, debug_overlay: bool) -> Result<()> { } else { println!("🔨 Building rustyboy-web Docker image…"); } - let mut args = vec!["build", "-f", "platform/web/Dockerfile", "-t", "rustyboy-web"]; + let mut args = vec![ + "build", + "-f", + "platform/web/Dockerfile", + "-t", + "rustyboy-web", + ]; if debug_overlay { args.extend_from_slice(&["--build-arg", "DEBUG_OVERLAY=1"]); } @@ -238,7 +244,11 @@ fn deploy_pico(root: &Path) -> Result<()> { let elf = root.join("target/thumbv8m.main-none-eabihf/release/rustyboy-pico2w"); println!("⚡ Flashing via picotool…"); - cmd("picotool", &["load", "-f", "-t", "elf", elf.to_str().unwrap()], root)?; + cmd( + "picotool", + &["load", "-f", "-t", "elf", elf.to_str().unwrap()], + root, + )?; cmd("picotool", &["reboot"], root)?; println!("✅ Done — Pico 2W is rebooting into the new firmware."); Ok(()) @@ -364,7 +374,11 @@ fn setup_pico() -> Result<()> { reload_udev(); let user = current_user(); - cmd_best_effort("sudo", &["usermod", "-aG", "plugdev", &user], Path::new("/")); + cmd_best_effort( + "sudo", + &["usermod", "-aG", "plugdev", &user], + Path::new("/"), + ); println!("\n✅ pico setup complete."); println!( @@ -432,11 +446,7 @@ fn install_picotool() -> Result<()> { let sdk_path_arg = format!("-DPICO_SDK_PATH={}", sdk_dir.display()); println!("🔨 Building picotool…"); - cmd( - "cmake", - &["..", &sdk_path_arg], - &cmake_build, - )?; + cmd("cmake", &["..", &sdk_path_arg], &cmake_build)?; let jobs = nproc().to_string(); cmd("make", &["-j", &jobs], &cmake_build)?;