summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: b9cd4db4a936fa9655cc177e159ee1fc72328912 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#![feature(restricted_std)]

use core::ptr::null_mut;
use libctru::raw::{
    aptMainLoop, c_char, c_int, consoleInit, gfxExit, gfxFlushBuffers, gfxInitDefault,
    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();

        consoleInit(gfxScreen_t_GFX_TOP, null_mut());

        libctru::println!("Standard print in next line:");
        println!("Standard print");

        std::thread::spawn(|| {
            println!("Hello thread world");
        })
        .join()
        .unwrap();

        libctru::println!("Check end");

        while aptMainLoop() {
            hidScanInput();
            let keys = hidKeysDown();

            if keys & (KEY_START as u32) != 0 {
                break;
            }

            gfxFlushBuffers();
            gfxSwapBuffers();

            gspWaitForEvent(GSPGPU_Event_GSPGPU_EVENT_VBlank0, true);
        }

        gfxExit();
    }

    0
}