Beispiel #1
0
        ProgramHeader[] ReadElfProgramHeader(BufferedStream elfFileReader)
        {
            elfFileReader.Seek(0, SeekOrigin.Begin);
            int elf = ReadNextBigEndianInt(elfFileReader);

            if (elf != 0x7f454c46)
            {
                throw new ArgumentException("Input file is not an ELF file.");
            }
            elfFileReader.Seek(0x1C, SeekOrigin.Begin);
            int po = ReadNextBigEndianInt(elfFileReader);

            elfFileReader.Seek(11, SeekOrigin.Current);
            int plen = elfFileReader.ReadByte();

            elfFileReader.Seek(1, SeekOrigin.Current);
            int pnum = elfFileReader.ReadByte();

            elfFileReader.Seek(po, SeekOrigin.Begin);
            ProgramHeader[] ret = new ProgramHeader[pnum];
            for (int i = 0; i < pnum; i++)
            {
                ret[i]        = new ProgramHeader();
                ret[i].type   = ReadNextBigEndianInt(elfFileReader);
                ret[i].offset = ReadNextBigEndianInt(elfFileReader);
                ret[i].vaddr  = ReadNextBigEndianInt(elfFileReader);
                elfFileReader.Seek(4, SeekOrigin.Current);
                ret[i].length = ReadNextBigEndianInt(elfFileReader);
                elfFileReader.Seek(12, SeekOrigin.Current);
            }
            return(ret);
        }
Beispiel #2
0
        public void SeveralFilesInSeveralSegments()
        {
            var firstFileBytes  = TestData.GetElfFileBytesFromBuildId(TestData.expectedId);
            var secondFileBytes = TestData.GetElfFileBytesFromBuildId(TestData.anotherExpectedId);
            var data            = firstFileBytes.Concat(secondFileBytes).ToArray();

            var firstFileSection  = new FileSection("", 0, (ulong)firstFileBytes.Length);
            var secondFileSection = new FileSection("", (ulong)firstFileBytes.Length,
                                                    (ulong)data.Length);

            var reader = new BinaryReader(new MemoryStream(data));

            var firstSegmentSize = firstFileBytes.Length - 1;
            var firstSegment     = new ProgramHeader(ProgramHeader.Type.LoadableSegment, 0, 0,
                                                     (ulong)firstFileBytes.Length - 1);

            var secondSegment = new ProgramHeader(ProgramHeader.Type.LoadableSegment,
                                                  (ulong)firstSegmentSize,
                                                  (ulong)firstSegmentSize,
                                                  (ulong)secondFileBytes.Length + 1);

            var firstModule = ReadModule(data, new[] { secondSegment, firstSegment },
                                         firstFileSection);

            Assert.AreEqual(TestData.expectedId, firstModule.Id);

            var secondModule = ReadModule(data, new[] { firstSegment, secondSegment },
                                          secondFileSection);

            Assert.AreEqual(TestData.anotherExpectedId, secondModule.Id);
        }
Beispiel #3
0
        private void WriteProgramHeaders(EndianAwareBinaryWriter writer)
        {
            writer.Position = elfheader.ProgramHeaderOffset;

            foreach (var section in Sections)
            {
                if (section.Size == 0 && section.SectionKind != SectionKind.BSS)
                {
                    continue;
                }

                var pheader = new ProgramHeader
                {
                    Alignment       = 0,
                    FileSize        = section.AlignedSize,
                    MemorySize      = section.AlignedSize,
                    Offset          = section.FileOffset,
                    VirtualAddress  = (uint)section.VirtualAddress,
                    PhysicalAddress = (uint)section.VirtualAddress,
                    Type            = ProgramHeaderType.Load,
                    Flags           =
                        (section.SectionKind == SectionKind.Text) ? ProgramHeaderFlags.Read | ProgramHeaderFlags.Execute :
                        (section.SectionKind == SectionKind.ROData) ? ProgramHeaderFlags.Read : ProgramHeaderFlags.Read | ProgramHeaderFlags.Write
                };

                pheader.Write(writer);
            }
        }
        public void ShortStream()
        {
            var data   = new byte[ProgramHeader.Size - 1];
            var reader = new BinaryReader(new MemoryStream(data));

            Assert.IsFalse(ProgramHeader.TryRead(reader, out ProgramHeader h));
        }
Beispiel #5
0
        public static ElfHeader Read(Stream input)
        {
            var fileHeader = input.ReadStructure <FileHeader>();

            fileHeader.Swap();

            if (fileHeader.HeaderSize != Marshal.SizeOf(fileHeader))
            {
                throw new FormatException("size mismatch for ELF header size");
            }

            input.Seek(fileHeader.ProgramHeadersOffset, SeekOrigin.Begin);
            var programHeaders = new ProgramHeader[fileHeader.ProgramHeaderCount];

            for (int i = 0; i < programHeaders.Length; i++)
            {
                programHeaders[i] = input.ReadStructure <ProgramHeader>();
                if (fileHeader.ProgramHeaderEntrySize != Marshal.SizeOf(programHeaders[i]))
                {
                    throw new FormatException("size mismatch for ELF program header size");
                }
                programHeaders[i].Swap();
            }

            input.Seek(fileHeader.SectionHeadersOffset, SeekOrigin.Begin);
            var sectionHeaders = new SectionHeader[fileHeader.SectionHeaderCount];

            for (int i = 0; i < sectionHeaders.Length; i++)
            {
                sectionHeaders[i] = input.ReadStructure <SectionHeader>();
                if (fileHeader.SectionHeaderEntrySize != Marshal.SizeOf(sectionHeaders[i]))
                {
                    throw new FormatException("size mismatch for ELF section header size");
                }
                sectionHeaders[i].Swap();
            }

            var sectionNames = new string[fileHeader.SectionHeaderCount];

            if (fileHeader.SectionHeaderStringTableIndex < fileHeader.SectionHeaderCount)
            {
                var stringTableHeader = sectionHeaders[fileHeader.SectionHeaderStringTableIndex];
                for (int i = 0; i < sectionHeaders.Length; i++)
                {
                    input.Seek(stringTableHeader.FileOffset + sectionHeaders[i].Name, SeekOrigin.Begin);
                    sectionNames[i] = input.ReadStringZ(Encoding.ASCII);
                }
            }

            return(new ElfHeader()
            {
                _FileHeader = fileHeader,
                _ProgramHeaders = programHeaders,
                _SectionHeaders = sectionHeaders,
                _SectionNames = sectionNames,
            });
        }
Beispiel #6
0
        public void FileStartBeforeSegment()
        {
            var data    = TestData.GetElfFileBytesFromBuildId(TestData.expectedId);
            var segment = new ProgramHeader(ProgramHeader.Type.LoadableSegment, 0, 1,
                                            (ulong)data.Length);

            var module = ReadModule(data, new[] { segment },
                                    new FileSection("", 0, (ulong)data.Length));

            Assert.AreEqual(BuildId.Empty, module.Id);
        }
Beispiel #7
0
        public void BuildIdEndsOutsideSegment()
        {
            var data    = TestData.GetElfFileBytesFromBuildId(TestData.expectedId);
            var segment = new ProgramHeader(
                ProgramHeader.Type.LoadableSegment, 0, 0, (ulong)data.Length - 1);

            var module = ReadModule(data, new[] { segment },
                                    new FileSection("", 0, (ulong)data.Length));

            Assert.AreNotEqual(TestData.expectedId, module.Id);
        }
        public void OtherSegment()
        {
            var data = TestData.GetProgramHeaderBytes(
                (ProgramHeader.Type) byte.MaxValue, expectedOffset, expectedVaddr, expectedSize);

            var reader = new BinaryReader(new MemoryStream(data));

            Assert.IsTrue(ProgramHeader.TryRead(reader, out ProgramHeader h));
            Assert.AreEqual(expectedOffset, h.OffsetInFile);
            Assert.AreEqual(expectedVaddr, h.VirtualAddress);
            Assert.AreEqual(expectedSize, h.SizeInFile);
            Assert.AreEqual(ProgramHeader.Type.Other, h.HeaderType);
        }
Beispiel #9
0
        /// <summary>
        /// Parse the program header
        /// </summary>
        /// <param name="pLine">A line from the Rinex header</param>
        /// <returns>A instance of the header yexy</returns>
        public IProgramHeader ParseProgramHeader(string pLine)
        {
            string versionString = pLine.Substring(0, 9).TrimStart();

            IProgramHeader header = new ProgramHeader
            {
                ProgramName  = pLine.Substring(0, 20),
                Agency       = pLine.Substring(20, 19).Trim(),
                CreationDate = pLine.Substring(40, 19).Trim()
            };

            return(header);
        }
Beispiel #10
0
        public void FileAtTheMiddleOfSegment()
        {
            var buildIdFileData = TestData.GetElfFileBytesFromBuildId(TestData.expectedId);
            var buildIdLength   = buildIdFileData.Length;
            var data            = new byte[buildIdLength].Concat(buildIdFileData).ToArray();

            var segment = new ProgramHeader(ProgramHeader.Type.LoadableSegment, 0, 0,
                                            (ulong)data.Length);

            var module = ReadModule(data, new[] { segment },
                                    new FileSection("", (ulong)buildIdLength, (ulong)buildIdLength * 2));

            Assert.AreEqual(TestData.expectedId, module.Id);
        }
        public void UpdateExistingProgramHeader(ProgramHeader programHeader)
        {
            var updatedHeader = _ascendDb.ProgramHeaders.Where(p => p.Id == programHeader.Id).SingleOrDefault();

            if (updatedHeader == null)
            {
                throw new Exception(String.Format("Error updating a non-existent program header with id: {0}", programHeader.Id));
            }

            updatedHeader.BlockNo = programHeader.BlockNo;
            updatedHeader.WeekNo  = programHeader.WeekNo;
            updatedHeader.DayNo   = programHeader.DayNo;

            _ascendDb.SaveChanges();
        }
Beispiel #12
0
        virtual public void Load(Stream FileStream)
        {
            FileStream = new MemoryStream(FileStream.ReadAll());

            this.FileStream = FileStream;

            this.Header = FileStream.ReadStruct <Elf.HeaderStruct>();
            if (this.Header.Magic != Elf.HeaderStruct.MagicEnum.ExpectedValue)
            {
                throw(new InvalidProgramException("Not an ELF File"));
            }

            if (this.Header.Machine != Elf.HeaderStruct.MachineEnum.ALLEGREX)
            {
                throw (new InvalidProgramException("Invalid Elf.Header.Machine"));
            }

            this.ProgramHeaders = FileStream.ReadStructVectorAt <Elf.ProgramHeader>(Header.ProgramHeaderOffset, Header.ProgramHeaderCount, Header.ProgramHeaderEntrySize);
            this.SectionHeaders = FileStream.ReadStructVectorAt <Elf.SectionHeader>(Header.SectionHeaderOffset, Header.SectionHeaderCount, Header.SectionHeaderEntrySize);

            this.NamesSectionHeader = this.SectionHeaders[Header.SectionHeaderStringTable];
            this.StringTable        = FileStream.SliceWithLength(this.NamesSectionHeader.Offset, this.NamesSectionHeader.Size).ReadAll();

            this.SectionHeadersByName = new Dictionary <string, Elf.SectionHeader>();
            foreach (var SectionHeader in this.SectionHeaders)
            {
                var SectionHeaderName = GetStringFromStringTable(SectionHeader.Name);
                this.SectionHeadersByName[SectionHeaderName] = SectionHeader;
            }

            Console.WriteLine("ProgramHeaders:{0}", this.ProgramHeaders.Length);
            foreach (var ProgramHeader in ProgramHeaders)
            {
                Console.WriteLine("{0}", ProgramHeader.ToStringDefault());
            }

            Console.WriteLine("SectionHeaders:{0}", this.SectionHeaders.Length);
            foreach (var SectionHeader in SectionHeaders)
            {
                Console.WriteLine("{0}:{1}", GetStringFromStringTable(SectionHeader.Name), SectionHeader.ToStringDefault());
            }

            if (NeedsRelocation && this.ProgramHeaders.Length > 1)
            {
                //throw (new NotImplementedException("Not implemented several ProgramHeaders yet using relocation"));
            }
        }
Beispiel #13
0
        public void FileInSeveralSegments(int firstSegmentSize)
        {
            var data = TestData.GetElfFileBytesFromBuildId(TestData.expectedId);
            var secondSegmentSize = data.Length - firstSegmentSize;
            var firstSegment      = new ProgramHeader(
                ProgramHeader.Type.LoadableSegment, 0, 0, (ulong)firstSegmentSize);

            var secondSegment = new ProgramHeader(ProgramHeader.Type.LoadableSegment,
                                                  (ulong)firstSegmentSize,
                                                  (ulong)firstSegmentSize,
                                                  (ulong)secondSegmentSize);

            var module = ReadModule(data, new[] { secondSegment, firstSegment },
                                    new FileSection("", 0, (ulong)data.Length));

            Assert.AreEqual(TestData.expectedId, module.Id);
        }
 public void SwitchProgramTo(ProgramHeader destinationProgram)
 {
     try
     {
         this.Sequencer.SwitchProgram(destinationProgram.ProgramNo);
         this.AutoCommunicator.DoWork(true);
     }
     catch (SettingChangeException ex)
     {
         this.Dispose();
         throw new ConnectionLostException(ex.Message, (Exception)ex);
     }
     catch (ConnectionLostException ex)
     {
         this.Dispose();
         throw;
     }
 }
        internal override XDocument CreateXml()
        {
            XmlParserTempProjectHelper.currentObjectNum   = 0;
            XmlParserTempProjectHelper.currentScriptNum   = 0;
            XmlParserTempProjectHelper.currentBrickNum    = 0;
            XmlParserTempProjectHelper.currentVariableNum = 0;

            XmlParserTempProjectHelper.Document = new XDocument {
                Declaration = new XDeclaration("1.0", "UTF-8", "yes")
            };

            XmlParserTempProjectHelper.Program = this;

            var xProject = new XElement(XmlConstants.Program);

            xProject.Add(ProgramHeader.CreateXml());
            xProject.Add(SpriteList.CreateXml());
            xProject.Add(VariableList.CreateXml());
            XmlParserTempProjectHelper.Document.Add(xProject);

            return(XmlParserTempProjectHelper.Document);
        }
Beispiel #16
0
        public static void CheckBasicText()
        {
            string  fileName = "TreasureIsland";
            TapFile tapFile  = TapFileReader.ReadTapFile(PlatformSpecific.GetStreamForProjectFile("TapeFiles/SampleTapFiles/" + fileName + ".tap"), fileName);

            ProgramHeader firstHeader     = (ProgramHeader)tapFile.DataBlocks[0];
            int           programLength   = firstHeader.ProgramLength;
            int           variablesLength = firstHeader.FollowingDataLength - firstHeader.ProgramLength;

            TapDataBlock programAndVarsBlock = tapFile.DataBlocks[1];
            MemoryStream binaryMemoryStream  = new MemoryStream(programAndVarsBlock.TapeData);

            // Read flag
            binaryMemoryStream.ReadByte();

            BasicProgram program = BasicReader.ReadMemoryFormat(fileName, binaryMemoryStream, programLength, variablesLength);

            /*
             * 10 REM Treasure island
             * 100 REM parrot
             * 110 POKE USR "p"+0|0,BIN 00100000|32
             * 120 POKE USR "p"+1|1,BIN 00110110|54
             * 130 POKE USR "p"+2|2,BIN 00111110|62
             * 140 POKE USR "p"+3|3,BIN 00011100|28
             * 150 POKE USR "p"+4|4,BIN 00011110|30
             * 160 POKE USR "p"+5|5,BIN 00100111|39
             * 170 POKE USR "p"+6|6,BIN 01000000|64
             * 180 POKE USR "p"+7|7,BIN 00000000|0
             * 200 REM native
             * 210 POKE USR "n"+0|0,BIN 00000001|1
             * 220 POKE USR "n"+1|1,BIN 00011001|25
             * 230 POKE USR "n"+2|2,BIN 11011001|217
             * 240 POKE USR "n"+3|3,BIN 11111111|255
             * 250 POKE USR "n"+4|4,BIN 11011001|217
             * 260 POKE USR "n"+5|5,BIN 00011001|25
             * 270 POKE USR "n"+6|6,BIN 00100101|37
             * 280 POKE USR "n"+7|7,BIN 00100101|37
             * 300 REM ship sail
             * 310 POKE USR "j"+0|0,BIN 11111111|255
             * 320 POKE USR "j"+1|1,BIN 01111110|126
             * 330 POKE USR "j"+2|2,BIN 10100101|165
             * 340 POKE USR "j"+3|3,BIN 11000011|195
             * 350 POKE USR "j"+4|4,BIN 11000011|195
             * 360 POKE USR "j"+5|5,BIN 10100101|165
             * 370 POKE USR "j"+6|6,BIN 01111110|126
             * 380 POKE USR "j"+7|7,BIN 11111111|255
             * 400 REM ship
             * 410 POKE USR "s"+0|0,BIN 00010000|16
             * 420 POKE USR "s"+1|1,BIN 11111111|255
             * 430 POKE USR "s"+2|2,BIN 11111111|255
             * 440 POKE USR "s"+3|3,BIN 01111110|126
             * 450 POKE USR "s"+4|4,BIN 01111110|126
             * 460 POKE USR "s"+5|5,BIN 01111110|126
             * 470 POKE USR "s"+6|6,BIN 00111100|60
             * 480 POKE USR "s"+7|7,BIN 00111100|60
             * 500 REM quicksand
             * 510 POKE USR "q"+0|0,BIN 00001100|12
             * 520 POKE USR "q"+1|1,BIN 00011100|28
             * 530 POKE USR "q"+2|2,BIN 00111110|62
             * 540 POKE USR "q"+3|3,BIN 01111111|127
             * 550 POKE USR "q"+4|4,BIN 11111111|255
             * 560 POKE USR "q"+5|5,BIN 11111110|254
             * 570 POKE USR "q"+6|6,BIN 01111100|124
             * 580 POKE USR "q"+7|7,BIN 00111000|56
             * 600 REM man
             * 610 POKE USR "m"+0|0,BIN 00011000|24
             * 620 POKE USR "m"+1|1,BIN 00011000|24
             * 630 POKE USR "m"+2|2,BIN 01111110|126
             * 640 POKE USR "m"+3|3,BIN 00011000|24
             * 650 POKE USR "m"+4|4,BIN 00111100|60
             * 660 POKE USR "m"+5|5,BIN 01100110|102
             * 670 POKE USR "m"+6|6,BIN 01100110|102
             * 680 POKE USR "m"+7|7,BIN 00000000|0
             * 810 LET f=0|0
             * 820 LET xs=1|1: LET ys=1|1
             * 830 LET mes=0|0
             * 840 DIM v(10|10)
             * 850 DIM u(10|10)
             * 860 DIM l(20|20)
             * 870 DIM r(20|20)
             * 880 DIM x(20|20)
             * 1050 GO SUB 5000|5000
             * 1060 LET xm=x(t+1|1)
             * 1070 LET ym=t+1|1
             * 1100 GO SUB 3000|3000
             * 1110 PAUSE 50|50+RND *20|20
             * 1150 GO SUB 7000|7000
             * 1200 GO SUB 3570|3570
             * 1210 GO SUB 3500|3500
             * 1270 IF xm=xtAND ym=ytTHEN  GO TO 9000|9000
             * 1280 LET f=f+1|1
             * 1290 IF INT (f/5|5)=f/5|5THEN  GO SUB 6000|6000
             * 1300 IF x(ym)=xmAND INT (f/5|5)=f/5|5THEN  GO TO 1150|1150
             * 1310 IF x(ym)=xmTHEN  GO TO 1210|1210
             * 1330 REM off path
             * 1340 BEEP .3|0.299999999930151,-6|6: GO SUB 6000|6000
             * 1350 FOR q=1|1TO 10|10
             * 1360 REM test for quicksands
             * 1370 IF v(q)=xmAND u(q)=ymTHEN  GO SUB 4000|4000
             * 1380 NEXT q
             * 1400 IF RND <= .4|0.399999999906868THEN  GO TO 2000|2000
             * 1410 REM natives logic
             * 1420 GO SUB 7000|7000
             * 1430 PRINT AT 19|19,1|1; PAPER 8|8; INK 0|0;"HOSTILE NATIVES AHEAD"
             * 1440 FOR n=1|1TO 3|3
             * 1445 LET r=INT (RND *3|3)
             * 1448 IF ym+r>= bTHEN  LET r=0|0
             * 1450 PRINT AT ym+r,xm; PAPER 8|8; INK 0|0;"[UDG-N]"
             * 1460 NEXT n
             * 1470 LET ym=ym-3|3
             * 1480 IF ym<= t+1|1THEN  LET ym=t+1|1
             * 1490 LET xm=x(ym)
             * 1500 PRINT AT ym,xm; PAPER 8|8; INK 0|0;"[UDG-M]"
             * 1550 LET mes=1|1
             * 1560 GO TO 1210|1210
             * 2000 REM parrot logic
             * 2010 GO SUB 7000|7000
             * 2020 GO SUB 3570|3570
             * 2050 PRINT AT 19|19,1|1; PAPER 8|8; INK 0|0;"FOLLOW LONG JOHN SILVERS PARROT"
             * 2100 LET yj=ym+1|1
             * 2110 IF yj>pTHEN  LET yj=p
             * 2120 LET xj=x(yj)
             * 2130 PRINT AT yj,xj; PAPER 8|8; INK 2|2;"[UDG-P]"
             * 2140 LET mes=1|1
             * 2150 GO TO 1210|1210
             * 3000 REM print island
             * 3110 PAPER 7|7: INK 0|0
             * 3120 CLS
             * 3140 PRINT AT t,l(t);"[BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12]"(1|1TO r(t)-l(t)+1|1)
             * 3160 FOR y=tTO b
             * 3170 PRINT AT y,l(y);"[BG-9]";AT y,r(y);"[BG-6]"
             * 3180 NEXT y
             * 3260 PRINT AT b+1|1,l(b);"[BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12][BG-12]"(1|1TO r(b)-l(b)+1|1)
             * 3300 REM print path
             * 3350 FOR y=t+1|1TO p
             * 3360 PRINT AT y,x(y);"#"
             * 3370 NEXT y
             * 3400 PRINT AT 20|20,1|1;"X MARKS THE SPOT"
             * 3410 PRINT AT p,x(p);"X"
             * 3420 PRINT AT ym,xm;"[UDG-M]"
             * 3440 RETURN
             * 3460 GO TO 3510|3510
             * 3500 REM move man
             * 3510 BEEP .1|0.0999999999767169,6|6
             * 3515 LET a$=INKEY$
             * 3520 IF a$=""THEN  GO TO 3515|3515
             * 3525 PRINT AT ym,xm; PAPER 8|8; INK 0|0;" "
             * 3530 IF a$="h"THEN  GO SUB 8000|8000: RETURN
             * 3535 IF a$="5"THEN  LET xm=xm-1|1: GO TO 3560|3560
             * 3540 IF a$="8"THEN  LET xm=xm+1|1: GO TO 3560|3560
             * 3550 IF a$<> "6"THEN  GO TO 3510|3510
             * 3560 LET ym=ym+1|1
             * 3570 PRINT AT ym,xm; PAPER 8|8; INK 0|0;"[UDG-M]"
             * 3580 IF mes=0|0THEN  RETURN
             * 3585 FOR i=0|0TO 31|31
             * 3590 PRINT AT 19|19,i; PAPER 8|8;" "
             * 3595 NEXT i
             * 3598 LET mes=0|0: RETURN
             * 3600 REM print quicksands
             * 3620 FOR q=1|1TO 10|10
             * 3650 PRINT AT u(q),v(q); INK 4|4; PAPER 8|8;"[UDG-Q]"
             * 3660 NEXT q
             * 3700 PRINT AT 17|17,3|3; INK 0|0; PAPER 8|8;"[UDG-P]";AT 16|16,3|3;"[UDG-N]"
             * 3800 LET xs=xs+1|1
             * 3810 LET ys=ys+1|1
             * 3900 RETURN
             * 4000 REM quicksand
             * 4010 GO SUB 7000|7000
             * 4020 PRINT AT ym,xm; INK 6|6; PAPER 8|8;"[UDG-Q]"
             * 4100 PRINT AT ym+1|1,xm+1|1; PAPER 8|8; INK 0|0;"AARGH"
             * 4110 FOR i=5|5TO -5|5STEP -1|1
             * 4120 BEEP .1|0.0999999999767169,i
             * 4150 NEXT i
             * 4160 PRINT AT 19|19,1|1; INK 0|0; PAPER 8|8;"IN THE QUICKSAND"
             * 4170 IF RND >0.5|0.499999999883585THEN  PRINT  INK 0|0; PAPER 8|8;"A friendly native pulled you out": PAUSE 100|100: RETURN
             * 4180 GO TO 9990|9990
             * 5000 REM calculate island
             * 5120 LET l=INT (RND *3|3)+10|10
             * 5130 LET t=INT (RND *3|3)+2|2
             * 5140 LET w=INT (RND *3|3)+10|10
             * 5150 LET b=INT (RND *2|2)+17|17
             * 5230 FOR y=tTO b
             * 5240 LET l(y)=l
             * 5250 LET r(y)=l+w
             * 5340 LET l=l-(SGN (10|10-y)*INT (RND *2|2))
             * 5350 LET w=w+(SGN (10|10-y)*INT (RND *2|2))
             * 5360 IF l(y)>30|30THEN  LET l(y)=30|30
             * 5380 NEXT y
             * 5500 REM path logic
             * 5510 LET x(t+1|1)=l(t+1|1)+INT (RND *4|4)
             * 5520 LET k=t+2|2
             * 5550 FOR p=kTO b-1|1-INT (RND *3|3)
             * 5610 LET x(p)=x(p-1|1)+INT (RND *3|3)-1|1
             * 5620 IF x(p)>= r(p)THEN  LET x(p)=r(p)-1|1
             * 5630 IF x(p)<= l(p)THEN  LET x(p)=l(p)+1|1
             * 5640 NEXT p
             * 5645 LET p=p-1|1
             * 5650 REM treasure
             * 5660 LET xt=x(p)
             * 5670 LET yt=p
             * 5700 REM quicksand logic
             * 5710 FOR q=1|1TO 10|10
             * 5720 LET d=INT (RND *(p-t-2|2))+t+1|1
             * 5750 LET u(q)=d
             * 5760 LET v(q)=x(d)+SGN (RND *.5|0.499999999883585)
             * 5770 IF v(q)<= l(d)THEN  LET v(q)=v(q)+3|3
             * 5780 IF v(q)>= r(d)THEN  LET v(q)=v(q)-3|3
             * 5790 NEXT q
             * 5800 RETURN
             * 6000 REM priate ship
             * 6010 INK 5|5: PAPER 5|5
             * 6020 CLS
             * 6030 LET r=INT (RND *3|3)
             * 6100 LET xs=xs+r
             * 6200 LET ys=ys+r
             * 6210 PRINT AT 18|18,18|18; INK 4|4;"[UDG-Q]"
             * 6220 PRINT AT ys,xs; INK 0|0;"[UDG-J]"
             * 6230 PRINT AT ys+1|1,xs; INK 0|0;"[UDG-S]"
             * 6240 PAUSE 50|50
             * 6250 IF ys<18|18THEN  RETURN
             * 6280 PRINT AT 19|19,1|1; PAPER 8|8; INK 0|0;"THE PIRATES HAVE LANDED"
             * 6290 PRINT  PAPER 8|8; INK 0|0;"YOU AE CAPTURED"
             * 6300 GO TO 9990|9990
             * 7000 REM reprint island
             * 7100 PAPER 5|5: INK 0|0
             * 7110 CLS
             * 7225 PRINT AT t-1|1,l(t); PAPER 6|6;"                                "(1|1TO r(t)-l(t)+1|1)
             * 7230 FOR y=tTO b
             * 7250 PRINT AT y,l(y)-1|1; PAPER 6|6;" "; PAPER 4|4;"                                "(1|1TO r(y)-l(y)+1|1); PAPER 6|6;" "
             * 7360 NEXT y
             * 7410 PRINT AT y,l(b); PAPER 6|6;"                                "(1|1TO r(b)-l(b)+1|1)
             * 7500 RETURN
             * 8000 GO SUB 3000|3000
             * 8010 GO SUB 3600|3600
             * 8020 PAUSE 100|100+INT RND *100|100
             * 8030 GO SUB 6000|6000
             * 8040 GO SUB 7000|7000
             * 8050 GO SUB 3570|3570
             * 8060 RETURN
             * 9000 REM treasure found
             * 9100 FOR c=0|0TO 6|6
             * 9140 BRIGHT 0|0
             * 9150 PAPER c
             * 9160 CLS
             * 9180 PAUSE 5|5
             * 9200 BRIGHT 1|1
             * 9239 CLS
             * 9240 BEEP .1|0.0999999999767169,c*2|2
             * 9260 PAUSE 5|5
             * 9270 NEXT c
             * 9300 PRINT AT 10|10,7|7;"YOU FOUND THE GOLD"
             * 9310 BEEP 1|1,14|14
             * 9350 BRIGHT 0|0
             * 9360 PAUSE 20|20
             * 9990 INPUT "Another game (y/n)?";a$
             * 9991 IF a$=""THEN  GO TO 9990|9990
             * 9995 IF a$(1|1)="y"THEN  RUN
             * 9999 PAPER 7|7: INK 0|0: CLS
             *
             * --- PROGRAM VARIABLES ---
             *
             #Number# f = 0
             #Number# xs = 1
             #Number# ys = 1
             #Number# mes = 0
             #Number# l = 10
             #Number# t = 2
             #Number# w = 11
             #Number# b = 18
             #ForLoopControl# y = value:8, limit:17, step:1, loopingline:3350, statementinline:2
             #Number# k = 4
             #ForLoopControl# p = value:17, limit:17, step:1, loopingline:5550, statementinline:2
             #Number# xt = 14
             #Number# yt = 17
             #ForLoopControl# q = value:11, limit:10, step:1, loopingline:5710, statementinline:2
             #Number# d = 12
             #Number# xm = 11
             #Number# ym = 3
             #Number# r = 2
             #Number# yj = 15
             #Number# xj = 10
             #ForLoopControl# i = value:32, limit:31, step:1, loopingline:3585, statementinline:2
             #ForLoopControl# n = value:4, limit:3, step:1, loopingline:1440, statementinline:2
             #String# a$ = 8
             #ForLoopControl# c = value:5, limit:6, step:1, loopingline:9100, statementinline:2
             #NumberArray# v = [ 13 14 14 13 14 14 15 14 15 14 ]
             #NumberArray# u = [ 6 14 12 5 11 14 15 14 15 12 ]
             #NumberArray# l = [ 0 10 10 10 9 8 7 6 5 4 4 4 5 6 6 7 8 9 0 0 ]
             #NumberArray# r = [ 0 21 21 21 20 20 20 20 20 19 19 19 19 19 19 20 21 21 0 0 ]
             #NumberArray# x = [ 0 0 11 12 12 12 12 12 12 12 13 13 13 13 14 13 14 0 0 0 ]
             */
        }
Beispiel #17
0
        public OricProgram Load(string strTapeName, string strProgName, ushort siProgIndex)
        {
            ushort i16ProgramCount = 0;
            ushort i16NoNameCount  = 0;

            OricProgram loadProgram = new OricProgram();

            TapeName = strTapeName;

            ReadTapeIntoBuffer();

            m_ui32BufferIdx = 0;

            while (SyncTape() && siProgIndex >= i16ProgramCount)
            {
                // Store the program header
                ProgramHeader programHeader = ReadProgramHeader();

                // Set the parent name
                loadProgram.ParentName = strTapeName;

                // Store program information
                loadProgram.StartAddress = programHeader.ui16StartAddress;
                loadProgram.EndAddress   = programHeader.ui16EndAddress;
                loadProgram.AutoRun      = programHeader.bAutoRun;

                if (programHeader.bProgramFormat == 0x00)
                {
                    loadProgram.Format = OricProgram.ProgramFormat.BasicProgram;
                }
                else
                {
                    if (programHeader.ui16StartAddress == 0xA000)
                    {
                        loadProgram.Format = OricProgram.ProgramFormat.HiresScreen;
                    }
                    else if (programHeader.ui16StartAddress == 0xB500)
                    {
                        loadProgram.Format = OricProgram.ProgramFormat.CharacterSet;
                    }
                    else if (programHeader.ui16StartAddress.In((ushort)0xBB80, (ushort)0xBBA8))
                    {
                        loadProgram.Format = OricProgram.ProgramFormat.TextScreen;
                    }
                    else
                    {
                        loadProgram.Format = OricProgram.ProgramFormat.BinaryFile;
                    }
                }

                if (programHeader.strProgramName == null)
                {
                    loadProgram.ProgramName = string.Format("NONAME{0:G3}", i16NoNameCount);
                    i16NoNameCount++;
                }
                else
                {
                    loadProgram.ProgramName = programHeader.strProgramName;
                }

                if (i16ProgramCount == siProgIndex)
                {
                    ushort ui16Count      = 0;
                    ushort ui16ProgLength = loadProgram.ProgramLength;

                    loadProgram.ProgramData = new byte[ui16ProgLength];

                    do
                    {
                        loadProgram.ProgramData[ui16Count] = m_bTapeBuffer[m_ui32BufferIdx];

                        ui16Count++;
                        m_ui32BufferIdx++;
                    } while((ui16Count < ui16ProgLength) && (m_ui32BufferIdx < m_bTapeBuffer.Length));
                }
                else
                {
                    // Move buffer pointer beyond program data
                    m_ui32BufferIdx += loadProgram.ProgramLength;

                    // Skip passed the null terminator
                    m_ui32BufferIdx++;
                }

                i16ProgramCount++;
            }

            return(loadProgram);
        }
Beispiel #18
0
        private ProgramHeader ReadProgramHeader()
        {
            byte highByte;
            byte lowByte;

            ProgramHeader programHeader = new ProgramHeader();

            // Skip passed the unused bytes
            m_ui32BufferIdx += 1;

            if (WriteToLogFile)
            {
                swLogfile.WriteLine("> Reading program header. (Offset 0x{0:X4})", m_ui32BufferIdx);
            }

            // Get the program type
            byte bProgramFormat = m_bTapeBuffer[m_ui32BufferIdx];

            programHeader.bProgramFormat = m_bTapeBuffer[m_ui32BufferIdx];

            m_ui32BufferIdx++;

            // Get the AutoRun flag
            if (m_bTapeBuffer[m_ui32BufferIdx] == 0x00)
            {
                programHeader.bAutoRun = OricProgram.AutoRunFlag.Disabled;
            }
            else
            {
                programHeader.bAutoRun = OricProgram.AutoRunFlag.Enabled;
            }

            m_ui32BufferIdx++;

            // Get the programs end address
            highByte = m_bTapeBuffer[m_ui32BufferIdx];
            lowByte  = m_bTapeBuffer[m_ui32BufferIdx + 1];

            programHeader.ui16EndAddress = Convert.ToUInt16(lowByte + (highByte * 256));

            m_ui32BufferIdx += 2;

            // Get the programs start address
            highByte = m_bTapeBuffer[m_ui32BufferIdx];
            lowByte  = m_bTapeBuffer[m_ui32BufferIdx + 1];

            programHeader.ui16StartAddress = Convert.ToUInt16(lowByte + (highByte * 256));

            if (bProgramFormat == 0x00)
            {
                programHeader.bProgramFormat = (byte)OricProgram.ProgramFormat.BasicProgram;
            }
            else
            {
                if (programHeader.ui16StartAddress == 0xA000)
                {
                    programHeader.bProgramFormat = (byte)OricProgram.ProgramFormat.HiresScreen;
                }
                else if (programHeader.ui16StartAddress == 0xB500)
                {
                    programHeader.bProgramFormat = (byte)OricProgram.ProgramFormat.CharacterSet;
                }
                else if (programHeader.ui16StartAddress.In((ushort)0xBB80, (ushort)0xBBA8))
                {
                    programHeader.bProgramFormat = (byte)OricProgram.ProgramFormat.TextScreen;
                }
                else
                {
                    programHeader.bProgramFormat = (byte)OricProgram.ProgramFormat.BinaryFile;
                }
            }

            m_ui32BufferIdx += 3;

            while (m_bTapeBuffer[m_ui32BufferIdx] != 0)
            {
                programHeader.strProgramName += Convert.ToChar(m_bTapeBuffer[m_ui32BufferIdx]);
                m_ui32BufferIdx++;
            }

            // Skip passed the null terminator
            m_ui32BufferIdx++;

            return(programHeader);
        }
Beispiel #19
0
        public OricFileInfo[] Catalog(FileInfo fiFileInfo)
        {
            ushort i16ProgramCount = 0;
            ushort i16NoNameCount  = 1;

            bool bReadError = false;

            // Store the tape name
            TapeName = fiFileInfo.FullName;

            if (fiFileInfo.Name == "NewTape.tap")
            {
                i16NoNameCount  = 1;
                i16ProgramCount = 0;
            }

            // Read the entire tape into a buffer
            ReadTapeIntoBuffer();

            // Create an array to store program information
            ArrayList tapeCatalog = new ArrayList();

            // Initialise the buffer position
            m_ui32BufferIdx = 0;

            // Syncronise with the tape header
            while (SyncTape() && !bReadError)
            {
                // Store the program header
                ProgramHeader programHeader = ReadProgramHeader();

                // Check details in Program header are valid
                if (programHeader.ui16StartAddress >= programHeader.ui16EndAddress)
                {
                    if (WriteToLogFile)
                    {
                        swLogfile.WriteLine("> *** Invalid Start/End address found in header. ***");
                        swLogfile.WriteLine("> *** Start : ${0:X4}, End : ${1:X4} ***",
                                            programHeader.ui16StartAddress, programHeader.ui16EndAddress);

                        bReadError = true;

                        m_ui32BufferIdx = (uint)(m_bTapeBuffer.Length + 1);
                    }
                }
                else
                {
                    // Create a Catalog object to store tape information
                    OricFileInfo tapeProgram = new OricFileInfo
                    {
                        Folder = fiFileInfo.DirectoryName,

                        // Set the parent name
                        ParentName = fiFileInfo.Name,

                        // Store program information
                        StartAddress = programHeader.ui16StartAddress,
                        EndAddress   = programHeader.ui16EndAddress,
                        AutoRun      = programHeader.bAutoRun
                    };

                    if (programHeader.bProgramFormat == 0x00)
                    {
                        tapeProgram.Format = OricProgram.ProgramFormat.BasicProgram;
                    }
                    else
                    {
                        if (programHeader.ui16StartAddress == 0xA000)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.HiresScreen;
                        }
                        else if (programHeader.ui16StartAddress == 0xB500)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.CharacterSet;
                        }
                        else if (programHeader.ui16StartAddress.In((ushort)0xBB80, (ushort)0xBBA8))
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.TextScreen;
                        }
                        else
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.BinaryFile;
                        }
                    }

                    if (programHeader.strProgramName == null)
                    {
                        tapeProgram.ProgramName = string.Format("NONAME{0:G3}", i16NoNameCount);
                        i16NoNameCount++;
                    }
                    else
                    {
                        tapeProgram.ProgramName = programHeader.strProgramName;
                    }

                    tapeProgram.MediaType = ConstantsAndEnums.MediaType.TapeFile;

                    tapeProgram.ProgramIndex = i16ProgramCount;
                    i16ProgramCount++;

                    // Add information to the catalog
                    tapeCatalog.Add(tapeProgram);

                    // Move buffer pointer beyond program data
                    m_ui32BufferIdx += tapeProgram.LengthBytes;

                    // Skip passed the null terminator
                    m_ui32BufferIdx++;
                }
            }

            OricFileInfo[] programList = new OricFileInfo[tapeCatalog.Count];
            tapeCatalog.CopyTo(programList);

            //foreach (var grp in programList.ToList().GroupBy(g => g.ProgramName))
            //{
            //    int i = 0;
            //    if (grp.Count() > 1)
            //    {
            //        foreach(var itm in grp)
            //        {
            //            itm.ProgramName += $"#{++i}";
            //        }
            //    }
            //}

            return(programList);
        }
 public void DeleteProgramHeader(ProgramHeader header)
 {
     _ascendDb.ProgramHeaders.Remove(header);
     _ascendDb.SaveChanges();
 }
 public void CreateProgramHeader(ProgramHeader header)
 {
     _ascendDb.ProgramHeaders.Add(header);
     _ascendDb.SaveChanges();
 }
Beispiel #22
0
        public OricFileInfo[] Catalog(FileInfo fiFileInfo)
        {
            Int16 i16ProgramCount = 0;
            Int16 i16NoNameCount  = 1;

            Boolean bReadError = false;

            // Store the tape name
            TapeName = fiFileInfo.FullName;

            if (fiFileInfo.Name == "NewTape.tap")
            {
                i16NoNameCount  = 1;
                i16ProgramCount = 0;
            }

            // Read the entire tape into a buffer
            ReadTapeIntoBuffer();

            // Create an array to store program information
            ArrayList tapeCatalog = new ArrayList();

            // Initialise the buffer position
            m_ui32BufferIdx = 0;

            // Syncronise with the tape header
            while (SyncTape() && !bReadError)
            {
                // Store the program header
                ProgramHeader programHeader = ReadProgramHeader();

                // Check details in Program header are valid
                if (programHeader.ui16StartAddress >= programHeader.ui16EndAddress)
                {
                    if (m_bWriteToLogfile)
                    {
                        swLogfile.WriteLine("> *** Invalid Start/End address found in header. ***");
                        swLogfile.WriteLine("> *** Start : ${0:X4}, End : ${1:X4} ***",
                                            programHeader.ui16StartAddress, programHeader.ui16EndAddress);

                        bReadError = true;

                        m_ui32BufferIdx = (UInt32)(m_bTapeBuffer.Length + 1);
                    }
                }
                else
                {
                    // Create a Catalog object to store tape information
                    OricFileInfo tapeProgram = new OricFileInfo();

                    tapeProgram.Folder = fiFileInfo.DirectoryName;

                    // Set the parent name
                    tapeProgram.ParentName = fiFileInfo.Name;

                    // Store program information
                    tapeProgram.StartAddress = programHeader.ui16StartAddress;
                    tapeProgram.EndAddress   = programHeader.ui16EndAddress;
                    tapeProgram.AutoRun      = programHeader.bAutoRun;

                    if (programHeader.bProgramFormat == 0x00)
                    {
                        tapeProgram.Format = OricProgram.ProgramFormat.BasicProgram;
                    }
                    else
                    {
                        if (programHeader.ui16StartAddress == 0xA000)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.HiresScreen;
                        }
                        else if (programHeader.ui16StartAddress == 0xB500)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.CharacterSet;
                        }
                        else if (programHeader.ui16StartAddress == 0xBB80 || programHeader.ui16StartAddress == 0xBBA8)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.TextScreen;
                        }
                        else
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.CodeFile;
                        }
                    }

                    if (programHeader.strProgramName == null)
                    {
                        tapeProgram.ProgramName = String.Format("NONAME{0:G3}", i16NoNameCount);
                        i16NoNameCount++;
                    }
                    else
                    {
                        tapeProgram.ProgramName = programHeader.strProgramName;
                    }

                    tapeProgram.MediaType = OricExplorer.MediaType.TapeFile;

                    tapeProgram.ProgramIndex = i16ProgramCount;
                    i16ProgramCount++;

                    // Add information to the catalog
                    tapeCatalog.Add(tapeProgram);

                    // Move buffer pointer beyond program data
                    m_ui32BufferIdx += tapeProgram.LengthBytes;

                    // Skip passed the null terminator
                    m_ui32BufferIdx++;
                }
            }

            OricFileInfo[] programList = new OricFileInfo[tapeCatalog.Count];
            tapeCatalog.CopyTo(programList);

            return(programList);
        }
Beispiel #23
0
        public static void DecompileZ80tests()
        {
            string  fileName = "z80tests";
            TapFile tapFile  = TapFileReader.ReadTapFile(PlatformSpecific.GetStreamForProjectFile("TestTapes/" + fileName + ".tap"), fileName);

            ProgramHeader loaderHeader    = (ProgramHeader)tapFile.DataBlocks[0];
            int           programLength   = loaderHeader.ProgramLength;
            int           variablesLength = loaderHeader.FollowingDataLength - loaderHeader.ProgramLength;

            TapDataBlock loaderBlock        = tapFile.DataBlocks[1];
            MemoryStream binaryMemoryStream = new MemoryStream(loaderBlock.TapeData);

            /* Read flag */ binaryMemoryStream.ReadByte();
            BasicProgram basicLoader = BasicReader.ReadMemoryFormat(fileName, binaryMemoryStream, programLength, variablesLength);

            ByteArrayHeader codeHeader = (ByteArrayHeader)tapFile.DataBlocks[2];
            int             dataLength = codeHeader.DataLength;

            TapDataBlock codeBlock = tapFile.DataBlocks[3];

            binaryMemoryStream = new MemoryStream(codeBlock.TapeData);
            /* Read flag */ binaryMemoryStream.ReadByte();

            int baseAddress  = codeHeader.StartAddress;
            int startAddress = codeHeader.StartAddress;

            SpectrumMemoryMap spectrumMemory = new SpectrumMemoryMap();

            // Load machine code in memory to generate entry points BEFORE dissassembly
            int  b = -1;
            int  currentAddress       = baseAddress;
            long streamPositionBefore = binaryMemoryStream.Position;

            while ((b = binaryMemoryStream.ReadByte()) >= 0)
            {
                spectrumMemory.MemoryCells[currentAddress]            = (byte)b;
                spectrumMemory.MemoryCellDescriptions[currentAddress] = null; // Reset previous cell descriptions
                currentAddress++;
            }
            binaryMemoryStream.Position = streamPositionBefore;

            List <CallTarget> entryPoints = new List <CallTarget>();

            entryPoints.Add(new CallTarget(new CallSource(CallSourceType.ExternalEntryPoint, 0, null), startAddress));
            entryPoints.Add(new CallTarget(new CallSource(CallSourceType.CallInstruction, 0, null), 0x80B8));
            entryPoints.Add(new CallTarget(new CallSource(CallSourceType.CallInstruction, 0, null), 0x80C0));
            entryPoints.Add(new CallTarget(new CallSource(CallSourceType.JumpInstruction, 0x94CE, null), 0x94D1));
            ReadEntryPointsInTestsParametersTable(0x822B, spectrumMemory, entryPoints);
            ReadEntryPointsInTestsParametersTable(0x8407, spectrumMemory, entryPoints);

            Program program = Disassembler.GenerateProgram(fileName, binaryMemoryStream, baseAddress, entryPoints.ToArray(), spectrumMemory);

            foreach (ProgramLine line in program.Lines)
            {
                if (line.Type == ProgramLineType.OpCodeInstruction)
                {
                    TryReplaceAddressWithSystemVariables(spectrumMemory, program, line, 0);
                    TryReplaceAddressWithSystemVariables(spectrumMemory, program, line, 1);
                }
            }

            program.Lines.Insert(5, Assembler.ParseProgramLine("VAR_MEMPTR_CHECKSUM EQU FFFFH"));
            program.Lines.Insert(5, Assembler.ParseProgramLine("LAST_K EQU 5C08H"));
            program.Lines.Insert(5, Assembler.ParseProgramLine("CHAN_OPEN EQU 1601H"));
            program.Lines.Insert(5, Assembler.ParseProgramLine("CLS EQU 0D6BH"));
            program.Lines.Insert(5, Assembler.ParseProgramLine("START EQU 0000H"));
            program.Lines.Insert(5, Assembler.ParseProgramLine(""));
            program.RenumberLinesAfterLineNumber(0);

            program.PrefixLabelToProgramLine(0x8000, "MAIN");
            program.RenameSymbolInProgram("L8003", "EXEC_LDIR");
            program.RenameSymbolInProgram("L800A", "EXEC_LDDR");
            program.RenameSymbolInProgram("L8011", "EXEC_CPIR");
            program.RenameSymbolInProgram("L801A", "EXEC_CPDR");
            program.RenameSymbolInProgram("L8023", "EXEC_DJNZ_FF");
            program.RenameSymbolInProgram("L802B", "EXEC_DJNZ_FF_LOOP");
            program.RenameSymbolInProgram("L802E", "EXEC_DJNZ_01");
            program.RenameSymbolInProgram("L8036", "EXEC_DJNZ_01_LOOP");
            program.RenameSymbolInProgram("L8039", "MENU_SCREEN");
            program.RenameSymbolInProgram("L8042", "MENU_SCREEN_INPUT");
            program.RenameSymbolInProgram("L80DA", "INIT_SCREEN");
            program.AppendCommentToProgramLine(0x803C, "Menu screen string start address");
            program.InsertCommentAboveProgramLine(0x8114, "--- Menu screen string ---");
            CharDecoder decoder = new CharDecoder();

            program.CommentStringChars(0x8114, decoder.DecodeChar, Program.StringTerminationType.SpecialChar, 0, 0xFF);
            program.AppendCommentToProgramLine(0x8045, "If Key 1 was pressed");
            program.RenameSymbolInProgram("L8057", "FLAGS_TESTS");
            program.AppendCommentToProgramLine(0x8049, "If Key 2 was pressed");
            program.RenameSymbolInProgram("L805F", "MEMPTR_TESTS");
            program.AppendCommentToProgramLine(0x804D, "If Key 3 was pressed");
            program.InsertCommentAboveProgramLine(0x8057, "=> exit to BASIC");
            program.AppendCommentToProgramLine(0x80DA, "Clear the display");
            program.AppendCommentToProgramLine(0x80DF, "Open a channel : user stream 02");
            program.InsertCommentAboveProgramLine(0x80E2, "=> return to MENU_SCREEN");
            program.RenameSymbolInProgram("L80E2", "WAIT_KEYPRESS");
            program.RenameSymbolInProgram("L80E6", "WAIT_KEYPRESS_LOOP");
            program.RenameSymbolInProgram("L80ED", "DISPLAY_STRING");
            program.RenameSymbolInProgram("L80D2", "SETIY_DISPLAY_STRING");
            program.RenameSymbolInProgram("L80F5", "DISPLAY_TWO_HEXBYTES");
            program.RenameSymbolInProgram("L80FE", "DISPLAY_TWO_HEXCHARS");
            program.RenameSymbolInProgram("L810B", "DISPLAY_ONE_HEXCHAR");
            program.InsertCommentAboveProgramLine(0x80ED, "Display all chars starting from address DE upwards, until char FF");
            program.RenameSymbolInProgram("L8072", "TEST_SCREEN");
            program.RenameSymbolInProgram("L807D", "TEST_SCREEN_LAUNCH_TEST");
            program.RenameSymbolInProgram("L80AF", "TEST_SCREEN_NEXT_TEST");
            program.PrefixLabelToProgramLine(0x80B8, "TEST_SCREEN_TEST_PASSED", true);
            Program.ReplaceAddressWithSymbolInProgramLine(program.GetLineFromAddress(0x80A6), 1, false, "TEST_SCREEN_TEST_PASSED");
            program.PrefixLabelToProgramLine(0x80C0, "TEST_SCREEN_TEST_FAILED", true);
            Program.ReplaceAddressWithSymbolInProgramLine(program.GetLineFromAddress(0x80AA), 1, false, "TEST_SCREEN_TEST_FAILED");
            program.AppendCommentToProgramLine(0x805A, "Flags test screen string start address");
            program.InsertCommentAboveProgramLine(0x81CD, "--- Flags test screen string ---");
            program.CommentStringChars(0x81CD, decoder.DecodeChar, Program.StringTerminationType.SpecialChar, 0, 0xFF);
            program.AppendCommentToProgramLine(0x8057, "Flags tests parameter table start address");
            program.InsertCommentAboveProgramLine(0x822B, "--- Flags tests parameter table ---");
            program.AppendCommentToProgramLine(0x8062, "MEMPTR test screen string start address");
            program.InsertCommentAboveProgramLine(0x81EA, "--- MEMPTR test screen string ---");
            program.CommentStringChars(0x81EA, decoder.DecodeChar, Program.StringTerminationType.SpecialChar, 0, 0xFF);
            program.AppendCommentToProgramLine(0x805F, "MEMPTR tests parameter table start address");
            program.InsertCommentAboveProgramLine(0x8407, "--- MEMPTR tests parameter table ---");
            program.RenameSymbolInProgram("L8067", "END_OF_TESTS");
            program.AppendCommentToProgramLine(0x8067, "End of tests string start address");
            program.InsertCommentAboveProgramLine(0x81AB, "--- End of tests string ---");
            program.CommentStringChars(0x81AB, decoder.DecodeChar, Program.StringTerminationType.SpecialChar, 0, 0xFF);
            program.AppendCommentToProgramLine(0x8226, "Space reserved to save HL in routine TEST_SCREEN");
            program.AppendCommentToProgramLine(0x8227, "Space reserved to save HL in routine TEST_SCREEN");
            program.AppendCommentToProgramLine(0x8228, "Space reserved to save SP in routine TEST_SCREEN");
            program.AppendCommentToProgramLine(0x8229, "Space reserved to save SP in routine TEST_SCREEN");
            program.InsertCommentAboveProgramLine(0x8085, "Here HL points to an entry in the tests parameters table");
            program.InsertCommentAboveProgramLine(0x8088, "Test params structure 0 - 1 : Pointer to an executable machine code function : the test launcher. 00H|00H marks the end of the parameters table.");
            program.InsertCommentAboveProgramLine(0x8088, "Test params structure 2 -> FFH : starting with the third byte, the parameter table entry contains a string describing the test");
            program.AppendCommentToProgramLine(0x8091, "Display tested opcode name");
            program.AppendCommentToProgramLine(0x8094, "TAB");
            program.AppendCommentToProgramLine(0x8097, "BRIGHT ...");
            program.AppendCommentToProgramLine(0x809A, "... 0");
            program.AppendCommentToProgramLine(0x809C, ":");
            program.AppendCommentToProgramLine(0x809F, "space");
            program.InsertCommentAboveProgramLine(0x80AF, "=> jump to test launcher, start address found at the beginning the current parameter table entry");
            program.RenameSymbolInProgram("L892D", "FLAGS_TEST_COMMON_EXEC");
            program.RenameSymbolInProgram("L9423", "MEMPTR_TEST_COMMON_EXEC");
            program.RenameSymbolInProgram("L89B9", "FLAGS_TEST_REPEAT_EXEC");
            program.RenameSymbolInProgram("L8A0B", "FLAGS_TEST_DDCB_EXEC");
            program.RenameSymbolInProgram("L8A6D", "FLAGS_TEST_FDCB_EXEC");
            program.RenameSymbolInProgram("L8B03", "FLAGS_TEST_CB_EXEC");
            program.CommentStringChars(0x8208, decoder.DecodeChar, Program.StringTerminationType.SpecialChar, 0, 0xFF);
            program.CommentStringChars(0x820F, decoder.DecodeChar, Program.StringTerminationType.SpecialChar, 0, 0xFF);
            program.AppendCommentToProgramLine(0x8083, "Set white border around the screen");
            program.AppendCommentToProgramLine(0x808C, "Here : HL points to the address of the test laucher routine, DE points to the string describing the test");
            program.AppendCommentToProgramLine(0x808F, "If HL = 00 : end of the tests table, else :");
            program.AppendCommentToProgramLine(0x80A2, "After the end of the string, save the address of the next entry in tests table for next iteration");
            program.InsertCommentAboveProgramLine(0x8208, "--- Passed test string ---");
            program.InsertCommentAboveProgramLine(0x820F, "--- Failed test string ---");
            program.InsertCommentAboveProgramLine(0x892D, "Generic execution environment for flags test");
            program.RenameSymbolInProgram("L9520", "ADD_FLAGS_TO_CHECKSUM");
            program.AppendCommentToProgramLine(0x954A, "Flags Checksum value");
            program.AppendCommentToProgramLine(0x892F, "Replaces instruction CALL START below with CALL (test EXEC address)");
            program.InsertCommentAboveProgramLine(0x894E, "==> call to one of the FLAGS_TEST_nn_EXEC routine");
            program.AppendCommentToProgramLine(0x895C, "Display Flags checksum value");
            program.AppendCommentToProgramLine(0x8964, "Compare Flags checksum with expected value");
            program.AppendCommentToProgramLine(0x8966, "==> return to TEST_SCREEN_TEST_FAILED");
            program.AppendCommentToProgramLine(0x8968, "==> return to TEST_SCREEN_TEST_PASSED");
            program.RenameSymbolInProgram("L8949", "FLAGS_TEST_CMN_EXEC_AF_VAL");
            program.AppendCommentToProgramLine(0x89BA, "Replaces instruction LDI below with one of the repeated instructions from the test table");
            program.InsertCommentAboveProgramLine(0x89D1, "==> executes one of the repeated instructions from the test table");
            program.RenameSymbolInProgram("L89C3", "FLAGS_TEST_REPEAT_EXEC_EXT_LOOP");
            program.RenameSymbolInProgram("L89CD", "FLAGS_TEST_REPEAT_EXEC_INN_LOOP");
            program.AppendCommentToProgramLine(0x89E1, "Display Flags checksum value");
            program.AppendCommentToProgramLine(0x89E9, "Compare Flags checksum with expected value");
            program.AppendCommentToProgramLine(0x89EB, "==> return to TEST_SCREEN_TEST_FAILED");
            program.AppendCommentToProgramLine(0x89ED, "==> return to TEST_SCREEN_TEST_PASSED");
            program.RenameSymbolInProgram("L8A1C", "FLAGS_TEST_DDCB_EXEC_LOOP");
            program.AppendCommentToProgramLine(0x8A1F, "<= third byte of opcode replaced with all values between 00 and FF by the line above");
            program.AppendCommentToProgramLine(0x8A45, "Display Flags checksum value");
            program.AppendCommentToProgramLine(0x8A4D, "Compare Flags checksum with expected value");
            program.AppendCommentToProgramLine(0x8A4F, "==> return to TEST_SCREEN_TEST_FAILED");
            program.AppendCommentToProgramLine(0x8A51, "==> return to TEST_SCREEN_TEST_PASSED");
            program.RenameSymbolInProgram("L8A81", "FLAGS_TEST_FDCB_EXEC_LOOP");
            program.AppendCommentToProgramLine(0x8A84, "<= third byte of opcode replaced with all values between 00 and FF by the line above");
            program.AppendCommentToProgramLine(0x8AAA, "Display Flags checksum value");
            program.AppendCommentToProgramLine(0x8AB2, "Compare Flags checksum with expected value");
            program.AppendCommentToProgramLine(0x8AB4, "==> return to TEST_SCREEN_TEST_FAILED");
            program.AppendCommentToProgramLine(0x8AB6, "==> return to TEST_SCREEN_TEST_PASSED");
            program.RenameSymbolInProgram("L8B14", "FLAGS_TEST_CB_EXEC_LOOP");
            program.RenameSymbolInProgram("L8B2A", "FLAGS_TEST_CB_EXEC_CASE1");
            program.RenameSymbolInProgram("L8B2C", "FLAGS_TEST_CB_EXEC_CASE2");
            program.RenameSymbolInProgram("L8B3A", "FLAGS_TEST_CB_EXEC_CASE3");
            program.AppendCommentToProgramLine(0x8B24, "<= third byte of opcode replaced with all values between 00 and FF by the line above at 8B17");
            program.AppendCommentToProgramLine(0x8B2A, "<= third byte of opcode replaced with all values between 00 and FF by the line above at 8B14");
            program.AppendCommentToProgramLine(0x8B51, "Display Flags checksum value");
            program.AppendCommentToProgramLine(0x8B59, "Compare Flags checksum with expected value");
            program.AppendCommentToProgramLine(0x8B5B, "==> return to TEST_SCREEN_TEST_FAILED");
            program.AppendCommentToProgramLine(0x8B5D, "==> return to TEST_SCREEN_TEST_PASSED");
            program.RenameSymbolInProgram("L942E", "MEMPTR_CMN_EXEC_START");
            program.AppendCommentToProgramLine(0x94CF, "==> loop back to MEMPTR_CMN_EXEC_LOOP");
            program.AppendCommentToProgramLine(0x94CE, "==> jump to MEMPTR_CMN_EXEC_CHECKSUM");
            program.PrefixLabelToProgramLine(0x94D1, "MEMPTR_CMN_EXEC_CHECKSUM", true);
            program.RenameSymbolInProgram("L94E1", "MEMPTR_CMN_EXEC_RET");
            program.AppendCommentToProgramLine(0x9429, "Compare Flags checksum with expected value");
            program.AppendCommentToProgramLine(0x942B, "==> return to TEST_SCREEN_TEST_FAILED");
            program.AppendCommentToProgramLine(0x942D, "==> return to TEST_SCREEN_TEST_PASSED");
            program.InsertCommentAboveProgramLine(0x9445, "--- NOPs below will be replaced by MEMPTR_TEST_nn_EXEC (instruction LDIR at address 9435 above) ---");
            program.InsertCommentAboveProgramLine(0x9459, "--- End of replaced code ---");
            program.AppendCommentToProgramLine(0x94DB, "Display Flags checksum value");
            program.RenameSymbolInProgram("L94E2", "MEMPTR_CHECKSUM");
            program.RenameSymbolInProgram("L94EE", "MEMPTR_CHECKSUM_LOOP1");
            program.RenameSymbolInProgram("L94F0", "MEMPTR_CHECKSUM_LOOP2");
            program.RenameSymbolInProgram("L94FB", "MEMPTR_CHECKSUM_CASE1");
            program.RenameSymbolInProgram("L94FE", "MEMPTR_CHECKSUM_CASE2");
            program.RenameSymbolInProgram("L9500", "MEMPTR_CHECKSUM_LOOP3");
            program.RenameSymbolInProgram("L950B", "MEMPTR_CHECKSUM_CASE3");
            program.RenameSymbolInProgram("L950C", "MEMPTR_CHECKSUM_CASE4");
            program.RenameSymbolInProgram("L9515", "MEMPTR_CHECKSUM_CASE5");
            program.RenameSymbolInProgram("L9517", "RESET_FLAGS_CHECKSUM");
            program.AppendCommentToProgramLine(0x8B5E, "Used to save and restore accumulator in FLAGS_TEST_CB_EXEC");
            program.AppendCommentToProgramLine(0x822A, "Used to restore accumulator in MEMPTR_TEST_COMMON_EXEC");
            program.AppendCommentToProgramLine(0x954B, "Not used ?");
            program.AppendCommentToProgramLine(0x954C, "Not used ?");
            program.PrefixLabelToProgramLine(0x954A, "VAR_FLAGS_CHECKSUM", true);
            program.ReplaceAddressWithSymbol(0xFFFF, "VAR_MEMPTR_CHECKSUM", true);
            program.PrefixLabelToProgramLine(0x8226, "VAR_SAVE_HL", true);
            program.PrefixLabelToProgramLine(0x8228, "VAR_SAVE_SP", true);
            program.PrefixLabelToProgramLine(0x822A, "VAR_SAVE_A", true);
            program.PrefixLabelToProgramLine(0x8114, "STRING_MENU_SCREEN", true);
            program.PrefixLabelToProgramLine(0x81AB, "STRING_END_OF_TESTS", true);
            program.PrefixLabelToProgramLine(0x81CD, "STRING_FLAGS_TESTS_SCREEN", true);
            program.PrefixLabelToProgramLine(0x81EA, "STRING_MEMPTR_TESTS_SCREEN", true);
            program.PrefixLabelToProgramLine(0x8208, "STRING_PASSED_TEST", true);
            program.PrefixLabelToProgramLine(0x820F, "STRING_FAILED_TEST", true);
            program.PrefixLabelToProgramLine(0x822B, "TABLE_FLAGS_TESTS", true);
            program.PrefixLabelToProgramLine(0x8407, "TABLE_MEMPTR_TESTS", true);
            program.PrefixLabelToProgramLine(0x8B5E, "VAR_SAVE_A2", true);
            program.PrefixLabelToProgramLine(0x9445, "MEMPTR_CMN_EXEC_LOOP", true);
            program.PrefixLabelToProgramLine(0x945C, "AREA_MEMPTR_TEST_INSERT", true);

            AddCommentsInTestsParametersTable(0x822B, spectrumMemory, decoder, program);
            AddCommentsInTestsParametersTable(0x8407, spectrumMemory, decoder, program);

            MemoryMap testMemoryMap = new MemoryMap(65536);

            program.Variables.Clear();
            Assembler.CompileProgram(program, 0x8000, testMemoryMap);
            for (int programAddress = program.BaseAddress; programAddress <= program.MaxAddress; programAddress++)
            {
                if (testMemoryMap.MemoryCells[programAddress] != spectrumMemory.MemoryCells[programAddress])
                {
                    throw new Exception("Error in decompiled program at address " + programAddress + " : source byte = " + spectrumMemory.MemoryCells[programAddress] + ", decompiled program line + " + ((ProgramLine)spectrumMemory.MemoryCellDescriptions[programAddress].Description).Text + " produced byte = " + testMemoryMap.MemoryCells[programAddress]);
                }
            }

            string htmlProgram = AsmHtmlFormatter.BeautifyAsmCode(fileName, program);
        }
Beispiel #24
0
        public static void DecompileZexall2()
        {
            string  fileName = "zexall2";
            TapFile tapFile  = TapFileReader.ReadTapFile(PlatformSpecific.GetStreamForProjectFile("TestTapes/" + fileName + ".tap"), fileName);

            ProgramHeader loaderHeader    = (ProgramHeader)tapFile.DataBlocks[0];
            int           programLength   = loaderHeader.ProgramLength;
            int           variablesLength = loaderHeader.FollowingDataLength - loaderHeader.ProgramLength;

            TapDataBlock loaderBlock        = tapFile.DataBlocks[1];
            MemoryStream binaryMemoryStream = new MemoryStream(loaderBlock.TapeData);

            /* Read flag */
            binaryMemoryStream.ReadByte();
            BasicProgram basicLoader = BasicReader.ReadMemoryFormat(fileName, binaryMemoryStream, programLength, variablesLength);

            ByteArrayHeader codeHeader = (ByteArrayHeader)tapFile.DataBlocks[2];
            int             dataLength = codeHeader.DataLength;

            TapDataBlock codeBlock = tapFile.DataBlocks[3];

            binaryMemoryStream = new MemoryStream(codeBlock.TapeData);
            /* Read flag */
            binaryMemoryStream.ReadByte();

            int baseAddress  = codeHeader.StartAddress;
            int startAddress = codeHeader.StartAddress;

            SpectrumMemoryMap spectrumMemory = new SpectrumMemoryMap();

            // Load machine code in memory to generate entry points BEFORE dissassembly
            int  b = -1;
            int  currentAddress       = baseAddress;
            long streamPositionBefore = binaryMemoryStream.Position;

            while ((b = binaryMemoryStream.ReadByte()) >= 0)
            {
                spectrumMemory.MemoryCells[currentAddress]            = (byte)b;
                spectrumMemory.MemoryCellDescriptions[currentAddress] = null; // Reset previous cell descriptions
                currentAddress++;
            }
            binaryMemoryStream.Position = streamPositionBefore;

            List <CallTarget> entryPoints = new List <CallTarget>();

            entryPoints.Add(new CallTarget(new CallSource(CallSourceType.ExternalEntryPoint, 0, null), startAddress));

            Program program = Disassembler.GenerateProgram(fileName, binaryMemoryStream, baseAddress, entryPoints.ToArray(), spectrumMemory);

            program.Lines.Insert(5, Assembler.ParseProgramLine("PRINT_A EQU 0010H"));
            program.Lines.Insert(5, Assembler.ParseProgramLine("CHAN_OPEN EQU 1601H"));
            program.Lines.Insert(5, Assembler.ParseProgramLine(""));
            program.RenumberLinesAfterLineNumber(0);

            program.PrefixLabelToProgramLine(0x8000, "MAIN");
            program.RenameSymbolInProgram("L8013", "START");
            program.PrefixLabelToProgramLine(0x9F69, "MSG1");
            program.RenameSymbolInProgram("L9F41", "BDOS");
            program.PrefixLabelToProgramLine(0x8043, "TESTS");
            program.RenameSymbolInProgram("L802B", "LOOP");
            program.RenameSymbolInProgram("L8038", "DONE");
            program.RenameSymbolInProgram("L9C4F", "STT");
            program.RenameSymbolInProgram("L8040", "STOP");
            program.PrefixLabelToProgramLine(0x9F8B, "MSG2");
            program.PrefixLabelToProgramLine(0x9ED7, "FLGMSK");
            program.PrefixLabelToProgramLine(0x9E49, "COUNTER");
            program.RenameSymbolInProgram("L9DB8", "INITMASK");
            program.PrefixLabelToProgramLine(0x9E71, "SHIFTER");
            program.PrefixLabelToProgramLine(0x9EB3, "IUT");
            program.PrefixLabelToProgramLine(0x8003, "MSBT");
            program.RenameSymbolInProgram("L9FF4", "INITCRC");
            program.RenameSymbolInProgram("L9C94", "TLP");
            program.RenameSymbolInProgram("L9CA8", "TLP1");
            program.RenameSymbolInProgram("L9CAB", "TLP2");
            program.RenameSymbolInProgram("L9E99", "TEST");
            program.RenameSymbolInProgram("L9DF8", "COUNT");
            program.RenameSymbolInProgram("L9E1C", "SHIFT");
            program.RenameSymbolInProgram("L9CE9", "TLP3");
            program.RenameSymbolInProgram("L9FB5", "CMPCRC");
            program.PrefixLabelToProgramLine(0x9F9A, "OKMSG");
            program.RenameSymbolInProgram("L9CE0", "TLPOK");
            program.PrefixLabelToProgramLine(0x9F9F, "ERMSG1");
            program.RenameSymbolInProgram("L9F0C", "PHEX8");
            program.PrefixLabelToProgramLine(0x9FA7, "ERMSG2");
            program.PrefixLabelToProgramLine(0x9FB2, "CRLF");
            program.PrefixLabelToProgramLine(0x9D5F, "CNBIT");
            program.PrefixLabelToProgramLine(0x9D83, "SHFBIT");
            program.PrefixLabelToProgramLine(0x9D60, "CNTBYT");
            program.PrefixLabelToProgramLine(0x9D84, "SHBYT");
            program.RenameSymbolInProgram("L9D13", "SETUP");
            program.RenameSymbolInProgram("L9D1C", "SUBYTE");
            program.RenameSymbolInProgram("L9D3D", "SUBSHF");
            program.RenameSymbolInProgram("L9D2C", "SUBCLP");
            program.RenameSymbolInProgram("L9D62", "NXTCBIT");
            program.RenameSymbolInProgram("L9D58", "SUBSTR");
            program.RenameSymbolInProgram("L9D49", "SBSHF1");
            program.RenameSymbolInProgram("L9D86", "NXTSBIT");
            program.RenameSymbolInProgram("L9D7B", "NCB1");
            program.RenameSymbolInProgram("L9D9F", "NSB1");
            program.RenameSymbolInProgram("L9DA7", "CLRMEM");
            program.RenameSymbolInProgram("L9DC7", "IMLP");
            program.RenameSymbolInProgram("L9DC8", "IMLP1");
            program.RenameSymbolInProgram("L9DCE", "IMLP2");
            program.RenameSymbolInProgram("L9DEB", "IMLP3");
            program.RenameSymbolInProgram("L9E04", "CNTLP");
            program.RenameSymbolInProgram("L9E13", "CNTEND");
            program.RenameSymbolInProgram("L9E17", "CNTLP1");
            program.RenameSymbolInProgram("L9E28", "SHFLP");
            program.RenameSymbolInProgram("L9E3E", "SHFLP2");
            program.RenameSymbolInProgram("L9E40", "SHFLPE");
            program.RenameSymbolInProgram("L9E44", "SHFLP1");
            program.PrefixLabelToProgramLine(0x9F00, "SPSAV");
            program.PrefixLabelToProgramLine(0x8011, "SPBT");
            program.PrefixLabelToProgramLine(0x9EFE, "SPAT");
            program.PrefixLabelToProgramLine(0x9EF0, "MSAT");
            program.PrefixLabelToProgramLine(0x9EFC, "FLGSAT");
            program.PrefixLabelToProgramLine(0xA008, "CRCVAL");
            program.RenameSymbolInProgram("L9EE2", "TCRC");
            program.RenameSymbolInProgram("L9FCC", "UPDCRC");
            program.PrefixLabelToProgramLine(0x9F04, "HEXSTR");
            program.RenameSymbolInProgram("L9F11", "PH8LP");
            program.RenameSymbolInProgram("L9F1E", "PHEX2");
            program.RenameSymbolInProgram("L9F27", "PHEX1");
            program.RenameSymbolInProgram("L9F34", "PH11");
            program.RenameSymbolInProgram("L9F54", "PRCHAR");
            program.RenameSymbolInProgram("L9F5C", "PRSTRING");
            program.RenameSymbolInProgram("L9F4F", "BDOSDONE");
            program.RenameSymbolInProgram("L9FBD", "CCLP");
            program.RenameSymbolInProgram("L9FC8", "CCE");
            program.PrefixLabelToProgramLine(0xA00C, "CRCTAB");
            program.RenameSymbolInProgram("L9FE5", "CRCLP");
            program.RenameSymbolInProgram("L9FFE", "ICRCLP");

            string[] testNames = new string[] { "SCFOP", "CCFOP", "SCFCCF", "CCFSCF", "BITA", "BITHL", "BITX", "BITZ80", "DAAOP", "CPLOP", "ADC16", "ADD16", "ADD16X",
                                                "ADD16Y", "ALU8I", "ALU8R", "ALU8RX", "ALU8X", "CPD1", "CPI1", "INCA", "INCB", "INCBC", "INCC", "INCD", "INCDE", "INCE", "INCH", "INCHL", "INCIX", "INCIY",
                                                "INCL", "INCM", "INCSP", "INCX", "INCXH", "INCXL", "INCYH", "INCYL", "LD161", "LD162", "LD163", "LD164", "LD165", "LD166", "LD167", "LD168", "LD16IM", "LD16IX",
                                                "LD8BD", "LD8IM", "LD8IMX", "LD8IX1", "LD8IX2", "LD8IX3", "LD8IXY", "LD8RR", "LD8RRX", "LDA", "LDD1", "LDD2", "LDI1", "LDI2", "NEGOP", "RLDOP", "ROT8080",
                                                "ROTXY", "ROTZ80", "SRZ80", "SRZX", "ST8IX1", "ST8IX2", "ST8IX3", "STABD" };

            int testTableAddress = 0x8043;

            foreach (string testName in testNames)
            {
                int testAddress = spectrumMemory.MemoryCells[testTableAddress++] + 256 * spectrumMemory.MemoryCells[testTableAddress++];
                program.PrefixLabelToProgramLine(testAddress, testName);
            }

            MemoryMap testMemoryMap = new MemoryMap(65536);

            program.Variables.Clear();
            Assembler.CompileProgram(program, 0x8000, testMemoryMap);
            for (int programAddress = program.BaseAddress; programAddress <= program.MaxAddress; programAddress++)
            {
                if (testMemoryMap.MemoryCells[programAddress] != spectrumMemory.MemoryCells[programAddress])
                {
                    throw new Exception("Error in decompiled program at address " + programAddress + " : source byte = " + spectrumMemory.MemoryCells[programAddress] + ", decompiled program line + " + ((ProgramLine)spectrumMemory.MemoryCellDescriptions[programAddress].Description).Text + " produced byte = " + testMemoryMap.MemoryCells[programAddress]);
                }
            }

            string htmlProgram = AsmHtmlFormatter.BeautifyAsmCode(fileName, program);
        }
Beispiel #25
0
        public List <ProgramHeaderMovement> GetProgramHeaderMovementsByProgramHeader(ProgramHeader programHeader)
        {
            var programHeaderMovementList = _ascendDb.ProgramHeaderMovements.Where(hm => hm.ProgramHeader.Id == programHeader.Id).ToList();

            return(programHeaderMovementList);
        }
        public void EmptyStream()
        {
            var emptyReader = new BinaryReader(new MemoryStream());

            Assert.IsFalse(ProgramHeader.TryRead(emptyReader, out ProgramHeader h));
        }