Exemple #1
0
    static bool TryParseProgram(Tokens tokens, out FxProgram program)
    {
        program = new FxProgram();
        var tokensCopy = tokens;

        while (!tokensCopy.IsEmpty)
        {
            if (TryParseFunction(ref tokensCopy, program, out FxFunction function))
            {
                program.Functions.Add(function);
            }
Exemple #2
0
        public void Generate(string directory, FxProgram program)
        {
            _program   = program;
            _directory = directory;
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            using (TextWriter writer = new StreamWriter(Path.Combine(directory, "main.c"))) {
                writer.WriteLine(@"#include <stdio.h>");
                writer.WriteLine();


                foreach (var type in program.Types)
                {
                    throw new NotImplementedException();
                }

                foreach (var function in program.Functions)
                {
                    Generate(writer, function);
                }
            }

            var    clInfo        = new ProcessStartInfo();
            string crt           = @"""c:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\ucrt""";
            string windowsShared = @"""c:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared""";
            string windowsOther  = @"""c:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um""";
            string vsInclude     = @"""c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include""";

            clInfo.FileName               = "cl.exe";
            clInfo.Arguments              = $" -c /MT /Gz /I {crt} /I {windowsShared} /I {windowsOther} /I {vsInclude} main.c";
            clInfo.CreateNoWindow         = true;
            clInfo.WorkingDirectory       = directory;
            clInfo.RedirectStandardOutput = true;
            clInfo.UseShellExecute        = false;

            Console.WriteLine($"{clInfo.FileName} {clInfo.Arguments}");
            var clProcess = Process.Start(clInfo);

            Console.Out.Write(clProcess.StandardOutput.ReadToEnd());
            clProcess.WaitForExit();

            string crtLibs = @"""c:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\ucrt\x86""";
            string vsLibs  = @"""c:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\lib""";
            string osLibs  = @"""c:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x86""";
            // /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\um\x86"
            var linkInfo = new ProcessStartInfo();

            linkInfo.FileName               = "link.exe";
            linkInfo.Arguments              = $" /SUBSYSTEM:console main.obj /LIBPATH:{crtLibs} /LIBPATH:{vsLibs} /LIBPATH:{osLibs}";
            linkInfo.CreateNoWindow         = true;
            linkInfo.WorkingDirectory       = directory;
            linkInfo.RedirectStandardOutput = true;
            linkInfo.UseShellExecute        = false;

            Console.WriteLine($"{linkInfo.FileName} {linkInfo.Arguments}");
            var linkProcess = Process.Start(linkInfo);

            Console.Out.Write(clProcess.StandardOutput.ReadToEnd());
            clProcess.WaitForExit();
        }
Exemple #3
0
        private static FXP ReadFXP(BinaryFile bf)
        {
            string ChunkMagic = bf.ReadString(4);

            if (ChunkMagic != "CcnK")
            {
                throw new FormatException(string.Format("Error reading file. Missing preset header information {0}", ChunkMagic));
            }

            var    fxp      = new FXP();
            int    ByteSize = bf.ReadInt32();
            string FxMagic  = bf.ReadString(4);

            if (FxMagic == "FBCh")
            {
                // Bank (.fxb) with chunk (magic = 'FBCh')
                var chunkSet = new FxChunkSet();
                chunkSet.ChunkMagic = ChunkMagic;
                chunkSet.ByteSize   = ByteSize;
                chunkSet.FxMagic    = FxMagic;

                chunkSet.Version   = bf.ReadInt32();
                chunkSet.FxID      = bf.ReadString(4);
                chunkSet.FxVersion = bf.ReadInt32();

                chunkSet.NumPrograms = bf.ReadInt32();
                chunkSet.Future      = bf.ReadString(128).TrimEnd('\0');
                chunkSet.ChunkSize   = bf.ReadInt32();

                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                chunkSet.ChunkData = bf.ReadBytes(0, chunkSet.ChunkSize, BinaryFile.ByteOrder.LittleEndian);

                // read the xml chunk into memory
                try
                {
                    if (chunkSet.ChunkData != null)
                    {
                        var xmlDocument   = new XmlDocument();
                        var chunkAsString = Encoding.UTF8.GetString(chunkSet.ChunkData);
                        xmlDocument.LoadXml(chunkAsString);
                        fxp.XmlDocument = xmlDocument;
                    }
                }
                catch (XmlException)
                {
                }

                fxp.Content = chunkSet;
            }
            else if (FxMagic == "FPCh")
            {
                // Preset (Program) (.fxp) with chunk (magic = 'FPCh')
                var programSet = new FxProgramSet();
                programSet.ChunkMagic = ChunkMagic;
                programSet.ByteSize   = ByteSize;
                programSet.FxMagic    = FxMagic;

                programSet.Version   = bf.ReadInt32();
                programSet.FxID      = bf.ReadString(4);
                programSet.FxVersion = bf.ReadInt32();

                programSet.NumPrograms = bf.ReadInt32();
                programSet.Name        = bf.ReadString(28).TrimEnd('\0');
                programSet.ChunkSize   = bf.ReadInt32();

                // Even though the main FXP is BigEndian format the preset chunk is saved in LittleEndian format
                programSet.ChunkData = bf.ReadBytes(0, programSet.ChunkSize, BinaryFile.ByteOrder.LittleEndian);

                // read the xml chunk into memory
                try
                {
                    if (programSet.ChunkData != null)
                    {
                        var xmlDocument   = new XmlDocument();
                        var chunkAsString = Encoding.UTF8.GetString(programSet.ChunkData);
                        xmlDocument.LoadXml(chunkAsString);
                        fxp.XmlDocument = xmlDocument;
                    }
                }
                catch (XmlException)
                {
                }

                fxp.Content = programSet;
            }
            else if (FxMagic == "FxCk")
            {
                // For Preset (Program) (.fxp) without chunk (magic = 'FxCk')
                var program = new FxProgram();
                program.ChunkMagic = ChunkMagic;
                program.ByteSize   = ByteSize;
                program.FxMagic    = FxMagic;

                program.Version   = bf.ReadInt32();
                program.FxID      = bf.ReadString(4);
                program.FxVersion = bf.ReadInt32();

                program.NumParameters = bf.ReadInt32();
                program.ProgramName   = bf.ReadString(28).TrimEnd('\0');

                // variable no. of parameters
                program.Parameters = new float[program.NumParameters];
                for (int i = 0; i < program.NumParameters; i++)
                {
                    program.Parameters[i] = bf.ReadSingle();
                }

                fxp.Content = program;
            }
            else if (FxMagic == "FxBk")
            {
                // For bank (.fxb) without chunk (magic = 'FxBk')
                var set = new FxSet();
                set.ChunkMagic = ChunkMagic;
                set.ByteSize   = ByteSize;
                set.FxMagic    = FxMagic;

                set.Version   = bf.ReadInt32();
                set.FxID      = bf.ReadString(4);
                set.FxVersion = bf.ReadInt32();

                set.NumPrograms = bf.ReadInt32();
                set.Future      = bf.ReadString(128).TrimEnd('\0');

                // variable no. of programs
                set.Programs = new FxProgram[set.NumPrograms];
                for (int p = 0; p < set.NumPrograms; p++)
                {
                    var content = ReadFXP(bf).Content;
                    if (content is FxProgram)
                    {
                        set.Programs[p] = (FxProgram)content;
                    }
                }

                fxp.Content = set;
            }

            return(fxp);
        }