public override string[] GetLines() { string[] lines = new string[data.GetLength(0)]; for (int i = 0; i < data.GetLength(0); i++) { string line = string.Empty; object[] args = new object[data.GetLength(1)]; for (int j = 0; j < data.GetLength(1); j++) { if (LineOutputFormat == null) { if (DataOutputFormat == "HEX") { line += TGUIUtils.ByteToHex(data[i, j]); } else if (DataOutputFormat == "DEC") { line += data[i, j].ToString(); } else if (DataOutputFormat == "STR") { line += ASCIICoDec.DecodeASCII(data[i, j]); } if (_colSep != 0x00 && j != data.GetLength(1)) { line += _colSep; } } else { args[j] = TGUIUtils.ByteToHex(data[i, j]); } } if (LineOutputFormat == null) { lines[i] = line; } else { lines[i] += string.Format(LineOutputFormat, args); } } return(lines); }
public System.Collections.Generic.IEnumerable <char> ReadBuffer() { char cr = ASCIICoDec.DecodeASCII((byte)ASCIICoDec.ControlCharacters.LF); for (int h = 0; h < HEIGHT; h++) { for (int w = 0; w < WIDTH; w++) { if (ShowCursor && h == _coord.Y && w == _coord.X && !(Full && ActiveChar)) { yield return(ASCIICoDec.DecodeASCII(0xDB)); } else { yield return(ASCIICoDec.DecodeASCII(_buffer[h, w])); } } yield return(cr); } }
public override string[] GetLines() { string[] lines = new string[data.GetLength(0)]; for (int i = 0; i < data.GetLength(0); i++) { string line = string.Empty; for (int j = 0; j < data.GetLength(1); j++) { if (i == 0 && j > 0 && j <= Title.Length) { line += Title[j - 1]; } else { line += ASCIICoDec.DecodeASCII(data[i, j]); } } lines[i] = line; } return(lines); }
private void HandleTerminalInput(byte data) { bool cursorState = _writeCursorH; _writeCursorH = false; if (ASCIICoDec.DecodeASCII(data).ToString().ToLower() == "m") { SwitchMemType(); return; } else if (ASCIICoDec.DecodeASCII(data).ToString().ToLower() == "r") { if (_focus == 3) { SwitchFocus(0); } ShowMessage(null); if (!_emu8051.IsRunning) { _emu8051.IsRunning = true; } else { _emu8051.IsRunning = false; } return; } else if (ASCIICoDec.DecodeASCII(data).ToString().ToLower() == "i") { if (_focus != 3) { _emu8051.IsRunning = false; SwitchFocus(3); } else { SwitchFocus(0); } return; } else if (ASCIICoDec.DecodeASCII(data).ToString().ToLower() == "g") { if (_focus == 3) { _emu8051.SetProgramCounter(GetInputAddr()); ShowMessage("PC set"); } return; } else if (ASCIICoDec.DecodeASCII(data).ToString().ToLower() == "p") { if (_focus == 3) { if (!_emu8051.HasBreakpoint) { _emu8051.SetBreakpoint(GetInputAddr()); ShowMessage("Breakpoint set"); } else { _emu8051.SetBreakpoint(-1); ShowMessage("Breakpoint clear"); } } return; } else if (data == (byte)ASCIICoDec.ControlCharacters.SPC) { _emu8051.Step(); Clock.Impulse(); _timer += Clock.MsPerTick; return; } else if (data == (byte)ASCIICoDec.ControlCharacters.FS) { Clock.AdjustSpeed('+'); } else if (data == (byte)ASCIICoDec.ControlCharacters.RS) { Clock.AdjustSpeed('-'); } else if (ASCIICoDec.DecodeASCII(data).ToString() == "x") { Reset(0); } else if (ASCIICoDec.DecodeASCII(data).ToString() == "X") { Reset(1); } else if (ASCIICoDec.DecodeASCII(data).ToString() == "t") { _dataelements["ascii"].Hidden = !_dataelements["ascii"].Hidden; RedrawStatic(); } else if (data == (byte)ASCIICoDec.ControlCharacters.DC1) { int moveOp = _focusedElement.MoveCursor(CursorMoveDirection.LEFT); if (_focus == 2 && moveOp == -1) { SwitchFocus(1); } } else if (data == (byte)ASCIICoDec.ControlCharacters.DC2) { int moveOp = _focusedElement.MoveCursor(CursorMoveDirection.RIGHT); if (_focus == 1 && moveOp == -1) { SwitchFocus(2); } } else if (data == (byte)ASCIICoDec.ControlCharacters.DC3) { int moveOp = _focusedElement.MoveCursor(CursorMoveDirection.UP); if (_focus == 0 && moveOp == -1) { if (_memOffset > 0) { _memOffset -= 8; } } } else if (data == (byte)ASCIICoDec.ControlCharacters.DC4) { int moveOp = _focusedElement.MoveCursor(CursorMoveDirection.DOWN); if (_focus == 0 && moveOp == -1) { if (_memOffset < _emu8051.GetMemVol(_memoryFrameMode) - 8 * 8) { _memOffset += 8; } } } else if (data == (byte)ASCIICoDec.ControlCharacters.TAB) { SwitchFocus(); } else { char inpChar = ASCIICoDec.DecodeASCII(data).ToString().ToLower()[0]; int code = ASCIICoDec.CodeASCII(inpChar); if ((code > 47 && code <= 57) || (code > 96 && code <= 102)) // 0-9 A-F { _inputVal = inpChar; _writeCursorH = cursorState; } } }
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); } } }
public void HandleInput() { if (!Interact) { return; } byte inpChr = 0x00; if (Input.GetKeyDown(KeyCode.F1)) { _tio.Print(ASCIICoDec.ControlCharacters.STX); } else if (Input.GetKey(KeyCode.Return)) { _tio.Print(ASCIICoDec.ControlCharacters.LF); } else if (Input.GetKey(KeyCode.LeftArrow) && CheckDelay()) { inpChr = (byte)ASCIICoDec.ControlCharacters.DC1; } else if (Input.GetKey(KeyCode.RightArrow) && CheckDelay()) { inpChr = (byte)ASCIICoDec.ControlCharacters.DC2; } else if (Input.GetKey(KeyCode.UpArrow) && CheckDelay()) { inpChr = (byte)ASCIICoDec.ControlCharacters.DC3; } else if (Input.GetKey(KeyCode.DownArrow) && CheckDelay()) { inpChr = (byte)ASCIICoDec.ControlCharacters.DC4; } else if (Input.GetKeyDown(KeyCode.Tab)) { inpChr = (byte)ASCIICoDec.ControlCharacters.TAB; } else if (Input.GetKey(KeyCode.Space) && CheckDelay(0.5f)) { inpChr = (byte)ASCIICoDec.ControlCharacters.SPC; } else if (Input.GetKeyDown(KeyCode.Plus) || Input.GetKeyDown(KeyCode.KeypadPlus)) { inpChr = (byte)ASCIICoDec.ControlCharacters.FS; } else if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus)) { inpChr = (byte)ASCIICoDec.ControlCharacters.RS; } else if (Input.anyKeyDown && Input.inputString.Length > 0) { inpChr = ASCIICoDec.CodeASCII(Input.inputString[0]); } if (inpChr != 0x00) { if (InputEnabled) { _tio.Print(ASCIICoDec.DecodeASCII(inpChr)); } _lastInputData = inpChr; } }