コード例 #1
0
        public void SerializationWorksAsExpected()
        {
            // --- Arrange
            var dc = new DisassemblyAnnotation();

            dc.SetLabel(0x0100, "FirstLabel");
            dc.SetLabel(0x0200, "SecondLabel");
            dc.SetComment(0x0100, "FirstComment");
            dc.SetComment(0x0200, "SecondComment");
            dc.SetPrefixComment(0x0100, "FirstPrefixComment");
            dc.SetPrefixComment(0x0200, "SecondPrefixComment");
            dc.AddLiteral(0x0000, "Entry");
            dc.AddLiteral(0x0000, "Start");
            dc.AddLiteral(0x0028, "Calculator");
            dc.MemoryMap.Add(new MemorySection(0x0000, 0x3BFF));
            dc.MemoryMap.Add(new MemorySection(0x3C00, 0x3FFF, MemorySectionType.ByteArray));
            dc.SetLiteralReplacement(0x100, "Entry");
            dc.SetLiteralReplacement(0x1000, "Calculator");

            // --- Act
            var serialized = dc.Serialize();

            DisassemblyAnnotation.Deserialize(serialized, out var back);

            // --- Assert
            dc.Labels.Count.ShouldBe(back.Labels.Count);
            foreach (var item in dc.Labels)
            {
                back.Labels[item.Key].ShouldBe(item.Value);
            }
            dc.Comments.Count.ShouldBe(back.Comments.Count);
            foreach (var item in dc.Comments)
            {
                back.Comments[item.Key].ShouldBe(item.Value);
            }
            dc.PrefixComments.Count.ShouldBe(back.PrefixComments.Count);
            foreach (var item in dc.PrefixComments)
            {
                back.PrefixComments[item.Key].ShouldBe(item.Value);
            }
            dc.Literals.Count.ShouldBe(back.Literals.Count);
            foreach (var item in dc.Literals)
            {
                back.Literals[item.Key].ForEach(v => dc.Literals[item.Key].ShouldContain(v));
                dc.Literals[item.Key].ForEach(v => back.Literals[item.Key].ShouldContain(v));
            }
            dc.LiteralReplacements.Count.ShouldBe(back.LiteralReplacements.Count);
            foreach (var item in dc.LiteralReplacements)
            {
                back.LiteralReplacements[item.Key].ShouldBe(item.Value);
            }
            dc.MemoryMap.Count.ShouldBe(back.MemoryMap.Count);
            for (var i = 0; i < dc.MemoryMap.Count; i++)
            {
                dc.MemoryMap[i].ShouldBe(back.MemoryMap[i]);
            }
        }
コード例 #2
0
        /// <summary>
        /// Saves the contents of annotations
        /// </summary>
        public void SaveAnnotations(DisassemblyAnnotation annotation, string filename)
        {
            if (annotation == null || filename == null)
            {
                return;
            }

            var annotationData = annotation.Serialize();

            File.WriteAllText(filename, annotationData);
        }
コード例 #3
0
ファイル: RomGenerators.cs プロジェクト: rdacomp/spectnetide
        public void GenerateSpectrum48Annotations()
        {
            // --- Arrange
            var dc = new DisassemblyAnnotation();

            dc.MemoryMap.Add(new MemorySection(0x0000, 0x3BFF));
            dc.MemoryMap.Add(new MemorySection(0x3C00, 0x3FFF));
            dc.AddLiteral(0x04C2, "$SaveBytesRoutineAddress");
            dc.AddLiteral(0x0000, "$SaveBytesResumeAddress");
            dc.AddLiteral(0x056C, "$LoadBytesRoutineAddress");
            dc.AddLiteral(0x05E2, "$LoadBytesResumeAddress");
            dc.AddLiteral(0x05B6, "$LoadBytesInvalidHeaderAddress");

            // --- Act
            Console.WriteLine(dc.Serialize());
        }
コード例 #4
0
        /// <summary>
        /// Saves the annotation file for the specified address
        /// </summary>
        /// <param name="annotation">Annotation to save</param>
        /// <param name="address"></param>
        public void SaveAnnotations(DisassemblyAnnotation annotation, ushort address)
        {
            string filename;
            var    isRom      = false;
            var    spectrumVm = SpectNetPackage.Default.EmulatorViewModel.Machine.SpectrumVm;

            if (Parent.FullViewMode)
            {
                var memDevice = spectrumVm.MemoryDevice;
                var(isInRom, index, _) = memDevice.GetAddressLocation(address);
                if (isInRom)
                {
                    filename = RomAnnotationFiles.TryGetValue(index, out var romFile)
                        ? romFile : null;
                    isRom = true;
                }
                else
                {
                    filename = RamBankAnnotationFile;
                }
            }
            else if (Parent.RomViewMode)
            {
                filename = RomAnnotationFiles.TryGetValue(Parent.RomIndex, out var romFile)
                    ? romFile : null;
                isRom = true;
            }
            else
            {
                filename = RamBankAnnotationFile;
            }
            if (filename == null)
            {
                return;
            }

            var annotationData = isRom ? annotation.Serialize() : SerializeRamBankAnnotations();

            File.WriteAllText(filename, annotationData);
        }