-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
cargo build --examples | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/basic_keyinput >target/ex-basic_keyinput.txt | ||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/basic_keyinput >target/ex-basic_keyinput.txt | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/do_nothing >target/ex-do_nothing.txt | ||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/do_nothing >target/ex-do_nothing.txt | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/mode0 >target/ex-mode0.txt | ||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/mode0 >target/ex-mode0.txt | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/mode3 >target/ex-mode3.txt | ||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/mode3 >target/ex-mode3.txt | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/mode4 >target/ex-mode4.txt | ||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/mode4 >target/ex-mode4.txt | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/mode5 >target/ex-mode5.txt | ||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/mode5 >target/ex-mode5.txt | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std target/thumbv4t-none-eabi/debug/examples/paddle_ball >target/ex-paddle_ball.txt | ||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/paddle_ball >target/ex-paddle_ball.txt | ||
|
||
arm-none-eabi-objdump --headers --disassemble --demangle --architecture=armv4t --no-show-raw-insn -Mreg-names-std --visualize-jumps target/thumbv4t-none-eabi/debug/examples/timer >target/ex-timer.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use gba::{ | ||
asm_runtime::USER_IRQ_HANDLER, | ||
bios::VBlankIntrWait, | ||
gba_cell::GbaCell, | ||
mmio::{BACKDROP_COLOR, DISPCNT, DISPSTAT, IE, IME, TIMER0_CONTROL}, | ||
timers::{CpusPerTick, TimerControl}, | ||
video::{Color, DisplayControl, DisplayStatus}, | ||
IrqBits, | ||
}; | ||
|
||
static SECONDS: GbaCell<u32> = GbaCell::new(0); | ||
|
||
gba::panic_handler!(mgba_log_err); | ||
|
||
#[no_mangle] | ||
extern "C" fn main() -> ! { | ||
USER_IRQ_HANDLER.write(Some(irq_handler)); | ||
IE.write(IrqBits::new().with_vblank(true).with_timer0(true)); | ||
IME.write(true); | ||
DISPSTAT.write(DisplayStatus::new().with_vblank_irq(true)); | ||
|
||
TIMER0_CONTROL.write( | ||
TimerControl::new() | ||
.with_enabled(true) | ||
.with_send_irq(true) | ||
// .with_cpus_per_tick(CpusPerTick::_64), | ||
); | ||
|
||
DISPCNT.write(DisplayControl::new().with_bg_mode(3)); | ||
loop { | ||
VBlankIntrWait(); | ||
BACKDROP_COLOR.write(Color(SECONDS.read() as u16)); | ||
} | ||
} | ||
|
||
extern "C" fn irq_handler(bits: IrqBits) { | ||
if bits.timer0() { | ||
SECONDS.write(SECONDS.read().wrapping_add(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Timer related data types. | ||
|
||
use bitfrob::{u8_with_bit, u8_with_region}; | ||
|
||
/// Control bits for one of the GBA's four timers. | ||
#[derive(Debug, Clone, Copy)] | ||
#[repr(transparent)] | ||
pub struct TimerControl(u8); | ||
impl TimerControl { | ||
/// A new, zeroed value. | ||
#[inline] | ||
pub const fn new() -> Self { | ||
Self(0) | ||
} | ||
/// The number of CPU cycles per timer tick. | ||
#[inline] | ||
pub const fn with_cpus_per_tick(self, cpus: CpusPerTick) -> Self { | ||
Self(u8_with_region(0, 1, self.0, cpus as u8)) | ||
} | ||
/// If the timer should *only* tick when the lower-number timer overflows. | ||
/// | ||
/// * When set, this **overrides** the `cpus_per_tick` value and Timer N will | ||
/// instead tick once per overflow of Timer (N-1). | ||
/// * This has no effect for Timer 0, since it has no lower numbered timer. | ||
#[inline] | ||
pub const fn cascade_ticks(self, cascade: bool) -> Self { | ||
Self(u8_with_bit(2, self.0, cascade)) | ||
} | ||
/// If an overflow of this timer should send an interrupt. | ||
#[inline] | ||
pub const fn with_send_irq(self, irq: bool) -> Self { | ||
Self(u8_with_bit(6, self.0, irq)) | ||
} | ||
/// If this timer is enabled. | ||
#[inline] | ||
pub const fn with_enabled(self, enabled: bool) -> Self { | ||
Self(u8_with_bit(7, self.0, enabled)) | ||
} | ||
} | ||
|
||
/// How many CPU cycles per timer tick. | ||
#[repr(u8)] | ||
#[allow(missing_docs)] | ||
pub enum CpusPerTick { | ||
_1 = 0, | ||
_64 = 1, | ||
_256 = 2, | ||
_1024 = 3, | ||
} |