// Copyright 2011-2012 Paulo Augusto Peccin. See licence.txt distributed with this file.

package org.javatari.atari.cartridge.formats;

import org.javatari.atari.cartridge.CartridgeFormat;
import org.javatari.atari.cartridge.ROM;

/**
 * Implements generic bank switching using unmasked address access via bus monitoring (outside Cart area)
 */
public abstract class CartridgeBankedByBusMonitoring extends CartridgeBanked {

	protected CartridgeBankedByBusMonitoring(ROM rom, CartridgeFormat format) {
		super(rom, format);
	}

	@Override
	public boolean needsBusMonitoring() {
		return true;
	}

	@Override
	public void monitorBusBeforeRead(int address, byte data) {
		performBankSwitchOnMonitoredAccess(address);
	}

	@Override
	public void monitorBusBeforeWrite(int address, byte data) {
		performBankSwitchOnMonitoredAccess(address);
	}
	
	@Override
	protected void performBankSwitchOnMaskedAddress() {
		// Bank switching is not done within masked address range
		// Its done directly via bus monitoring
	}

	protected abstract void performBankSwitchOnMonitoredAccess(int address);

	
	public static final long serialVersionUID = 1L;

}