public void Insert(DataBus cpuBus, DataBus ppuBus) { _cpuBus = cpuBus; _ppuBus = ppuBus; cpuBus.ConnectDevice(this, 0x4020, 0xFFFF); ppuBus.ConnectDevice(this, 0x0000, 0x1FFF); if (Mapper.NameTableSize > 0) { ppuBus.ConnectDevice(this, 0x2000, 0x2000 + Mapper.NameTableSize); } }
static void Run(byte[] program) { Rom programMemory = new Rom(program); DataBus mainBus = new DataBus(0xFFFF); mainBus.ConnectDevice(programMemory, (uint)(0xFFFF - program.Length), 0xFFFF); Cpu cpu = new Cpu(mainBus); cpu.Reset(); stepMode = StepMode.RUN; ProcessInput(); while (true) { bool isDoStep = doStep; if (stepMode == StepMode.RUN || doStep) { cpu.Clock(); } //if (cpu.RemainingInstructionCycles == 0) //{ if (stepMode == StepMode.RUN || doStep) { Console.WriteLine("A: ${0:X2} | X: ${1:X2} | Y: ${2:X2}", cpu.A, cpu.X, cpu.Y); Console.WriteLine("PC: ${0:X4}", cpu.ProgramCounter); Console.WriteLine("Next: {0}", InstructionSet.InstuctionsByOpcode[programMemory.ReadByte(cpu.ProgramCounter)].Name); } if (stepMode == StepMode.STEP && isDoStep == doStep) { doStep = false; } //} } }
public override bool OnUserCreate() { // SETUP THE RAM _ram = new Ram(NES_RAM_SIZE); // SETUP THE BUSSES _cpuBus = new DataBus(CPU_ADDRESSABLE_RANGE); _ppuBus = new DataBus(PPU_ADDRESSABLE_RANGE); _cpuBus.ConnectDevice(_ram, 0x0000, 0x1FFF); // SETUP THE CPU _cpu = new Cpu(_cpuBus); // SETUP THE PPU _ppu = new Ppu(_ppuBus, _cpu); _oamDma = new OamDirectMemoryAccess(_ppu, _ram); _ppuControlBus = new PpuControlBus(_ppu); _cpuExtended = new CpuExtended(_oamDma, _cpu); _cpuBus.ConnectDevice(_cpuExtended, 0x4000, 0x4015); // 4016 is connected to controller device _cpuBus.ConnectDevice(_cpuExtended, 0x4017, 0x401F); _cpuBus.ConnectDevice(_ppuControlBus, 0x2000, 0x3FFF); // SETUP THE CARTRIDGE _cartridge = new Cartridge(); //_cartridge.Load(@"D:\tmp\full_palette.nes"); //_cartridge.Load(@"D:\tmp\nestest.nes"); //_cartridge.Load(@"D:\tmp\Legend of Zelda, The (USA).nes"); _cartridge.Load(@"E:\games\roms\Super Mario Bros (E).nes"); //_cartridge.Load(@"D:\tmp\Super Mario Bros. 3 (USA).nes"); //_cartridge.Load(@"D:\tmp\Clu Clu Land (World).nes"); //_cartridge.Load(@"D:\tmp\DuckTales (USA).nes"); //_cartridge.Load(@"D:\tmp\Chip n Dale - Rescue Rangers (USA).nes"); //_cartridge.Load(@"D:\tmp\Ninja Gaiden (USA).nes"); _cartridge.Insert(_cpuBus, _ppuBus); if (_cartridge.Mapper.NameTableSize < 0x2000) { _vram = new NameTableRam(_cartridge); _ppuBus.ConnectDevice(_vram, 0x2000, 0x3EFF); _paletteRam = new PaletteRam(); _ppuBus.ConnectDevice(_paletteRam, 0x3F00, 0x3FFF); } _controller = new Controller(); _cpuBus.ConnectDevice(_controller, 0x4016, 0x4016); // RESET TO INITIAL STATE _cpu.Reset(); //Thread printThread = new Thread(this.tStart); //printThread.Start(); //_ppuThread = new Thread(this.ppuStart); //_cpuThread = new Thread(this.cpuStart); //_ppuThread.Start(_ppu); //_cpuThread.Start(_cpu); //Thread main = new Thread(this.mainStart); //main.Start(); return(true); }