private void ChangeMode(int mode) { _gameboy.Mmu.STAT = (_gameboy.Mmu.STAT & ~0x03) | (mode & 0x03); // Handle Interrupts switch (mode) { case 0: if (Bitwise.IsBitOn(_gameboy.Mmu.STAT, 3)) { _gameboy.Mmu.SetInterrupt(Interrupts.LCDStat); } RenderLine(); break; case 1: if (Bitwise.IsBitOn(_gameboy.Mmu.STAT, 4)) { _gameboy.Mmu.SetInterrupt(Interrupts.LCDStat); } _gameboy.Mmu.SetInterrupt(Interrupts.VBlank); useFb1 = !useFb1; if (useFb1) { FrameBuffer = fb1; } else { FrameBuffer = fb2; } _gameboy.EnqeueFrameBuffer(FrameBuffer); break; case 2: if (Bitwise.IsBitOn(_gameboy.Mmu.STAT, 5)) { _gameboy.Mmu.SetInterrupt(Interrupts.LCDStat); } break; } }