sm64_binds/sm64/portable/builds.rs
1//! The two builds a state can come from or go to.
2//!
3//! Both WASMs are linked from the same objects with the same struct layouts
4//! (wasm32), so the only things that differ for one variable are its address
5//! (headless and visual columns of `tables::VARS`) and, for heap data, where
6//! malloc put it.
7//!
8//! Read next: `addresses.rs`.
9
10use super::tables::*;
11
12/// Which of the two builds a memory image or state belongs to.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub enum Build {
15 /// `build/us_web_headless`: what nodes, bots and the Rust/Python bindings run.
16 Headless,
17 /// `build/us_web`: the rendering build the browser runs.
18 Visual,
19}
20
21impl Build {
22 /// 0 for headless, 1 for visual: the column of the per-build tables, and the byte in the format.
23 pub fn index(self) -> usize {
24 match self {
25 Build::Headless => 0,
26 Build::Visual => 1,
27 }
28 }
29 pub fn name(self) -> &'static str {
30 match self {
31 Build::Headless => "headless",
32 Build::Visual => "visual",
33 }
34 }
35 /// The SHA-1 of the WASM's code (without data sections) the tables were made from.
36 pub fn build_id(self) -> &'static str {
37 match self {
38 Build::Headless => BUILD_ID_HEADLESS,
39 Build::Visual => BUILD_ID_VISUAL,
40 }
41 }
42}
43
44/// Variable `i` of `VARS` in `build`'s memory: (address, size, layout, 0xFFFF for raw bytes).
45pub(super) fn var_addr(build: Build, i: usize) -> (u32, u32, u16) {
46 let v = &VARS[i];
47 (if build == Build::Headless { v.1 } else { v.2 }, v.3, v.4)
48}