c64 0.1.0-alpha.0

Driver for the Commodore 64 platform
//! HAL for the Commodore 64 Kernal ROM.

use crate::{
    hal::{AddressSpace, Kernal},
    pac::kernal,
};

/// Type-safe interface to the Kernal ROM.
///
/// This can only be constructed when the memory configuration has the Kernal ROM overlay
/// enabled, making it safe to call Kernal functions.
pub struct KernalRom<'a, LORAM, CHAREN> {
    _asp: &'a AddressSpace<Kernal, LORAM, CHAREN>,
}

impl<'a, LORAM, CHAREN> KernalRom<'a, LORAM, CHAREN> {
    /// Constructs an access API for the Kernal ROM overlay.
    pub fn new(asp: &'a AddressSpace<Kernal, LORAM, CHAREN>) -> Self {
        Self { _asp: asp }
    }

    /// Returns the trigonometry constants in the Kernel ROM.
    pub fn trig_constants(&self) -> &kernal::TrigConstants {
        unsafe { &*kernal::TRIG_CONSTANTS }
    }

    /// Returns the time in jiffies (60ths of a second) since the system was turned on or
    /// reset, or since midnight if [`Self::set_system_clock`] has been called.
    pub fn read_system_clock(&self) -> u32 {
        unsafe { kernal::rdtim() }
    }
}