minimal template project for gba-0.14.1

This commit is contained in:
lif 2023-12-09 01:07:49 -08:00
commit 221e9bd8f6
7 changed files with 235 additions and 0 deletions

13
.cargo/config.toml Normal file
View file

@ -0,0 +1,13 @@
[build]
target = "armv4t-none-eabi"
[unstable]
build-std = ["core"]
[target.thumbv4t-none-eabi]
runner = "mgba-qt"
rustflags = ["-Clink-arg=-Tlinker_scripts/mono_boot.ld"]
[target.armv4t-none-eabi]
runner = "mgba-qt"
rustflags = ["-Clink-arg=-Tlinker_scripts/mono_boot.ld"]

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

46
Cargo.lock generated Normal file
View file

@ -0,0 +1,46 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "bitfrob"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a96c7c818dc8807bb1982dd2cba4c7de0ed6eba4ffb5fc24321d1b38676a120"
[[package]]
name = "bracer"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00248d542917c4ef013367c0907300e9befbbc1f99b12938c9e5a356ab50582d"
[[package]]
name = "bytemuck"
version = "1.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9134a6ef01ce4b366b50689c94f82c14bc72bc5d0386829828a2e2752ef7958c"
[[package]]
name = "gba"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff72a04df599de9991069ab6807f00e02dc24840e13d16f92dfa2929c4e6950"
dependencies = [
"bitfrob",
"bracer",
"bytemuck",
"voladdress",
]
[[package]]
name = "gba-template"
version = "0.1.0"
dependencies = [
"gba",
]
[[package]]
name = "voladdress"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fbf3fef7bc995d3f8350936bdd07966c7a1f96183d52e3f28c29d099d0b5ecc"

13
Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "gba-template"
version = "0.1.0"
edition = "2024"
[dependencies]
gba = "0.14.1"
[profile.release]
opt-level = 3
[profile.dev]
opt-level = "s"

100
linker_scripts/mono_boot.ld Normal file
View file

@ -0,0 +1,100 @@
/* THIS LINKER SCRIPT FILE IS RELEASED TO THE PUBLIC DOMAIN (SPDX: CC0-1.0) */
ENTRY(__start)
MEMORY {
ewram (w!x) : ORIGIN = 0x2000000, LENGTH = 256K
iwram (w!x) : ORIGIN = 0x3000000, LENGTH = 32K
rom (rx) : ORIGIN = 0x8000000, LENGTH = 32M
}
SECTIONS {
.text : {
/* be sure that the ROM header is the very first */
*(.text.gba_rom_header);
*(.text .text.*);
. = ALIGN(4);
} >rom = 0x00
.rodata : {
*(.rodata .rodata.*);
. = ALIGN(4);
} >rom = 0x00
. = ALIGN(4);
__iwram_position_in_rom = .;
.data : {
__iwram_start = ABSOLUTE(.);
*(.data .data.*);
*(.iwram .iwram.*);
. = ALIGN(4);
__iwram_end = ABSOLUTE(.);
} >iwram AT>rom = 0x00
. = ALIGN(4);
__ewram_position_in_rom = __iwram_position_in_rom + (__iwram_end - __iwram_start);
.ewram : {
__ewram_start = ABSOLUTE(.);
*(.ewram .ewram.*);
. = ALIGN(4);
__ewram_end = ABSOLUTE(.);
} >ewram AT>rom = 0x00
. = ALIGN(4);
__bss_position_in_rom = __ewram_position_in_rom + (__ewram_end - __ewram_start);
.bss : {
__bss_start = ABSOLUTE(.);
*(.bss .bss.*);
. = ALIGN(4);
__bss_end = ABSOLUTE(.);
} >iwram
__iwram_word_copy_count = (__iwram_end - __iwram_start) / 4;
__ewram_word_copy_count = (__ewram_end - __ewram_start) / 4;
__bss_word_clear_count = (__bss_end - __bss_start) / 4;
/* rust-lld demands we keep the `section header string table` */
.shstrtab 0 : { *(.shstrtab) }
/* debugging sections */
/* Stabs */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* discard anything not already mentioned */
/DISCARD/ : { *(*) }
}

12
make-rom.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
# terrible
eval $(grep '^name *=' Cargo.toml | head -n1 | sed 's/ //g')
set -exo pipefail
cargo build --release
arm-none-eabi-objcopy -O binary "target/armv4t-none-eabi/release/$name" "target/${name}.gba"
gbafix "target/${name}.gba"

50
src/main.rs Normal file
View file

@ -0,0 +1,50 @@
// from https://github.com/rust-console/gba/blob/main/examples/hello.rs
#![no_std]
#![no_main]
use core::panic::PanicInfo;
use gba::prelude::*;
#[allow(unused_must_use)]
#[unsafe(no_mangle)]
#[instruction_set(arm::t32)]
extern "C" fn main() -> ! {
BG_PALETTE.index(0).write(Color(0x7F2B)); // blue
BG_PALETTE.index(1).write(Color(0x5EBE)); // pink
BG_PALETTE.index(2).write(Color(0x7FFF)); // white
// rotate and streeetch
BG2PA.write(i16fx8::from_bits(0));
BG2PB.write(i16fx8::from_bits(8));
BG2PC.write(i16fx8::from_bits(1));
BG2PD.write(i16fx8::from_bits(0));
// load-bearing low-order 00 byte (it's a blue pixel and a tile ID)
unsafe { CHARBLOCK0_8BPP.index(0).cast() }.write(0x01020100);
DISPCNT.write(
DisplayControl::new()
.with_video_mode(VideoMode::_2)
.with_show_bg2(true),
);
// waits forever, as we haven't enabled interrupts
VBlankIntrWait();
unreachable!();
}
#[panic_handler]
fn panic_handler(panic_info: &PanicInfo) -> ! {
#[cfg(debug_assertions)]
if let Ok(mut log) = MgbaBufferedLogger::try_new(MgbaMessageLevel::Fatal) {
use core::fmt::Write;
if let Some(loc) = panic_info.location() {
log.write_fmt(format_args!("{loc}: ")).ok();
}
log.write_fmt(format_args!("{}", panic_info.message())).ok();
}
let _ = panic_info;
loop {
VBlankIntrWait();
}
}