예제 #1
0
        public void SetMemoryCrossPages()
        {
            var mb = new Mock <IMemoryBank>();

            mb.SetupGet(b => b.HI_ADDRESS).Returns(0xFFFF);
            mb.SetupGet(b => b.LOW_ADDRESS).Returns(0xFFF0);
            var mb2 = new Mock <IMemoryBank>();

            mb2.SetupGet(b => b.HI_ADDRESS).Returns(0xFFEF);
            mb2.SetupGet(b => b.LOW_ADDRESS).Returns(0xFFE0);

            byte[] newMem = new byte[] { 1, 2, 3, 4 };

            mb.Setup(b => b.SetContents(0xFFF0, newMem, 2, 2)).Verifiable("Didn't set the second bank");
            mb2.Setup(b => b.SetContents(0xFFEE, newMem, 0, 4)).Verifiable("Didn't set four on the first bank");

            IMemoryBank[] mbs = new IMemoryBank[]
            {
                mb.Object, mb2.Object
            };

            var memory = new RC2014.EMU.Memory(mbs);

            memory.SetContents(0xFFEE, new byte[] { 1, 2, 3, 4 }, 0, 4);

            mb2.VerifyAll();
            mb.VerifyAll();
            mb.Verify(x => x.SetContents(It.IsAny <int>(), It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>()), Times.Once);
            mb2.Verify(x => x.SetContents(It.IsAny <int>(), It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int?>()), Times.Once);
        }
예제 #2
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;
        }
예제 #3
0
        public MemoryBankAddress Attach(IMemoryBank Bank)
        {
            var t_Address = _GenerateNewAddress();

            m_Banks[t_Address] = Bank;
            return(t_Address);
        }
예제 #4
0
        public void GetMemoryCrossPage2Bytes()
        {
            var mb = new Mock <IMemoryBank>();

            mb.SetupGet(b => b.HI_ADDRESS).Returns(0xFFFF);
            mb.SetupGet(b => b.LOW_ADDRESS).Returns(0xFFF0);
            var mb2 = new Mock <IMemoryBank>();

            mb2.SetupGet(b => b.HI_ADDRESS).Returns(0xFFEF);
            mb2.SetupGet(b => b.LOW_ADDRESS).Returns(0xFFE0);

            mb.Setup(b => b.GetContents(0xFFF0, 1)).Returns(new byte[] { 3 }).Verifiable("Didn't get two from second bank");
            mb2.Setup(b => b.GetContents(0xFFEF, 2)).Returns(new byte[] { 2 }).Verifiable("Didn't get four from first bank");

            IMemoryBank[] mbs = new IMemoryBank[]
            {
                mb.Object, mb2.Object
            };

            var memory = new RC2014.EMU.Memory(mbs);

            var bytes = memory.GetContents(0xFFEF, 2);

            mb.VerifyAll();
            mb2.VerifyAll();

            Assert.That(bytes, Has.Length.EqualTo(2));
            Assert.AreEqual(new byte[] { 2, 3 }, bytes);
        }
예제 #5
0
 public void Initialize()
 {
     m_Bank   = new MemoryBank(64);
     m_Reader = new OperationDTOReader(
         ArchitectureFactory.CreateArchitecture(new MemoryBankService(new List <IMemoryBank> {
         m_Bank
     })));
 }
예제 #6
0
        private OperationDTO _ReadOperationDTOFromMemory(MemoryAddress Address, IMemoryBank Bank)
        {
            var t_OpCode = _InspectCode(Address, Bank);

            return
                (m_DTOReader.CanRead(t_OpCode) ?
                 m_DTOReader.ReadMemory(Address, Bank) :
                 throw new UnknownOperation(t_OpCode));
        }
예제 #7
0
 public void Initialize()
 {
     m_Oscillator  = new Clock();
     m_CPU         = new CPU();
     m_Bank        = new MemoryBank(512);
     m_BankService = new MemoryBankService(new List <IMemoryBank>
     {
         m_Bank
     });
     m_Machine = new Machine(m_CPU, m_Oscillator, m_BankService);
 }
예제 #8
0
 public void AttachAtAddress(IMemoryBank Bank, MemoryBankAddress Address)
 {
     if (!HasBankAtAddress(Address))
     {
         m_Banks.Add(Address, Bank);
     }
     else
     {
         throw new AddressOccupied();
     }
 }
예제 #9
0
        private byte[] _ReadData(int Count, MemoryAddress Address, IMemoryBank Bank)
        {
            var t_CurrentAddress = Address;
            var t_Data           = new List <byte>();

            for (int t_I = 0; t_I < Count; t_I++, t_CurrentAddress = _IncrementAddress(t_CurrentAddress))
            {
                t_Data.Add(Bank.Load <byte>(t_CurrentAddress));
            }

            return(t_Data.ToArray());
        }
예제 #10
0
        private void _WriteOpLoadToBank(IMemoryBank Bank)
        {
            var t_Data = new byte[]
            {
                1,
                0, 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0
            };

            for (int i = 0; i < t_Data.Length; i++)
            {
                Bank.Store(t_Data[i], new MemoryAddress(i));
            }
        }
예제 #11
0
        public void Constructs()
        {
            var mb = new Mock <IMemoryBank>();

            mb.SetupGet(b => b.HI_ADDRESS).Returns(0xFFFF);

            IMemoryBank[] mbs = new IMemoryBank[]
            {
                mb.Object
            };

            var memory = new RC2014.EMU.Memory(mbs);

            mb.VerifyAll();
            Assert.AreEqual(0x10000, memory.Size);
        }
예제 #12
0
        public void Initialize()
        {
            m_Arch = _CreateArchitecture();

            m_CPU         = new CPU();
            m_Oscillator  = new Clock();
            m_Bank        = new MemoryBank(512);
            m_BankService = new MemoryBankService(new List <IMemoryBank>()
            {
                m_Bank
            });
            m_AddressReader = new MemoryLocationAddressReader();
            m_OpDtoReader   = new OperationDTOReader(m_Arch);
            m_OpReader      = new OperationReader(m_Arch, m_OpDtoReader);

            m_Fetcher     = new OperationFetcher(m_OpReader, m_BankService, m_AddressReader);
            m_OpFeeder    = new OperationFeeder(m_Fetcher);
            m_CPUConsumer = new CPUConsumer(m_CPU);

            SetupComponents();
        }
예제 #13
0
        public void GetMemoryTopMostByte()
        {
            var mb = new Mock <IMemoryBank>();

            mb.SetupGet(b => b.HI_ADDRESS).Returns(0xFFFF);
            mb.SetupGet(b => b.LOW_ADDRESS).Returns(0xFFF0);

            mb.Setup(b => b.GetContents(0xFFFF, 1)).Returns(new byte[] { 9 }).Verifiable("Didn't get two from second bank");

            IMemoryBank[] mbs = new IMemoryBank[]
            {
                mb.Object
            };

            var memory = new RC2014.EMU.Memory(mbs);

            var bytes = memory.GetContents(0xFFFF, 1);

            mb.VerifyAll();

            Assert.That(bytes, Has.Length.EqualTo(1));
            Assert.AreEqual(new byte[] { 9 }, bytes);
        }
예제 #14
0
 public void Initialize()
 {
     m_Reader = new MemoryLocationAddressReader();
     m_Bank   = new MemoryBank(8);
 }
예제 #15
0
 private OperationDTO _CreateDTO(OperationDefinition Definition, MemoryAddress Address, IMemoryBank Bank)
 {
     return(new OperationDTO
            (
                Definition.OpCode,
                Definition.DataSize == 0 ?
                new byte[] {} :
                _ReadData(Definition.DataSize, Address + new MemoryAddress(1), Bank)
            ));
 }
예제 #16
0
 private byte _InspectCode(MemoryAddress Address, IMemoryBank Bank)
 {
     return(Bank.Load <byte>(Address));
 }
예제 #17
0
        public MemoryAddress ReadNextOperationAddress(MemoryAddress Address, IMemoryBank Bank)
        {
            var t_DTO = _ReadOperationDTOFromMemory(Address, Bank);

            return(Address + new MemoryAddress(t_DTO.TotalSize));
        }
예제 #18
0
 public IOperation ReadOperationFromMemory(MemoryAddress Address, IMemoryBank Bank)
 {
     return(ReadOperation(_ReadOperationDTOFromMemory(Address, Bank)));
 }
예제 #19
0
 public void SetFetchFromAddress(MemoryAddress MemoryAddress, MemoryBankAddress BankAddress)
 {
     FetchFromAddress = MemoryAddress;
     m_CurrentBank    = _ResolveMemoryBank(BankAddress);
     _SetReadAndNextLocations();
 }
예제 #20
0
 private byte _ReadOpCode(MemoryAddress Address, IMemoryBank Bank)
 {
     return(Bank.Load <byte>(Address));
 }
예제 #21
0
 public void Initialize()
 {
     m_CPU  = new CPU();
     m_Bank = new MemoryBank(64);
 }
예제 #22
0
 public void InitializeTestVariables()
 {
     m_CPU  = new CPU();
     m_Bank = new MemoryBank(32);
 }
예제 #23
0
 public MemoryLocation(MemoryAddress Address, IMemoryBank Bank)
 {
     m_Address = Address;
     m_Bank    = Bank;
 }
예제 #24
0
 public MemoryLocationAddress ReadLocationAddressFromMemory(MemoryAddress Address, IMemoryBank Bank)
 {
     return(new MemoryLocationAddress(_ReadAddress(Address, Bank), _ReadBankAddress(Address, Bank)));
 }
예제 #25
0
        public OperationDTO ReadMemory(MemoryAddress Address, IMemoryBank Bank)
        {
            var t_Definition = _LookupDefinition(_ReadOpCode(Address, Bank));

            return(_CreateDTO(t_Definition, Address, Bank));
        }
예제 #26
0
 public void Initialize()
 {
     m_Bank = new MemoryBank(32);
 }
예제 #27
0
 private MemoryBankAddress _ReadBankAddress(MemoryAddress Address, IMemoryBank Bank)
 {
     return(new MemoryBankAddress(Bank.Load <int>(Address + new MemoryAddress(4))));
 }