Maccraft123
2 years ago
4 changed files with 89 additions and 0 deletions
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
use ctru::prelude::*; |
||||
use ctru::services::am::Am; |
||||
use ctru::services::fs::FsMediaType; |
||||
|
||||
fn main() { |
||||
ctru::use_panic_handler(); |
||||
|
||||
let gfx = Gfx::init().expect("Couldn't obtain GFX controller"); |
||||
let hid = Hid::init().expect("Couldn't obtain HID controller"); |
||||
let apt = Apt::init().expect("Couldn't obtain APT controller"); |
||||
let am = Am::init().expect("Couldn't obtain AM controller"); |
||||
let _console = Console::init(gfx.top_screen.borrow_mut()); |
||||
|
||||
let title_count = am.get_title_count(FsMediaType::Sd).expect("Failed to get title count"); |
||||
println!("This 3DS has {title_count} titles on its SD Card:"); |
||||
|
||||
let title_list = am.get_title_list(FsMediaType::Sd).expect("Failed to get title list"); |
||||
for id in title_list { |
||||
println!("{id:x}"); |
||||
} |
||||
|
||||
// Main loop
|
||||
while apt.main_loop() { |
||||
//Scan all the inputs. This should be done once for each frame
|
||||
hid.scan_input(); |
||||
|
||||
if hid.keys_down().contains(KeyPad::KEY_START) { |
||||
break; |
||||
} |
||||
// Flush and swap framebuffers
|
||||
gfx.flush_buffers(); |
||||
gfx.swap_buffers(); |
||||
|
||||
//Wait for VBlank
|
||||
gfx.wait_for_vblank(); |
||||
} |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
use crate::error::ResultCode; |
||||
use crate::services::fs::FsMediaType; |
||||
|
||||
pub struct Am(()); |
||||
|
||||
impl Am { |
||||
pub fn init() -> crate::Result<Am> { |
||||
unsafe { |
||||
ResultCode(ctru_sys::amInit())?; |
||||
Ok(Am(())) |
||||
} |
||||
} |
||||
|
||||
pub fn get_title_count(&self, mediatype: FsMediaType) -> crate::Result<u32> { |
||||
unsafe { |
||||
let mut count = 0; |
||||
ResultCode(ctru_sys::AM_GetTitleCount(mediatype as u32, &mut count))?; |
||||
Ok(count) |
||||
} |
||||
} |
||||
|
||||
pub fn get_title_list(&self, mediatype: FsMediaType) -> crate::Result<Vec<u64>> { |
||||
unsafe { |
||||
let count = self.get_title_count(mediatype)?; |
||||
let mut buf = Vec::with_capacity(count as usize); |
||||
let mut read_amount = 0; |
||||
ResultCode(ctru_sys::AM_GetTitleList( |
||||
&mut read_amount, |
||||
mediatype as u32, |
||||
count, |
||||
buf.as_mut_ptr(), |
||||
))?; |
||||
buf.set_len(read_amount as usize); |
||||
Ok(buf) |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl Drop for Am { |
||||
fn drop(&mut self) { |
||||
unsafe { ctru_sys::amExit() }; |
||||
} |
||||
} |
Loading…
Reference in new issue