2014-07-26 16:07:29 +00:00
|
|
|
/*
|
2015-12-29 22:40:42 +00:00
|
|
|
* Copyright (c) 2016 Seth J. Morabito <web@loomcom.com>
|
2014-08-16 20:50:47 +00:00
|
|
|
* Maik Merten <maikmerten@googlemail.com>
|
2014-07-26 16:07:29 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
package com.loomcom.symon;
|
|
|
|
|
|
|
|
import com.loomcom.symon.machines.MulticompMachine;
|
2014-08-10 20:53:04 +00:00
|
|
|
import com.loomcom.symon.machines.SimpleMachine;
|
2014-07-26 16:07:29 +00:00
|
|
|
import com.loomcom.symon.machines.SymonMachine;
|
2023-10-18 07:38:55 +00:00
|
|
|
import com.loomcom.symon.machines.BenEaterMachine;
|
2019-10-12 21:54:05 +00:00
|
|
|
import org.apache.commons.cli.*;
|
|
|
|
|
2014-07-26 16:07:29 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
import javax.swing.JOptionPane;
|
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
import javax.swing.UIManager;
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main entry point to the simulator. Creates a simulator and shows the main
|
|
|
|
* window.
|
|
|
|
*
|
2015-12-30 01:55:41 +00:00
|
|
|
* @param args Program arguments
|
2014-07-26 16:07:29 +00:00
|
|
|
*/
|
2019-10-12 21:54:05 +00:00
|
|
|
public static void main(String[] args) throws Exception {
|
2014-07-26 16:07:29 +00:00
|
|
|
|
2014-07-26 16:52:57 +00:00
|
|
|
Class machineClass = SymonMachine.class;
|
2019-10-12 21:54:05 +00:00
|
|
|
|
|
|
|
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);
|
2015-12-30 01:55:41 +00:00
|
|
|
switch (machine) {
|
|
|
|
case "multicomp":
|
|
|
|
machineClass = MulticompMachine.class;
|
|
|
|
break;
|
|
|
|
case "simple":
|
|
|
|
machineClass = SimpleMachine.class;
|
|
|
|
break;
|
2019-10-12 21:54:05 +00:00
|
|
|
case "symon":
|
|
|
|
machineClass = SymonMachine.class;
|
|
|
|
break;
|
2023-10-18 07:38:55 +00:00
|
|
|
case "beneater":
|
|
|
|
machineClass = BenEaterMachine.class;
|
|
|
|
break;
|
2019-10-12 21:54:05 +00:00
|
|
|
default:
|
|
|
|
System.err.println("Could not start Symon. Unknown machine type " + machine);
|
|
|
|
return;
|
2014-07-26 16:07:29 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-12 21:54:05 +00:00
|
|
|
|
|
|
|
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;
|
2014-07-26 16:52:57 +00:00
|
|
|
}
|
2014-07-26 16:07:29 +00:00
|
|
|
}
|
2019-10-12 21:54:05 +00:00
|
|
|
|
|
|
|
if (line.hasOption("rom")) {
|
|
|
|
romFile = line.getOptionValue("rom");
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (machineClass == null) {
|
2023-10-18 07:38:55 +00:00
|
|
|
Object[] possibilities = {"Symon", "Multicomp", "Simple", "BenEater"};
|
2019-10-12 21:54:05 +00:00
|
|
|
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;
|
2023-10-18 07:38:55 +00:00
|
|
|
} else if (s != null && s.equals("BenEater")) {
|
|
|
|
machineClass = BenEaterMachine.class;
|
2019-10-12 21:54:05 +00:00
|
|
|
} else {
|
|
|
|
machineClass = SymonMachine.class;
|
2016-01-09 03:11:42 +00:00
|
|
|
}
|
2014-07-26 16:07:29 +00:00
|
|
|
}
|
2019-10-12 21:54:05 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2014-07-26 16:52:57 +00:00
|
|
|
}
|
2019-10-12 21:54:05 +00:00
|
|
|
} catch (ParseException ex) {
|
|
|
|
System.err.println("Could not start Symon. Reason: " + ex.getMessage());
|
2014-07-26 16:52:57 +00:00
|
|
|
}
|
2014-07-26 16:07:29 +00:00
|
|
|
}
|
|
|
|
}
|