Exemplo n.º 1
0
		public Cpu()
		{
			processor = new MOS6502X();
			processor.DummyReadMemory = CoreReadMemory;
			processor.ReadMemory = CoreReadMemory;
			processor.WriteMemory = CoreWriteMemory;
			Reset();
		}
Exemplo n.º 2
0
        // ------------------------------------
        public MOS6510()
        {
            cpu = new MOS6502X();

            // configure cpu r/w
            cpu.DummyReadMemory = Read;
            cpu.ReadMemory = Read;
            cpu.WriteMemory = Write;

            // perform hard reset
            HardReset();
        }
Exemplo n.º 3
0
		// ------------------------------------

		public Chip6510()
		{
            // configure cpu r/w
            _cpu = new MOS6502X
            {
		        DummyReadMemory = CpuRead,
		        ReadMemory = CpuRead,
		        WriteMemory = CpuWrite,
                PeekMemory = CpuPeek
		    };

		    // perform hard reset
			HardReset();
		}
Exemplo n.º 4
0
        public Drive1541(int clockNum, int clockDen)
        {
            DriveRom = new Chip23128();
            _cpu = new MOS6502X
            {
                ReadMemory = CpuRead,
                WriteMemory = CpuWrite,
                DummyReadMemory = CpuRead,
                PeekMemory = CpuPeek,
                NMI = false
            };

            _ram = new int[0x800];
            Via0 = Chip6522.Create(ViaReadClock, ViaReadData, ViaReadAtn, 8);
            Via1 = Chip6522.Create(ReadVia1PrA, ReadVia1PrB);

            _cpuClockNum = clockNum;
            _driveCpuClockNum = clockDen*16000000; // 16mhz
        }
Exemplo n.º 5
0
		public void HardReset()
		{
			cpu = new MOS6502X();
			cpu.SetCallbacks(ReadMemory, ReadMemory, PeekMemory, WriteMemory);

			cpu.BCD_Enabled = false;
			cpu.OnExecFetch = ExecFetch;
			ppu = new PPU(this);
			ram = new byte[0x800];
			CIRAM = new byte[0x800];
			
			// wire controllers
			// todo: allow changing this
			ControllerDeck = ControllerSettings.Instantiate(ppu.LightGunCallback);
			// set controller definition first time only
			if (ControllerDefinition == null)
			{
				ControllerDefinition = new ControllerDefinition(ControllerDeck.GetDefinition());
				ControllerDefinition.Name = "NES Controller";
				// controls other than the deck
				ControllerDefinition.BoolButtons.Add("Power");
				ControllerDefinition.BoolButtons.Add("Reset");
				if (Board is FDS)
				{
					var b = Board as FDS;
					ControllerDefinition.BoolButtons.Add("FDS Eject");
					for (int i = 0; i < b.NumSides; i++)
						ControllerDefinition.BoolButtons.Add("FDS Insert " + i);
				}
			}

			// don't replace the magicSoundProvider on reset, as it's not needed
			// if (magicSoundProvider != null) magicSoundProvider.Dispose();

			// set up region
			switch (_display_type)
			{
				case Common.DisplayType.PAL:
					apu = new APU(this, apu, true);
					ppu.region = PPU.Region.PAL;
					CoreComm.VsyncNum = 50;
					CoreComm.VsyncDen = 1;
					cpuclockrate = 1662607;
					cpu_sequence = cpu_sequence_PAL;
					_display_type = DisplayType.PAL;
					break;
				case Common.DisplayType.NTSC:
					apu = new APU(this, apu, false);
					ppu.region = PPU.Region.NTSC;
					CoreComm.VsyncNum = 39375000;
					CoreComm.VsyncDen = 655171;
					cpuclockrate = 1789773;
					cpu_sequence = cpu_sequence_NTSC;
					break;
				// this is in bootgod, but not used at all
				case Common.DisplayType.DENDY:
					apu = new APU(this, apu, false);
					ppu.region = PPU.Region.Dendy;
					CoreComm.VsyncNum = 50;
					CoreComm.VsyncDen = 1;
					cpuclockrate = 1773448;
					cpu_sequence = cpu_sequence_NTSC;
					_display_type = DisplayType.DENDY;
					break;
				default:
					throw new Exception("Unknown displaytype!");
			}
			if (magicSoundProvider == null)
				magicSoundProvider = new MagicSoundProvider(this, (uint)cpuclockrate);

			BoardSystemHardReset();

			//check fceux's PowerNES and FCEU_MemoryRand function for more information:
			//relevant games: Cybernoid; Minna no Taabou no Nakayoshi Daisakusen; Huang Di; and maybe mechanized attack
			for(int i=0;i<0x800;i++) if((i&4)!=0) ram[i] = 0xFF; else ram[i] = 0x00;

			SetupMemoryDomains();

			//in this emulator, reset takes place instantaneously
			cpu.PC = (ushort)(ReadMemory(0xFFFC) | (ReadMemory(0xFFFD) << 8));
			cpu.P = 0x34;
			cpu.S = 0xFD;
		}
Exemplo n.º 6
0
 public string Disassemble(MemoryDomain m, uint addr, out int length)
 {
     return(MOS6502X.Disassemble((ushort)addr, out length, a => m.PeekByte((int)a)));
 }
Exemplo n.º 7
0
 public string Disassemble(ushort pc, out int bytesToAdvance)
 {
     return(MOS6502X.Disassemble(pc, out bytesToAdvance, _link.PeekMemory));
 }
Exemplo n.º 8
0
		public VIC1541Motherboard(Region initRegion, byte[] initRom)
		{
			cpu = new MOS6502X();
			pla = new VIC1541PLA();
			ram = new byte[0x800];
			rom = initRom;
			serPort = new SerialPort();
			via0 = new MOS6522();
			via1 = new MOS6522();

			cpu.DummyReadMemory = pla.Read;
			cpu.ReadMemory = pla.Read;
			cpu.WriteMemory = pla.Write;

			pla.PeekRam = ((int addr) => { return ram[addr & 0x07FF]; });
			pla.PeekRom = ((int addr) => { return rom[addr & 0x3FFF]; });
			pla.PeekVia0 = via0.Peek;
			pla.PeekVia1 = via1.Peek;
			pla.PokeRam = ((int addr, byte val) => { ram[addr & 0x07FF] = val; });
			pla.PokeRom = ((int addr, byte val) => { });
			pla.PokeVia0 = via0.Poke;
			pla.PokeVia1 = via1.Poke;
			pla.ReadRam = ((ushort addr) => { return ram[addr & 0x07FF]; });
			pla.ReadRom = ((ushort addr) => { return rom[addr & 0x3FFF]; });
			pla.ReadVia0 = via0.Read;
			pla.ReadVia1 = via1.Read;
			pla.WriteRam = ((ushort addr, byte val) => { ram[addr & 0x07FF] = val; });
			pla.WriteRom = ((ushort addr, byte val) => { });
			pla.WriteVia0 = via0.Write;
			pla.WriteVia1 = via1.Write;

			via0CA0 = false;
			via0CA1 = false;
			via0CB0 = false;
			via0CB1 = false;
			via0DirA = 0x00;
			via0DirB = 0x00;
			via0DataA = 0xFF;
			via0DataB = 0xFF;
			via1CA0 = false;
			via1CA1 = false;
			via1CB0 = false;
			via1CB1 = false;
			via1DirA = 0x00;
			via1DirB = 0x00;
			via1DataA = 0xFF;
			via1DataB = 0xFF;

			via0.ReadCA0 = (() => { return via0CA0; });
			via0.ReadCA1 = (() => { return via0CA1; });
			via0.ReadCB0 = (() => { return via0CB0; });
			via0.ReadCB1 = (() => { return via0CB1; });
			via0.ReadDirA = (() => { return via0DirA; });
			via0.ReadDirB = (() => { return via0DirB; });
			via0.ReadPortA = (() => { return via0DataA; });
			via0.ReadPortB = (() => { return via0DataB; });
			via0.WriteCA0 = ((bool val) => { via0CA0 = val; });
			via0.WriteCA1 = ((bool val) => { via0CA1 = val; });
			via0.WriteCB0 = ((bool val) => { via0CB0 = val; });
			via0.WriteCB1 = ((bool val) => { via0CB1 = val; });
			via0.WriteDirA = ((byte val) => { via0DirA = val; });
			via0.WriteDirB = ((byte val) => { via0DirB = val; });
			via0.WritePortA = ((byte val) => {
				via0DataA = Port.CPUWrite(via0DataA, val, via0DirA);
			});
			via0.WritePortB = ((byte val) => {
				via0DataB = Port.CPUWrite(via0DataB, val, via0DirB);
				serPort.DeviceWriteAtn((via0DataB & 0x80) != 0);
				serPort.DeviceWriteClock((via0DataB & 0x08) != 0);
				serPort.DeviceWriteData((via0DataB & 0x02) != 0);
			});

			via1.ReadCA0 = (() => { return via1CA0; });
			via1.ReadCA1 = (() => { return via1CA1; });
			via1.ReadCB0 = (() => { return via1CB0; });
			via1.ReadCB1 = (() => { return via1CB1; });
			via1.ReadDirA = (() => { return via1DirA; });
			via1.ReadDirB = (() => { return via1DirB; });
			via1.ReadPortA = (() => { return via1DataA; });
			via1.ReadPortB = (() => { return via1DataB; });
			via1.WriteCA0 = ((bool val) => { via1CA0 = val; });
			via1.WriteCA1 = ((bool val) => { via1CA1 = val; });
			via1.WriteCB0 = ((bool val) => { via1CB0 = val; });
			via1.WriteCB1 = ((bool val) => { via1CB1 = val; });
			via1.WriteDirA = ((byte val) => { via1DirA = val; });
			via1.WriteDirB = ((byte val) => { via1DirB = val; });
			via1.WritePortA = ((byte val) => {
				via1DataA = Port.CPUWrite(via1DataA, val, via1DirA);
			});
			via1.WritePortB = ((byte val) => {
				via1DataB = Port.CPUWrite(via1DataB, val, via1DirB);
			});	
		}
Exemplo n.º 9
0
		public void HardReset()
		{
			Ram = new byte[128];
			_mapper.HardReset();

			Cpu = new MOS6502X
			{
				ReadMemory = this.ReadMemory,
				WriteMemory = this.WriteMemory,
				PeekMemory = this.PeekMemory,
				DummyReadMemory = this.ReadMemory,
				OnExecFetch = this.ExecFetch
			};

			_tia.Reset();

			M6532 = new M6532(this);
			Cpu.PC = (ushort)(ReadMemory(0x1FFC) + (ReadMemory(0x1FFD) << 8)); // set the initial PC
		}
Exemplo n.º 10
0
		public void RebootCore()
		{
			// Regenerate mapper here to make sure its state is entirely clean
			switch (_game.GetOptionsDict()["m"])
			{
				case "2IN1":
					_mapper = SetMultiCartMapper(Rom.Length, 2);
					break;
				case "4IN1":
					_mapper = SetMultiCartMapper(Rom.Length, 4);
					break;
				case "8IN1":
					_mapper = SetMultiCartMapper(Rom.Length, 8);
					break;
				case "16IN1":
					_mapper = SetMultiCartMapper(Rom.Length, 16);
					break;
				case "32IN1":
					_mapper = SetMultiCartMapper(Rom.Length, 32);
					break;
				case "AR":
					_mapper = new mAR(this); // This mapper has to set up configurations in the contructor.
					break;
				case "4K":
					_mapper = new m4K();
					break;
				case "2K":
					_mapper = new m2K();
					break;
				case "CM":
					_mapper = new mCM();
					break;
				case "CV":
					_mapper = new mCV();
					break;
				case "DPC":
					_mapper = new mDPC();
					break;
				case "DPC+":
					_mapper = new mDPCPlus();
					break;
				case "F8":
					_mapper = new mF8();
					break;
				case "F8SC":
					_mapper = new mF8SC();
					break;
				case "F6":
					_mapper = new mF6();
					break;
				case "F6SC":
					_mapper = new mF6SC();
					break;
				case "F4":
					_mapper = new mF4();
					break;
				case "F4SC":
					_mapper = new mF4SC();
					break;
				case "FE":
					_mapper = new mFE();
					break;
				case "E0":
					_mapper = new mE0();
					break;
				case "3F":
					_mapper = new m3F();
					break;
				case "FA":
					_mapper = new mFA();
					break;
				case "FA2":
					_mapper = new mFA2();
					break;
				case "E7":
					_mapper = new mE7();
					break;
				case "F0":
					_mapper = new mF0();
					break;
				case "UA":
					_mapper = new mUA();
					break;

				// Homebrew mappers
				case "3E":
					_mapper = new m3E();
					break;
				case "0840":
					_mapper = new m0840();
					break;
				case "MC":
					_mapper = new mMC();
					break;
				case "EF":
					_mapper = new mEF();
					break;
				case "EFSC":
					_mapper = new mEFSC();
					break;
				case "X07":
					_mapper = new mX07();
					break;
				case "4A50":
					_mapper = new m4A50();
					break;
				case "SB":
					_mapper = new mSB();
					break;

				default:
					throw new InvalidOperationException("mapper not supported: " + _game.GetOptionsDict()["m"]);
			}

			_mapper.Core = this;

			_lagcount = 0;
			Cpu = new MOS6502X
			{
				ReadMemory = this.ReadMemory,
				WriteMemory = this.WriteMemory,
				PeekMemory = this.PeekMemory,
				DummyReadMemory = this.ReadMemory,
				OnExecFetch = this.ExecFetch
			};

			if (_game["PAL"])
			{
				_pal = true;
			}
			else if (_game["NTSC"])
			{
				_pal = false;
			}
			else
			{
				_pal = DetectPal(_game, Rom);
			}

			_tia = new TIA(this, _pal, Settings.SECAMColors);
			_tia.GetFrameRate(out CoreComm.VsyncNum, out CoreComm.VsyncDen);

			// dcfilter coefficent is from real observed hardware behavior: a latched "1" will fully decay by ~170 or so tia sound cycles
			_dcfilter = DCFilter.AsISoundProvider(_tia, 256);

			M6532 = new M6532(this);

			// Set up the system state here. for instance..
			// Read from the reset vector for where to start
			Cpu.PC = (ushort)(ReadMemory(0x1FFC) + (ReadMemory(0x1FFD) << 8)); // set the initial PC

			// Show mapper class on romstatusdetails
			CoreComm.RomStatusDetails =
				string.Format(
					"{0}\r\nSHA1:{1}\r\nMD5:{2}\r\nMapper Impl \"{3}\"",
					this._game.Name,
					Rom.HashSHA1(),
					Rom.HashMD5(),
					_mapper.GetType());
		}
Exemplo n.º 11
0
        private void HardReset()
        {
            Ram = new byte[128];
            _mapper.HardReset();

            Cpu = new MOS6502X
            {
                ReadMemory = this.ReadMemory,
                WriteMemory = this.WriteMemory,
                PeekMemory = this.PeekMemory,
                DummyReadMemory = this.ReadMemory,
                OnExecFetch = this.ExecFetch
            };

            _tia.Reset();

            M6532 = new M6532(this);
            Cpu.PC = (ushort)(ReadMemory(0x1FFC) + (ReadMemory(0x1FFD) << 8)); // set the initial PC

            // as it turns out, the stack pointer cannot be set to 0 for some games as they do not initilize it themselves.
            // some documentation seems to indicate it should beset to FD, but currently there is no documentation of the 6532
            // executing a reset sequence at power on, but it's needed so let's hard code it for now
            Cpu.S = 0xFD;
        }