convert from lsdpack output source

This commit is contained in:
lif 2024-01-13 22:33:58 -08:00
parent b11f484e7d
commit 28fd640d28
4 changed files with 177638 additions and 0 deletions

8
Cargo.lock generated
View file

@ -14,6 +14,12 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6559b8c3065745016f5cc2d1095273fe8a175e953c976426947ad828d6ba6fda" checksum = "6559b8c3065745016f5cc2d1095273fe8a175e953c976426947ad828d6ba6fda"
[[package]]
name = "build_const"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7"
[[package]] [[package]]
name = "gba" name = "gba"
version = "0.11.3" version = "0.11.3"
@ -29,7 +35,9 @@ dependencies = [
name = "gba-template" name = "gba-template"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"build_const",
"gba", "gba",
"voladdress",
] ]
[[package]] [[package]]

View file

@ -6,4 +6,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
build_const = { version = "0.2.2", default-features = false }
gba = "0.11.3" gba = "0.11.3"
#once_cell = { version = "1.19.0", default-features = false }
voladdress = "*"
[build-dependencies]
build_const = "0.2.2"

34
build.rs Normal file
View file

@ -0,0 +1,34 @@
use build_const::ConstWriter;
const SONG_SOURCE: &str = include_str!("lsdpack.s");
fn main() {
let mut consts = ConstWriter::for_build("lsdpack_bc")
.unwrap()
.finish_dependencies();
let bytes: Vec<u8> = SONG_SOURCE
.lines()
.map(|s| s.trim().strip_prefix("DB "))
.flatten() // filter to lines starting with DB
.map(|s| {
s.split_once(';')
.unwrap_or((s, ""))
.0 // remove comments
.chars()
.filter(|c| *c == ',' || c.is_ascii_hexdigit()) // remove spaces and dollars
.collect::<String>()
.split(',')
.map(|s| u8::from_str_radix(s, 16).unwrap())
.collect::<Vec<u8>>()
})
.flatten() // merge iterator of vectors
.collect();
let song_positions: Vec<usize> = SONG_SOURCE
.lines()
.map(|s| s.trim().strip_prefix("dw "))
.flatten() // filter to lines from SongLocations
.map(|s| usize::from_str_radix(s.split_once('$').unwrap().1, 16).unwrap() - 0x4000)
.collect();
consts.add_array("LSDPACK_DATA", "u8", &bytes);
consts.add_array("LSDPACK_SONG_POSITIONS", "usize", &song_positions);
}

177590
lsdpack.s Normal file

File diff suppressed because it is too large Load diff