c64_assembler/instruction/
mod.rs

1use operation::Operation;
2
3use crate::memory::address_mode::AddressMode;
4use crate::memory::Address;
5use crate::validator::AssemblerResult;
6use crate::Application;
7pub mod operation;
8
9/// Assembly instruction
10///
11/// An instruction is the combination of the operation and the address mode that the
12/// operation should be using.
13#[derive(Debug, Default, Clone, PartialEq)]
14pub struct Instruction {
15    /// Operation of the instruction.
16    pub operation: Operation,
17    /// Address mode of the instruction.
18    pub address_mode: AddressMode,
19    /// Comments for when generating source code.
20    pub comments: Vec<String>,
21}
22
23impl Instruction {
24    /// Total number of bytes the instruction occupies on a 6502.
25    ///
26    /// Application parameter is used to identify if an instruction should use its zeropage variant.
27    pub fn byte_size(&self, application: &Application) -> AssemblerResult<Address> {
28        if let Operation::Raw(bytes) = &self.operation {
29            Ok(bytes.len() as u16)
30        } else if let Operation::Label(_) = &self.operation {
31            Ok(0)
32        } else {
33            self.address_mode.byte_size(application)
34        }
35    }
36}