Browse Source

Merge pull request #9 from FenrirWolf/master

A few minor API changes, and panic messages
pull/10/head
Ronald Kinard 8 years ago committed by GitHub
parent
commit
d1c4e474bf
  1. 16
      ctru-sys/src/lib.rs
  2. 1
      ctru-sys/src/sys/libc.rs
  3. 2
      ctru-sys/src/sys/lock.rs
  4. 2
      ctru-sys/src/sys/mod.rs
  5. 13
      src/lib.rs
  6. 65
      src/panic.rs
  7. 2
      src/sdmc.rs
  8. 4
      src/services/apt.rs
  9. 4
      src/services/hid.rs
  10. 2
      src/srv.rs

16
ctru-sys/src/lib.rs

@ -1,30 +1,30 @@ @@ -1,30 +1,30 @@
/*
* C bindings generation:
* bindgen --match=file.h --use-core --ctypes-prefix=libc -- --sysroot=$DEVKITARM/arm-none-eabi -I$CTRULIB/include $CTRULIB/include/3ds.h
*
* bindgen --sysroot=$DEVKITARM/arm-none-eabi -I$CTRULIB/include $CTRULIB/include/3ds.h
*/
#![no_std]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(overflowing_literals)]
#![feature(question_mark)]
#![allow(non_camel_case_types, non_snake_case, overflowing_literals)]
pub mod console;
pub mod env;
pub mod gfx;
pub mod gpu;
pub mod ipc;
pub mod lock;
pub mod libc;
pub mod os;
pub mod sdmc;
pub mod srv;
pub mod services;
pub mod svc;
pub mod srv;
pub mod sys;
pub mod synchronization;
pub mod thread;
pub mod types;
pub mod services;
pub use self::sys::*;
pub use self::types::*;
pub type Result = i32;

1
ctru-sys/src/libc.rs → ctru-sys/src/sys/libc.rs

@ -7,5 +7,6 @@ pub enum c_void { @@ -7,5 +7,6 @@ pub enum c_void {
}
extern "C" {
pub fn abort() -> !;
pub fn write(fd: i32, buf: *const c_void, count: usize) -> isize;
}

2
ctru-sys/src/lock.rs → ctru-sys/src/sys/lock.rs

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
//<sys/lock.h> from devkitArm, needed for synchronization.rs to compile
//TODO: I don't even know this thing looks really spooky
pub type _LOCK_T = i32;
#[repr(C)]
#[derive(Copy)]

2
ctru-sys/src/sys/mod.rs

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
pub mod lock;
pub mod libc;

13
src/lib.rs

@ -1,24 +1,21 @@ @@ -1,24 +1,21 @@
#![feature(lang_items)]
#![feature(alloc, collections, lang_items)]
#![no_std]
#![crate_type = "rlib"]
#![crate_name = "ctru"]
extern crate ctru_sys as libctru;
extern crate alloc;
extern crate collections;
pub mod console;
pub mod srv;
pub mod gfx;
pub mod sdmc;
pub mod services;
pub mod panic;
pub use srv::Srv;
pub use gfx::Gfx;
pub use sdmc::Sdmc;
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[lang = "panic_fmt"]
fn panic_fmt() -> ! {
loop {}
}

65
src/panic.rs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Implementation of various bits and pieces of the `panic!` macro and
//! associated runtime pieces.
use core::fmt::{self, Display, Write};
use core::any::Any;
use collections::String;
use collections::boxed::Box;
///The compiler wants this to be here. Otherwise it won't be happy. And we like happy compilers.
#[lang = "eh_personality"]
extern fn eh_personality() {}
/// Entry point of panic from the libcore crate.
#[lang = "panic_fmt"]
extern fn panic_fmt(msg: fmt::Arguments, file: &'static str, line: u32) -> ! {
begin_panic_fmt(&msg, &(file, line))
}
/// The entry point for panicking with a formatted message.
///
/// This is designed to reduce the amount of code required at the call
/// site as much as possible (so that `panic!()` has as low an impact
/// on (e.g.) the inlining of other functions as possible), by moving
/// the actual formatting into this shared place.
#[inline(never)]
#[cold]
pub fn begin_panic_fmt(msg: &fmt::Arguments, file_line: &(&'static str, u32)) -> ! {
let mut s = String::new();
let _ = s.write_fmt(*msg);
begin_panic(s, file_line);
}
/// This is where the main panic logic happens.
#[inline(never)]
#[cold]
pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line: &(&'static str, u32)) -> ! {
use gfx::Screen;
use console::Console;
let msg = Box::new(msg);
let (file, line) = *file_line;
let mut error_top = Console::init(Screen::Top);
let mut error_bottom = Console::init(Screen::Bottom);
write!(error_top, "--------------------------------------------------").unwrap();
writeln!(error_top, "PANIC in {} at line {}:", file, line).unwrap();
writeln!(error_top, " {}", msg).unwrap();
write!(error_top, "\x1b[29;00H--------------------------------------------------").unwrap();
write!(error_bottom, "").unwrap();
loop {}
}

2
src/sdmc.rs

@ -7,7 +7,7 @@ pub struct Sdmc { @@ -7,7 +7,7 @@ pub struct Sdmc {
}
impl Sdmc {
pub fn new() -> Result<Sdmc, i32> {
pub fn init() -> Result<Sdmc, i32> {
unsafe {
let r = sdmcInit();
if r < 0 {

4
src/services/apt.rs

@ -55,7 +55,7 @@ pub struct Apt { @@ -55,7 +55,7 @@ pub struct Apt {
}
impl Apt {
pub fn new() -> Result<Apt, i32> {
pub fn init() -> Result<Apt, i32> {
unsafe {
let r = apt::aptInit();
if r < 0 {
@ -86,7 +86,7 @@ impl Apt { @@ -86,7 +86,7 @@ impl Apt {
unsafe { apt::aptReturnToMenu() }
}
pub fn main_loop(&mut self) -> bool {
pub fn main_loop(&self) -> bool {
unsafe {
match apt::aptMainLoop() {
1 => true,

4
src/services/hid.rs

@ -78,7 +78,7 @@ pub struct Hid { @@ -78,7 +78,7 @@ pub struct Hid {
}
impl Hid {
pub fn new() -> Result<Hid, i32> {
pub fn init() -> Result<Hid, i32> {
unsafe {
let r = hid::hidInit();
if r < 0 {
@ -89,7 +89,7 @@ impl Hid { @@ -89,7 +89,7 @@ impl Hid {
}
}
pub fn scan_input(&mut self) {
pub fn scan_input(&self) {
unsafe { hid::hidScanInput() };
}

2
src/srv.rs

@ -7,7 +7,7 @@ pub struct Srv { @@ -7,7 +7,7 @@ pub struct Srv {
}
impl Srv {
pub fn new() -> Result<Srv, i32> {
pub fn init() -> Result<Srv, i32> {
unsafe {
let r = srvInit();
if r < 0 {

Loading…
Cancel
Save