VICConfiguration.java

package libsidplay.common;

import java.util.Objects;

/**
 * Immutable VIC configuration targets for the existing PAL and NTSC slots.
 * <p>
 * C64 uses each selected identity for its implemented timing rules, including MOS8562 D021 grey dots.
 * This value does not select a palette or claim complete revision-specific emulation.
 * <p>
 * The two slots allow the existing clock resolution to choose PAL or NTSC
 * without turning a PAL override into an NTSC chip or vice versa.
 */
public final class VICConfiguration {

    private final VICChipModel palModel;
    private final VICChipModel ntscModel;

    public VICConfiguration(final VICChipModel palModel, final VICChipModel ntscModel) {
        this.palModel = requireClock(palModel, CPUClock.PAL);
        this.ntscModel = requireClock(ntscModel, CPUClock.NTSC);
    }

    private static VICChipModel requireClock(final VICChipModel model, final CPUClock clock) {
        Objects.requireNonNull(model, "model");
        if (model.getClock() != clock) {
            throw new IllegalArgumentException(model + " is not a " + clock + " VIC target");
        }
        return model;
    }

    public VICChipModel getPalModel() {
        return palModel;
    }

    public VICChipModel getNtscModel() {
        return ntscModel;
    }

    /**
     * Return the target for an already resolved PAL or NTSC clock. Rejects
     * AUTO and any other unresolved/unsupported value, rather than silently
     * treating it as PAL.
     */
    public VICChipModel getModel(final CPUClock resolvedClock) {
        Objects.requireNonNull(resolvedClock, "resolvedClock");
        if (resolvedClock == CPUClock.PAL) {
            return palModel;
        }
        if (resolvedClock == CPUClock.NTSC) {
            return ntscModel;
        }
        throw new IllegalArgumentException("Resolve PAL/NTSC first: " + resolvedClock);
    }

    /** Return a new configuration; this instance is never modified. */
    public VICConfiguration withPalModel(final VICChipModel model) {
        return new VICConfiguration(model, ntscModel);
    }

    /** Return a new configuration; this instance is never modified. */
    public VICConfiguration withNtscModel(final VICChipModel model) {
        return new VICConfiguration(palModel, model);
    }
}