Пример #1
0
        public Processor(IMemoryBank memory = null, IMemoryMap map = null, ushort?topOfStackAddress = null, float frequencyInMHz = 4, bool enableFlagPrecalculation = true)
        {
            // You can supply your own memory implementations, for example if you need to do RAM paging for >64K implementations.
            // Since there are several different methods for doing this and no 'official' method, there is no paged RAM implementation in the core code.

            FrequencyInMHz          = frequencyInMHz;
            _windowsTicksPerZ80Tick = (int)Math.Ceiling(10 / frequencyInMHz);

            Registers = new Registers(this);
            Ports     = new Ports(this);
            Memory    = memory ?? new MemoryBank();
            Memory.Initialise(this, map ?? new MemoryMap(MAX_MEMORY_SIZE_IN_BYTES, true));
            IO = new ProcessorIO(this);

            TimingMode    = TimingMode.FastAndFurious;
            InterruptMode = InterruptMode.IM0;

            _topOfStack  = topOfStackAddress ?? 0;
            Registers.SP = _topOfStack;

            // If precalculation is enabled, all flag combinations for all input values for 8-bit ALU / bitwise operations are pre-built now
            // (but not the 16-bit ALU operations, the number space is far too big).
            // This is *slightly* faster than calculating them in real-time, but if you need to debug flag calculation you should
            // disable this and attach a debugger to the flag calculation methods in FlagLookup.cs.
            FlagLookup.EnablePrecalculation = enableFlagPrecalculation;
            FlagLookup.BuildFlagLookupTables();

            // The Z80 instruction set needs to be built (all Instruction objects are created, bound to the microcode instances, and indexed into a hashtable - undocumented 'overloads' are built here too)
            InstructionSet.Build();

            _debugging = Debugger.IsAttached;
        }