Esempio n. 1
0
		public void LoadRom(MemoryBlock externalRom)
		{
			RomInformation romInformation;

			if (externalRom == null) throw new ArgumentNullException("externalRom");

			if ((externalRom.Length & 0x3FFF) != 0
				|| (externalRom.Length >> 14) > 256)
				throw new InvalidOperationException();

			romInformation = new RomInformation(externalRom);

			if (romInformation.RomSize != externalRom.Length) throw new InvalidOperationException();

			Mapper mapper;

			switch (romInformation.RomType)
			{
				case RomType.RomOnly:
				case RomType.RomRam:
				case RomType.RomRamBattery:
					mapper = new Mappers.RomController(this);
					break;
				case RomType.RomMbc1:
				case RomType.RomMbc1Ram:
				case RomType.RomMbc1RamBattery:
					mapper = new Mappers.MemoryBankController1(this);
					break;
				case RomType.RomMbc2:
				case RomType.RomMbc2Battery:
					mapper = new Mappers.MemoryBankController2(this);
					break;
				case RomType.RomMbc3:
				case RomType.RomMbc3Ram:
				case RomType.RomMbc3RamBattery:
				case RomType.RomMbc3TimerBattery:
				case RomType.RomMbc3TimerRamBattery:
					mapper = new Mappers.MemoryBankController3(this);
					break;
				case RomType.RomMbc5:
				case RomType.RomMbc5Ram:
				case RomType.RomMbc5RamBattery:
				case RomType.RomMbc5Rumble:
				case RomType.RomMbc5RumbleRam:
				case RomType.RomMbc5RumbleRamBattery:
					mapper = new Mappers.MemoryBankController5(this);
					break;
				default:
					throw new NotSupportedException("Unsupported Cartidge Type");
			}

#if WITH_THREADING
			SuspendEmulation();
#endif

			this.romInformation = romInformation;
			this.externalRomBlock = externalRom;
			this.mapper = mapper;
			this.colorMode = ColorHardware & romInformation.ColorGameBoySupport;

#if WITH_DEBUGGING
			ClearBreakpoints();
#endif
			Reset(); // Will call “ResumeEmulation”…

			// Fills the external RAM with random data.
			// It can be loaded with real data later.
			unsafe { RandomFill((byte*)externalRamBlock.Pointer, externalRamBlock.Length); }

			romLoaded = true;
		}
Esempio n. 2
0
		public void UnloadRom()
		{
			if (externalRomBlock != null)
			{
#if WITH_THREADING
				SuspendEmulation();
#endif
				this.mapper = null;
				this.externalRomBlock = null;
				this.romInformation = null;
				this.colorMode = ColorHardware;
#if WITH_DEBUGGING
				ClearBreakpoints();
#endif
				Reset(); // Will call “ResumeEmulation”…
			}
		}