2021-06-06 19:53:16 +10:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
extern crate agb;
|
|
|
|
|
2021-08-01 06:47:05 +10:00
|
|
|
use agb::input::{Button, ButtonController, Tri};
|
|
|
|
use agb::number::Num;
|
2021-06-06 21:44:32 +10:00
|
|
|
use agb::sound::mixer::SoundChannel;
|
2021-10-18 08:38:19 +11:00
|
|
|
use agb::{include_wav, Gba};
|
2021-06-06 19:53:16 +10:00
|
|
|
|
2021-10-18 08:38:19 +11:00
|
|
|
// Music - "Dead Code" by Josh Woodward, free download at http://joshwoodward.com
|
|
|
|
const DEAD_CODE: &[u8] = include_wav!("examples/JoshWoodward-DeadCode.wav");
|
2021-06-06 19:53:16 +10:00
|
|
|
|
2021-08-08 01:36:41 +10:00
|
|
|
#[agb::entry]
|
|
|
|
fn main() -> ! {
|
2021-06-06 21:44:32 +10:00
|
|
|
let mut gba = Gba::new();
|
2021-06-26 06:53:42 +10:00
|
|
|
let mut input = ButtonController::new();
|
2021-07-04 03:57:17 +10:00
|
|
|
let vblank_provider = agb::interrupt::VBlank::get();
|
2021-06-06 21:44:32 +10:00
|
|
|
|
2021-11-23 06:27:08 +11:00
|
|
|
let mut timers = gba.timers.timers();
|
|
|
|
let mut mixer = gba.mixer.mixer(&mut timers.timer0);
|
2021-06-06 19:53:16 +10:00
|
|
|
mixer.enable();
|
|
|
|
|
2021-10-18 08:38:19 +11:00
|
|
|
let channel = SoundChannel::new(DEAD_CODE);
|
2021-06-26 06:53:42 +10:00
|
|
|
let channel_id = mixer.play_sound(channel).unwrap();
|
2021-06-06 19:53:16 +10:00
|
|
|
|
2021-06-06 21:44:32 +10:00
|
|
|
loop {
|
2021-06-26 06:53:42 +10:00
|
|
|
input.update();
|
|
|
|
|
|
|
|
{
|
2021-06-26 06:54:12 +10:00
|
|
|
if let Some(channel) = mixer.get_channel(&channel_id) {
|
|
|
|
let half: Num<i16, 4> = Num::new(1) / 2;
|
|
|
|
let half_usize: Num<usize, 8> = Num::new(1) / 2;
|
|
|
|
match input.x_tri() {
|
|
|
|
Tri::Negative => channel.panning(-half),
|
|
|
|
Tri::Zero => channel.panning(0.into()),
|
|
|
|
Tri::Positive => channel.panning(half),
|
|
|
|
};
|
2021-08-01 06:47:05 +10:00
|
|
|
|
2021-06-26 06:54:12 +10:00
|
|
|
match input.y_tri() {
|
|
|
|
Tri::Negative => channel.playback(half_usize.change_base() + 1),
|
|
|
|
Tri::Zero => channel.playback(1.into()),
|
|
|
|
Tri::Positive => channel.playback(half_usize),
|
|
|
|
};
|
2021-06-26 07:01:50 +10:00
|
|
|
|
|
|
|
if input.is_pressed(Button::L) {
|
|
|
|
channel.volume(half);
|
|
|
|
} else {
|
|
|
|
channel.volume(1.into());
|
|
|
|
}
|
2021-06-26 06:54:12 +10:00
|
|
|
}
|
2021-06-26 06:53:42 +10:00
|
|
|
}
|
|
|
|
|
2021-06-28 10:03:08 +10:00
|
|
|
vblank_provider.wait_for_vblank();
|
2021-06-06 21:44:32 +10:00
|
|
|
mixer.vblank();
|
|
|
|
}
|
2021-06-06 19:53:16 +10:00
|
|
|
}
|