public void TestAllInterruptsCanBeEnabled(int interrupt, byte expectedValue)
        {
            var interruptRegisters = new InterruptRegisters();

            interruptRegisters.RequestInterrupt((Interrupt)interrupt);

            Assert.Equal(expectedValue, interruptRegisters.InterruptFlags);
        }
        public void TestInterruptResetWorks()
        {
            var interruptRegisters = new InterruptRegisters();

            foreach (var interrupt in Enum.GetValues(typeof(Interrupt)).Cast <Interrupt>())
            {
                interruptRegisters.RequestInterrupt(interrupt);
                Assert.Equal(interrupt.Mask() | 0b11100000, interruptRegisters.InterruptFlags);
                interruptRegisters.ResetInterrupt(interrupt);
                Assert.Equal(0b11100000, interruptRegisters.InterruptFlags);
            }
        }
        public void TestInterruptsCanOverlap()
        {
            var interruptRegisters = new InterruptRegisters();

            interruptRegisters.RequestInterrupt(Interrupt.VerticalBlank);
            interruptRegisters.RequestInterrupt(Interrupt.LCDSTAT);
            Assert.Equal(0b11100011, interruptRegisters.InterruptFlags);

            interruptRegisters.RequestInterrupt(Interrupt.Timer);
            interruptRegisters.RequestInterrupt(Interrupt.Serial);
            Assert.Equal(0b11101111, interruptRegisters.InterruptFlags);

            interruptRegisters.RequestInterrupt(Interrupt.Joypad);
            Assert.Equal(0b11111111, interruptRegisters.InterruptFlags);
        }
Пример #4
0
        public Device(Cartridge.Cartridge cartridge, DeviceType type, IRenderer renderer, ISoundOutput soundOutput, byte[] bootRom)
        {
            Log = new LoggerConfiguration()
                  .MinimumLevel.Information()
                  .CreateLogger();

            // A bit of double checking that we're loading a valid cartridge for the device type
            if (cartridge.CGBSupportCode == CGBSupportCode.CGBExclusive && type == DeviceType.DMG)
            {
                Log.Error("Cartridge can't be loaded because it's CGB only and this device was created as DMG");
                throw new ApplicationException("Cartridge can't be loaded because it's CGB only and this device was created as DMG");
            }

            Type = type;
            Mode = cartridge.CGBSupportCode switch
            {
                CGBSupportCode.CGBExclusive => DeviceType.CGB,
                CGBSupportCode.CGBCompatible => type,
                CGBSupportCode.CGBIncompatible => DeviceType.DMG,
                _ => throw new ArgumentOutOfRangeException()
            };

            Renderer    = renderer;
            SoundOutput = soundOutput;

            InterruptRegisters = new InterruptRegisters();
            ControlRegisters   = new ControlRegisters();
            APU           = new APU(this);
            LCDRegisters  = new LCDRegisters(this);
            Cartridge     = cartridge;
            MMU           = new MMU(bootRom, this);
            CPU           = new CPU.CPU(this);
            _cpuGenerator = CPU.GetEnumerator();
            LCDDriver     = new LCDDriver(this);
            Timer         = new Timer(this);
            DMAController = new DMAController(this);
            JoypadHandler = new JoypadHandler(this);

            // Set default values if there was no passed in boot rom
            if (bootRom == null)
            {
                SkipBootRom();
            }
        }