looklook 0.7.0

Descriptive signal synthesiser.
// Copyright 2026 Gabriel Bjørnager Jensen.
//
// This file is part of LOOKLOOK.
//
// LOOKLOOK is free software: you can redistribute it and/or modify it under the
// terms of the GNU Affero General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later ver-
// sion.
//
// LOOKLOOK is distributed in the hope that it will be useful, but WITHOUT ANY WAR-
// RANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License along
// with LOOKLOOK. If not, see <https://www.gnu.org/licenses/>.

//! The [`Vm`] type.

mod exec;
mod read_image;
mod render_signal;

use crate::vm::{Int, Mem, Regs};

/// A MC68EC020 virtual machine.
#[derive(Debug)]
pub struct Vm {
	/// The registers.
	regs: Regs,

	/// The memory.
	mem: Mem,
}

impl Vm {
	/// The entry address.
	pub const ENTRY_ADDR: Int<4> = Int::from_u32(0x100);

	/// Constructs a new emulator.
	#[expect(clippy::new_without_default)]
	#[inline]
	#[must_use]
	pub fn new() -> Self {
		let mem = Mem::with_capacity(Mem::DEFAULT_SIZE);
		Self { regs: Default::default(), mem }
	}

	/// Borrows the registers.
	#[inline(always)]
	#[must_use]
	pub fn regs(&self) -> &Regs {
		&self.regs
	}

	/// Mutably borrows the registers.
	#[inline(always)]
	#[must_use]
	pub fn regs_mut(&mut self) -> &mut Regs {
		&mut self.regs
	}

	/// Borrows memory.
	#[inline(always)]
	#[must_use]
	pub fn mem(&self) -> &Mem {
		&self.mem
	}

	/// Mutably borrows memory.
	#[inline(always)]
	#[must_use]
	pub fn mem_mut(&mut self) -> &mut Mem {
		&mut self.mem
	}

	/// Reboots the virtual machine.
	#[inline]
	pub fn reboot(&mut self) {
		*self.regs.pc_mut() = Self::ENTRY_ADDR;
	}
}