From 3f315a25c94a213d913fd23a124397a0e23b9f14 Mon Sep 17 00:00:00 2001 From: Conando Date: Mon, 26 Feb 2024 00:00:39 +0100 Subject: [PATCH] Project restructuring Set the project up to use cargo workspaces --- .gitignore | 1 + Cargo.lock | 7 +++++ Cargo.toml | 13 ++------ examples/Cargo.toml | 10 ++++++ examples/mvp/arm7.rs | 49 +++++++++++++++++++++++++++++ examples/mvp/arm9.rs | 17 ++++++++++ examples/mvp/main.rs | 19 +++++++++++ lib/Cargo.toml | 11 +++++++ {src => lib/src}/arm7/constants.rs | 0 {src => lib/src}/arm7/firmware.rs | 0 {src => lib/src}/arm7/interrupts.rs | 0 {src => lib/src}/arm7/mod.rs | 0 {src => lib/src}/arm9/mod.rs | 0 {src => lib/src}/aux.rs | 0 {src => lib/src}/lib.rs | 0 15 files changed, 116 insertions(+), 11 deletions(-) create mode 100644 examples/Cargo.toml create mode 100644 examples/mvp/arm7.rs create mode 100644 examples/mvp/arm9.rs create mode 100644 examples/mvp/main.rs create mode 100644 lib/Cargo.toml rename {src => lib/src}/arm7/constants.rs (100%) rename {src => lib/src}/arm7/firmware.rs (100%) rename {src => lib/src}/arm7/interrupts.rs (100%) rename {src => lib/src}/arm7/mod.rs (100%) rename {src => lib/src}/arm9/mod.rs (100%) rename {src => lib/src}/aux.rs (100%) rename {src => lib/src}/lib.rs (100%) diff --git a/.gitignore b/.gitignore index ea8c4bf..0f84cc9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +/.vscode \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 3ef0a3d..02d2b6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,3 +31,10 @@ dependencies = [ "libc-print", "libc_alloc", ] + +[[package]] +name = "nitro-rs_examples" +version = "0.0.1" +dependencies = [ + "nitro-rs", +] diff --git a/Cargo.toml b/Cargo.toml index 90ab70a..f13cd74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,2 @@ -[package] -name = "nitro-rs" -version = "0.0.1" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -libc = {version = "0.2.121", default-features = true} -libc_alloc = "1.0.4" -libc-print = "0.1.20" \ No newline at end of file +[workspace] +members = ["examples", "lib"] \ No newline at end of file diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 0000000..49f2881 --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "nitro-rs_examples" +version = "0.0.1" + +[[bin]] +name = "mvp" +path = "mpv/main.rs" + +[dependencies] +nitro-rs = { path = "../lib" } diff --git a/examples/mvp/arm7.rs b/examples/mvp/arm7.rs new file mode 100644 index 0000000..116674e --- /dev/null +++ b/examples/mvp/arm7.rs @@ -0,0 +1,49 @@ +use core::{ptr::read_volatile, sync::atomic::AtomicBool, sync::atomic::Ordering}; + +use nitro_rs::arm7::*; +//use libnds_sys::bios_registers::*; + +unsafe extern "C" fn vblank_handler() { + Wifi_Update(); +} + +unsafe extern "C" fn vcount_handler() { + inputGetAndSend(); +} + +static EXIT_FLAG: AtomicBool = AtomicBool::new(false); + +unsafe extern "C" fn power_button_cb() { + EXIT_FLAG.store(true, core::sync::atomic::Ordering::Release); +} + +#[start] +fn main(_argc: isize, _argv: *const *const u8) -> isize { + unsafe { + readUserSettings(); + unimplemented!(); + irqInit(); + fifoInit(); + mmInstall(FIFO_MAXMOD as i32); + // Start the RTC tracking IRQ + initClockIRQ(); + + SetYtrigger(30); + installWifiFIFO(); + installSoundFIFO(); + installSystemFIFO(); + irqSet(IRQ_VCOUNT as u32, Some(vcount_handler)); + irqSet(IRQ_VBLANK as u32, Some(vblank_handler)); + irqEnable((IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK) as u32); + setPowerButtonCB(Some(power_button_cb)); + + // Keep the ARM7 mostly idle + while !EXIT_FLAG.load(Ordering::Acquire) { + let keyinput = read_volatile(REG_KEYINPUT); + if (keyinput & KEY_START as u16) > 0 { + EXIT_FLAG.store(true, Ordering::Release); + } + } + return 0; + } +} diff --git a/examples/mvp/arm9.rs b/examples/mvp/arm9.rs new file mode 100644 index 0000000..ab3de6f --- /dev/null +++ b/examples/mvp/arm9.rs @@ -0,0 +1,17 @@ +use nitro_rs::arm9::*; + +#[start] +fn main(_argc: isize, _argv: *const *const u8) -> isize +{ + unsafe { + loop { + scanKeys(); + if (keysDown() & KEY_START) > 0 + { + swiWaitForVBlank(); + break; + } + } + } + return 0; +} diff --git a/examples/mvp/main.rs b/examples/mvp/main.rs new file mode 100644 index 0000000..03d3fa9 --- /dev/null +++ b/examples/mvp/main.rs @@ -0,0 +1,19 @@ +#![no_std] +#![feature(start)] + +extern crate nitro_rs; + +#[cfg(target_os = "nintendo_ds_arm7")] +mod arm7; + +#[cfg(target_os = "nintendo_ds_arm9")] +mod arm9; + +#[global_allocator] +static ALLOCATOR: libc_alloc::LibcAlloc = libc_alloc::LibcAlloc; + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop { + } +} diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..90ab70a --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "nitro-rs" +version = "0.0.1" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libc = {version = "0.2.121", default-features = true} +libc_alloc = "1.0.4" +libc-print = "0.1.20" \ No newline at end of file diff --git a/src/arm7/constants.rs b/lib/src/arm7/constants.rs similarity index 100% rename from src/arm7/constants.rs rename to lib/src/arm7/constants.rs diff --git a/src/arm7/firmware.rs b/lib/src/arm7/firmware.rs similarity index 100% rename from src/arm7/firmware.rs rename to lib/src/arm7/firmware.rs diff --git a/src/arm7/interrupts.rs b/lib/src/arm7/interrupts.rs similarity index 100% rename from src/arm7/interrupts.rs rename to lib/src/arm7/interrupts.rs diff --git a/src/arm7/mod.rs b/lib/src/arm7/mod.rs similarity index 100% rename from src/arm7/mod.rs rename to lib/src/arm7/mod.rs diff --git a/src/arm9/mod.rs b/lib/src/arm9/mod.rs similarity index 100% rename from src/arm9/mod.rs rename to lib/src/arm9/mod.rs diff --git a/src/aux.rs b/lib/src/aux.rs similarity index 100% rename from src/aux.rs rename to lib/src/aux.rs diff --git a/src/lib.rs b/lib/src/lib.rs similarity index 100% rename from src/lib.rs rename to lib/src/lib.rs