Ejemplo n.º 1
0
 public Nametable(ChrMapper mapper)
 {
     this.bitmap  = new PaletteBitmap(screenWidth * 8u, screenHeight * 8u);
     this.mapper  = mapper;
     this.ppuAddr = 0x0000;
     this.SetDirection(AccessDirection.Horizontal);
     bitmap.AddColor(0x00000000);                                // Transparent
 }
Ejemplo n.º 2
0
 private void GenerateTile(PaletteBitmap bitmap, ChrMapper mapper, uint row, uint col, byte tile)
 {
     for (uint tileY = 0; tileY < 8; tileY++)
     {
         uint drawY = (uint)(row * 8 + tileY);
         for (uint tileX = 0; tileX < 8; tileX++)
         {
             uint drawX = col * 8 + tileX;
             byte color = mapper.GetPixel(tile, tileX, tileY);
             bitmap.SetPixel(drawX, drawY, (byte)(color + 1));
         }
     }
 }
Ejemplo n.º 3
0
        private IVisualization2d GenerateBitmap(ReadOnlyDictionary <string, object> parms)
        {
            int  offset      = Util.GetFromObjDict(parms, P_OFFSET, 0);
            int  width       = Util.GetFromObjDict(parms, P_WIDTH, 1);
            int  height      = Util.GetFromObjDict(parms, P_HEIGHT, 1);
            bool showInvalid = Util.GetFromObjDict(parms, P_SHOWINVALID, false);

            // Check parameters.
            int lastAddress = offset + width * height - 1;

            if ((offset < 0) || (lastAddress >= this.mFileData.Length))
            {
                this.mAppRef.ReportError("Invalid parameter");
                return(null);
            }

            // Set palette.
            PaletteBitmap bitmap = new PaletteBitmap((uint)width, (uint)height);

            bitmap.AddColor(0x00000000);                                        // Transparent
            for (int i = 0; i < NesPalette.Length; i++)
            {
                UInt32 color = 0xFF000000U | (UInt32)NesPalette[i];
                bitmap.AddColor((int)color);                    // Palette color (1 shift)
            }

            // Convert to pixels.
            for (uint y = 0; y < (uint)height; y++)
            {
                for (uint x = 0; x < (uint)width; x++)
                {
                    uint index = y * (uint)width + x;

                    byte palette = this.mFileData[offset + index];
                    if (!showInvalid & ((int)palette > NesPalette.Length))
                    {
                        // Transparent invalid color.
                        bitmap.SetPixel(x, y, 0);
                        continue;
                    }

                    palette = (byte)((palette % NesPalette.Length) + 1);
                    bitmap.SetPixel(x, y, palette);
                }
            }

            return(bitmap.Bitmap);
        }
Ejemplo n.º 4
0
        private void GenerateTile(PaletteBitmap bitmap, int width, int row, int col, int offset)
        {
            int baseAddr = offset + (row * width + col) * 16;

            for (int tileY = 0; tileY < 8; tileY++)
            {
                uint drawY = (uint)(row * 8 + tileY);
                byte high  = this.mFileData[baseAddr + tileY + 8];
                byte low   = this.mFileData[baseAddr + tileY];
                for (int tileX = 0; tileX < 8; tileX++)
                {
                    uint drawX   = (uint)(col * 8 + tileX);
                    int  shift   = 7 - tileX;
                    int  highBit = ((high >> shift) & 0x01) << 1;
                    int  lowBit  = ((low >> shift) & 0x01);
                    int  pColor  = highBit | lowBit;
                    bitmap.SetPixel(drawX, drawY, (byte)(pColor + 1));
                }
            }
        }
Ejemplo n.º 5
0
        private IVisualization2d GenerateBitmap(ReadOnlyDictionary <string, object> parms)
        {
            int offset   = Util.GetFromObjDict(parms, P_OFFSET, 0);
            int width    = Util.GetFromObjDict(parms, P_WIDTH, 1);
            int height   = Util.GetFromObjDict(parms, P_HEIGHT, 1);
            int palette1 = Util.GetFromObjDict(parms, P_PALETTE1, 0x0F);
            int palette2 = Util.GetFromObjDict(parms, P_PALETTE2, 0x00);
            int palette3 = Util.GetFromObjDict(parms, P_PALETTE3, 0x10);
            int palette4 = Util.GetFromObjDict(parms, P_PALETTE4, 0x30);

            int[] palette = new int[4] {
                palette1, palette2, palette3, palette4
            };

            // Check parameters.
            int lastAddress = offset + width * height * 16 - 1;

            if ((offset < 0) || (lastAddress >= this.mFileData.Length))
            {
                this.mAppRef.ReportError("Invalid parameter");
                return(null);
            }
            for (int i = 0; i < palette.Length; i++)
            {
                int color = palette[i];
                if (color >= NesPalette.Length)
                {
                    this.mAppRef.ReportError("Invalid parameter");
                    return(null);
                }
            }

            // Set palette.
            PaletteBitmap bitmap = new PaletteBitmap((uint)(width * 8), (uint)(height * 8));

            bitmap.AddColor(0x00000000);                                // Transparent
            for (int i = 0; i < palette.Length; i++)
            {
                int index = palette[i];
                if (index >= 0)
                {
                    UInt32 color = 0xFF000000U | (UInt32)NesPalette[index];
                    bitmap.AddColor((int)color);                        // ARGB
                }
                else
                {
                    bitmap.AddColor(0x00000000);                        // Transparent
                }
            }

            // Convert to pixels.
            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    this.GenerateTile(bitmap, width, row, col, offset);
                }
            }

            return(bitmap.Bitmap);
        }
Ejemplo n.º 6
0
        private IVisualization2d GenerateBitmap(ReadOnlyDictionary <string, object> parms)
        {
            int  tileoffset = Util.GetFromObjDict(parms, P_TILEOFFSET, 0);
            int  width      = Util.GetFromObjDict(parms, P_WIDTH, 1);
            int  height     = Util.GetFromObjDict(parms, P_HEIGHT, 1);
            int  chroffset  = Util.GetFromObjDict(parms, P_CHROFFSET, 0);
            int  chipoffset = Util.GetFromObjDict(parms, P_CHIPOFFSET, 0);
            int  chrbank1   = Util.GetFromObjDict(parms, P_CHRBANK1, 0);
            int  chrbank2   = Util.GetFromObjDict(parms, P_CHRBANK2, 1);
            int  chrbank3   = Util.GetFromObjDict(parms, P_CHRBANK3, 2);
            int  chrbank4   = Util.GetFromObjDict(parms, P_CHRBANK4, 3);
            int  palette1   = Util.GetFromObjDict(parms, P_PALETTE1, 0x0F);
            int  palette2   = Util.GetFromObjDict(parms, P_PALETTE2, 0x00);
            int  palette3   = Util.GetFromObjDict(parms, P_PALETTE3, 0x10);
            int  palette4   = Util.GetFromObjDict(parms, P_PALETTE4, 0x30);
            bool vertical   = Util.GetFromObjDict(parms, P_VERTICAL, false);

            int[] bank = new int[4] {
                chrbank1, chrbank2, chrbank3, chrbank4
            };
            int[] palette = new int[4] {
                palette1, palette2, palette3, palette4
            };
            ChrMapper mapper = null;

            // Check parameters.
            try{
                {                       // tile
                    int lastAddress = tileoffset + width * height - 1;
                    if ((tileoffset < 0) || (lastAddress >= this.mFileData.Length))
                    {
                        this.mAppRef.ReportError("Invalid parameter");
                        return(null);
                    }
                }
                {                                         // bank
                    int lastAddress = chroffset + 0x03FF; // chr = [0, 0, 0, 0] -> 0x1000 / 4 - 1 = 0x03FF
                    if ((chroffset < 0) || (lastAddress >= this.mFileData.Length))
                    {
                        this.mAppRef.ReportError("Invalid parameter");
                        return(null);
                    }
                }
                // palette
                for (int i = 0; i < palette.Length; i++)
                {
                    int color = palette[i];
                    if (color >= NesPalette.Length)
                    {
                        this.mAppRef.ReportError("Invalid parameter");
                        return(null);
                    }
                }
                // Copy CHR data.
                mapper = new ChrMapper(this.mFileData, chroffset, bank);
            }
            catch {
                this.mAppRef.ReportError("Invalid parameter");
                return(null);
            }

            // Set palette.
            PaletteBitmap bitmap = new PaletteBitmap((uint)(width * 8), (uint)(height * 8));

            bitmap.AddColor(0x00000000);                                // Transparent
            for (int i = 0; i < palette.Length; i++)
            {
                int index = palette[i];
                if (index >= 0)
                {
                    UInt32 color = 0xFF000000U | (UInt32)NesPalette[index];
                    bitmap.AddColor((int)color);                        // ARGB
                }
                else
                {
                    bitmap.AddColor(0x00000000);                        // Transparent
                }
            }

            // Convert to pixels.
            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    int address;
                    if (!vertical)
                    {
                        // Horizontal
                        address = tileoffset + (row * width) + col;
                    }
                    else
                    {
                        // Vertical
                        address = tileoffset + (col * height) + row;
                    }
                    byte tile = (byte)(this.mFileData[address] + chipoffset);
                    this.GenerateTile(bitmap, mapper, (uint)row, (uint)col, tile);
                }
            }

            return(bitmap.Bitmap);
        }