Browse Source

More experimental console/stdio stuff.

pull/10/head
Fenrir 9 years ago
parent
commit
3329bcb300
  1. 9
      3ds.json
  2. 3
      Cargo.toml
  3. 3
      ctru-sys/src/ipc.rs
  4. 54
      ctru-sys/src/result.rs
  5. 24
      src/console.rs
  6. 4
      src/lib.rs

9
3ds.json

@ -18,12 +18,13 @@ @@ -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
]
}

3
Cargo.toml

@ -7,9 +7,6 @@ links = "ctru" @@ -7,9 +7,6 @@ links = "ctru"
name = "ctru-rs"
version = "0.2.1"
[dependencies]
rcstring = "0.2.1"
[dependencies.ctru-sys]
path = "ctru-sys"

3
ctru-sys/src/ipc.rs

@ -1,4 +1,4 @@ @@ -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 { @@ -7,4 +7,3 @@ pub enum IPC_BufferRights {
IPC_BUFFER_W = 4,
IPC_BUFFER_RW = 6,
}

54
ctru-sys/src/result.rs

@ -0,0 +1,54 @@ @@ -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;

24
src/console.rs

@ -1,17 +1,31 @@ @@ -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() }
}

4
src/lib.rs

@ -1,5 +1,5 @@ @@ -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; @@ -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;

Loading…
Cancel
Save