summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 1970dfd593bd1615221c964df465c68461f57564 (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
#![no_std]

use core::{panic::PanicInfo, 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,
};

extern "C" {
    fn puts(string: *const c_char);
}

#[no_mangle]
pub extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int {
    unsafe {
        gfxInitDefault();

        consoleInit(gfxScreen_t_GFX_TOP, null_mut());

        puts("Hello World from Rust".as_ptr());

        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
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}