Пример #1
0
        public void UpdateCGB(MMU mmu, int value)
        {
            int  register  = mmu.ReadByte(PaletteIndexAddress);
            bool increment = Bitwise.IsBitOn(register, 7);
            int  index     = register & 0x3F;

            int colorToModify = (index % 8) / 2;

            if ((index % 8) % 2 == 0)
            {
                red[colorToModify]   = value & 0x1F;
                green[colorToModify] = (green[colorToModify] & 0x18) | (value >> 5);
            }
            else
            {
                green[colorToModify] = (green[colorToModify] & 0x07) | ((value & 0x03) << 3);
                blue[colorToModify]  = (value >> 2) & 0x1F;
            }

            Colors[colorToModify].R = (int)((red[colorToModify] / 31.0) * 255);
            Colors[colorToModify].G = (int)((green[colorToModify] / 31.0) * 255);
            Colors[colorToModify].B = (int)((blue[colorToModify] / 31.0) * 255);

            if (increment)
            {
                index = (index + 1) % 64;
                mmu.WriteByte(index | (0x80), PaletteIndexAddress);
            }
        }
Пример #2
0
    protected override void Draw(GameTime gameTime)
    {
        byte stat = 0;

        _mmu[Registers.LY] = 0;
        for (int i = 0; i < 154; i++)
        {
            //Per ogni scanline
            for (int j = 0; j < 114; j++)
            {
                stat = _mmu[Registers.STAT];
                if (j < 20)
                {
                    //Mode 2 10
                    stat.SetBit(1, true);
                    stat.SetBit(0, false);
                }
                if (j > 20)
                {
                    //Mode 3 11
                    stat.SetBit(1, true);
                    stat.SetBit(0, true);
                }
                if (j > 63)
                {
                    //Mode 0 00
                    stat.SetBit(1, false);
                    stat.SetBit(0, false);
                }
                if (i > 143)
                {
                    //Mode 1 01
                    stat.SetBit(1, false);
                    stat.SetBit(0, true);
                }
                _mmu[Registers.STAT] = stat;
            }
            _mmu[Registers.LY]++;
        }

        if (_mmu[Registers.LY] == _mmu[Registers.LYC])
        {
            /*
             * The Game Boy permanently compares the value of the LYC and LY registers.
             * When both values are identical, the “LYC=LY” flag in the STAT register is set, and (if enabled) a STAT interrupt is requested.
             */
        }

        _dmgTilemap.Draw(gameTime);
        _dmgBackground.Draw(gameTime);

        _spriteBatch.Begin(samplerState: SamplerState.PointClamp);
        GraphicsDevice.SetRenderTarget(null);
        ////////////////////
        _spriteBatch.Draw(_dmgTilemap.TileMap, new Rectangle(2, 2, 128 * 2, 128 * 2), Color.White);
        _spriteBatch.Draw(_dmgBackground.Background, new Rectangle(260, 2, 256 * 2, 256 * 2), Color.White);
        _spriteBatch.Draw(_dmgBackgroundDisplayOverlay.BackgroundDisplayOverlay, new Rectangle(260, 2 + _mmu[Registers.SCY] * 2, DMG_SCREEN_WIDTH * 2, DMG_SCREEN_HEIGHT * 2), Color.White);
        _spriteBatch.End();
        //////////////////////////////////////////////

        //Trigghera l'interrupt V-Blank
        byte oldif = _mmu.ReadByte(0xFF0F);

        oldif.SetBit(0, true);

        //Trigghera l'interrupt STAT
        byte oldstat = _mmu[Registers.STAT];

        if (oldstat.CheckBit(6))
        {
            if (_mmu[Registers.LY] == _mmu[Registers.LYC])
            {
                oldif.SetBit(1, true);
            }
        }
        _mmu.WriteByte(0xFF0F, oldif);
        base.Draw(gameTime);

        _spriteBatch.Begin();
        GraphicsDevice.SetRenderTarget(null);
        int b = 100;

        //8 bit registers
        _spriteBatch.DrawString(debugFont, $"A: (0x{_cpu.A:X2}) {_cpu.A}", new Vector2(2, b + 300), Color.White);
        _spriteBatch.DrawString(debugFont, $"F: (0x{_cpu.F:X2}) {_cpu.F}", new Vector2(2, b + 320), Color.White);
        _spriteBatch.DrawString(debugFont, $"B: (0x{_cpu.B:X2}) {_cpu.B}", new Vector2(2, b + 340), Color.White);
        _spriteBatch.DrawString(debugFont, $"C: (0x{_cpu.C:X2}) {_cpu.C}", new Vector2(2, b + 360), Color.White);
        _spriteBatch.DrawString(debugFont, $"D: (0x{_cpu.D:X2}) {_cpu.D}", new Vector2(2, b + 380), Color.White);
        _spriteBatch.DrawString(debugFont, $"E: (0x{_cpu.E:X2}) {_cpu.E}", new Vector2(2, b + 400), Color.White);
        _spriteBatch.DrawString(debugFont, $"H: (0x{_cpu.H:X2}) {_cpu.H}", new Vector2(2, b + 420), Color.White);
        _spriteBatch.DrawString(debugFont, $"H: (0x{_cpu.H:X2}) {_cpu.H}", new Vector2(2, b + 440), Color.White);

        //16 bit registers
        _spriteBatch.DrawString(debugFont, $"BC: (0x{_cpu.BC:X4}) {_cpu.BC}", new Vector2(2, b + 480), Color.White);
        _spriteBatch.DrawString(debugFont, $"DE: (0x{_cpu.DE:X4}) {_cpu.DE}", new Vector2(2, b + 500), Color.White);
        _spriteBatch.DrawString(debugFont, $"HL: (0x{_cpu.HL:X4}) {_cpu.HL}", new Vector2(2, b + 520), Color.White);

        //PC e SP
        _spriteBatch.DrawString(debugFont, $"SP: (0x{_cpu.SP:X4}) {_cpu.SP:X4}", new Vector2(2, b + 560), Color.White);
        _spriteBatch.DrawString(debugFont, $"PC: (0x{_cpu.PC:X4}) {_cpu.PC:X4}", new Vector2(2, b + 580), Color.White);

        //Current instruction
        _spriteBatch.DrawString(debugFont, $"{_cpu.PC:X4} (3F)(5E)(C2) PUSH HL", new Vector2(1420, 2), Color.White);
        _spriteBatch.End();
    }