예제 #1
0
파일: YCPU.cs 프로젝트: pabru/YCPU
        /// <summary>
        /// Executes one instruction and returns.
        /// </summary>
        public void RunOneInstruction()
        {
            try {
                ushort word = ReadMemInt16(PC, SegmentIndex.CS);
                PC += 2;

                // Check for hardware interrupt:
                if (PS_H && !PS_Q && BUS.IsIRQ)
                {
                    Interrupt_HWI();
                }

                // Check for RTC interrupt:
                if (m_RTC.IsEnabled && m_RTC.IRQ(Cycles))
                {
                    Interrupt_Clock();
                }

                // Execute Memory[PC]
                YCPUInstruction opcode = m_Opcodes[word & 0x00FF];
                opcode.Opcode(word);
                // Increment the Cycle counter.
                Cycles += opcode.Cycles;
            }
            catch (SegFaultException e) {
                Interrupt_SegFault(e.SegmentType, 0xffff, PC);
            }
        }
예제 #2
0
파일: YCPU.cs 프로젝트: pabru/YCPU
        /// <summary>
        /// Executes a set number of cycles, or infinite cycles.
        /// </summary>
        /// <param name="cyclecount">How many cycles to run before stopping. Default value of -1 will run until Pause() is called.</param>
        public void Run(int cyclecount = -1)
        {
            // Count Cycles:
            long cyclesTarget = cyclecount == -1 ? long.MaxValue : cyclecount + Cycles;

            // Run the processor for cyclecount Cycles:
            Running = true;
            while (Running)
            {
                try {
                    ushort word = ReadMemInt16(PC, SegmentIndex.CS);
                    PC += 2;

                    // Execute Memory[PC] and increment the cycle counter:
                    YCPUInstruction opcode = m_Opcodes[word & 0x00FF];
                    opcode.Opcode(word);
                    Cycles += opcode.Cycles;

                    // Check for hardware interrupt:
                    if (PS_H && !PS_Q && BUS.IsIRQ)
                    {
                        Interrupt_HWI();
                    }

                    // Check for RTC interrupt:
                    if (m_RTC.IsEnabled && m_RTC.IRQ(Cycles))
                    {
                        Interrupt_Clock();
                    }

                    // Check to see if we've exceeded our cycle target:
                    if (Cycles >= cyclesTarget)
                    {
                        m_Pausing = true;
                    }
                    if (m_Pausing)
                    {
                        Running   = false;
                        m_Pausing = false;
                    }
                }
                catch (SegFaultException e) {
                    Interrupt_SegFault(e.SegmentType, 0xffff, PC);
                }
            }
        }