示例#1
0
        public void LoadAwithValueWhenOperationIsLDAn()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0x3E },
                { 0x0081, 0x02 },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            // Load 2 into register A, which starts out having a value of 3...
            var cpu = new Z80()
            {
                A = 0x03, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);
            cpu.Step();

            Assert.Equal(0x02, cpu.A);

            // No affect on Condition Flags
            FlagsUnchanged(cpu);
        }
示例#2
0
        public void Initialize()
        {
            Ports  = new TVCPorts();
            Memory = new TVCMemory(this);
            Memory.LoadSystemMemory(@"..\..\roms\rom.bin");
            Memory.LoadExtMemory(@"..\..\roms\ext.bin");
            Memory.LoadCartMemory(@"d:\Stuff\tvc\szanko.rom");
            //Memory.LoadCartMemory(@"c:\Temp\tvc\mralex.rom");
            //Memory.LoadCartMemory(@"c:\Temp\tvc\invaders.rom");
            //Memory.LoadCartMemory(@"c:\Temp\tvc\vili.rom");

            Video     = new TVCVideo(this);
            Keyboard  = new TVCKeyboard(this);
            Interrupt = new TVCInterrupt(this);

            CPU = new Z80(Memory, Ports, null, true);

            Cards = new ITVCCard[ExpansionCardCount];

            InsertCard(0, new HBFCard());

            Ports.AddPortReader(0x5a, PortRead5AH);

            Reset();
        }
示例#3
0
        private void HandleStrayOpCodes2()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xDD },
                { 0x0081, 0xDD },
                { 0x0082, 0xDD },
                { 0x0083, 0xFD },
                { 0x0084, 0xDD }, // LD IX &1000
                { 0x0085, 0x21 },
                { 0x0086, 0x00 },
                { 0x0087, 0x10 },
                { 0x0088, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x00, IX = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            while (cpu.PC < 0x0088)
            {
                cpu.Step();
            }

            Assert.Equal(0x1000, cpu.IX);
        }
示例#4
0
        private void JumpToIY()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xFD }, // JR IY
                { 0x0081, 0xE9 },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
                { 0x0085, 0x00 },
                { 0x0086, 0x00 }, // <- jump here
                { 0x0087, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x00, IY = 0x0086, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x086, cpu.PC);
            FlagsUnchanged(cpu);
        }
示例#5
0
文件: PUSH.cs 项目: chazjn/Z80CPU
 private void Push(Z80 z80, Register16 register)
 {
     z80.SP.Value++;
     z80.Memory.Set(z80.SP.Value, register.High.Value);
     z80.SP.Value++;
     z80.Memory.Set(z80.SP.Value, register.Low.Value);
 }
示例#6
0
        private void LoadProgramCounterWithAddressForJPNN()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xC3 }, // JP 0191h
                { 0x0081, 0x91 },
                { 0x0082, 0x01 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },

                { 0x0190, 0x00 },
                { 0x0191, 0x00 }, // <- jump here
                { 0x0192, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x0191, cpu.PC);
            FlagsUnchanged(cpu);
        }
示例#7
0
        private void NotJumpBackFourForDJNZ_WhenZero()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x007C, 0x00 }, // <- jump here
                { 0x007D, 0x00 },
                { 0x007E, 0x00 },
                { 0x007F, 0x00 },
                { 0x0080, 0x10 }, // DJNZ $-4
                { 0x0081, 0xFA }, // Assembler with compensate for PC incrementing twice
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
                { 0x0085, 0x00 },
                { 0x0086, 0x00 },
                { 0x0087, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                B = 0x01, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x082, cpu.PC);
        }
示例#8
0
        private void SwapAFandAFPrime()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0x08 }, // EX AF,AF'
                { 0x0081, 0x00 },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x11, F = (Flags)0x22, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x0000, cpu.AF);
            Assert.Equal(0x1122, cpu.AF1);
            FlagsUnchanged(cpu);
        }
示例#9
0
        private void SwapRegistersWithEXX()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xD9 }, // EXX
                { 0x0081, 0x00 },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                B = 0x11, C = 0x22, D = 0x12, E = 0x23, H = 0x14, L = 0x24, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x0000, cpu.BC);
            Assert.Equal(0x1122, cpu.BC1);
            Assert.Equal(0x0000, cpu.DE);
            Assert.Equal(0x1223, cpu.DE1);
            Assert.Equal(0x0000, cpu.HL);
            Assert.Equal(0x1424, cpu.HL1);

            FlagsUnchanged(cpu);
        }
示例#10
0
        void UpdateListing(Z80 z80)
        {
            if (z80 == null)
            {
                return;
            }
            Disassembler.DisassembleROM = true;
            if (Disassembler.SourceLines[z80.PC].Text == null)
            {
                if (addresses == null)
                {
                    addresses = new List <int>();
                }
                addresses.Add(z80.PC);
                Disassembler.Disassemble(z80.Memory);
                Disassembler.Disassemble(0, addresses, 0, 65535, z80.Memory, true, true, true);
                //MonitorWindow.ReadOnly = false;
                scintillaZ80Monitor1.ForceText = Disassembler.Listing.ToString();
                //MonitorWindow.ReadOnly = true;
            }
            else if (scintillaZ80Monitor1.Text.Length == 0)
            {
                scintillaZ80Monitor1.ForceText = Disassembler.Listing.ToString();
            }


            int line = scintillaZ80Monitor1.LineFromPosition(Disassembler.SourceLines[z80.PC].Start);

            scintillaZ80Monitor1.GotoPosition(Disassembler.SourceLines[z80.PC].Start);
            scintillaZ80Monitor1.SelectionStart = Disassembler.SourceLines[z80.PC].Start;
            scintillaZ80Monitor1.SelectionEnd   = Disassembler.SourceLines[z80.PC].Start + Disassembler.SourceLines[z80.PC].Length;
            Globals.DoEvents();
        }
示例#11
0
        private void SwapDEandHL()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xEB }, // EX DE,HL
                { 0x0081, 0x00 },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                D = 0x11, E = 0x22, H = 0x33, L = 0x44, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x3344, cpu.DE);
            Assert.Equal(0x1122, cpu.HL);
            FlagsUnchanged(cpu);
        }
示例#12
0
        public void Initialize()
        {
            Ports  = new TVCPorts();
            Memory = new TVCMemory(this);

            CPU = new Z80(Memory, (IZ80Port)Ports, null, true);

            Video     = new TVCVideo(this);
            Keyboard  = new TVCKeyboard(this);
            Interrupt = new TVCInterrupt(this);
            Sound     = new TVCSound(this);

            Cards = new ITVCCard[TVComputerConstants.ExpansionCardCount];

            Ports.AddPortReader(0x5a, PortRead5AH);

            // cartridge init
            Cartridge = new TVCCartridge();
            Cartridge.Initialize(this);
            //((TVCCartridge)Cartridge).ReadCartridgeFile(@"d:\Projects\Retro\TVCDOC\Multicart4\test.bin");



            Reset();
        }
示例#13
0
        private void SetInterruptMode2()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xED }, // IM 2
                { 0x0081, 0x5E },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.True(cpu.InterruptMode == InterruptMode.Mode2);
        }
示例#14
0
        private void EnableInterruptBySettingIFF()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xFB }, // EI
                { 0x0081, 0x00 },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.True(cpu.IFF1);
            Assert.True(cpu.IFF2);
        }
示例#15
0
        private void OpenFile()
        {
            if (openFileDia.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var fileName = openFileDia.FileName;

            if (File.Exists(fileName) == false)
            {
                return;
            }

            var fileBytes = File.ReadAllBytes(fileName);

            if (fileBytes.Length > Memory.MEMORY_SIZE)
            {
                MessageBox.Show("The program file is too big.\nMax file size = " + Memory.MEMORY_SIZE + " bytes",
                                "Large File",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Memory mem = new Memory(fileBytes.Length);

            mem.LoadRom(fileBytes);

            _cpu = new Z80(mem);
            RefreshMemory();
            RefreshRegisters();
            RefreshFlags();
        }
示例#16
0
文件: IN.cs 项目: chazjn/Z80CPU
        public TStates SetRegister(Z80 z80, Register8 register)
        {
            var address = ByteHelper.CreateUShort(z80.B.Value, z80.C.Value);

            register.Value = z80.Ports.GetByte(address);
            return(TStates.Count(12));
        }
示例#17
0
        private void DecrementRegisterFlagsTest2()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0x15 },
                { 0x0081, 0x00 },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                D = 0x80, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);
            cpu.Step();

            Assert.Equal(0x7F, cpu.D);

            Assert.True((cpu.F & Z80.Flags.N) == Z80.Flags.N);
            Assert.False((cpu.F & Z80.Flags.Z) == Z80.Flags.Z);
            Assert.False((cpu.F & Z80.Flags.S) == Z80.Flags.S);
            Assert.True((cpu.F & Z80.Flags.H) == Z80.Flags.H);
            Assert.True((cpu.F & Z80.Flags.P) == Z80.Flags.P);
            Assert.False((cpu.F & Z80.Flags.C) == Z80.Flags.C);
            Assert.True((cpu.F & Z80.Flags.U) == Z80.Flags.U);
            Assert.True((cpu.F & Z80.Flags.X) == Z80.Flags.X);
        }
示例#18
0
        protected override void LoadRegisters(Z80 cpu)
        {
            cpu.RaiseRESET();

            cpu.IV = this.Peek(Offset_I);

            cpu.HL.Word = this.PeekWord(Offset_HL_);
            cpu.DE.Word = this.PeekWord(Offset_DE_);
            cpu.BC.Word = this.PeekWord(Offset_BC_);
            cpu.AF.Word = this.PeekWord(Offset_AF_);

            cpu.Exx();

            cpu.HL.Word = this.PeekWord(Offset_HL);
            cpu.DE.Word = this.PeekWord(Offset_DE);
            cpu.BC.Word = this.PeekWord(Offset_BC);

            cpu.IY.Word = this.PeekWord(Offset_IY);
            cpu.IX.Word = this.PeekWord(Offset_IX);

            cpu.IFF2    = (this.Peek(Offset_IFF2) >> 2) != 0;
            cpu.REFRESH = this.Peek(Offset_R);

            cpu.ExxAF();

            cpu.AF.Word = this.PeekWord(Offset_AF);
            cpu.SP.Word = this.PeekWord(Offset_SP);
            cpu.IM      = this.Peek(Offset_IM);
        }
示例#19
0
        private void DoNotJumpForwardFourForJRCPositiveSix_CarryNotSet()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0x38 }, // JR C $+6
                { 0x0081, 0x04 }, // Assembler with compensate for PC incrementing twice
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
                { 0x0085, 0x00 },
                { 0x0086, 0x00 },
                { 0x0087, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x082, cpu.PC);
            FlagsUnchanged(cpu);
        }
示例#20
0
        public MasterSystem()
        {
            Clock        = new SystemClock();
            Interconnect = new Interconnect();

            CPU = new Z80(Clock, Interconnect);
        }
示例#21
0
        private void JumpForwardFourForJRNZPositiveSix_NotZeroSet()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0x20 }, // JR NZ $+6
                { 0x0081, 0x04 }, // Assembler with compensate for PC incrementing twice
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
                { 0x0085, 0x00 },
                { 0x0086, 0x00 }, // <- jump here
                { 0x0087, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x00, PC = 0x0080
            };

            cpu.F = (Flags)0b00000000; // Reset Z flag
            cpu.ConnectToBus(fakeBus);

            cpu.Step();

            Assert.Equal(0x086, cpu.PC);
        }
示例#22
0
        public void LoadRfromA()
        {
            var fakeBus = A.Fake <IBus>();

            var program = new Dictionary <ushort, byte>
            {
                // Program Code
                { 0x0080, 0xED },
                { 0x0081, 0x4F },
                { 0x0082, 0x00 },
                { 0x0083, 0x00 },
                { 0x0084, 0x00 },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => program[addr]);

            var cpu = new Z80()
            {
                A = 0x17, R = 0x00, IFF2 = true, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);
            cpu.Step();

            Assert.Equal(0x17, cpu.A);
            Assert.Equal(0x17, cpu.R);

            // No affect on Condition Flags
            FlagsUnchanged(cpu);
        }
示例#23
0
        public void Initialize()
        {
            Ports  = new TVCPorts();
            Memory = new TVCMemory(this);
            Memory.LoadSystemMemory(@"..\..\roms\rom.bin");
            Memory.LoadExtMemory(@"..\..\roms\ext.bin");
            //Memory.LoadCartMemory(@"d:\Stuff\tvc\szanko.rom");
            //Memory.LoadCartMemory(@"c:\Temp\tvc\mralex.rom");
            //Memory.LoadCartMemory(@"c:\Temp\tvc\invaders.rom");
            //Memory.LoadCartMemory(@"c:\Temp\tvc\vili.rom");
            //Memory.LoadCartMemory(@"c:\Users\laszlo.arvai\Downloads\cfcart128.crt");

            Video     = new TVCVideo(this);
            Keyboard  = new TVCKeyboard(this);
            Interrupt = new TVCInterrupt(this);

            CPU = new Z80(Memory, Ports, null, true);

            Cards = new ITVCCard[TVComputerConstants.ExpansionCardCount];

            //InsertCard(0, new HBF.HBFCard());

            Ports.AddPortReader(0x5a, PortRead5AH);

            // cartridge init
            Cartridge = new TVCCartridge();
            Cartridge.Initialize(this);
            //Cartridge = new TVCMultiCart();
            //Cartridge.Initialize(this);

            Reset();
        }
示例#24
0
        private void DisassembleDDCBandFDCBOpcodesCorrectly()
        {
            var fakeBus = A.Fake <IBus>();
            var ram     = HexFileReader.Read("../../../HexFiles/TestDDCBandFDCB.hex");

            var expectedDisassembly = new Dictionary <ushort, string>
            {
                { 0x8000, "RL (IX+2)" },
                { 0x8004, "RL (IY-3)" },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);


            var cpu = new Z80()
            {
                A = 0x00, PC = 0x8000
            };

            cpu.ConnectToBus(fakeBus);
            var disassembledCode = cpu.Disassemble(0x8000, 0x8007);

            Assert.Equal(expectedDisassembly, disassembledCode);
        }
示例#25
0
        private void DisassembleMultiplicationHexFileCorrectly()
        {
            var fakeBus = A.Fake <IBus>();
            var ram     = HexFileReader.Read("../../../HexFiles/Multiplication.hex");

            var expectedDisassembly = new Dictionary <ushort, string>
            {
                { 0x8000, "LD BC,&0015" },
                { 0x8003, "LD B,&08" },
                { 0x8005, "LD DE,&002A" },
                { 0x8008, "LD D,&00" },
                { 0x800A, "LD HL,&0000" },
                { 0x800D, "SRL C" },
                { 0x800F, "JR C,$+3" },
                { 0x8011, "ADD HL,DE" },
                { 0x8012, "SLA E" },
                { 0x8014, "RL D" },
                { 0x8016, "DEC B" },
                { 0x8017, "JP NZ,&800D" },
            };

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);


            var cpu = new Z80()
            {
                A = 0x00, PC = 0x8000
            };

            cpu.ConnectToBus(fakeBus);
            var disassembledCode = cpu.Disassemble(0x8000, 0x8017);

            Assert.Equal(expectedDisassembly, disassembledCode);
        }
示例#26
0
        private void DisassembleArithmetic1HexFileCorrectly()
        {
            var fakeBus = A.Fake <IBus>();

            var expectedDisassembly = new Dictionary <ushort, string>
            {
                { 0x0080, "LD A,&05" },
                { 0x0082, "LD B,&0A" },
                { 0x0084, "ADD A,B" },
                { 0x0085, "ADD A,A" },
                { 0x0086, "LD C,&0F" },
                { 0x0088, "SUB A,C" },
                { 0x0089, "LD H,&08" },
                { 0x008B, "LD L,&FF" },
                { 0x008D, "LD (HL),A" },
                { 0x008E, "NOP" },
            };

            var ram = HexFileReader.Read("../../../HexFiles/Arithmetic1.hex");

            A.CallTo(() => fakeBus.Read(A <ushort> ._, A <bool> ._))
            .ReturnsLazily((ushort addr, bool ro) => ram[addr]);

            var cpu = new Z80()
            {
                A = 0x00, PC = 0x0080
            };

            cpu.ConnectToBus(fakeBus);
            var disassembledCode = cpu.Disassemble(0x0080, 0x008E);

            Assert.Equal(expectedDisassembly, disassembledCode);
        }
示例#27
0
文件: GBEmu.cs 项目: saintwolf/GBEmu
        public static void frame()
        {
            Thread.Sleep(2);
            int fclk = Z80.Clock.t + 70224;

            do
            {
                try
                {
                    Z80.step();
                    GPU.step();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Registers:");
                    Console.WriteLine("A : " + Z80.Registers.a.ToString("X"));
                    Console.WriteLine("B : " + Z80.Registers.b.ToString("X"));
                    Console.WriteLine("C : " + Z80.Registers.c.ToString("X"));
                    Console.WriteLine("D : " + Z80.Registers.d.ToString("X"));
                    Console.WriteLine("E : " + Z80.Registers.e.ToString("X"));
                    Console.WriteLine("H : " + Z80.Registers.h.ToString("X"));
                    Console.WriteLine("L : " + Z80.Registers.l.ToString("X"));
                    Console.WriteLine("PC : " + Z80.Registers.pc.ToString("X"));
                    Console.WriteLine("SP : " + Z80.Registers.sp.ToString("X"));
                    Console.WriteLine("F (Decimal) : " + Z80.Registers.f.ToString("X"));
                    Console.WriteLine("Clock m : " + Z80.Clock.m.ToString("X"));
                    Console.WriteLine("Clock t : " + Z80.Clock.t.ToString("X"));
                }
            } while (Z80.Clock.t < fclk);
        }
示例#28
0
文件: Program.cs 项目: mrange/z80emu
        static void Main(string[] args)
        {
            var ram = new byte[65536];

            Array.Clear(ram, 0, ram.Length);
            var romData = File.ReadAllBytes(_rom);

            if (romData.Length != 16384)
            {
                throw new InvalidOperationException("Not a valid ROM file");
            }

            Array.Copy(romData, ram, 16384);
            _cpu = new Z80();
            IBus simpleBus = new SimpleBus(ram);

            _cpu.ConnectToBus(simpleBus);

            Console.Clear();

            while (!(Console.KeyAvailable && (Console.ReadKey(true).Key == ConsoleKey.Escape)))
            {
                try
                {
                    _cpu.Step();
                    Console.Write($"\rPC: {_cpu.PC.ToString("X4")}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    Console.ReadLine();
                }
            }

            Console.WriteLine();
            Console.WriteLine();

            for (var i = 0x4000; i < 0x5800; i++)
            {
                if (i % 16 == 0)
                {
                    Console.Write("{0:X4} | ", i);
                }
                {
                    Console.Write("{0:x2} ", ram[i]);
                }

                if (i % 8 == 7)
                {
                    Console.Write("  ");
                }

                if (i % 16 == 15)
                {
                    Console.WriteLine();
                }
            }
        }
示例#29
0
 static public void OptReset()
 {
     Z80.Reset();
     CRTC.Reset();
     PPI.Reset();
     UPD.Reset();
     VGA.Reset();
 }
示例#30
0
文件: JP.cs 项目: chazjn/Z80CPU
 private void Jump(Z80 z80, bool performJump)
 {
     if (performJump)
     {
         var address = BitConverter.ToUInt16(new[] { z80.Buffer[2], z80.Buffer[1] }, 0);
         z80.PC.Value = address;
     }
 }
示例#31
0
文件: ZAsm.cs 项目: jo215/ZXSpectrum
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cpu"></param>
        /// <param name="memory"></param>
        public ZAsm(Z80 cpu, int[] memory)
        {
            Cpu = cpu;
            Memory = memory;
            ReadOpcodeMap();

            Registers = new List<string>();
            ReadListFromFile("Registers.txt", Registers);

            Mnemonics = new List<string>();
            ReadListFromFile("Mnemonics.txt", Mnemonics);

            SymbolTable = new Dictionary<string,int>();
        }
示例#32
0
        public MainEmulator()
        {
            _memoryMapper = new MemoryMapper();
            _portMapper = new PortMapper();
            _cpu = new Z80 { MemProvider = _memoryMapper, PortProvider = _portMapper };

            _graphics = new Graphics();
            _memoryMapper.Register(0x1000, 0x1fff, _graphics, true, false);
            _portMapper.Register(5, 7, _graphics);

            _ram = new Ram();
            _memoryMapper.Register(0, 0xffff, _ram, true, true);
            _portMapper.Register(0, 0, _ram);

            _tickCounter = new TickCounter(_cancellationTokenSource.Token);
            _portMapper.Register(130, 133, _tickCounter);

            _diskController = new DiskController(_memoryMapper, () => _cpu.Reset());
            _portMapper.Register(160, 169, _diskController);

            _serial = new Serial(_memoryMapper);
            _portMapper.Register(170, 179, _serial);

            _led = new Led();
            _portMapper.Register(3, 3, _led);

            _speaker = new Speaker();
            _portMapper.Register(4, 4, _speaker);

            _keyboard = new Keyboard();
            _portMapper.Register(128, 129, _keyboard);

            //FBootLoader = new BootLoader(FMemoryMapper);

            _memoryMapper.FinishRegistration();

            OriginalSpeed = true;
        }
示例#33
0
文件: z80ALU.cs 项目: leon737/Z80VM
 public Z80ALU(Z80 proc)
 {
     this.proc = proc;
 }