Andrea Ciliberti
3 years ago
2 changed files with 29 additions and 38 deletions
@ -1,56 +1,44 @@ |
|||||||
|
extern crate ctru; |
||||||
use ctru::console::Console; |
use ctru::console::Console; |
||||||
use ctru::gfx::{Gfx, Screen}; |
use ctru::gfx::Gfx; |
||||||
use ctru::services::apt::Apt; |
use ctru::services::apt::Apt; |
||||||
use ctru::services::hid::{Hid, KeyPad}; |
use ctru::services::hid::{Hid, KeyPad}; |
||||||
|
|
||||||
fn main() { |
extern crate ferris_says; |
||||||
// Initialize ctrulib service handles.
|
|
||||||
// Service handles are internally reference-counted. When all instances of a
|
|
||||||
// service handle go out of scope, the service will be closed.
|
|
||||||
ctru::init(); |
|
||||||
|
|
||||||
// The APT service handles application management functions, such as enabling sleep
|
use std::io::BufWriter; |
||||||
// mode and jumping to the home menu or to other applications
|
|
||||||
let apt = Apt::init().unwrap(); |
|
||||||
|
|
||||||
// The HID service handles button and touch screen inputs.
|
fn main() { |
||||||
let hid = Hid::init().unwrap(); |
ctru::init(); |
||||||
|
|
||||||
// The GFX service manages the framebuffers for the top and bottom screens.
|
|
||||||
let gfx = Gfx::default(); |
let gfx = Gfx::default(); |
||||||
|
let hid = Hid::init().expect("Couldn't obtain HID controller"); |
||||||
|
let apt = Apt::init().expect("Couldn't obtain APT controller"); |
||||||
|
let _console = Console::init(gfx.top_screen.borrow_mut()); |
||||||
|
|
||||||
// Initialize a ctrulib console and direct standard output to it.
|
let out = b"Hello fellow Rustaceans, I'm on the Nintendo 3DS!"; |
||||||
// Consoles can be initialized on both the top and bottom screens.
|
let width = 24; |
||||||
let _console = Console::init(&gfx, Screen::Top); |
|
||||||
|
|
||||||
// Now we can print to stdout!
|
let mut writer = BufWriter::new(Vec::new()); |
||||||
println!("Hello, world!"); |
ferris_says::say(out, width, &mut writer).unwrap(); |
||||||
|
|
||||||
// We can use escape sequences to move the cursor around the terminal.
|
println!( |
||||||
// The following text will be moved down 29 rows and right 16 characters
|
"\x1b[0;0H{}", |
||||||
// before printing begins.
|
String::from_utf8_lossy(&writer.into_inner().unwrap()) |
||||||
println!("\x1b[29;16HPress Start to exit"); |
); |
||||||
|
|
||||||
// Main application loop.
|
// Main loop
|
||||||
while apt.main_loop() { |
while apt.main_loop() { |
||||||
// Flushes and swaps the framebuffers when double-buffering
|
//Scan all the inputs. This should be done once for each frame
|
||||||
// is enabled
|
|
||||||
gfx.flush_buffers(); |
|
||||||
gfx.swap_buffers(); |
|
||||||
|
|
||||||
// Wait for the next frame to begin
|
|
||||||
gfx.wait_for_vblank(); |
|
||||||
|
|
||||||
// Scan for user input.
|
|
||||||
hid.scan_input(); |
hid.scan_input(); |
||||||
|
|
||||||
// Check if the user has pressed the given button on this frame.
|
|
||||||
// If so, break out of the loop.
|
|
||||||
if hid.keys_down().contains(KeyPad::KEY_START) { |
if hid.keys_down().contains(KeyPad::KEY_START) { |
||||||
break; |
break; |
||||||
} |
} |
||||||
} |
// Flush and swap framebuffers
|
||||||
|
gfx.flush_buffers(); |
||||||
|
gfx.swap_buffers(); |
||||||
|
|
||||||
// All of our service handles will drop out of scope at this point,
|
//Wait for VBlank
|
||||||
// triggering the end of our application.
|
gfx.wait_for_vblank(); |
||||||
|
} |
||||||
} |
} |
Loading…
Reference in new issue