Exemplo n.º 1
0
        public Bitmap GetBitmap(NESPalette nesPalette, PaletteSelection paletteSelection, ChrTable chrTable, bool chr8x16)
        {
            Bitmap   bm = new Bitmap(128, 128);
            Graphics g  = Graphics.FromImage(bm);

            g.Clear(nesPalette[paletteSelection[0][0]]);

            for (int i = this.Count - 1; i >= 0; i--)
            {
                OamEntry o = this[i];

                Bitmap b = chrTable.GetBitmap(o.Char, paletteSelection[o.GetPaletteIndex()], nesPalette, chr8x16);
                if (o.VerticalIsFlipped())
                {
                    b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }
                if (o.HorizontalIsFlipped())
                {
                    b.RotateFlip(RotateFlipType.RotateNoneFlipX);
                }

                g.DrawImage(b, o.X, o.Y);
            }

            return(bm);
        }
Exemplo n.º 2
0
        public Bitmap GetBitmap(int chrIndex, int[] currPalette, NESPalette nesPalette, bool chr8x16)
        {
            int sizeX = 8;
            int sizeY = 8;

            if (chr8x16)
            {
                // TODO: find out if chrIndex is even or odd. That will determine which pattern table will be used.
                int temp_int = chrIndex / 2 * 2;
                if (chrIndex > temp_int)
                {
                    // odd number. switch pattern table
                    // how?
                    chrIndex += 256;
                }
                chrIndex = chrIndex / 2 * 2;
                sizeY    = 16;
            }

            Bitmap tileBitmap = new Bitmap(sizeX, sizeY);

            for (int y = 0; y < 8; y++)  // loop through 8 rows
            {
                // read bits of tiles[i][y] and tiles[i][y+8]

                for (int x = 0; x < 8; x++)
                {
                    // read bit x of tiles[i][y] and tiles[i][y+8]
                    //System.Collections.BitArray bitsA = new System.Collections.BitArray()

                    System.Collections.BitArray bitsA = new System.Collections.BitArray(this[chrIndex][y]);
                    System.Collections.BitArray bitsB = new System.Collections.BitArray(this[chrIndex][y + 8]);

                    int endResult = 0;



                    var bit0 = (this[chrIndex][y] & (1 << ((x * -1) + 8) - 1)) != 0;
                    var bit1 = (this[chrIndex][y + 8] & (1 << ((x * -1) + 8) - 1)) != 0;


                    if (bit0 == true)
                    {
                        endResult += 1;
                    }

                    if (bit1 == true)
                    {
                        endResult += 2;
                    }

                    Color c = nesPalette[currPalette[endResult]];
                    if (endResult == 0)
                    {
                        c = Color.FromArgb(0, c);
                    }


                    tileBitmap.SetPixel(x, y, c);
                }
            }

            if (chr8x16)
            {
                chrIndex++;

                for (int y = 0; y < 8; y++)  // loop through 8 rows
                {
                    // read bits of tiles[i][y] and tiles[i][y+8]

                    for (int x = 0; x < 8; x++)
                    {
                        // read bit x of tiles[i][y] and tiles[i][y+8]
                        //System.Collections.BitArray bitsA = new System.Collections.BitArray()

                        System.Collections.BitArray bitsA = new System.Collections.BitArray(this[chrIndex][y]);
                        System.Collections.BitArray bitsB = new System.Collections.BitArray(this[chrIndex][y + 8]);

                        int endResult = 0;



                        var bit0 = (this[chrIndex][y] & (1 << ((x * -1) + 8) - 1)) != 0;
                        var bit1 = (this[chrIndex][y + 8] & (1 << ((x * -1) + 8) - 1)) != 0;


                        if (bit0 == true)
                        {
                            endResult += 1;
                        }

                        if (bit1 == true)
                        {
                            endResult += 2;
                        }

                        Color c = nesPalette[currPalette[endResult]];
                        if (endResult == 0)
                        {
                            c = Color.FromArgb(0, c);
                        }


                        tileBitmap.SetPixel(x, y + 8, c);
                    }
                }
            }

            return(tileBitmap);
        }