Ejemplo n.º 1
0
        public void CopyConstructorTest()
        {
            var ExtendedBitArray = new ExtendedBitArray("00110000");
            var copy             = new ExtendedBitArray(ExtendedBitArray);

            Assert.AreEqual(ExtendedBitArray.ToBinString(), copy.ToBinString());
        }
Ejemplo n.º 2
0
 public void ShowRegisters(ExtendedBitArray _arL, ExtendedBitArray _arH, ExtendedBitArray _dr, ExtendedBitArray _cr)
 {
     arHBinTextBox.Text = _arH.ToBinString();
     arLBinTextBox.Text = _arL.ToBinString();
     drBinTextBox.Text  = _dr.ToBinString();
     crBinTextBox.Text  = _cr.ToBinString();
 }
Ejemplo n.º 3
0
        public DebugCommand(ExtendedBitArray lowCommand, ExtendedBitArray highCommand, int address)
        {
            Address      = address;
            _lowCommand  = lowCommand;
            _highCommand = highCommand;

            Command  = new string(highCommand.ToBinString().ToArray()) + ' ' + new string(lowCommand.ToBinString().ToArray());
            Name     = GetCommandName(lowCommand, highCommand);
            Argument = GetCommandArgument(lowCommand, highCommand);
        }
Ejemplo n.º 4
0
        public void SetBitTest()
        {
            var array = new ExtendedBitArray("00100101");

            array[1] = true;
            Assert.AreEqual(array.ToBinString(), "00100111");

            array[1] = true;
            Assert.AreEqual(array.ToBinString(), "00100111");

            array[1] = false;
            Assert.AreEqual(array.ToBinString(), "00100101");

            array[7] = false;
            Assert.AreEqual(array.ToBinString(), "00100101");

            array[7] = true;
            Assert.AreEqual(array.ToBinString(), "10100101");
        }
Ejemplo n.º 5
0
 public void ShowRegisters(ExtendedBitArray tcntH, ExtendedBitArray tcntL,
                           ExtendedBitArray tiorH, ExtendedBitArray tiorL,
                           ExtendedBitArray tscrH, ExtendedBitArray tscrL)
 {
     tcntHTextBox.Text = tcntH.ToBinString();
     tcntLTextBox.Text = tcntL.ToBinString();
     tiorHTextBox.Text = tiorH.ToBinString();
     tiorLTextBox.Text = tiorL.ToBinString();
     tscrHTextBox.Text = tscrH.ToBinString();
     tscrLTextBox.Text = tscrL.ToBinString();
 }
Ejemplo n.º 6
0
        public void ConstructorTest()
        {
            var array = new List <string> {
                "00001100", "01110111", "00011100", "01010101", "01010001"
            };

            foreach (var code in array)
            {
                var extendedBitArray = new ExtendedBitArray(code);
                Assert.AreEqual(extendedBitArray.ToBinString(), code);
            }
        }
Ejemplo n.º 7
0
        public void IntConstructorTest()
        {
            var array = new List <int> {
                0, 15, 255
            };
            var codes = new List <string> {
                "00000000", "00001111", "11111111"
            };

            for (var i = 0; i < array.Count; i++)
            {
                var extendedBitArray = new ExtendedBitArray(array[i]);
                Assert.AreEqual(extendedBitArray.ToBinString(), codes[i]);
            }
        }
Ejemplo n.º 8
0
        //установка видеопамяти
        private void SetVideoMem(ExtendedBitArray memory)
        {
            int index = new ExtendedBitArray(_addr.ToBinString().Substring(CountIgnoredBits())).NumValue();

            if (_form.SevenSegmentCount == 6)
            {
                index = index % 6;
            }

            _videoMem[index] = memory;

            if (IsAutoincrement())
            {
                _addr.Inc();
                _addr.Mod(new ExtendedBitArray(_form.SevenSegmentCount));
            }
        }
Ejemplo n.º 9
0
        public void ShowRegisters(ExtendedBitArray tcntH, ExtendedBitArray tcntL,
                                  ExtendedBitArray ocrH, ExtendedBitArray ocrL,
                                  ExtendedBitArray icrH, ExtendedBitArray icrL,
                                  ExtendedBitArray tscrH, ExtendedBitArray tscrL,
                                  bool outputPinValue)
        {
            tcntHTextBox.Text = tcntH.ToBinString();
            tcntLTextBox.Text = tcntL.ToBinString();
            ocrHTextBox.Text  = ocrH.ToBinString();
            ocrLTextBox.Text  = ocrL.ToBinString();
            icrHTextBox.Text  = icrH.ToBinString();
            icrLTextBox.Text  = icrL.ToBinString();
            tscrHTextBox.Text = tscrH.ToBinString();
            tscrLTextBox.Text = tscrL.ToBinString();

            outputPinTextBox.Text = outputPinValue ? "1" : "0";
        }
Ejemplo n.º 10
0
        public void ShowRegisters(ExtendedBitArray addr, ExtendedBitArray sym, ExtendedBitArray cr, ExtendedBitArray sr, ExtendedBitArray [] videoMem, Queue <ExtendedBitArray> keyBuffer)
        {
            addrBinTextBox.Text = addr.ToBinString();
            symBinTextBox.Text  = sym.ToBinString();
            crBinTextBox.Text   = cr.ToBinString();
            srBinTextBox.Text   = sr.ToBinString();

            StringBuilder strVideoMem = new StringBuilder();

            for (var line = 0; line < videoMem.Length; line++)
            {
                strVideoMem.Append(videoMem[line].ToBinString() + "\r");
            }
            videoMemBinTextBox.Text = strVideoMem.ToString();
            videoMemBinTextBox.SelectAll();
            videoMemBinTextBox.SelectionAlignment = HorizontalAlignment.Center;

            var bufferExtendedBitArrays = keyBuffer.ToArray();

            for (int col = 0; col < 8; col++)
            {
                bufferDataGridView[col, 0].Value = (col >= bufferExtendedBitArrays.Length) ? " " : bufferExtendedBitArrays[col].ToHexString().Substring(1);
            }
        }
Ejemplo n.º 11
0
        private string GetCommandArgument(ExtendedBitArray lowCommand, ExtendedBitArray highCommand)
        {
            var highBin = highCommand.ToBinString();
            var highHex = highCommand.ToHexString();
            var lowBin  = lowCommand.ToBinString();
            var lowHex  = lowCommand.ToHexString();

            // Безадресные
            if (highHex == "00")
            {
                return(null);
            }

            // DJRNZ
            if (highBin.StartsWith("0001"))
            {
                int    register = (highCommand.NumValue() >> 2) & 0b11;
                string segment  = (highCommand.NumValue() & 0b11).ToString();
                string address  = lowCommand.ToHexString();
                return(string.Format("R{0}, 0x{1}{2}", register.ToString(), segment, address));
            }

            // операторы перехода
            if (highBin.StartsWith("001"))
            {
                string segment = (highCommand.NumValue() & 0b11).ToString();
                string address = lowCommand.ToHexString();
                return(string.Format("0x{0}{1}", segment, address));
            }

            // Операторы передачи управления
            if (highBin.StartsWith("0100"))
            {
                string segment = (highCommand.NumValue() & 0b11).ToString();
                string address = lowCommand.ToHexString();
                return(string.Format("0x{0}{1}", segment, address));
            }

            // Регистровые команды
            //Прямая - 000
            //@R     - 100
            //@R+    - 001
            //+@R    - 101
            //@R-    - 011
            //-@R    - 111
            // 041537
            if (highBin.StartsWith("0101") || highBin.StartsWith("1111"))
            {
                //MOV R{0}, R{1}
                if (highBin.StartsWith("01011111"))
                {
                    int    registerSource      = lowCommand.NumValue() >> 4;
                    int    registerDestination = lowCommand.NumValue() & 0x0F;
                    string registerFormat      = "R{0}, R{1}";
                    return(string.Format(registerFormat, registerDestination, registerSource));
                }
                else
                {
                    int    addressType    = lowCommand.NumValue() >> 4;
                    int    register       = lowCommand.NumValue() & 0x0F;
                    string registerFormat = "R{0}";
                    switch (addressType)
                    {
                    case 0:
                        registerFormat = "R{0}";
                        break;

                    case 1:
                        registerFormat = "@R{0}";
                        break;

                    case 4:
                        registerFormat = "@R{0}+";
                        break;

                    case 5:
                        registerFormat = "+@R{0}";
                        break;

                    case 6:
                        registerFormat = "@R{0}-";
                        break;

                    case 7:
                        registerFormat = "-@R{0}";
                        break;
                    }
                    return(string.Format(registerFormat, register));
                }
            }

            // ОЗУ
            if (highBin.StartsWith("011"))
            {
                //Dec: lowCommand.NumValue().ToString();
                //Hex: lowHex.ToString();
                string addressOrConst = lowHex.ToString();
                bool   isConst        = highBin.StartsWith("0111");
                return((isConst ? "#0x" : "") + addressOrConst);
            }

            // Битовые команды
            if (highBin.StartsWith("100"))
            {
                string bit     = (highCommand.NumValue() & 0b111).ToString();
                string address = "0x" + lowCommand.ToHexString();//lowCommand.NumValue().ToString();
                return($"{address}, {bit}");
            }
            if (highBin.StartsWith("101"))
            {
                string           bit  = (highCommand.NumValue() & 0b111).ToString();
                ExtendedBitArray addr = new ExtendedBitArray(lowCommand);
                //addr.And(new ExtendedBitArray("0111111")); //зачем этот AND ???
                string address = "0x" + addr.ToHexString();//addr.NumValue().ToString();
                return($"{address}, {bit}");
            }

            // Команды ввода-вывода
            if (highBin == "11000000" || highBin == "11000001")
            {
                //string address = lowCommand.NumValue().ToString();
                string address = "0x" + lowCommand.ToHexString();
                return(address);
            }

            return(null);
        }
Ejemplo n.º 12
0
        private string GetCommandName(ExtendedBitArray lowCommand, ExtendedBitArray highCommand)
        {
            var highBin = highCommand.ToBinString();
            var highHex = highCommand.ToHexString();
            var lowBin  = lowCommand.ToBinString();
            var lowHex  = lowCommand.ToHexString();

            // Безадресные
            if (highHex == "00")
            {
                if (lowHex == "00")
                {
                    return("HLT");
                }
                if (lowHex == "01")
                {
                    return("NOP");
                }
                if (lowHex == "02")
                {
                    return("RET");
                }
                if (lowHex == "03")
                {
                    return("IRET");
                }
                if (lowHex == "04")
                {
                    return("EI");
                }
                if (lowHex == "05")
                {
                    return("DI");
                }
                if (lowHex == "06")
                {
                    return("RR");
                }
                if (lowHex == "07")
                {
                    return("RL");
                }
                if (lowHex == "08")
                {
                    return("RRC");
                }
                if (lowHex == "09")
                {
                    return("RLC");
                }
                if (lowHex == "0A")
                {
                    return("HLT");
                }
                if (lowHex == "0B")
                {
                    return("INCA");
                }
                if (lowHex == "0C")
                {
                    return("DECA");
                }
                if (lowHex == "0D")
                {
                    return("SWAPA");
                }
                if (lowHex == "0E")
                {
                    return("DAA");
                }
                if (lowHex == "0F")
                {
                    return("DSA");
                }
                if (lowHex == "10")
                {
                    return("IN");
                }
                if (lowHex == "11")
                {
                    return("OUT");
                }
                if (lowHex == "12")
                {
                    return("ES");
                }
                if (lowHex == "13")
                {
                    return("MOVASR");
                }
                if (lowHex == "14")
                {
                    return("MOVSRA");
                }
                if (lowHex == "15")
                {
                    return("NOTA");
                }
                if (lowHex == "16")
                {
                    return("MOVAPSW");
                }
            }

            // DJRNZ
            if (highBin.StartsWith("0001"))
            {
                return("DJRNZ");
            }

            // операторы перехода
            if (highBin.StartsWith("001"))
            {
                if (highBin.StartsWith("001100"))
                {
                    return("JZ");
                }
                if (highBin.StartsWith("001000"))
                {
                    return("JNZ");
                }
                if (highBin.StartsWith("001101"))
                {
                    return("JC");
                }
                if (highBin.StartsWith("001001"))
                {
                    return("JNC");
                }
                if (highBin.StartsWith("001110"))
                {
                    return("JN");
                }
                if (highBin.StartsWith("001010"))
                {
                    return("JNN");
                }
                if (highBin.StartsWith("001111"))
                {
                    return("JO");
                }
                if (highBin.StartsWith("001011"))
                {
                    return("JNO");
                }
            }

            // Операторы передачи управления
            if (highBin.StartsWith("0100"))
            {
                if (highBin.StartsWith("010000"))
                {
                    return("JMP");
                }
                if (highBin.StartsWith("010010"))
                {
                    return("CALL");
                }
                if (highBin.StartsWith("010011"))
                {
                    return("INT");
                }
            }

            // Регистровые команды
            if (highBin.StartsWith("0101"))
            {
                if (highHex[1] == 'F')
                {
                    return("MOV");
                }
                if (highHex[1] == 'D')
                {
                    return("POP");
                }
                if (highHex[1] == 'A')
                {
                    return("WR");
                }
                if (highHex[1] == '0')
                {
                    return("NOT");
                }
                if (highHex[1] == '1')
                {
                    return("ADD");
                }
                if (highHex[1] == '2')
                {
                    return("SUB");
                }
                if (highHex[1] == '3')
                {
                    return("MUL");
                }
                if (highHex[1] == '4')
                {
                    return("DIV");
                }
                if (highHex[1] == '5')
                {
                    return("AND");
                }
                if (highHex[1] == '6')
                {
                    return("OR");
                }
                if (highHex[1] == '7')
                {
                    return("XOR");
                }
                if (highHex[1] == '8')
                {
                    return("CMP");
                }
                if (highHex[1] == '9')
                {
                    return("RD");
                }
                if (highHex[1] == 'B')
                {
                    return("INC");
                }
                if (highHex[1] == 'C')
                {
                    return("DEC");
                }
                if (highHex[1] == 'E')
                {
                    return("PUSH");
                }
            }
            //дополнительные регистровые SUBB и ADC
            if (highBin.StartsWith("1111"))
            {
                if (highHex == "F0")
                {
                    return("ADC");
                }
                if (highHex == "F1")
                {
                    return("SUBB");
                }
            }
            // ОЗУ
            if (highBin.StartsWith("011"))
            {
                if (highHex[1] == 'A')
                {
                    return("WR");
                }
                if (highHex[1] == '0')
                {
                    return("NOT");
                }
                if (highHex[1] == '1')
                {
                    return("ADD");
                }
                if (highHex[1] == '2')
                {
                    return("SUB");
                }
                if (highHex[1] == '3')
                {
                    return("MUL");
                }
                if (highHex[1] == '4')
                {
                    return("DIV");
                }
                if (highHex[1] == '5')
                {
                    return("AND");
                }
                if (highHex[1] == '6')
                {
                    return("OR");
                }
                if (highHex[1] == '7')
                {
                    return("XOR");
                }
                if (highHex[1] == '8')
                {
                    return("CMP");
                }
                if (highHex[1] == '9')
                {
                    return("RD");
                }
                if (highHex[1] == 'B')
                {
                    return("INC");
                }
                if (highHex[1] == 'C')
                {
                    return("DEC");
                }
                if (highHex[1] == 'D')
                {
                    return("ADC");
                }
                if (highHex[1] == 'E')
                {
                    return("SUBB");
                }
                if (highHex[1] == 'F')
                {
                    return("XCH");
                }
            }

            // Битовые команды
            if (highBin.StartsWith("10000"))
            {
                return("CB");
            }
            if (highBin.StartsWith("10001"))
            {
                return("SB");
            }
            if (highBin.StartsWith("10010"))
            {
                return("SBC");
            }
            if (highBin.StartsWith("10011"))
            {
                return("SBS");
            }
            if (highBin.StartsWith("10100") && lowBin[0] == '1')
            {
                return("CBI");
            }
            if (highBin.StartsWith("10101") && lowBin[0] == '0')
            {
                return("SBI");
            }
            if (highBin.StartsWith("10101") && lowBin[0] == '1')
            {
                return("NBI");
            }
            if (highBin.StartsWith("10110") && lowBin[0] == '0')
            {
                return("SBIC");
            }
            if (highBin.StartsWith("10110") && lowBin[0] == '1')
            {
                return("SBIS");
            }
            if (highBin.StartsWith("10111") && lowBin[0] == '0')
            {
                return("SBISC");
            }

            // Команды ввода-вывода
            if (highBin == "11000000")
            {
                return("IN");
            }
            if (highBin == "11000001")
            {
                return("OUT");
            }

            return("ERROR");
        }
Ejemplo n.º 13
0
        public void EmptyConstructorTest()
        {
            var ExtendedBitArray = new ExtendedBitArray();

            Assert.AreEqual(ExtendedBitArray.ToBinString(), "00000000");
        }
Ejemplo n.º 14
0
 public void ShowRegisters(ExtendedBitArray dr, ExtendedBitArray cr, ExtendedBitArray sr)
 {
     drBinTextBox.Text = dr.ToBinString();
     crBinTextBox.Text = cr.ToBinString();
     srBinTextBox.Text = sr.ToBinString();
 }