mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Update the book and the template
This commit is contained in:
parent
9feab2b689
commit
f3e3782699
|
@ -1,15 +1,15 @@
|
||||||
# The Gba struct
|
# The Gba struct
|
||||||
|
|
||||||
In this section, we'll cover the importance of the Gba struct and how to create it.
|
In this section, we'll cover the importance of the Gba struct and how it gets created for you.
|
||||||
|
|
||||||
# The importance of the Gba struct
|
# The importance of the Gba struct
|
||||||
|
|
||||||
Almost all interaction with the Game Boy Advance's hardware goes through the [Gba singleton struct](https://docs.rs/agb/latest/agb/struct.Gba.html).
|
Almost all interaction with the Game Boy Advance's hardware goes through the [Gba singleton struct](https://docs.rs/agb/latest/agb/struct.Gba.html).
|
||||||
Your games using `agb` will typically create this in the `main` function and then handle the abstractions in there.
|
You should not create the Gba struct yourself, instead having it be passed into your main function.
|
||||||
|
|
||||||
The Gba struct is used to take advantage of rust's borrow checker, and lean on it to ensure that access to the Game Boy Advance hardware is done 'sensibly'.
|
The Gba struct is used to take advantage of rust's borrow checker, and lean on it to ensure that access to the Game Boy Advance hardware is done 'sensibly'.
|
||||||
You won't have to worry about 2 bits of your code modifying data in the wrong way!
|
You won't have to worry about 2 bits of your code modifying data in the wrong way!
|
||||||
This struct is a 'singleton', so you cannot create 2 instances of it at once.
|
This struct is a 'singleton', so you cannot create another instance of it.
|
||||||
Attempting to do so will result in a panic which by default crashes the game.
|
Attempting to do so will result in a panic which by default crashes the game.
|
||||||
|
|
||||||
# How all agb games start
|
# How all agb games start
|
||||||
|
@ -21,8 +21,6 @@ Replace the content of the `main` function with the following:
|
||||||
# #![no_main]
|
# #![no_main]
|
||||||
# #[agb::entry]
|
# #[agb::entry]
|
||||||
# fn main() -> ! {
|
# fn main() -> ! {
|
||||||
let mut gba = agb::Gba::new();
|
|
||||||
|
|
||||||
loop {} // infinite loop for now
|
loop {} // infinite loop for now
|
||||||
# }
|
# }
|
||||||
```
|
```
|
||||||
|
@ -36,6 +34,6 @@ Although there isn't much to see at the moment (just a black screen), you can st
|
||||||
# What we did
|
# What we did
|
||||||
|
|
||||||
This was a very simple but incredibly important part of any game using `agb`.
|
This was a very simple but incredibly important part of any game using `agb`.
|
||||||
All interactions with the hardware are gated via the Gba struct, so it must be created at the start of your `main` function and never again.
|
All interactions with the hardware are gated via the Gba struct, which you never create yourself.
|
||||||
|
|
||||||
You are now ready to learn about display modes and how to start getting things onto the screen!
|
You are now ready to learn about display modes and how to start getting things onto the screen!
|
|
@ -12,12 +12,11 @@
|
||||||
|
|
||||||
use agb::{display, syscall};
|
use agb::{display, syscall};
|
||||||
|
|
||||||
// The main function must take 0 arguments and never return. The agb::entry decorator
|
// The main function must take 1 arguments and never return. The agb::entry decorator
|
||||||
// ensures that everything is in order. `agb` will call this after setting up the stack
|
// ensures that everything is in order. `agb` will call this after setting up the stack
|
||||||
// and interrupt handlers correctly.
|
// and interrupt handlers correctly. It will also handle creating the `Gba` struct for you.
|
||||||
#[agb::entry]
|
#[agb::entry]
|
||||||
fn main() -> ! {
|
fn main(mut gba: agb::Gba) -> ! {
|
||||||
let mut gba = agb::Gba::new();
|
|
||||||
let mut bitmap = gba.display.video.bitmap3();
|
let mut bitmap = gba.display.video.bitmap3();
|
||||||
|
|
||||||
for x in 0..display::WIDTH {
|
for x in 0..display::WIDTH {
|
||||||
|
|
Loading…
Reference in a new issue