Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed May 14, 2024
1 parent c048783 commit 5168cd2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion examples/basic_keyinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub extern "C" fn main() -> ! {

// The body of the game is to just sleep until each vblank (this saves a lot
// of battery power), then immediately upon waking we just go back to sleep.
// The handler is effectively run "during" this wait call.
// The handler is effectively run "during" this wait call (after the GBA wakes
// up, but before the BIOS function call returns).
loop {
VBlankIntrWait();
}
Expand Down
31 changes: 20 additions & 11 deletions src/bios.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#![allow(non_snake_case)]

//! Module for calls to BIOS functions.
//!
//! The BIOS functions aren't called using a normal foreign function call (eg:
//! using the `extern "C"` ABI). Instead, a special instruction `swi`
//! (software-interrupt) is executed, and an immediate data byte in the
//! instruction tells the BIOS what function to execute. Because of this, the
//! BIOS functions have a rather high calls overhead compared to a normal
//! foreign function.

use crate::IrqBits;

Expand All @@ -25,22 +32,24 @@ use crate::IrqBits;
/// * Otherwise, any previous interrupts that match `target_irqs` will cause the
/// function to return immediately without waiting for a new interrupt.
#[inline]
#[instruction_set(arm::t32)]
#[cfg_attr(feature = "on_gba", instruction_set(arm::t32))]
pub fn IntrWait(ignore_existing: bool, target_irqs: IrqBits) {
unsafe {
core::arch::asm! {
"swi #0x04",
inout("r0") ignore_existing as u32 => _,
inout("r1") target_irqs.0 => _,
out("r3") _,
options(preserves_flags),
}
};
on_gba_or_unimplemented!(
unsafe {
core::arch::asm! {
"swi #0x04",
inout("r0") ignore_existing as u32 => _,
inout("r1") target_irqs.0 => _,
out("r3") _,
options(preserves_flags),
}
};
);
}

/// `0x05`: Builtin shorthand for [`IntrWait(true, IrqBits::VBLANK)`](IntrWait)
#[inline]
#[instruction_set(arm::t32)]
#[cfg_attr(feature = "on_gba", instruction_set(arm::t32))]
pub fn VBlankIntrWait() {
on_gba_or_unimplemented!(
unsafe {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ impl KeyInput {
#[repr(transparent)]
pub struct IrqBits(u16);
impl IrqBits {
/// The vblank bit.
pub const VBLANK: Self = Self::new().with_vblank(true);

/// Makes a new, empty value.
#[inline]
pub const fn new() -> Self {
Expand Down Expand Up @@ -227,7 +230,6 @@ impl IrqBits {
pub const fn gamepak(self) -> bool {
u16_get_bit(13, self.0)
}
/* * * * */

/// Set if vblank triggers an interrupt.
#[inline]
Expand Down

0 comments on commit 5168cd2

Please sign in to comment.