Skip to content

Commit

Permalink
a working objects demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed May 27, 2024
1 parent 7fe46b6 commit 869562b
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 262 deletions.
209 changes: 0 additions & 209 deletions backup/examples/game.rs

This file was deleted.

54 changes: 29 additions & 25 deletions backup/examples/game_vblank_draw.rs → examples/objects.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#![no_std]
#![no_main]

use gba::prelude::*;

#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
#[cfg(debug_assertions)]
if let Ok(mut logger) = MgbaBufferedLogger::try_new(MgbaMessageLevel::Fatal) {
use core::fmt::Write;
writeln!(logger, "{info}").ok();
}
loop {}
}
use gba::{
asm_runtime::USER_IRQ_HANDLER,
bios::VBlankIntrWait,
gba_cell::GbaCell,
mmio::{
obj_palbank, BG0CNT, BG_PALRAM, DISPCNT, DISPSTAT, IE, IME, KEYINPUT,
OBJ_ATTR0, OBJ_ATTR_ALL, TEXT_SCREENBLOCKS, VRAM_BG_TILE4, VRAM_OBJ_TILE4,
},
obj::{ObjAttr, ObjAttr0, ObjDisplayStyle},
sample_art::{decompress_cga_face_to_vram_4bpp, Cga},
video::{BackgroundControl, Color, DisplayControl, DisplayStatus, TextEntry},
IrqBits,
};

gba::panic_handler!(mgba_log_err);

#[derive(Debug, Clone, Copy, Default)]
struct Position {
Expand Down Expand Up @@ -88,36 +92,36 @@ extern "C" fn main() -> ! {
// indexing with `[y][x]`
let mut world = [[0_u8; 32]; 32];
for i in 0..32 {
world[0][i] = Cga8x8Thick::BOX_HORIZONTAL;
world[19][i] = Cga8x8Thick::BOX_HORIZONTAL;
world[i][0] = Cga8x8Thick::BOX_VERTICAL;
world[i][29] = Cga8x8Thick::BOX_VERTICAL;
world[0][i] = Cga::LEFT_RIGHT;
world[19][i] = Cga::LEFT_RIGHT;
world[i][0] = Cga::UP_DOWN;
world[i][29] = Cga::UP_DOWN;
}
world[0][0] = Cga8x8Thick::BOX_UPPER_LEFT;
world[0][29] = Cga8x8Thick::BOX_UPPER_RIGHT;
world[19][0] = Cga8x8Thick::BOX_LOWER_LEFT;
world[19][29] = Cga8x8Thick::BOX_LOWER_RIGHT;
world[0][0] = Cga::DOWN_RIGHT;
world[0][29] = Cga::LEFT_DOWN;
world[19][0] = Cga::UP_RIGHT;
world[19][29] = Cga::UP_LEFT;
world[1][3] = b'B';
world[2][3] = b'G';
world[3][3] = b'0';

// interrupt configuration
RUST_IRQ_HANDLER.write(Some(irq_handler));
DISPSTAT.write(DisplayStatus::new().with_irq_vblank(true));
USER_IRQ_HANDLER.write(Some(irq_handler));
DISPSTAT.write(DisplayStatus::new().with_vblank_irq(true));
IE.write(IrqBits::VBLANK);
IME.write(true);

// bg
BG_PALETTE.index(1).write(Color::MAGENTA);
BG_PALRAM.index(1).write(Color::MAGENTA);
// obj
let colors =
[Color::CYAN, Color::GREEN, Color::RED, Color::BLUE, Color::YELLOW];
for (pal, color) in colors.iter().enumerate() {
obj_palbank(pal).index(1).write(*color);
}

Cga8x8Thick.bitunpack_4bpp(CHARBLOCK0_4BPP.as_region(), 0);
Cga8x8Thick.bitunpack_4bpp(OBJ_TILES.as_region(), 0);
decompress_cga_face_to_vram_4bpp(VRAM_BG_TILE4.as_region());
decompress_cga_face_to_vram_4bpp(VRAM_OBJ_TILE4.as_region());

BG0CNT.write(BackgroundControl::new().with_screenblock(8));
let screenblock = TEXT_SCREENBLOCKS.get_frame(8).unwrap();
Expand All @@ -132,7 +136,7 @@ extern "C" fn main() -> ! {
let no_display = ObjAttr0::new().with_style(ObjDisplayStyle::NotDisplayed);
OBJ_ATTR0.iter().skip(creatures.len()).for_each(|va| va.write(no_display));

DISPCNT.write(DisplayControl::new().with_show_obj(true).with_show_bg0(true));
DISPCNT.write(DisplayControl::new().with_objects(true).with_bg0(true));

let mut l_was_pressed = false;
let mut r_was_pressed = false;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub mod gba_fixed;
pub mod mem;
pub mod mgba;
pub mod mmio;
pub mod obj;
pub mod panic_handlers;
pub mod per_project_setup;
pub mod per_system_setup;
Expand Down
Loading

0 comments on commit 869562b

Please sign in to comment.