ds_rom/rom/
arm7.rs

1use std::borrow::Cow;
2
3use serde::{Deserialize, Serialize};
4
5/// ARM7 program.
6pub struct Arm7<'a> {
7    data: Cow<'a, [u8]>,
8    offsets: Arm7Offsets,
9}
10
11/// Offsets in the ARM7 program.
12#[derive(Serialize, Deserialize)]
13pub struct Arm7Offsets {
14    /// Base address.
15    pub base_address: u32,
16    /// Entrypoint function address.
17    pub entry_function: u32,
18    /// Build info offset.
19    pub build_info: u32,
20    /// Autoload callback address.
21    pub autoload_callback: u32,
22}
23
24impl<'a> Arm7<'a> {
25    /// Creates a new ARM7 program from raw data.
26    pub fn new<T: Into<Cow<'a, [u8]>>>(data: T, offsets: Arm7Offsets) -> Self {
27        Self { data: data.into(), offsets }
28    }
29
30    /// Returns a reference to the full data.
31    pub fn full_data(&self) -> &[u8] {
32        &self.data
33    }
34
35    /// Returns the base address of this.
36    pub fn base_address(&self) -> u32 {
37        self.offsets.base_address
38    }
39
40    /// Returns the entrypoint function address.
41    pub fn entry_function(&self) -> u32 {
42        self.offsets.entry_function
43    }
44
45    /// Returns the build info offset.
46    pub fn build_info_offset(&self) -> u32 {
47        self.offsets.build_info
48    }
49
50    /// Returns the autoload callback address.
51    pub fn autoload_callback(&self) -> u32 {
52        self.offsets.autoload_callback
53    }
54
55    /// Returns a reference to the ARM7 offsets.
56    pub fn offsets(&self) -> &Arm7Offsets {
57        &self.offsets
58    }
59}