hg80 1.0.0

Z80 and Z80N CPU core, stepped one clock edge at a time
Documentation
// Portions of this file are derived from the T80 Z80-compatible microprocessor core,
// Copyright (c) 2001-2002 Daniel Wallner, and from the T80N modifications made for the
// ZX Spectrum Next Project, Copyright 2020 Fabio Belavenuto, Victor Trucco, Charlie Ingley,
// Garry Lancaster, ACX. Redistributed under the three-clause BSD licence reproduced in NOTICE.

/// Bit positions within the flag register, and the masks that select them.
///
/// Bits 3 and 5 carry no architectural meaning but are written by most instructions and are
/// readable with `PUSH AF`, so they are named here alongside the documented flags.
pub mod flag {
    /// Carry.
    pub const C: u8 = 0;
    /// Add or subtract, used by `DAA` to tell which operation produced the result.
    pub const N: u8 = 1;
    /// Parity or overflow, depending on the instruction.
    pub const P: u8 = 2;
    /// Undocumented, bit 3.
    pub const X: u8 = 3;
    /// Half carry, the carry out of bit 3.
    pub const H: u8 = 4;
    /// Undocumented, bit 5.
    pub const Y: u8 = 5;
    /// Zero.
    pub const Z: u8 = 6;
    /// Sign, a copy of bit 7 of the result.
    pub const S: u8 = 7;

    /// Mask selecting the carry flag.
    pub const C_MASK: u8 = 1 << C;
    /// Mask selecting the add/subtract flag.
    pub const N_MASK: u8 = 1 << N;
    /// Mask selecting the parity/overflow flag.
    pub const P_MASK: u8 = 1 << P;
    /// Mask selecting undocumented bit 3.
    pub const X_MASK: u8 = 1 << X;
    /// Mask selecting the half-carry flag.
    pub const H_MASK: u8 = 1 << H;
    /// Mask selecting undocumented bit 5.
    pub const Y_MASK: u8 = 1 << Y;
    /// Mask selecting the zero flag.
    pub const Z_MASK: u8 = 1 << Z;
    /// Mask selecting the sign flag.
    pub const S_MASK: u8 = 1 << S;

    /// Mask selecting both undocumented bits, which several instructions copy from a result or
    /// from the accumulator as a group.
    pub const XY_MASK: u8 = X_MASK | Y_MASK;
}