public GameBoy(ICartridge cartridge) { Cartridge = cartridge; Memory = new GameBoyMemory(this); Cpu = new GameBoyCpu(this); Gpu = new GameBoyGpu(this); Spu = new GameBoySpu(this); KeyPad = new GameBoyPad(this); Timer = new GameBoyTimer(this); Reset(); IsPoweredOn = true; }
public GameBoy(ICartridge cartridge, IClock clock, bool preferGbcMode) { GbcMode = preferGbcMode && (cartridge.GameBoyColorFlag & GameBoyColorFlag.SupportsColor) != 0; _clock = clock; Components = new List <IGameBoyComponent> { (Cartridge = cartridge), (Memory = new GameBoyMemory(this)), (Cpu = new GameBoyCpu(this, clock)), (Gpu = new GameBoyGpu(this)), (Spu = new GameBoySpu(this)), (KeyPad = new GameBoyPad(this)), (Timer = new GameBoyTimer(this)) }.AsReadOnly(); foreach (var component in Components) { component.Initialize(); } Reset(); IsPoweredOn = true; _clock.Tick += NextFrame; new Thread(CpuLoop) { Name = "Z80CPULOOP", IsBackground = true }.Start(); _lastFrameTime = DateTime.Now; Gpu.VBlankStarted += (_, __) => { _framesCount++; FrameDelta = DateTime.Now - _lastFrameTime; _lastFrameTime = DateTime.Now; }; }
public GameBoy(ICartridge cartridge, IClock clock, bool preferGbcMode) { GbcMode = preferGbcMode && (cartridge.GameBoyColorFlag & GameBoyColorFlag.SupportsColor) != 0; Components = new List <IGameBoyComponent> { (Cartridge = cartridge), (Memory = new GameBoyMemory(this)), (Cpu = new GameBoyCpu(this, clock)), (Gpu = new GameBoyGpu(this)), (Spu = new GameBoySpu(this)), (KeyPad = new GameBoyPad(this)), (Timer = new GameBoyTimer(this)) }.AsReadOnly(); foreach (var component in Components) { component.Initialize(); } Reset(); IsPoweredOn = true; }
void InitalizeComponent() { Application.targetFrameRate = 60; //Create display texture = new Texture2D(width, height); Sprite sprite = Sprite.Create(texture, new Rect(0, 0, width, height), Vector2.zero, 1); sprite.name = "Screen"; GogbGraphic = GameObject.Find("GameBoyScreen"); GogbGraphic.GetComponent <SpriteRenderer>().sprite = sprite; Vector2 pivotPoints = new Vector2(0.0f, 0.0f); GogbGraphic.GetComponent <RectTransform>().pivot = pivotPoints; //Load Cartiridge gbCart = new GameBoyCartiridge(0); try { gbCart.LoadRom(pathToRom); } catch { Debug.Log("NO ROM LOADED"); } //Create memory gbMemory = new GameBoyMemory(gbCart); bool reset = false; try { gbMemory.LoadBios(pathToBios); } catch { reset = true; } //Create Interrupts gbInterrupts = new GameBoyInterrupts(gbMemory); //Create Timer gbTimer = new GameBoyTimer(gbMemory, gbInterrupts); gbMemory.AddTimer(gbTimer); //Create CPU gbCPU = new GameBoyCPU(gbMemory, gbInterrupts); if (reset && !GameBoyCartiridge.IsGameBoyColor) { gbCPU.ResetGBNoBios(); } else if (reset && GameBoyCartiridge.IsGameBoyColor) { gbCPU.ResetCGBNoBios(); } //Create GPU gbGraphic = new GameBoyGraphic(width, height, texture, gbInterrupts, gbMemory); //Create Audio gbAudio = new GameBoyAudio(); gbMemory.AddGraphics(gbGraphic); gbMemory.AddAudio(gbAudio); //Create Keyboard gbJoyPad = new GameBoyJoyPad(gbInterrupts, gbMemory); Debug.Log(GameBoyCartiridge.Title); Debug.Log(GameBoyCartiridge.IsGameBoyColor); Debug.Log(gbCart.CartiridgeType.ToString("X2")); }
public void AddTimer(GameBoyTimer gbTimer) { this.gbTimer = gbTimer; }