Beispiel #1
0
        private int GetCursorPointedMemValue()
        {
            if (_focus == 0)
            {
                return(_emu8051.ReadMem(_memoryFrameMode, GetCursorPointedMemAddress()));
            }
            else if (_focus == 1)
            {
                return(_emu8051.ReadReg(_cursorPointedAddress));
            }
            else if (_focus == 2)
            {
                return(TGUIUtils.Get16BitHalfs((ushort)_emu8051.ReadReg(10))[_cursorPointedAddress]);
            }
            else if (_focus == 3)
            {
                return(_addrInputVal[_cursorPointedAddress]);
            }

            return(-1);
        }
Beispiel #2
0
        private void WriteVal(char val)
        {
            string hex = string.Empty;

            char[] halfs = TGUIUtils.Get8bitHalfs((byte)_cursorPointedDisplayValue);

            if (_writeCursorH)
            {
                hex           = halfs[0].ToString() + val.ToString();
                _writeCursorH = false;
                _currentCaretPos.X--;
            }
            else
            {
                hex = val.ToString() + halfs[1].ToString();
                _currentCaretPos.X++;
                _writeCursorH = true;
            }

            byte b = (byte)int.Parse(hex, System.Globalization.NumberStyles.HexNumber);

            if (_focus == 0)
            {
                _emu8051.WriteMem(_memoryFrameMode, _cursorPointedAddress, b);
            }
            else if (_focus == 1)
            {
                _emu8051.WriteReg(_cursorPointedAddress, b);
            }
            else if (_focus == 2)
            {
                _dataelements["data_pointer"][0, _cursorPointedAddress] = b;
                short dptr = TGUIUtils.BytesTo16Bit(_dataelements["data_pointer"][0, 1], _dataelements["data_pointer"][0, 0]);
                _emu8051.WriteReg(10, dptr);
            }
            else if (_focus == 3)
            {
                _addrInputVal[_cursorPointedAddress] = b;
            }
        }
Beispiel #3
0
 private short GetInputAddr()
 {
     return(TGUIUtils.BytesTo16Bit(
                _addrInputVal[1], _addrInputVal[0]));
 }
Beispiel #4
0
        private void RedrawData(bool updateHistory)
        {
            int row = 0;

            for (UInt16 addr = _memOffset; addr < _memOffset + 8 * 8; addr += 8)
            {
                byte[] addr_halfs = TGUIUtils.Get16BitHalfs(addr);

                for (int j = 0; j < 2; j++)
                {
                    _dataelements["memgrid_addr"][row, j] = addr_halfs[j];
                }

                for (int j = 0; j < 8; j++)
                {
                    byte b = _emu8051.ReadMem(_memoryFrameMode, addr + j);
                    _dataelements["memgrid"][row, j] = b;
                }
                row++;
            }

            // ASCII view

            if (!_dataelements["ascii"].Hidden)
            {
                int    asciiRow = 0;
                int    asciiCol = 5;
                byte   padd     = ASCIICoDec.CodeASCII('.');
                UInt16 memaddr  = _memOffset;
                for (int i = 0; i < 8; i++)
                {
                    if (i == 4)
                    {
                        asciiRow = 0;
                        asciiCol = 19;
                    }

                    string saddr = memaddr.ToString("X4");

                    int sp = 0;
                    for (int k = asciiCol - 5; k < asciiCol - 1; k++)
                    {
                        _dataelements["ascii"][asciiRow, k] = ASCIICoDec.CodeASCII(saddr[sp]);
                        sp++;
                    }

                    for (int j = 0; j < 8; j++)
                    {
                        byte val = _emu8051.ReadMem(_memoryFrameMode, memaddr);

                        if (val > 32 && val < 127)
                        {
                            _dataelements["ascii"][asciiRow, asciiCol + j] = val;
                        }
                        else
                        {
                            _dataelements["ascii"][asciiRow, asciiCol + j] = padd;
                        }

                        memaddr++;
                    }
                    asciiRow++;
                }
            }

            if (updateHistory)
            {
                UpdateHistory(_dataelements["machine_status_h"], _dataelements["machine_status"], 5, 7);
                UpdateHistory(_dataelements["ports_h"], _dataelements["ports"], 5, 7);
                UpdateHistory(_dataelements["common_regs_h"], _dataelements["common_regs"], 5, 10);
                UpdateHistory(_dataelements["data_pointer_h"], _dataelements["data_pointer"], 5, 2);
                UpdateHistory(_dataelements["code_h"], _dataelements["code"], 5, 38);
            }

            // Stack

            byte[] stackData = _emu8051.ReadStack();
            for (int i = 0; i < 14; i++)
            {
                _dataelements["stack"][i, 0] = stackData[i];
            }

            // Common registers

            for (int i = 0; i < 10; i++)
            {
                _dataelements["common_regs"][0, i] = (byte)_emu8051.ReadReg(i);
            }

            // Data pointer

            byte[] dptr = TGUIUtils.Get16BitHalfs((ushort)_emu8051.ReadReg(10));
            for (int j = 0; j < 2; j++)
            {
                _dataelements["data_pointer"][0, j] = dptr[j];
            }

            // Code

            Instruction instr  = _emu8051.DecodeOp(_programCounter);
            string      format = "{0:X4}  {1} {2} {3}  {4}";
            string      asm    = string.Empty;

            for (int i = 0; i < instr.Assembly.Length; i++)
            {
                byte b = instr.Assembly[i];
                if (b == 0x00) // end of cstring
                {
                    break;
                }
                asm += ASCIICoDec.DecodeASCII(b);
            }

            string outstr = string.Format(format, _programCounter,
                                          TGUIUtils.ByteToHex(instr.Opcodes[0]),
                                          instr.Opcodes.Length > 1 ? TGUIUtils.ByteToHex(instr.Opcodes[1]) : "  ",
                                          instr.Opcodes.Length > 2 ? TGUIUtils.ByteToHex(instr.Opcodes[2]) : "  ",
                                          asm
                                          );

            if (outstr.Length < 38)
            {
                outstr += new string(' ', 38 - outstr.Length);
            }

            for (int i = 0; i < outstr.Length; i++)
            {
                _dataelements["code"][0, i] = ASCIICoDec.CodeASCII(outstr[i]);
            }

            // Ports

            _dataelements["ports"][0, 0] = _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_SP - 0x80);
            _dataelements["ports"][0, 1] = _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_P0 - 0x80);
            _dataelements["ports"][0, 2] = _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_P1 - 0x80);
            _dataelements["ports"][0, 3] = _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_P2 - 0x80);
            _dataelements["ports"][0, 4] = _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_P3 - 0x80);
            _dataelements["ports"][0, 5] = _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_IP - 0x80);
            _dataelements["ports"][0, 6] = _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_IE - 0x80);

            // Machine status word

            int[] machine_status = TGUIUtils.GetBits(
                _emu8051.ReadMem(MEM_TYPES.SFR, SFR_REGS.REG_PSW - 0x80));

            for (int i = 0; i < 8; i++)
            {
                _dataelements["machine_status"][0, i] = (byte)machine_status[i];
            }

            // Address input

            _dataelements["addr_input"][0, 0] = _addrInputVal[0];
            _dataelements["addr_input"][0, 1] = _addrInputVal[1];

            // Cursor info

            RefreshCursorInfo();

            if (!_writeCursorH)
            {
                _currentCaretPos = TGUIUtils.GetGlobalCoords(
                    _focusedElement, _focusedElement.Position.Y, _focusedElement.Position.X);
            }

            // Info display

            int[] bits = TGUIUtils.GetBits((byte)_cursorPointedDisplayValue);

            WriteAt(CaretCoord.New(11, 2),
                    string.Format("Sel     : {0} {1} {2} {3} {4} {5} {6} {7}",
                                  bits[0], bits[1], bits[2], bits[3], bits[4], bits[5], bits[6], bits[7]));

            WriteAt(CaretCoord.New(12, 2),
                    string.Format("Time    : {0}ms", _timer.ToString("1.000")));

            WriteAt(CaretCoord.New(13, 2),
                    string.Format("Cycles  : {0}", _emu8051.Cycles));

            string spd = string.Empty;

            if (Clock.SpeedMode == 0)
            {
                spd = "MAX   ";
            }
            else if (Clock.SpeedMode == 1)
            {
                spd = "HIGH  ";
            }
            else if (Clock.SpeedMode == 2)
            {
                spd = "MIDDLE";
            }
            else if (Clock.SpeedMode == 3)
            {
                spd = "LOW   ";
            }
            else if (Clock.SpeedMode == 4)
            {
                spd = "LOWEST";
            }

            WriteAt(CaretCoord.New(14, 2),
                    string.Format("Clk spd : {0}      ", spd));

            foreach (ATUiElement element in _dataelements.Values)
            {
                if (!element.Hidden)
                {
                    DrawUTUiElement(element);
                }
            }
        }