Exemple #1
0
        public CPU(Memory memory, PPU ppu, LoadUnit loadUnit, ALU alu, MiscUnit miscUnit, JumpUnit jumpUnit, BitUnit bitUnit)
        {
            this.ppu = ppu;

            this.loadUnit = loadUnit;
            this.alu      = alu;
            this.miscUnit = miscUnit;
            this.jumpUnit = jumpUnit;
            this.bitUnit  = bitUnit;

            this.loadUnit.TickEvent += Tick;
            this.alu.TickEvent      += Tick;
            this.jumpUnit.TickEvent += Tick;
            this.bitUnit.TickEvent  += Tick;

            CreateLoadUnitOpCodes();
            CreateALUOpCodes();
            CreateMiscOpCodes();
            CreateJumpOpCodes();
            CreateBitUnitOpCodes();

            this.memory = memory;
            this.timer  = new Timer(memory);
            this.memory.DivResetEvent += DivResetHandler;

            interruptVector = new Dictionary <Interrupt, ushort>
            {
                { Interrupt.VBlank, 0x40 },
                { Interrupt.LCDStat, 0x48 },
                { Interrupt.Timer, 0x50 },
                { Interrupt.Serial, 0x58 },
                { Interrupt.Joypad, 0x60 }
            };
        }
Exemple #2
0
        public CPUTests(ITestOutputHelper testOutputHelper)
        {
            this.testOutputHelper = testOutputHelper;

            memory = new Memory(new byte[]
            {
                IMMEDIATE_BYTE,
                (IMMEDIATE_WORD >> 8) & 0xFF
            });
            display  = new BlankDisplay();
            ppu      = new PPU(memory, display);
            loadUnit = A.Fake <LoadUnit>();
            alu      = A.Fake <ALU>();
            miscUnit = A.Fake <MiscUnit>();
            jumpUnit = A.Fake <JumpUnit>();
            bitUnit  = A.Fake <BitUnit>();
            cpu      = new CPU(memory, ppu, loadUnit, alu, miscUnit, jumpUnit, bitUnit)
            {
                A  = 0x0A,
                B  = 0x0B,
                C  = 0x0C,
                D  = 0x0D,
                E  = 0x0E,
                H  = 0xAA,
                L  = 0xBB,
                PC = 0x00,
                SP = 0xFF
            };
            memory.WriteByte(0xAABB, MEM_HL_BYTE);
        }
Exemple #3
0
        public void SetCarryTest()
        {
            var  miscUnit = new MiscUnit(new Memory());
            byte flags    = 0b11100000;

            miscUnit.SetCarry(ref flags);

            Assert.Equal(0b10010000, flags);
        }
Exemple #4
0
        public void HaltTest()
        {
            var memory   = new Memory();
            var miscUnit = new MiscUnit(memory);
            var mode     = CPU.PowerMode.Normal;

            miscUnit.Halt(ref mode, true);
            Assert.Equal(CPU.PowerMode.Halt, mode);

            // Interrupt pending causes halt bug
            memory.WriteByte(0xFFFF, 0x1);
            memory.WriteByte(0xFF0F, 0x1);
            miscUnit.Halt(ref mode, false);
            Assert.Equal(CPU.PowerMode.HaltBug, mode);

            memory.WriteByte(0xFFFF, 0x2);
            memory.WriteByte(0xFF0F, 0x1);
            miscUnit.Halt(ref mode, false);
            Assert.Equal(CPU.PowerMode.Halt, mode);
        }
Exemple #5
0
        public void DecimalAdjustTest()
        {
            var  miscUnit = new MiscUnit(new Memory());
            byte flags    = 0;

            byte value = 0x01;

            miscUnit.DecimalAdjust(ref value, ref flags);
            Assert.Equal(0x1, value);

            value = 0x0A;
            miscUnit.DecimalAdjust(ref value, ref flags);
            Assert.Equal(0x10, value);

            value = 0x0F;
            miscUnit.DecimalAdjust(ref value, ref flags);
            Assert.Equal(0x15, value);

            flags = 0b01100000;
            value = 0x1F;
            miscUnit.DecimalAdjust(ref value, ref flags);
            Assert.Equal(0x19, value);
        }