public Gameboy( GameboyOptions options, Cartridge rom, IDisplay display, IController controller, ISoundOutput soundOutput, SerialEndpoint serialEndpoint) { _display = display; _gbc = rom.Gbc; SpeedMode = new SpeedMode(); var interruptManager = new InterruptManager(_gbc); _timer = new Timer(interruptManager, SpeedMode); Mmu = new Mmu(); var oamRam = new Ram(0xfe00, 0x00a0); _dma = new Dma(Mmu, oamRam, SpeedMode); _gpu = new Gpu(display, interruptManager, _dma, oamRam, _gbc); _hdma = new Hdma(Mmu); _sound = new Sound(soundOutput, _gbc); _serialPort = new SerialPort(interruptManager, serialEndpoint, SpeedMode); Mmu.AddAddressSpace(rom); Mmu.AddAddressSpace(_gpu); Mmu.AddAddressSpace(new Joypad(interruptManager, controller)); Mmu.AddAddressSpace(interruptManager); Mmu.AddAddressSpace(_serialPort); Mmu.AddAddressSpace(_timer); Mmu.AddAddressSpace(_dma); Mmu.AddAddressSpace(_sound); Mmu.AddAddressSpace(new Ram(0xc000, 0x1000)); if (_gbc) { Mmu.AddAddressSpace(SpeedMode); Mmu.AddAddressSpace(_hdma); Mmu.AddAddressSpace(new GbcRam()); Mmu.AddAddressSpace(new UndocumentedGbcRegisters()); } else { Mmu.AddAddressSpace(new Ram(0xd000, 0x1000)); } Mmu.AddAddressSpace(new Ram(0xff80, 0x7f)); Mmu.AddAddressSpace(new ShadowAddressSpace(Mmu, 0xe000, 0xc000, 0x1e00)); Cpu = new Cpu(Mmu, interruptManager, _gpu, display, SpeedMode); interruptManager.DisableInterrupts(false); if (!options.UseBootstrap) { InitiliseRegisters(); } }
public static void Main(string[] args) { var cancellation = new CancellationTokenSource(); var arguments = GameboyOptions.Parse(args); Application.SetCompatibleTextRenderingDefault(false); Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); var emulator = new Emulator(arguments); if (!arguments.RomSpecified && arguments.ShowUi) { var(success, romPath) = WinFormsEmulatorSurface.PromptForRom(); arguments.Rom = success ? romPath : string.Empty; } if (!arguments.RomSpecified) { GameboyOptions.PrintUsage(Console.Out); Console.Out.Flush(); Environment.Exit(1); } if (arguments.ShowUi) { var ui = new WinFormsEmulatorSurface(); ui.Closed += (_, e) => { cancellation.Cancel(); }; emulator.Controller = ui; emulator.Display.OnFrameProduced += ui.UpdateDisplay; emulator.Run(cancellation.Token); Application.Run(ui); } else { emulator.Run(cancellation.Token); Console.WriteLine("Emulator running headless."); Console.WriteLine("Press ANY key to exit."); Console.ReadKey(true); cancellation.Cancel(); } }