Exemplo n.º 1
0
            public ScanlineSprite Load(DataBus ppuBus, UInt16 patternTable, bool is8x16mode, uint scanline)
            {
                // 8x16 000j iiii iiis hsss
                // 8x8  000p iiii iiii hsss
                // p - patternTable
                // i - patternIndex
                // j - lowest nibble of pattern index
                // h - high/low byte of pattern
                // s - scanline - y

                uint yIdx = scanline - Y;

                if (FlipVer)
                {
                    yIdx = (is8x16mode ? 15u : 7u) - yIdx;
                }

                UInt16 pattTable = patternTable;
                byte   pattIndex = PatternIndex;

                if (is8x16mode)
                {
                    // Set pattern table to lowest nibble of index and clear that bit
                    pattTable = (UInt16)((pattIndex & 0x01) << 12);
                    pattIndex = (byte)(pattIndex & 0xFE);
                    // Move the 4th bit to the 5th
                    yIdx = (yIdx & 0x07) | ((yIdx & 0x08) << 1);
                }

                UInt16 patternAddress = (UInt16)(pattTable | (pattIndex << 4) | (byte)yIdx);

                LowPatternByte  = ppuBus.Read(patternAddress);
                HighPatternByte = ppuBus.Read((UInt16)(patternAddress | 0x0008));

                Loaded = true;
                return(this);
            }
Exemplo n.º 2
0
        private void DrawPalettes()
        {
            Sprite bgTex   = new Sprite(1, 1);
            Pixel  bgColor = BasePixels.Palette[_ppuBus.Read(0x3F00) & 0x3F];

            bgTex.SetPixel(0, 0, bgColor);

            DrawSprite(0, 250, bgTex, 4, (byte)Sprite.Flip.NONE);

            for (int i = 0; i < 8; i++)
            {
                Sprite palTex = new Sprite(3, 1);

                palTex.SetPixel(0, 0, BasePixels.Palette[_ppuBus.Read((UInt16)(0x3F00 + i * 4 + 1)) & 0x3F]);
                palTex.SetPixel(1, 0, BasePixels.Palette[_ppuBus.Read((UInt16)(0x3F00 + i * 4 + 2)) & 0x3F]);
                palTex.SetPixel(2, 0, BasePixels.Palette[_ppuBus.Read((UInt16)(0x3F00 + i * 4 + 3)) & 0x3F]);

                DrawSprite(4 + i * 12, 250, palTex, 4, (byte)Sprite.Flip.NONE);
            }
        }
Exemplo n.º 3
0
        private List <string> Disassemble(int length)
        {
            UInt16        tmpPC       = (UInt16)(_cpu.ProgramCounter - 1);
            List <string> disassembly = new List <string>();

            for (int i = 0; i < length; i++)
            {
                byte        opCode      = _cpuBus.Read(tmpPC++);
                Instruction instruction = InstructionSet.InstuctionsByOpcode[opCode];

                disassembly.Add(instruction.Name);

                if (instruction.AddressMode == AddressModes.ABS)
                {
                    tmpPC += 2;
                }
                if (instruction.AddressMode == AddressModes.ABX)
                {
                    tmpPC += 2;
                }
                if (instruction.AddressMode == AddressModes.ABY)
                {
                    tmpPC += 2;
                }
                if (instruction.AddressMode == AddressModes.IMM)
                {
                    tmpPC += 1;
                }
                if (instruction.AddressMode == AddressModes.IMP)
                {
                    tmpPC += 0;
                }
                if (instruction.AddressMode == AddressModes.IND)
                {
                    tmpPC += 2;
                }
                if (instruction.AddressMode == AddressModes.IZX)
                {
                    tmpPC += 1;
                }
                if (instruction.AddressMode == AddressModes.IZY)
                {
                    tmpPC += 1;
                }
                if (instruction.AddressMode == AddressModes.REL)
                {
                    tmpPC += 1;
                }
                if (instruction.AddressMode == AddressModes.ZP0)
                {
                    tmpPC += 1;
                }
                if (instruction.AddressMode == AddressModes.ZPX)
                {
                    tmpPC += 1;
                }
                if (instruction.AddressMode == AddressModes.ZPY)
                {
                    tmpPC += 1;
                }
            }

            return(disassembly);
        }