public static void SetHookAfterRead(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null) { var runner = new BusHooksPythonEngine(sysbus, peripheral, pythonScript); sysbus.SetHookAfterRead<uint>(peripheral, runner.ReadHook, subrange); sysbus.SetHookAfterRead<ushort>(peripheral, (readValue, offset) => (ushort)runner.ReadHook(readValue, offset), subrange); sysbus.SetHookAfterRead<byte>(peripheral, (readValue, offset) => (byte)runner.ReadHook(readValue, offset), subrange); }
public static void SetHookBeforeWrite(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null) { var runner = new BusHooksPythonEngine(sysbus, peripheral, null, pythonScript); sysbus.SetHookBeforeWrite<uint>(peripheral, runner.WriteHook, subrange); sysbus.SetHookBeforeWrite<ushort>(peripheral, (valueToWrite, offset) => (ushort)runner.WriteHook(valueToWrite, offset), subrange); sysbus.SetHookBeforeWrite<byte>(peripheral, (valueToWrite, offset) => (byte)runner.WriteHook(valueToWrite, offset), subrange); }
public void ShouldShiftRange() { var range = new Range(0x2200, 0x200); var expectedResult = new Range(0x2500, 0x200); var result = range.ShiftBy(0x300); Assert.AreEqual(expectedResult, result); }
public void ShouldIntersectRangesWithOneCommonAddress() { var range1 = new Range(0x1000, 0x200); var range2 = new Range(0x11ff, 0x300); var expectedResult = new Range(0x11ff, 0x1); var intersection = range1.Intersect(range2); Assert.AreEqual(expectedResult, intersection); }
public RelativeRangeToken(string value) : base(value) { var trimmed = value.TrimStart('<').TrimEnd('>'); var split = trimmed.Split(new []{ ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray(); var resultValues = ParseNumbers(split); Value = new Range(resultValues[0], resultValues[1]); }
public Range Intersect(Range range) { var startAddress = Math.Max(StartAddress, range.StartAddress); var endAddress = Math.Min(EndAddress, range.EndAddress); if(startAddress >= endAddress) { return Range.Empty; } return new Range(startAddress, endAddress - startAddress); }
public void ShouldIntersectRange() { var range1 = new Range(0x1000, 0x200); var range2 = new Range(0x1100, 0x300); var expectedResult = new Range(0x1100, 0x100); var intersection1 = range1.Intersect(range2); var intersection2 = range2.Intersect(range1); Assert.AreEqual(expectedResult, intersection1); Assert.AreEqual(expectedResult, intersection2); }
public static bool TryCreate(long startAddress, long size, out Range range) { range = default(Range); if(size < 0) { return false; } range.StartAddress = startAddress; range.EndAddress = startAddress + size; return true; }
public void UnmapMemory(Range range) { using(machine.ObtainPausedState()) { var startAddress = checked((uint)range.StartAddress); var endAddress = checked((uint)(range.EndAddress - 1)); ValidateMemoryRangeAndThrow(startAddress, (uint)range.Size); // when unmapping memory, two things has to be done // first is to flag address range as no-memory (that is, I/O) TlibUnmapRange(startAddress, endAddress); // and second is to remove mappings that are not used anymore currentMappings = currentMappings. Where(x => TlibIsRangeMapped((uint)x.Segment.StartingOffset, (uint)(x.Segment.StartingOffset + x.Segment.Size)) == 1).ToList(); } }
public static void Register(this SystemBus sysbus, IBusPeripheral peripheral, Range range) { sysbus.Register(peripheral, new BusRangeRegistration(range)); }
public virtual void UnmapMemory(Range range) { }
protected HookWrapper(IBusPeripheral peripheral, Type type, Range? subrange) { Peripheral = peripheral; Name = type.Name; Subrange = subrange; }
public void ShouldContainItself() { var range = new Range(0x1000, 0x1200); Assert.IsTrue(range.Contains(range)); }
public void ShouldNotContainNearbyAddresses() { var range = new Range(0x600, 0x100); Assert.IsFalse(range.Contains(0x5FF)); Assert.IsFalse(range.Contains(0x700)); }
public void RelativeRangeTest() { var result = tokenizer.Tokenize("<-5,+5>"); var expectedValue = new Range(-5, 11); AssertTokenizationTypes(result, typeof(AbsoluteRangeToken)); AssertTokenizationValues(result, expectedValue); result = tokenizer.Tokenize("<0x6 0x2>"); expectedValue = new Range(0x6, 0x2); AssertTokenizationTypes(result, typeof(RelativeRangeToken)); AssertTokenizationValues(result, expectedValue); }
public void RangeTest() { var result = tokenizer.Tokenize("<-5,+5>"); var expectedValue = new Range(-5, 11); AssertTokenizationTypes(result, typeof(AbsoluteRangeToken)); AssertTokenizationValues(result, expectedValue); result = tokenizer.Tokenize("< \t0x123abDE \t, \t\t 0xabcdef0 \t\t >"); expectedValue = new Range(0x123abde, 0xabcdef0 - 0x123abde + 1); AssertTokenizationTypes(result, typeof(AbsoluteRangeToken)); AssertTokenizationValues(result, expectedValue); result = tokenizer.Tokenize("<0xdefg, 0xefgh>"); AssertTokenizationResult(result, 16); result = tokenizer.Tokenize("<5,-6>"); AssertTokenizationResult(result, 6, typeof(RecoverableException)); }
public bool Contains(Range range) { return range.StartAddress >= StartAddress && range.EndAddress <= EndAddress; }
public void ShouldContainLastAddress() { var range = new Range(0x1600, 0xA00); Assert.IsTrue(range.Contains(0x1fff)); }
public bool Intersects(Range range) { return Intersect(range) != Range.Empty; }
public BusRangeRegistration(Range range, long offset = 0) { Range = range; Offset = offset; }