public Form1(string obj_file = null) { InitializeComponent(); _obj_file_path = obj_file; hv = new HexViewer(_sic_memory); _sic_machine = new MaquinaSic(); _opcodes = new Hashtable(); _opcodes.Add(0x18, "ADD"); _opcodes.Add(0x40, "AND"); _opcodes.Add(0x28, "COMP"); _opcodes.Add(0x24, "DIV"); _opcodes.Add(0x3C, "J"); _opcodes.Add(0x30, "JEQ"); _opcodes.Add(0x34, "JGT"); _opcodes.Add(0x38, "JLT"); _opcodes.Add(0x48, "JSUB"); _opcodes.Add(0x00, "LDA"); _opcodes.Add(0x50, "LDCH"); _opcodes.Add(0x08, "LDL"); _opcodes.Add(0x04, "LDX"); _opcodes.Add(0x20, "MUL"); _opcodes.Add(0x44, "OR"); _opcodes.Add(0xD8, "RD"); _opcodes.Add(0x4C, "RSUB"); _opcodes.Add(0x0C, "STA"); _opcodes.Add(0x54, "STCH"); _opcodes.Add(0x14, "STL"); _opcodes.Add(0xE8, "STSW"); _opcodes.Add(0x10, "STX"); _opcodes.Add(0x1C, "SUB"); _opcodes.Add(0xE0, "TD"); _opcodes.Add(0x2C, "TIX"); _opcodes.Add(0xDC, "WD"); }
public int CargaProgramaObjeto(List <string> LineasObj, MaquinaSic maquina) { int ret = 1; UInt32 start_addr = 0; UInt32 obj_start_addr = 0; int prog_size = 0; string prog_name = ""; UInt32 reg_addr; Byte reg_size; String reg_data = ""; Boolean is_first_line = true; for (int i = 0; i < LineasObj.Count; i++) { if (LineasObj[i] != "") { switch (LineasObj[i][0]) { case 'H': if (!is_first_line) { return(0); // error, solo la primera linea debe empezar con H. } if (LineasObj[i].Length != 19) { return(0); // error, el formato de la linea es invalido } prog_name = LineasObj[i].Substring(1, 6); prog_name = prog_name.Replace('0', '\0'); obj_start_addr = uint.Parse(LineasObj[i].Substring(7, 6), System.Globalization.NumberStyles.HexNumber); prog_size = int.Parse(LineasObj[i].Substring(13, 6), System.Globalization.NumberStyles.HexNumber); if (obj_start_addr + prog_size >= MaquinaSic.MEMORY_SIZE) { return(0); // error, el programa no cabe en memoria } is_first_line = false; break; case 'T': if (LineasObj[i].Length < 11) { return(0); // error, el formato de la linea es invalido } reg_addr = uint.Parse(LineasObj[i].Substring(1, 6), System.Globalization.NumberStyles.HexNumber); reg_size = Byte.Parse(LineasObj[i].Substring(7, 2), System.Globalization.NumberStyles.HexNumber); reg_data = LineasObj[i].Substring(9); if (reg_size != reg_data.Count() / 2) { return(0); // error, el formato de registro de datos es invalido. } List <string> groups = new List <string>(); for (int j = 0; j < reg_data.Length; j++) { string s = "" + reg_data[j]; j++; s += reg_data[j]; groups.Add(s); } foreach (string b in groups) { maquina.Memory[reg_addr] = Byte.Parse(b, System.Globalization.NumberStyles.HexNumber); reg_addr++; } is_first_line = false; break; case 'E': if (LineasObj[i].Length != 7) { return(0); // error, formato del registo E no valido. } start_addr = uint.Parse(LineasObj[i].Substring(1, 6), System.Globalization.NumberStyles.HexNumber); is_first_line = false; break; default: return(0); // Error, linea no valida para registro objeto } } } maquina.Load(maquina.Memory, start_addr); maquina.ProgName = prog_name; maquina.ProgSize = prog_size; return(ret); }