package ga050426;

public class Opcodes {
	
	//order important
	
	static final byte NOP =0x0;
	static final byte CLA =0x1;
	static final byte CLC =0x2;
	static final byte CLX =0x3;
	static final byte CMC =0x4;
	static final byte INC =0x5;
	static final byte DEC =0x6;
	static final byte INX =0x7;
	static final byte DEX =0x8;
	static final byte TAX =0x9;
	static final byte INI =0xA;
	static final byte INA =0xB;
	static final byte OTI =0xC;
	static final byte OTA =0xD;
	static final byte PSH =0xE;
	static final byte POP =0xF;
	static final byte SHL =0x10;
	static final byte SHR =0x11;
	static final byte MSA =0x12;
	static final byte MAS =0x13;
	static final byte LDA =0x14;
	static final byte LDX =0x15;
	static final byte RET =0x16;
	static final byte HLT =0x17;

	static final byte LDI =0x1A;
	static final byte LDD =0x1B;
	static final byte LDR =0x1C;
	static final byte STA =0x1D;
	static final byte STX =0x1E;
	static final byte ADD =0x1F;
	static final byte ADX =0x20;
	static final byte ADI =0x21;
	static final byte ADC =0x22;
	static final byte SUB =0x23;
	static final byte SBX =0x24;
	static final byte SBI =0x25;
	static final byte SBC =0x26;
	static final byte CMP =0x27;
	static final byte CPI =0x28;
	static final byte ANA =0x29;
	static final byte ANI =0x2A;
	static final byte ORA =0x2B;
	static final byte ORI =0x2C;
	static final byte BRR =0x2D;
	static final byte BZE =0x2E;
	static final byte BNZ =0x2F;
	static final byte BPZ =0x30;
	static final byte BNG =0x31;
	static final byte BCC =0x32;
	static final byte BCS =0x33;
	static final byte JSR =0x34;
	//directives
	static final byte BEG =0x35;
	static final byte END =0x36;
	static final byte ORG =0x39;
	static final byte DC =0x3A;
	static final byte DS =0x3B;
	static final byte EQU =0x3C;
	static final byte TXT =0x3D;
	static final byte BSS =0x3E;
	static final byte DAT =0x3F;
	static final byte DEF =0x40;
	static final byte USE =0x41;
	static final byte ERR =0x42;
	
	public static byte getOpcode(String opcode){
		if (opcode.toLowerCase().equals("nop"))return NOP;
		else if (opcode.toLowerCase().equals("cla"))return CLA;
		else if (opcode.toLowerCase().equals("clc"))return CLC;
		else if (opcode.toLowerCase().equals("clx"))return CLX;
		else if (opcode.toLowerCase().equals("cmc"))return CMC;
		else if (opcode.toLowerCase().equals("inc"))return INC;
		else if (opcode.toLowerCase().equals("dec"))return DEC;
		else if (opcode.toLowerCase().equals("inx"))return INX;
		else if (opcode.toLowerCase().equals("dex"))return DEX;
		else if (opcode.toLowerCase().equals("tax"))return TAX;
		else if (opcode.toLowerCase().equals("ini"))return INI;
		else if (opcode.toLowerCase().equals("ina"))return INA;
		else if (opcode.toLowerCase().equals("oti"))return OTI;
		else if (opcode.toLowerCase().equals("ota"))return OTA;
		else if (opcode.toLowerCase().equals("psh"))return PSH;
		else if (opcode.toLowerCase().equals("pop"))return POP;
		else if (opcode.toLowerCase().equals("shl"))return SHL;
		else if (opcode.toLowerCase().equals("shr"))return SHR;
		else if (opcode.toLowerCase().equals("msa"))return MSA;
		else if (opcode.toLowerCase().equals("mas"))return MAS;
		else if (opcode.toLowerCase().equals("lda"))return LDA;
		else if (opcode.toLowerCase().equals("ldx"))return LDX;
		else if (opcode.toLowerCase().equals("ret"))return RET;
		else if (opcode.toLowerCase().equals("hlt"))return HLT;
		
		else if (opcode.toLowerCase().equals("ldi"))return LDI;
		else if (opcode.toLowerCase().equals("ldd"))return LDD;
		else if (opcode.toLowerCase().equals("ldr"))return LDR;
		else if (opcode.toLowerCase().equals("sta"))return STA;
		else if (opcode.toLowerCase().equals("stx"))return STX;
		else if (opcode.toLowerCase().equals("add"))return ADD;
		else if (opcode.toLowerCase().equals("adx"))return ADX;
		else if (opcode.toLowerCase().equals("adi"))return ADI;
		else if (opcode.toLowerCase().equals("adc"))return ADC;
		else if (opcode.toLowerCase().equals("sub"))return SUB;
		else if (opcode.toLowerCase().equals("sbx"))return SBX;
		else if (opcode.toLowerCase().equals("sbi"))return SBI;
		else if (opcode.toLowerCase().equals("sbc"))return SBC;
		else if (opcode.toLowerCase().equals("cmp"))return CMP;
		else if (opcode.toLowerCase().equals("cpi"))return CPI;
		else if (opcode.toLowerCase().equals("ana"))return ANA;
		else if (opcode.toLowerCase().equals("ani"))return ANI;
		else if (opcode.toLowerCase().equals("ora"))return ORA;
		else if (opcode.toLowerCase().equals("ori"))return ORI;
		else if (opcode.toLowerCase().equals("brr"))return BRR;
		else if (opcode.toLowerCase().equals("bze"))return BZE;
		else if (opcode.toLowerCase().equals("bnz"))return BNZ;
		else if (opcode.toLowerCase().equals("bpz"))return BPZ;
		else if (opcode.toLowerCase().equals("bng"))return BNG;
		else if (opcode.toLowerCase().equals("bcc"))return BCC;
		else if (opcode.toLowerCase().equals("bcs"))return BCS;
		else if (opcode.toLowerCase().equals("jsr"))return JSR;
		
		//directives
		else if (opcode.toLowerCase().equals("beg"))return BEG;
		else if (opcode.toLowerCase().equals("end"))return END;
		else if (opcode.toLowerCase().equals("org"))return ORG;
		else if (opcode.toLowerCase().equals("dc"))return DC;
		else if (opcode.toLowerCase().equals("ds"))return DS;
		else if (opcode.toLowerCase().equals("equ"))return EQU;
		else if (opcode.toLowerCase().contains("txt"))return TXT;
		else if (opcode.toLowerCase().contains("bss"))return BSS;
		else if (opcode.toLowerCase().contains("dat"))return DAT;
		else if (opcode.toLowerCase().equals("def"))return DEF;
		else if (opcode.toLowerCase().equals("use"))return USE;
		
		else return ERR;
	}
	public static String getMnemonic(byte opcode){
		if (opcode==NOP) return "NOP";
		if (opcode==CLA) return "CLA";
		if (opcode==CLC) return "CLC";
		if (opcode==CLX) return "CLX";
		if (opcode==CMC) return "CMC";
		if (opcode==INC) return "INC";
		if (opcode==DEC) return "DEC";
		if (opcode==INX) return "INX";
		if (opcode==DEX) return "DEX";
		if (opcode==TAX) return "TAX";
		if (opcode==INI) return "INI";
		if (opcode==INA) return "INA";
		if (opcode==OTI) return "OTI";
		if (opcode==OTA) return "OTA";
		if (opcode==PSH) return "PSH";
		if (opcode==POP) return "POP";
		if (opcode==SHL) return "SHL";
		if (opcode==SHR) return "SHR";
		if (opcode==MSA) return "MSA";
		if (opcode==MAS) return "MAS";
		if (opcode==LDA) return "LDA";
		if (opcode==LDX) return "LDX";
		if (opcode==RET) return "RET";
		if (opcode==HLT) return "HLT";
		
		if (opcode==LDI) return "LDI";
		if (opcode==LDD) return "LDD";
		if (opcode==LDR) return "LDR";
		if (opcode==STA) return "STA";
		if (opcode==STX) return "STX";
		if (opcode==ADD) return "ADD";
		if (opcode==ADX) return "ADX";
		if (opcode==ADI) return "ADI";
		if (opcode==ADC) return "ADC";
		if (opcode==SUB) return "SUB";
		if (opcode==SBX) return "SBX";
		if (opcode==SBI) return "SBI";
		if (opcode==SBC) return "SBC";
		if (opcode==CMP) return "CMP";
		if (opcode==CPI) return "CPI";
		if (opcode==ANA) return "ANA";
		if (opcode==ANI) return "ANI";
		if (opcode==ORA) return "ORA";
		if (opcode==ORI) return "ORI";
		if (opcode==BRR) return "BRR";
		if (opcode==BZE) return "BZE";
		if (opcode==BNZ) return "BNZ";
		if (opcode==BPZ) return "BPZ";
		if (opcode==BNG) return "BNG";
		if (opcode==BCC) return "BCC";
		if (opcode==BCS) return "BCS";
		if (opcode==JSR) return "JSR";
		return "ERR";
	}
}
