VICInspection.java

package libsidplay.components.mos656x;

/**
 * Read-only access for tooling. Kept beside VIC so the emulator does not need debug hooks or public mutable fields.
 * Call only on the emulation thread. Cycles use the core's existing one-based numbering; a raster begins at cycle 10.
 */
public final class VICInspection {
    public record State(int raster, int cycle, int videoCounter, int videoCounterBase, int rowCounter,
                        int screenAddress, int characterAddress, int bitmapAddress, int dmaMask,
                        boolean badLine, boolean displayActive, boolean verticalBorder, byte[] registers) {
    }

    private VICInspection() {
    }

    public static int raster(VIC vic) {
        return vic.rasterY;
    }

    public static int cycle(VIC vic) {
        return vic.lineCycle;
    }

    /**
     * First raster in the existing monitor viewport, including its normal borders.
     */
    public static int firstDisplayedRaster(VIC vic) {
        return vic instanceof MOS6569 ? 16 : 40;
    }

    public static int dmaMask(VIC vic) {
        int mask = 0;
        for (int sprite = 0; sprite < vic.sprites.length; sprite++) {
            if (vic.sprites[sprite].isDMA()) {
                mask |= 1 << sprite;
            }
        }
        return mask;
    }

    public static State capture(VIC vic) {
        return new State(vic.rasterY, vic.lineCycle, vic.vc, vic.vcBase, vic.rc, vic.videoMatrixBase,
                vic.charMemBase, vic.bitmapMemBase, dmaMask(vic), vic.isBadLine, vic.isDisplayActive,
                vic.showBorderVertical, vic.registers.clone());
    }
}