package miggy.cpupoet;

import junit.framework.TestCase;

public class InstructionTests extends TestCase {
	static {
		MacroPLA.decode(0);
	}

	public void testBCD() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("ABCD");
		test.executeBinTest("NBCD");
		test.executeBinTest("SBCD");
	}

	public void testADD() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("ADD.b");
		test.executeBinTest("ADD.w");
		test.executeBinTest("ADD.l");
		test.executeBinTest("ADDA.w");
		test.executeBinTest("ADDA.l");
		test.executeBinTest("ADDX.b");
		test.executeBinTest("ADDX.w");
		test.executeBinTest("ADDX.l");
	}

	public void testAND() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("AND.b");
		test.executeBinTest("AND.w");
		test.executeBinTest("AND.l");

		test.executeBinTest("ANDItoCCR");
	}

	public void testOR() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("OR.b");
		test.executeBinTest("OR.w");
		test.executeBinTest("OR.l");

		test.executeBinTest("ORItoCCR");
	}

	public void testEOR() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("EOR.b");
		test.executeBinTest("EOR.w");
		test.executeBinTest("EOR.l");

		test.executeBinTest("NOT.b");
		test.executeBinTest("NOT.w");
		test.executeBinTest("NOT.l");

		test.executeBinTest("EORItoCCR");
	}

	public void testBIT() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("BCHG");
		test.executeBinTest("BCLR");
		test.executeBinTest("BSET");
		test.executeBinTest("BTST");
	}

	// public void testASL() {
	// CoreTest test = new CoreTest(0xffffff + 1, true);
	//
	// test.executeBinTest("ASL.b");
	// test.executeBinTest("ASL.w");
	// test.executeBinTest("ASL.l");
	// }

	 public void testBcc() {
	 CoreTest test = new CoreTest(0xffffff + 1, true);
	
	 test.executeBinTest("Bcc", 373, 466, 570, 1547, 1695, 1782, 2166, 2224, 2441);
	 test.executeBinTest("BSR", 25, 573, 814, 1357, 1443, 1509, 1734, 1934, 2232, 2338);
	 }

		public void testDBcc() {
			CoreTest test = new CoreTest(0xffffff + 1, true);

			test.executeBinTest("DBcc");
		}

		public void testMisc() {
			CoreTest test = new CoreTest(0xffffff + 1, true);

			test.executeBinTest("NOP");
			test.executeBinTest("EXG");
			test.executeBinTest("SWAP");
			test.executeBinTest("EXT.w");
			test.executeBinTest("EXT.l");
			test.executeBinTest("LEA");
			test.executeBinTest("PEA");
			test.executeBinTest("RTS");
			test.executeBinTest("RTR");
			test.executeBinTest("LINK");
			test.executeBinTest("UNLINK");
			test.executeBinTest("Scc");
			test.executeBinTest("TST.b");
			test.executeBinTest("TST.w");
			test.executeBinTest("TST.l");
//			test.executeBinTest("CLR.b");
//			test.executeBinTest("CLR.w");
//			test.executeBinTest("CLR.l");
			test.executeBinTest("TRAP");
			test.executeBinTest("TRAPV");
		}

	public void testJMP() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("JMP");
		test.executeBinTest("JSR");
	}

	public void testSUB() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("SUB.b");
		test.executeBinTest("SUB.w");
		test.executeBinTest("SUB.l");
		test.executeBinTest("SUBA.w");
		test.executeBinTest("SUBA.l");
		test.executeBinTest("CMP.b");
		test.executeBinTest("CMP.w");
		test.executeBinTest("CMP.l");
		test.executeBinTest("CMPA.w");
		test.executeBinTest("CMPA.l");
		test.executeBinTest("SUBX.b");
		test.executeBinTest("SUBX.w");
		test.executeBinTest("SUBX.l");
		test.executeBinTest("NEG.b");
		//test.executeBinTest("NEG.w");
		test.executeBinTest("NEG.l");
		test.executeBinTest("NEGX.b");
		test.executeBinTest("NEGX.w");
		test.executeBinTest("NEGX.l");
	}

	public void testMOVE() {
		CoreTest test = new CoreTest(0xffffff + 1, true);

		test.executeBinTest("MOVE.b");
		/*
		 * 295 is not compatible (post incremented value is written by design)
		 * 342 is not compatible (post incremented value is written by design)
		 * 494 is not compatible (post incremented value is written by design)
		 * 994 is not compatible (pre decremented value is written by design)
		 * 1225 is not compatible (pre decremented value is written by design)
		 * 1846 is not compatible (post incremented value is written by design)
		 */
		test.executeBinTest("MOVE.w", 295, 342, 494, 994, 1225, 1846);
		/*
		 * 217 is not compatible (post incremented value is written by design)
		 * 502 is not compatible (post incremented value is written by design)
		 * 1152 is not compatible (post incremented value is written by design)
		 * 1691 is not compatible (post incremented value is written by design)
		 * 1830 is not compatible (pre decremented value is written by design)
		 * 2057 is not compatible (post incremented value is written by design)
		 * 2135 is not compatible (post incremented value is written by design)
		 */
		test.executeBinTest("MOVE.l", 217, 502, 1152, 1691, 1830, 2057, 2135);
		test.executeBinTest("MOVE.q");
		
		test.executeBinTest("MOVEP.w");
		test.executeBinTest("MOVEP.l");

		test.executeBinTest("MOVEA.w");
		test.executeBinTest("MOVEA.l");

//		test.executeBinTest("MOVEM.w");
//		test.executeBinTest("MOVEM.l");
		
		test.executeBinTest("MOVEtoCCR");
		test.executeBinTest("MOVEtoUSP");
		test.executeBinTest("MOVEfromUSP");
	}

}
