mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Really simple beep
This commit is contained in:
parent
404be633c1
commit
71160c7116
18
examples/beep.rs
Normal file
18
examples/beep.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#![no_std]
|
||||||
|
#![feature(start)]
|
||||||
|
|
||||||
|
extern crate gba;
|
||||||
|
|
||||||
|
use gba::display;
|
||||||
|
|
||||||
|
#[start]
|
||||||
|
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||||
|
let mut gba = gba::Gba::new();
|
||||||
|
let mut bitmap = gba.display.video.bitmap3();
|
||||||
|
let vblank = gba.display.vblank.get();
|
||||||
|
|
||||||
|
gba.sound.enable();
|
||||||
|
gba.sound.channel1().play_sound();
|
||||||
|
|
||||||
|
loop {}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
pub mod display;
|
pub mod display;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
|
pub mod sound;
|
||||||
|
|
||||||
mod interrupt;
|
mod interrupt;
|
||||||
mod memory_mapped;
|
mod memory_mapped;
|
||||||
|
@ -37,6 +38,7 @@ static mut GBASINGLE: single::Singleton<Gba> = single::Singleton::new(unsafe { G
|
||||||
|
|
||||||
pub struct Gba {
|
pub struct Gba {
|
||||||
pub display: display::Display,
|
pub display: display::Display,
|
||||||
|
pub sound: sound::Sound,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gba {
|
impl Gba {
|
||||||
|
@ -47,6 +49,7 @@ impl Gba {
|
||||||
const unsafe fn single_new() -> Self {
|
const unsafe fn single_new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
display: display::Display::new(),
|
display: display::Display::new(),
|
||||||
|
sound: sound::Sound::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
40
src/sound/mod.rs
Normal file
40
src/sound/mod.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
use crate::memory_mapped::MemoryMapped;
|
||||||
|
|
||||||
|
const CHANNEL_1_SWEEP: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0060) };
|
||||||
|
const CHANNEL_1_LENGTH_DUTY_ENVELOPE: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0062) };
|
||||||
|
const CHANNEL_1_FREQUENCY_CONTROL: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0064) };
|
||||||
|
|
||||||
|
const MASTER_SOUND_VOLUME_ENABLE: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0080) };
|
||||||
|
const MASTER_SOUND_VOLUME_MIXING: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0082) };
|
||||||
|
const MASTER_SOUND_STATUS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0084) };
|
||||||
|
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub struct Sound {}
|
||||||
|
|
||||||
|
impl Sound {
|
||||||
|
pub(crate) const unsafe fn new() -> Self {
|
||||||
|
Sound {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn channel1(&self) -> Channel1 {
|
||||||
|
Channel1 {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn enable(&self) {
|
||||||
|
MASTER_SOUND_STATUS.set_bits(1, 1, 7);
|
||||||
|
|
||||||
|
MASTER_SOUND_VOLUME_ENABLE.set(0b1111_1111_0_111_0_111);
|
||||||
|
MASTER_SOUND_VOLUME_MIXING.set(0b10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub struct Channel1 {}
|
||||||
|
|
||||||
|
impl Channel1 {
|
||||||
|
pub fn play_sound(&self) {
|
||||||
|
CHANNEL_1_SWEEP.set(0b00000000_111_0_010);
|
||||||
|
CHANNEL_1_LENGTH_DUTY_ENVELOPE.set(0b111_1_001_01_111111);
|
||||||
|
CHANNEL_1_FREQUENCY_CONTROL.set(0b1_0_000_01000000000);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue