Exemplo n.º 1
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();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void WriteBitCmd(ExtendedBitArray cmd, int address)
        {
            bool value    = cmd[0];
            int  bitIndex = (cmd.NumValue() & 0xF) >> 1;

            SetMemoryBit(value, address, bitIndex);
        }
Exemplo n.º 3
0
        //установка символа и точки в сегменте по видеопамяти
        private void SetSymbols(int index, ExtendedBitArray symbol)
        {
            int pointPosition = _form.PointPosition;

            if (index >= _form.SevenSegmentCount)
            {
                return;
            }
            //установка точки
            _form.sevenSegments[index].DecimalOn = symbol[pointPosition];
            //установка символа
            if (pointPosition == 7)
            {
                _form.sevenSegments[index].CustomPattern = symbol.NumValue();
            }
            else
            {
                _form.sevenSegments[index].CustomPattern = symbol.NumValue() >> 1;
            }
        }
Exemplo n.º 4
0
        public ExtendedBitArray GetDr()
        {
            if (IsPalette())
            {
                byte palette = 0;

                int address = _arL.NumValue() & 63;

                switch (address % 4)
                {
                case 0:
                    palette = colors[address / 4].A;
                    break;

                case 1:
                    palette = colors[address / 4].R;
                    break;

                case 2:
                    palette = colors[address / 4].G;
                    break;

                case 3:
                    palette = colors[address / 4].B;

                    break;
                }

                return(new ExtendedBitArray(palette));
            }

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

                return(new ExtendedBitArray(_videomemory[address]));
            }
        }
Exemplo n.º 5
0
        private void SetDr(ExtendedBitArray value)
        {
            if (IsEnabled() && 0 <= _ar.NumValue() && _ar.NumValue() < 8 * 16 + 7)
            {
                int lineIndex = _ar.NumValue() / 16;
                int linePos   = _ar.NumValue() % 16;

                int textBoxIndex = lineIndex * 18 + linePos;

                string s         = cp1251.GetString(new byte[] { (byte)value.NumValue() });
                char   character = s[0];

                _form.Invoke(_updateFormDelegate, textBoxIndex, character);
            }
        }
Exemplo n.º 6
0
        private ExtendedBitArray GetDr()
        {
            if (0 <= _ar.NumValue() && _ar.NumValue() < 8 * 16 + 7)
            {
                int lineIndex = _ar.NumValue() / 16;
                int linePos   = _ar.NumValue() % 16;

                int  textBoxIndex = lineIndex * 18 + linePos;
                char character    = _form.GetCharacter(textBoxIndex);

                byte[] bs = cp1251.GetBytes(new char[] { character });
                byte   b  = bs[0];

                return(new ExtendedBitArray(b));
            }

            return(new ExtendedBitArray());
        }
Exemplo n.º 7
0
        private void OnTimerEvent(object sender, MicroTimerEventArgs e)
        {
            if (++_internalCounter < GetDividerMode())
            {
                return;
            }

            _internalCounter = 0;

            if (_tcntL.Inc())
            {
                if (_tcntH.Inc())
                {
                    SetOverflowFlag(true);
                }
            }
            byte mode = GetMode();

            if (mode == 2)   // сравнение
            {
                if (_tcntL.NumValue() == _tiorL.NumValue() && _tcntH.NumValue() == _tiorH.NumValue())
                {
                    SetComparisonFlag(true);

                    if (IsResetOnCmp())
                    {
                        _tcntH = new ExtendedBitArray();
                        _tcntL = new ExtendedBitArray();
                    }
                }
            }

            double nowMillis = DateTime.Now.ToUniversalTime().Subtract(
                new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                ).TotalMilliseconds;

            if (nowMillis - _lastUpdateMillis > UPDATE_PERIOD_MILLIS)
            {
                _form.Invoke(_updateFormDelegate);
                _lastUpdateMillis = nowMillis;
            }
        }
Exemplo n.º 8
0
        public void ChangeTwoPixels(ExtendedBitArray _arH, ExtendedBitArray _arL)
        {
            int address = (256 * _arH.NumValue() + _arL.NumValue()) & 4095;

            ExtendedBitArray data = new ExtendedBitArray(_videomemory[address]);


            lock (new object())
            {
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        Pixels.SetPixel(GetCoordinates(address)[0] + j, GetCoordinates(address)[1] + i, colors[data.NumValue() & 15]);

                        Pixels.SetPixel(GetCoordinates(address)[2] + j, GetCoordinates(address)[3] + i, colors[data.NumValue() >> 4]);
                    }
                }
            }
        }
Exemplo n.º 9
0
        public override void SetMemory(ExtendedBitArray memory, int address)
        {
            int localAddress = address - _baseAddress;

            switch (localAddress)
            {
            case 0:
                _tcntL = memory;
                _tcntH = new ExtendedBitArray(_hBuffer);
                break;

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

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

            case 6:
                _tscrL = memory;
                break;

            case 7:
                var value = memory.NumValue() & 0x1F | _tscrH.NumValue() & 0xE0;
                _tscrH = new ExtendedBitArray(value);
                break;

            case 1:
            case 3:
            case 5:
                _hBuffer = new ExtendedBitArray(memory);
                break;
            }
            ApplySettings();
        }
Exemplo n.º 10
0
        public override void SetMemory(ExtendedBitArray memory, int address)
        {
            int localAddress = address - _baseAddress;

            if (4 <= localAddress && localAddress <= 5 && memory[7])
            {
                WriteBitCmd(memory, address);
                return;
            }

            switch (localAddress)
            {
            case 0:
                _tcntL = memory;
                _tcntH = new ExtendedBitArray(_hBuffer);
                break;

            case 2:
                _tiorL = memory;
                _tiorH = new ExtendedBitArray(_hBuffer);
                break;

            case 4:
                _tscrL = memory;
                var value = _hBuffer.NumValue() & 0xF1 | _tscrH.NumValue() & 0x0E;
                _tscrH = new ExtendedBitArray(value);
                break;

            case 1:
            case 3:
            case 5:
                _hBuffer = new ExtendedBitArray(memory);
                break;
            }
            ApplySettings();
        }
Exemplo n.º 11
0
        public void DrawMemory()

        {
            ExtendedBitArray _arL1 = new ExtendedBitArray();
            ExtendedBitArray _arH1 = new ExtendedBitArray();


            bool maxmemory = false;

            while (!maxmemory)
            {
                ChangeTwoPixels(_arH1, _arL1);

                if (_arL1.NumValue() == 255)
                {
                    if (_arH1.NumValue() == 15)
                    {
                        maxmemory = true;
                    }
                    _arH1.Inc();
                }
                _arL1.Inc();
            }
        }
Exemplo n.º 12
0
 public bool HasInterruptionRequests()
 {
     lock (_lock) {
         return(_irqs.NumValue() != 0);
     }
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        private void ProcessNonAddressCommands(string lowHex)
        {
            //NOP
            if (lowHex == "01")
            {
                //Do nothing
            }

            //RET
            if (lowHex == "02")
            {
                _y45();
                _y1();
                _y34();

                _y29();

                _y45();
                _y1();
                _y34();

                _y33();
            }

            //IRET
            if (lowHex == "03")
            {
                _y45();
                _y1();
                _y34();

                _y37();
                _y29();

                _y45();
                _y1();
                _y34();

                _y33();
                _y66();
            }

            //EI
            if (lowHex == "04")
            {
                _flags.I = true;
            }

            //DI
            if (lowHex == "05")
            {
                _flags.I = false;
            }

            //RR
            if (lowHex == "06")
            {
                _y11();
            }

            //RL
            if (lowHex == "07")
            {
                _y12();
            }

            //RRC
            if (lowHex == "08")
            {
                _y13();
            }

            //RLC
            if (lowHex == "09")
            {
                _y14();
            }

            //HLT
            if (lowHex == "0A")
            {
                _shouldStopRunning = true;
            }

            //INCA
            if (lowHex == "0B")
            {
                _flags.SetPreviousState(_acc);
                var overflow = _acc.Inc();
                _flags.UpdateFlags(_acc, "inc", overflow);
            }

            //DECA
            if (lowHex == "0C")
            {
                _flags.SetPreviousState(_acc);
                var overflow = _acc.Dec();
                _flags.UpdateFlags(_acc, "dec", overflow);
            }

            //SWAPA
            if (lowHex == "0D")
            {
                _y18();
            }

            //DAA
            if (lowHex == "0E")
            {
                _flags.SetPreviousState(_acc);
                var temp = new ExtendedBitArray(_acc);
                temp.And(new ExtendedBitArray("00001111"));
                if (temp.NumValue() > 9 || _flags.A)
                {
                    _y19();
                }
                temp = new ExtendedBitArray(_acc);
                temp.And(new ExtendedBitArray("11110000"));
                if (temp.NumValue() > 144 || _flags.C)
                {
                    _y20();
                }
                _flags.UpdateFlags(_acc, "daa", _flags.C);
            }

            //DSA
            if (lowHex == "0F")
            {
                _flags.SetPreviousState(_acc);
                if (_flags.A)
                {
                    _y21();
                }
                if (_flags.C)
                {
                    _y22();
                }
                _flags.UpdateFlags(_acc, "dsa", _flags.C);
            }

            //IN
            if (lowHex == "10")
            {
            }

            //OUT
            if (lowHex == "11")
            {
            }

            //ES
            if (lowHex == "12")
            {
                _flags.Flags[6] = !_flags.Flags[6];
            }

            //MOVASR
            if (lowHex == "13")
            {
                _y9();
            }

            //MOVSRA
            if (lowHex == "14")
            {
                _y28();
            }

            //NOTA
            if (lowHex == "15")
            {
                _flags.SetPreviousState(_acc);
                _y17();
                _flags.UpdateFlags(_acc, "not");
            }
        }
Exemplo n.º 15
0
        /// Определяет к какой группе относится команда и запускает специфичный обработчик
        private void RunCommand()
        {
            var highBin = _cr[1].ToBinString();
            var highHex = _cr[1].ToHexString();
            var lowBin  = _cr[0].ToBinString();
            var lowHex  = _cr[0].ToHexString();

            //Регистровые
            if (highHex[0] == '5' || highHex == "F0" || highHex == "F1")
            {
                ProcessRegisterCommand(highHex, lowBin);
            }

            //ОЗУ
            if (highBin.StartsWith("011"))
            {
                ProcessRamCommand(highBin, highHex);
            }

            //Переходы
            if (highBin.StartsWith("0100") || highBin.StartsWith("001"))
            {
                ProcessJumpCommand(highBin);
            }

            //DJRNZ
            if (highBin.StartsWith("0001"))
            {
                _y63();
                _y2();
                var overflow = _rdb.Dec();
                if (_rdb.NumValue() != 0)
                {
                    Jump();
                }
                _y5();
            }

            //безадресные команды
            if (highBin.StartsWith("0000"))
            {
                ProcessNonAddressCommands(lowHex);
            }

            //Битовые команды
            if (highBin.StartsWith("1000") || highBin.StartsWith("1001"))
            {
                ProcessBitCommands(highBin, highHex, lowBin, lowHex);
            }

            //Битовые команды с регистрами ввода/вывода
            if (highBin.StartsWith("1010") || highBin.StartsWith("1011"))
            {
                ProcessIOBitCommands(highBin, highHex, lowBin, lowHex);
            }

            //Команды ввода/вывода
            if (highBin.StartsWith("1100"))
            {
                ProcessIOCommand(highBin, highHex, lowBin, lowHex);
            }

            if (_cr[0].NumValue() == 0 && _cr[1].NumValue() == 0)
            {
                _shouldStopRunning = true;
            }
        }
Exemplo n.º 16
0
        public void ChangeTwoPixels(int row, int column)
        {
            int address = 16 * row + column;

            ExtendedBitArray data = new ExtendedBitArray(_videomemory[address]);

            lock (new object())
            {
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        Pixels.SetPixel(GetCoordinates(address)[0] + j, GetCoordinates(address)[1] + i, colors[data.NumValue() & 15]);

                        Pixels.SetPixel(GetCoordinates(address)[2] + j, GetCoordinates(address)[3] + i, colors[data.NumValue() >> 4]);
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void OnTimerEvent(object sender, MicroTimerEventArgs e)
        {
            if (++_internalCounter < GetDivider())
            {
                return;
            }

            _internalCounter = 0;

            bool equalUpperLimit = _tcntL.NumValue() == upperLimit[0].NumValue() && _tcntH.NumValue() == upperLimit[1].NumValue();
            bool equalLowerLimit = _tcntL.NumValue() == 0 && _tcntH.NumValue() == 0;

            // Инкремент/декремент
            if (dec)
            {
                if (_tcntL.Dec())
                {
                    if (_tcntH.Dec())
                    {
                        // 0000 -> FFFF underflow
                        Console.WriteLine("Shouldn't normally happen! 0000.Dec()");
                    }
                }
            }
            else
            {
                if (equalUpperLimit)
                {
                    _tcntL.And(new ExtendedBitArray());
                    _tcntH.And(new ExtendedBitArray());

                    SetOverflowFlag(true);
                }
                else if (_tcntL.Inc())
                {
                    if (_tcntH.Inc())
                    {
                        // FFFF -> 0000 overflow
                        Console.WriteLine("Shouldn't normally happen! FFFF.Inc()");
                        SetOverflowFlag(true);
                    }
                }
            }

            equalUpperLimit = _tcntL.NumValue() == upperLimit[0].NumValue() && _tcntH.NumValue() == upperLimit[1].NumValue();
            equalLowerLimit = _tcntL.NumValue() == 0 && _tcntH.NumValue() == 0;
            bool equalTcntOcr = _tcntL.NumValue() == _ocrL.NumValue() && _tcntH.NumValue() == _ocrH.NumValue();

            byte mode = GetMode();

            switch (mode)
            {
            case 1:     // сброс при совпадении
                if (equalTcntOcr)
                {
                    SetComparisonFlag(true);

                    _tcntH = new ExtendedBitArray();
                    _tcntL = new ExtendedBitArray();
                }
                break;

            case 2:     // быстрый ШИМ
                break;

            case 3:     // ШИМ с фазовой коррекцией
                // проверка совпадения с верхним пределом
                if (equalUpperLimit)
                {
                    dec = true;
                }
                else if (equalLowerLimit)
                {
                    dec = false;
                }
                break;
            }

            byte outputMode = GetOutputMode();

            switch (outputMode)
            {
            case 0:
                outputPinValue = false;
                break;

            case 1:     // инверсия при совпадении TCNT == OCR
                if (equalTcntOcr)
                {
                    outputPinValue = !outputPinValue;
                }
                break;

            case 2:
                if (mode < 2)         // Без ШИМ
                {
                    if (equalTcntOcr) // сброс при совпадении
                    {
                        outputPinValue = false;
                    }
                }
                if (mode == 2)        // Быстрый ШИМ
                {
                    if (equalTcntOcr) // сброс при совпадении
                    {
                        outputPinValue = false;
                    }
                    else if (equalUpperLimit)         // установка на вершине счета
                    {
                        outputPinValue = true;
                    }
                }
                if (mode == 3)       // ШИМ с ФК
                {
                    if (equalTcntOcr)
                    {
                        if (dec)
                        {
                            outputPinValue = true;     // установка при совпадении во время обратного счета
                        }
                        else
                        {
                            outputPinValue = false;     // сброс при совпадении во время прямого счета
                        }
                    }
                }
                break;

            case 3:
                if (mode < 2)         // Без ШИМ
                {
                    if (equalTcntOcr) // установка при совпадении
                    {
                        outputPinValue = true;
                    }
                }
                if (mode == 2)        // Быстрый ШИМ
                {
                    if (equalTcntOcr) // установка при совпадении
                    {
                        outputPinValue = true;
                    }
                    else if (equalUpperLimit)         // сброс на вершине счета
                    {
                        outputPinValue = false;
                    }
                }
                if (mode == 3)       // ШИМ с ФК
                {
                    if (equalTcntOcr)
                    {
                        if (dec)
                        {
                            outputPinValue = false;     // сброс при совпадении во время обратного счета
                        }
                        else
                        {
                            outputPinValue = true;     // установка при совпадении во время прямого счета
                        }
                    }
                }
                break;
            }

            double nowMillis = DateTime.Now.ToUniversalTime().Subtract(
                new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                ).TotalMilliseconds;

            if (nowMillis - _lastUpdateMillis > UPDATE_PERIOD_MILLIS)
            {
                _form.Invoke(_updateFormDelegate);
                _lastUpdateMillis = nowMillis;
            }
        }
Exemplo n.º 18
0
 private void _y36()
 {
     _spl = Convert.ToByte(_acc.NumValue());
 }