Browse Source

Update libraries for ctru-sys changes

pull/10/head
Fenrir 8 years ago
parent
commit
a572fa0a5a
  1. 31
      ctr-std/3ds.json
  2. 7
      ctr-std/Xargo.toml
  3. 6
      ctr-std/src/panicking.rs
  4. 4
      ctr-std/src/sys/unix/condvar.rs
  5. 24
      ctr-std/src/sys/unix/mutex.rs
  6. 2
      ctr-std/src/sys/unix/rand.rs
  7. 8
      ctr-std/src/sys/unix/thread.rs
  8. 2
      ctr-std/src/sys/unix/time.rs
  9. 31
      ctru-rs/3ds.json
  10. 3
      ctru-rs/Cargo.toml
  11. 11
      ctru-rs/Xargo.toml
  12. 12
      ctru-rs/src/console.rs
  13. 58
      ctru-rs/src/gfx.rs
  14. 6
      ctru-rs/src/sdmc.rs
  15. 12
      ctru-rs/src/services/apt.rs
  16. 72
      ctru-rs/src/services/fs.rs
  17. 20
      ctru-rs/src/services/gspgpu.rs
  18. 17
      ctru-rs/src/services/hid.rs
  19. 13
      ctru-rs/src/services/sslc.rs
  20. 6
      ctru-rs/src/srv.rs

31
ctr-std/3ds.json

@ -1,31 +0,0 @@
{
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"llvm-target": "arm-none-eabihf",
"linker": "arm-none-eabi-gcc",
"ar": "arm-none-eabi-ar",
"target-endian": "little",
"target-pointer-width": "32",
"target-family": "unix",
"arch": "arm",
"os": "linux",
"env": "newlib",
"cpu": "mpcore",
"features": "+vfp2",
"relocation-model": "static",
"executables": true,
"exe-suffix": ".elf",
"panic-strategy": "abort",
"pre-link-args": [
"-specs=3dsx.specs",
"-march=armv6k",
"-mtune=mpcore",
"-mfloat-abi=hard",
"-mtp=soft"
],
"post-link-args": [
"-lc",
"-lm",
"-lsysbase",
"-lc"
]
}

7
ctr-std/Xargo.toml

@ -1,7 +0,0 @@
[dependencies.collections]
[dependencies.rand]
[dependencies.ctr-libc]
path = "../ctr-libc"
stage = 1

6
ctr-std/src/panicking.rs

@ -63,8 +63,8 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u
let msg = Box::new(msg); let msg = Box::new(msg);
let (file, line) = *file_line; let (file, line) = *file_line;
use libctru::console::consoleInit; use libctru::consoleInit;
use libctru::gfx::gfxScreen_t; use libctru::gfxScreen_t;
// set up a new console, overwriting whatever was on the top screen // set up a new console, overwriting whatever was on the top screen
// before we started panicking // before we started panicking
@ -74,7 +74,7 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u
println!(" {}", msg); println!(" {}", msg);
// Terminate the process to ensure that all threads cease when panicking. // Terminate the process to ensure that all threads cease when panicking.
unsafe { ::libctru::svc::svcExitProcess() } unsafe { ::libctru::svcExitProcess() }
// On 3DS hardware, code execution will have terminated at the above function. // On 3DS hardware, code execution will have terminated at the above function.
// //

4
ctr-std/src/sys/unix/condvar.rs

@ -17,8 +17,8 @@ use time::Duration;
use sys::mutex::{self, Mutex}; use sys::mutex::{self, Mutex};
use libctru::synchronization::{__sync_get_arbiter, LightLock}; use libctru::{__sync_get_arbiter, LightLock};
use libctru::svc::{svcArbitrateAddress, ArbitrationType}; use libctru::{svcArbitrateAddress, ArbitrationType};
pub struct Condvar { pub struct Condvar {
lock: UnsafeCell<*mut LightLock>, lock: UnsafeCell<*mut LightLock>,

24
ctr-std/src/sys/unix/mutex.rs

@ -11,12 +11,10 @@
use cell::UnsafeCell; use cell::UnsafeCell;
use mem; use mem;
use libctru::synchronization; pub struct Mutex { inner: UnsafeCell<::libctru::LightLock> }
pub struct Mutex { inner: UnsafeCell<synchronization::LightLock> }
#[inline] #[inline]
pub unsafe fn raw(m: &Mutex) -> *mut synchronization::LightLock { pub unsafe fn raw(m: &Mutex) -> *mut ::libctru::LightLock {
m.inner.get() m.inner.get()
} }
@ -30,19 +28,19 @@ impl Mutex {
} }
#[inline] #[inline]
pub unsafe fn init(&mut self) { pub unsafe fn init(&mut self) {
synchronization::LightLock_Init(self.inner.get()); ::libctru::LightLock_Init(self.inner.get());
} }
#[inline] #[inline]
pub unsafe fn lock(&self) { pub unsafe fn lock(&self) {
synchronization::LightLock_Lock(self.inner.get()); ::libctru::LightLock_Lock(self.inner.get());
} }
#[inline] #[inline]
pub unsafe fn unlock(&self) { pub unsafe fn unlock(&self) {
synchronization::LightLock_Unlock(self.inner.get()); ::libctru::LightLock_Unlock(self.inner.get());
} }
#[inline] #[inline]
pub unsafe fn try_lock(&self) -> bool { pub unsafe fn try_lock(&self) -> bool {
match synchronization::LightLock_TryLock(self.inner.get()) { match ::libctru::LightLock_TryLock(self.inner.get()) {
0 => true, 0 => true,
_ => false, _ => false,
} }
@ -51,7 +49,7 @@ impl Mutex {
pub unsafe fn destroy(&self) {} pub unsafe fn destroy(&self) {}
} }
pub struct ReentrantMutex { inner: UnsafeCell<synchronization::RecursiveLock> } pub struct ReentrantMutex { inner: UnsafeCell<::libctru::RecursiveLock> }
unsafe impl Send for ReentrantMutex {} unsafe impl Send for ReentrantMutex {}
unsafe impl Sync for ReentrantMutex {} unsafe impl Sync for ReentrantMutex {}
@ -62,19 +60,19 @@ impl ReentrantMutex {
} }
#[inline] #[inline]
pub unsafe fn init(&mut self) { pub unsafe fn init(&mut self) {
synchronization::RecursiveLock_Init(self.inner.get()); ::libctru::RecursiveLock_Init(self.inner.get());
} }
#[inline] #[inline]
pub unsafe fn lock(&self) { pub unsafe fn lock(&self) {
synchronization::RecursiveLock_Lock(self.inner.get()); ::libctru::RecursiveLock_Lock(self.inner.get());
} }
#[inline] #[inline]
pub unsafe fn unlock(&self) { pub unsafe fn unlock(&self) {
synchronization::RecursiveLock_Unlock(self.inner.get()); ::libctru::RecursiveLock_Unlock(self.inner.get());
} }
#[inline] #[inline]
pub unsafe fn try_lock(&self) -> bool { pub unsafe fn try_lock(&self) -> bool {
match synchronization::RecursiveLock_TryLock(self.inner.get()) { match ::libctru::RecursiveLock_TryLock(self.inner.get()) {
0 => true, 0 => true,
_ => false, _ => false,
} }

2
ctr-std/src/sys/unix/rand.rs

@ -12,7 +12,7 @@ use io::{self, Error, ErrorKind};
use mem; use mem;
use rand::Rng; use rand::Rng;
use libctru::services::sslc::{sslcInit, sslcExit, sslcGenerateRandomData}; use libctru::{sslcInit, sslcExit, sslcGenerateRandomData};
pub struct OsRng(()); pub struct OsRng(());

8
ctr-std/src/sys/unix/thread.rs

@ -18,9 +18,9 @@ use ptr;
use sys_common::thread::start_thread; use sys_common::thread::start_thread;
use time::Duration; use time::Duration;
use libctru::svc::{svcSleepThread, svcGetThreadPriority}; use libctru::{svcSleepThread, svcGetThreadPriority};
use libctru::thread::{threadCreate, threadJoin, threadFree}; use libctru::{threadCreate, threadJoin, threadFree};
use libctru::thread::Thread as ThreadHandle; use libctru::Thread as ThreadHandle;
pub struct Thread { pub struct Thread {
handle: ThreadHandle, handle: ThreadHandle,
@ -44,7 +44,7 @@ impl Thread {
priority -= 1; priority -= 1;
let handle = threadCreate(Some(thread_func), &*p as *const _ as *mut _, let handle = threadCreate(Some(thread_func), &*p as *const _ as *mut _,
stack_size, priority, -2, 0); stack_size, priority, -2, false);
return if handle == ptr::null_mut() { return if handle == ptr::null_mut() {
Err(io::Error::from_raw_os_error(libc::EAGAIN)) Err(io::Error::from_raw_os_error(libc::EAGAIN))

2
ctr-std/src/sys/unix/time.rs

@ -192,7 +192,7 @@ mod inner {
// Gets the current system tick // Gets the current system tick
#[inline] #[inline]
fn get_system_tick() -> u64 { fn get_system_tick() -> u64 {
unsafe { libctru::svc::svcGetSystemTick() } unsafe { libctru::svcGetSystemTick() }
} }
// A struct representing the clock speed of the 3DS // A struct representing the clock speed of the 3DS

31
ctru-rs/3ds.json

@ -1,31 +0,0 @@
{
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"llvm-target": "arm-none-eabihf",
"linker": "arm-none-eabi-gcc",
"ar": "arm-none-eabi-ar",
"target-endian": "little",
"target-pointer-width": "32",
"target-family": "unix",
"arch": "arm",
"os": "linux",
"env": "newlib",
"cpu": "mpcore",
"features": "+vfp2",
"relocation-model": "static",
"executables": true,
"exe-suffix": ".elf",
"panic-strategy": "abort",
"pre-link-args": [
"-specs=3dsx.specs",
"-march=armv6k",
"-mtune=mpcore",
"-mfloat-abi=hard",
"-mtp=soft"
],
"post-link-args": [
"-lc",
"-lm",
"-lsysbase",
"-lc"
]
}

3
ctru-rs/Cargo.toml

@ -3,8 +3,7 @@ authors = ["Ronald Kinard <furyhunter600@gmail.com>"]
description = "A safe wrapper around smealum's ctrulib." description = "A safe wrapper around smealum's ctrulib."
license = "https://en.wikipedia.org/wiki/Zlib_License" license = "https://en.wikipedia.org/wiki/Zlib_License"
name = "ctru-rs" name = "ctru-rs"
version = "0.5.0" version = "0.5.1"
links = "ctru"
[lib] [lib]
crate-type = ["rlib"] crate-type = ["rlib"]

11
ctru-rs/Xargo.toml

@ -1,11 +0,0 @@
[dependencies.collections]
[dependencies.rand]
[dependencies.ctr-libc]
path = "../ctr-libc"
stage = 1
[dependencies.std]
path = "../ctr-std"
stage = 2

12
ctru-rs/src/console.rs

@ -3,30 +3,28 @@ use std::ptr;
use gfx::Screen; use gfx::Screen;
use libctru::console::*;
pub struct Console { pub struct Console {
context: PrintConsole, context: ::libctru::PrintConsole,
} }
impl Console { impl Console {
pub fn init(screen: Screen) -> Self { pub fn init(screen: Screen) -> Self {
unsafe { unsafe {
let ret = *(consoleInit(screen.into(), ptr::null_mut())); let ret = *(::libctru::consoleInit(screen.into(), ptr::null_mut()));
Console { context: ret } Console { context: ret }
} }
} }
pub fn select(&mut self) { pub fn select(&mut self) {
unsafe { consoleSelect(&mut self.context); } unsafe { ::libctru::consoleSelect(&mut self.context); }
} }
pub fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) { pub fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) {
unsafe { consoleSetWindow(&mut self.context, x, y, width, height) } unsafe { ::libctru::consoleSetWindow(&mut self.context, x, y, width, height) }
} }
pub fn clear(&mut self) { pub fn clear(&mut self) {
unsafe { consoleClear() } unsafe { ::libctru::consoleClear() }
} }
} }

58
ctru-rs/src/gfx.rs

@ -1,5 +1,3 @@
use libctru::gfx;
use std::default::Default; use std::default::Default;
use std::ops::Drop; use std::ops::Drop;
@ -19,10 +17,10 @@ pub enum Side {
Right, Right,
} }
impl From<gfx::gfxScreen_t> for Screen { impl From<::libctru::gfxScreen_t> for Screen {
#[inline] #[inline]
fn from(g: gfx::gfxScreen_t) -> Screen { fn from(g: ::libctru::gfxScreen_t) -> Screen {
use libctru::gfx::gfxScreen_t::*; use ::libctru::gfxScreen_t::*;
use self::Screen::*; use self::Screen::*;
match g { match g {
GFX_TOP => Top, GFX_TOP => Top,
@ -31,10 +29,10 @@ impl From<gfx::gfxScreen_t> for Screen {
} }
} }
impl From<Screen> for gfx::gfxScreen_t { impl From<Screen> for ::libctru::gfxScreen_t {
#[inline] #[inline]
fn from(g: Screen) -> gfx::gfxScreen_t { fn from(g: Screen) -> ::libctru::gfxScreen_t {
use libctru::gfx::gfxScreen_t::*; use ::libctru::gfxScreen_t::*;
use self::Screen::*; use self::Screen::*;
match g { match g {
Top => GFX_TOP, Top => GFX_TOP,
@ -43,10 +41,10 @@ impl From<Screen> for gfx::gfxScreen_t {
} }
} }
impl From<gfx::gfx3dSide_t> for Side { impl From<::libctru::gfx3dSide_t> for Side {
#[inline] #[inline]
fn from(s: gfx::gfx3dSide_t) -> Side { fn from(s: ::libctru::gfx3dSide_t) -> Side {
use libctru::gfx::gfx3dSide_t::*; use ::libctru::gfx3dSide_t::*;
use self::Side::*; use self::Side::*;
match s { match s {
GFX_LEFT => Left, GFX_LEFT => Left,
@ -55,10 +53,10 @@ impl From<gfx::gfx3dSide_t> for Side {
} }
} }
impl From<Side> for gfx::gfx3dSide_t { impl From<Side> for ::libctru::gfx3dSide_t {
#[inline] #[inline]
fn from(s: Side) -> gfx::gfx3dSide_t { fn from(s: Side) -> ::libctru::gfx3dSide_t {
use libctru::gfx::gfx3dSide_t::*; use ::libctru::gfx3dSide_t::*;
use self::Side::*; use self::Side::*;
match s { match s {
Left => GFX_LEFT, Left => GFX_LEFT,
@ -70,10 +68,7 @@ impl From<Side> for gfx::gfx3dSide_t {
impl Gfx { impl Gfx {
pub fn set_3d_enabled(&mut self, enabled: bool) { pub fn set_3d_enabled(&mut self, enabled: bool) {
unsafe { unsafe {
gfx::gfxSet3D(match enabled { ::libctru::gfxSet3D(enabled)
true => 1u8,
false => 0u8,
});
} }
} }
@ -84,7 +79,7 @@ impl Gfx {
let mut w: u16 = 0; let mut w: u16 = 0;
let mut h: u16 = 0; let mut h: u16 = 0;
let buf: *mut u8 = gfx::gfxGetFramebuffer(screen.into(), let buf: *mut u8 = ::libctru::gfxGetFramebuffer(screen.into(),
side.into(), side.into(),
&mut w as *mut u16, &mut w as *mut u16,
&mut h as &mut u16); &mut h as &mut u16);
@ -96,47 +91,44 @@ impl Gfx {
} }
pub fn flush_buffers(&mut self) { pub fn flush_buffers(&mut self) {
unsafe { gfx::gfxFlushBuffers() }; unsafe { ::libctru::gfxFlushBuffers() };
} }
pub fn swap_buffers(&mut self) { pub fn swap_buffers(&mut self) {
unsafe { gfx::gfxSwapBuffers() }; unsafe { ::libctru::gfxSwapBuffers() };
} }
pub fn swap_buffers_gpu(&mut self) { pub fn swap_buffers_gpu(&mut self) {
unsafe { gfx::gfxSwapBuffersGpu() }; unsafe { ::libctru::gfxSwapBuffersGpu() };
} }
pub fn get_framebuffer_format(&self, screen: Screen) -> FramebufferFormat { pub fn get_framebuffer_format(&self, screen: Screen) -> FramebufferFormat {
use std::convert::Into; use std::convert::Into;
unsafe { gfx::gfxGetScreenFormat(screen.into()).into() } unsafe { ::libctru::gfxGetScreenFormat(screen.into()).into() }
} }
pub fn set_framebuffer_format(&mut self, screen: Screen, fmt: FramebufferFormat) { pub fn set_framebuffer_format(&mut self, screen: Screen,
fmt: FramebufferFormat) {
use std::convert::Into; use std::convert::Into;
unsafe { gfx::gfxSetScreenFormat(screen.into(), fmt.into()) } unsafe { ::libctru::gfxSetScreenFormat(screen.into(), fmt.into()) }
} }
pub fn set_double_buffering(&mut self, screen: Screen, enabled: bool) { pub fn set_double_buffering(&mut self, screen: Screen, enabled: bool) {
unsafe { unsafe {
gfx::gfxSetDoubleBuffering(screen.into(), ::libctru::gfxSetDoubleBuffering(screen.into(), enabled)
match enabled { }
true => 1u8,
false => 0u8,
})
};
} }
} }
impl Default for Gfx { impl Default for Gfx {
fn default() -> Self { fn default() -> Self {
unsafe { gfx::gfxInitDefault() }; unsafe { ::libctru::gfxInitDefault() };
Gfx(()) Gfx(())
} }
} }
impl Drop for Gfx { impl Drop for Gfx {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { gfx::gfxExit() }; unsafe { ::libctru::gfxExit() };
} }
} }

6
ctru-rs/src/sdmc.rs

@ -1,11 +1,9 @@
use libctru::sdmc::*;
pub struct Sdmc(()); pub struct Sdmc(());
impl Sdmc { impl Sdmc {
pub fn init() -> ::Result<Sdmc> { pub fn init() -> ::Result<Sdmc> {
unsafe { unsafe {
let r = sdmcInit(); let r = ::libctru::sdmcInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -17,6 +15,6 @@ impl Sdmc {
impl Drop for Sdmc { impl Drop for Sdmc {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { sdmcExit() }; unsafe { ::libctru::sdmcExit() };
} }
} }

12
ctru-rs/src/services/apt.rs

@ -1,11 +1,9 @@
use libctru::services::apt;
pub struct Apt(()); pub struct Apt(());
impl Apt { impl Apt {
pub fn init() -> ::Result<Apt> { pub fn init() -> ::Result<Apt> {
unsafe { unsafe {
let r = apt::aptInit(); let r = ::libctru::aptInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -16,17 +14,13 @@ impl Apt {
pub fn main_loop(&self) -> bool { pub fn main_loop(&self) -> bool {
unsafe { unsafe {
match apt::aptMainLoop() { ::libctru::aptMainLoop()
1 => true,
0 => false,
_ => unreachable!(),
}
} }
} }
} }
impl Drop for Apt { impl Drop for Apt {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { apt::aptExit() }; unsafe { ::libctru::aptExit() };
} }
} }

72
ctru-rs/src/services/fs.rs

@ -17,8 +17,6 @@ use std::sync::Arc;
use widestring::{WideCString, WideCStr}; use widestring::{WideCString, WideCStr};
use libctru::services::fs::*;
bitflags! { bitflags! {
flags FsOpen: u32 { flags FsOpen: u32 {
const FS_OPEN_READ = 1, const FS_OPEN_READ = 1,
@ -271,7 +269,7 @@ pub struct ReadDir<'a> {
/// filesystem. Each entry can be inspected via methods to learn about the full /// filesystem. Each entry can be inspected via methods to learn about the full
/// path or possibly other metadata. /// path or possibly other metadata.
pub struct DirEntry<'a> { pub struct DirEntry<'a> {
entry: FS_DirectoryEntry, entry: ::libctru::FS_DirectoryEntry,
root: Arc<PathBuf>, root: Arc<PathBuf>,
arch: &'a Archive, arch: &'a Archive,
} }
@ -299,7 +297,7 @@ impl Fs {
/// instances of Fs drop out of scope. /// instances of Fs drop out of scope.
pub fn init() -> ::Result<Fs> { pub fn init() -> ::Result<Fs> {
unsafe { unsafe {
let r = fsInit(); let r = ::libctru::fsInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -313,8 +311,8 @@ impl Fs {
unsafe { unsafe {
let mut handle = 0; let mut handle = 0;
let id = ArchiveID::Sdmc; let id = ArchiveID::Sdmc;
let path = fsMakePath(PathType::Empty.into(), ptr::null() as _); let path = ::libctru::fsMakePath(PathType::Empty.into(), ptr::null() as _);
let r = FSUSER_OpenArchive(&mut handle, id.into(), path); let r = ::libctru::FSUSER_OpenArchive(&mut handle, id.into(), path);
if r < 0 { if r < 0 {
Err(::Error::from(r)) Err(::Error::from(r))
} else { } else {
@ -398,7 +396,7 @@ impl File {
/// This function will return an error if the file is not opened for writing. /// This function will return an error if the file is not opened for writing.
pub fn set_len(&mut self, size: u64) -> IoResult<()> { pub fn set_len(&mut self, size: u64) -> IoResult<()> {
unsafe { unsafe {
let r = FSFILE_SetSize(self.handle, size); let r = ::libctru::FSFILE_SetSize(self.handle, size);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::PermissionDenied, ::Error::from(r))) Err(IoError::new(IoErrorKind::PermissionDenied, ::Error::from(r)))
} else { } else {
@ -413,7 +411,7 @@ impl File {
// This is likely to change in the future. // This is likely to change in the future.
unsafe { unsafe {
let mut size = 0; let mut size = 0;
let r = FSFILE_GetSize(self.handle, &mut size); let r = ::libctru::FSFILE_GetSize(self.handle, &mut size);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::PermissionDenied, ::Error::from(r))) Err(IoError::new(IoErrorKind::PermissionDenied, ::Error::from(r)))
} else { } else {
@ -425,7 +423,7 @@ impl File {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> { fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
unsafe { unsafe {
let mut n_read = 0; let mut n_read = 0;
let r = FSFILE_Read( let r = ::libctru::FSFILE_Read(
self.handle, self.handle,
&mut n_read, &mut n_read,
self.offset, self.offset,
@ -448,7 +446,7 @@ impl File {
fn write(&mut self, buf: &[u8]) -> IoResult<usize> { fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
unsafe { unsafe {
let mut n_written = 0; let mut n_written = 0;
let r = FSFILE_Write( let r = ::libctru::FSFILE_Write(
self.handle, self.handle,
&mut n_written, &mut n_written,
self.offset, self.offset,
@ -586,8 +584,9 @@ impl OpenOptions {
unsafe { unsafe {
let mut file_handle = 0; let mut file_handle = 0;
let path = to_utf16(path); let path = to_utf16(path);
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = FSUSER_OpenFile(&mut file_handle, self.arch_handle, fs_path, flags.bits, 0); let r = ::libctru::FSUSER_OpenFile(&mut file_handle, self.arch_handle,
fs_path, flags.bits, 0);
if r < 0 { if r < 0 {
return Err(IoError::new(IoErrorKind::Other, ::Error::from(r))); return Err(IoError::new(IoErrorKind::Other, ::Error::from(r)));
} }
@ -634,7 +633,8 @@ impl<'a> Iterator for ReadDir<'a> {
}; };
let mut entries_read = 0; let mut entries_read = 0;
let entry_count = 1; let entry_count = 1;
let r = FSDIR_Read(self.handle.0, &mut entries_read, entry_count, &mut ret.entry); let r = ::libctru::FSDIR_Read(self.handle.0, &mut entries_read,
entry_count, &mut ret.entry);
if r < 0 { if r < 0 {
return Some(Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))) return Some(Err(IoError::new(IoErrorKind::Other, ::Error::from(r))))
@ -683,8 +683,9 @@ impl<'a> DirEntry<'a> {
pub fn create_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn create_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = FSUSER_CreateDirectory(arch.handle, fs_path, FS_ATTRIBUTE_DIRECTORY.bits); let r = ::libctru::FSUSER_CreateDirectory(arch.handle, fs_path,
FS_ATTRIBUTE_DIRECTORY.bits);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -738,8 +739,8 @@ pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<Metadata> {
pub fn remove_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn remove_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = FSUSER_DeleteDirectory(arch.handle, fs_path); let r = ::libctru::FSUSER_DeleteDirectory(arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -756,8 +757,8 @@ pub fn remove_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
pub fn remove_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn remove_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = FSUSER_DeleteDirectoryRecursively(arch.handle, fs_path); let r = ::libctru::FSUSER_DeleteDirectoryRecursively(arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -782,8 +783,8 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
let mut handle = 0; let mut handle = 0;
let root = Arc::new(path.as_ref().to_path_buf()); let root = Arc::new(path.as_ref().to_path_buf());
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = FSUSER_OpenDirectory(&mut handle, arch.handle, fs_path); let r = ::libctru::FSUSER_OpenDirectory(&mut handle, arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -804,8 +805,8 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
pub fn remove_file<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { pub fn remove_file<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
unsafe { unsafe {
let path = to_utf16(path.as_ref()); let path = to_utf16(path.as_ref());
let fs_path = fsMakePath(PathType::UTF16.into(), path.as_ptr() as _); let fs_path = ::libctru::fsMakePath(PathType::UTF16.into(), path.as_ptr() as _);
let r = FSUSER_DeleteFile(arch.handle, fs_path); let r = ::libctru::FSUSER_DeleteFile(arch.handle, fs_path);
if r < 0 { if r < 0 {
Err(IoError::new(IoErrorKind::Other, ::Error::from(r))) Err(IoError::new(IoErrorKind::Other, ::Error::from(r)))
} else { } else {
@ -832,14 +833,14 @@ pub fn rename<P, Q>(arch: &Archive, from: P, to: Q) -> IoResult<()>
let from = to_utf16(from.as_ref()); let from = to_utf16(from.as_ref());
let to = to_utf16(to.as_ref()); let to = to_utf16(to.as_ref());
let fs_from = fsMakePath(PathType::UTF16.into(), from.as_ptr() as _); let fs_from = ::libctru::fsMakePath(PathType::UTF16.into(), from.as_ptr() as _);
let fs_to = fsMakePath(PathType::UTF16.into(), to.as_ptr() as _); let fs_to = ::libctru::fsMakePath(PathType::UTF16.into(), to.as_ptr() as _);
let r = FSUSER_RenameFile(arch.handle, fs_from, arch.handle, fs_to); let r = ::libctru::FSUSER_RenameFile(arch.handle, fs_from, arch.handle, fs_to);
if r == 0 { if r == 0 {
return Ok(()) return Ok(())
} }
let r = FSUSER_RenameDirectory(arch.handle, fs_from, arch.handle, fs_to); let r = ::libctru::FSUSER_RenameDirectory(arch.handle, fs_from, arch.handle, fs_to);
if r == 0 { if r == 0 {
return Ok(()) return Ok(())
} }
@ -944,7 +945,7 @@ impl Seek for File {
impl Drop for Fs { impl Drop for Fs {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
fsExit(); ::libctru::fsExit();
} }
} }
} }
@ -952,7 +953,7 @@ impl Drop for Fs {
impl Drop for Archive { impl Drop for Archive {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
FSUSER_CloseArchive(self.handle); ::libctru::FSUSER_CloseArchive(self.handle);
} }
} }
} }
@ -960,7 +961,7 @@ impl Drop for Archive {
impl Drop for File { impl Drop for File {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
FSFILE_Close(self.handle); ::libctru::FSFILE_Close(self.handle);
} }
} }
} }
@ -968,15 +969,15 @@ impl Drop for File {
impl Drop for Dir { impl Drop for Dir {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
FSDIR_Close(self.0); ::libctru::FSDIR_Close(self.0);
} }
} }
} }
impl From<PathType> for FS_PathType { impl From<PathType> for ::libctru::FS_PathType {
fn from(p: PathType) -> Self { fn from(p: PathType) -> Self {
use self::PathType::*; use self::PathType::*;
use libctru::services::fs::FS_PathType::*; use ::libctru::FS_PathType::*;
match p { match p {
Invalid => PATH_INVALID, Invalid => PATH_INVALID,
Empty => PATH_EMPTY, Empty => PATH_EMPTY,
@ -987,10 +988,11 @@ impl From<PathType> for FS_PathType {
} }
} }
impl From<ArchiveID> for FS_ArchiveID { impl From<ArchiveID> for ::libctru::FS_ArchiveID {
fn from(a: ArchiveID) -> Self { fn from(a: ArchiveID) -> Self {
use self::ArchiveID::*; use self::ArchiveID::*;
use libctru::services::fs::FS_ArchiveID::*; use ::libctru::FS_ArchiveID::*;
match a { match a {
RomFS => ARCHIVE_ROMFS, RomFS => ARCHIVE_ROMFS,
Savedata => ARCHIVE_SAVEDATA, Savedata => ARCHIVE_SAVEDATA,

20
ctru-rs/src/services/gspgpu.rs

@ -1,5 +1,3 @@
use libctru::services::gspgpu;
use std::convert::From; use std::convert::From;
pub enum Event { pub enum Event {
@ -34,10 +32,10 @@ impl FramebufferFormat {
} }
} }
impl From<gspgpu::GSPGPU_FramebufferFormats> for FramebufferFormat { impl From<::libctru::GSPGPU_FramebufferFormats> for FramebufferFormat {
#[inline] #[inline]
fn from(g: gspgpu::GSPGPU_FramebufferFormats) -> FramebufferFormat { fn from(g: ::libctru::GSPGPU_FramebufferFormats) -> FramebufferFormat {
use libctru::services::gspgpu::GSPGPU_FramebufferFormats::*; use ::libctru::GSPGPU_FramebufferFormats::*;
use self::FramebufferFormat::*; use self::FramebufferFormat::*;
match g { match g {
GSP_RGBA8_OES => Rgba8, GSP_RGBA8_OES => Rgba8,
@ -49,10 +47,10 @@ impl From<gspgpu::GSPGPU_FramebufferFormats> for FramebufferFormat {
} }
} }
impl From<FramebufferFormat> for gspgpu::GSPGPU_FramebufferFormats { impl From<FramebufferFormat> for ::libctru::GSPGPU_FramebufferFormats {
#[inline] #[inline]
fn from(g: FramebufferFormat) -> gspgpu::GSPGPU_FramebufferFormats { fn from(g: FramebufferFormat) -> ::libctru::GSPGPU_FramebufferFormats {
use libctru::services::gspgpu::GSPGPU_FramebufferFormats::*; use ::libctru::GSPGPU_FramebufferFormats::*;
use self::FramebufferFormat::*; use self::FramebufferFormat::*;
match g { match g {
Rgba8 => GSP_RGBA8_OES, Rgba8 => GSP_RGBA8_OES,
@ -64,8 +62,8 @@ impl From<FramebufferFormat> for gspgpu::GSPGPU_FramebufferFormats {
} }
} }
fn to_raw_event(ev: Event) -> gspgpu::GSPGPU_Event { fn to_raw_event(ev: Event) -> ::libctru::GSPGPU_Event {
use libctru::services::gspgpu::GSPGPU_Event::*; use ::libctru::GSPGPU_Event::*;
use self::Event::*; use self::Event::*;
match ev { match ev {
@ -93,6 +91,6 @@ fn to_raw_event(ev: Event) -> gspgpu::GSPGPU_Event {
pub fn wait_for_event(ev: Event) -> () { pub fn wait_for_event(ev: Event) -> () {
unsafe { unsafe {
// TODO second argument? // TODO second argument?
gspgpu::gspWaitForEvent(to_raw_event(ev), 0); ::libctru::gspWaitForEvent(to_raw_event(ev), false);
} }
} }

17
ctru-rs/src/services/hid.rs

@ -1,7 +1,5 @@
use std::convert::Into; use std::convert::Into;
use libctru::services::hid;
pub enum PadKey { pub enum PadKey {
A, A,
B, B,
@ -36,9 +34,8 @@ pub enum PadKey {
impl From<PadKey> for u32 { impl From<PadKey> for u32 {
fn from(p: PadKey) -> u32 { fn from(p: PadKey) -> u32 {
use libctru::services::hid::PAD_KEY::*;
use self::PadKey::*; use self::PadKey::*;
use ::libctru::_bindgen_ty_18::*;
match p { match p {
Up => KEY_DUP as u32 | KEY_CPAD_UP as u32, Up => KEY_DUP as u32 | KEY_CPAD_UP as u32,
Down => KEY_DDOWN as u32 | KEY_CPAD_DOWN as u32, Down => KEY_DDOWN as u32 | KEY_CPAD_DOWN as u32,
@ -77,7 +74,7 @@ pub struct Hid(());
impl Hid { impl Hid {
pub fn init() -> ::Result<Hid> { pub fn init() -> ::Result<Hid> {
unsafe { unsafe {
let r = hid::hidInit(); let r = ::libctru::hidInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -87,13 +84,13 @@ impl Hid {
} }
pub fn scan_input(&self) { pub fn scan_input(&self) {
unsafe { hid::hidScanInput() }; unsafe { ::libctru::hidScanInput() };
} }
pub fn key_down(&self, key: PadKey) -> bool { pub fn key_down(&self, key: PadKey) -> bool {
let k: u32 = key.into(); let k: u32 = key.into();
unsafe { unsafe {
if hid::hidKeysDown() & k != 0 { if ::libctru::hidKeysDown() & k != 0 {
true true
} else { } else {
false false
@ -104,7 +101,7 @@ impl Hid {
pub fn key_held(&self, key: PadKey) -> bool { pub fn key_held(&self, key: PadKey) -> bool {
let k: u32 = key.into(); let k: u32 = key.into();
unsafe { unsafe {
if hid::hidKeysHeld() & k != 0 { if ::libctru::hidKeysHeld() & k != 0 {
true true
} else { } else {
false false
@ -115,7 +112,7 @@ impl Hid {
pub fn key_up(&self, key: PadKey) -> bool { pub fn key_up(&self, key: PadKey) -> bool {
let k: u32 = key.into(); let k: u32 = key.into();
unsafe { unsafe {
if hid::hidKeysUp() & k != 0 { if ::libctru::hidKeysUp() & k != 0 {
return true; return true;
} else { } else {
return false; return false;
@ -126,6 +123,6 @@ impl Hid {
impl Drop for Hid { impl Drop for Hid {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { hid::hidExit() }; unsafe { ::libctru::hidExit() };
} }
} }

13
ctru-rs/src/services/sslc.rs

@ -1,15 +1,12 @@
use libctru::services::sslc::*;
use Result;
// TODO: Implement remaining functions // TODO: Implement remaining functions
pub struct SslC(()); pub struct SslC(());
impl SslC { impl SslC {
/// Initialize sslc /// Initialize sslc
pub fn init() -> Result<Self> { pub fn init() -> ::Result<Self> {
unsafe { unsafe {
let r = sslcInit(0); let r = ::libctru::sslcInit(0);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -19,9 +16,9 @@ impl SslC {
} }
/// Fill `buf` with `buf.len()` random bytes /// Fill `buf` with `buf.len()` random bytes
pub fn generate_random_data(&self, buf: &mut [u8]) -> Result<()> { pub fn generate_random_data(&self, buf: &mut [u8]) -> ::Result<()> {
unsafe { unsafe {
let r = sslcGenerateRandomData(buf.as_ptr() as _, buf.len() as u32); let r = ::libctru::sslcGenerateRandomData(buf.as_ptr() as _, buf.len() as u32);
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -33,6 +30,6 @@ impl SslC {
impl Drop for SslC { impl Drop for SslC {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { sslcExit() }; unsafe { ::libctru::sslcExit() };
} }
} }

6
ctru-rs/src/srv.rs

@ -1,11 +1,9 @@
use libctru::srv::*;
pub struct Srv(()); pub struct Srv(());
impl Srv { impl Srv {
pub fn init() -> ::Result<Srv> { pub fn init() -> ::Result<Srv> {
unsafe { unsafe {
let r = srvInit(); let r = ::libctru::srvInit();
if r < 0 { if r < 0 {
Err(r.into()) Err(r.into())
} else { } else {
@ -17,6 +15,6 @@ impl Srv {
impl Drop for Srv { impl Drop for Srv {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { srvExit() }; unsafe { ::libctru::srvExit() };
} }
} }

Loading…
Cancel
Save