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 @@ @@ -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 @@ @@ -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 @@ -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 (file, line) = *file_line;
use libctru::console::consoleInit;
use libctru::gfx::gfxScreen_t;
use libctru::consoleInit;
use libctru::gfxScreen_t;
// set up a new console, overwriting whatever was on the top screen
// before we started panicking
@ -74,7 +74,7 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u @@ -74,7 +74,7 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u
println!(" {}", msg);
// 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.
//

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

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

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

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

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

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

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

@ -18,9 +18,9 @@ use ptr; @@ -18,9 +18,9 @@ use ptr;
use sys_common::thread::start_thread;
use time::Duration;
use libctru::svc::{svcSleepThread, svcGetThreadPriority};
use libctru::thread::{threadCreate, threadJoin, threadFree};
use libctru::thread::Thread as ThreadHandle;
use libctru::{svcSleepThread, svcGetThreadPriority};
use libctru::{threadCreate, threadJoin, threadFree};
use libctru::Thread as ThreadHandle;
pub struct Thread {
handle: ThreadHandle,
@ -44,7 +44,7 @@ impl Thread { @@ -44,7 +44,7 @@ impl Thread {
priority -= 1;
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() {
Err(io::Error::from_raw_os_error(libc::EAGAIN))

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

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

31
ctru-rs/3ds.json

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

11
ctru-rs/Xargo.toml

@ -1,11 +0,0 @@ @@ -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; @@ -3,30 +3,28 @@ use std::ptr;
use gfx::Screen;
use libctru::console::*;
pub struct Console {
context: PrintConsole,
context: ::libctru::PrintConsole,
}
impl Console {
pub fn init(screen: Screen) -> Self {
unsafe {
let ret = *(consoleInit(screen.into(), ptr::null_mut()));
let ret = *(::libctru::consoleInit(screen.into(), ptr::null_mut()));
Console { context: ret }
}
}
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) {
unsafe { consoleSetWindow(&mut self.context, x, y, width, height) }
unsafe { ::libctru::consoleSetWindow(&mut self.context, x, y, width, height) }
}
pub fn clear(&mut self) {
unsafe { consoleClear() }
unsafe { ::libctru::consoleClear() }
}
}

58
ctru-rs/src/gfx.rs

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

6
ctru-rs/src/sdmc.rs

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

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

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

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

@ -1,5 +1,3 @@ @@ -1,5 +1,3 @@
use libctru::services::gspgpu;
use std::convert::From;
pub enum Event {
@ -34,10 +32,10 @@ impl FramebufferFormat { @@ -34,10 +32,10 @@ impl FramebufferFormat {
}
}
impl From<gspgpu::GSPGPU_FramebufferFormats> for FramebufferFormat {
impl From<::libctru::GSPGPU_FramebufferFormats> for FramebufferFormat {
#[inline]
fn from(g: gspgpu::GSPGPU_FramebufferFormats) -> FramebufferFormat {
use libctru::services::gspgpu::GSPGPU_FramebufferFormats::*;
fn from(g: ::libctru::GSPGPU_FramebufferFormats) -> FramebufferFormat {
use ::libctru::GSPGPU_FramebufferFormats::*;
use self::FramebufferFormat::*;
match g {
GSP_RGBA8_OES => Rgba8,
@ -49,10 +47,10 @@ impl From<gspgpu::GSPGPU_FramebufferFormats> for FramebufferFormat { @@ -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]
fn from(g: FramebufferFormat) -> gspgpu::GSPGPU_FramebufferFormats {
use libctru::services::gspgpu::GSPGPU_FramebufferFormats::*;
fn from(g: FramebufferFormat) -> ::libctru::GSPGPU_FramebufferFormats {
use ::libctru::GSPGPU_FramebufferFormats::*;
use self::FramebufferFormat::*;
match g {
Rgba8 => GSP_RGBA8_OES,
@ -64,8 +62,8 @@ impl From<FramebufferFormat> for gspgpu::GSPGPU_FramebufferFormats { @@ -64,8 +62,8 @@ impl From<FramebufferFormat> for gspgpu::GSPGPU_FramebufferFormats {
}
}
fn to_raw_event(ev: Event) -> gspgpu::GSPGPU_Event {
use libctru::services::gspgpu::GSPGPU_Event::*;
fn to_raw_event(ev: Event) -> ::libctru::GSPGPU_Event {
use ::libctru::GSPGPU_Event::*;
use self::Event::*;
match ev {
@ -93,6 +91,6 @@ fn to_raw_event(ev: Event) -> gspgpu::GSPGPU_Event { @@ -93,6 +91,6 @@ fn to_raw_event(ev: Event) -> gspgpu::GSPGPU_Event {
pub fn wait_for_event(ev: Event) -> () {
unsafe {
// 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 @@ @@ -1,7 +1,5 @@
use std::convert::Into;
use libctru::services::hid;
pub enum PadKey {
A,
B,
@ -36,9 +34,8 @@ pub enum PadKey { @@ -36,9 +34,8 @@ pub enum PadKey {
impl From<PadKey> for u32 {
fn from(p: PadKey) -> u32 {
use libctru::services::hid::PAD_KEY::*;
use self::PadKey::*;
use ::libctru::_bindgen_ty_18::*;
match p {
Up => KEY_DUP as u32 | KEY_CPAD_UP as u32,
Down => KEY_DDOWN as u32 | KEY_CPAD_DOWN as u32,
@ -77,7 +74,7 @@ pub struct Hid(()); @@ -77,7 +74,7 @@ pub struct Hid(());
impl Hid {
pub fn init() -> ::Result<Hid> {
unsafe {
let r = hid::hidInit();
let r = ::libctru::hidInit();
if r < 0 {
Err(r.into())
} else {
@ -87,13 +84,13 @@ impl Hid { @@ -87,13 +84,13 @@ impl Hid {
}
pub fn scan_input(&self) {
unsafe { hid::hidScanInput() };
unsafe { ::libctru::hidScanInput() };
}
pub fn key_down(&self, key: PadKey) -> bool {
let k: u32 = key.into();
unsafe {
if hid::hidKeysDown() & k != 0 {
if ::libctru::hidKeysDown() & k != 0 {
true
} else {
false
@ -104,7 +101,7 @@ impl Hid { @@ -104,7 +101,7 @@ impl Hid {
pub fn key_held(&self, key: PadKey) -> bool {
let k: u32 = key.into();
unsafe {
if hid::hidKeysHeld() & k != 0 {
if ::libctru::hidKeysHeld() & k != 0 {
true
} else {
false
@ -115,7 +112,7 @@ impl Hid { @@ -115,7 +112,7 @@ impl Hid {
pub fn key_up(&self, key: PadKey) -> bool {
let k: u32 = key.into();
unsafe {
if hid::hidKeysUp() & k != 0 {
if ::libctru::hidKeysUp() & k != 0 {
return true;
} else {
return false;
@ -126,6 +123,6 @@ impl Hid { @@ -126,6 +123,6 @@ impl Hid {
impl Drop for Hid {
fn drop(&mut self) {
unsafe { hid::hidExit() };
unsafe { ::libctru::hidExit() };
}
}

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

@ -1,15 +1,12 @@ @@ -1,15 +1,12 @@
use libctru::services::sslc::*;
use Result;
// TODO: Implement remaining functions
pub struct SslC(());
impl SslC {
/// Initialize sslc
pub fn init() -> Result<Self> {
pub fn init() -> ::Result<Self> {
unsafe {
let r = sslcInit(0);
let r = ::libctru::sslcInit(0);
if r < 0 {
Err(r.into())
} else {
@ -19,9 +16,9 @@ impl SslC { @@ -19,9 +16,9 @@ impl SslC {
}
/// 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 {
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 {
Err(r.into())
} else {
@ -33,6 +30,6 @@ impl SslC { @@ -33,6 +30,6 @@ impl SslC {
impl Drop for SslC {
fn drop(&mut self) {
unsafe { sslcExit() };
unsafe { ::libctru::sslcExit() };
}
}

6
ctru-rs/src/srv.rs

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

Loading…
Cancel
Save