OscilloscopeUtil.java

package libsidutils.oscilloscope;

import libsidplay.C64;
import libsidplay.common.Event;
import libsidplay.common.SIDEmu;

/**
 * A view subscription, not a sampler. All subscriptions share C64's service.
 */
public abstract class OscilloscopeUtil {
    private final C64 c64;
    private volatile boolean requested;

    protected OscilloscopeUtil(C64 c64) {
        this.c64 = c64;
    }

    boolean isRequested() {
        return requested;
    }

    public void start() {
        requested = true;
        c64.getEventScheduler().scheduleThreadSafe(Event.of("Subscribe Oscilloscope",
                event -> c64.getOscilloscope().subscribe(this)));
    }

    public void stop() {
        requested = false;
        c64.getEventScheduler().scheduleThreadSafe(Event.of("Unsubscribe Oscilloscope",
                event -> c64.getOscilloscope().unsubscribe(this)));
    }

    protected int getFastForwardBitMask() {
        return 0;
    }

    final boolean acceptsFrame(int sequence) {
        int mask = getFastForwardBitMask();
        return (sequence & mask) == mask;
    }

    protected boolean isOplEnabled() {
        return true;
    }

    protected abstract void updateGauges(long absTime, Integer chipNum, SIDEmu sid);

    protected void updateFrame(long time, OscilloscopeService source, int generation, int sequence) {
    }

    protected void updateOplGauges(long absTime, OplOscilloscope opl, int type, int generation, int sequence) {
    }

    protected void updateSources(int oplType, int generation) {
    }
}