Exemple #1
0
 private void SpriteRefreshMenuItem_Click(object sender, EventArgs e)
 {
     SpriteView.Refresh();
 }
Exemple #2
0
        private unsafe void Generate(bool now = false)
        {
            if (!IsHandleCreated || IsDisposed)
            {
                return;
            }

            if (Global.Emulator.Frame % RefreshRate.Value == 0 || now)
            {
                int  b0;
                int  b1;
                byte value;
                int  cvalue;

                if (CheckChange())
                {
                    _forceChange = false;

                    // Pattern Viewer
                    for (var i = 0; i < 16; i++)
                    {
                        PaletteView.BgPalettesPrev[i].Value     = PaletteView.BgPalettes[i].Value;
                        PaletteView.SpritePalettesPrev[i].Value = PaletteView.SpritePalettes[i].Value;
                        PaletteView.BgPalettes[i].Value         = _nes.LookupColor(_nes.ppu.PALRAM[PaletteView.BgPalettes[i].Address]);
                        PaletteView.SpritePalettes[i].Value     = _nes.LookupColor(_nes.ppu.PALRAM[PaletteView.SpritePalettes[i].Address]);
                    }

                    if (PaletteView.HasChanged())
                    {
                        PaletteView.Refresh();
                    }

                    DrawPatternView(PatternView, _ppuBus);
                }

                var bmpdata2  = SpriteView.sprites.LockBits(new Rectangle(new Point(0, 0), SpriteView.sprites.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                var framebuf2 = (int *)bmpdata2.Scan0.ToPointer();

                int  pt_add = _nes.ppu.reg_2000.obj_pattern_hi ? 0x1000 : 0;
                bool is8x16 = _nes.ppu.reg_2000.obj_size_16;


                // Sprite Viewer
                for (int n = 0; n < 4; n++)
                {
                    for (int r = 0; r < 16; r++)
                    {
                        int BaseAddr = (r << 2) + (n << 6);
                        int TileNum  = _nes.ppu.OAM[BaseAddr + 1];
                        int patternAddr;

                        if (is8x16)
                        {
                            patternAddr  = (TileNum >> 1) * 0x20;
                            patternAddr += 0x1000 * (TileNum & 1);
                        }
                        else
                        {
                            patternAddr  = TileNum * 0x10;
                            patternAddr += pt_add;
                        }

                        int Attributes = _nes.ppu.OAM[BaseAddr + 2];
                        int Palette    = Attributes & 0x03;

                        for (int x = 0; x < 8; x++)
                        {
                            for (int y = 0; y < 8; y++)
                            {
                                int address = patternAddr + y;
                                b0     = (byte)((_ppuBus[address] >> (7 - x)) & 1);
                                b1     = (byte)((_ppuBus[address + 8] >> (7 - x)) & 1);
                                value  = (byte)(b0 + (b1 << 1));
                                cvalue = _nes.LookupColor(_nes.ppu.PALRAM[16 + value + (Palette << 2)]);

                                int adr = (x + (r * 16)) + (y + (n * 24)) * (bmpdata2.Stride >> 2);
                                framebuf2[adr] = cvalue;
                            }

                            if (is8x16)
                            {
                                patternAddr += 0x10;
                                for (int y = 0; y < 8; y++)
                                {
                                    int address = patternAddr + y;
                                    b0     = (byte)((_ppuBus[address] >> (7 - x)) & 1);
                                    b1     = (byte)((_ppuBus[address + 8] >> (7 - x)) & 1);
                                    value  = (byte)(b0 + (b1 << 1));
                                    cvalue = _nes.LookupColor(_nes.ppu.PALRAM[16 + value + (Palette << 2)]);

                                    int adr = (x + (r << 4)) + ((y + 8) + (n * 24)) * (bmpdata2.Stride >> 2);
                                    framebuf2[adr] = cvalue;
                                }

                                patternAddr -= 0x10;
                            }
                        }
                    }
                }

                SpriteView.sprites.UnlockBits(bmpdata2);
                SpriteView.Refresh();

                HandleSpriteViewMouseMove(SpriteView.PointToClient(MousePosition));
                HandlePaletteViewMouseMove(PaletteView.PointToClient(MousePosition));
            }
        }