blob: 73afa2241e06e2a1a533f3b5b519fe8f8dd54a26 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
extern crate ctru;
use ctru::gfx::Gfx;
use ctru::console::Console;
use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad};
fn main() {
// 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.
// The APT service handles application management functions, such as enabling sleep
// 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.
let hid = Hid::init().unwrap();
// The GFX service manages the framebuffers for the top and bottom screens.
let gfx = Gfx::default();
// Initialize a ctrulib console and direct standard output to it.
// Consoles can be initialized on both the top and bottom screens.
// The top screen is initialized by default.
let _console = Console::default();
// Now we can print to stdout!
println!("Hello, world!");
// We can use escape sequences to move the cursor around the terminal.
// The following text will be moved down 29 rows and right 16 characters
// before printing begins.
println!("\x1b[29;16HPress Start to exit");
// Main application loop.
while apt.main_loop() {
// Flushes and swaps the framebuffers when double-buffering
// 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();
// 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) {
break;
}
}
// All of our service handles will drop out of scope at this point,
// triggering the end of our application.
}
|