Exemplo n.º 1
0
        public string InspectCPUStates(CPUState oldState, CPUState newState)
        {
            string str = "";

            if (oldState.A != newState.A)
            {
                str += string.Format("\t\t    A: ${0,2:X2} -> ${1,2:X2}\n", oldState.A, newState.A);
            }
            if (oldState.X != newState.X)
            {
                str += string.Format("\t\t    X: ${0,2:X2} -> ${1,2:X2}\n", oldState.X, newState.X);
            }
            if (oldState.Y != newState.Y)
            {
                str += string.Format("\t\t    Y: ${0,2:X2} -> ${1,2:X2}\n", oldState.Y, newState.Y);
            }
            // if (oldState.PC != newState.PC)
            //     str += string.Format("\t\t   PC: ${0,2:X2} -> ${1,2:X2}\n", oldState.PC, newState.PC);
            if (oldState.SP != newState.SP)
            {
                str += string.Format("\t\t   SP: ${0,2:X2} -> ${1,2:X2}\n", oldState.SP, newState.SP);
            }
            if (oldState.Flags != newState.Flags)
            {
                str += string.Format("\t\tFlags: ${0,2:X2} -> ${1,2:X2}\n", oldState.Flags, newState.Flags);
            }

            return(str);
        }
Exemplo n.º 2
0
 private void btnGet_Click(object sender, EventArgs e)
 {
     m6809FState = m6809State;
     m6809State  = CPUState.STOP;
     GetData();
     m6809State = m6809FState;
 }
Exemplo n.º 3
0
    public CPUState[] GetStateArray()
    {
        CPUState[] result = new CPUState[CyberspaceBattlefield.Current.TotalCores];

        int usedByPlayerCoreNumbers = CyberspaceBattlefield.Current.UsedCores - CyberspaceBattlefield.Current.StolenCores;
        for (int i = 0; i < result.Length; i++)
        {
            if (i < usedByPlayerCoreNumbers)
            {
                result[i] = CPUState.Provisioned;
            }
            else if (i < usedByPlayerCoreNumbers + CyberspaceBattlefield.Current.CurrentCores)
            {
                result[i] = CPUState.Available;
            }
            else if (i < usedByPlayerCoreNumbers + CyberspaceBattlefield.Current.CurrentCores + CyberspaceBattlefield.Current.StolenCores)
            {
                result[i] = CPUState.Occupied;
            }
            else
            {
                result[i] = CPUState.Infected;
            }
        }

        return result;
    }
Exemplo n.º 4
0
 public override void Execute(CPUState state, Bus bus)
 {
     if (state.HasStatusFlag(StatusFlag.Zero))
     {
         state.PC = (ushort)CalculateEffectiveAddress(state, bus);
     }
 }
Exemplo n.º 5
0
        public void ZoomTimeWindow()
        {
            ClearZoomedTimes();

            long      zoomed_t0     = itparms.T0;
            long      zoomed_t1     = itparms.T1;
            const int zoomed_splits = 50;

            int idCSwitch = atomsRecords.Lookup("CSwitch");

            int i = 1;

            long timeStart = zoomed_t0;
            long timeEnd   = zoomed_t0 + (zoomed_t1 - zoomed_t0) * i / zoomed_splits;

            CPUState[] state = new CPUState[maxCPU];

            InitializeStartingCPUStates(state, idCSwitch);

            ETWLineReader l = StandardLineReader();

            foreach (ByteWindow b in l.Lines())
            {
                while (l.t >= timeEnd && i <= zoomed_splits)
                {
                    AddZoomedTimeRow(timeStart, timeEnd, state);
                    i++;
                    timeStart = timeEnd;
                    timeEnd   = zoomed_t0 + (zoomed_t1 - zoomed_t0) * i / zoomed_splits;
                }

                if (l.idType != idCSwitch)
                {
                    continue;
                }

                int newTid = b.GetInt(fldCSwitchNewTID);
                int oldTid = b.GetInt(fldCSwitchOldTID);
                int cpu    = b.GetInt(fldCSwitchCPU);

                int tusage = (int)(l.t - state[cpu].time);

                if (state[cpu].tid != 0)
                {
                    state[cpu].usage += tusage;
                }

                state[cpu].time   = l.t;
                state[cpu].tid    = newTid;
                state[cpu].active = true;
            }

            while (i <= zoomed_splits)
            {
                AddZoomedTimeRow(timeStart, timeEnd, state);
                i++;
                timeStart = timeEnd;
                timeEnd   = zoomed_t0 + (zoomed_t1 - zoomed_t0) * i / zoomed_splits;
            }
        }
Exemplo n.º 6
0
 public void m6809_start_debug()
 {
     if (bLogNew && lPPC.IndexOf(M6809.mm1[0].PPC.LowWord) < 0)
     {
         m6809FState = m6809State;
         m6809State  = CPUState.STOP;
         lPPC.Add(M6809.mm1[0].PPC.LowWord);
         tbResult.AppendText(M6809.mm1[0].PPC.LowWord.ToString("X4") + ": ");
         m6809State = m6809FState;
     }
     if (m6809State == CPUState.STEP2)
     {
         if (M6809.mm1[0].PPC.LowWord == PPCTill)
         {
             m6809State = CPUState.STOP;
         }
     }
     if (m6809State == CPUState.STEP3)
     {
         if (M6809.mm1[0].TotalExecutedCycles >= CyclesTill)
         {
             m6809State = CPUState.STOP;
         }
     }
     if (m6809State == CPUState.STOP)
     {
         GetData();
         tsslStatus.Text = "m6809 stop";
     }
     while (m6809State == CPUState.STOP)
     {
         Video.video_frame_update();
         Application.DoEvents();
     }
 }
Exemplo n.º 7
0
 public void m6809_stop_debug()
 {
     if (m6809State == CPUState.STEP)
     {
         m6809State      = CPUState.STOP;
         tsslStatus.Text = "m6809 stop";
     }
 }
Exemplo n.º 8
0
 public override void Execute(CPUState state, Bus bus)
 {
     state.Status = bus.StackPop(state);
     byte[] returnAddress = new byte[2];
     returnAddress[0] = bus.StackPop(state); // Pop low byte
     returnAddress[1] = bus.StackPop(state); // Pop high byte
     state.PC         = BitConverter.ToUInt16(returnAddress, 0);
 }
Exemplo n.º 9
0
 public x86CPU(Config cfg)
 {
     _cfg = cfg;
     Registers = new Registers();
     State = new CPUState();
     Memmory = new Memmory(_cfg);
     _opcode = new Opcode();
 }
Exemplo n.º 10
0
        public override void Execute(CPUState state, Bus bus)
        {
            byte operandValue = GetOperandValue(state, bus);
            int  result       = state.Accumulator & operandValue;

            CheckNegativeFlag(state, result);
            CheckZeroFlag(state, result);
            state.Accumulator = (byte)result;
        }
Exemplo n.º 11
0
        public override void Execute(CPUState state, Bus bus)
        {
            int addressToPush = state.PC - 1;

            bus.StackPush(state, (byte)(addressToPush >> 8)); // Push high byte
            bus.StackPush(state, (byte)addressToPush);        // Push low byte

            state.PC = (ushort)CalculateEffectiveAddress(state, bus);
        }
Exemplo n.º 12
0
        public override void Execute(CPUState state, Bus bus)
        {
            byte operandValue = GetOperandValue(state, bus);
            int  result       = state.RegisterY - operandValue;

            CheckZeroFlag(state, result);
            CheckNegativeFlag(state, result);
            CheckCarryFlag(state, state.RegisterY, operandValue);
        }
Exemplo n.º 13
0
        public override void Execute(CPUState state, Bus bus)
        {
            int  effectiveAddress = CalculateEffectiveAddress(state, bus);
            byte decOperand       = bus.Read(effectiveAddress);

            --decOperand;
            bus.Write(effectiveAddress, decOperand);
            CheckZeroFlag(state, decOperand);
            CheckNegativeFlag(state, decOperand);
        }
Exemplo n.º 14
0
        private void UpdateCPUStatus(ref CPUState state)
        {
            _cpuBinder.Entity = state;
            _cpuBinder.UpdateUI();

            UpdateCpuFlags();

            chkExternal.Checked     = state.IRQFlag.HasFlag(IRQSource.External);
            chkFrameCounter.Checked = state.IRQFlag.HasFlag(IRQSource.FrameCounter);
            chkDMC.Checked          = state.IRQFlag.HasFlag(IRQSource.DMC);
        }
Exemplo n.º 15
0
        public override void Execute(CPUState state, Bus bus)
        {
            byte operandValue = GetOperandValue(state, bus);
            byte result       = (byte)(state.Accumulator & operandValue);

            // Bits 7 and 6 of operand are transfered to bit 7 and 6 of status register (Negative, Overflow)
            state.ChangeStatusFlag(StatusFlag.Negative, (operandValue & 0x80) != 0);
            state.ChangeStatusFlag(StatusFlag.Overflow, (operandValue & 0x40) != 0);

            // The zeroflag is set to the result of operand AND accumulator
            CheckZeroFlag(state, result);
        }
Exemplo n.º 16
0
 private void btnStep2_Click(object sender, EventArgs e)
 {
     try
     {
         PPCTill         = int.Parse(tbPPCTill.Text, NumberStyles.HexNumber);
         m6809State      = CPUState.STEP2;
         tsslStatus.Text = "m6809 step2";
     }
     catch
     {
         tsslStatus.Text = "error PPC";
     }
 }
Exemplo n.º 17
0
 private void btnStep3_Click(object sender, EventArgs e)
 {
     try
     {
         CyclesTill      = ulong.Parse(tbCyclesTill.Text, NumberStyles.HexNumber);
         m6809State      = CPUState.STEP3;
         tsslStatus.Text = "m6809 step3";
     }
     catch
     {
         tsslStatus.Text = "error TotalExecutedCycles";
     }
 }
Exemplo n.º 18
0
 private void btnStep_Click(object sender, EventArgs e)
 {
     if (m6809State == CPUState.RUN)
     {
         m6809State      = CPUState.STOP;
         tsslStatus.Text = "m6809 stop";
     }
     else
     {
         m6809State      = CPUState.STEP;
         tsslStatus.Text = "m6809 step";
     }
 }
Exemplo n.º 19
0
        public override void Execute(CPUState state, Bus bus)
        {
            byte operandValue = GetOperandValue(state, bus);
            int  result       = state.Accumulator + operandValue + (state.HasStatusFlag(StatusFlag.Carry) ? 1 : 0);

            CheckOverflowFlag(state, state.Accumulator, operandValue, result);

            // Need to work here with integer result as we need to look at the 9th bit for carry
            state.ChangeStatusFlag(StatusFlag.Carry, (result & 0x100) != 0);

            state.Accumulator = (byte)result;
            CheckNegativeFlag(state, state.Accumulator);
            CheckZeroFlag(state, state.Accumulator);
        }
Exemplo n.º 20
0
 public static void Record(CPUState state)
 {
     rewindBufferStartPos  = -1;
     ringBuffer[bufferPos] = state;
     bufferPos++;
     recordedStates++;
     if (bufferPos >= ringBuffer.Length)
     {
         bufferPos = 0;
     }
     if (recordedStates > ringBuffer.Length)
     {
         recordedStates = ringBuffer.Length;
     }
 }
Exemplo n.º 21
0
        public void Constructor_GivenValidValues_SetsValuesAsExpected(
            ICPUState copyFrom,
            int expectedProgramCounter,
            int expectedAccumulator,
            bool expectedHalt,
            IOperation expectedLastOperation
            )
        {
            var sut = new CPUState(copyFrom);

            Assert.Equal(expectedProgramCounter, sut.ProgramCounter);
            Assert.Equal(expectedAccumulator, sut.Accumulator);
            Assert.Equal(expectedHalt, sut.Halt);
            Assert.Equal(expectedLastOperation, sut.LastOperation);
        }
Exemplo n.º 22
0
        public override void Execute(CPUState state, Bus bus)
        {
            // Same as ADC, just used one's complement of the operand
            byte operandValue = (byte)~GetOperandValue(state, bus);
            int  result       = state.Accumulator + operandValue + (state.HasStatusFlag(StatusFlag.Carry) ? 1 : 0);

            // TODO: learn how this works: http://www.righto.com/2012/12/the-6502-overflow-flag-explained.html
            CheckOverflowFlag(state, state.Accumulator, operandValue, result);

            // Need to work here with integer result as we need to look at the 9th bit for carry
            state.ChangeStatusFlag(StatusFlag.Carry, (result & 0x100) != 0);

            state.Accumulator = (byte)result;
            CheckNegativeFlag(state, state.Accumulator);
            CheckZeroFlag(state, state.Accumulator);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Returns the next unhandled interrupt. If there is more than one flagged and enabled, the one with the highest priority is returned.
        /// </summary>
        /// <remarks>
        /// Interrupts are triggered in HALT state even if IME is off.
        /// When an interrupt ends the HALT state, the flag isn't cleared afterwards.
        /// </remarks>
        /// <returns>The type of interrupt being handled.</returns>
        public InterruptType FetchNextInterrupt(CPUState currentState)
        {
            if (!InterruptMasterEnable && currentState != CPUState.Halt)
            {
                return(InterruptType.None);
            }
            var triggered = IE & IF;
            var returned  = InterruptType.None;

            #region Getting interrupt according to priority

            if ((triggered & 0x01) != 0)
            {
                returned = InterruptType.VBlank;
            }
            else if ((triggered & 0x02) != 0)
            {
                returned = InterruptType.LCDC;
            }
            else if ((triggered & 0x04) != 0)
            {
                returned = InterruptType.Timer;
            }
            else if ((triggered & 0x08) != 0)
            {
                returned = InterruptType.Serial;
            }
            else if ((triggered & 0x10) != 0)
            {
                returned = InterruptType.Joypad;
            }

            #endregion Getting interrupt according to priority

            if (returned == InterruptType.None)
            {
                return(returned);
            }
            // If interrupt wakes CPU from HALT, do not disable IME
            if (currentState != CPUState.Halt)
            {
                IF ^= (byte)returned;
                DisableInterrupts();
            }
            return(returned);
        }
Exemplo n.º 24
0
        public override void Execute(CPUState state, Bus bus)
        {
            short result;

            if (Instruction.AddressMode != AddressMode.Accumulator)
            {
                int  effectiveAddress = CalculateEffectiveAddress(state, bus);
                byte operandValue     = bus.Read(effectiveAddress);
                result = (short)(operandValue << 1);
                bus.Write(effectiveAddress, (byte)result);
            }
            else
            {
                result            = (short)(state.Accumulator << 1);
                state.Accumulator = (byte)result;
            }

            CheckNegativeFlag(state, (byte)result);
            CheckZeroFlag(state, result);
            state.ChangeStatusFlag(StatusFlag.Carry, result >> 8 == 1); // Set carry flag depending on whether the highest bit is 1 or not
        }
Exemplo n.º 25
0
        public override void Execute(CPUState state, Bus bus)
        {
            byte result;
            int  carryBitmask = state.HasStatusFlag(StatusFlag.Carry) ? 0x80 : 0;

            if (Instruction.AddressMode != AddressMode.Accumulator)
            {
                int  effectiveAddress = CalculateEffectiveAddress(state, bus);
                byte operandValue     = bus.Read(effectiveAddress);
                state.ChangeStatusFlag(StatusFlag.Carry, (operandValue & 1) == 1); // The lowest bit is displaced by the left shift and stored as a carry flag
                result = (byte)((operandValue >> 1) | carryBitmask);               // Set the carry bit in the shifted value via bitwise OR
                bus.Write(effectiveAddress, result);
            }
            else
            {
                state.ChangeStatusFlag(StatusFlag.Carry, (state.Accumulator & 1) == 1); // The lowest bit is displaced by the left shift and stored as a carry flag
                result            = (byte)((state.Accumulator >> 1) | carryBitmask);    // Set the carry bit in the shifted value via bitwise OR
                state.Accumulator = result;
            }

            CheckZeroFlag(state, result);
            CheckNegativeFlag(state, result);
        }
Exemplo n.º 26
0
 public override void Execute(CPUState state, Bus bus)
 {
     state.SP = state.RegisterX;
     CheckZeroFlag(state, state.SP);
     CheckNegativeFlag(state, state.SP);
 }
Exemplo n.º 27
0
 public override void Execute(CPUState state, Bus bus)
 {
     state.RegisterY = state.Accumulator;
     CheckZeroFlag(state, state.RegisterY);
     CheckNegativeFlag(state, state.RegisterY);
 }
Exemplo n.º 28
0
 public override void Execute(CPUState state, Bus bus)
 {
     state.ChangeStatusFlag(StatusFlag.Carry, true);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Returns the next unhandled interrupt. If there is more than one flagged and enabled, the one with the highest priority is returned.
        /// </summary>
        /// <remarks>
        /// Interrupts are triggered in HALT state even if IME is off.
        /// When an interrupt ends the HALT state, the flag isn't cleared afterwards.
        /// </remarks>
        /// <returns>The type of interrupt being handled.</returns>
        public InterruptType FetchNextInterrupt(CPUState currentState)
        {
            if (!InterruptMasterEnable && currentState != CPUState.Halt)
            {
                return InterruptType.None;
            }
            var triggered = IE & IF;
            var returned = InterruptType.None;

            #region Getting interrupt according to priority

            if ((triggered & 0x01) != 0)
            {
                returned = InterruptType.VBlank;
            }
            else if ((triggered & 0x02) != 0)
            {
                returned = InterruptType.LCDC;
            }
            else if ((triggered & 0x04) != 0)
            {
                returned = InterruptType.Timer;
            }
            else if ((triggered & 0x08) != 0)
            {
                returned = InterruptType.Serial;
            }
            else if ((triggered & 0x10) != 0)
            {
                returned = InterruptType.Joypad;
            }

            #endregion Getting interrupt according to priority

            if (returned == InterruptType.None)
            {
                return returned;
            }
            IF ^= (byte)returned;
            DisableInterrupts();
            return returned;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Initializes the default values for a standard DMG CPU.
        /// </summary>
        public void InitializeDefaultValues()
        {
            #region DMG-specific register variables

            PC.w = 0x0100;
            SP.w = 0xFFFE;
            AF.w = 0x01B0;
            BC.w = 0x0013;
            DE.w = 0x00D8;
            HL.w = 0x014D;

            #endregion DMG-specific register variables

            CyclesSinceLastStep = 0;
            state = CPUState.Normal;
            RepeatLastInstruction = false;
        }
Exemplo n.º 31
0
        public ContextSwitchResult ComputeContextSwitchesRaw()
        {
            IContextSwitchParameters icswitchparms = itparms.ContextSwitchParameters;

            bool       fSimulateHyperthreading = icswitchparms.SimulateHyperthreading;
            bool       fSortBySwitches         = icswitchparms.SortBySwitches;
            bool       fComputeReasons         = icswitchparms.ComputeReasons;
            int        nTop = icswitchparms.TopThreadCount;
            ByteWindow bT   = new ByteWindow();

            long timeTotal     = 0;
            int  switchesTotal = 0;

            tStart = itparms.T0;
            tEnd   = itparms.T1;

            ThreadStat[] stats = NewThreadStats();

            CPUState[] state = new CPUState[maxCPU];

            int idCSwitch = atomsRecords.Lookup("CSwitch");

            bool[] threadFilters = itparms.GetThreadFilters();

            InitializeStartingCPUStates(state, idCSwitch);

            // rewind

            ETWLineReader l = StandardLineReader();

            foreach (ByteWindow b in l.Lines())
            {
                if (l.idType != idCSwitch)
                {
                    continue;
                }

                int oldTid = b.GetInt(fldCSwitchOldTID);

                int cpu = b.GetInt(fldCSwitchCPU);
                timeTotal += AddCSwitchTime(fSimulateHyperthreading, l.t, stats, state);

                int newTid = b.GetInt(fldCSwitchNewTID);

                int idx = FindThreadInfoIndex(l.t, oldTid);

                stats[idx].switches++;
                switchesTotal++;

                if (fComputeReasons)
                {
                    bT.Assign(b, fldCSwitchWaitReason).Trim();
                    int id = atomsReasons.EnsureContains(bT);

                    if (stats[idx].swapReasons == null)
                    {
                        stats[idx].swapReasons = new int[maxReasons];
                    }

                    stats[idx].swapReasons[id]++;
                }

                state[cpu].active = true;
                state[cpu].tid    = newTid;
                state[cpu].time   = l.t;
            }

            timeTotal += AddCSwitchTime(fSimulateHyperthreading, l.t1, stats, state);

            if (fSortBySwitches)
            {
                Array.Sort(stats,
                           delegate(ThreadStat c1, ThreadStat c2)
                {
                    if (c1.switches > c2.switches)
                    {
                        return(-1);
                    }

                    if (c1.switches < c2.switches)
                    {
                        return(1);
                    }

                    return(0);
                }
                           );
            }
            else
            {
                Array.Sort(stats,
                           delegate(ThreadStat c1, ThreadStat c2)
                {
                    if (c1.time > c2.time)
                    {
                        return(-1);
                    }

                    if (c1.time < c2.time)
                    {
                        return(1);
                    }

                    return(0);
                }
                           );
            }

            var result = new ContextSwitchResult();

            result.stats           = stats;
            result.switchesTotal   = switchesTotal;
            result.timeTotal       = timeTotal;
            result.fSortBySwitches = fSortBySwitches;
            result.reasonsComputed = fComputeReasons;
            result.threadFilters   = threadFilters;
            result.countCPU        = maxCPU;
            result.nTop            = nTop;

            return(result);
        }
Exemplo n.º 32
0
 public Target(MOS6502 cpu)
 {
     _state = cpu.State;
 }
Exemplo n.º 33
0
        /// <summary>
        /// Checks for any interrupts. If an interrupt is handled, the PC is reset to the specified interrupt vector.
        /// </summary>
        private void CheckInterrupts()
        {
            InterruptType iType = interruptManager.FetchNextInterrupt(state);
            if (iType != InterruptType.None)
            {
                ushort intVector = 0;
                switch (iType)
                {
                    case InterruptType.VBlank:
                        intVector = IntVector_VBlank;
                        break;

                    case InterruptType.LCDC:
                        intVector = IntVector_LCDC;
                        break;

                    case InterruptType.Timer:
                        intVector = IntVector_Timer;
                        break;

                    case InterruptType.Serial:
                        intVector = IntVector_Serial;
                        break;

                    case InterruptType.Joypad:
                        intVector = IntVector_Joypad;
                        break;
                }

                //Is this for reading from the int vector table (using ReadMMU for low and high bytes of address)?
                UpdateSystemTime(8);
                Push(PC.w);
                PCChange(intVector);
                interruptManager.DisableInterrupts();
                state = CPUState.Normal;
            }
        }
Exemplo n.º 34
0
        void InitializeFromPrimary()
        {
            atomsFields     = new ByteAtomTable();
            atomsRecords    = new ByteAtomTable();
            atomsProcesses  = new ByteAtomTable();
            listEventFields = new List <List <int> >();

            byte[] byRecordEscape = ByteWindow.MakeBytes("$R");
            idRecordEscape = atomsFields.EnsureContains(byRecordEscape);

            byte[] byTimeEscape = ByteWindow.MakeBytes("$T");
            idTimeEscape = atomsFields.EnsureContains(byTimeEscape);

            byte[] byTimeOffsetEscape = ByteWindow.MakeBytes("$TimeOffset");
            idTimeOffsetEscape = atomsFields.EnsureContains(byTimeOffsetEscape);

            byte[] byWhenEscape = ByteWindow.MakeBytes("$When");
            idWhenEscape = atomsFields.EnsureContains(byWhenEscape);

            byte[] byFirstEscape = ByteWindow.MakeBytes("$First");
            idFirstEscape = atomsFields.EnsureContains(byFirstEscape);

            byte[] byLastEscape = ByteWindow.MakeBytes("$Last");
            idLastEscape = atomsFields.EnsureContains(byLastEscape);

            byte[] byBeginHeader = ByteWindow.MakeBytes("BeginHeader");
            byte[] byEndHeader   = ByteWindow.MakeBytes("EndHeader");

            ByteWindow b = new ByteWindow();

            threads.Clear();
            offsets.Clear();

            while (stm.ReadLine(b))
            {
                if (b.StartsWith(byBeginHeader))
                {
                    break;
                }
            }

            while (stm.ReadLine(b))
            {
                if (b.StartsWith(byEndHeader))
                {
                    break;
                }

                b.Field(0).Trim();

                int iCountBefore = atomsRecords.Count;
                atomsRecords.EnsureContains(b);
                if (atomsRecords.Count == iCountBefore)
                {
                    continue;
                }

                List <int> listFields = new List <int>();
                listEventFields.Add(listFields);

                listFields.Add(0); // the ID for $R, the record escape field

                // start from field 1 -- that skips only field 0 which is already mapped to $R
                for (int i = 1; i < b.fieldsLen; i++)
                {
                    b.Field(i).Trim();
                    int id = atomsFields.EnsureContains(b);
                    listFields.Add(id);
                }
            }

            stackIgnoreEvents = new bool[atomsRecords.Count];

            foreach (string strEvent in stackIgnoreEventStrings)
            {
                int id = atomsRecords.Lookup(strEvent);
                if (id >= 0)
                {
                    stackIgnoreEvents[id] = true;
                }
            }

            recordInfo = new RecordInfo[atomsRecords.Count];

            int idThreadField      = atomsFields.Lookup("ThreadID");
            int idFileNameField    = atomsFields.Lookup("FileName");
            int idTypeField        = atomsFields.Lookup("Type");
            int idSizeField        = atomsFields.Lookup("Size");
            int idIOSizeField      = atomsFields.Lookup("IOSize");
            int idElapsedTimeField = atomsFields.Lookup("ElapsedTime");

            for (int i = 0; i < recordInfo.Length; i++)
            {
                List <int> fieldList = listEventFields[i];
                recordInfo[i].threadField = fieldList.IndexOf(idThreadField);
                recordInfo[i].sizeField   = fieldList.IndexOf(idSizeField);

                if (-1 == recordInfo[i].sizeField)
                {
                    recordInfo[i].sizeField = fieldList.IndexOf(idIOSizeField);
                }

                recordInfo[i].goodNameField = fieldList.IndexOf(idFileNameField);
                if (-1 == recordInfo[i].goodNameField)
                {
                    recordInfo[i].goodNameField = fieldList.IndexOf(idTypeField);
                }

                recordInfo[i].elapsedTimeField = fieldList.IndexOf(idElapsedTimeField);
            }

            int idT_DCEnd   = atomsRecords.Lookup("T-DCEnd");
            int idT_DCStart = atomsRecords.Lookup("T-DCStart");
            int idT_Start   = atomsRecords.Lookup("T-Start");
            int idT_End     = atomsRecords.Lookup("T-End");
            int idCSwitch   = atomsRecords.Lookup("CSwitch");
            int idStack     = atomsRecords.Lookup("Stack");
            int idAlloc     = atomsRecords.Lookup("Allocation");

            int idFirstReliableEventTimeStamp        = atomsRecords.Lookup("FirstReliableEventTimeStamp");
            int idFirstReliableCSwitchEventTimeStamp = atomsRecords.Lookup("FirstReliableCSwitchEventTimeStamp");

            long tNext = 100000;
            long t     = 0;

            // seed offsets for the 0th record
            offsets.Add(stm.Position);

            listInitialTime = new List <TimeMark>();

            maxCPU = 64;
            CPUState[] state = new CPUState[maxCPU];

            const int maxEvent = 16;

            PreviousEvent[] prev       = new PreviousEvent[maxEvent];
            int             iNextEvent = 0;

            stackTypes = new bool[atomsRecords.Count];

            Dictionary <int, int> dictStartedThreads = new Dictionary <int, int>();

            ByteWindow record      = new ByteWindow();
            ByteWindow bThreadProc = new ByteWindow();
            ByteWindow bProcess    = new ByteWindow();

            // the first line of the trace is the trace info, that, importantly, has the OSVersion tag
            if (stm.ReadLine(b))
            {
                traceinfo = b.GetString();
            }
            else
            {
                traceinfo = "None";
            }

            while (stm.ReadLine(b))
            {
                if (b.len < typeLen)
                {
                    continue;
                }

                record.Assign(b, 0).Trim();
                int idrec = atomsRecords.Lookup(record);

                if (idrec < 0)
                {
                    continue;
                }

                if (idrec == idFirstReliableCSwitchEventTimeStamp ||
                    idrec == idFirstReliableEventTimeStamp)
                {
                    continue;
                }

                recordInfo[idrec].count++;

                t = b.GetLong(1);
                while (t >= tNext)
                {
                    tNext = AddTimeRow(tNext, state);
                }

                if (idrec != idStack && !stackIgnoreEvents[idrec])
                {
                    prev[iNextEvent].time    = t;
                    prev[iNextEvent].eventId = idrec;
                    iNextEvent = (iNextEvent + 1) % maxEvent;
                }

                if (idrec == idStack)
                {
                    int i = iNextEvent;
                    for (; ;)
                    {
                        if (--i < 0)
                        {
                            i = maxEvent - 1;
                        }

                        if (i == iNextEvent)
                        {
                            break;
                        }

                        if (prev[i].time == t)
                        {
                            stackTypes[prev[i].eventId] = true;
                            break;
                        }
                    }
                }
                else if (idrec == idT_Start ||
                         idrec == idT_End ||
                         idrec == idT_DCStart ||
                         idrec == idT_DCEnd)
                {
                    ThreadInfo ti = new ThreadInfo();

                    ti.threadid = b.GetInt(fldTStartThreadId);

                    bool fStarted = dictStartedThreads.ContainsKey(ti.threadid);

                    if (idrec == idT_Start)
                    {
                        ti.timestamp = t;
                    }
                    else if (idrec == idT_DCStart)
                    {
                        ti.timestamp = 0;
                    }
                    else
                    {
                        if (fStarted)
                        {
                            continue;
                        }

                        ti.timestamp = 0;
                    }

                    if (!fStarted)
                    {
                        dictStartedThreads.Add(ti.threadid, 0);
                    }

                    bThreadProc.Assign(b, fldTStartThreadProc).Trim();
                    bProcess.Assign(b, fldTStartProcess).Trim();

                    ti.processPid = bProcess.Clone();

                    if (atomsProcesses.Lookup(bProcess) == -1)
                    {
                        atomsProcesses.EnsureContains(ti.processPid);
                        ProcessInfo pi = new ProcessInfo();
                        pi.processPid = ti.processPid;
                        processes.Add(pi);
                    }

                    bProcess.Truncate((byte)'(').Trim();

                    ti.processNopid = bProcess.Clone();
                    ti.threadproc   = bThreadProc.Clone();

                    threads.Add(ti);
                }
                else if (idrec == idCSwitch)
                {
                    int newTid = b.GetInt(fldCSwitchNewTID);
                    int oldTid = b.GetInt(fldCSwitchOldTID);
                    int cpu    = b.GetInt(fldCSwitchCPU);

                    if (cpu < 0 || cpu > state.Length)
                    {
                        continue;
                    }

                    int tusage = (int)(t - state[cpu].time);

                    if (state[cpu].tid != 0 && tusage > 0)
                    {
                        state[cpu].usage += tusage;
                    }

                    state[cpu].time   = t;
                    state[cpu].tid    = newTid;
                    state[cpu].active = true;
                }
            }

            AddTimeRow(t, state);

            threads.Sort();
            int tid = -1;

            mp_tid_firstindex = new Dictionary <int, int>();

            for (int i = 0; i < threads.Count; i++)
            {
                if (tid != threads[i].threadid)
                {
                    tid = threads[i].threadid;
                    mp_tid_firstindex.Add(tid, i);
                }
            }

            sortedThreads = new int[threads.Count];
            for (int i = 0; i < sortedThreads.Length; i++)
            {
                sortedThreads[i] = i;
            }

            Array.Sort(sortedThreads,
                       delegate(int id1, int id2)
            {
                byte[] b1 = threads[id1].processPid;
                byte[] b2 = threads[id2].processPid;

                int cmp = ByteWindow.CompareBytes(b1, b2, true);
                if (cmp != 0)
                {
                    return(cmp);
                }

                if (threads[id1].threadid < threads[id2].threadid)
                {
                    return(-1);
                }

                if (threads[id1].threadid > threads[id2].threadid)
                {
                    return(1);
                }

                return(0);
            }
                       );


            sortedProcesses = new int[processes.Count];
            for (int i = 0; i < sortedProcesses.Length; i++)
            {
                sortedProcesses[i] = i;
            }

            Array.Sort(sortedProcesses,
                       delegate(int id1, int id2)
            {
                byte[] b1 = processes[id1].processPid;
                byte[] b2 = processes[id2].processPid;

                return(ByteWindow.CompareBytes(b1, b2, true));
            }
                       );

            tmax = t;

            TrySaveState();
        }
Exemplo n.º 35
0
 public override void Execute(CPUState state, Bus bus)
 {
     state.PC = (ushort)CalculateEffectiveAddress(state, bus);
 }
Exemplo n.º 36
0
 public override void Execute(CPUState state, Bus bus)
 {
     state.IrqInvoked = true;
 }
Exemplo n.º 37
0
 /// <summary>
 /// Halts the CPU.
 /// </summary>
 private void Halt()
 {
     if (!interruptManager.InterruptMasterEnable && interruptManager.InterruptsReady)
     {
         //if (mmu.IsCGB) CycleCounter += 4;
         /*else*/
         RepeatLastInstruction = true;
     }
     else
     {
         state = CPUState.Halt;
     }
 }