// Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
//     EMULATION_ERROR, EXECUTION,
//     MISALIGNED_READ, MISALIGNED_WRITE,
//     ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
//     ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };


import se.sics.mspsim.core.EmulationLogger.WarningType;
package se.sics.mspsim.core;


public class FlashSegment implements Memory {

    private final MSP430Core core;
    private final int memory[];
    private final Flash flash;

    public FlashSegment(MSP430Core core, Flash flash) {
        this.core = core;
        this.memory = core.memory;
        this.flash = flash;
    }

    @Override
    public int read(int address, AccessMode mode, AccessType type) throws EmulationException {
        if (core.isFlashBusy) {
            flash.notifyRead(address);
        }

        int val = memory[address] & 0xff;
        if (mode != AccessMode.BYTE) {
            val |= (memory[address + 1] & 0xff) << 8;
            if ((address & 1) != 0) {
// Path: se/sics/mspsim/core/EmulationLogger.java
// public enum WarningType {
//     EMULATION_ERROR, EXECUTION,
//     MISALIGNED_READ, MISALIGNED_WRITE,
//     ADDRESS_OUT_OF_BOUNDS_READ, ADDRESS_OUT_OF_BOUNDS_WRITE,
//     ILLEGAL_IO_WRITE, VOID_IO_READ, VOID_IO_WRITE
// };


// Path: se/sics/mspsim/core/FlashSegment.java
import se.sics.mspsim.core.EmulationLogger.WarningType;

package se.sics.mspsim.core;


public class FlashSegment implements Memory {

    private final MSP430Core core;
    private final int memory[];
    private final Flash flash;

    public FlashSegment(MSP430Core core, Flash flash) {
        this.core = core;
        this.memory = core.memory;
        this.flash = flash;
    }

    @Override
    public int read(int address, AccessMode mode, AccessType type) throws EmulationException {
        if (core.isFlashBusy) {
            flash.notifyRead(address);
        }

        int val = memory[address] & 0xff;
        if (mode != AccessMode.BYTE) {
            val |= (memory[address + 1] & 0xff) << 8;
            if ((address & 1) != 0) {
                core.printWarning(WarningType.MISALIGNED_READ, address);