use super::builds::{Build, var_addr};
use super::heap::{heap_chunks, read_u32};
use super::tables::*;
pub fn draw_pools(mem: &[u8], build: Build) -> Vec<u32> {
[":gGfxAllocOnlyPool"]
.iter()
.filter_map(|n| {
let i = VARS.iter().position(|v| v.0.ends_with(n))?;
read_u32(mem, var_addr(build, i).0).filter(|&p| p != 0)
})
.collect()
}
pub fn unsupported(mem: &[u8], build: Build) -> Option<String> {
let pool_at = |name: &str| {
let i = VARS.iter().position(|v| v.0.ends_with(name))?;
read_u32(mem, var_addr(build, i).0)
};
let pool = pool_at(":sMemPoolForGoddard")?;
if pool == 0 {
return None;
}
let mut b = pool_at(":sPoolListHeadL")?;
for _ in 0..100_000 {
if b == 0 {
return None;
}
if b + 12 == pool {
return Some(
"goddard (the intro's Mario head) is running; its state has no portable form"
.to_string(),
);
}
b = read_u32(mem, b)?;
}
None
}
pub fn display_list_blocks(mem: &[u8], build: Build) -> Result<Vec<u32>, String> {
let chunks = heap_chunks(mem, build)?;
let mut out = Vec::new();
let is_block = |b: u32| chunks.binary_search_by(|c| c.user.cmp(&b)).is_ok();
for pool in draw_pools(mem, build) {
let mut b = read_u32(mem, pool).unwrap_or(0);
while b != 0 && is_block(b) && out.len() < 100_000 {
out.push(b);
b = read_u32(mem, b).unwrap_or(0);
}
}
Ok(out)
}