Add new options -cpu and -rom
This commit is contained in:
1 parent
d466a21b3e
commit
0aeb97bb56
7 files changed
+153
-71
No files matched your search
@@ -28,6 +28,8 @@ package com.loomcom.symon;
|
||||
import com.loomcom.symon.machines.MulticompMachine;
|
||||
import com.loomcom.symon.machines.SimpleMachine;
|
||||
import com.loomcom.symon.machines.SymonMachine;
|
||||
import org.apache.commons.cli.*;
|
||||
|
||||
import java.util.Locale;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
@@ -41,71 +43,115 @@ public class Main {
|
||||
*
|
||||
* @param args Program arguments
|
||||
*/
|
||||
public static void main(String args[]) throws Exception {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Class machineClass = SymonMachine.class;
|
||||
for(int i = 0; i < args.length; ++i) {
|
||||
String arg = args[i].toLowerCase(Locale.ENGLISH);
|
||||
if(arg.equals("-machine") && (i+1) < args.length) {
|
||||
String machine = args[i+1].trim().toLowerCase(Locale.ENGLISH);
|
||||
|
||||
Options options = new Options();
|
||||
|
||||
options.addOption(new Option("m", "machine", true, "Specify machine type."));
|
||||
options.addOption(new Option("c", "cpu", true, "Specify CPU type."));
|
||||
options.addOption(new Option("r", "rom", true, "Specify ROM file."));
|
||||
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
|
||||
try {
|
||||
CommandLine line = parser.parse(options, args);
|
||||
InstructionTable.CpuBehavior cpuBehavior = null;
|
||||
String romFile = null;
|
||||
|
||||
if (line.hasOption("machine")) {
|
||||
String machine = line.getOptionValue("machine").toLowerCase(Locale.ENGLISH);
|
||||
switch (machine) {
|
||||
case "symon":
|
||||
machineClass = SymonMachine.class;
|
||||
break;
|
||||
case "multicomp":
|
||||
machineClass = MulticompMachine.class;
|
||||
break;
|
||||
case "simple":
|
||||
machineClass = SimpleMachine.class;
|
||||
break;
|
||||
case "symon":
|
||||
machineClass = SymonMachine.class;
|
||||
break;
|
||||
default:
|
||||
System.err.println("Could not start Symon. Unknown machine type " + machine);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (machineClass == null) {
|
||||
Object[] possibilities = {"Symon", "Multicomp", "Simple"};
|
||||
String s = (String)JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Please choose the machine type to be emulated:",
|
||||
"Machine selection",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
possibilities,
|
||||
"Symon");
|
||||
|
||||
|
||||
if (s != null && s.equals("Multicomp")) {
|
||||
machineClass = MulticompMachine.class;
|
||||
} else if (s != null && s.equals("Simple")) {
|
||||
machineClass = SimpleMachine.class;
|
||||
} else {
|
||||
machineClass = SymonMachine.class;
|
||||
if (line.hasOption("cpu")) {
|
||||
String cpu = line.getOptionValue("cpu").toLowerCase(Locale.ENGLISH);
|
||||
switch (cpu) {
|
||||
case "6502":
|
||||
cpuBehavior = InstructionTable.CpuBehavior.NMOS_6502;
|
||||
break;
|
||||
case "65c02":
|
||||
cpuBehavior = InstructionTable.CpuBehavior.CMOS_6502;
|
||||
break;
|
||||
case "65c816":
|
||||
cpuBehavior = InstructionTable.CpuBehavior.CMOS_65816;
|
||||
break;
|
||||
default:
|
||||
System.err.println("Could not start Symon. Unknown cpu type " + cpu);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final Simulator simulator = new Simulator(machineClass);
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
// Create the main UI window
|
||||
simulator.createAndShowUi();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
if (line.hasOption("rom")) {
|
||||
romFile = line.getOptionValue("rom");
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (machineClass == null) {
|
||||
Object[] possibilities = {"Symon", "Multicomp", "Simple"};
|
||||
String s = (String)JOptionPane.showInputDialog(
|
||||
null,
|
||||
"Please choose the machine type to be emulated:",
|
||||
"Machine selection",
|
||||
JOptionPane.PLAIN_MESSAGE,
|
||||
null,
|
||||
possibilities,
|
||||
"Symon");
|
||||
|
||||
|
||||
if (s != null && s.equals("Multicomp")) {
|
||||
machineClass = MulticompMachine.class;
|
||||
} else if (s != null && s.equals("Simple")) {
|
||||
machineClass = SimpleMachine.class;
|
||||
} else {
|
||||
machineClass = SymonMachine.class;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Simulator.MainCommand cmd = simulator.waitForCommand();
|
||||
if (cmd.equals(Simulator.MainCommand.SELECTMACHINE)) {
|
||||
machineClass = null;
|
||||
} else {
|
||||
break;
|
||||
|
||||
if (cpuBehavior == null) {
|
||||
cpuBehavior = InstructionTable.CpuBehavior.NMOS_6502;
|
||||
}
|
||||
|
||||
final Simulator simulator = new Simulator(machineClass, cpuBehavior, romFile);
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
// Create the main UI window
|
||||
simulator.createAndShowUi();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Simulator.MainCommand cmd = simulator.waitForCommand();
|
||||
|
||||
if (cmd.equals(Simulator.MainCommand.SELECTMACHINE)) {
|
||||
machineClass = null;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ParseException ex) {
|
||||
System.err.println("Could not start Symon. Reason: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user