Inheritance: IBytePeripheral, IWordPeripheral, IDoubleWordPeripheral, IMapped, IDisposable, IKnownSize, ISpeciallySerializable, IMemory, IMultibyteWritePeripheral
 public void ShouldUnregisterPeripheralGroups()
 {
     using(var machine = new Machine())
     {
         var peripheral = new MappedMemory(10);
         machine.SystemBus.Register(peripheral, new BusPointRegistration(0x0));
         var group = machine.PeripheralsGroups.GetOrCreate("test-group", new [] { peripheral });
         Assert.IsTrue(machine.IsRegistered(peripheral));
         group.Unregister();
         Assert.IsFalse(machine.IsRegistered(peripheral));
     }
 }
Exemple #2
0
        public void ShouldReadWriteMemoryBiggerThan2GB()
        {
            const uint MemorySize = 3u * 1024 * 1024 * 1024;
            var memory = new MappedMemory(MemorySize);
            var machine = new Machine();
            var start = (long)100.MB();
            machine.SystemBus.Register(memory, start);
            var offset1 = start + 16;
            var offset2 = start + MemorySize - 16;
            machine.SystemBus.WriteByte(offset1, 0x1);
            machine.SystemBus.WriteByte(offset2, 0x2);

            Assert.AreEqual(0x1, machine.SystemBus.ReadByte(offset1));
            Assert.AreEqual(0x2, machine.SystemBus.ReadByte(offset2));
        }
Exemple #3
0
		public void ShouldSerializeMemory()
		{
			// preparing some random data
			const int size = 128 * 1024 * 1024;
			const int bufCount = 30;
			const int bufSize = 100 * 1024;
			var random = new Random();
			var buffers = new List<Tuple<int, byte[]>>(bufCount);
			for(var i = 0; i < bufCount; i++)
			{
				var buffer = new byte[bufSize];
				random.NextBytes(buffer);								
				int address;
				do 
				{					
					address = random.Next(size - bufSize);					
				}
				while (buffers.Any(x => address >= (x.Item1 - bufSize) && address <= (x.Item1 + bufSize)));
				buffers.Add(new Tuple<int, byte[]>(address, buffer));
			}
			
			using(var memory = new MappedMemory(size))
			{
				foreach(var buf in buffers)
				{
					memory.WriteBytes(buf.Item1, buf.Item2);					
				}				
				serializer.Serialize(memory, stream);
			}
			
			RewindStream();
			using(var memory = serializer.Deserialize<MappedMemory>(stream))
			{
				foreach(var buf in buffers)
				{					
					var bufCopy = memory.ReadBytes(buf.Item1, bufSize);
					CollectionAssert.AreEqual(bufCopy, buf.Item2);
				}
			}
		}
        public void ShouldNotUnregisterSinglePeripheralFromGroup()
        {
            using(var machine = new Machine())
            {
                var peripheral = new MappedMemory(10);
                machine.SystemBus.Register(peripheral, new BusPointRegistration(0x0));
                machine.SystemBus.Unregister(peripheral);

                machine.SystemBus.Register(peripheral, new BusPointRegistration(0x0));
                machine.PeripheralsGroups.GetOrCreate("test-group", new [] { peripheral });

                try 
                {
                    machine.SystemBus.Unregister(peripheral);
                }
                catch (RegistrationException)
                {
                    return;
                }

                Assert.Fail();
            }
        }
Exemple #5
0
 public MappedSegment(MappedMemory parent, int index, uint size)
 {
     this.index = index;
     this.parent = parent;
     this.size = size;
 }
Exemple #6
0
 public MappedSegment(MappedMemory parent, int index, uint size)
 {
     this.index  = index;
     this.parent = parent;
     this.size   = size;
 }
Exemple #7
0
        private void CreateMachineAndExecute(Action<SystemBus> action)
        {
            using (var machine = new Machine())
            {
                var sb = machine.SystemBus;
                var memory = new MappedMemory(16);
                sb.Register(memory, 0.By(16));
                sb.Register(memory, 0xC0000000.By(16));

                action(sb);
            }
        }