From 3329bcb30038f4ba7ade56c8ef15a2663c700506 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Mon, 30 May 2016 20:03:48 -0700 Subject: [PATCH] More experimental console/stdio stuff. --- 3ds.json | 9 +++---- Cargo.toml | 3 --- ctru-sys/src/ipc.rs | 3 +-- ctru-sys/src/result.rs | 54 ++++++++++++++++++++++++++++++++++++++++++ src/console.rs | 24 +++++++++++++++---- src/lib.rs | 4 +--- 6 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 ctru-sys/src/result.rs diff --git a/3ds.json b/3ds.json index a54295d..3255f2a 100644 --- a/3ds.json +++ b/3ds.json @@ -18,12 +18,13 @@ "dynamic-linking": false, "no-compiler-rt": true, "exe-suffix": ".elf", - "pre-link-args": ["-specs", + "is-like-windows": true, + "function-sections": false, + "pre-link-args": [ + "-specs", "3dsx.specs", "-march=armv6k", "-mtune=mpcore", "-mfloat-abi=hard" - ], - "is-like-windows": true, - "function-sections": false + ] } diff --git a/Cargo.toml b/Cargo.toml index d691e86..3418dff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,6 @@ links = "ctru" name = "ctru-rs" version = "0.2.1" -[dependencies] -rcstring = "0.2.1" - [dependencies.ctru-sys] path = "ctru-sys" diff --git a/ctru-sys/src/ipc.rs b/ctru-sys/src/ipc.rs index 390022d..419b3ec 100644 --- a/ctru-sys/src/ipc.rs +++ b/ctru-sys/src/ipc.rs @@ -1,4 +1,4 @@ -//TODO: Implement static inline functions + solve the anonymous enum enigma +//TODO: Implement static inline functions #[derive(Clone, Copy)] #[repr(C)] @@ -7,4 +7,3 @@ pub enum IPC_BufferRights { IPC_BUFFER_W = 4, IPC_BUFFER_RW = 6, } - diff --git a/ctru-sys/src/result.rs b/ctru-sys/src/result.rs new file mode 100644 index 0000000..f8ad8b4 --- /dev/null +++ b/ctru-sys/src/result.rs @@ -0,0 +1,54 @@ +//TODO: Implement C macro functions? Maybe? + +//Result code level values +pub const RL_SUCCESS :i32 = 0; +pub const RL_INFO :i32 = 1; +pub const RL_FATAL :i32 = 31; +pub const RL_RESET :i32 = 30; +pub const RL_REINITIALIZE :i32 = 29; +pub const RL_USAGE :i32 = 28; +pub const RL_PERMANENT :i32 = 27; +pub const RL_TEMPORARY :i32 = 26; +pub const RL_STATUS :i32 = 25; + +//Result code summary values +pub const RS_SUCCESS :i32 = 0; +pub const RS_NOP :i32 = 1; +pub const RS_WOULDBLOCK :i32 = 2; +pub const RS_OUTOFRESOURCE :i32 = 3; +pub const RS_NOTFOUND :i32 = 4; +pub const RS_INVALIDSTATE :i32 = 5; +pub const RS_NOTSUPPORTED :i32 = 6; +pub const RS_INVALIDARG :i32 = 7; +pub const RS_WRONGARG :i32 = 8; +pub const RS_CANCELED :i32 = 9; +pub const RS_STATUSCHANGED :i32 = 10; +pub const RS_INTERNAL :i32 = 11; +pub const RS_INVALIDRESVAL :i32 = 63; + +//Result code generic description values +pub const RD_SUCCESS :i32 = 0; +pub const RD_INVALID_RESULT_VALUE :i32 = 1023; +pub const RD_TIMEOUT :i32 = 1022; +pub const RD_OUT_OF_RANGE :i32 = 1021; +pub const RD_ALREADY_EXISTS :i32 = 1020; +pub const RD_CANCEL_REQUESTED :i32 = 1019; +pub const RD_NOT_FOUND :i32 = 1018; +pub const RD_ALREADY_INITIALIZED :i32 = 1017; +pub const RD_NOT_INITIALIZED :i32 = 1016; +pub const RD_INVALID_HANDLE :i32 = 1015; +pub const RD_INVALID_POINTER :i32 = 1014; +pub const RD_INVALID_ADDRESS :i32 = 1013; +pub const RD_NOT_IMPLEMENTED :i32 = 1012; +pub const RD_OUT_OF_MEMORY :i32 = 1011; +pub const RD_MISALIGNED_SIZE :i32 = 1010; +pub const RD_MISALIGNED_ADDRESS :i32 = 1009; +pub const RD_BUSY :i32 = 1008; +pub const RD_NO_DATA :i32 = 1007; +pub const RD_INVALID_COMBINATION :i32 = 1006; +pub const RD_INVALID_ENUM_VALUE :i32 = 1005; +pub const RD_INVALID_SIZE :i32 = 1004; +pub const RD_ALREADY_DONE :i32 = 1003; +pub const RD_NOT_AUTHORIZED :i32 = 1002; +pub const RD_TOO_LARGE :i32 = 1001; +pub const RD_INVALID_SELECTION :i32 = 1000; diff --git a/src/console.rs b/src/console.rs index 98090d5..c8c9601 100644 --- a/src/console.rs +++ b/src/console.rs @@ -1,17 +1,31 @@ -use libctru::console::{PrintConsole, consoleInit}; +use libctru::console::{PrintConsole, consoleInit, consoleClear}; use libctru::gfx; -use rcstring::CString; use core::ptr; extern "C" { - fn puts(cstr: *const u8) -> u8; + fn putchar(ch: u8) -> i32; } pub fn console_default_init() -> *mut PrintConsole { unsafe { consoleInit(gfx::gfxScreen_t::GFX_TOP, ptr::null_mut()) } } -pub fn console_write<'a>(s: &'a str) -> u8 { - unsafe { puts(CString::new(s).unwrap().into_raw()) } +pub fn console_write<'a>(s: &'a str) { + unsafe { + for c in s.as_bytes().iter() { + putchar(*c); + } + } +} + +pub fn console_writeln<'a>(s: &'a str) { + unsafe { + console_write(s); + putchar('\n' as u8); + } +} + +pub fn console_clear() { + unsafe { consoleClear() } } diff --git a/src/lib.rs b/src/lib.rs index 70de26c..f082bf9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ -#![no_std] #![feature(lang_items, alloc, collections, slice_concat_ext, macro_reexport, allow_internal_unstable)] +#![no_std] #![crate_type = "rlib"] #![crate_name = "ctru"] @@ -8,8 +8,6 @@ extern crate alloc; extern crate collections; extern crate ctru_sys as libctru; -#[macro_use] -extern crate rcstring; pub mod console; pub mod srv;