Exemple #1
0
        /// <summary>
        /// Writes out a cmd file with a 01 02 loadLo loadHi header
        /// </summary>
        /// <param name="fileName"></param>
        public static string BuildTRS80(Xml xproject)
        {
            string oldDir     = Environment.CurrentDirectory;
            string projName   = xproject.Project.ProjName;
            string outputName = xproject.Project.Output;
            string binFile    = outputName + ".cmd";

            try
            {
                string workingDirectory = projName + "_TRS80";

                Environment.CurrentDirectory = workingDirectory;
                Assembly asm = new Assembly("main.asm");
                asm.Assemble();

                //add the header to make it a .cmd file
                byte[] fileData = File.ReadAllBytes("main.bin");
                ushort loadAddr = 0x5200;

                BinaryWriter bw = new BinaryWriter(File.OpenWrite(binFile));

                try
                {
                    for (int i = 0; i < fileData.Length; i++)
                    {
                        if (i % 256 == 0)
                        {                         //write out a record header
                            bw.Write((byte)0x01); //record type
                            int remaining = fileData.Length - i;
                            if (remaining >= 256)
                            {
                                bw.Write((byte)0x02); //number of bytes to follow
                            }
                            else
                            {
                                bw.Write((byte)(remaining + 2)); //number of bytes to follow
                            }
                            bw.Write((byte)(loadAddr % 256));    //lo
                            bw.Write((byte)(loadAddr / 256));    //hi
                            loadAddr += 256;
                            bw.Flush();
                        }

                        bw.Write((byte)fileData[i]);
                    }
                    bw.Write((byte)2);
                    bw.Write((byte)2);
                    bw.Write((byte)0);
                    bw.Write((byte)(0x52));
                    bw.Flush();
                }
                catch (Exception ex1)
                {
                    Console.WriteLine("Huh?");
                }
                finally
                {
                    bw.Flush();
                    bw.Dispose();
                }
                MoveOutputFiles();

                return(binFile);
            }
            catch (Exception e)
            {
                throw new Exception("Couldn't assemble main.asm", e);
            }
            finally
            {
                Environment.CurrentDirectory = oldDir;
            }
        }
Exemple #2
0
        /// <summary>
        ///Assemble the files produced by the converter
        /// </summary>
        /// <param name="xmlFileName"></param>
        public static string BuildSpeccy(Xml xproject)
        {
            string oldDir = Environment.CurrentDirectory;

            try
            {
                string projName   = xproject.Project.ProjName;
                string outputName = xproject.Project.Output;

                Environment.CurrentDirectory = projName + "_Spectrum";

                try
                {
                    if (File.Exists("data"))
                    {
                        File.Delete("data");
                    }
                    if (File.Exists("game.tap"))
                    {
                        File.Delete("game.tap");
                    }

                    Assembly lasm = new Assembly("main.asm");
                    lasm.Assemble();
                    //rename output to 'data'
                    File.Move("main.bin", "data");
                }
                catch (Exception ex)
                {
                    throw new Exception("Error assembling main.asm", ex);
                }

                //try to run the mctrd script
                //Process.Start("build.bat").WaitForExit()
                ProcessStartInfo startInfo = new ProcessStartInfo(@"..\bin\zxbin2tap.exe");

                string loadScreen = xproject.Project.BuildSettings.SpectrumLoadScreen;

                if (loadScreen == "" || loadScreen == null)
                {//use the blank tape
                    File.Copy("loader.tap", "game.tap");
                }
                else
                {//add the loadscreen
                    if (!File.Exists(loadScreen))
                    {
                        throw new Exception("Couldn't find " + loadScreen);
                    }

                    string localFile = Path.GetFileName(loadScreen);

                    if (localFile != loadScreen)
                    {
                        if (File.Exists(localFile))
                        {
                            File.Delete(localFile);
                        }

                        File.Copy(loadScreen, localFile);
                    }


                    File.Copy("sloader.tap", "game.tap");
                    //zxbin2tap tape loadscreen
                    startInfo.Arguments = "game.tap " + localFile;
                    Process.Start(startInfo).WaitForExit();
                }
                startInfo.Arguments = "game.tap data";
                Process.Start(startInfo).WaitForExit();

                if (File.Exists("game.tap"))
                {
                    RenameBinary("game.tap", outputName + ".tap");
                }

                File.Delete("loader.tap");
                File.Delete("sloader.tap");
                File.Delete("build.bat");

                MoveOutputFiles();
                return(outputName + ".tap");
            }
            catch (Exception ex)
            {
                throw new Exception("Spectrum build failed.", ex);
            }
            finally
            {
                Environment.CurrentDirectory = oldDir;
            }
        }
Exemple #3
0
        /// <summary>
        /// Assembles code and runs CPCDiskXP to create disk file
        /// </summary>
        /// <param name="xmlFileName"></param>
        /// <returns></returns>
        public static string BuildCPC464(Xml xproject, string cpcDiskXPPath)
        {
            string oldDir = Environment.CurrentDirectory;

            try
            {
                string projName   = xproject.Project.ProjName;
                string outputName = xproject.Project.Output;

                Environment.CurrentDirectory = projName + "_CPC464";

                string diskName = outputName + ".dsk";
                string fileName = outputName + ".bin";

                try
                {
                    File.Delete(fileName);

                    Assembly lasm = new Assembly("main.asm");
                    lasm.Assemble();
                    //rename output to 'data'
                    File.Move("main.bin", fileName);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error assembling main.asm", ex);
                }

                //try to run the CPCDiskXP

                if (cpcDiskXPPath == "" || cpcDiskXPPath == null)
                {
                    throw new Exception(fileName + " was assembled in " + Environment.CurrentDirectory + "\r\nbut the file was not attached to a disk image." +
                                        "Install CPCDiskXP and set the path to it in the 'Build Settings' tab.");
                }

                ProcessStartInfo startInfo = new ProcessStartInfo(cpcDiskXPPath);

                string diskCmd = string.Format(
                    " -File {0} -AddAmsdosHeader 4000 -AddToNewDsk {1} -NewDSKFormat 1",
                    fileName,
                    diskName
                    );

                startInfo.Arguments = diskCmd;

                //  File.WriteAllText("build.bat", diskCmd);

                Process.Start(startInfo).WaitForExit();

                if (!File.Exists(diskName))
                {
                    throw new Exception("Error creating disk.  Couldn't find " + diskName);
                }

                MoveOutputFiles();
                return(outputName);
            }
            catch (Exception ex)
            {
                throw new Exception("CPC464 build failed.", ex);
            }
            finally
            {
                Environment.CurrentDirectory = oldDir;
            }
        }
Exemple #4
0
 public Interpreter(XTAC.Xml xproject, TextBox tb)
 {
     PrintTitle();
     PrintAuthor();
     Printcr();
 }
Exemple #5
0
        public void Import(Xml project, string fileName)
        {
            Trizbort triz;
            Dictionary <int, int> idToIndex = new Dictionary <int, int>();

            System.Xml.Serialization.XmlSerializer reader = new XmlSerializer(typeof(Trizbort));

            // Read the XML file.
            StreamReader file = new StreamReader(fileName);

            // Deserialize the content of the file into a Book object.
            triz = (Trizbort)reader.Deserialize(file);

            file.Close();

            project.Project.Objects.Object.RemoveAt(2); // remove default room
            int index = 2;                              //start index

            foreach (Room r in triz.Map.Room)
            {
                int _id = Convert.ToInt32(r.Id);
                idToIndex[_id] = index;
                index++;
            }


            int id = 2;

            //convert the file into a Xml project
            foreach (Room r in triz.Map.Room)
            {
                Object obj = CreateObject();

                obj.Name = r.Name;

                if (r.Name.Equals(""))
                {
                    obj.Name = "Unamed Room";
                }

                obj.Id          = "" + id;
                obj.Description = r.Description;

                if (obj.Description.Length == 0)
                {
                    obj.Description = "DESCRIPTION NOT SET";
                }

                obj.Holder = "0";
                //obj.Flags.Emittinglight = r.Objects.
                obj.Flags.Emittinglight = "1";
                obj.Initialdescription  = "";
                obj.Synonyms            = new Synonyms();
                obj.Synonyms.Names      = "";

                project.Project.Objects.Object.Add(obj);
                ++id;
            }

            //create the connections between rooms
            int i = 3;

            foreach (Line l in triz.Map.Line)
            {
                try
                {
                    int id1;
                    int id2;

                    id1 = Convert.ToInt32(l.Dock[0].Id);
                    id2 = Convert.ToInt32(l.Dock[1].Id);


                    int index1 = idToIndex[id1];
                    int index2 = idToIndex[id2];

                    Object r1 = project.Project.Objects.Object.ElementAt(index1); //convert triz ids to internal ids
                    Object r2 = project.Project.Objects.Object.ElementAt(index2);


                    SetRoomConnection(r1, l.Dock[0].Port, index2);

                    if (l.flow != null)
                    {
                        if (!l.flow.Equals("oneWay"))
                        {
                            SetRoomConnection(r2, l.Dock[1].Port, index1);
                        }
                    }
                    else
                    {
                        SetRoomConnection(r2, l.Dock[1].Port, index1);
                    }
                }
                catch (Exception ex)
                {
                    //    throw new Exception("Import failed", ex);
                }
            }


            //create object entries for the objects in each room
            //create the connections between rooms
            i = 2;

            foreach (Room r in triz.Map.Room)
            {
                string objects = r.Objects;
                if (objects != null)
                {
                    string[] objs = objects.Split('|');

                    foreach (string s in objs)
                    {
                        if (!s.Equals(""))
                        {
                            Object thing = CreateObject();
                            thing.Name               = s.Trim();
                            thing.Id                 = "" + id;
                            thing.Description        = "YOU NOTICE NOTHING UNEXPECTED.";
                            thing.Initialdescription = "";
                            thing.Synonyms           = new Synonyms();
                            thing.Synonyms.Names     = "";
                            thing.Holder             = "" + i;
                            project.Project.Objects.Object.Add(thing);
                            id++;
                        }
                    }
                }
                i++;
            }
        }
Exemple #6
0
        public void Import(Xml project, string fileName)
        {
            Trizbort triz;
            Dictionary <int, int>    idToIndex  = new Dictionary <int, int>();
            Dictionary <string, int> nameCounts = new Dictionary <string, int>();

            System.Xml.Serialization.XmlSerializer reader = new XmlSerializer(typeof(Trizbort));

            // Read the XML file.
            StreamReader file = new StreamReader(fileName);

            // Deserialize the content of the file into an object.
            triz = (Trizbort)reader.Deserialize(file);

            file.Close();

            try
            {
                project.Project.Author = triz.Info.Author;
            } catch  { }

            try
            {
                string title = triz.Info.Title;
                title = title.Replace(' ', '_');
                project.Project.ProjName = title;
            } catch { }

            try
            {
                string temp = triz.Info.Description;
                temp = temp.Substring(0, Math.Min(255, temp.Length));
                temp = temp.Replace('\n', ' ');
                temp = temp.Replace('\r', ' ');
                project.Project.Welcome = temp;
            }
            catch { }

            project.Project.Objects.Object.RemoveAt(2); // remove default room
            int index = 2;                              //start index

            foreach (Room r in triz.Map.Room)
            {
                int _id = Convert.ToInt32(r.Id);
                idToIndex[_id] = index;
                index++;
            }

            //count the names to see which ones are unique
            CountNames(triz.Map.Room, nameCounts);

            int id = 2;

            //convert the file into a Xml project
            foreach (Room r in triz.Map.Room)
            {
                Object obj = CreateObject();

                obj.Name = FixObjectName(r.Name);

                if (!nameCounts.ContainsKey(obj.Name))
                {
                    throw new Exception(obj.Name + " not found in nameCounts while assigning ids.");
                }

                if (nameCounts[obj.Name] > 1)
                {//append the index
                    obj.Name += id;
                }

                obj.PrintedName = r.Name;

                if (r.Name.Equals(""))
                {
                    obj.Name = "Unamed Room";
                }

                obj.Id          = "" + id;
                obj.Description = r.Description.Trim();

                if (obj.Description.Length == 0)
                {
                    obj.Description = "Description not set.";
                }

                obj.Holder = "0";

                if (r.isDark == "yes")
                {
                    obj.Flags.Emittinglight = "0";
                }
                else
                {
                    obj.Flags.Emittinglight = "1";
                }

                obj.Initialdescription = "";
                obj.Synonyms           = new Synonyms();
                obj.Synonyms.Names     = "";

                project.Project.Objects.Object.Add(obj);
                ++id;
            }

            //create the connections between rooms
            int i = 3;

            foreach (Line l in triz.Map.Line)
            {
                try
                {
                    int id1;
                    int id2;

                    id1 = Convert.ToInt32(l.Dock[0].Id);
                    id2 = Convert.ToInt32(l.Dock[1].Id);

                    int index1 = idToIndex[id1];
                    int index2 = idToIndex[id2];

                    Object r1 = project.Project.Objects.Object.ElementAt(index1); //convert triz ids to internal ids
                    Object r2 = project.Project.Objects.Object.ElementAt(index2);


                    if (l.StartText == "up")
                    {//up / down
                        SetRoomConnection(r1, "up", index2);

                        if (l.flow == null || !l.flow.Equals("oneWay"))
                        {
                            SetRoomConnection(r2, "down", index1);
                        }
                        continue;
                    }
                    else if (l.StartText == "down")
                    {
                        SetRoomConnection(r1, "down", index2);

                        if (l.flow != null && !l.flow.Equals("oneWay"))
                        {
                            SetRoomConnection(r2, "up", index1);
                        }
                        continue;
                    }
                    else
                    {//normal connnection
                        SetRoomConnection(r1, l.Dock[0].Port, index2);
                    }

                    //make reverse connection
                    if (l.flow != null)
                    {
                        if (!l.flow.Equals("oneWay"))
                        {
                            SetRoomConnection(r2, l.Dock[1].Port, index1);
                        }
                    }
                    else
                    {
                        SetRoomConnection(r2, l.Dock[1].Port, index1);
                    }
                }
                catch (Exception ex)
                {
                    //    throw new Exception("Import failed", ex);
                }
            }


            //create object entries for the objects in each room
            //create the connections between rooms
            i = 2;

            foreach (Room r in triz.Map.Room)
            {
                string objects = r.Objects;
                if (objects != null)
                {
                    string[] objs = objects.Split('|');

                    foreach (string s in objs)
                    {
                        if (!s.Equals(""))
                        {
                            Object thing = CreateObject();

                            int idNum = project.Project.Objects.Object.Count;

                            string fixedName = FixObjectName(s);

                            if (nameCounts.ContainsKey(fixedName))
                            {
                                if (nameCounts[fixedName] == 1)
                                {
                                    thing.Name = fixedName;
                                }
                                else
                                {
                                    thing.Name = fixedName + idNum;
                                }
                            }
                            else
                            {
                                //throw new Exception("Couldn't get a count of " + fixedName);
                                nameCounts[fixedName] = 1;
                            }
                            thing.PrintedName = s.Trim();

                            thing.Id                 = "" + id;
                            thing.Description        = "You notice nothing unexpected.";
                            thing.Initialdescription = "";
                            thing.Synonyms           = new Synonyms();
                            thing.Synonyms.Names     = "";
                            thing.Holder             = "" + i;
                            project.Project.Objects.Object.Add(thing);
                            id++;
                        }
                    }
                }
                i++;
            }
        }