Example #1
0
        public void SavePalette()
        {
            if (mainentry > 0xFF && mainentry < 0x26C)
            {
                int palBank;

                // Compute palBank
                palBank = mainentry - 0xFF;

                // Compute palSubBank
                rom.Seek(ROMInfo.palInfoAddress + (mainentry * 12));

                // Compute palAddress
                palAddress = ROMInfo.palStartAddress + rom.ReadWord(
                    ROMInfo.palStartAddress + 4 + (palBank << 2));
            }
            else
            {
                palAddress = ROMInfo.palStartAddress + rom.ReadWord(
                    ROMInfo.palStartAddress + 4) + (palSubBank * 32);
            }

            // Write the colours
            rom.Seek(palAddress);
            for (int i = 0; i < 16; i++)
            {
                rom.WriteColor(_pal[i]);
            }
        }
        public byte[,] GetTile(int tileNum)
        {
            // Check if it's already in the cache
            if (tileCache.ContainsKey(tileNum))
            {
                return(tileCache[tileNum]);
            }

            byte[,] pixels = new byte[8, 8];
            //counter++;

            // Get the address of the tile
            int address = startPointer + (tileNum << 5);

            // Parse the tile
            byte tmp = 0;

            rom.Seek(address);
            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x += 2)
                {
                    tmp              = (byte)rom.ReadByte();
                    pixels[y, x]     = (byte)(tmp & 0xF);
                    pixels[y, x + 1] = (byte)((tmp >> 4) & 0xF);
                }
            }

            tileCache.Add(tileNum, pixels);
            return(pixels);
        }
            public void SaveProperties()
            {
                romFile.Seek(romAddress);
                romFile.WriteByte((byte)OffsetY);
                romFile.WriteByte((byte)OffsetX);
                int tmp = (Tile & 0x3FF);

                tmp |= (FlipX ? 1 << 10 : 0);
                tmp |= (FlipY ? 1 << 11 : 0);
                tmp |= ((Size & 3) << 12);
                tmp |= ((Shape & 3) << 14);
                romFile.WriteByte((byte)(tmp & 0xFF));
                romFile.WriteByte((byte)((tmp >> 8) & 0xFF));
            }
Example #4
0
        public Palette(ROMHandler romFile, int bank, int mainEntry, Color?transparentColor)
        {
            // Bank is irrelevant? Requires ROM research; check if the
            // [0x100, 0x26B] custom range is applicable beyond bank 0

            int palBank;

            //int palAddress;
            rom       = romFile;
            mainentry = mainEntry;

            // Compute palBank
            palBank = ((mainEntry > 0xFF) && (mainEntry < 0x26C)) ? mainEntry - 0xFF : 0;

            // Compute palSubBank
            rom.Seek(ROMInfo.palInfoAddress + (mainEntry * 12));
            palSubBank = ((mainEntry > 0xFF) && (mainEntry < 0x26C)) ? 0 : (romFile.ReadByte() & 0xF);

            // Compute palAddress
            palAddress = ROMInfo.palStartAddress + rom.ReadWord(
                ROMInfo.palStartAddress + 4 + (palBank * 4)) +
                         (palSubBank * 32);

            // Parse the palette data
            rom.Seek(palAddress);
            for (int i = 0; i < 16; i++)
            {
                if (i == 0 && transparentColor != null)
                {
                    _pal[i] = (Color)transparentColor;
                }
                else
                {
                    _pal[i] = rom.ReadColor();
                }
            }
        }
        public Sprite(ROMHandler ROMFile, int Bank, int MainEntry, int SpriteEntry)
        {
            int infoAddress;
            int entryCounter = 0;

            romFile     = ROMFile;
            bank        = Bank;
            mainEntry   = MainEntry;
            spriteEntry = SpriteEntry;

            // Instantiate the tileset and palette
            tSet = new Tileset(romFile, bank, mainEntry);
            pal  = new Palette(romFile, bank, mainEntry);

            // Parse the sub sprite information
            infoAddress = ROMInfo.sprStartAddress[bank] + romFile.ReadWord(
                ROMInfo.sprStartAddress[bank] + 4 + (mainEntry * 4)) +
                          8;
            NumSprites   = romFile.ReadHWord(infoAddress);
            infoAddress += 2;

            while (spriteEntry > entryCounter)
            {
                infoAddress += (romFile.ReadHWord(infoAddress) + 1) * 4;
                entryCounter++;
            }

            romFile.Seek(infoAddress);
            NumSubSprites = romFile.ReadHWord();
            SubSprite retVal;

            subSprites = new List <SubSprite>();
            int tmp;

            for (int i = 0; i < NumSubSprites; i++)
            {
                retVal            = new SubSprite();
                retVal.romAddress = (int)romFile.Address;
                retVal.romFile    = romFile;

                retVal.OffsetY = romFile.ReadByte();
                retVal.OffsetX = romFile.ReadByte();
                if (retVal.OffsetY >= 0x80)
                {
                    retVal.OffsetY -= 0x100;                         // Sign the offsets
                }
                if (retVal.OffsetX >= 0x80)
                {
                    retVal.OffsetX -= 0x100;
                }
                tmp           = romFile.ReadHWord();
                retVal.Tile   = (tmp & 0x3FF);
                retVal.FlipX  = (((tmp >> 10) & 1) == 1);
                retVal.FlipY  = (((tmp >> 11) & 1) == 1);
                retVal.Width  = sprWidthConst[(tmp >> 14) & 3, (tmp >> 12) & 3];
                retVal.Height = sprHeightConst[(tmp >> 14) & 3, (tmp >> 12) & 3];
                retVal.Size   = (tmp >> 12) & 3;
                retVal.Shape  = (tmp >> 14) & 3;

                retVal.tileSet = tSet;
                retVal.pal     = pal;

                subSprites.Add(retVal);
            }
        }