diff options
| author | Dario Bartussek <[email protected]> | 2021-04-20 18:13:39 +0200 |
|---|---|---|
| committer | Dario Bartussek <[email protected]> | 2021-04-20 18:13:39 +0200 |
| commit | f8d74724667f349184ab6e0d8cf87573afc8eb82 (patch) | |
| tree | 245ef00962a2eb807d4725f2c0c81aa15bfa5e15 | |
| parent | Experimental use of Rust std (diff) | |
| download | rust_3ds-f8d74724667f349184ab6e0d8cf87573afc8eb82.tar.xz rust_3ds-f8d74724667f349184ab6e0d8cf87573afc8eb82.zip | |
Custom std can now create threads and panic
| -rw-r--r-- | src/lib.rs | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -3,12 +3,32 @@ use core::ptr::null_mut; use libctru::raw::{ aptMainLoop, c_char, c_int, consoleInit, gfxExit, gfxFlushBuffers, gfxInitDefault, - gfxScreen_t_GFX_TOP, gfxSwapBuffers, gspWaitForEvent, hidKeysDown, hidScanInput, - GSPGPU_Event_GSPGPU_EVENT_VBlank0, KEY_START, + gfxScreen_t_GFX_BOTTOM, gfxScreen_t_GFX_TOP, gfxSwapBuffers, gspWaitForEvent, hidKeysDown, + hidScanInput, GSPGPU_Event_GSPGPU_EVENT_VBlank0, KEY_START, }; #[no_mangle] pub extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int { + std::panic::set_hook(Box::new(|info| unsafe { + consoleInit(gfxScreen_t_GFX_BOTTOM, null_mut()); + + println!("Rust panic: \n {}\nPress start to crash", info); + + while aptMainLoop() { + hidScanInput(); + let keys = hidKeysDown(); + + if keys & (KEY_START as u32) != 0 { + break; + } + + gfxFlushBuffers(); + gfxSwapBuffers(); + + gspWaitForEvent(GSPGPU_Event_GSPGPU_EVENT_VBlank0, true); + } + })); + unsafe { gfxInitDefault(); @@ -20,7 +40,8 @@ pub extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int { std::thread::spawn(|| { println!("Hello thread world"); }) - .join(); + .join() + .unwrap(); libctru::println!("Check end"); |