cpclib_asm/assembler/
section.rs1use crate::{Env, ExprResult};
2
3#[derive(Clone, Debug)]
4pub struct Section {
5 pub(crate) name: String,
7 pub(crate) start: u16,
9 pub(crate) stop: u16,
11 pub(crate) mmr: u8,
13
14 pub(crate) output_adr: u16,
15 pub(crate) max_output_adr: u16,
16 pub(crate) code_adr: u16
17}
18
19impl Section {
20 pub(crate) fn new(name: &str, start: u16, stop: u16, mmr: u8) -> Self {
21 Section {
22 mmr,
23 name: name.to_owned(),
24 start,
25 stop,
26
27 output_adr: start,
28 code_adr: start,
29
30 max_output_adr: start
31 }
32 }
33
34 pub fn contains(&self, addr: u16) -> bool {
35 addr >= self.start && addr <= self.stop
36 }
37
38 pub(crate) fn new_pass(&mut self) {
39 self.output_adr = self.start;
40 self.code_adr = self.start;
41 }
42
43 pub fn length(&self) -> u16 {
44 self.stop - self.start + 1
45 }
46
47 pub fn used(&self) -> u16 {
48 self.max_output_adr - self.start
49 }
50}
51
52pub fn section_start(section_name: &str, env: &Env) -> Result<ExprResult, crate::AssemblerError> {
54 Ok(env.get_section_description(section_name)?.start.into())
55}
56
57pub fn section_stop(section_name: &str, env: &Env) -> Result<ExprResult, crate::AssemblerError> {
58 Ok(env.get_section_description(section_name)?.stop.into())
59}
60
61pub fn section_length(section_name: &str, env: &Env) -> Result<ExprResult, crate::AssemblerError> {
63 Ok(env.get_section_description(section_name)?.length().into())
64}
65
66pub fn section_used(section_name: &str, env: &Env) -> Result<ExprResult, crate::AssemblerError> {
68 Ok(env.get_section_description(section_name)?.used().into())
69}
70
71pub fn section_mmr(section_name: &str, env: &Env) -> Result<ExprResult, crate::AssemblerError> {
72 Ok(env.get_section_description(section_name)?.mmr.into())
73}