Esempio n. 1
0
        public bool ParseJumpCallToAnAddressValue(FormCpu i_form, bool i_justParse = false)
        {
            try
            {
                UInt16 detectedJumpAddress = ConvertRadix.ConvertNumberWithPrefix(i_form.textBoxJumpToAnAddress.Text);
                if (detectedJumpAddress > 0xFFFF)
                {
                    Locator.Resolve <IUserMessage>().Error("Value for jump to an address is too big...\n\nMaximum is 2 bytes(0xFFFF).");
                    i_form.textBoxJumpToAnAddress.Focus();
                }
                else
                {
                    _detectingJumpToAddress = detectedJumpAddress;
                }
            }
            catch (CommandParseException)
            {
                if (!i_justParse)
                {
                    Locator.Resolve <IUserMessage>().Error("Incorrect number in field for jump to an address..");
                    i_form.textBoxJumpToAnAddress.Focus();
                }
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public void AddNewAddrArea(FormCpu i_form)
        {
            int FromAddr = 0;
            int ToAddr   = 0;
            var service  = Locator.Resolve <IUserQuery>();

            if (service == null)
            {
                return;
            }
            if (!service.QueryValue("Address area", "From:", "#{0:X4}", ref FromAddr, 0, 0xFFFF))
            {
                return;
            }
            ToAddr = FromAddr;
            if (!service.QueryValue("Address area", "To:", "#{0:X4}", ref ToAddr, FromAddr, 0xFFFF))
            {
                return;
            }

            ListViewItem item = new ListViewItem(new[] { String.Format("#{0:X4}", FromAddr), String.Format("#{0:X4}", ToAddr), "Yes" });

            item.Tag = String.Format("{0:X4};{1:X4};Yes", FromAddr, ToAddr);
            i_form.listViewAdressRanges.Items.Add(item);

            i_form.listViewAdressRanges.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
            i_form.listViewAdressRanges.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent);
            i_form.listViewAdressRanges.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Esempio n. 3
0
        public bool ParseTracedOpcode(FormCpu i_form, bool i_justParse = false)
        {
            try
            {
                UInt16 opcode = ConvertRadix.ConvertNumberWithPrefix(i_form.textBoxOpcode.Text);
                if (opcode > 0xFF) //ToDo: only one byte for traced opcode
                {
                    SetTracedOpcode((byte)(opcode % 256));
                }
                else
                {
                    SetTracedOpcode((byte)opcode);
                }
            }
            catch (CommandParseException)
            {
                if (!i_justParse)
                {
                    Locator.Resolve <IUserMessage>().Error("Incorrect opcode number...");
                    i_form.textBoxOpcode.Focus();
                }
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        private void SetTraceArea(FormCpu i_form)
        {
            if (i_form.listViewAdressRanges.Items.Count == 0 || i_form.checkBoxTraceArea.Checked == false)
            {
                _isTraceAreaDefined = false;
                return;
            }

            Array.Clear(_addrsFlags, 0, _addrsFlags.Length);

            foreach (ListViewItem item in i_form.listViewAdressRanges.Items)
            {
                string[] tags = ((string)item.Tag).Split(new char[] { ';' });
                if (tags.Length != 3)
                {
                    continue;
                }

                //setting
                int addrFrom = int.Parse(tags[0], System.Globalization.NumberStyles.HexNumber);
                int addrTo   = int.Parse(tags[1], System.Globalization.NumberStyles.HexNumber);
                for (; addrFrom <= addrTo; addrFrom++)
                {
                    _addrsFlags[addrFrom] = (tags[2] == "Yes");
                }
            }

            _isTraceAreaDefined = true;
        }
Esempio n. 5
0
        public void UpdateNewAddrArea(FormCpu i_form)
        {
            //this will only toggle Yes/No
            if (i_form.listViewAdressRanges.FocusedItem.Index < 0)
            {
                return;
            }

            ListViewItem itemToUpdate = i_form.listViewAdressRanges.Items[i_form.listViewAdressRanges.FocusedItem.Index];
            string       strNewTraceStatus;

            string[] tags = ((string)itemToUpdate.Tag).Split(new char[] { ';' });
            if (tags.Length != 3)
            {
                return;
            }

            strNewTraceStatus = (tags[2] == "Yes" ? "No" : "Yes");
            ListViewItem item = new ListViewItem(new[] { "#" + tags[0], "#" + tags[1], strNewTraceStatus });

            item.Tag = tags[0] + ";" + tags[1] + ";" + strNewTraceStatus;
            i_form.listViewAdressRanges.Items[i_form.listViewAdressRanges.FocusedItem.Index] = item;
        }
Esempio n. 6
0
        public bool StartTrace(FormCpu i_form)
        {
            lock (_sync)
            {
                _tactCount = -1;

                SetTraceOpcodes(i_form);
                SetTraceArea(i_form);
                //Detecting jump to an address
                _isDetectingJumpOnAddress = i_form.checkBoxDetectJumpOnAddress.Checked;

                if (!ValidateTrace(i_form))
                {
                    return(false);
                }

                _counters         = new int[65536]; //create and clear
                _traceLogFilename = i_form.textBoxTraceFileName.Text.Trim();

                MakeTraceInfo(i_form);

                return(true);
            }
        }
Esempio n. 7
0
        private void SetTraceOpcodes(FormCpu i_form)
        {
            _currentTraceOpcodes = null;

            if (i_form.checkBoxAllJumps.Checked && i_form.checkBoxAllJumps.Enabled)
            {
                _currentTraceOpcodes = new byte[CommonJumps.Length + ConditionalJumps.Length];
                _currentTraceOpcodes = CommonJumps.Union(ConditionalJumps).ToArray();
                _currentTraceOpcodes = _currentTraceOpcodes.Union(ConditionalCalls).ToArray();

                _isTracingJumps = true;
            }
            else if (i_form.checkBoxConditionalJumps.Checked && i_form.checkBoxConditionalJumps.Enabled)
            {
                _currentTraceOpcodes = ConditionalJumps;
                _isTracingJumps      = true;
            }
            else if (i_form.checkBoxConditionalCalls.Checked && i_form.checkBoxConditionalCalls.Enabled)
            {
                _currentTraceOpcodes = ConditionalCalls;
                _isTracingJumps      = true;
            }
            else
            {
                _isTracingJumps = false;
            }

            if (i_form.checkBoxOpcode.Checked)
            {
                _isTracingOpcode = true;
            }
            else
            {
                _isTracingOpcode = false;
            }
        }
Esempio n. 8
0
 private void MakeTraceInfo(FormCpu i_form)
 {
     _traceInfo = "Trace filter:\r\n===========================\r\n";
     if (i_form.checkBoxAllJumps.Checked)
     {
         _traceInfo += "- all jumps\r\n";
     }
     if (i_form.checkBoxConditionalJumps.Checked)
     {
         _traceInfo += "- conditional jumps\r\n";
     }
     if (i_form.checkBoxConditionalCalls.Checked)
     {
         _traceInfo += "- conditional calls\r\n";
     }
     if (i_form.checkBoxDetectJumpOnAddress.Checked)
     {
         _traceInfo += String.Format("- detecting jump/call to an address #{0:X4}\r\n", _detectingJumpToAddress);
     }
     if (i_form.checkBoxOpcode.Checked)
     {
         _traceInfo += String.Format("- tracing opcode #{0:X2}\r\n", _tracedOpcode);
     }
     if (i_form.checkBoxTraceArea.Checked)
     {
         int[] tracedAreas = _addrsFlags.Select((s, index) => new { s, index })
                             .Where(x => x.s == true)
                             .Select(x => x.index)
                             .ToArray();
         if (tracedAreas.Length > 0)
         {
             if (tracedAreas.Length == _addrsFlags.Length)
             {
                 _traceInfo += "- trace area: whole memory";
             }
             else
             {
                 _traceInfo += "- trace area in: ";
                 int    prevMemAddr     = tracedAreas[0];
                 int    actualStartAddr = tracedAreas[0];
                 string tracedAreaOut   = String.Empty;
                 for (int memCounter = 1; memCounter < tracedAreas.Length; memCounter++)
                 {
                     if (prevMemAddr != tracedAreas[memCounter] - 1 || memCounter + 1 >= tracedAreas.Length)
                     {
                         if (tracedAreas[memCounter] - 1 != tracedAreas[memCounter - 1])
                         {
                             tracedAreaOut += String.Format("#{0:X4}->#{1:X4}; ", actualStartAddr, tracedAreas[memCounter - 1]);
                         }
                         else
                         {
                             tracedAreaOut += String.Format("#{0:X4}->#{1:X4}; ", actualStartAddr, tracedAreas[memCounter]);
                         }
                         actualStartAddr = prevMemAddr = tracedAreas[memCounter];
                         continue;
                     }
                     prevMemAddr = tracedAreas[memCounter];
                 }
                 _traceInfo += tracedAreaOut;
             }
             _traceInfo += "\r\n";
         }
         else
         {
             _traceInfo += "- trace area: no valid address => nothing will be traced"; //this should not happen
         }
     }
 }
Esempio n. 9
0
        public bool ValidateTrace(FormCpu i_form) //returns false when trace failed
        {
            //opcode filter
            if (i_form.checkBoxOpcode.Checked)
            {
                //bool error = false;
                if (i_form.textBoxOpcode.Text.Trim() == String.Empty)
                {
                    Locator.Resolve <IUserMessage>().Error("Filtering by opcode, but opcode not defined.");
                    i_form.textBoxOpcode.Focus();
                    return(false);
                }
                if (ParseTracedOpcode(i_form, true) == false)
                {
                    Locator.Resolve <IUserMessage>().Error("Opcode has incorrect number.");
                    i_form.textBoxOpcode.Focus();
                    return(false);
                }
            }

            //detecting jump/call to an address
            if (i_form.checkBoxDetectJumpOnAddress.Checked)
            {
                if (i_form.checkBoxDetectJumpOnAddress.Text.Trim() == String.Empty)
                {
                    Locator.Resolve <IUserMessage>().Error("Detecting jump to an address, but\naddress not defined...");
                    i_form.checkBoxDetectJumpOnAddress.Focus();
                    return(false);
                }
                if (ParseJumpCallToAnAddressValue(i_form, false) == false)
                {
                    return(false);
                }
            }

            //trace area - no valid address
            if (!_addrsFlags.Contains(true) && i_form.checkBoxTraceArea.Checked)
            {
                Locator.Resolve <IUserMessage>().Error("No valid trace address detected !\n\nHint: Uncheck adress range or define valid address to trace");
                return(false);
            }
            //trace area - final check
            if ((!_isTraceAreaDefined && !_isTracingJumps && !_isTracingOpcode)
                &&
                (!_addrsFlags.Contains(true) && i_form.checkBoxTraceArea.Checked) //no valid addr to trace
                )
            {
                _isTraceFilterDefined = false;

                //Trace everything, are you sure ?
                var service = Locator.Resolve <IUserQuery>();
                if (service == null)
                {
                    return(true);
                }

                if (service.Show("Because no trace filter/s is defined the\nemulation will be very slow.\n\nConsole output is allowed only when\nno trace filter is defined.\n\nAre you sure?",
                                 "Trace: Performance warning",
                                 ZXMAK2.Host.Entities.DlgButtonSet.YesNo,
                                 ZXMAK2.Host.Entities.DlgIcon.Warning)
                    != ZXMAK2.Host.Entities.DlgResult.Yes)
                {
                    return(false);
                }
            }
            else
            {
                _isTraceFilterDefined = true;
            }

            return(true); //ok; if false => do not start tracing
        }