// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie // // SPDX-License-Identifier: MIT //! What a stopped machine is, for both front ends. //! //! `session8.zig` and `session16.zig` are separate modules and neither may //! import the other, so the vocabulary they share has to live in the library. //! This is that vocabulary: what a processor is doing between redraws, and why //! it is not running when it is not. //! //! The two differ in the width of an address and in nothing else, which is why //! `Stop` is a function of that width rather than two near-identical unions. //! An eight-bit machine's is `Stop(u16)`; a IIgs's is `Stop(u24)`, because a //! 65816 fetches through a bank register and an address without its bank does //! not say where anything is. /// What the processor is doing between redraws. pub const State = enum { /// Running on its own, paced by the clock. running, /// Stopped, because an instruction ended in a way that leaves nowhere to /// go. Only a reset starts it again. halted, /// Running one instruction each time the user asks for one. single_step, pub fn name(self: State) []const u8 { return switch (self) { .running => "RUNNING", .halted => "HALTED", .single_step => "STEP", }; } }; /// Why the processor is not executing, over addresses of the given width. /// /// A jam and a BRK are opposites and were worth telling apart: one is the /// processor giving up, the other is it doing exactly what it was told. pub fn Stop(comptime Address: type) type { return union(enum) { /// A JAM opcode, or a 65816's STP. The processor is wedged and only a /// reset gets it back. Carries where it happened, because by the time /// this is known the program counter has already stepped past the /// opcode and the screen would otherwise point at the wrong byte. jam: struct { address: Address, opcode: u8 }, /// A BRK. Nothing is wrong: the processor pushed its return address /// and flags and vectored, and is sitting in the handler. The debugger /// stops anyway, since stopping is what a BRK is usually for, but the /// processor can carry straight on. brk: struct { address: Address, vector: Address }, }; }