feo3boy_opcodes/
lib.rs

1//! Defines the opcodes for the `feo3boy` gameboy.
2//!
3//! This library is intended to provide the basic opcodes of the gbz80 CPU. Opcodes are
4//! defined in terms of a microcode which allows instructions to be broken into smaller
5//! steps.
6//!
7//! The [`microcode`] module supplies the [`Microcode`][microcode::Microcode] type, which
8//! defines the steps that opcodes can be broken down into.
9//!
10//! The [`opcode`] module supplies [`Opcode`][opcode::Opcode] and
11//! [`CBOpcode`][opcode::CBOpcode] which define the actual instructions the GameBoy CPU
12//! can execute.
13
14pub mod compiler;
15pub mod gbz80types;
16pub mod microcode;
17pub mod opcode;
18
19/// Helper function for getting the size of an array as a constant by reference. This is
20/// used to implement `count_repetition`.
21#[doc(hidden)]
22pub const fn ___array_size_helper<T, const N: usize>(_: &[T; N]) -> usize {
23    N
24}
25
26/// Counts the number of repetitions in a macro invocation. Produces a constant
27/// expression.
28///
29/// Usage:
30/// ```
31/// # use feo3boy_opcodes::count_repetition;
32/// count_repetition!(a, 3, (), {}, 4, foo);
33/// ```
34#[macro_export]
35macro_rules! count_repetition {
36    () => { 0 };
37    ($($rep:tt),* $(,)?) => {
38        $crate::___array_size_helper(&[
39            $(count_repetition!(@__replace $rep)),*
40        ])
41    };
42
43    (@__replace $v:tt) => { () };
44}