// Path: src/main/java/fi/helsinki/cs/ttk91/TTK91Memory.java
// public interface TTK91Memory {
//     /**
//      * @return the size of the memory.
//      */
//     public int getSize();
// 
//     /**
//      * First usable index is 0, last is getSize()-1
//      *
//      * @param memoryslot memory address where required data is
//      * @return data from requested address
//      */
//     public int getValue(int memoryslot);
// 
//     /**
//      * @return HashMap with symbol name as a key, and Integer as value.
//      *         Integer describes the memory slot where the value is stored.
//      */
//     public HashMap<String, Integer> getSymbolTable();
// 
//     /**
//      * @return whole memory as a dump
//      */
//     public int[] getMemory();
// 
//     /**
//      * @return a code area dump. assumed to be located from
//      *         offset 0 to "codeAreaSize"
//      */
//     public int[] getCodeArea();
// 
//     /**
//      * @return a data area dump. Assumed to be located beginning
//      *         from the end of codeAreaSize to codeAreaSize+dataAreaSize
//      */
//     public int[] getDataArea();
// }


import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import fi.helsinki.cs.ttk91.TTK91Memory;
// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
// Copyright © 2012 various contributors
// This software is released under GNU Lesser General Public License 2.1.
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html

package fi.helsinki.cs.titokone;



// Display class was added by Toni Ruottu 8.4.2012

public class Display extends JPanel implements Runnable {
    static final int fontWidth = 5, fontHeight = 6;
    static final int X = 160, Y = 120;
    static final int MARGIN = 50; //30 minimum real pixel margin on every side
    static final int DEFAULT_START = 0x2000;
    static TTK91Memory mem;
    boolean updates = false;
    //BufferedImage backBuffer;
    BufferedImage compatible;
    protected int baseAddress = DEFAULT_START;
    protected int lastX = 0;
    protected int lastY = 0;
    protected int left = 0; //screen corner in real pixels
    protected int top = 0;
    protected int xscale, yscale; //integer scaling factors
    protected Color margin = Color.GRAY;

    protected int mode = 0;
    /* Display methods */

    public Display() {
    }

    protected void checkBuffers() {
        if (lastX != getWidth() || lastY != getHeight()) {
            Graphics2D g = (Graphics2D) getGraphics();
            GraphicsConfiguration gc = g.getDeviceConfiguration();
            lastX = getWidth();
            lastY = getHeight();
            compatible = gc.createCompatibleImage(lastX, lastY);
            xscale = roundUp(((double) (lastX - 2 * MARGIN)) / X);
            yscale = roundUp(((double) (lastY - 2 * MARGIN)) / Y);
            left = (lastX - xscale * X) / 2;
            top = (lastY - yscale * Y) / 2;

            clearBuffer();
        }
    }

// Path: src/main/java/fi/helsinki/cs/ttk91/TTK91Memory.java
// public interface TTK91Memory {
//     /**
//      * @return the size of the memory.
//      */
//     public int getSize();
// 
//     /**
//      * First usable index is 0, last is getSize()-1
//      *
//      * @param memoryslot memory address where required data is
//      * @return data from requested address
//      */
//     public int getValue(int memoryslot);
// 
//     /**
//      * @return HashMap with symbol name as a key, and Integer as value.
//      *         Integer describes the memory slot where the value is stored.
//      */
//     public HashMap<String, Integer> getSymbolTable();
// 
//     /**
//      * @return whole memory as a dump
//      */
//     public int[] getMemory();
// 
//     /**
//      * @return a code area dump. assumed to be located from
//      *         offset 0 to "codeAreaSize"
//      */
//     public int[] getCodeArea();
// 
//     /**
//      * @return a data area dump. Assumed to be located beginning
//      *         from the end of codeAreaSize to codeAreaSize+dataAreaSize
//      */
//     public int[] getDataArea();
// }


// Path: src/main/java/fi/helsinki/cs/titokone/Display.java
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import fi.helsinki.cs.ttk91.TTK91Memory;

// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
// Copyright © 2012 various contributors
// This software is released under GNU Lesser General Public License 2.1.
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html

package fi.helsinki.cs.titokone;



// Display class was added by Toni Ruottu 8.4.2012

public class Display extends JPanel implements Runnable {
    static final int fontWidth = 5, fontHeight = 6;
    static final int X = 160, Y = 120;
    static final int MARGIN = 50; //30 minimum real pixel margin on every side
    static final int DEFAULT_START = 0x2000;
    static TTK91Memory mem;
    boolean updates = false;
    //BufferedImage backBuffer;
    BufferedImage compatible;
    protected int baseAddress = DEFAULT_START;
    protected int lastX = 0;
    protected int lastY = 0;
    protected int left = 0; //screen corner in real pixels
    protected int top = 0;
    protected int xscale, yscale; //integer scaling factors
    protected Color margin = Color.GRAY;

    protected int mode = 0;
    /* Display methods */

    public Display() {
    }

    protected void checkBuffers() {
        if (lastX != getWidth() || lastY != getHeight()) {
            Graphics2D g = (Graphics2D) getGraphics();
            GraphicsConfiguration gc = g.getDeviceConfiguration();
            lastX = getWidth();
            lastY = getHeight();
            compatible = gc.createCompatibleImage(lastX, lastY);
            xscale = roundUp(((double) (lastX - 2 * MARGIN)) / X);
            yscale = roundUp(((double) (lastY - 2 * MARGIN)) / Y);
            left = (lastX - xscale * X) / 2;
            top = (lastY - yscale * Y) / 2;

            clearBuffer();
        }
    }

    public void setMem(TTK91Memory mem) {