Skip to content

Commit

Permalink
Add open file support
Browse files Browse the repository at this point in the history
  • Loading branch information
Wakeful-Cloud authored and TheThirdOne committed Feb 27, 2023
1 parent 3d684ef commit 5868f71
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/help/Command.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h4>Using RARS from a command line.</h4>
<tr><td width=40 align="right"><tt>dump</tt></td><td>dump memory contents to file.
Option has 3 arguments, e.g. <tt>dump &lt;segment&gt; &lt;format&gt; &lt;file&gt;</tt>. Current supported segments are <tt>.text</tt>
and <tt>.data</tt>. Also supports an address range (see <i>m-n</i> below). Current supported dump formats are <tt>Binary</tt>, <tt>HexText</tt>, <tt>BinaryText</tt>, <tt>AsciiText</tt>. See examples below.</td><td>3.4</td></tr>
<tr><td width=40 align="right"><tt>g</tt></td><td>force GUI mode</td><td>1.6</td></tr>
<tr><td width=40 align="right"><tt>hex</tt></td><td>display memory or register contents in hexadecimal - this is the default. (alternatives are <tt>ascii</tt> and <tt>dec</tt>)</td><td>2.2</td></tr>
<tr><td width=40 align="right"><tt>h</tt></td><td>display this help. Use this option by itself and with no filename.</td><td>1.0</td></tr>
<tr><td width=40 align="right"><tt>ic</tt></td><td>display instruction count; the number of basic instructions 'executed'</td><td>4.3</td></tr>
Expand Down
51 changes: 32 additions & 19 deletions src/rars/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class Launch {
* an address range (see <i>m-n</i> below). Current supported <br>
* segments are <tt>.text</tt> and <tt>.data</tt>. Current supported dump formats <br>
* are <tt>Binary</tt>, <tt>HexText</tt>, <tt>BinaryText</tt>.<br>
* g -- force GUI mode
* h -- display help. Use by itself and with no filename</br>
* hex -- display memory or register contents in hexadecimal (default)<br>
* ic -- display count of basic instructions 'executed'");
Expand Down Expand Up @@ -109,6 +110,7 @@ public class Launch {
**/

private Options options;
private boolean gui;
private boolean simulate;
private boolean rv64;
private int displayFormat;
Expand All @@ -135,28 +137,34 @@ public static void main(String[] args){
}
private Launch(String[] args) {
Globals.initialize();
if (args.length == 0) {

options = new Options();
gui = args.length == 0;
simulate = true;
displayFormat = HEXADECIMAL;
verbose = true;
assembleProject = false;
countInstructions = false;
instructionCount = 0;
assembleErrorExitCode = 0;
simulateErrorExitCode = 0;
registerDisplayList = new ArrayList<>();
memoryDisplayList = new ArrayList<>();
filenameList = new ArrayList<>();
MemoryConfigurations.setCurrentConfiguration(MemoryConfigurations.getDefaultConfiguration());
out = System.out;

if (!parseCommandArgs(args)) {
System.exit(Globals.exitCode);
}

if (gui) {
launchIDE();
} else { // running from command line.
// assure command mode works in headless environment (generates exception if not)
System.setProperty("java.awt.headless", "true");
options = new Options();
simulate = true;
displayFormat = HEXADECIMAL;
verbose = true;
assembleProject = false;
countInstructions = false;
instructionCount = 0;
assembleErrorExitCode = 0;
simulateErrorExitCode = 0;
registerDisplayList = new ArrayList<>();
memoryDisplayList = new ArrayList<>();
filenameList = new ArrayList<>();
MemoryConfigurations.setCurrentConfiguration(MemoryConfigurations.getDefaultConfiguration());
out = System.out;
if (parseCommandArgs(args)) {
dumpSegments(runCommand());
}

dumpSegments(runCommand());
System.exit(Globals.exitCode);
}
}
Expand Down Expand Up @@ -228,7 +236,7 @@ private void launchIDE() {
public void run() {
//Turn off metal's use of bold fonts
//UIManager.put("swing.boldMetal", Boolean.FALSE);
new VenusUI("RARS " + Globals.version);
new VenusUI("RARS " + Globals.version, filenameList);
}
});
}
Expand Down Expand Up @@ -347,6 +355,10 @@ private boolean parseCommandArgs(String[] args) {
displayFormat = DECIMAL;
continue;
}
if (args[i].toLowerCase().equals("g")) {
gui = true;
continue;
}
if (args[i].toLowerCase().equals("hex")) {
displayFormat = HEXADECIMAL;
continue;
Expand Down Expand Up @@ -714,6 +726,7 @@ private void displayHelp() {
out.println(" Segment and format are case-sensitive and possible values are:");
out.println(" <segment> = " + segments+", or a range like 0x400000-0x10000000");
out.println(" <format> = " + formats);
out.println(" g -- force GUI mode");
out.println(" h -- display this help. Use by itself with no filename.");
out.println(" hex -- display memory or register contents in hexadecimal (default)");
out.println(" ic -- display count of basic instructions 'executed'");
Expand Down
16 changes: 16 additions & 0 deletions src/rars/venus/Editor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rars.venus;

import java.io.File;
import java.util.ArrayList;

/*
Copyright (c) 2003-2007, Pete Sanderson and Kenneth Vollmar
Expand Down Expand Up @@ -243,6 +244,21 @@ public boolean open() {
return editTabbedPane.openFile();
}

/**
* Open files in new tabs.
* @param paths File paths to open
* @return true if succeeded, else false.
*/
public boolean open(ArrayList<String> paths) {
for (String path : paths) {
File file = new File(path);
if (!editTabbedPane.openFile(file)) {
return false;
}
}

return true;
}

/**
* Called by several of the Action objects when there is potential
Expand Down
14 changes: 11 additions & 3 deletions src/rars/venus/VenusUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.ArrayList;

/*
Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar
Expand Down Expand Up @@ -116,11 +117,12 @@ public class VenusUI extends JFrame {
/**
* Constructor for the Class. Sets up a window object for the UI
*
* @param s Name of the window to be created.
* @param name Name of the window to be created.
* @param paths File paths to open width
**/

public VenusUI(String s) {
super(s);
public VenusUI(String name, ArrayList<String> paths) {
super(name);
mainUI = this;
Globals.setGui(this);
this.editor = new Editor(this);
Expand Down Expand Up @@ -238,6 +240,12 @@ public void windowClosing(WindowEvent e) {

this.pack();
this.setVisible(true);

// Open files
if (!this.editor.open(paths)) {
System.out.println("Internal Error: could not open files" + String.join(", ", paths));
System.exit(1);
}
}


Expand Down

0 comments on commit 5868f71

Please sign in to comment.