예제 #1
0
        public void LoadRom(string fileName)
        {
            if (this.imageStream != null)
            {
                this.imageStream.Close();
                this.imageStream.Dispose();
            }

            this.imageStream = File.OpenRead(fileName);

            this.reader = this.GetReader();
            if (reader == null)
            {
                throw new InvalidOperationException("Not a valid ROM!");
            }

            Trace.WriteLine("Loaded ROM: {0}".FormatCurrentCulture(fileName));
            Trace.WriteLine("  PRG ROM: {0} bytes".FormatCurrentCulture(this.reader.PrgRomSize));
            Trace.WriteLine("  PRG RAM: {0} bytes".FormatCurrentCulture(this.reader.PrgRamSize));
            Trace.WriteLine("  CHR ROM: {0} bytes".FormatCurrentCulture(this.reader.ChrRomSize));
            Trace.WriteLine("  Mapper ID: {0}".FormatCurrentCulture(this.reader.Mapper));

            IMapperFactory mapperFactory = this.MapperFactories.FirstOrDefault(f => f.Metadata.MapperId == this.reader.Mapper)?.Value;

            if (mapperFactory == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "No mapper available with ID '{0}'!", this.reader.Mapper));
            }

            if (this.currentMapper != null)
            {
                // Dispose the old mapper to unhook it from the memory buses
                this.currentMapper.Dispose();
                this.currentMapper = null;
            }

            this.currentMapper = mapperFactory.CreateInstance(this.reader, this.cpuBus, this.ppuBus, this.irq);

            Trace.WriteLine("  Mapper name: {0}".FormatCurrentCulture(this.currentMapper.Name));
        }
예제 #2
0
 public static IMapper CreateDefault(object config = null) => DefaultFactory.CreateInstance(config);