Пример #1
0
        public void ShouldGenerateImmediateInstruction(CpuInstructions opcodeEnum, byte finalOpcode, int value)
        {
            CpuInstructionStatement instruction = new CpuInstructionStatement();

            instruction.AddressingMode = CpuAddressingMode.Immediate;
            instruction.Opcode         = opcodeEnum;
            if (value > byte.MaxValue)
            {
                instruction.Arguments.Add(new NumberInstructionArgument(value, ArgumentSize.Word));
            }
            else
            {
                instruction.Arguments.Add(new NumberInstructionArgument(value, ArgumentSize.Byte));
            }

            List <CpuInstructionStatement> instructions = new List <CpuInstructionStatement>();

            instructions.Add(instruction);

            MemoryStream     memoryStream = new MemoryStream(8);
            CpuCodeGenerator generator    = new CpuCodeGenerator(memoryStream);

            generator.Instructions = instructions;
            generator.Generate();

            Assert.Equal(finalOpcode, memoryStream.GetBuffer()[0]);
            Assert.Equal((byte)(value & 0xFF), memoryStream.GetBuffer()[1]);
            Assert.Equal((byte)(value >> 8), memoryStream.GetBuffer()[2]);
        }
Пример #2
0
        public void ShouldParseImpliedInstructions(string opcodeText, CpuInstructions opcodeEnum)
        {
            string input = String.Format(ProcedureTemplate, opcodeText);

            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());

            driver.Parse();

            CpuInstructionStatement instructionStatement = driver.GlobalScope.Children[0].Statements[0] as CpuInstructionStatement;

            Assert.Equal(opcodeEnum, instructionStatement.Opcode);
            Assert.Equal(CpuAddressingMode.Implied, instructionStatement.AddressingMode);
        }
Пример #3
0
        public void ShouldParseAbsoluteInstructions(string instruction, CpuInstructions opcodeEnum, int value)
        {
            string input = String.Format(ProcedureTemplate, instruction);

            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());
            driver.Parse();

            CpuInstructionStatement instructionStatement = driver.GlobalScope.Children[0].Statements[0] as CpuInstructionStatement;
            Assert.Equal(opcodeEnum, instructionStatement.Opcode);
            Assert.Equal(CpuAddressingMode.Absolute, instructionStatement.AddressingMode);

            var numberArgument = instructionStatement.Arguments[0] as NumberInstructionArgument;
            Assert.Equal(value, numberArgument.Number);
        }
Пример #4
0
        public void ShouldParseAbsoluteInstructions(string instruction, CpuInstructions opcodeEnum, int value)
        {
            string input = String.Format(ProcedureTemplate, instruction);

            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());

            driver.Parse();

            CpuInstructionStatement instructionStatement = driver.GlobalScope.Children[0].Statements[0] as CpuInstructionStatement;

            Assert.Equal(opcodeEnum, instructionStatement.Opcode);
            Assert.Equal(CpuAddressingMode.Absolute, instructionStatement.AddressingMode);

            var numberArgument = instructionStatement.Arguments[0] as NumberInstructionArgument;

            Assert.Equal(value, numberArgument.Number);
        }
Пример #5
0
        public void ShouldGenerateImpliedInstruction(CpuInstructions opcodeEnum, byte finalOpcode)
        {
            CpuInstructionStatement instruction = new CpuInstructionStatement();

            instruction.AddressingMode = CpuAddressingMode.Implied;
            instruction.Opcode         = opcodeEnum;

            List <CpuInstructionStatement> instructions = new List <CpuInstructionStatement>();

            instructions.Add(instruction);

            MemoryStream     memoryStream = new MemoryStream(8);
            CpuCodeGenerator generator    = new CpuCodeGenerator(memoryStream);

            generator.Instructions = instructions;
            generator.Generate();

            Assert.Equal(finalOpcode, memoryStream.GetBuffer()[0]);
        }
Пример #6
0
        public void ShouldGenerateAbsoluteInstruction(CpuInstructions opcodeEnum, byte finalOpcode, int value)
        {
            CpuInstructionStatement instruction = new CpuInstructionStatement();
            instruction.AddressingMode = CpuAddressingMode.Absolute;
            instruction.Opcode = opcodeEnum;
            instruction.Arguments.Add(new NumberInstructionArgument(value, ArgumentSize.Word));

            List<CpuInstructionStatement> instructions = new List<CpuInstructionStatement>();
            instructions.Add(instruction);

            MemoryStream memoryStream = new MemoryStream(8);
            CpuCodeGenerator generator = new CpuCodeGenerator(memoryStream);
            generator.Instructions = instructions;
            generator.Generate();

            Assert.Equal(finalOpcode, memoryStream.GetBuffer()[0]);
            Assert.Equal((byte)(value & 0xFF), memoryStream.GetBuffer()[1]);
            Assert.Equal((byte)(value >> 8), memoryStream.GetBuffer()[2]);
        }
Пример #7
0
        public void ShouldParseImpliedInstructions(string opcodeText, CpuInstructions opcodeEnum)
        {
            string input = String.Format(ProcedureTemplate, opcodeText);

            ZealCpuDriver driver = new ZealCpuDriver(input.ToMemoryStream());
            driver.Parse();

            CpuInstructionStatement instructionStatement = driver.GlobalScope.Children[0].Statements[0] as CpuInstructionStatement;
            Assert.Equal(opcodeEnum, instructionStatement.Opcode);
            Assert.Equal(CpuAddressingMode.Implied, instructionStatement.AddressingMode);
        }
Пример #8
0
        public void ShouldGenerateImpliedInstruction(CpuInstructions opcodeEnum, byte finalOpcode)
        {
            CpuInstructionStatement instruction = new CpuInstructionStatement();
            instruction.AddressingMode = CpuAddressingMode.Implied;
            instruction.Opcode = opcodeEnum;

            List<CpuInstructionStatement> instructions = new List<CpuInstructionStatement>();
            instructions.Add(instruction);

            MemoryStream memoryStream = new MemoryStream(8);
            CpuCodeGenerator generator = new CpuCodeGenerator(memoryStream);
            generator.Instructions = instructions;
            generator.Generate();

            Assert.Equal(finalOpcode, memoryStream.GetBuffer()[0]);
        }