Beispiel #1
0
        /// <summary>
        /// Populates the tree view nodes with the contents of the data file.
        /// </summary>
        /// <param name="tv">TreeView to add items to</param>
        /// <param name="prevSelSystem">Name of previously-selected system.</param>
        /// <returns>The node that matches prevSelSystem, or null if not found.</returns>
        private TreeNode PopulateNodes(TreeView tv, string prevSelSystem)
        {
            TreeNode selNode = null;

            string sysDefsPath = RuntimeDataAccess.GetPathName("SystemDefs.json");

            if (sysDefsPath == null)
            {
                TreeNode errNode = new MyTreeNode(
                    SourceGen.Properties.Resources.ERR_LOAD_CONFIG_FILE, false, null);
                tv.Nodes.Add(errNode);
                return(null);
            }

            try {
                mSystemDefs = SystemDefSet.ReadFile(sysDefsPath);
            } catch (Exception ex) {
                Debug.WriteLine("Failed loading system def set: " + ex);
                TreeNode errNode = new MyTreeNode(
                    SourceGen.Properties.Resources.ERR_LOAD_CONFIG_FILE, false, null);
                tv.Nodes.Add(errNode);
                return(null);
            }

            if (mSystemDefs.Defs == null || mSystemDefs.Defs.Length == 0)
            {
                Debug.WriteLine("Empty def set found");
                TreeNode errNode = new MyTreeNode(
                    SourceGen.Properties.Resources.ERR_LOAD_CONFIG_FILE, false, null);
                tv.Nodes.Add(errNode);
                return(null);
            }

            var groups = new Dictionary <string, MyTreeNode>();

            foreach (SystemDef sd in mSystemDefs.Defs)
            {
                if (!groups.TryGetValue(sd.GroupName, out MyTreeNode groupNode))
                {
                    groupNode            = new MyTreeNode(sd.GroupName, false, null);
                    groups[sd.GroupName] = groupNode;
                    tv.Nodes.Add(groupNode);
                }

                bool   isValid  = sd.Validate();
                string treeName = isValid ? sd.Name :
                                  sd.Name + SourceGen.Properties.Resources.ERR_INVALID_SYSDEF;

                MyTreeNode newNode = new MyTreeNode(treeName, isValid, sd);
                groupNode.Nodes.Add(newNode);

                if (isValid && sd.Name == prevSelSystem)
                {
                    selNode = newNode;
                }
            }

            return(selNode);
        }
        private void addExtensionScriptsButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDlg = new OpenFileDialog()
            {
                Filter           = Sandbox.ScriptManager.FILENAME_FILTER,
                Multiselect      = true,
                InitialDirectory = RuntimeDataAccess.GetDirectory(),
                RestoreDirectory = true     // doesn't seem to work?
            };

            if (fileDlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            foreach (string pathName in fileDlg.FileNames)
            {
                // I'm assuming the full names got the Path.GetFullPath() canonicalization and
                // don't need further processing.  Also, I'm assuming that all files live in
                // the same directory, so if one is in an invalid location then they all are.
                ExternalFile ef = ExternalFile.CreateFromPath(pathName, mProjectDir);
                if (ef == null)
                {
                    // Files not found in runtime or project directory.
                    string projDir = mProjectDir;
                    if (string.IsNullOrEmpty(projDir))
                    {
                        projDir = Properties.Resources.UNSET;
                    }
                    string msg = string.Format(Properties.Resources.EXTERNAL_FILE_BAD_DIR,
                                               RuntimeDataAccess.GetDirectory(), projDir, pathName);
                    MessageBox.Show(this, msg, Properties.Resources.EXTERNAL_FILE_BAD_DIR_CAPTION,
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string ident = ef.Identifier;

                if (mWorkProps.ExtensionScriptFileIdentifiers.Contains(ident))
                {
                    Debug.WriteLine("Already present: " + ident);
                    continue;
                }

                Debug.WriteLine("Adding extension script: " + ident);
                mWorkProps.ExtensionScriptFileIdentifiers.Add(ident);
                mDirty = true;
            }

            if (mDirty)
            {
                LoadExtensionScriptNames();
                UpdateControls();
            }
        }
Beispiel #3
0
        private void AddSymbolFiles(bool fromPlatform)
        {
            OpenFileDialog fileDlg = new OpenFileDialog()
            {
                Filter           = PlatformSymbols.FILENAME_FILTER,
                Multiselect      = true,
                InitialDirectory = fromPlatform ? RuntimeDataAccess.GetDirectory() : mProjectDir,
                RestoreDirectory = true     // doesn't seem to work?
            };

            if (fileDlg.ShowDialog() != true)
            {
                return;
            }

            foreach (string pathName in fileDlg.FileNames)
            {
                // I'm assuming the full names got the Path.GetFullPath() canonicalization and
                // don't need further processing.  Also, I'm assuming that all files live in
                // the same directory, so if one is in an invalid location then they all are.
                ExternalFile ef = ExternalFile.CreateFromPath(pathName, mProjectDir);
                if (ef == null)
                {
                    // Files not found in runtime or project directory.
                    string projDir = mProjectDir;
                    if (string.IsNullOrEmpty(projDir))
                    {
                        projDir = Res.Strings.UNSET;
                    }
                    string msg = string.Format(Res.Strings.EXTERNAL_FILE_BAD_DIR_FMT,
                                               RuntimeDataAccess.GetDirectory(), projDir, pathName);
                    MessageBox.Show(msg, Res.Strings.EXTERNAL_FILE_BAD_DIR_CAPTION,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                string ident = ef.Identifier;

                if (mWorkProps.PlatformSymbolFileIdentifiers.Contains(ident))
                {
                    Debug.WriteLine("Already present: " + ident);
                    continue;
                }

                Debug.WriteLine("Adding symbol file: " + ident);
                mWorkProps.PlatformSymbolFileIdentifiers.Add(ident);
                IsDirty = true;
            }

            if (IsDirty)
            {
                LoadPlatformSymbolFiles();
                UpdateControls();
            }
        }
Beispiel #4
0
 /// <summary>
 /// Computes the path to the plugin directory.  Does not attempt to verify that it exists.
 /// </summary>
 /// <returns>Plugin directory path, or null if we can't find the application data
 ///   area.</returns>
 public static string GetPluginDirPath()
 {
     if (sPluginDirPath == null)
     {
         string runtimeUp = Path.GetDirectoryName(RuntimeDataAccess.GetDirectory());
         if (runtimeUp == null)
         {
             return(null);
         }
         sPluginDirPath = Path.Combine(runtimeUp, PLUGIN_DIR_NAME);
     }
     return(sPluginDirPath);
 }
Beispiel #5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string text;
            string pathName = RuntimeDataAccess.GetPathName(LEGAL_STUFF_FILE_NAME);

            try {
                text = File.ReadAllText(pathName);
            } catch (Exception ex) {
                text = ex.ToString();
            }

            legalStuffTextBox.Text = text;
        }
Beispiel #6
0
        public AboutBox()
        {
            InitializeComponent();

            boardPictureBox.ImageLocation = RuntimeDataAccess.GetPathName(IMAGE_FILE_NAME);
            versionLabel.Text             = string.Format(Properties.Resources.VERSION_FMT,
                                                          Program.ProgramVersion);

            osPlatformLabel.Text = "OS: " +
                                   System.Runtime.InteropServices.RuntimeInformation.OSDescription;
#if DEBUG
            debugEnabledLabel.Visible = true;
#endif
        }
Beispiel #7
0
        /// <summary>
        /// Runs generate/assemble test cases.  Main entry point.
        /// </summary>
        /// <param name="worker">Background worker object from dialog box.</param>
        public List <GenTestResults> Run(BackgroundWorker worker)
        {
            Debug.Assert(mWorker == null);  // don't re-use object

            mWorker = worker;
            string runtimeDir = RuntimeDataAccess.GetDirectory();

            mTestDir = Path.Combine(Path.GetDirectoryName(runtimeDir), TEST_DIR_NAME);

            if (!Directory.Exists(mTestDir))
            {
                ReportErrMsg("Regression test directory not found: " + mTestDir);
                ReportFailure();
                return(null);
            }

            List <string> testCases = new List <string>();

            foreach (string pathName in Directory.EnumerateFiles(mTestDir))
            {
                // Filter out everything that doesn't look like "1000-nifty-test".  We
                // want to ignore .dis65 files and assembler output (which has the name
                // of the assembler following an underscore).
                string          fileName = Path.GetFileName(pathName);
                MatchCollection matches  = sTestCaseRegex.Matches(fileName);
                if (matches.Count == 0)
                {
                    //ReportProgress("Ignoring " + fileName + "\r\n", Color.Gray);
                    continue;
                }

                ReportProgress("Found " + fileName + "\r\n");
                testCases.Add(pathName);
            }

            ReportProgress("Processing " + testCases.Count + " test cases...\r\n");
            DateTime startWhen = DateTime.Now;

            int successCount = 0;

            foreach (string pathName in testCases)
            {
                if (GenerateAndAssemble(pathName))
                {
                    successCount++;
                }

                if (worker.CancellationPending)
                {
                    ReportProgress("\r\nCancelled.\r\n", Colors.Red);
                    return(mResults);
                }
            }

            DateTime endWhen = DateTime.Now;

            if (successCount == testCases.Count)
            {
                ReportProgress(string.Format("All " + testCases.Count +
                                             " tests passed in {0:N3} sec\r\n",
                                             (endWhen - startWhen).TotalSeconds), Colors.Green);
            }
            else
            {
                ReportProgress(successCount + " of " + testCases.Count + " tests passed\r\n");
            }

            return(mResults);
        }
Beispiel #8
0
        private bool GenerateDataAndProject()
        {
            // Sum up the segment lengths to get the total project size.
            int totalLen = 0;

            foreach (SegmentMapEntry ent in mSegmentMap)
            {
                if (ent == null)
                {
                    continue;
                }
                totalLen += ent.Segment.Length;
            }
            Debug.WriteLine("Total length of loaded binary is " + totalLen);

            byte[] data = new byte[totalLen];

            // Create the project object.
            DisasmProject proj = new DisasmProject();

            proj.Initialize(data.Length);

            // Try to get the Apple IIgs system definition.  This is fragile, because it
            // relies on the name in the JSON file, but it's optional.  (If the default CPU
            // type stops being 65816, we should be sure to set that here.)
            try {
                // TODO(maybe): encapsulate this somewhere else
                string       sysDefsPath = RuntimeDataAccess.GetPathName("SystemDefs.json");
                SystemDefSet sds         = SystemDefSet.ReadFile(sysDefsPath);
                SystemDef    sd          = sds.FindEntryByName(IIGS_SYSTEM_DEF);
                if (sd != null)
                {
                    proj.ApplySystemDef(sd);
                }
                else
                {
                    Debug.WriteLine("Unable to find Apple IIgs system definition");
                }
            } catch (Exception) {
                // never mind
                Debug.WriteLine("Failed to apply Apple IIgs system definition");
            }

            ChangeSet cs = new ChangeSet(mSegmentMap.Count * 2);

            AddHeaderComment(proj, cs);
            UndoableChange uc;

            // Load the segments, and add entries to the project.
            int bufOffset = 0;

            foreach (SegmentMapEntry ent in mSegmentMap)
            {
                if (ent == null)
                {
                    continue;
                }

                if (ent.Segment.Kind == OmfSegment.SegmentKind.JumpTable)
                {
                    if (!RelocJumpTable(ent, data, bufOffset, cs))
                    {
                        // Could treat this as non-fatal, but it really ought to work.
                        Debug.WriteLine("Jump Table reloc failed");
                        return(false);
                    }
                }
                else
                {
                    // Perform relocation.
                    if (!RelocSegment(ent, data, bufOffset))
                    {
                        return(false);
                    }
                }

                // Add one or more address entries.  (Normally one, but data segments
                // can straddle multiple pages.)
                AddAddressEntries(proj, ent, bufOffset, cs);

                if ((mFlags & Flags.AddNotes) != 0)
                {
                    // Add a comment identifying the segment and its attributes.
                    string segCmt = string.Format(Res.Strings.OMF_SEG_COMMENT_FMT,
                                                  ent.Segment.SegNum, ent.Segment.Kind, ent.Segment.Attrs, ent.Segment.SegName);
                    uc = UndoableChange.CreateLongCommentChange(bufOffset, null,
                                                                new MultiLineComment(segCmt));
                    cs.Add(uc);

                    // Add a note identifying the segment.
                    string segNote = string.Format(Res.Strings.OMF_SEG_NOTE_FMT,
                                                   ent.Segment.SegNum, mFormatter.FormatAddress(ent.Address, true),
                                                   ent.Segment.SegName);
                    uc = UndoableChange.CreateNoteChange(bufOffset, null,
                                                         new MultiLineComment(segNote));
                    cs.Add(uc);
                }

                bufOffset += ent.Segment.Length;
            }

            proj.PrepForNew(data, "new_proj");
            foreach (KeyValuePair <int, DisasmProject.RelocData> kvp in mRelocData)
            {
                proj.RelocList.Add(kvp.Key, kvp.Value);
            }

            // Enable "use reloc" in the analysis parameters.
            ProjectProperties newProps = new ProjectProperties(proj.ProjectProps);

            newProps.AnalysisParams.UseRelocData = true;
            uc = UndoableChange.CreateProjectPropertiesChange(proj.ProjectProps, newProps);
            cs.Add(uc);

            // TODO(someday): by default we apply a code start tag to offset 0 of the first
            // segment.  The placement should take the segment's ENTRY into account.

            Debug.WriteLine("Applying " + cs.Count + " changes");
            proj.ApplyChanges(cs, false, out _);

            mLoadedData = data;
            mNewProject = proj;
            return(true);
        }