Beispiel #1
0
        public List <ushort> GetBreakpoints(BreakpointKinds kind)
        {
            switch (kind)
            {
            case BreakpointKinds.EXECUTION:
                return(_executionBreakpoints);

            case BreakpointKinds.READ:
                return(_readBreakpoints);

            case BreakpointKinds.WRITE:
                return(_writeBreakpoints);

            case BreakpointKinds.JUMP:
                return(_jumpBreakpoints);
            }

            throw new InvalidProgramException("Wrong Breakpoint kind");
        }
Beispiel #2
0
        public void RemoveBreakpoint(BreakpointKinds kind, ushort address)
        {
            switch (kind)
            {
            case BreakpointKinds.EXECUTION:
                _executionBreakpoints.Remove(address);
                break;

            case BreakpointKinds.READ:
                _readBreakpoints.Remove(address);
                break;

            case BreakpointKinds.WRITE:
                _writeBreakpoints.Remove(address);
                break;

            case BreakpointKinds.JUMP:
                _jumpBreakpoints.Remove(address);
                break;
            }
        }
Beispiel #3
0
        public void AddBreakpoint(BreakpointKinds kind, ushort address)
        {
            switch (kind)
            {
            case BreakpointKinds.EXECUTION:
                if (_executionBreakpoints.Contains(address))
                {
                    return;
                }
                _executionBreakpoints.Add(address);
                break;

            case BreakpointKinds.READ:
                if (_readBreakpoints.Contains(address))
                {
                    return;
                }
                _readBreakpoints.Add(address);
                break;

            case BreakpointKinds.WRITE:
                if (_writeBreakpoints.Contains(address))
                {
                    return;
                }
                _writeBreakpoints.Add(address);
                break;

            case BreakpointKinds.JUMP:
                if (_jumpBreakpoints.Contains(address))
                {
                    return;
                }
                _jumpBreakpoints.Add(address);
                break;
            }
        }
Beispiel #4
0
 public void RemoveBreakpoint(BreakpointKinds kind, ushort address)
 {
     switch (kind)
     {
         case BreakpointKinds.EXECUTION:
             _executionBreakpoints.Remove(address);
             break;
         case BreakpointKinds.READ:
             _readBreakpoints.Remove(address);
             break;
         case BreakpointKinds.WRITE:
             _writeBreakpoints.Remove(address);
             break;
         case BreakpointKinds.JUMP:
             _jumpBreakpoints.Remove(address);
             break;
     }
 }
Beispiel #5
0
        public List<ushort> GetBreakpoints(BreakpointKinds kind)
        {
            switch (kind)
            {
                case BreakpointKinds.EXECUTION:
                    return _executionBreakpoints;
                case BreakpointKinds.READ:
                    return _readBreakpoints;
                case BreakpointKinds.WRITE:
                    return _writeBreakpoints;
                case BreakpointKinds.JUMP:
                    return _jumpBreakpoints;
            }

            throw new InvalidProgramException("Wrong Breakpoint kind");
        }
Beispiel #6
0
 public void AddBreakpoint(BreakpointKinds kind, ushort address)
 {
     switch (kind)
     {
         case BreakpointKinds.EXECUTION:
             if (_executionBreakpoints.Contains(address)) { return; }
             _executionBreakpoints.Add(address);
             break;
         case BreakpointKinds.READ:
             if (_readBreakpoints.Contains(address)) { return; }
             _readBreakpoints.Add(address);
             break;
         case BreakpointKinds.WRITE:
             if (_writeBreakpoints.Contains(address)) { return; }
             _writeBreakpoints.Add(address);
             break;
         case BreakpointKinds.JUMP:
             if (_jumpBreakpoints.Contains(address)) { return; }
             _jumpBreakpoints.Add(address);
             break;
     }
 }
Beispiel #7
0
        /// <summary>
        /// Sets the current instruction to be executed. Note that this DOES NOT execute the opcode,
        /// but sets the CPU internal state so it can be executed when the correct clock ticks happen
        /// before the execution has to runb.
        /// </summary>
        /// <param name="ignoreBreakpoints">If this step should check for breakpoints</param>
        /// <returns>
        /// The number of ticks that have to run before the opcode is executed.
        /// The base clock frequency (2^22hz, ~4Mhz).
        /// </returns>
        internal byte DetermineStep(bool ignoreBreakpoints)
        {
            if (_state.Stopped)
            {
                return(0);
            }
            if (_state.Halted)
            {
                return(0);
            }

            if (_state.InterruptRequired)
            {
                // NOTE(Cristian): We store the interrupt so we break on the next
                //                 step. This will enable that we're breaking on the
                //                 first instruction of the interrupt handler, vs
                //                 an invented CALL
                _state.InterruptInProgress = true;
                _state.InterruptTriggered  = _state.InterruptToTrigger;
                _state.CurrentInstruction  = InterruptHandler(_state.InterruptToTrigger);

                // We need to check if there is another interrupt waiting
                CheckForInterruptRequired();
            }
            else
            {
                // If we have set an interupt to trigger a breakpoint, we break
                if (_state.InterruptInProgress)
                {
                    // TODO(Cristian): Change this to an array!
                    if (_breakableInterrupts[_state.InterruptTriggered])
                    {
                        InterruptHappened(_state.InterruptTriggered);
                        return(0); // We don't advance the state because we're breaking
                    }

                    _state.InterruptInProgress = false;
                }

                // Otherwise we fetch as usual
                FetchAndDecode(ref _state.CurrentInstruction, _state.Registers.PC, _state.HaltLoad);
                _state.HaltLoad = false;
            }

            // We see if there is an breakpoint to this address
            if (!ignoreBreakpoints && _executionBreakpoints.Contains(_state.CurrentInstruction.Address))
            {
                CurrentBreakpoint.Address = _state.CurrentInstruction.Address;
                CurrentBreakpoint.Target  = _state.CurrentInstruction.Address;
                CurrentBreakpoint.Kind    = BreakpointKinds.EXECUTION;
                BreakpointFound();
                return(0);
            }

            // We check to see if there is breakpoint to be triggered
            BreakpointKinds breakpointKind = BreakpointKinds.NONE;

            if (!_state.CurrentInstruction.CB)
            {
                breakpointKind = CPUInstructionBreakpoints.Check(this,
                                                                 (byte)_state.CurrentInstruction.OpCode,
                                                                 _state.CurrentInstruction.Literal,
                                                                 ignoreBreakpoints);
            }
            else
            {
                breakpointKind = CPUCBInstructionBreakpoints.Check(this,
                                                                   (byte)_state.CurrentInstruction.OpCode,
                                                                   _state.CurrentInstruction.Literal,
                                                                   ignoreBreakpoints);
            }

            // We see if there is an breakpoint to this address
            // NOTE(Cristian): CurrentBreakpoint.Target was calculated by Check
            if (breakpointKind != BreakpointKinds.NONE)
            {
                CurrentBreakpoint.Address = _state.CurrentInstruction.Address;
                CurrentBreakpoint.Kind    = breakpointKind;
                BreakpointFound();
                return(0);
            }

            byte prevTicksRequired = GetPreClocks();

            return(prevTicksRequired);
        }