예제 #1
0
        public void AddOverflowMethodTest()
        {
            var array1 = new ExtendedBitArray("11111111");
            var array2 = new ExtendedBitArray("00000001");

            Assert.IsTrue(array1.Add(array2));
        }
예제 #2
0
        public override ExtendedBitArray GetMemory(int address)
        {
            switch (address - _baseAddress)
            {
            case 0:
                _hBuffer = new ExtendedBitArray(_tcntH);
                return(_tcntL);

            case 2:
                _hBuffer = new ExtendedBitArray(_ocrH);
                return(_ocrL);

            case 4:
                _hBuffer = new ExtendedBitArray(_icrH);
                return(_icrL);

            case 6:
                _hBuffer = new ExtendedBitArray(_tscrH);
                return(_tscrL);

            case 1:
            case 3:
            case 5:
            case 7:
                return(_hBuffer);
            }
            return(new ExtendedBitArray());
        }
            private static void POP(string[] args, CompilerEnvironment env)
            {
                if (args.Length != 1)
                {
                    throw new CompilationErrorExcepton("Оператор POP должен принимать 1 аргумент.", env.GetCurrentLine());
                }
                var r = CompilerSupport.ConvertToRegister(args[0]);

                if (!r.HasValue)
                {
                    throw new CompilationErrorExcepton("Аргументом должен быть регистр.", env.GetCurrentLine());
                }
                var registr = r.Value;

                if (!registr.IsDirect)
                {
                    throw new CompilationErrorExcepton("Адресация регистра должна быть прямой.", env.GetCurrentLine());
                }
                var highBitArray = new ExtendedBitArray()
                {
                    [6] = true,
                    [4] = true,
                    [3] = true,
                    [2] = true,
                    [0] = true
                };
                var lowBitArray = new ExtendedBitArray();

                CompilerSupport.FillBitArray(null, lowBitArray, registr.Number, 4);

                env.SetByte(lowBitArray);
                env.SetByte(highBitArray);
            }
예제 #4
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();
 }
예제 #5
0
        public override void SetMemory(ExtendedBitArray memory, int address)
        {
            switch (address - _baseAddress)
            {
            case 0:
                _addr = memory;
                break;

            case 2:
                _cr = memory;
                break;

            case 3:
                _sr = memory;
                break;

            case 4:
                SetVideoMem(memory);
                break;
            }

            if (IsEnabled())
            {
                for (var reg = 0; reg < _videoMem.Length; reg++)
                {
                    SetSymbols(reg, _videoMem[reg]);
                }
                SizeBuffer();
            }

            if (!_cr[0] || _cr[7])
            {
                ResetButtonClicked();
            }
        }
예제 #6
0
        private void WriteBitCmd(ExtendedBitArray cmd, int address)
        {
            bool value    = cmd[0];
            int  bitIndex = (cmd.NumValue() & 0xF) >> 1;

            SetMemoryBit(value, address, bitIndex);
        }
예제 #7
0
        /// <summary>
        /// Функция, вызываемая при изменении пользователем текста в ячейке памяти.
        /// Помещает новое значение ячейки в память или выводит сообщение об ощибке, если введено некорректное число.
        /// </summary>
        /// <param name="row">Строка измененной ячейки.</param>
        /// <param name="collumn">Столбец измененной ячейки.</param>
        /// <param name="s">Строка, введенная в ячейку.</param>
        public void MemoryChanged(int row, int collumn, string s)
        {
            int num;

            try {
                num = Convert.ToInt32(s, 16);
                if (num > 255 || num < 0)
                {
                    _forms.First()?.ShowMessage("Число должно быть от 0 до FF");
                    _forms.ForEach(x => x.SetMemory(row, collumn, MemoryHex(row, collumn)));
                    return;
                }
            } catch {
                _forms.First()?.ShowMessage("Введено некорректное число");
                _forms.ForEach(x => x.SetMemory(row, collumn, MemoryHex(row, collumn)));
                return;
            }
            var bitArray = new ExtendedBitArray();

            CompilerSupport.FillBitArray(null, bitArray, num, 8);
            _memory[row * MemoryForm.ColumnCount + collumn] = bitArray;
            if (s.Length == 1)
            {
                s = "0" + s;
            }
            s = s.ToUpper();
            _forms.ForEach(x => x.SetMemory(row, collumn, s));
        }
예제 #8
0
        public virtual void SetMemoryBit(bool value, int address, int bitIndex)
        {
            ExtendedBitArray byteValue = GetMemory(address);

            byteValue[bitIndex] = value;
            SetMemory(byteValue, address);
        }
예제 #9
0
        private void _perform_mul()
        {
            int result = _acc.NumValue() * _rdb.NumValue();

            _registers[0] = new ExtendedBitArray(result & 0xFF);
            _registers[1] = new ExtendedBitArray((result >> 8) & 0xFF);
        }
예제 #10
0
        private void _y23()
        {
            var temp = _acc;

            _acc = _rdb;
            _rdb = temp;
        }
예제 #11
0
        public override void SetMemory(ExtendedBitArray memory, int address)
        {
            switch (address - _baseAddress)
            {
            case 0:
                if (IsEnabled())
                {
                    _arL = memory;
                }
                break;

            case 1:
                if (IsEnabled())
                {
                    _arH = memory;
                }
                break;

            case 2:
                SetDr(memory);
                NextAddress();
                break;

            case 3:
                _cr = memory;
                if (IsRedraw())
                {
                    DrawMemory();
                    Draw();
                }
                break;
            }
        }
예제 #12
0
        public void CopyConstructorTest()
        {
            var ExtendedBitArray = new ExtendedBitArray("00110000");
            var copy             = new ExtendedBitArray(ExtendedBitArray);

            Assert.AreEqual(ExtendedBitArray.ToBinString(), copy.ToBinString());
        }
예제 #13
0
        public void SetDr(ExtendedBitArray value)
        {
            if (IsEnabled())
            {
                _dr = value;

                if (IsPalette())
                {
                    int address        = _arL.NumValue() & 63;
                    int colorIndex     = address / 4;
                    int colorComponent = address % 4;


                    switch (colorComponent)
                    {
                    case 0:
                        colors[colorIndex] = Color.FromArgb(_dr.NumValue(), colors[colorIndex].R, colors[colorIndex].G, colors[colorIndex].B);
                        break;

                    case 1:
                        colors[colorIndex] = Color.FromArgb(colors[colorIndex].A, _dr.NumValue(), colors[colorIndex].G, colors[colorIndex].B);
                        break;

                    case 2:
                        colors[colorIndex] = Color.FromArgb(colors[colorIndex].A, colors[colorIndex].R, _dr.NumValue(), colors[colorIndex].B);
                        break;

                    case 3:
                        colors[colorIndex] = Color.FromArgb(colors[colorIndex].A, colors[colorIndex].R, colors[colorIndex].G, _dr.NumValue());
                        break;
                    }

                    if (_form1 != null)
                    {
                        _form1.SetPalette(colorIndex, colors[colorIndex]);
                        _form1.ShowColor(colorIndex, colors[colorIndex]);
                    }

                    if (IsRedraw())
                    {
                        DrawMemory();
                        Draw();
                    }
                }

                else
                {
                    int address = 256 * (_arH.NumValue() & 15) + _arL.NumValue();

                    SetVideomemory(_dr, address);
                    ChangeTwoPixels(_arH, _arL);

                    if (IsRedraw())
                    {
                        Draw();
                    }
                }
            }
        }
예제 #14
0
        /// Устанавливает переданный байт по переданному адресу
        public void SetMemory(ExtendedBitArray memory, int address)
        {
            _memory[address] = memory;
            int i = address / MemoryForm.ColumnCount;
            int j = address % MemoryForm.ColumnCount;

            _forms.ForEach(x => x.SetMemory(i, j, MemoryHex(i, j)));
        }
예제 #15
0
        public void ResetButtonClicked()
        {
            _form.ClearScreen();

            _cr = new ExtendedBitArray();
            _ar = new ExtendedBitArray();

            UpdateForm();
        }
예제 #16
0
        private void _y68()
        {
            var bitNumber = _cr[1].NumValue() & 0x7;

            _rdb = new ExtendedBitArray()
            {
                [0] = GetExternalMemoryBit(_rab, bitNumber)
            };
        }
예제 #17
0
        public void ResetButtonClicked()
        {
            _form.ClearBuffer();

            _readIndex = 0;
            _cr        = new ExtendedBitArray();
            _sr        = new ExtendedBitArray();

            _form.Invoke(_updateFormDelegate);
        }
예제 #18
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);
        }
예제 #19
0
        public void GetBitTest()
        {
            var code  = "00100101";
            var array = new ExtendedBitArray(code);

            for (int i = 0; i < 8; i++)
            {
                Assert.AreEqual(array[i], code[7 - i] == '1');
            }
        }
예제 #20
0
        private void _y53()
        {
            var temp = new ExtendedBitArray();

            for (int i = 0; i < Constants.WordSize; i++)
            {
                temp[i] = _rdb[(i + Constants.WordSize / 2) % Constants.WordSize];
            }
            _rdb = temp;
        }
예제 #21
0
        public void VideomemoryChange(int row, int column, object o)
        {
            if (o == null)

            {
                _form2.ShowMessage("Должно быть введено число от 0 до FF");
                _form2.SetMemory(row, column, VideomemoryHex(row, column));
                return;
            }
            string s = o.ToString();

            if (s.Length > 2)
            {
                _form2.ShowMessage("Должно быть введено число от 0 до FF");
                _form2.SetMemory(row, column, VideomemoryHex(row, column));
                return;
            }

            int num;

            try
            {
                num = Convert.ToInt32(s, 16);
                if (num > 255 || num < 0)
                {
                    _form2.SetMemory(row, column, VideomemoryHex(row, column));
                    return;
                }
            }
            catch
            {
                _form2.ShowMessage("Должно быть введено число от 0 до FF");
                _form2.SetMemory(row, column, VideomemoryHex(row, column));
                return;
            }
            var bitArray = new ExtendedBitArray();

            CompilerSupport.FillBitArray(null, bitArray, num, 8);
            _videomemory[row * VideomemoryForm.ColumnCount + column] = bitArray;
            if (s.Length == 1)
            {
                s = "0" + s;
            }
            s = s.ToUpper();
            _form2.SetMemory(row, column, s);


            if (IsRedraw())
            {
                ChangeTwoPixels(row, column);
                Draw();
            }

            UpdateForm();
        }
예제 #22
0
        public void SetVideomemory(ExtendedBitArray memory, int address)
        {
            _videomemory[address] = memory;
            int i = address / VideomemoryForm.ColumnCount;
            int j = address % VideomemoryForm.ColumnCount;

            if (_form2 != null)
            {
                _form2.SetMemory(i, j, VideomemoryHex(i, j));
            }
        }
예제 #23
0
        public override void OpenForm()
        {
            colors[0] = Color.FromArgb(255, 0, 0, 0);

            colors[1] = Color.FromArgb(255, 0, 0, 255);

            colors[2] = Color.FromArgb(255, 0, 255, 0);

            colors[3] = Color.FromArgb(255, 255, 0, 0);

            colors[5] = Color.FromArgb(255, 255, 255, 0);

            colors[6] = Color.FromArgb(255, 255, 0, 255);

            colors[7] = Color.FromArgb(255, 0, 255, 255);

            colors[8] = Color.FromArgb(255, 255, 255, 255);


            colors[9] = Color.FromArgb(255, 127, 127, 0);

            colors[10] = Color.FromArgb(255, 127, 0, 127);

            colors[11] = Color.FromArgb(255, 0, 127, 127);

            colors[12] = Color.FromArgb(255, 127, 127, 255);

            colors[13] = Color.FromArgb(255, 127, 255, 127);

            colors[14] = Color.FromArgb(255, 255, 127, 127);

            colors[15] = Color.FromArgb(255, 127, 127, 127);



            for (int i = 0; i < 4096; i++)
            {
                _videomemory[i] = new ExtendedBitArray("0");
            }

            if (_form == null)

            {
                _form = new GraphicDisplayForm(this);
            }

            Pixels = new Bitmap(_form.GetScreen().Width, _form.GetScreen().Height);

            _form.ShowDeviceParameters(_baseAddress);
            DrawMemory();
            Draw();
            _form.Show();
            UpdateForm();
        }
예제 #24
0
 public void SetExternalMemory(ExtendedBitArray memory, int address)
 {
     foreach (var device in _devices)
     {
         if (device.HasMemory(address))
         {
             device.SetMemory(memory, address);
             break;
         }
     }
 }
예제 #25
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();
 }
예제 #26
0
        public void IntConstructorTestFail()
        {
            var array = new List <int> {
                -1, 256, 5000
            };

            foreach (var code in array)
            {
                var extendedBitArray = new ExtendedBitArray(code);
            }
        }
예제 #27
0
            private static void EI(string[] args, CompilerEnvironment env)
            {
                ValidateNoAddressCommand(args, "EI", env.GetCurrentLine());
                var array = new ExtendedBitArray()
                {
                    [2] = true
                };

                env.SetByte(array);
                env.SetByte(new ExtendedBitArray());
            }
예제 #28
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);
            }
        }
예제 #29
0
            private static void CALL(string[] args, CompilerEnvironment env)
            {
                Validate(args, "CALL", env.GetCurrentLine());

                var highBitArray = new ExtendedBitArray();
                var lowBitArray  = new ExtendedBitArray();

                highBitArray[3] = true;
                highBitArray[6] = true;

                FillAddressAndSetCommand(highBitArray, lowBitArray, args[0], env);
            }
예제 #30
0
 private void _y9()
 {
     _acc = new ExtendedBitArray()
     {
         [0] = (_cs & 1) != 0,
         [1] = (_cs & 2) != 0,
         [2] = (_ds & 1) != 0,
         [3] = (_ds & 2) != 0,
         [4] = (_ss & 1) != 0,
         [5] = (_ss & 2) != 0
     };
 }