예제 #1
0
 public Form1()
 {
     InitializeComponent();
     this.button6.Click += new System.EventHandler(this.button6_Click);
     for (int i = 0; i < 4; i++)//粽
     {
         List <TextBox> tbl = new List <TextBox>();
         for (int j = 0; j < 4; j++)//恆
         {
             TextBox tb = new TextBox()
             {
                 Size     = new Size(40, 22),
                 Location = new Point(57 + j * 50, 34 + i * 30),
             };
             tb.MouseClick += new System.Windows.Forms.MouseEventHandler(this.tb_MouseClick);
             Controls.Add(tb);
             tbl.Add(tb);
         }
         TBL.Add(tbl);
     }
     for (int i = 0; i < 4; i++)
     {
         TBL[i][i].Text = $"{i + 1}";
     }
     button3.Text = "1";
     button4.Text = "2";
     button5.Text = "3";
     button6.Text = "4";
     label1.Text  = "";
     button1.Text = "產生提示";
     button2.Text = "Check";
     button1_Click(null, null);
 }
예제 #2
0
    public override void Execute()
    {
        // Fetch
        int instructionDirection = TBL.InstDirToIndex(pcRegister);

        instructionRegister = instructionsCache.Read(instructionDirection);

        if (instructionRegister.Equals(InstructionsCache.INVALID_INSTRUCTION)) // Miss
        {
            instructionsCache.LoadBlock(instructionDirection);                 // Write Allocate
            instructionRegister = instructionsCache.Read(instructionDirection);
            clock += ProcessorConstants.CacheMissDelay;
        }

        pcRegister += 4; // siguiente instruccion

        // Decode and Execute
        if (currentThread == 1)
        {
            Debug.Log("Hilo 1");
        }
        DecodeAndExecute();


        threadsDuration[currentThread]++;

        quantumCounter++;
        if (quantumCounter == quantum) // si el hilo ya "acabo" su quantum
        {
            SwitchContext();           // Cambiar de contexto
        }
    }
예제 #3
0
    public void UpdateInstructionCacheUI()
    {
        if (instructionCache == null)
        {
            GetInstructionCache();
        }

        for (int i = 0; i < CacheConstants.Blocks; i++)
        {
            blocks[i].w0.text = instructionCache.GetInstruction(i, 0).Code.ToString();
            blocks[i].w1.text = instructionCache.GetInstruction(i, 1).Code.ToString();

            blocks[i].tag.text = TBL.InstIndexToDir(instructionCache.GetTag(i)).ToString();
        }
    }
예제 #4
0
    public void UpdateDataCacheUI()
    {
        if (dataCache == null)
        {
            GetDataCache();
        }

        for (int i = 0; i < CacheConstants.Blocks; i++)
        {
            blocks[i].w0.text  = dataCache.GetWord(i, 0).ToString();
            blocks[i].w1.text  = dataCache.GetWord(i, 1).ToString();
            blocks[i].tag.text = TBL.DataIndexToDir(dataCache.GetTag(i)).ToString();

            string status = dataCache.GetStatus(i);
            blocks[i].status.text = status;
        }
    }
예제 #5
0
        private void FillTBL()
        {
            DataColumn col = new DataColumn();

            col.Caption    = "ID";
            col.ColumnName = "ID";
            col.DataType   = System.Type.GetType("System.Int32");
            col.ReadOnly   = true;
            col.Unique     = true;
            TBL.Columns.Add(col);

            col            = new DataColumn();
            col.Caption    = "ID2";
            col.ColumnName = "ID2";
            col.DataType   = System.Type.GetType("System.Int32");
            col.ReadOnly   = true;
            col.Unique     = false;
            TBL.Columns.Add(col);

            col            = new DataColumn();
            col.Caption    = "Name";
            col.ColumnName = "Name";
            col.DataType   = System.Type.GetType("System.String");
            col.ReadOnly   = true;
            col.Unique     = false;
            TBL.Columns.Add(col);

            DataRow row;

            for (int i = 0; i <= 2; i++)
            {
                row         = TBL.NewRow();
                row["ID"]   = i;
                row["ID2"]  = 2 * i;
                row["Name"] = "ParentItem " + i;
                TBL.Rows.Add(row);
            }
        }
예제 #6
0
    // Cargar programas a memoria
    // esta funcionalidad podria ser traspasada a otra clase
    void LoadPrograms(string[] programNames)
    {
        int i      = 0;
        int thread = 0;

        foreach (string program in programNames)
        {
            bool firstLine = true;

            if (!System.IO.File.Exists(program)) // si el archivo no existe
            {
                continue;                        // continuar con el siguiente
            }
            string[] lines = System.IO.File.ReadAllLines(program);
            foreach (string line in lines)
            {
                string[]    args            = line.Split(' ');
                int         instructionCode = int.Parse(args[0]);
                int         r1          = int.Parse(args[1]);
                int         r2          = int.Parse(args[2]);
                int         imm         = int.Parse(args[3]);
                Instruction instruction = new Instruction(instructionCode, r1, r2, imm);
                memory.WriteInstruction(i, instruction);

                if (firstLine)                           // guardar el inicio de ejecucion de cada hilo
                {
                    int instDir = TBL.InstIndexToDir(i); // direccion de la instruccion
                    contextMemory.SetPC(thread, instDir);
                    firstLine = false;
                    //Debug.Log("Hilo " + threads + " PC Inicial: " + instDir);
                }

                i++;
            }
            thread++;
        }
    }
예제 #7
0
        private static void Functions()
        {
            Console.Clear();
            if (choose == null || choose == "")
            {
                return;
            }

            if (choose[0] == '1' || choose[0] == '2')
            {
                FARC.Processor(choose == "1");
            }
            else if (choose[0] == '3')
            {
                Choose(1, "", out string[] FileNames);
                foreach (string FileName in FileNames)
                {
                    DIVAFILE.Decrypt(FileName);
                }
            }
            else if (choose[0] == '4')
            {
                Choose(1, "", out string[] FileNames);
                foreach (string FileName in FileNames)
                {
                    DIVAFILE.Encrypt(FileName);
                }
            }
            else if (choose[0] == '5')
            {
                DataBase.Processor(json, choose.Length > 1 ? choose[1] : '\0');
            }
            else if (choose[0] == '6')
            {
                string localChoose = "";
                if (choose.Length == 1)
                {
                    Console.Clear();
                    Console.Title = "AC/DT/F/AFT Converting Tools";
                    ConsoleDesign(true);
                    ConsoleDesign("               Choose converter:");
                    ConsoleDesign(false);
                    ConsoleDesign("1. A3DA");
                    ConsoleDesign("2. AET");
                    ConsoleDesign("3. DataBank");
                    ConsoleDesign("4. DEX");
                    ConsoleDesign("5. DIVA");
                    ConsoleDesign("6. MotHead");
                    ConsoleDesign("7. MOT");
                    ConsoleDesign("8. STR");
                    ConsoleDesign("9. Table");
                    ConsoleDesign(false);
                    ConsoleDesign("R. Return to Main Menu");
                    ConsoleDesign(false);
                    ConsoleDesign(true);
                    Console.WriteLine();
                    localChoose = Console.ReadLine().ToUpper();
                }
                else
                {
                    localChoose = choose[1].ToString();
                }
                if (localChoose == "1")
                {
                    A3D.Processor(json);
                }
                else if (localChoose == "2")
                {
                    AET.Processor(json);
                }
                else if (localChoose == "3")
                {
                    DB.Processor(json);
                }
                else if (localChoose == "4")
                {
                    DEX.Processor(json);
                }
                else if (localChoose == "5")
                {
                    DIV.Processor();
                }
                else if (localChoose == "6")
                {
                    MHD.Processor(json);
                }
                else if (localChoose == "7")
                {
                    MOT.Processor(json);
                }
                else if (localChoose == "8")
                {
                    STR.Processor(json);
                }
                else if (localChoose == "9")
                {
                    TBL.Processor(json);
                }
                else
                {
                    choose = localChoose;
                }
            }
            else if (choose[0] == '7')
            {
                string localChoose = "";
                if (choose.Length == 1)
                {
                    Console.Clear();
                    Console.Title = "F/F2/FT Converting Tools";
                    ConsoleDesign(true);
                    ConsoleDesign("               Choose converter:");
                    ConsoleDesign(false);
                    ConsoleDesign("1. A3DA");
                    ConsoleDesign("2. Bloom");
                    ConsoleDesign("3. Color Correction");
                    ConsoleDesign("4. DEX");
                    ConsoleDesign("5. DOF");
                    ConsoleDesign("6. Light");
                    ConsoleDesign("7. STR");
                    ConsoleDesign("8. VAG");
                    ConsoleDesign(false);
                    ConsoleDesign("R. Return to Main Menu");
                    ConsoleDesign(false);
                    ConsoleDesign(true);
                    Console.WriteLine();
                    localChoose = Console.ReadLine().ToUpper();
                }
                else
                {
                    localChoose = choose[1].ToString();
                }
                if (localChoose == "1")
                {
                    A3D.Processor(json);
                }
                else if (localChoose == "2")
                {
                    BLT.Processor(json);
                }
                else if (localChoose == "3")
                {
                    CCT.Processor(json);
                }
                else if (localChoose == "4")
                {
                    DEX.Processor(json);
                }
                else if (localChoose == "5")
                {
                    DFT.Processor(json);
                }
                else if (localChoose == "6")
                {
                    LIT.Processor(json);
                }
                else if (localChoose == "7")
                {
                    STR.Processor(json);
                }
                else if (localChoose == "8")
                {
                    VAG.Processor();
                }
                else
                {
                    choose = localChoose;
                }
            }
            else if (choose[0] == '8')
            {
                string localChoose = "";
                if (choose.Length == 1)
                {
                    Console.Clear();
                    Console.Title = "X/XHD Converting Tools";
                    ConsoleDesign(true);
                    ConsoleDesign("               Choose converter:");
                    ConsoleDesign(false);
                    ConsoleDesign("1. A3DA");
                    ConsoleDesign("2. Bloom");
                    ConsoleDesign("3. Color Correction");
                    ConsoleDesign("4. DEX");
                    ConsoleDesign("5. DOF");
                    ConsoleDesign("6. Light");
                    ConsoleDesign("7. VAG");
                    ConsoleDesign(false);
                    ConsoleDesign("R. Return to Main Menu");
                    ConsoleDesign(false);
                    ConsoleDesign(true);
                    Console.WriteLine();
                    localChoose = Console.ReadLine().ToUpper();
                }
                else
                {
                    localChoose = choose[1].ToString();
                }
                if (localChoose == "1")
                {
                    A3D.Processor(json);
                }
                else if (localChoose == "2")
                {
                    BLT.Processor(json);
                }
                else if (localChoose == "3")
                {
                    CCT.Processor(json);
                }
                else if (localChoose == "4")
                {
                    DEX.Processor(json);
                }
                else if (localChoose == "5")
                {
                    DFT.Processor(json);
                }
                else if (localChoose == "6")
                {
                    LIT.Processor(json);
                }
                else if (localChoose == "7")
                {
                    VAG.Processor();
                }
                else
                {
                    choose = localChoose;
                }
            }
            else if (choose[0] == '9')
            {
                string localChoose = "";
                if (choose.Length == 1)
                {
                    Console.Clear();
                    Console.Title = "FT/M39 Converting Tools";
                    ConsoleDesign(true);
                    ConsoleDesign("               Choose converter:");
                    ConsoleDesign(false);
                    ConsoleDesign("1. A3DA");
                    ConsoleDesign("2. AET");
                    ConsoleDesign("3. DEX");
                    ConsoleDesign("4. DIVA");
                    ConsoleDesign("5. MotHead");
                    ConsoleDesign("6. MOT");
                    ConsoleDesign("7. STR");
                    ConsoleDesign("8. Table");
                    ConsoleDesign(false);
                    ConsoleDesign("R. Return to Main Menu");
                    ConsoleDesign(false);
                    ConsoleDesign(true);
                    Console.WriteLine();
                    localChoose = Console.ReadLine().ToUpper();
                }
                else
                {
                    localChoose = choose[1].ToString();
                }
                if (localChoose == "1")
                {
                    A3D.Processor(json);
                }
                else if (localChoose == "2")
                {
                    AET.Processor(json);
                }
                else if (localChoose == "3")
                {
                    DEX.Processor(json);
                }
                else if (localChoose == "4")
                {
                    DIV.Processor();
                }
                else if (localChoose == "5")
                {
                    MHD.Processor(json);
                }
                else if (localChoose == "6")
                {
                    MOT.Processor(json);
                }
                else if (localChoose == "7")
                {
                    STR.Processor(json);
                }
                else if (localChoose == "8")
                {
                    TBL.Processor(json);
                }
                else
                {
                    choose = localChoose;
                }
            }
            else if (choose[0] == 'A')
            {
                Console.Title = json ? "MsgPack to JSON" : "JSON to MsgPack";
                Choose(1, json ? "mp" : "json", out string[] fileNames);
                foreach (string file in fileNames)
                {
                    if (json)
                    {
                        Console.Title = "MsgPack to JSON: " + Path.GetFileNameWithoutExtension(file);
                        Path.RemoveExtension(file).ToJSON();
                    }
                    else
                    {
                        Console.Title = "JSON to MsgPack: " + Path.GetFileNameWithoutExtension(file);
                        Path.RemoveExtension(file).ToMsgPack();
                    }
                }
            }
        }
예제 #8
0
    void DecodeAndExecute()
    {
        // Decode
        r1 = instructionRegister.Register1;
        r2 = instructionRegister.Register2;
        r3 = imm = instructionRegister.Immediate;

        // variables que se usan en diferentes casos
        int  dataDirection, val, address, sourceReg;
        bool writeHit;

        // Execute
        switch (instructionRegister.Code)
        {
        case 19:     // addi
            registers[r1] = registers[r2] + imm;
            break;

        case 71:     // add
            registers[r1] = registers[r2] + registers[r3];
            break;

        case 83:     // sub
            registers[r1] = registers[r2] - registers[r3];
            break;

        case 72:     // mul
            registers[r1] = registers[r2] * registers[r3];
            break;

        case 56:     // div
            registers[r1] = registers[r2] / registers[r3];
            break;

        case 5:     // lw
            MemoryAccess++;
            LoadAccess++;
            dataDirection = TBL.DataDirToIndex(imm + registers[r2]);
            val           = dataCache.Read(dataDirection);
            if (!dataCache.ReadMiss)     // lw hit
            {
                registers[r1] = val;
            }
            else     // lw miss
            {
                TotalCacheMisses++;
                LoadMisses++;
                dataCache.LoadBlock(dataDirection);     // Write Allocate
                val           = dataCache.Read(dataDirection);
                registers[r1] = val;
                clock        += ProcessorConstants.CacheMissDelay;
            }
            break;

        case 37:     // sw
            MemoryAccess++;
            StoreAccess++;
            address       = imm + registers[r1];
            sourceReg     = r2;
            dataDirection = TBL.DataDirToIndex(address);
            writeHit      = dataCache.Write(dataDirection, registers[sourceReg]);
            if (!writeHit)     // sw miss
            {
                TotalCacheMisses++;
                StoreMisses++;
                dataCache.LoadBlock(dataDirection);     // Write Allocate
                dataCache.Write(dataDirection, registers[sourceReg]);
                clock += ProcessorConstants.CacheMissDelay;
            }
            break;

        case 99:     // beq
            if (registers[r1] == registers[r2])
            {
                pcRegister += 4 * imm;
            }
            break;

        case 100:     //bne
            if (registers[r1] != registers[r2])
            {
                pcRegister += 4 * imm;
            }
            break;

        case 51:     // lr
            // x1 <- M[x2]
            dataDirection = TBL.DataDirToIndex(registers[r2]);
            val           = dataCache.Read(dataDirection);
            if (!dataCache.ReadMiss)     // lw hit
            {
                registers[r1] = val;
            }
            else                                    // lw miss
            {
                dataCache.LoadBlock(dataDirection); // Write Allocate
                val           = dataCache.Read(dataDirection);
                registers[r1] = val;
                clock        += ProcessorConstants.CacheMissDelay;
            }
            rl = registers[r2];     // RL <- x2
            break;

        case 52:     //sc
            int x1 = r2;
            int x2 = r1;
            if (RL == imm + registers[x2])
            {
                address       = imm + registers[x2];
                sourceReg     = x1;
                dataDirection = TBL.DataDirToIndex(address);
                writeHit      = dataCache.Write(dataDirection, registers[sourceReg]);
                if (!writeHit)                          // sw miss
                {
                    dataCache.LoadBlock(dataDirection); // Write Allocate
                    dataCache.Write(dataDirection, registers[sourceReg]);
                    clock += ProcessorConstants.CacheMissDelay;
                }
            }
            else
            {
                registers[x1] = 0;
            }
            break;

        case 111:     // jal
            registers[r1] = pcRegister;
            pcRegister   += imm;
            break;

        case 103:     // jalr
            registers[r1] = pcRegister;
            pcRegister    = registers[r2] + imm;
            break;

        case 999:                                               // end
            threadStates[currentThread] = ThreadState.Finished; // marcar que el thread actual finalizo
            Debug.Log("Hilo #" + currentThread + " finalizo.");
            SwitchContext();                                    // cambiar de contexto a siguiente hilo
            break;

        default:     // operacion no soportada
            Debug.Log("Instruccion no Soportada: " + instructionRegister);
            break;
        }
        clock++;
    }
예제 #9
0
        private DataTable parseJSON(string JSON, out string rowsaffected, out string err)
        {
            err          = "";
            rowsaffected = "";
            if (JSON.StartsWith("Error:"))
            {
                err = JSON;
                return(null);
            }

            JObject JData = JObject.Parse(JSON);

            if (JData == null)
            {
                return(null);
            }

            if (JData["result"] == null)
            {
                return(null);
            }

            if (JData["affected"] != null)
            {
                rowsaffected = JData["affected"].ToString();
            }


            DataTable  TBL = null;
            DataColumn col = null;
            DataRow    TableRows;
            bool       firstPass = true;

            foreach (var d in JData["result"])
            {
                //Console.WriteLine(d);
                Dictionary <string, object> tmp = Parse2(d.ToString());

                //setup the COLUMNS
                if (firstPass)
                {
                    TBL = new DataTable("TBL");
                    foreach (KeyValuePair <string, object> kvp in tmp)
                    {
                        col = new DataColumn(kvp.Key.ToString(), Type.GetType("System.String"));
                        TBL.Columns.Add(col);
                    }
                    TBL.AcceptChanges();

                    firstPass = false;
                }

                TableRows = TBL.NewRow();
                //add the rows!
                foreach (KeyValuePair <string, object> kvp in tmp)
                {
                    TableRows[kvp.Key.ToString()] = kvp.Value;
                }

                TBL.Rows.Add(TableRows);
            }

            //Console.WriteLine(TBL.Rows.Count.ToString());
            return(TBL);
            //Parse2(JData["result"].ToString());
            //return null;
            //foreach (var x in JData)
            //{
            //    string name = x.Key;
            //    JToken value = x.Value;

            //    //Console.WriteLine(name + " - " + value);

            //    foreach (var d in value)
            //    {
            //        //Console.WriteLine(d);
            //        Parse2(d.ToString());
            //    }
            //}
        }
예제 #10
0
    void ProcessInput()
    {
        string input = inputField.text;

        string[] words = input.Split(' ');
        //Debug.Log("input: " + input);
        bool validCommand = false;

        // comando clear
        if (input.Contains("clear"))
        {
            validCommand    = true;
            outputText.text = "";
        }
        // comando exists: revisa si archivo existe
        else if (words.Length == 2 && (words[0] == "exists" || words[0] == "e"))
        {
            validCommand = true;
            bool exists = System.IO.File.Exists(words[1]);
            outputText.text += exists ? "archivo existe\n" : "archivo no existe\n";
        }
        // comando esc: comando para salir de la aplicacion
        else if (words.Length == 1 && words[0] == "esc")
        {
            validCommand = true;
            Application.Quit();
        }
        // comando mem
        else if (words.Length == 2 && words[0] == "mem")
        {
            validCommand = true;
            int dir = TBL.DataDirToIndex(int.Parse(words[1]));
            outputText.text += processorComponent.processor.Memory.GetData(dir);
        }
        // comando abort
        else if (words.Length == 1 && words[0] == "abort")
        {
            validCommand     = true;
            outputText.text += "proceso terminado\n";
            processorComponent.Abort();
        }
        // comando results: para escribir en un txt los resultados de la ejecucion
        else if (words.Length == 1 && (words[0] == "r" || words[0] == "results"))
        {
            validCommand = true;
            processorComponent.processor.WriteResults("resultados.txt");
        }
        // comando debug
        else if (words.Length == 1 && (words[0] == "d" || words[0] == "debug"))
        {
            processorComponent.debug = !processorComponent.debug;
        }
        else if (words.Length > 0 && (words[0] == "start" || words[0] == "s"))
        {
            validCommand = true;

            if (words.Length != 7)
            {
                outputText.text += "formato de start no soportado\n";
            }
            else
            {
                int pParamIndex           = -1;
                int quantumParamIndex     = -1;
                int quantumTimeParamIndex = -1;
                int wordsCount            = words.Length;

                for (int i = 0; i < wordsCount; i++)
                {
                    if (pParamIndex == -1 && words[i] == "-p")
                    {
                        pParamIndex = i + 1;
                    }
                    else if (quantumParamIndex == -1 && words[i] == "-q")
                    {
                        quantumParamIndex = i + 1;
                    }
                    else if (quantumTimeParamIndex == -1 && words[i] == "-qt")
                    {
                        quantumTimeParamIndex = i + 1;
                    }
                }

                if (pParamIndex + quantumParamIndex + quantumTimeParamIndex > 3) // los tres parametros estan definidos
                {
                    string programsNameFileName = words[pParamIndex];
                    bool   qpR  = int.TryParse(words[quantumParamIndex], out int quantum);
                    bool   qtpR = float.TryParse(words[quantumTimeParamIndex], out float quantumTime);

                    if (qpR && qtpR) // argumentos validos
                    {
                        if (System.IO.File.Exists(programsNameFileName))
                        {
                            string[] programNames = System.IO.File.ReadAllLines(programsNameFileName);
                            processorComponent.StartProcessor(programNames, quantum, quantumTime);
                            outputText.text += "archivo: " + programsNameFileName +
                                               "\nquantum: " + quantum +
                                               "\ntiempo quantum: " + quantumTime + "\n";
                        }
                        else
                        {
                            outputText.text += "archivo no existe\n";
                        }
                    }
                    else
                    {
                        outputText.text += "start argumentos invalidos\n";
                    }
                }
            }
        }

        if (!validCommand)
        {
            outputText.text += "comando invalido\n";
        }

        inputField.text = "";
        inputField.Select();
    }
예제 #11
0
 public ActionResult UyeEkle(TBL p1)
 {
     db.TBLs.Add(p1);
     db.SaveChanges();
     return(View());
 }