summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDario Bartussek <[email protected]>2021-04-19 13:50:42 +0200
committerDario Bartussek <[email protected]>2021-04-19 13:50:42 +0200
commit1f8f4e05410df148b7f3c3fd35f85c9b37d0401f (patch)
tree02f04335c9c2a9497b9c4a7113e0d1338194d674 /src
parentMerge branch '2_3ds_exe' of https://github.com/dbartussek/rust_3ds into 2_3ds... (diff)
downloadrust_3ds-1f8f4e05410df148b7f3c3fd35f85c9b37d0401f.tar.xz
rust_3ds-1f8f4e05410df148b7f3c3fd35f85c9b37d0401f.zip
Simple hello world program using libctru2.5_libctru
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs46
-rw-r--r--src/main.rs18
-rw-r--r--src/start.s22
3 files changed, 46 insertions, 40 deletions
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 {}
+}
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index 6133bfd..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-#![feature(asm)]
-#![no_std]
-#![no_main]
-
-use core::panic::PanicInfo;
-
-#[no_mangle]
-pub extern "C" fn pre_main() -> ! {
- unsafe {
- core::ptr::null::<usize>().read_volatile();
- }
- loop {}
-}
-
-#[panic_handler]
-fn panic(_info: &PanicInfo) -> ! {
- loop {}
-}
diff --git a/src/start.s b/src/start.s
deleted file mode 100644
index 158feef..0000000
--- a/src/start.s
+++ /dev/null
@@ -1,22 +0,0 @@
-.cpu mpcore
-.section ".crt0","ax"
-
-.align 2
-.arm
-
-_start:
- b pre_main
-
-.ascii "_prm"
-__service_ptr:
- .word 0
-__apt_appid:
- .word 0x300
-__heap_size:
- .word 24*1024*1024
-__linear_heap_size:
- .word 32*1024*1024
-__system_arglist:
- .word 0
-__system_runflags:
- .word 0