示例#1
0
        public void JumpTrackingTests_IndirectAddress_NotJump()
        {
            var sourceCode   = @"    nop
lblA4  nop
       jp   nz,lblA5
       or   (hl)
       nop
lblA5  jp   lblA5
       nop
       nop";
            var expectedCode = @"    nop
; Runnable Code Begin
lblA4  nop
       jp   nz,lblA5
       or   (hl)
       nop
lblA5  jp   lblA5
; Runnable Code End
       nop
       nop";

            var parser      = new Z80LineParser();
            var parsedLines = sourceCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));
            var jumpTracker = new JumpTracker(new List <string>()
            {
                "lblA4"
            });
            var actualCommands   = jumpTracker.FindJumps(parsedLines);
            var expectedCommands = expectedCode.Split(Environment.NewLine).ToList();

            CollectionAssert.AreEqual(expectedCommands, actualCommands.Select(c => c.SourceText), "OR command should not be marked with a comment about indirect addrsssing because it is not a jump command.");
        }
示例#2
0
        public void JumpTrackingTests_Comment_AvoidInfinitLoop()
        {
            var sourceCode   = @"    nop
lblA4  nop
       jp   nz,lblA5
       jp   (hl)
       nop
lblA5  jp   lblA5
       nop
       nop";
            var expectedCode = @"; These labels were never hit:
;    labelThatWillNeverBeHit";

            var parser      = new Z80LineParser();
            var parsedLines = sourceCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));
            var jumpTracker = new JumpTracker(new List <string>()
            {
                "lblA4", "labelThatWillNeverBeHit"
            });
            var actualCommands = jumpTracker.FindJumps(parsedLines);

            CollectionAssert.AreEqual(new List <string>()
            {
                "labelThatWillNeverBeHit"
            }, jumpTracker.BranchableLabels);
            CollectionAssert.AreEqual(expectedCode.Split(Environment.NewLine).ToList(), actualCommands.Take(2).Select(c => c.SourceText).ToList());
        }
示例#3
0
        public void JumpTrackingTests_Comment_IndirectAddressing()
        {
            var sourceCode   = @"    nop
lblA4  nop
       jp   nz,lblA5
       jp   pe,(hl)
       nop
lblA5  jp   lblA5
       nop
       nop";
            var expectedCode = @"    nop
; Runnable Code Begin
lblA4  nop
       jp   nz,lblA5
; Indirect Address Jump
       jp   pe,(hl)
       nop
lblA5  jp   lblA5
; Runnable Code End
       nop
       nop";

            var parser      = new Z80LineParser();
            var parsedLines = sourceCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));
            var jumpTracker = new JumpTracker(new List <string>()
            {
                "lblA4"
            });
            var actualCommands   = jumpTracker.FindJumps(parsedLines);
            var expectedCommands = expectedCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));

            CollectionAssert.AreEqual(expectedCommands.Select(c => c.SourceText), actualCommands.Select(c => c.SourceText));
        }
示例#4
0
        public void JumpTrackingTests_Comment_results2()
        {
            var sourceCode   = @"    nop
lblA4  nop
       jp   nz,lblA5
       nop
lblA5  jp   lblA5
       nop
lblB2  nop
       nop
lblB1  nop
       jr   nc,lblB2
       nop
lblB3  nop
       jr   lblB2
       nop
lblC1  nop
       nop
lblC2  nop
       jp   lblC1
lblC3  nop";
            var expectedCode = @"    nop
; Runnable Code Begin
lblA4  nop
       jp   nz,lblA5
       nop
lblA5  jp   lblA5
; Runnable Code End
       nop
lblB2  nop
       nop
lblB1  nop
       jr   nc,lblB2
       nop
lblB3  nop
       jr   lblB2
       nop
; Runnable Code Begin
lblC1  nop
       nop
lblC2  nop
       jp   lblC1
; Runnable Code End
lblC3  nop";

            var parser      = new Z80LineParser();
            var parsedLines = sourceCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));
            var jumpTracker = new JumpTracker(new List <string>()
            {
                "lblA4", "lblC1"
            });
            var actualCommands   = jumpTracker.FindJumps(parsedLines);
            var expectedCommands = expectedCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));

            CollectionAssert.AreEqual(expectedCommands.Select(c => c.SourceText), actualCommands.Select(c => c.SourceText));
        }
示例#5
0
        public void JumpTrackingTests_AvoidEndingAndImmediatelyBeginningRunnableCode()
        {
            var sourceCode   = @"    nop
lblA4  nop
       jp   nz,lblA6
       or   (hl)
       nop
lblA5  jp   lblA5

lblA6  nop
       jp   nz,lblA5
       nop
       jp   lblA5
       nop";
            var expectedCode = @"    nop
; Runnable Code Begin
lblA4  nop
       jp   nz,lblA6
       or   (hl)
       nop
lblA5  jp   lblA5

lblA6  nop
       jp   nz,lblA5
       nop
       jp   lblA5
; Runnable Code End
       nop";

            var parser      = new Z80LineParser();
            var parsedLines = sourceCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));
            var jumpTracker = new JumpTracker(new List <string>()
            {
                "lblA4"
            });
            var actualCommands   = jumpTracker.FindJumps(parsedLines);
            var expectedCommands = expectedCode.Split(Environment.NewLine).ToList();

            CollectionAssert.AreEqual(expectedCommands, actualCommands.Select(c => c.SourceText), "There shouldn't be 'end' and 'begin' comments in between lblA5 and lblA6.");
        }
示例#6
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                throw new Exception("Required arguments are a source file of z80 code and a destination file of TMS9900 code.");
            }
            var z80AssemblyInputFile  = args[0];
            var z80AssemblyOutputFile = args[1];
            var entryLabels           = args[2].Split(';').ToList();

            using (var reader = new StreamReader(z80AssemblyInputFile))
                using (var writer = new StreamWriter(z80AssemblyOutputFile))
                {
                    var parsedLines    = GetZ80sourceCode(reader);
                    var jumpTracker    = new JumpTracker(entryLabels);
                    var actualCommands = jumpTracker.FindJumps(parsedLines);
                    foreach (var command in actualCommands)
                    {
                        writer.WriteLine(command.SourceText);
                    }
                }
        }
示例#7
0
        public void JumpTrackingTests_BranchedLabels()
        {
            var sourceCode     = @"    nop
lblA4  nop
       jp   nz,lblA5
       nop
lblA5  jp   lblA5
       nop
lblB2  nop
       nop
lblB1  nop
       jr   nc,lblB2
       nop
lblB3  nop
       jr   lblB2
       nop
lblC1  nop
       nop
lblC2  nop
       jp   lblC1
lblC3  nop";
            var expectedLabels = new List <string>()
            {
                "lblB1", "lblB2", "lblB3"
            };

            var parser      = new Z80LineParser();
            var parsedLines = sourceCode.Split(Environment.NewLine).Select(ln => parser.ParseLine(ln));
            var jumpTracker = new JumpTracker(new List <string>()
            {
                "lblB1"
            });

            jumpTracker.FindJumps(parsedLines);

            CollectionAssert.AreEquivalent(expectedLabels, jumpTracker.BranchedLabels);
            Assert.IsFalse(jumpTracker.BranchableLabels.Any());
        }