gba/examples-bak/bg_demo.rs

70 lines
2.1 KiB
Rust
Raw Normal View History

2018-11-19 16:19:13 +11:00
#![no_std]
2018-12-16 14:35:57 +11:00
#![feature(start)]
2018-11-19 16:19:13 +11:00
2018-12-26 10:46:11 +11:00
use gba::{
io::{
2018-12-26 17:19:16 +11:00
background::{BackgroundControlSetting, BG0CNT},
2018-12-26 10:46:11 +11:00
display::{DisplayControlSetting, DISPCNT},
},
palram::index_palram_bg_4bpp,
2018-12-28 05:51:53 +11:00
vram::{text::TextScreenblockEntry, Tile4bpp, CHAR_BASE_BLOCKS, SCREEN_BASE_BLOCKS},
2018-12-26 10:46:11 +11:00
Color,
};
2018-11-19 16:19:13 +11:00
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
2018-12-26 10:46:11 +11:00
pub const WHITE: Color = Color::from_rgb(31, 31, 31);
pub const LIGHT_GRAY: Color = Color::from_rgb(25, 25, 25);
pub const DARK_GRAY: Color = Color::from_rgb(15, 15, 15);
2018-12-06 15:56:39 +11:00
// bg palette
2018-12-26 10:46:11 +11:00
index_palram_bg_4bpp(0, 1).write(WHITE);
index_palram_bg_4bpp(0, 2).write(LIGHT_GRAY);
index_palram_bg_4bpp(0, 3).write(DARK_GRAY);
2018-12-06 15:56:39 +11:00
// bg tiles
set_bg_tile_4bpp(0, 0, ALL_TWOS);
set_bg_tile_4bpp(0, 1, ALL_THREES);
// screenblock
let light_entry = TextScreenblockEntry::from_tile_id(0);
let dark_entry = TextScreenblockEntry::from_tile_id(1);
2018-12-06 15:56:39 +11:00
checker_screenblock(8, light_entry, dark_entry);
// bg0 control
2018-12-28 05:51:53 +11:00
BG0CNT.write(BackgroundControlSetting::new().with_screen_base_block(8));
2018-12-06 15:56:39 +11:00
// Display Control
2018-12-26 17:19:16 +11:00
DISPCNT.write(DisplayControlSetting::new().with_bg0(true));
2018-12-28 17:22:48 +11:00
loop {}
2018-11-19 16:19:13 +11:00
}
2018-12-26 10:46:11 +11:00
pub const ALL_TWOS: Tile4bpp = Tile4bpp([
0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222, 0x22222222,
]);
2018-11-19 16:19:13 +11:00
2018-12-26 10:46:11 +11:00
pub const ALL_THREES: Tile4bpp = Tile4bpp([
0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333, 0x33333333,
]);
2018-12-06 15:56:39 +11:00
pub fn set_bg_tile_4bpp(charblock: usize, index: usize, tile: Tile4bpp) {
assert!(charblock < 4);
assert!(index < 512);
2018-12-27 17:13:10 +11:00
unsafe { CHAR_BASE_BLOCKS.index(charblock).cast::<Tile4bpp>().offset(index as isize).write(tile) }
2018-11-24 08:48:37 +11:00
}
2018-11-26 19:35:30 +11:00
2018-12-26 10:46:11 +11:00
pub fn checker_screenblock(slot: usize, a_entry: TextScreenblockEntry, b_entry: TextScreenblockEntry) {
2018-12-27 17:13:10 +11:00
let mut p = unsafe { SCREEN_BASE_BLOCKS.index(slot).cast::<TextScreenblockEntry>() };
2018-12-06 15:56:39 +11:00
let mut checker = true;
for _row in 0..32 {
for _col in 0..32 {
2018-12-26 10:46:11 +11:00
unsafe {
p.write(if checker { a_entry } else { b_entry });
p = p.offset(1);
}
2018-12-06 15:56:39 +11:00
checker = !checker;
2018-11-26 19:35:30 +11:00
}
2018-12-06 15:56:39 +11:00
checker = !checker;
2018-11-26 19:35:30 +11:00
}
}