diff --git a/pom.xml b/pom.xml index 9350954..6f4b061 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.loomcom.j6502 j6502 jar - 1.0-SNAPSHOT + 0.1.0 j6502 http://www.loomcom.com/j6502 @@ -15,4 +15,27 @@ test + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + com.loomcom.j6502.Control + com.loomcom.j6502 + + + development + ${pom.url} + + + + + + + diff --git a/src/main/java/com/loomcom/j6502/CommandParser.java b/src/main/java/com/loomcom/j6502/CommandParser.java new file mode 100644 index 0000000..e8e3c32 --- /dev/null +++ b/src/main/java/com/loomcom/j6502/CommandParser.java @@ -0,0 +1,70 @@ +package com.loomcom.j6502; + +import java.io.*; + +public class CommandParser { + + private BufferedReader m_in; + private BufferedWriter m_out; + + public CommandParser(InputStream in, OutputStream out) { + m_in = new BufferedReader(new InputStreamReader(in)); + m_out = new BufferedWriter(new OutputStreamWriter(out)); + } + + public void run() { + try { + String command = null; + greeting(); + prompt(); + while (!shouldQuit(command = readLine())) { + dispatch(command); + prompt(); + } + writeLine("Goodbye!"); + } catch (IOException ex) { + System.err.println("Error: " + ex.toString()); + System.exit(1); + } + } + + /** + * Dispatch the command. + */ + public void dispatch(String command) throws IOException { + writeLine("You entered: " + command); + } + + /******************************************************************* + * Private + *******************************************************************/ + + private void greeting() throws IOException { + writeLine("Welcome to the j6502 Simulator!"); + } + + private void prompt() throws IOException { + m_out.write("> "); + m_out.flush(); + } + + private String readLine() throws IOException { + String line = m_in.readLine(); + if (line == null) { return null; } + return line.trim(); + } + + private void writeLine(String line) throws IOException { + m_out.write(line); + m_out.newLine(); + m_out.flush(); + } + + /** + * Returns true if the line is a quit. + */ + private boolean shouldQuit(String line) { + return (line == null || "q".equals(line.toLowerCase())); + } + +} \ No newline at end of file diff --git a/src/main/java/com/loomcom/j6502/Control.java b/src/main/java/com/loomcom/j6502/Control.java index 339e063..f914a8b 100644 --- a/src/main/java/com/loomcom/j6502/Control.java +++ b/src/main/java/com/loomcom/j6502/Control.java @@ -1,11 +1,17 @@ package com.loomcom.j6502; +import java.io.IOException; + /** * Main control class for the J6502 Simulator. */ public class Control { + public static void main(String[] args) { - System.out.println("Hello, world!"); + + CommandParser parser = new CommandParser(System.in, System.out); + parser.run(); + } } \ No newline at end of file