package ckelling.baukasten;

import java.awt.*;
import java.lang.*;
import java.util.*;


/**
 *	SimpleMemory.java
 *
 *	Simuliert ein RAM und zeichnet dieses.
 *	Speicherzellen sind editierbar, falls nicht gesperrt.
 *
 *	@author		Carsten Kelling
 *	@version	0.7.7, 12.12.96
 */
public abstract class SimpleMemory extends RechnerKomponente
{
    public final static int    OUTPUTWIDTH     = 8;
    public final static int    OUTPUTHEIGHT    = 8;
    public final static String CELLDEFAULT     = "1800  ";
	public String	    label;

	public    int       startX;
	public    int       startY;
	protected int       memorySize;
	public    int       bitWidth;
	public    long		zwei_hoch_bitWidth;
	protected int       speicher[];
	public    String    displaySpeicher[];

	protected int       address;
	private   int		savedAddress;
	protected boolean   hasBeenActivated;

	protected boolean	showOpcodes = false;
	public static boolean	technicalOpcodes = false;

	protected boolean   blinker;
	protected int 	    activatedX;
	protected int 	    activatedY;
	protected String	activatedString;

	protected Image     imageCache;

	public    Rechner   parent;


	public SimpleMemory()
	{
	}

	public SimpleMemory(String str, int x1, int y1, int memsize, int bitwidth, Rechner par)
	{
		System.out.println("Init SimpleMemory - Anfang");

		parent = par;

		label = str;
		startX = x1; startY = y1;

		memorySize = memsize;
		bitWidth = bitwidth;
		zwei_hoch_bitWidth = (long) Math.pow(2, (double) bitWidth);
		speicher = new int[memorySize];
		displaySpeicher = new String[memorySize];

		activated = false;
		hasBeenActivated = false;

		blinker = false;
		activatedX = activatedY = -1;
		activatedString = new String("");

		imageCache = null;

		initRam();

		/*******************************
		address = 24; setValue(-196609);
		address = 25; setValue(-196608);
		address = 26; setValue(-196607);
		address = 27; setValue(-131073);
		address = 28; setValue(-131072);
		address = 29; setValue(-131071);
		address = 30; setValue(-65537);
		address = 31; setValue(-65536);
		address = 32; setValue(-65535);
		address = 33; setValue(-32769);
		address = 34; setValue(-32768);
		address = 35; setValue(-32767);
		address = 36; setValue(-1);
		address = 37; setValue(-0);
		address = 38; setValue(0);
		address = 39; setValue(1);
		address = 40; setValue(2);
		address = 41; setValue(32767);
		address = 42; setValue(32768);
		address = 43; setValue(32769);
		address = 44; setValue(65535);
		address = 45; setValue(65536);
		address = 46; setValue(65537);
		********************************/

		address = 0;
		savedAddress = address;

		System.out.println("Init SimpleMemory - Ende");
	}


	public void initRam()
	{
		initRam("");
	}

	public void initRam(String memoryContents)
	{
		int i;
		int defaultValue = 0xff;
		if (memoryContents.equalsIgnoreCase("zero"))
		    defaultValue = 0;

		for (i = 0; i < memorySize; i++)
			speicher[i] = defaultValue;

		if (memoryContents.equalsIgnoreCase("vnr_loadabs"))
		{
			for (i = 0; i < memorySize; i++)
				speicher[i] = (Rechner.LDA_ABSOL * 256) + (int)(Math.random() * 256);
		}
		else if (memoryContents.equalsIgnoreCase("vnr_loadstore"))
		{
			if (memorySize-1 < 0x2f)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
				speicher[0x00] = (Rechner.LDA_ABSOL * 256)		+ 0x04;  // Code
				speicher[0x01] = (Rechner.LDA_MEM * 256)		+ 0x18;
				speicher[0x02] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x10;
				speicher[0x03] = (Rechner.STA_ABSOL * 256)		+ 0x1a;
				speicher[0x04] = (Rechner.STA_MEM * 256)		+ 0x11;
				speicher[0x05] = (Rechner.NOP * 256);
				speicher[0x06] = (Rechner.NOP * 256);
				speicher[0x07] = (Rechner.NOP * 256);

				speicher[0x08] = (Rechner.LDA_ABSOL * 256)		+ 0x27;
				speicher[0x09] = (Rechner.LDA_MEM * 256)		+ 0x27;
				speicher[0x0a] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x27;
				speicher[0x0b] = (Rechner.STA_ABSOL * 256)		+ 0x27;
				speicher[0x0c] = (Rechner.STA_MEM * 256)		+ 0x27;
				speicher[0x0d] = (Rechner.NOP * 256);
				speicher[0x0e] = (Rechner.NOP * 256);
				speicher[0x0f] = (Rechner.NOP * 256);

				speicher[0x10] = 0x19;  // Zeiger
				speicher[0x11] = 0x1b;

				speicher[0x18] = 0x06;  // Daten
				speicher[0x19] = 0x09;

				speicher[0x27] = 0x2f;
				speicher[0x2f] = 0x33;
			}
		}
		else if (memoryContents.equalsIgnoreCase("vnr_calculate"))
		{
			if (memorySize-1 < 0x34)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
				speicher[0x00] = (Rechner.LDA_ABSOL * 256)	+ 0x74;  // Code
				speicher[0x01] = (Rechner.ADD_MEM * 256)	+ 0x30;
				speicher[0x02] = (Rechner.STA_ABSOL * 256)	+ 0x38;
				speicher[0x03] = (Rechner.LDA_MEM * 256)	+ 0x31;
				speicher[0x04] = (Rechner.MUL_MEM * 256)	+ 0x32;
				speicher[0x05] = (Rechner.STA_MEM * 256)	+ 0x34;
				speicher[0x06] = (Rechner.NOP * 256);
				speicher[0x07] = (Rechner.NOP * 256);

				speicher[0x08] = (Rechner.LDA_MEM * 256) 	+ 0x12;
				speicher[0x09] = (Rechner.ADD_MEM * 256)	+ 0x13;
				speicher[0x0a] = (Rechner.STA_ABSOL * 256)	+ 0x21;
				speicher[0x0b] = (Rechner.LDA_MEM * 256)	+ 0x10;
				speicher[0x0c] = (Rechner.ADD_MEM * 256)	+ 0x11;
				speicher[0x0d] = (Rechner.DIV_MEM * 256)	+ 0x21;
				speicher[0x0e] = (Rechner.MUL_MEM * 256)	+ 0x14;
				speicher[0x0f] = (Rechner.NOP * 256);

				speicher[0x10] = 30;  // Daten, dezimal!
				speicher[0x11] = 40;
				speicher[0x12] = 5;
				speicher[0x13] = 6;
				speicher[0x14] = 7;

				speicher[0x30] = 0xfe;
				speicher[0x31] = 0x07;
				speicher[0x32] = 0x05;

				speicher[0x34] = 0x3a;  // Zeiger
			}
		}
		else if (memoryContents.equalsIgnoreCase("vnr_jump"))
		{
			if (memorySize-1 < 0x37)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
				speicher[0x00] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x28;
				speicher[0x01] = (Rechner.STA_MEM * 256)		+ 0x29;
				speicher[0x02] = (Rechner.LDA_MEM * 256)		+ 0x28;
				speicher[0x03] = (Rechner.INC * 256);
				speicher[0x04] = (Rechner.STA_ABSOL * 256)		+ 0x28;
				speicher[0x05] = (Rechner.LDA_MEM * 256)		+ 0x29;
				speicher[0x06] = (Rechner.INC * 256);
				speicher[0x07] = (Rechner.STA_ABSOL * 256)		+ 0x29;
				speicher[0x08] = (Rechner.JMP_ABSOL * 256)		+ 0;

				speicher[0x10] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x28;
				speicher[0x11] = (Rechner.STA_MEM * 256)		+ 0x29;
				speicher[0x12] = (Rechner.LDA_MEM * 256)		+ 0x28;
				speicher[0x13] = (Rechner.INC * 256);
				speicher[0x14] = (Rechner.STA_ABSOL * 256)		+ 0x28;
				speicher[0x15] = (Rechner.LDA_MEM * 256)		+ 0x29;
				speicher[0x16] = (Rechner.INC * 256);
				speicher[0x17] = (Rechner.STA_ABSOL * 256)		+ 0x29;
				speicher[0x18] = (Rechner.SUB_MEM * 256)		+ 0x2c;
				speicher[0x19] = (Rechner.JLE_ABSOL * 256)		+ 0x10;

				speicher[0x1a] = (Rechner.LDA_ABSOL * 256)		+ 0x30;
				speicher[0x1b] = (Rechner.STA_ABSOL * 256)		+ 0x28;
				speicher[0x1c] = (Rechner.LDA_ABSOL * 256)		+ 0x38;
				speicher[0x1d] = (Rechner.STA_ABSOL * 256)		+ 0x29;
				speicher[0x1e] = (Rechner.IN_MEM * 256)			+ 0x30;
				speicher[0x1f] = (Rechner.IN_MEM * 256)			+ 0x31;
				speicher[0x20] = (Rechner.IN_MEM * 256)			+ 0x32;
				speicher[0x21] = (Rechner.IN_MEM * 256)			+ 0x33;
				speicher[0x22] = (Rechner.IN_MEM * 256)			+ 0x34;
				speicher[0x23] = (Rechner.IN_MEM * 256)			+ 0x35;
				speicher[0x24] = (Rechner.IN_MEM * 256)			+ 0x36;
				speicher[0x25] = (Rechner.IN_MEM * 256)			+ 0x37;
				speicher[0x26] = (Rechner.JMP_ABSOL * 256)		+ 0x10;

				speicher[0x28]= 0x30;
				speicher[0x29] = 0x38;
				speicher[0x2c] = 0x3f;

				for (i = 0x30; i <= 0x37; i++)
					speicher[i] = (int) (Math.random() * zwei_hoch_bitWidth);
			}
		}
		else if (memoryContents.equalsIgnoreCase("allcommands"))
		{
			if (memorySize-1 < 0x66)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
	 			speicher[0x00] = (Rechner.NOP * 256);
				speicher[0x01] = (Rechner.LDA_ABSOL * 256)		+ 0x38;
				speicher[0x02] = (Rechner.LDA_MEM * 256)		+ 0x38;
				speicher[0x03] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x38;
				speicher[0x04] = (Rechner.STA_ABSOL * 256)		+ 0x3b;
				speicher[0x05] = (Rechner.STA_MEM * 256)		+ 0x3a;
				speicher[0x06] = (Rechner.LDA_ABSOL * 256)		+ 0x27;
				speicher[0x07] = (Rechner.NOP * 256);
				speicher[0x08] = (Rechner.ADD_MEM * 256)		+ 0x3c;
				speicher[0x09] = (Rechner.SUB_MEM * 256)		+ 0x3d;
				speicher[0x0a] = (Rechner.MUL_MEM * 256)		+ 0x3e;
				speicher[0x0b] = (Rechner.DIV_MEM * 256)		+ 0x3f;
				speicher[0x0c] = (Rechner.INC * 256);
				speicher[0x0d] = (Rechner.DEC * 256);
				speicher[0x0e] = (Rechner.SHL * 256)			+ 0x01;
				speicher[0x0f] = (Rechner.SHR * 256)			+ 0x01;


				speicher[0x10] = (Rechner.SUB_MEM * 256)		+ 0x39;
				speicher[0x11] = (Rechner.JNZ_ABSOL * 256)		+ 0x00;
				speicher[0x12] = (Rechner.JZE_ABSOL * 256)		+ 0x14;
				speicher[0x13] = (Rechner.JMP_ABSOL * 256)		+ 0x00;
				speicher[0x14] = (Rechner.JLE_ABSOL * 256)		+ 0x18;

				speicher[0x18] = (Rechner.LDA_ABSOL * 256)		+ 0;
				speicher[0x19] = (Rechner.DEC * 256);
				speicher[0x1a] = (Rechner.JZE_ABSOL * 256)		+ 0x00;
				speicher[0x1b] = (Rechner.JNZ_ABSOL * 256)		+ 0x1d;
				speicher[0x1c] = (Rechner.JMP_ABSOL * 256)		+ 0x00;
				speicher[0x1d] = (Rechner.JLE_ABSOL * 256)		+ 0x20;
				speicher[0x1e] = (Rechner.JMP_ABSOL * 256)		+ 0x00;

				speicher[0x20] = (Rechner.LDA_ABSOL * 256)		+ 0x27;
				speicher[0x21] = (Rechner.INC * 256);
				speicher[0x22] = (Rechner.JZE_ABSOL * 256)		+ 0x00;
				speicher[0x23] = (Rechner.JNZ_ABSOL * 256)		+ 0x25;
				speicher[0x24] = (Rechner.JMP_ABSOL * 256)		+ 0x00;
				speicher[0x25] = (Rechner.JLE_ABSOL * 256)		+ 0x00;
				speicher[0x26] = (Rechner.JMP_ABSOL * 256)		+ 0x30;


				speicher[0x30] = (Rechner.IN_MEM * 256)			+ 0x38;
				speicher[0x31] = (Rechner.OUT_MEM * 256)		+ 0x39;
				speicher[0x32] = (Rechner.JMP_ABSOL * 256)		+ 0x40;

				speicher[0x38] = 0x39;
				speicher[0x39] = 0x69;
				speicher[0x3a] = 0x38;
				speicher[0x3c] = 0x0a;
				speicher[0x3d] = 0x1c;
				speicher[0x3e] = 0x0f;
				speicher[0x3f] = 0x03;


				speicher[0x40] = (Rechner.LDA_ABSOL * 256)		+ 0x69;
				speicher[0x41] = (Rechner.SUB_MEM * 256)		+ 0x39;
				speicher[0x42] = (Rechner.JNZ_MEM * 256)		+ 0x60;
				speicher[0x43] = (Rechner.JZE_MEM * 256)		+ 0x61;
				speicher[0x44] = (Rechner.JMP_MEM * 256)		+ 0x60;
				speicher[0x45] = (Rechner.JLE_MEM * 256)		+ 0x62;
				speicher[0x46] = (Rechner.JMP_MEM * 256)		+ 0x60;

				speicher[0x48] = (Rechner.LDA_ABSOL * 256)		+ 0;
				speicher[0x49] = (Rechner.DEC * 256);
				speicher[0x4a] = (Rechner.JZE_MEM * 256)		+ 0x60;
				speicher[0x4b] = (Rechner.JNZ_MEM * 256)		+ 0x63;
				speicher[0x4c] = (Rechner.JMP_MEM * 256)		+ 0x60;
				speicher[0x4d] = (Rechner.JLE_MEM * 256)		+ 0x64;
				speicher[0x4e] = (Rechner.JMP_MEM * 256)		+ 0x60;

				speicher[0x50] = (Rechner.LDA_ABSOL * 256)		+ 0x27;
				speicher[0x51] = (Rechner.INC * 256);
				speicher[0x52] = (Rechner.JZE_MEM * 256)		+ 0x60;
				speicher[0x53] = (Rechner.JNZ_MEM * 256)		+ 0x65;
				speicher[0x54] = (Rechner.JMP_MEM * 256)		+ 0x60;
				speicher[0x55] = (Rechner.JLE_MEM * 256)		+ 0x60;
				speicher[0x56] = (Rechner.JMP_MEM * 256)		+ 0x66;

				speicher[0x58] = (Rechner.AND_MEM * 256)		+ 0x3c;
				speicher[0x59] = (Rechner.OR_MEM * 256)			+ 0x3d;
				speicher[0x5a] = (Rechner.XOR_MEM * 256)		+ 0x3e;
				speicher[0x5b] = (Rechner.NOT * 256);
				speicher[0x5c] = (Rechner.JMP_MEM * 256)		+ 0x60;

				speicher[0x60] = 0x00;
				speicher[0x61] = 0x45;
				speicher[0x62] = 0x48;
				speicher[0x63] = 0x4d;
				speicher[0x64] = 0x50;
				speicher[0x65] = 0x55;
				speicher[0x66] = 0x58;
			}
		}
		else if (memoryContents.equalsIgnoreCase("loadstore"))
		{
			for (i = 0; i < memorySize; i++)
			{
				double r = Math.random();
				if (r <= 0.2)
					speicher[i] = (Rechner.LDA_MEM * 256)		+ i + 3; // LDA_MEM i+3
				else if (r <= 0.4)
					speicher[i] = (Rechner.LDA_MEM_INDIR * 256)	+ 2*i + 1; // LDA_MEM_INDIR 2*i+1
				else if (r <= 0.6)
					speicher[i] = (Rechner.LDA_ABSOL * 256)		+ i; // LDA_ABSOL i
				else if (r <= 0.8)
					speicher[i] = (Rechner.STA_ABSOL * 256)		+ i + 32; // STA_ABSOL i+32
				else
					speicher[i] = (Rechner.STA_MEM * 256)		+ i + 2; // STA_MEM i+2
			}
		}

		else if (memoryContents.equalsIgnoreCase("loadstore2"))
		{
			if (memorySize-1 < 32)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
				for (i = 0; i < 32; i++)
				{
					if (i < 8)
						speicher[i] = (Rechner.LDA_ABSOL * 256)	+ i + 1; // LDA_ABSOL i+1
					else if (i < 16)
					{
						if (i%2 == 0)
							speicher[i] = (Rechner.LDA_MEM * 256) + i + 8; // LDA_MEM aus naechster Zeile
						else
							speicher[i] = (Rechner.STA_ABSOL * 256) + i + 15; // STA_ABSOL in uebernaechste Zeile
					}
					else if (i < 24)
						speicher[i] = 0x1111 * (i-23); // Werte $1111, $2222, $3333 bis $8888
				}
			}
		}

		else if (memoryContents.equalsIgnoreCase("power"))
		/// Program: calculate a^b
		/// a is found at address $10, b at $11 and the result will be written to $12
		{
			if (memorySize-1 < 0x11)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
				speicher[0] = (Rechner.LDA_ABSOL * 256)	+ 0x01;	// LDA #1
				speicher[1] = (Rechner.STA_ABSOL * 256)	+ 0x12;	// STA #12	 result = 1
				speicher[2] = (Rechner.LDA_MEM * 256)	+ 0x10;	// LDA 10	[start of loop]
				speicher[3] = (Rechner.MUL_MEM * 256)	+ 0x12;	// MUL 12
				speicher[4] = (Rechner.STA_ABSOL * 256)	+ 0x12;	// STA #12	 result = result * a
				speicher[5] = (Rechner.LDA_MEM * 256)	+ 0x11;	// LDA 11
				speicher[6] = (Rechner.DEC * 256);				// DEC
				speicher[7] = (Rechner.STA_ABSOL * 256)	+ 0x11;	// STA #11	 b = b - 1
				speicher[8] = (Rechner.JNZ_ABSOL * 256)	+ 0x02;	// JNZ #02	if (b != 0) goto [start of loop]
				speicher[9] = (Rechner.NOP * 256);
				speicher[0x0a] = (Rechner.NOP * 256);
				speicher[0x0b] = (Rechner.NOP * 256);
				speicher[0x0c] = (Rechner.NOP * 256);
				speicher[0x0d] = (Rechner.NOP * 256);
				speicher[0x0e] = (Rechner.NOP * 256);
				speicher[0x0f] = (Rechner.JMP_ABSOL * 256) + 0;	// JMP #0

				speicher[0x10] = 2;
				speicher[0x11] = 10;
			}
		}

		else if (memoryContents.equalsIgnoreCase("cachetest"))
		/// Program: Test the caching of memory reads
		/// Fits in cache of 8 bytes
		{
			for (i = 0; i < memorySize; i++)
				speicher[i] = i*257;

			speicher[0]    = (Rechner.LDA_MEM * 256)	+ 0x27;	// LDA 27
			speicher[1]    = (Rechner.INC * 256);			    // INC
			speicher[2]    = (Rechner.JMP_ABSOL * 256)	+ 0x33;	// JMP #33
			speicher[0x33] = (Rechner.STA_ABSOL * 256)	+ 0x27;	// STA #27
			speicher[0x34] = (Rechner.STA_MEM * 256)	+ 0x27;	// STA 27
			speicher[0x35] = (Rechner.JMP_ABSOL * 256)	+ 0;	// JMP #0

			speicher[0x27] = 0x0B;
		}

		else if (memoryContents.equalsIgnoreCase("cachetest2"))
		/// Program: Test the caching of memory reads
		/// Fits in cache of 8 bytes
		{
			for (i = 0; i < memorySize; i++)
				speicher[i] = i*257;

			speicher[0]    = (Rechner.LDA_ABSOL * 256)	+ 0x10;	// LDA #10
			speicher[1]    = (Rechner.LDA_ABSOL * 256)	+ 0x11;	// LDA #11
			speicher[2]    = (Rechner.LDA_ABSOL * 256)	+ 0x12;	// LDA #12
			speicher[3]    = (Rechner.LDA_ABSOL * 256)	+ 0x13;	// LDA #13
			speicher[4]    = (Rechner.LDA_ABSOL * 256)	+ 0x14;	// LDA #14
			speicher[5]    = (Rechner.JMP_ABSOL * 256)	+ 0;	// JMP #0
		}

		else if (memoryContents.equalsIgnoreCase("replacetest"))
		/// Program: Show difference of "random" and "least recently used" replacement in cache
		/// Use with fully-associative cache of 8 bytes
		{
			if (memorySize-1 < 0x31)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
				for (i = 0; i < memorySize; i++)
					speicher[i] = defaultValue;

				speicher[0x30] = 0x0027;  //         Imagine these are important variables
				speicher[0x31] = 0x0031;

				speicher[0x00] = (Rechner.LDA_MEM * 256)	+ 0x30;  // LDA 30
				speicher[0x01] = (Rechner.INC * 256);  				 // INC
				speicher[0x02] = (Rechner.STA_ABSOL * 256)	+ 0x30;  // STA #30
				speicher[0x03] = (Rechner.LDA_MEM * 256)	+ 0x31;  // LDA 31
				speicher[0x04] = (Rechner.INC * 256);  				 // INC
				speicher[0x05] = (Rechner.STA_ABSOL * 256)	+ 0x31;  // STA #31
				speicher[0x06] = (Rechner.JMP_ABSOL * 256)	+ 0x08;  // JMP #8

				speicher[0x08] = (Rechner.LDA_MEM * 256)	+ 0x30;  // LDA 30
				speicher[0x09] = (Rechner.DEC * 256);  				 // DEC
				speicher[0x0A] = (Rechner.STA_ABSOL * 256)	+ 0x30;  // STA #30
				speicher[0x0B] = (Rechner.LDA_MEM * 256)	+ 0x31;  // LDA 31
				speicher[0x0C] = (Rechner.DEC * 256);  				 // DEC
				speicher[0x0D] = (Rechner.STA_ABSOL * 256)	+ 0x31;  // STA #31
				speicher[0x0E] = (Rechner.JMP_ABSOL * 256)	+ 0x10;  // JMP #10

				speicher[0x10] = (Rechner.LDA_MEM * 256)	+ 0x30;  // LDA 30
				speicher[0x11] = (Rechner.SHL * 256)		+ 0x01;  // SHL #1
				speicher[0x12] = (Rechner.STA_ABSOL * 256)	+ 0x30;  // STA #30
				speicher[0x13] = (Rechner.LDA_MEM * 256)	+ 0x31;  // LDA 31
				speicher[0x14] = (Rechner.SHL * 256) 		+ 0x01;  // SHL #1
				speicher[0x15] = (Rechner.STA_ABSOL * 256)	+ 0x31;  // STA #31
				speicher[0x16] = (Rechner.JMP_ABSOL * 256)	+ 0x18;  // JMP #18

				speicher[0x18] = (Rechner.LDA_MEM * 256)	+ 0x30;  // LDA 30
				speicher[0x19] = (Rechner.SHR * 256)		+ 0x01;  // SHR #1
				speicher[0x1A] = (Rechner.STA_ABSOL * 256)	+ 0x30;  // STA #30
				speicher[0x1B] = (Rechner.LDA_MEM * 256)	+ 0x31;  // LDA 31
				speicher[0x1C] = (Rechner.SHR * 256)		+ 0x01;  // SHR #1
				speicher[0x1D] = (Rechner.STA_ABSOL * 256)	+ 0x31;  // STA #31
				speicher[0x1E] = (Rechner.JMP_ABSOL * 256)	+ 0x00;  // JMP #0
			}
		}
		else if ( memoryContents.equalsIgnoreCase("bubblesort") || memoryContents.equalsIgnoreCase("bubblesort_s"))
		/// Program: Bubble Sort of array at $38 to $3f
		/// Address of begin of array must be at $30, address of end at $31
		{
			if (memorySize-1 < 0x3f)
				Rechner.out("Dieses Programm paßt nicht in den Speicher: " + memoryContents);
			else
			{
				speicher[0x00] = (Rechner.LDA_MEM * 256)		+ 0x30;
				speicher[0x01] = (Rechner.STA_ABSOL * 256)		+ 0x21;  // i = 38
				speicher[0x02] = (Rechner.LDA_MEM * 256)		+ 0x21;
				speicher[0x03] = (Rechner.STA_ABSOL * 256)		+ 0x22;  // j = i

				speicher[0x04] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x22;
				speicher[0x05] = (Rechner.STA_ABSOL * 256)		+ 0x26;  // t1 = array[j]
				speicher[0x06] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x21;
				speicher[0x07] = (Rechner.SUB_MEM * 256)		+ 0x26;	 // compare t1 to array[i]
				speicher[0x08] = (Rechner.JLE_ABSOL * 256)		+ 0x0f;	 // JLE #f
				speicher[0x09] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x21;
				speicher[0x0a] = (Rechner.STA_ABSOL * 256)		+ 0x24;  // t2 = array[i]
				speicher[0x0b] = (Rechner.LDA_MEM_INDIR * 256)	+ 0x22;
				speicher[0x0c] = (Rechner.STA_MEM * 256)		+ 0x21;  // array[i] = array[j]
				speicher[0x0d] = (Rechner.LDA_MEM * 256)		+ 0x24;
				speicher[0x0e] = (Rechner.STA_MEM * 256)		+ 0x22;  // array[j] = t2

				speicher[0x0f] = (Rechner.LDA_MEM * 256)		+ 0x22;
				speicher[0x10] = (Rechner.INC * 256);	 				 // j++
				speicher[0x11] = (Rechner.STA_ABSOL * 256)		+ 0x22;

				speicher[0x12] = (Rechner.SUB_MEM * 256)		+ 0x31;	 // SUB 31
				speicher[0x13] = (Rechner.JLE_ABSOL * 256)		+ 0x04;	 // JLE #4

				speicher[0x14] = (Rechner.LDA_MEM * 256)		+ 0x21;
				speicher[0x15] = (Rechner.INC * 256);	 				 // i++
				speicher[0x16] = (Rechner.STA_ABSOL * 256)		+ 0x21;

				speicher[0x17] = (Rechner.SUB_MEM * 256)		+ 0x31;	 // SUB 31
				speicher[0x18] = (Rechner.JLE_ABSOL * 256)		+ 0x02;	 // JLE #2

				speicher[0x19] = (Rechner.NOP * 256);
				speicher[0x1a] = (Rechner.NOP * 256);
				speicher[0x1b] = (Rechner.NOP * 256);
				speicher[0x1c] = (Rechner.NOP * 256);
				speicher[0x1d] = (Rechner.NOP * 256);
				speicher[0x1e] = (Rechner.NOP * 256);
				speicher[0x1f] = (Rechner.JMP_ABSOL * 256) + 0x00;

				speicher[0x30] = 0x38;
				speicher[0x31] = 0x3f;

				if (memoryContents.equalsIgnoreCase("bubblesort"))  // random data to be sorted
					for (i = 0x38; i <= 0x3f; i++)
						speicher[i] = (int) (Math.random() * 255);
				else
				{
					speicher[0x38] = 0x28;  // known data for caching comparisons
					speicher[0x39] = 0xff;
					speicher[0x3a] = 0x25;
					speicher[0x3b] = 0x1e;
					speicher[0x3c] = 0x69;
					speicher[0x3d] = 0x1c;
					speicher[0x3e] = 0x45;
					speicher[0x3f] = 0xef;
				}
			}
		}

		else if ( (memoryContents.equalsIgnoreCase("mips_instructions")) ||
		          (memoryContents.equalsIgnoreCase("mips_single")) )
		{
			int numReg = Rechner.MIPS_NUMBER_OF_REGISTERS;  // Anzahl Allzweckregister
			int maxOffset = 4;
			int instr;
			double r;

			for (i = 0; i < memorySize; i++)
			{
				instr = 0;
				r = Math.random();
				if (r < 0.3)
				{
					instr += Rechner.MIPS_LW << 26;
					instr += ((int) (Math.random() * numReg)) << 21;
					instr += ((int) (Math.random() * numReg)) << 16;
					instr += (int) (Math.random() * maxOffset);
				}
				else if (r < 0.6)
				{
					instr += Rechner.MIPS_SW << 26;
					instr += ((int) (Math.random() * numReg)) << 21;
					instr += ((int) (Math.random() * numReg)) << 16;
					instr += (int) (Math.random() * maxOffset);
				}
				else
				{
					instr += Rechner.MIPS_R << 26;
					instr += ((int) (Math.random() * numReg)) << 21;
					instr += ((int) (Math.random() * numReg)) << 16;
					instr += ((int) (Math.random() * numReg)) << 11;
					if (Math.random() < 0.5)
						instr += 32;  // ADD
					else
						instr += 34;  // SUB
				}

				if ( (! memoryContents.equalsIgnoreCase("mips_single")) || (i % 6 == 0) )
					speicher[i] = instr;
				else
					speicher[i] = Rechner.MIPS_UNIMPORTANT;
			}
		}

		else if (memoryContents.equalsIgnoreCase("mips_random"))
		{
			for (i = 0; i < memorySize; i++)
				speicher[i] = (int) (Math.random() * Rechner.MIPS_DATA_MEM_SIZE);
		}

		else if (memoryContents.equalsIgnoreCase("3address"))
		{
			for (i = 0; i < memorySize; i++)
				speicher[i] = 3*i;
		}

		else if (memoryContents.equalsIgnoreCase("address"))
		{
			for (i = 0; i < memorySize; i++)
				speicher[i] = i;
		}
		else if (! (memoryContents.equals("") || memoryContents.equalsIgnoreCase("zero")))
			parseNewProgram(memoryContents);  // Kein vorgefertigtes Programm abrufen, sondern ein
											  // selbsterstelltes in den Speicher laden

		for (i = 0; i < displaySpeicher.length; i++)
		{
			if (showOpcodes)
				displaySpeicher[i] = toOpcode(speicher[i], zwei_hoch_bitWidth);
			else
				displaySpeicher[i] = parent.expandToString(speicher[i], zwei_hoch_bitWidth);
		}

	} /* end initRam */

	private void parseNewProgram(String p)
	{
		// Anzahl Zeilen feststellen, Leerzeilen werden gleich hier aussortiert.
		StringTokenizer lineCounter = new StringTokenizer(p, "\n");
		int numberOfLines = lineCounter.countTokens();

		// Jede Zeile als eigenen String ablegen
		String[] lines = new String[numberOfLines];
		int i = 0;
		while (lineCounter.hasMoreTokens())
		{
			lines[i] = lineCounter.nextToken();
			i++;
		}

		// Alle Zeilen durchgehen
		StringTokenizer line;
		int address, opcode, argument;
		for (i = 0; i < numberOfLines; i++)
		{
			address = opcode = argument = 0;
			line = new StringTokenizer(lines[i], " \t\r");

			String str = line.nextToken();
			if (str.startsWith(";") || str.startsWith("//") || new String(str).toLowerCase().startsWith("rem"))
			// Kommentar, Zeile ignorieren
				continue;
			try
			{
				address = Integer.valueOf(str, 16).intValue();
			}
			catch (java.lang.NumberFormatException error)
			{
				Rechner.out("FEHLER in Zeile " + (i+1) + ", erster Wert: Wert ist keine Hexadezimalzahl!");
				return;
			}

			if (address < 0)
			{
				Rechner.out("FEHLER in Zeile " + (i+1) + ", erster Wert: Adresse muß positiv sein!");
				return;
			}

			str = line.nextToken();
			boolean argumentExpected = true;
			boolean noOpcode = false;
			if (str.equalsIgnoreCase("NOP"))
			{
				opcode = Rechner.NOP; argumentExpected = false;
			}
			else if (str.equalsIgnoreCase("LM"))
				opcode = Rechner.LDA_MEM;
			else if (str.equalsIgnoreCase("LI"))
				opcode = Rechner.LDA_MEM_INDIR;
			else if (str.equalsIgnoreCase("LA"))
				opcode = Rechner.LDA_ABSOL;
			else if (str.equalsIgnoreCase("SM"))
				opcode = Rechner.STA_MEM;
			else if (str.equalsIgnoreCase("SA"))
				opcode = Rechner.STA_ABSOL;
			else if (str.equalsIgnoreCase("ADD") || str.equals("+"))
				opcode = Rechner.ADD_MEM;
			else if (str.equalsIgnoreCase("SUB") || str.equals("-"))
				opcode = Rechner.SUB_MEM;
			else if (str.equalsIgnoreCase("MUL") || str.equals("*"))
				opcode = Rechner.MUL_MEM;
			else if (str.equalsIgnoreCase("DIV") || str.equals("/"))
				opcode = Rechner.DIV_MEM;
			else if (str.equalsIgnoreCase("AND"))
				opcode = Rechner.AND_MEM;
			else if (str.equalsIgnoreCase("OR"))
				opcode = Rechner.OR_MEM;
			else if (str.equalsIgnoreCase("XOR"))
				opcode = Rechner.XOR_MEM;
			else if (str.equalsIgnoreCase("LEFT") || str.equalsIgnoreCase("<<"))
				opcode = Rechner.SHL;
			else if (str.equalsIgnoreCase("RIGT") || str.equalsIgnoreCase("RIGHT") || str.equalsIgnoreCase(">>"))
				opcode = Rechner.SHR;
			else if (str.equalsIgnoreCase("JM"))
				opcode = Rechner.JMP_MEM;
			else if (str.equalsIgnoreCase("JA"))
				opcode = Rechner.JMP_ABSOL;
			else if (str.equalsIgnoreCase("JZM"))
				opcode = Rechner.JZE_MEM;
			else if (str.equalsIgnoreCase("JZA"))
				opcode = Rechner.JZE_ABSOL;
			else if (str.equalsIgnoreCase("JNM"))
				opcode = Rechner.JNZ_MEM;
			else if (str.equalsIgnoreCase("JNA"))
				opcode = Rechner.JNZ_ABSOL;
			else if (str.equalsIgnoreCase("JLM"))
				opcode = Rechner.JLE_MEM;
			else if (str.equalsIgnoreCase("JLA"))
				opcode = Rechner.JLE_ABSOL;
			else if (str.equalsIgnoreCase("IN"))
				opcode = Rechner.IN_MEM;
			else if (str.equalsIgnoreCase("OUT"))
				opcode = Rechner.OUT_MEM;
			else if (str.equalsIgnoreCase("NOT"))
			{
				opcode = Rechner.NOT; argumentExpected = false;
			}
			else if (str.equalsIgnoreCase("+1") || str.equalsIgnoreCase("INC"))
			{
				opcode = Rechner.INC; argumentExpected = false;
			}
			else if (str.equalsIgnoreCase("-1") || str.equalsIgnoreCase("DEC"))
			{
				opcode = Rechner.DEC; argumentExpected = false;
			}
			else
				try  // Ist zweiter Wert der Zeile eine Zahl?
				{
					opcode = Integer.valueOf(str, 16).intValue();
					argumentExpected = false;
					noOpcode = true;
				}
				catch (java.lang.NumberFormatException error)
				{
					Rechner.out("FEHLER in Zeile " + (i+1) + ", zweiter Wert: Unbekannter Opcode - bekannte Opcodes: NOP, LM, LI, LA, SM, SA, +, ADD, -, SUB, *, MUL, /, DIV, AND, OR, XOR, NOT, LEFT, <<, RIGT, RIGHT, >>, +1, INC, -1, DEC, JM, JA, JZM, JZA, JNM, JNA, JLM, JLA, IN, OUT");
					return;
				}


			if (argumentExpected)
			{
				if (line.hasMoreTokens())
					str = line.nextToken();
				else
				{
					Rechner.out("FEHLER in Zeile " + (i+1) + ": Dieser Befehl benötigt ein Argument!");
					return;
				}
				try
				{
					argument = Integer.valueOf(str, 16).intValue();
				}
				catch (java.lang.NumberFormatException error)
				{
					Rechner.out("FEHLER in Zeile " + (i+1) + ", dritter Wert: Wert ist keine Hexadezimalzahl!");
					return;
				}
			}
			else if (line.hasMoreTokens()) // kein Argument mehr erwartet, aber dennoch vorhanden
			{
				str = line.nextToken();
				if (! (str.startsWith(";") || str.startsWith("//") || new String(str).toLowerCase().startsWith("rem")))
				// Argument ist kein Kommentar
				{
					Rechner.out("FEHLER in Zeile " + (i+1) + ", dritter Wert: Kein Argument ist mehr notwendig!");
					return;
				}
			}

			if (memorySize-1 < address)
			{
				Rechner.out("FEHLER in Zeile " + (i+1) + ", erster Wert: Diese Adresse liegt nicht mehr im Speicher!");
				return;
			}
			else if (noOpcode)
				speicher[address] = opcode;
			else
				speicher[address] = opcode*256 + argument;
		} // end Alle Zeilen durchgehen

	} /* end parseNewProgram */


	public void paint(Graphics g)
	{
		int labelHeight = parent.getHeight(parent.DIALOGFONT);
		int labelWidth = parent.stringWidth(parent.DIALOGFONT, CELLDEFAULT);

		if (imageCache == null)
		{
		    Graphics offScreenGC = g;
		    Point p = getCoordinates("rightbottom");
		    p.translate(-startX, -startY);
		    imageCache = parent.createImage(p.x, p.y + (labelHeight) );
		    g = imageCache.getGraphics();

    		// clear area of ram
    		g.setColor(parent.BACKGROUND);
    		g.fillRect(0, 0, p.x, p.y + (labelHeight) );

        	g.setColor(Color.black);
        	g.drawString(label, 0, (labelHeight) );

    		g.setColor(parent.MEM_COLOR);
    		g.drawLine(0, 6 + (labelHeight) , labelWidth*OUTPUTWIDTH, 6 + (labelHeight) );

    		int ax = 2;
    		int ay = labelHeight + 4 + (labelHeight);

    		int col, row;
    		int addressToBePainted;

    		for (row = 0; row < OUTPUTHEIGHT; row++)
    		{
    		    addressToBePainted = row*OUTPUTWIDTH - 1;

    			for (col = 0; col < OUTPUTWIDTH; col++)
    			{
    				addressToBePainted++;

    				if ((addressToBePainted == address) && (activated == true))
    				{
    					if ((parent.blackAndWhite == true) && (blinker == true))
    						g.setColor(parent.BACKGROUND);
    					else
    						g.setColor(parent.MEM_COLOR_ACTIVATED);
    					activatedX = startX + ax;
    					activatedY = startY + ay;
    					activatedString = new String(displaySpeicher[addressToBePainted]);
    				}
    				else
    					g.setColor(parent.MEM_COLOR);

    				g.drawString(displaySpeicher[addressToBePainted], ax, ay);

    				ax = ax + labelWidth;
    			}
    			g.setColor(parent.MEM_COLOR);
    			g.drawLine(0, ay + 4, labelWidth*OUTPUTWIDTH, ay + 4);
    			ax = 2;
    			ay = ay + labelHeight + 2;
    		}
    		ax = 0;
    		ay = 6 + (labelHeight);
    		for (col = 0; col <= OUTPUTWIDTH; col++)
    		{
    			g.drawLine(ax, ay, ax, ay + (labelHeight+2)*OUTPUTHEIGHT);
    			ax = ax + labelWidth;
    		}

    		offScreenGC.drawImage(imageCache, startX, startY - (labelHeight), parent);
    	}
    	else
    	// gespeichertes Abbild des RAMs ist noch gueltig
    	{
    		g.drawImage(imageCache, startX, startY - (labelHeight), parent);

    		if (activated == true)
    		{
        		int ax = startX + 2;
        		int ay = startY + labelHeight + 4;
        		int col, row;
        		int addressToBePainted;

        		outside: for (row = 0; row < OUTPUTHEIGHT; row++)
        		{
        		    addressToBePainted = row*OUTPUTWIDTH - 1;

        			for (col = 0; col < OUTPUTWIDTH; col++)
        			{
        				addressToBePainted++;

        				if (addressToBePainted == address)
        				{
        				    g.setColor(parent.BACKGROUND);
        				    g.fillRect(ax, ay - labelHeight + 3, labelWidth - 3, labelHeight);

           					activatedX = ax;
           					activatedY = ay;
           					activatedString = new String(displaySpeicher[addressToBePainted]);

        					if ((parent.blackAndWhite == false) || (blinker == false))
        					{
        						g.setColor(parent.MEM_COLOR_ACTIVATED);
                				g.drawString(displaySpeicher[addressToBePainted], ax, ay);
            				}

            				break outside;
        				}

        				ax = ax + labelWidth;
        			}
        			ax = startX + 2;
        			ay = ay + labelHeight + 2;
        		}
        	}
    	}

	} /* end paint */

	public void paintActivated(Graphics g)
	{
		if (activated || hasBeenActivated)
		{
			if (activated == false)
				hasBeenActivated = false;
			paint(g);
		}
	} /* end paintActivated */


	public Point getCoordinates(String str)
	{
		Point p = new Point(startX, startY);  // "leftTop"

		int halfHeight = (parent.getHeight(parent.DIALOGFONT) + 2) * OUTPUTHEIGHT / 2;
		int halfWidth = parent.stringWidth(parent.DIALOGFONT, CELLDEFAULT) * OUTPUTWIDTH / 2;

		if (str.equalsIgnoreCase("top"))
		{
			p.translate(halfWidth, -1);
		}
		else if (str.equalsIgnoreCase("left"))
		{
			p.translate(- 1, halfHeight + 3);
		}
		else if (str.equalsIgnoreCase("right"))
		{
			p.translate(2*halfWidth + 1, halfHeight + 3);
		}
		else if (str.equalsIgnoreCase("bottom"))
		{
			p.translate(halfWidth, 2*halfHeight + 7);
		}
		else if (str.equalsIgnoreCase("rightBottom"))
		{
			p.translate(2*halfWidth + 1, 2*halfHeight + 7);
		}
		return p;
	} /* end getCoordinates for SimpleMemory */


	public int getValue()
	{
		return speicher[address];
	}

	public long getMaxValue()
	{
		return zwei_hoch_bitWidth;
	}

	public int[] getAllValues()
	{
		int value[] = new int[speicher.length];
		for (int i = 0; i < speicher.length; i++)
			value[i] = speicher[i];
		return value;
	}

	public void setValue(int newVal)
	{
		long newValue = newVal % zwei_hoch_bitWidth;

		if (newValue >= zwei_hoch_bitWidth/2 )
			newValue = newValue - zwei_hoch_bitWidth;
		else if (newValue < -zwei_hoch_bitWidth/2 )
			newValue = newValue + zwei_hoch_bitWidth;

		speicher[address] = (int) newValue;
	} /* end setValue (at a single address) */

	public void setValue(int value[])
	{
		for (int i = 0; i < memorySize; i++)
			speicher[i] = value[i];
	} /* end setValue (array; only used to write back previously buffered data) */

	public void setAddress(int address)
	{
		this.address = address % memorySize;  // Adresslaenge beschraenken

		if (address < 0)
			this.address += memorySize;  // Eine "% x"-Operation bildet auf das Intervall ]-x, x[ ab!
	}

	public int getAddress()
	{
		return address;
	}

	public void saveAddress()
	{
		savedAddress = address;
	}

	public void restoreAddress()
	{
		setAddress(savedAddress);
	}

	public boolean isActivated()
	{
		return activated;
	}

	public int getMemorySize()
	{
		return memorySize;
	}

	public void activate()
	{
		if (! activationLocked)
		{
			activated = true;
			hasBeenActivated = true;
			displaySpeicher[address] = parent.expandToString(speicher[address], zwei_hoch_bitWidth);
		}
	}

	public synchronized void deactivate()
	{
		if (! activationLocked)
		{
			activated = false;
			blinker = false;
			imageCache = null;
		}
	}

	/**
	 *  Alle in den Speicherzellen angezeigten Werte werden auf den Stand der eventuell
	 *  durch setValue() geänderten internen Werte gebracht.
	 *  Hat nichts mit java.awt.Component.update() zu tun.
	 *
	 *  @see #deactivate
	 *  @see #activate
	 */
	public void updateAll()
	{
		for (int i = 0; i < memorySize; i++)
			displaySpeicher[i] = parent.expandToString(speicher[i], zwei_hoch_bitWidth);
		imageCache = null;
	}

	public synchronized void blink(boolean blinker)
	{
		if (activated == true)
		{
			this.blinker = blinker;
			Graphics g = parent.offScreenGC;

			if (blinker == true)
				g.setColor(parent.BACKGROUND);
			else
				g.setColor(parent.MEM_COLOR_ACTIVATED);

			g.drawString(activatedString, activatedX, activatedY);

		}
	}

	public void invalidateImageCache()
	{
	    imageCache = null;
	} /* end invalidateImageCache */


	public static String toOpcode(int value, long maxValue)
	{
		String str;
		int opcode = value / 256;
		int lowByte = value % 256;
		String operand = Rechner.expandToString(lowByte, 256, 16);
		if (technicalOpcodes == true)
		{
			technicalOpcodes = false;
            return toOpcode(value, maxValue);
		}
		else
		{
			switch(opcode)
			{
				case Rechner.NOP:
					str = new String("No Op.");
					break;
				case Rechner.LDA_MEM:
					str = new String("LM " + operand);
					break;
				case Rechner.LDA_MEM_INDIR:
					str = new String("LI " + operand);
					break;
				case Rechner.LDA_ABSOL:
					str = new String("LA " + operand);
					break;
				case Rechner.STA_MEM:
					str = new String("SM " + operand);
					break;
				case Rechner.STA_ABSOL:
					str = new String("SA " + operand);
					break;
				case Rechner.ADD_MEM:
					str = new String("+ " + operand);
					break;
				case Rechner.SUB_MEM:
					str = new String("- " + operand);
					break;
				case Rechner.MUL_MEM:
					str = new String("* " + operand);
					break;
				case Rechner.DIV_MEM:
					str = new String("/ " + operand);
					break;
                case Rechner.AND_MEM:
                    str = new String("AND" + operand);
					break;
                case Rechner.OR_MEM:
                    str = new String("OR " + operand);
					break;
                case Rechner.XOR_MEM:
                    str = new String("XOR " + operand);
					break;
                case Rechner.NOT:
                    str = new String("NOT");
					break;
                case Rechner.INC:
					str = new String("+1");
					break;
				case Rechner.DEC:
					str = new String("-1");
					break;
				case Rechner.SHL:
					str = new String("LEFT" + Integer.toString(lowByte % 16, 16));
					break;
				case Rechner.SHR:
					str = new String("RIGT" + Integer.toString(lowByte % 16, 16));
					break;
				case Rechner.JMP_MEM:
					str = new String("JM " + operand);
					break;
				case Rechner.JMP_ABSOL:
					str = new String("JA " + operand);
					break;
				case Rechner.JZE_MEM:
					str = new String("JZM" + operand);
					break;
				case Rechner.JZE_ABSOL:
					str = new String("JZA" + operand);
					break;
				case Rechner.JNZ_MEM:
					str = new String("JNM" + operand);
					break;
				case Rechner.JNZ_ABSOL:
					str = new String("JNA" + operand);
					break;
				case Rechner.JLE_MEM:
					str = new String("JLM" + operand);
					break;
				case Rechner.JLE_ABSOL:
					str = new String("JLA" + operand);
					break;
				case Rechner.IN_MEM:
					str = new String("IN " + operand);
					break;
				case Rechner.OUT_MEM:
					str = new String("OUT" + operand);
					break;
				default:
					str = Rechner.expandToString(value, maxValue);
			}
		}

		return str;
	} /* end toOpcode */

	public static String toLongerOpcode(int value, long maxValue)
	{
		String str;
		int opcode = value / 256;
		int lowByte = value % 256;
		String operand = Rechner.expandToString(lowByte, 256, 16);

		switch(opcode)
		{
			case Rechner.NOP:
				str = new String("NOP");
				break;
			case Rechner.LDA_MEM:
				str = new String("LM  " + operand);
				break;
			case Rechner.LDA_MEM_INDIR:
				str = new String("LI  " + operand);
				break;
			case Rechner.LDA_ABSOL:
				str = new String("LA  " + operand);
				break;
			case Rechner.STA_MEM:
				str = new String("SM  " + operand);
				break;
			case Rechner.STA_ABSOL:
				str = new String("SA  " + operand);
				break;
			case Rechner.ADD_MEM:
				str = new String("+   " + operand);
				break;
			case Rechner.SUB_MEM:
				str = new String("-   " + operand);
				break;
			case Rechner.MUL_MEM:
				str = new String("*   " + operand);
				break;
			case Rechner.DIV_MEM:
				str = new String("/   " + operand);
				break;
            case Rechner.AND_MEM:
                str = new String("AND " + operand);
				break;
            case Rechner.OR_MEM:
                str = new String("OR  " + operand);
				break;
            case Rechner.XOR_MEM:
                str = new String("XOR " + operand);
				break;
            case Rechner.NOT:
                str = new String("NOT");
				break;
            case Rechner.INC:
				str = new String("+1  ");
				break;
			case Rechner.DEC:
				str = new String("-1  ");
				break;
			case Rechner.SHL:
				str = new String("<<  " + Integer.toString(lowByte % 16, 16));
				break;
			case Rechner.SHR:
				str = new String(">>  " + Integer.toString(lowByte % 16, 16));
				break;
			case Rechner.JMP_MEM:
				str = new String("JM  " + operand);
				break;
			case Rechner.JMP_ABSOL:
				str = new String("JA  " + operand);
				break;
			case Rechner.JZE_MEM:
				str = new String("JZM " + operand);
				break;
			case Rechner.JZE_ABSOL:
				str = new String("JZA " + operand);
				break;
			case Rechner.JNZ_MEM:
				str = new String("JNM " + operand);
				break;
			case Rechner.JNZ_ABSOL:
				str = new String("JNA " + operand);
				break;
			case Rechner.JLE_MEM:
				str = new String("JLM " + operand);
				break;
			case Rechner.JLE_ABSOL:
				str = new String("JLA " + operand);
				break;
			case Rechner.IN_MEM:
				str = new String("IN  " + operand);
				break;
			case Rechner.OUT_MEM:
				str = new String("OUT " + operand);
				break;
			default:
				str = Rechner.expandToString(value, maxValue);
		}

		return str;
	} /* end toLongerOpcode */


	public void setLabel(String[] newLabel)
	{
		if (newLabel != null)
			label = newLabel[0];
	}

	public String[] getLabel()
	{
		String[] strArray = {label};
		return strArray;
	}

	public void reshape(int x, int y, int width, int height)
	{
		startX = x; startY = y;
	}

	public void reshape(int x, int y, int width, int height, String newGrabMode)
	{
		startX = x; startY = y;
	}

	public void setCoordinates(int x, int y, String grabMode)
	{
		startX = x; startY = y;
	}

	public String[] getPossibleQualifiers()
	{
		String[] q = {"leftTop"};
		return q;
	}


	public boolean intersectsWith(Point p)  // Wird von EditableMemory überschrieben!
	{
		Point start = getCoordinates("leftTop");
		Point end = getCoordinates("rightBottom");
		return ( (start.x <= p.x) && (end.x >= p.x) && (start.y <= p.y) && (end.y >= p.y) );
	}

	public String getInfoTipText(Point where)
	{
		return new String("");
	}

} /* end SimpleMemory */

