Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment with general system of mutually exclusive hardware #449

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions agb/examples/affine_background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use agb::{
display::{
affine::AffineMatrixBackground,
tiled::{AffineBackgroundSize, TileFormat, TileSet, TiledMap},
video::Tiled2Vram,
Priority,
},
fixnum::{num, Num},
Expand All @@ -15,7 +16,7 @@ include_background_gfx!(affine_tiles, water_tiles => 256 "examples/water_tiles.p

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let (gfx, mut vram) = gba.display.video.tiled2();
let (gfx, vram) = &mut *gba.display.video.get::<Tiled2Vram>();
let vblank = agb::interrupt::VBlank::get();

let tileset = TileSet::new(affine_tiles::water_tiles.tiles, TileFormat::EightBpp);
Expand All @@ -26,11 +27,11 @@ fn main(mut gba: agb::Gba) -> ! {

for y in 0..32u16 {
for x in 0..32u16 {
bg.set_tile(&mut vram, (x, y).into(), &tileset, 1);
bg.set_tile(vram, (x, y).into(), &tileset, 1);
}
}

bg.commit(&mut vram);
bg.commit(vram);
bg.show();

let mut rotation = num!(0.);
Expand Down Expand Up @@ -61,6 +62,6 @@ fn main(mut gba: agb::Gba) -> ! {
bg.set_transform(transformation);

vblank.wait_for_vblank();
bg.commit(&mut vram);
bg.commit(vram);
}
}
7 changes: 4 additions & 3 deletions agb/examples/animated_background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use agb::{
display::{
tiled::{RegularBackgroundSize, TileFormat, TileSet, TileSetting, TiledMap},
video::Tiled0Vram,
Priority,
},
include_background_gfx,
Expand All @@ -13,7 +14,7 @@ include_background_gfx!(water_tiles, water_tiles => "examples/water_tiles.png");

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let (gfx, mut vram) = gba.display.video.tiled0();
let (gfx, vram) = &mut *gba.display.video.get::<Tiled0Vram>();
let vblank = agb::interrupt::VBlank::get();

let tileset = TileSet::new(water_tiles::water_tiles.tiles, TileFormat::FourBpp);
Expand All @@ -29,15 +30,15 @@ fn main(mut gba: agb::Gba) -> ! {
for y in 0..20u16 {
for x in 0..30u16 {
bg.set_tile(
&mut vram,
vram,
(x, y).into(),
&tileset,
TileSetting::new(0, false, false, 0),
);
}
}

bg.commit(&mut vram);
bg.commit(vram);
bg.show();

let mut i = 0;
Expand Down
2 changes: 1 addition & 1 deletion agb/examples/bitmap3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Vector2D {

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let mut bitmap = gba.display.video.bitmap3();
let mut bitmap = gba.display.video.get::<display::bitmap3::Bitmap3>();
let vblank = agb::interrupt::VBlank::get();

let mut input = agb::input::ButtonController::new();
Expand Down
4 changes: 2 additions & 2 deletions agb/examples/bitmap4.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![no_std]
#![no_main]

use agb::display;
use agb::display::{self, bitmap4::Bitmap4};

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let mut bitmap = gba.display.video.bitmap4();
let mut bitmap = gba.display.video.get::<Bitmap4>();
let vblank = agb::interrupt::VBlank::get();

bitmap.set_palette_entry(1, 0x001F);
Expand Down
7 changes: 4 additions & 3 deletions agb/examples/chicken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use agb::{
object::{OamManaged, Object, Size, Sprite},
palette16::Palette16,
tiled::RegularBackgroundSize,
video::Tiled0Vram,
HEIGHT, WIDTH,
},
input::Button,
Expand Down Expand Up @@ -48,7 +49,7 @@ fn main(mut gba: agb::Gba) -> ! {
.unwrap()
};

let (gfx, mut vram) = gba.display.video.tiled0();
let (gfx, vram) = &mut *gba.display.video.get::<Tiled0Vram>();
let vblank = agb::interrupt::VBlank::get();
let mut input = agb::input::ButtonController::new();

Expand All @@ -64,15 +65,15 @@ fn main(mut gba: agb::Gba) -> ! {
for (i, &tile) in MAP_MAP.iter().enumerate() {
let i = i as u16;
background.set_tile(
&mut vram,
vram,
(i % 32, i / 32).into(),
&tileset,
TileSetting::from_raw(tile),
);
}

background.show();
background.commit(&mut vram);
background.commit(vram);

let object = gba.display.object.get_managed();

Expand Down
7 changes: 4 additions & 3 deletions agb/examples/dynamic_tiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
use agb::display::{
palette16::Palette16,
tiled::{RegularBackgroundSize, TileFormat, TileSetting, TiledMap},
video::Tiled0Vram,
Priority,
};

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let (gfx, mut vram) = gba.display.video.tiled0();
let (gfx, vram) = &mut *gba.display.video.get::<Tiled0Vram>();
let vblank = agb::interrupt::VBlank::get();

vram.set_background_palettes(&[Palette16::new([
Expand Down Expand Up @@ -39,7 +40,7 @@ fn main(mut gba: agb::Gba) -> ! {
}

bg.set_tile(
&mut vram,
vram,
(x as u16, y as u16).into(),
&dynamic_tile.tile_set(),
TileSetting::from_raw(dynamic_tile.tile_index()),
Expand All @@ -49,7 +50,7 @@ fn main(mut gba: agb::Gba) -> ! {
}
}

bg.commit(&mut vram);
bg.commit(vram);
bg.show();

loop {
Expand Down
15 changes: 8 additions & 7 deletions agb/examples/mixer_32768.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use agb::{
tiled::{
RegularBackgroundSize, RegularMap, TileFormat, TileSetting, TiledMap, VRamManager,
},
video::Tiled0Vram,
Font, Priority,
},
include_font, include_wav,
Expand All @@ -24,23 +25,23 @@ const FONT: Font = include_font!("examples/font/yoster.ttf", 12);
fn main(mut gba: Gba) -> ! {
let vblank_provider = agb::interrupt::VBlank::get();

let (gfx, mut vram) = gba.display.video.tiled0();
let (gfx, vram) = &mut *gba.display.video.get::<Tiled0Vram>();
let mut bg = gfx.background(
Priority::P0,
RegularBackgroundSize::Background32x32,
TileFormat::FourBpp,
);

init_background(&mut bg, &mut vram);
init_background(&mut bg, vram);

let mut title_renderer = FONT.render_text((0u16, 3u16).into());
let mut writer = title_renderer.writer(1, 0, &mut bg, &mut vram);
let mut writer = title_renderer.writer(1, 0, &mut bg, vram);

writeln!(&mut writer, "Crazy Glue by Josh Woodward").unwrap();

writer.commit();

bg.commit(&mut vram);
bg.commit(vram);
bg.show();

let timer_controller = gba.timers.timers();
Expand All @@ -62,7 +63,7 @@ fn main(mut gba: Gba) -> ! {
let mut stats_renderer = FONT.render_text((0u16, 6u16).into());
loop {
vblank_provider.wait_for_vblank();
bg.commit(&mut vram);
bg.commit(vram);

let before_mixing_cycles_high = timer2.value();
let before_mixing_cycles_low = timer.value();
Expand All @@ -83,9 +84,9 @@ fn main(mut gba: Gba) -> ! {

let percent = (total_cycles * 100) / 280896;

stats_renderer.clear(&mut vram);
stats_renderer.clear(vram);

let mut writer = stats_renderer.writer(1, 0, &mut bg, &mut vram);
let mut writer = stats_renderer.writer(1, 0, &mut bg, vram);
writeln!(&mut writer, "{total_cycles} cycles").unwrap();
writeln!(&mut writer, "{percent} percent").unwrap();

Expand Down
8 changes: 4 additions & 4 deletions agb/examples/multiple_video.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]
#![no_main]

use agb::display;
use agb::display::{self, bitmap3::Bitmap3, bitmap4::Bitmap4};

struct Vector2D {
x: i32,
Expand All @@ -14,8 +14,8 @@ fn main(mut gba: agb::Gba) -> ! {
let mut input = agb::input::ButtonController::new();

loop {
bitmap3_mode(&mut gba.display.video.bitmap3(), &vblank, &mut input);
bitmap4_mode(&mut gba.display.video.bitmap4(), &vblank, &mut input);
bitmap3_mode(&mut gba.display.video.get::<Bitmap3>(), &vblank, &mut input);
bitmap4_mode(&mut gba.display.video.get::<Bitmap4>(), &vblank, &mut input);
}
}

Expand Down Expand Up @@ -47,7 +47,7 @@ fn bitmap3_mode(
}

fn bitmap4_mode(
bitmap: &mut display::bitmap4::Bitmap4,
bitmap: &mut Bitmap4,
vblank: &agb::interrupt::VBlank,
input: &mut agb::input::ButtonController,
) {
Expand Down
4 changes: 2 additions & 2 deletions agb/examples/panic.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![no_std]
#![no_main]

use agb::display;
use agb::display::{self, bitmap3::Bitmap3};

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let mut bitmap = gba.display.video.bitmap3();
let mut bitmap = gba.display.video.get::<Bitmap3>();
let mut input = agb::input::ButtonController::new();

loop {
Expand Down
13 changes: 7 additions & 6 deletions agb/examples/stereo_sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use agb::{
tiled::{
RegularBackgroundSize, RegularMap, TileFormat, TileSetting, TiledMap, VRamManager,
},
video::Tiled0Vram,
Font, Priority,
},
include_font, include_wav,
Expand All @@ -24,23 +25,23 @@ const FONT: Font = include_font!("examples/font/yoster.ttf", 12);
fn main(mut gba: Gba) -> ! {
let vblank_provider = agb::interrupt::VBlank::get();

let (gfx, mut vram) = gba.display.video.tiled0();
let (gfx, vram) = &mut *gba.display.video.get::<Tiled0Vram>();
let mut bg = gfx.background(
Priority::P0,
RegularBackgroundSize::Background32x32,
TileFormat::FourBpp,
);

init_background(&mut bg, &mut vram);
init_background(&mut bg, vram);

let mut title_renderer = FONT.render_text((0u16, 3u16).into());
let mut writer = title_renderer.writer(1, 0, &mut bg, &mut vram);
let mut writer = title_renderer.writer(1, 0, &mut bg, vram);

writeln!(&mut writer, "Let it in by Josh Woodward").unwrap();

writer.commit();

bg.commit(&mut vram);
bg.commit(vram);
bg.show();

let timer_controller = gba.timers.timers();
Expand All @@ -60,7 +61,7 @@ fn main(mut gba: Gba) -> ! {
let mut stats_renderer = FONT.render_text((0u16, 6u16).into());
loop {
vblank_provider.wait_for_vblank();
bg.commit(&mut vram);
bg.commit(vram);

let before_mixing_cycles = timer.value();
mixer.frame();
Expand All @@ -73,7 +74,7 @@ fn main(mut gba: Gba) -> ! {

let percent = (total_cycles * 100) / 280896;

let mut writer = stats_renderer.writer(1, 0, &mut bg, &mut vram);
let mut writer = stats_renderer.writer(1, 0, &mut bg, vram);
writeln!(&mut writer, "{total_cycles} cycles").unwrap();
writeln!(&mut writer, "{percent} percent").unwrap();

Expand Down
7 changes: 5 additions & 2 deletions agb/examples/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#![no_std]
#![no_main]

use agb::{display, syscall};
use agb::{
display::{self, bitmap3::Bitmap3},
syscall,
};

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let mut bitmap = gba.display.video.bitmap3();
let mut bitmap = gba.display.video.get::<Bitmap3>();

for x in 0..display::WIDTH {
let y = syscall::sqrt(x << 6);
Expand Down
5 changes: 3 additions & 2 deletions agb/examples/test_logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
use agb::display::{
example_logo,
tiled::{RegularBackgroundSize, TileFormat},
video::Tiled0Vram,
};

#[agb::entry]
fn main(mut gba: agb::Gba) -> ! {
let (gfx, mut vram) = gba.display.video.tiled0();
let (gfx, vram) = &mut *gba.display.video.get::<Tiled0Vram>();

let mut map = gfx.background(
agb::display::Priority::P0,
RegularBackgroundSize::Background32x32,
TileFormat::FourBpp,
);

example_logo::display_logo(&mut map, &mut vram);
example_logo::display_logo(&mut map, vram);

loop {}
}
Loading
Loading