From 1f8f4e05410df148b7f3c3fd35f85c9b37d0401f Mon Sep 17 00:00:00 2001 From: Dario Bartussek Date: Mon, 19 Apr 2021 13:50:42 +0200 Subject: Simple hello world program using libctru --- src/lib.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/lib.rs (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..1970dfd --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,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 {} +} -- cgit v1.2.3