Exemplo n.º 1
0
        public void LoadBlockIntoTMem(F3DZEX_G_LoadBlock loadBlock)
        {
            RomFile file;
            int offset;
            TileDescriptor tile = TileDescriptors[loadBlock.Tile];

            if (RomProject.Instance.FindRamOffset(LastTImgCommand.ImageAddress, out file, out offset))
            {
                if (file.GetElementAt(offset) is Palette)
                {
                    Palette palette = (Palette)file.GetElementAt(offset);
                    LoadedElements[tile.TMem] = palette;
                }
                else if (file.GetElementAt(offset) is Texture)
                {
                    Texture texture = (Texture)file.GetElementAt(offset);
                    LoadedElements[tile.TMem] = texture;
                }
                else
                {
                    byte[] data = file.GetAsBytes();

                    double texelSizeInBytes = 1;
                    switch (tile.PixelSize)
                    {
                        case Texture.PixelInfo.Size_4b:
                            texelSizeInBytes = 0.5;
                            break;
                        case Texture.PixelInfo.Size_16b:
                            texelSizeInBytes = 2;
                            break;
                        case Texture.PixelInfo.Size_32b:
                            texelSizeInBytes = 4;
                            break;
                    }

                    int size = (int)Math.Round(loadBlock.Texels * texelSizeInBytes);
                    byte[] newData = new byte[size];

                    Array.Copy(data, offset, newData, 0, size);
                    Array.Copy(newData, 0, this.Data, tile.TMemInBytes, size);

                    LoadedData[tile.TMem] = new LoadedTMemData(file,
                        offset, size, newData);
                }
            }
        }
Exemplo n.º 2
0
        private static void ResetReaderVariables()
        {
            _foundCommands.Clear();
            _foundPalettes.Clear();
            _foundTextures.Clear();
            _foundVertices.Clear();

            _currentTexture = null;
            
            _vertexBuffer.Clear();
            for (int i = 0; i < 32; i++)
                _vertexBuffer.Add(null);
            
            TMEM = new TMem();

            DefaultTextureTile = 0;
            
            _lastSetTile = null;
            _lastSetTImg = null;
            _lastSetTileSize = null;
            _lastLoadBlock = null;
            _lastLoadTLut = null;
        }
Exemplo n.º 3
0
        private static void ParseCommand(F3DZEXCommand command)
        {
            TileDescriptor tile;
            //Here handle extra command things (like if it's referencing textures and such)
            switch (command.CommandID)
            {
                case F3DZEXCommandID.F3DZEX_G_TEXTURE:
                    F3DZEX_G_Texture textureCmd = (F3DZEX_G_Texture)command;
                    tile = TMEM.TileDescriptors[textureCmd.Tile];
                    tile.On = (textureCmd.TurnOn & 1) == 0;
                    tile.ScaleS = textureCmd.ScaleS;
                    tile.ScaleT = textureCmd.ScaleT;
                    tile.Level = textureCmd.Level;

                    break;
                case F3DZEXCommandID.F3DZEX_G_SETTILE:
                    _lastSetTile = (F3DZEX_G_SetTile)command;

                    tile = TMEM.TileDescriptors[_lastSetTile.Tile];
                    tile.CMSMirror = _lastSetTile.CMSMirror;
                    tile.CMTMirror = _lastSetTile.CMTMirror;
                    tile.CMSWrap = _lastSetTile.CMSWrap;
                    tile.CMTWrap = _lastSetTile.CMTWrap;
                    tile.ImageFormat = _lastSetTile.Format;
                    tile.Line = _lastSetTile.Line;
                    tile.MaskS = _lastSetTile.MaskS;
                    tile.MaskT = _lastSetTile.MaskT;
                    tile.Palette = _lastSetTile.Palette;
                    tile.PixelSize = _lastSetTile.PixelSize;
                    tile.ShiftS = _lastSetTile.ShiftS;
                    tile.ShiftT = _lastSetTile.ShiftT;
                    tile.TMem = _lastSetTile.TMem;

                    break;
                case F3DZEXCommandID.F3DZEX_G_SETTILESIZE:
                    _lastSetTileSize = (F3DZEX_G_SetTileSize)command;

                    tile = TMEM.TileDescriptors[_lastSetTileSize.Tile];
                    tile.LRS = _lastSetTileSize.LRS;
                    tile.LRT = _lastSetTileSize.LRT;
                    tile.ULS = _lastSetTileSize.ULS;
                    tile.ULT = _lastSetTileSize.ULT;

                    break;
                case F3DZEXCommandID.F3DZEX_G_SETTIMG:
                    _lastSetTImg = (F3DZEX_G_SetTImg)command;
                    TMEM.LastTImgCommand = _lastSetTImg;
                    //TMEM.RAMTexturePixelSize = _lastSetTImg.PixelSize;
                    //TMEM.RAMTextureAddress = _lastSetTImg.ImageAddress;
                    //TMEM.RAMTextureImageFormat = _lastSetTImg.Format;
                    //TMEM.RAMTextureWidth = _lastSetTImg.Width;

                    break;
                case F3DZEXCommandID.F3DZEX_G_LOADBLOCK:
                    _lastLoadBlock = (F3DZEX_G_LoadBlock)command;

                    TMEM.LoadBlockIntoTMem(_lastLoadBlock);
                    break;
                case F3DZEXCommandID.F3DZEX_G_LOADTLUT:
                    _lastLoadTLut = (F3DZEX_G_LoadTLut)command;

                    TMEM.LoadTLutIntoTMem(_lastLoadTLut);
                    break;
                case F3DZEXCommandID.F3DZEX_G_VTX:
                    F3DZEX_G_Vtx vtx = (F3DZEX_G_Vtx)command;

                    RomFile file;
                    int offset;
                    if(RomProject.Instance.FindRamOffset(vtx.VertexSourceAddress, out file, out offset))
                    {
                        if (file.GetElementAt(offset) is VertexCollection)
                        {
                            //Just update the reference buffer
                            VertexCollection collection = (VertexCollection)file.GetElementAt(offset);

                            if(vtx.VertexCount > 0)
                            {
                                int startIndex = 0;
                                bool foundVertices = false;
                                for (int i = 0; i < collection.Vertices.Count; i++)
                                {
                                    if (collection.Vertices[i].FileOffset == offset)
                                    {
                                        startIndex = i;
                                        foundVertices = true;
                                    }

                                    if (foundVertices)
                                    {
                                        _vertexBuffer[vtx.TargetBufferIndex + (i - startIndex)] = collection.Vertices[i];
                                        if (i - startIndex + 1 >= vtx.VertexCount)
                                            break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            //Actually load in the bytes as new Vertices
                            byte[] bytes = file.GetAsBytes();

                            byte[] vtxBytes = new byte[0x10];

                            List<Vertex> vertices = new List<Vertex>();

                            for (int i = 0; i < vtx.VertexCount; i++)
                            {
                                Array.Copy(bytes, offset, vtxBytes, 0, 0x10);
                                Vertex vertex = new Vertex(offset, vtxBytes);
                                //Add to collection somewhere
                                vertices.Add(vertex);

                                offset += 0x10;

                                _vertexBuffer[i + vtx.TargetBufferIndex] = vertex;
                            }

                            if (!_foundVertices.ContainsKey(file))
                                _foundVertices.Add(file, new List<Vertex>());

                            _foundVertices[file].AddRange(vertices);
                        }
                    }
                    break;
                case F3DZEXCommandID.F3DZEX_G_TRI1:
                case F3DZEXCommandID.F3DZEX_G_TRI2:
                    if (TMEM.TileDescriptors[DefaultTextureTile].SettingsChanged)
                    {
                        //Try seeing if the texture has been loaded before
                        if (!TryLoadExistingTexture(TMEM.TileDescriptors[DefaultTextureTile], out _currentTexture) &&
                            TMEM.LoadedData.ContainsKey(TMEM.TileDescriptors[DefaultTextureTile].TMem))
                        {
                            LoadedTMemData tmemInfo = TMEM.LoadedData[TMEM.TileDescriptors[DefaultTextureTile].TMem];

                            //First try loading up the palette
                            Palette palette = null;
                            if (!TryLoadExistingPalette(out palette) &&
                                TMEM.LoadedData.ContainsKey(PALETTE_TMEM_OFFSET))
                            {
                                palette = ReadPaletteFromTMem();

                                if (palette != null)
                                {
                                    tmemInfo = TMEM.LoadedData[PALETTE_TMEM_OFFSET];

                                    if (!_foundPalettes.ContainsKey(tmemInfo.SourceFile))
                                        _foundPalettes.Add(tmemInfo.SourceFile, new List<Palette>());

                                    _foundPalettes[tmemInfo.SourceFile].Add(palette);
                                }
                            }

                            //Load up new Texture
                            _currentTexture = ReadTextureFromTMem(TMEM.TileDescriptors[DefaultTextureTile], palette);

                            if (_currentTexture != null)
                            {
                                //Store in the found variables
                                if (!_foundTextures.ContainsKey(tmemInfo.SourceFile))
                                    _foundTextures.Add(tmemInfo.SourceFile, new List<Texture>());

                                _foundTextures[tmemInfo.SourceFile].Add(_currentTexture);

                            }
                        }
                        TMEM.TileDescriptors[0].SettingsChanged = false;
                    }
                    if (command.CommandID == F3DZEXCommandID.F3DZEX_G_TRI1)
                    {
                        F3DZEX_G_Tri1 tri = (F3DZEX_G_Tri1)command;
                        tri.TextureReference = _currentTexture;

                        tri.Vertex1Reference = _vertexBuffer[tri.Vertex1];
                        tri.Vertex2Reference = _vertexBuffer[tri.Vertex2];
                        tri.Vertex3Reference = _vertexBuffer[tri.Vertex3];
                    }
                    else if (command.CommandID == F3DZEXCommandID.F3DZEX_G_TRI2)
                    {
                        F3DZEX_G_Tri2 tri = (F3DZEX_G_Tri2)command;
                        tri.TextureReference = _currentTexture;


                        tri.Vertex1Reference = _vertexBuffer[tri.Vertex1];
                        tri.Vertex2Reference = _vertexBuffer[tri.Vertex2];
                        tri.Vertex3Reference = _vertexBuffer[tri.Vertex3];
                        tri.Vertex4Reference = _vertexBuffer[tri.Vertex4];
                        tri.Vertex5Reference = _vertexBuffer[tri.Vertex5];
                        tri.Vertex6Reference = _vertexBuffer[tri.Vertex6];

                    }

                    break;
            }
        }
Exemplo n.º 4
0
        public void TestF3DZEX_G_LoadBlock()
        {
            //F3123456 029ABCDE
            byte[] testVal = new byte[] { 0xF3, 0x12, 0x34, 0x56, 0x02, 0x9A, 0xBC, 0xDE };

            F3DZEX_G_LoadBlock cmd = new F3DZEX_G_LoadBlock(0, testVal);

            byte[] outVal = cmd.RawData;

            Assert.AreEqual(testVal.Length, outVal.Length);
            Assert.IsTrue(Enumerable.SequenceEqual(testVal, outVal));

            //F3123456 F29ABCDE
            testVal = new byte[] { 0xF3, 0x12, 0x34, 0x56, 0xF2, 0x9A, 0xBC, 0xDE };

            cmd.RawData = testVal;

            byte[] outVal2 = cmd.RawData;

            Assert.AreEqual(outVal.Length, outVal2.Length);
            Assert.IsTrue(Enumerable.SequenceEqual(outVal, outVal2));
        }