[O] Refactor
This commit is contained in:
@@ -1 +0,0 @@
|
||||
jar cmf mainclass.txt Mars.jar PseudoOps.txt Config.properties Syscall.properties Settings.properties MARSlicense.txt mainclass.txt MipsXRayOpcode.xml registerDatapath.xml controlDatapath.xml ALUcontrolDatapath.xml CreateMarsJar.bat CreateMarsJar.sh Mars.java Mars.class docs help images mars
|
||||
@@ -1,2 +0,0 @@
|
||||
# If you can't generate due of permissions, do a "chmod +x CreateMarsJar.sh".
|
||||
jar cmf mainclass.txt Mars.jar PseudoOps.txt Config.properties Syscall.properties Settings.properties MARSlicense.txt mainclass.txt MipsXRayOpcode.xml registerDatapath.xml controlDatapath.xml ALUcontrolDatapath.xml CreateMarsJar.bat CreateMarsJar.sh Mars.java Mars.class docs help images mars
|
||||
+1
-10
@@ -1,12 +1,3 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Java application project to get you started.
|
||||
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
|
||||
* User Manual available at https://docs.gradle.org/7.5.1/userguide/building_java_projects.html
|
||||
* This project uses @Incubating APIs which are subject to change.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
id 'application'
|
||||
@@ -34,5 +25,5 @@ testing {
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass = 'mars.assembler.App'
|
||||
mainClass = 'Mars'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
from subprocess import check_output
|
||||
|
||||
if __name__ == '__main__':
|
||||
java = Path('src/main/java')
|
||||
files = [Path(root) / f for root, dir, files in os.walk(java) for f in files]
|
||||
|
||||
for f in files:
|
||||
ftype = check_output(f'file {f}', shell=True).decode()
|
||||
if '8859' not in ftype:
|
||||
continue
|
||||
|
||||
print(f'Converting {f} to UTF-8...')
|
||||
f.write_text(f.read_text('ISO-8859-1'), 'utf8')
|
||||
|
||||
# print(files)
|
||||
+1
-11
@@ -1,11 +1 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/7.5.1/userguide/multi_project_builds.html
|
||||
* This project uses @Incubating APIs which are subject to change.
|
||||
*/
|
||||
|
||||
rootProject.name = 'MARS-Assembler'
|
||||
rootProject.name = 'MARS'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar
|
||||
|
||||
@@ -29,14 +28,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
/**
|
||||
* Portal to Mars
|
||||
*
|
||||
*
|
||||
* @author Pete Sanderson
|
||||
* @version March 2006
|
||||
**/
|
||||
|
||||
public class Mars {
|
||||
public static void main(String[] args) {
|
||||
new mars.MarsLaunch(args);
|
||||
}
|
||||
}
|
||||
public class Mars {
|
||||
public static void main(String[] args) {
|
||||
new mars.MarsLaunch(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
Main-Class: Mars
|
||||
Class-Path: .
|
||||
+250
-204
@@ -1,12 +1,16 @@
|
||||
package mars;
|
||||
import mars.mips.instructions.syscalls.*;
|
||||
import mars.mips.instructions.*;
|
||||
import mars.mips.hardware.*;
|
||||
import mars.assembler.*;
|
||||
import mars.venus.*;
|
||||
import mars.util.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
package mars;
|
||||
|
||||
import mars.assembler.SymbolTable;
|
||||
import mars.mips.hardware.Memory;
|
||||
import mars.mips.instructions.InstructionSet;
|
||||
import mars.mips.instructions.syscalls.SyscallNumberOverride;
|
||||
import mars.util.PropertiesFile;
|
||||
import mars.venus.VenusUI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2008, Pete Sanderson and Kenneth Vollmar
|
||||
@@ -38,212 +42,254 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
/**
|
||||
* Collection of globally-available data structures.
|
||||
*
|
||||
* @author Pete Sanderson
|
||||
*
|
||||
* @author Pete Sanderson
|
||||
* @version August 2003
|
||||
*/
|
||||
public class Globals
|
||||
{
|
||||
// List these first because they are referenced by methods called at initialization.
|
||||
private static String configPropertiesFile = "Config";
|
||||
private static String syscallPropertiesFile = "Syscall";
|
||||
|
||||
/** The set of implemented MIPS instructions. **/
|
||||
public static InstructionSet instructionSet;
|
||||
/** the program currently being worked with. Used by GUI only, not command line. **/
|
||||
public static MIPSprogram program;
|
||||
/** Symbol table for file currently being assembled. **/
|
||||
public static SymbolTable symbolTable;
|
||||
/** Simulated MIPS memory component. **/
|
||||
public static Memory memory;
|
||||
/** Lock variable used at head of synchronized block to guard MIPS memory and registers **/
|
||||
public static Object memoryAndRegistersLock = new Object();
|
||||
/** Flag to determine whether or not to produce internal debugging information. **/
|
||||
public static boolean debug = false;
|
||||
/** Object that contains various settings that can be accessed modified internally. **/
|
||||
static Settings settings;
|
||||
/** String to GUI's RunI/O text area when echoing user input from pop-up dialog. */
|
||||
public static String userInputAlert = "**** user input : ";
|
||||
/** Path to folder that contains images */
|
||||
public class Globals {
|
||||
/**
|
||||
* Path to folder that contains images
|
||||
*/
|
||||
// The leading "/" in filepath prevents package name from being pre-pended.
|
||||
public static final String imagesPath = "/images/";
|
||||
/** Path to folder that contains help text */
|
||||
public static final String helpPath = "/help/";
|
||||
/* Flag that indicates whether or not instructionSet has been initialized. */
|
||||
private static boolean initialized = false;
|
||||
public static final String imagesPath = "/images/";
|
||||
/**
|
||||
* Path to folder that contains help text
|
||||
*/
|
||||
public static final String helpPath = "/help/";
|
||||
/**
|
||||
* The current MARS version number. Can't wait for "initialize()" call to get it.
|
||||
*/
|
||||
public static final String version = "4.5";
|
||||
/**
|
||||
* MARS copyright years
|
||||
*/
|
||||
public static final String copyrightYears = getCopyrightYears();
|
||||
/**
|
||||
* MARS copyright holders
|
||||
*/
|
||||
public static final String copyrightHolders = getCopyrightHolders();
|
||||
/**
|
||||
* The set of implemented MIPS instructions.
|
||||
**/
|
||||
public static InstructionSet instructionSet;
|
||||
/**
|
||||
* the program currently being worked with. Used by GUI only, not command line.
|
||||
**/
|
||||
public static MIPSprogram program;
|
||||
/**
|
||||
* Symbol table for file currently being assembled.
|
||||
**/
|
||||
public static SymbolTable symbolTable;
|
||||
/**
|
||||
* Simulated MIPS memory component.
|
||||
**/
|
||||
public static Memory memory;
|
||||
/**
|
||||
* Lock variable used at head of synchronized block to guard MIPS memory and registers
|
||||
**/
|
||||
public static Object memoryAndRegistersLock = new Object();
|
||||
/**
|
||||
* Flag to determine whether or not to produce internal debugging information.
|
||||
**/
|
||||
public static boolean debug = false;
|
||||
/**
|
||||
* String to GUI's RunI/O text area when echoing user input from pop-up dialog.
|
||||
*/
|
||||
public static String userInputAlert = "**** user input : ";
|
||||
/**
|
||||
* MARS exit code -- useful with SYSCALL 17 when running from command line (not GUI)
|
||||
*/
|
||||
public static int exitCode = 0;
|
||||
public static boolean runSpeedPanelExists = false;
|
||||
/**
|
||||
* Object that contains various settings that can be accessed modified internally.
|
||||
**/
|
||||
static Settings settings;
|
||||
/* The GUI being used (if any) with this simulator. */
|
||||
static VenusUI gui = null;
|
||||
/** The current MARS version number. Can't wait for "initialize()" call to get it. */
|
||||
public static final String version = "4.5";
|
||||
/** List of accepted file extensions for MIPS assembly source files. */
|
||||
public static final ArrayList fileExtensions = getFileExtensions();
|
||||
/** Maximum length of scrolled message window (MARS Messages and Run I/O) */
|
||||
public static final int maximumMessageCharacters = getMessageLimit();
|
||||
/** Maximum number of assembler errors produced by one assemble operation */
|
||||
public static final int maximumErrorMessages = getErrorLimit();
|
||||
/** Maximum number of back-step operations to buffer */
|
||||
public static final int maximumBacksteps = getBackstepLimit();
|
||||
/** MARS copyright years */
|
||||
public static final String copyrightYears = getCopyrightYears();
|
||||
/** MARS copyright holders */
|
||||
public static final String copyrightHolders = getCopyrightHolders();
|
||||
/** Placeholder for non-printable ASCII codes */
|
||||
public static final String ASCII_NON_PRINT = getAsciiNonPrint();
|
||||
/** Array of strings to display for ASCII codes in ASCII display of data segment. ASCII code 0-255 is array index. */
|
||||
public static final String[] ASCII_TABLE = getAsciiStrings();
|
||||
/** MARS exit code -- useful with SYSCALL 17 when running from command line (not GUI) */
|
||||
public static int exitCode = 0;
|
||||
|
||||
public static boolean runSpeedPanelExists = false;
|
||||
|
||||
private static String getCopyrightYears() {
|
||||
return "2003-2014";
|
||||
}
|
||||
private static String getCopyrightHolders() {
|
||||
return "Pete Sanderson and Kenneth Vollmar";
|
||||
}
|
||||
|
||||
public static void setGui(VenusUI g) {
|
||||
gui = g;
|
||||
}
|
||||
public static VenusUI getGui() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
public static Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
static VenusUI gui = null;
|
||||
// List these first because they are referenced by methods called at initialization.
|
||||
private static final String configPropertiesFile = "Config";
|
||||
/**
|
||||
* List of accepted file extensions for MIPS assembly source files.
|
||||
*/
|
||||
public static final ArrayList fileExtensions = getFileExtensions();
|
||||
/**
|
||||
* Maximum length of scrolled message window (MARS Messages and Run I/O)
|
||||
*/
|
||||
public static final int maximumMessageCharacters = getMessageLimit();
|
||||
/**
|
||||
* Maximum number of assembler errors produced by one assemble operation
|
||||
*/
|
||||
public static final int maximumErrorMessages = getErrorLimit();
|
||||
/**
|
||||
* Maximum number of back-step operations to buffer
|
||||
*/
|
||||
public static final int maximumBacksteps = getBackstepLimit();
|
||||
/**
|
||||
* Placeholder for non-printable ASCII codes
|
||||
*/
|
||||
public static final String ASCII_NON_PRINT = getAsciiNonPrint();
|
||||
/**
|
||||
* Array of strings to display for ASCII codes in ASCII display of data segment. ASCII code 0-255 is array index.
|
||||
*/
|
||||
public static final String[] ASCII_TABLE = getAsciiStrings();
|
||||
private static final String syscallPropertiesFile = "Syscall";
|
||||
/* Flag that indicates whether or not instructionSet has been initialized. */
|
||||
private static boolean initialized = false;
|
||||
|
||||
private static String getCopyrightYears() {
|
||||
return "2003-2014";
|
||||
}
|
||||
|
||||
private static String getCopyrightHolders() {
|
||||
return "Pete Sanderson and Kenneth Vollmar";
|
||||
}
|
||||
|
||||
public static VenusUI getGui() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
public static void setGui(VenusUI g) {
|
||||
gui = g;
|
||||
}
|
||||
|
||||
public static Settings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called once upon system initialization to create the global data structures.
|
||||
**/
|
||||
|
||||
public static void initialize(boolean gui) {
|
||||
if (!initialized) {
|
||||
|
||||
public static void initialize(boolean gui) {
|
||||
if (!initialized) {
|
||||
memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory
|
||||
instructionSet = new InstructionSet();
|
||||
instructionSet.populate();
|
||||
instructionSet.populate();
|
||||
symbolTable = new SymbolTable("global");
|
||||
settings = new Settings(gui);
|
||||
initialized = true;
|
||||
debug = false;
|
||||
memory.clear(); // will establish memory configuration from setting
|
||||
}
|
||||
}
|
||||
|
||||
// Read byte limit of Run I/O or MARS Messages text to buffer.
|
||||
private static int getMessageLimit() {
|
||||
return getIntegerProperty(configPropertiesFile, "MessageLimit", 1000000);
|
||||
}
|
||||
|
||||
// Read limit on number of error messages produced by one assemble operation.
|
||||
private static int getErrorLimit() {
|
||||
return getIntegerProperty(configPropertiesFile, "ErrorLimit", 200);
|
||||
}
|
||||
|
||||
// Read backstep limit (number of operations to buffer) from properties file.
|
||||
private static int getBackstepLimit() {
|
||||
return getIntegerProperty(configPropertiesFile, "BackstepLimit", 1000);
|
||||
}
|
||||
|
||||
// Read ASCII default display character for non-printing characters, from properties file.
|
||||
public static String getAsciiNonPrint() {
|
||||
String anp = getPropertyEntry(configPropertiesFile, "AsciiNonPrint");
|
||||
return (anp == null) ? "." : ( (anp.equals("space")) ? " " : anp );
|
||||
}
|
||||
|
||||
// Read ASCII strings for codes 0-255, from properties file. If string
|
||||
// value is "null", substitute value of ASCII_NON_PRINT. If string is
|
||||
// "space", substitute string containing one space character.
|
||||
public static String[] getAsciiStrings() {
|
||||
String let = getPropertyEntry(configPropertiesFile,"AsciiTable");
|
||||
String placeHolder = getAsciiNonPrint();
|
||||
String[] lets = let.split(" +");
|
||||
int maxLength = 0;
|
||||
for (int i = 0; i < lets.length; i++) {
|
||||
if (lets[i].equals("null")) lets[i] = placeHolder;
|
||||
if (lets[i].equals("space")) lets[i] = " ";
|
||||
if (lets[i].length() > maxLength) maxLength = lets[i].length();
|
||||
}
|
||||
String padding = " ";
|
||||
maxLength++;
|
||||
for (int i = 0; i < lets.length; i++) {
|
||||
lets[i] = padding.substring(0,maxLength-lets[i].length()) + lets[i];
|
||||
}
|
||||
return lets;
|
||||
}
|
||||
|
||||
// Read and return integer property value for given file and property name.
|
||||
// Default value is returned if property file or name not found.
|
||||
private static int getIntegerProperty(String propertiesFile, String propertyName, int defaultValue) {
|
||||
int limit = defaultValue; // just in case no entry is found
|
||||
Properties properties = PropertiesFile.loadPropertiesFromFile(propertiesFile);
|
||||
try {
|
||||
debug = false;
|
||||
memory.clear(); // will establish memory configuration from setting
|
||||
}
|
||||
}
|
||||
|
||||
// Read byte limit of Run I/O or MARS Messages text to buffer.
|
||||
private static int getMessageLimit() {
|
||||
return getIntegerProperty(configPropertiesFile, "MessageLimit", 1000000);
|
||||
}
|
||||
|
||||
// Read limit on number of error messages produced by one assemble operation.
|
||||
private static int getErrorLimit() {
|
||||
return getIntegerProperty(configPropertiesFile, "ErrorLimit", 200);
|
||||
}
|
||||
|
||||
// Read backstep limit (number of operations to buffer) from properties file.
|
||||
private static int getBackstepLimit() {
|
||||
return getIntegerProperty(configPropertiesFile, "BackstepLimit", 1000);
|
||||
}
|
||||
|
||||
// Read ASCII default display character for non-printing characters, from properties file.
|
||||
public static String getAsciiNonPrint() {
|
||||
String anp = getPropertyEntry(configPropertiesFile, "AsciiNonPrint");
|
||||
return (anp == null) ? "." : ((anp.equals("space")) ? " " : anp);
|
||||
}
|
||||
|
||||
// Read ASCII strings for codes 0-255, from properties file. If string
|
||||
// value is "null", substitute value of ASCII_NON_PRINT. If string is
|
||||
// "space", substitute string containing one space character.
|
||||
public static String[] getAsciiStrings() {
|
||||
String let = getPropertyEntry(configPropertiesFile, "AsciiTable");
|
||||
String placeHolder = getAsciiNonPrint();
|
||||
String[] lets = let.split(" +");
|
||||
int maxLength = 0;
|
||||
for (int i = 0; i < lets.length; i++) {
|
||||
if (lets[i].equals("null")) lets[i] = placeHolder;
|
||||
if (lets[i].equals("space")) lets[i] = " ";
|
||||
if (lets[i].length() > maxLength) maxLength = lets[i].length();
|
||||
}
|
||||
String padding = " ";
|
||||
maxLength++;
|
||||
for (int i = 0; i < lets.length; i++) {
|
||||
lets[i] = padding.substring(0, maxLength - lets[i].length()) + lets[i];
|
||||
}
|
||||
return lets;
|
||||
}
|
||||
|
||||
// Read and return integer property value for given file and property name.
|
||||
// Default value is returned if property file or name not found.
|
||||
private static int getIntegerProperty(String propertiesFile, String propertyName, int defaultValue) {
|
||||
int limit = defaultValue; // just in case no entry is found
|
||||
Properties properties = PropertiesFile.loadPropertiesFromFile(propertiesFile);
|
||||
try {
|
||||
limit = Integer.parseInt(properties.getProperty(propertyName, Integer.toString(defaultValue)));
|
||||
}
|
||||
catch (NumberFormatException nfe) { } // do nothing, I already have a default
|
||||
return limit;
|
||||
}
|
||||
|
||||
|
||||
// Read assembly language file extensions from properties file. Resulting
|
||||
// string is tokenized into array list (assume StringTokenizer default delimiters).
|
||||
private static ArrayList getFileExtensions() {
|
||||
ArrayList extensionsList = new ArrayList();
|
||||
String extensions = getPropertyEntry(configPropertiesFile,"Extensions");
|
||||
if (extensions != null) {
|
||||
StringTokenizer st = new StringTokenizer(extensions);
|
||||
while (st.hasMoreTokens()) {
|
||||
extensionsList.add(st.nextToken());
|
||||
}
|
||||
}
|
||||
return extensionsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of MarsTools that reside outside the MARS distribution.
|
||||
* Currently this is done by adding the tool's path name to the list
|
||||
* of values for the external_tools property. Use ";" as delimiter!
|
||||
* @return ArrayList. Each item is file path to .class file
|
||||
* of a class that implements MarsTool. If none, returns empty list.
|
||||
*/
|
||||
public static ArrayList getExternalTools() {
|
||||
ArrayList toolsList = new ArrayList();
|
||||
String delimiter = ";";
|
||||
String tools = getPropertyEntry(configPropertiesFile,"ExternalTools");
|
||||
if (tools != null) {
|
||||
StringTokenizer st = new StringTokenizer(tools, delimiter);
|
||||
while (st.hasMoreTokens()) {
|
||||
toolsList.add(st.nextToken());
|
||||
}
|
||||
}
|
||||
return toolsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and return property file value (if any) for requested property.
|
||||
* @param propertiesFile name of properties file (do NOT include filename extension,
|
||||
* which is assumed to be ".properties")
|
||||
* @param propertyName String containing desired property name
|
||||
* @return String containing associated value; null if property not found
|
||||
*/
|
||||
public static String getPropertyEntry(String propertiesFile, String propertyName) {
|
||||
return PropertiesFile.loadPropertiesFromFile(propertiesFile).getProperty(propertyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read any syscall number assignment overrides from config file.
|
||||
* @return ArrayList of SyscallNumberOverride objects
|
||||
*/
|
||||
public ArrayList getSyscallOverrides() {
|
||||
ArrayList overrides = new ArrayList();
|
||||
Properties properties = PropertiesFile.loadPropertiesFromFile(syscallPropertiesFile);
|
||||
Enumeration keys = properties.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
} catch (NumberFormatException nfe) {
|
||||
} // do nothing, I already have a default
|
||||
return limit;
|
||||
}
|
||||
|
||||
|
||||
// Read assembly language file extensions from properties file. Resulting
|
||||
// string is tokenized into array list (assume StringTokenizer default delimiters).
|
||||
private static ArrayList getFileExtensions() {
|
||||
ArrayList extensionsList = new ArrayList();
|
||||
String extensions = getPropertyEntry(configPropertiesFile, "Extensions");
|
||||
if (extensions != null) {
|
||||
StringTokenizer st = new StringTokenizer(extensions);
|
||||
while (st.hasMoreTokens()) {
|
||||
extensionsList.add(st.nextToken());
|
||||
}
|
||||
}
|
||||
return extensionsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of MarsTools that reside outside the MARS distribution.
|
||||
* Currently this is done by adding the tool's path name to the list
|
||||
* of values for the external_tools property. Use ";" as delimiter!
|
||||
*
|
||||
* @return ArrayList. Each item is file path to .class file
|
||||
* of a class that implements MarsTool. If none, returns empty list.
|
||||
*/
|
||||
public static ArrayList getExternalTools() {
|
||||
ArrayList toolsList = new ArrayList();
|
||||
String delimiter = ";";
|
||||
String tools = getPropertyEntry(configPropertiesFile, "ExternalTools");
|
||||
if (tools != null) {
|
||||
StringTokenizer st = new StringTokenizer(tools, delimiter);
|
||||
while (st.hasMoreTokens()) {
|
||||
toolsList.add(st.nextToken());
|
||||
}
|
||||
}
|
||||
return toolsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and return property file value (if any) for requested property.
|
||||
*
|
||||
* @param propertiesFile name of properties file (do NOT include filename extension,
|
||||
* which is assumed to be ".properties")
|
||||
* @param propertyName String containing desired property name
|
||||
* @return String containing associated value; null if property not found
|
||||
*/
|
||||
public static String getPropertyEntry(String propertiesFile, String propertyName) {
|
||||
return PropertiesFile.loadPropertiesFromFile(propertiesFile).getProperty(propertyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read any syscall number assignment overrides from config file.
|
||||
*
|
||||
* @return ArrayList of SyscallNumberOverride objects
|
||||
*/
|
||||
public ArrayList getSyscallOverrides() {
|
||||
ArrayList overrides = new ArrayList();
|
||||
Properties properties = PropertiesFile.loadPropertiesFromFile(syscallPropertiesFile);
|
||||
Enumeration keys = properties.keys();
|
||||
while (keys.hasMoreElements()) {
|
||||
String key = (String) keys.nextElement();
|
||||
overrides.add(new SyscallNumberOverride(key,properties.getProperty(key)));
|
||||
}
|
||||
return overrides;
|
||||
}
|
||||
|
||||
}
|
||||
overrides.add(new SyscallNumberOverride(key, properties.getProperty(key)));
|
||||
}
|
||||
return overrides;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+1364
-1293
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,13 @@
|
||||
package mars.mips.hardware;
|
||||
import mars.*;
|
||||
import mars.util.*;
|
||||
import mars.simulator.*;
|
||||
import mars.mips.instructions.*;
|
||||
import java.util.*;
|
||||
package mars.mips.hardware;
|
||||
|
||||
import mars.Globals;
|
||||
import mars.ProgramStatement;
|
||||
import mars.Settings;
|
||||
import mars.mips.instructions.Instruction;
|
||||
import mars.simulator.Exceptions;
|
||||
import mars.util.Binary;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2009, Pete Sanderson and Kenneth Vollmar
|
||||
@@ -768,11 +772,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
value = fetchWordOrNullFromTable(stackBlockTable, relative);
|
||||
}
|
||||
else if (inTextSegment(address) || inKernelTextSegment(address)) {
|
||||
try {
|
||||
value = (getStatementNoNotify(address) == null) ? null : new Integer(getStatementNoNotify(address).getBinaryStatement());
|
||||
}
|
||||
catch (AddressErrorException aee) {
|
||||
value = null; }
|
||||
try {
|
||||
value = (getStatementNoNotify(address) == null) ? null : getStatementNoNotify(address).getBinaryStatement();
|
||||
} catch (AddressErrorException aee) {
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
else if (inKernelDataSegment(address)) {
|
||||
// in kernel data segment
|
||||
@@ -1382,7 +1386,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
else {
|
||||
value = blockTable[block][offset];
|
||||
}
|
||||
return new Integer(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1,11 +1,25 @@
|
||||
package mars.mips.instructions;
|
||||
import mars.simulator.*;
|
||||
import mars.mips.hardware.*;
|
||||
import mars.mips.instructions.syscalls.*;
|
||||
import mars.*;
|
||||
import mars.util.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
package mars.mips.instructions;
|
||||
|
||||
import mars.Globals;
|
||||
import mars.ProcessingException;
|
||||
import mars.ProgramStatement;
|
||||
import mars.mips.hardware.AddressErrorException;
|
||||
import mars.mips.hardware.Coprocessor0;
|
||||
import mars.mips.hardware.Coprocessor1;
|
||||
import mars.mips.hardware.RegisterFile;
|
||||
import mars.mips.instructions.syscalls.Syscall;
|
||||
import mars.simulator.DelayedBranch;
|
||||
import mars.simulator.Exceptions;
|
||||
import mars.util.Binary;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar
|
||||
@@ -1672,7 +1686,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
round = Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
Float floatObj = new Float(floatValue);
|
||||
Float floatObj = floatValue;
|
||||
// If we are EXACTLY in the middle, then round to even! To determine this,
|
||||
// find next higher integer and next lower integer, then see if distances
|
||||
// are exactly equal.
|
||||
@@ -1920,7 +1934,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
round = Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
Double doubleObj = new Double(doubleValue);
|
||||
Double doubleObj = doubleValue;
|
||||
// If we are EXACTLY in the middle, then round to even! To determine this,
|
||||
// find next higher integer and next lower integer, then see if distances
|
||||
// are exactly equal.
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package mars.mips.instructions.syscalls;
|
||||
import mars.util.*;
|
||||
import mars.mips.hardware.*;
|
||||
import mars.*;
|
||||
package mars.mips.instructions.syscalls;
|
||||
|
||||
import mars.ProcessingException;
|
||||
import mars.ProgramStatement;
|
||||
import mars.mips.hardware.Coprocessor1;
|
||||
import mars.util.SystemIO;
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar
|
||||
@@ -44,12 +46,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
public SyscallPrintFloat() {
|
||||
super(2, "PrintFloat");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs syscall function to display float whose bits are stored in $f12
|
||||
*/
|
||||
public void simulate(ProgramStatement statement) throws ProcessingException {
|
||||
SystemIO.printString(new Float(Float.intBitsToFloat(
|
||||
Coprocessor1.getValue(12))).toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs syscall function to display float whose bits are stored in $f12
|
||||
*/
|
||||
public void simulate(ProgramStatement statement) throws ProcessingException {
|
||||
SystemIO.printString(Float.toString(Float.intBitsToFloat(
|
||||
Coprocessor1.getValue(12))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package mars.mips.instructions.syscalls;
|
||||
import mars.util.*;
|
||||
import mars.mips.hardware.*;
|
||||
import mars.*;
|
||||
package mars.mips.instructions.syscalls;
|
||||
|
||||
import mars.ProcessingException;
|
||||
import mars.ProgramStatement;
|
||||
import mars.mips.hardware.RegisterFile;
|
||||
import mars.util.SystemIO;
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar
|
||||
@@ -50,7 +52,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
* Performs syscall function to print on the console the integer stored in $a0.
|
||||
*/
|
||||
public void simulate(ProgramStatement statement) throws ProcessingException {
|
||||
SystemIO.printString(
|
||||
new Integer(RegisterFile.getValue(4)).toString());
|
||||
}
|
||||
}
|
||||
SystemIO.printString(
|
||||
Integer.toString(RegisterFile.getValue(4)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,356 +1,357 @@
|
||||
package mars.tools;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import mars.Globals;
|
||||
import mars.mips.hardware.AddressErrorException;
|
||||
import mars.mips.hardware.Coprocessor0;
|
||||
import mars.mips.hardware.Memory;
|
||||
import mars.mips.hardware.MemoryAccessNotice;
|
||||
import mars.simulator.Exceptions;
|
||||
@SuppressWarnings("serial")
|
||||
/* Add these two lines in exceptions.java file
|
||||
* public static final int EXTERNAL_INTERRUPT_TIMER = 0x00000100; //Add for digital Lab Sim
|
||||
* public static final int EXTERNAL_INTERRUPT_HEXA_KEYBOARD = 0x00000200;// Add for digital Lab Sim
|
||||
*/
|
||||
|
||||
/*
|
||||
* Didier Teifreto LIFC Université de franche-Comté www.lifc.univ-fcomte.fr/~teifreto
|
||||
* didier.teifreto@univ-fcomte.fr
|
||||
*/
|
||||
public class DigitalLabSim extends AbstractMarsToolAndApplication {
|
||||
private static String heading = "Digital Lab Sim";
|
||||
private static String version = " Version 1.0 (Didier Teifreto)";
|
||||
private static final int IN_ADRESS_DISPLAY_1=Memory.memoryMapBaseAddress+0x10;
|
||||
private static final int IN_ADRESS_DISPLAY_2=Memory.memoryMapBaseAddress+0x11;
|
||||
private static final int IN_ADRESS_HEXA_KEYBOARD=Memory.memoryMapBaseAddress+0x12;
|
||||
private static final int IN_ADRESS_COUNTER=Memory.memoryMapBaseAddress+0x13;
|
||||
private static final int OUT_ADRESS_HEXA_KEYBOARD=Memory.memoryMapBaseAddress+0x14;
|
||||
|
||||
public static final int EXTERNAL_INTERRUPT_TIMER = 0x00000100; //Add for digital Lab Sim
|
||||
public static final int EXTERNAL_INTERRUPT_HEXA_KEYBOARD = 0x00000200;// Add for digital Lab Sim
|
||||
|
||||
// GUI Interface.
|
||||
private static JPanel panelTools;
|
||||
// Seven Segment display
|
||||
private SevenSegmentPanel sevenSegPanel;
|
||||
// Keyboard
|
||||
private static int KeyBoardValueButtonClick=-1; // -1 no button click
|
||||
private HexaKeyboard hexaKeyPanel;
|
||||
private static boolean KeyboardInterruptOnOff=false;
|
||||
// Counter
|
||||
private static int CounterValueMax=30;
|
||||
private static int CounterValue=CounterValueMax;
|
||||
private static boolean CounterInterruptOnOff=false;
|
||||
private static OneSecondCounter SecondCounter;
|
||||
|
||||
public DigitalLabSim(String title, String heading) {
|
||||
super(title,heading);
|
||||
}
|
||||
public DigitalLabSim() {
|
||||
super (heading+", "+version, heading);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
new DigitalLabSim(heading+", "+version,heading).go();
|
||||
}
|
||||
public String getName() {
|
||||
return "Digital Lab Sim";
|
||||
}
|
||||
protected void addAsObserver(){
|
||||
addAsObserver(IN_ADRESS_DISPLAY_1, IN_ADRESS_DISPLAY_1);
|
||||
addAsObserver(Memory.textBaseAddress, Memory.textLimitAddress);
|
||||
}
|
||||
public void update(Observable ressource, Object accessNotice){
|
||||
MemoryAccessNotice notice = (MemoryAccessNotice) accessNotice;
|
||||
int address=notice.getAddress();
|
||||
char value=(char)notice.getValue();
|
||||
if(address == IN_ADRESS_DISPLAY_1)
|
||||
updateSevenSegment(1, value);
|
||||
else
|
||||
if (address == IN_ADRESS_DISPLAY_2)
|
||||
updateSevenSegment(0, value);
|
||||
else
|
||||
if (address == IN_ADRESS_HEXA_KEYBOARD)
|
||||
updateHexaKeyboard(value);
|
||||
else
|
||||
if (address == IN_ADRESS_COUNTER)
|
||||
updateOneSecondCounter(value);
|
||||
if (CounterInterruptOnOff)
|
||||
if (CounterValue >0){
|
||||
CounterValue--;
|
||||
}
|
||||
else{
|
||||
CounterValue=CounterValueMax;
|
||||
if((Coprocessor0.getValue(Coprocessor0.STATUS) & 2)==0){
|
||||
mars.simulator.Simulator.externalInterruptingDevice = /*Exceptions.*/EXTERNAL_INTERRUPT_TIMER;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void reset(){
|
||||
sevenSegPanel.resetSevenSegment();
|
||||
hexaKeyPanel.resetHexaKeyboard();
|
||||
SecondCounter.resetOneSecondCounter();
|
||||
}
|
||||
protected JComponent buildMainDisplayArea() {
|
||||
panelTools=new JPanel(new GridLayout(1,2));
|
||||
sevenSegPanel=new SevenSegmentPanel();
|
||||
panelTools.add(sevenSegPanel);
|
||||
hexaKeyPanel = new HexaKeyboard();
|
||||
panelTools.add(hexaKeyPanel);
|
||||
SecondCounter= new OneSecondCounter();
|
||||
return panelTools;
|
||||
}
|
||||
private synchronized void updateMMIOControlAndData(int dataAddr, int dataValue) {
|
||||
if (!this.isBeingUsedAsAMarsTool || (this.isBeingUsedAsAMarsTool && connectButton.isConnected())) {
|
||||
synchronized (Globals.memoryAndRegistersLock) {
|
||||
try {
|
||||
Globals.memory.setByte(dataAddr, dataValue);
|
||||
}
|
||||
catch (AddressErrorException aee) {
|
||||
System.out.println("Tool author specified incorrect MMIO address!"+aee);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
if (Globals.getGui() != null && Globals.getGui().getMainPane().getExecutePane().getTextSegmentWindow().getCodeHighlighting() ) {
|
||||
Globals.getGui().getMainPane().getExecutePane().getDataSegmentWindow().updateValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected JComponent getHelpComponent() {
|
||||
final String helpContent =
|
||||
" This tool is composed of 3 parts : two seven-segment displays, an hexadecimal keyboard and counter \n"+
|
||||
"Seven segment display\n"+
|
||||
" Byte value at address 0xFFFF0010 : command right seven segment display \n "+
|
||||
" Byte value at address 0xFFFF0011 : command left seven segment display \n "+
|
||||
" Each bit of these two bytes are connected to segments (bit 0 for a segment, 1 for b segment and 7 for point \n \n"+
|
||||
"Hexadecimal keyboard\n"+
|
||||
" Byte value at address 0xFFFF0012 : command row number of hexadecimal keyboard (bit 0 to 3) and enable keyboard interrupt (bit 7) \n" +
|
||||
" Byte value at address 0xFFFF0014 : receive row and column of the key pressed, 0 if not key pressed \n"+
|
||||
" The mips program have to scan, one by one, each row (send 1,2,4,8...)"+
|
||||
" and then observe if a key is pressed (that mean byte value at adresse 0xFFFF0014 is different from zero). "+
|
||||
" This byte value is composed of row number (4 left bits) and column number (4 right bits)"+
|
||||
" Here you'll find the code for each key : 0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,0x14,0x24,0x44,0x84,0x18,0x28,0x48,0x88. \n"+
|
||||
" For exemple key number 2 return 0x41, that mean the key is on column 3 and row 1. \n"+
|
||||
" If keyboard interruption is enable, an exception is started, with cause register bit number 11 set.\n \n"+
|
||||
"Counter\n"+
|
||||
" Byte value at address 0xFFFF0013 : If one bit of this byte is set, the counter interruption is enable.\n"+
|
||||
" If counter interruption is enable, every 30 instructions, an exception is started with cause register bit number 10.\n" +
|
||||
" (contributed by Didier Teifreto, dteifreto@lifc.univ-fcomte.fr)"
|
||||
;
|
||||
JButton help = new JButton("Help");
|
||||
help.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JTextArea ja = new JTextArea(helpContent);
|
||||
ja.setRows(20);
|
||||
ja.setColumns(60);
|
||||
ja.setLineWrap(true);
|
||||
ja.setWrapStyleWord(true);
|
||||
JOptionPane.showMessageDialog(theWindow, new JScrollPane(ja),
|
||||
"Simulating the Hexa Keyboard and Seven segment display", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
return help;
|
||||
}/* ....................Seven Segment display start here................................... */
|
||||
/* ...........................Seven segment display start here ..............................*/
|
||||
public void updateSevenSegment(int number,char value) {
|
||||
sevenSegPanel.display[number].modifyDisplay(value);
|
||||
}
|
||||
public class SevenSegmentDisplay extends JComponent {
|
||||
public char aff;
|
||||
public SevenSegmentDisplay(char aff){
|
||||
this.aff=aff;
|
||||
this.setPreferredSize(new Dimension(60,80));
|
||||
}
|
||||
public void modifyDisplay(char val){
|
||||
aff=val;
|
||||
this.repaint();
|
||||
}
|
||||
public void SwitchSegment(Graphics g,char segment){
|
||||
switch(segment){
|
||||
case 'a': //a segment
|
||||
int[]pxa1={12,9,12};
|
||||
int[]pxa2={36,39,36};
|
||||
int[]pya={5,8,11};
|
||||
g.fillPolygon(pxa1,pya, 3);
|
||||
g.fillPolygon(pxa2,pya, 3);
|
||||
g.fillRect(12,5,24,6);
|
||||
break;
|
||||
case 'b': //b segment
|
||||
int[]pxb={37,40,43};
|
||||
int[]pyb1={12,9,12};
|
||||
int[]pyb2={36,39,36};
|
||||
g.fillPolygon(pxb,pyb1, 3);
|
||||
g.fillPolygon(pxb,pyb2, 3);
|
||||
g.fillRect(37,12,6,24);
|
||||
break;
|
||||
case 'c': // c segment
|
||||
int[]pxc={37,40,43};
|
||||
int[]pyc1={44,41,44};
|
||||
int[]pyc2={68,71,68};
|
||||
g.fillPolygon(pxc,pyc1, 3);
|
||||
g.fillPolygon(pxc,pyc2, 3);
|
||||
g.fillRect(37,44,6,24);
|
||||
break;
|
||||
case 'd': // d segment
|
||||
int[]pxd1={12,9,12};
|
||||
int[]pxd2={36,39,36};
|
||||
int[]pyd={69,72,75};
|
||||
g.fillPolygon(pxd1,pyd, 3);
|
||||
g.fillPolygon(pxd2,pyd, 3);
|
||||
g.fillRect(12,69,24,6);
|
||||
break;
|
||||
case 'e': // e segment
|
||||
int[]pxe={5,8,11};
|
||||
int[]pye1={44,41,44};
|
||||
int[]pye2={68,71,68};
|
||||
g.fillPolygon(pxe,pye1, 3);
|
||||
g.fillPolygon(pxe,pye2, 3);
|
||||
g.fillRect(5,44,6,24);
|
||||
break;
|
||||
case 'f': // f segment
|
||||
int[]pxf={5,8,11};
|
||||
int[]pyf1={12,9,12};
|
||||
int[]pyf2={36,39,36};
|
||||
g.fillPolygon(pxf,pyf1, 3);
|
||||
g.fillPolygon(pxf,pyf2, 3);
|
||||
g.fillRect(5,12,6,24);
|
||||
break;
|
||||
case 'g': // g segment
|
||||
int[]pxg1={12,9,12};
|
||||
int[]pxg2={36,39,36};
|
||||
int[]pyg={37,40,43};
|
||||
g.fillPolygon(pxg1,pyg, 3);
|
||||
g.fillPolygon(pxg2,pyg, 3);
|
||||
g.fillRect(12,37,24,6);
|
||||
break;
|
||||
case 'h': // decimal point
|
||||
g.fillOval(49,68,8,8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void paint(Graphics g) {
|
||||
char c='a';
|
||||
while(c<='h'){
|
||||
if ((aff & 0x1) == 1)
|
||||
g.setColor(Color.RED);
|
||||
else
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
SwitchSegment(g,c);
|
||||
aff = (char)(aff >>>1);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SevenSegmentPanel extends JPanel {
|
||||
public SevenSegmentDisplay[] display;
|
||||
public SevenSegmentPanel(){
|
||||
int i;
|
||||
FlowLayout fl= new FlowLayout();
|
||||
this.setLayout(fl);
|
||||
display= new SevenSegmentDisplay[2];
|
||||
for (i=0;i<2;i++){
|
||||
display[i]= new SevenSegmentDisplay((char)(0));
|
||||
this.add(display[i]);
|
||||
}
|
||||
}
|
||||
public void modifyDisplay(int num,char val){
|
||||
display[num].modifyDisplay(val);
|
||||
display[num].repaint();
|
||||
}
|
||||
public void resetSevenSegment() {
|
||||
int i;
|
||||
for (i=0;i<2;i++)
|
||||
modifyDisplay(i, (char)0);
|
||||
}
|
||||
}
|
||||
/* ...........................Seven segment display end here ..............................*/
|
||||
/* ....................Hexa Keyboard start here................................... */
|
||||
public void updateHexaKeyboard(char row) {
|
||||
int key = KeyBoardValueButtonClick;
|
||||
if ((key !=-1)&& ((1 << (key / 4))==(row & 0xF))){
|
||||
updateMMIOControlAndData(OUT_ADRESS_HEXA_KEYBOARD,
|
||||
(char)(1 << (key / 4)) | (1 << (4+(key%4))));
|
||||
}
|
||||
else{
|
||||
updateMMIOControlAndData(OUT_ADRESS_HEXA_KEYBOARD, 0);
|
||||
}
|
||||
if ((row & 0xF0) != 0)
|
||||
KeyboardInterruptOnOff = true;
|
||||
else
|
||||
KeyboardInterruptOnOff = false;
|
||||
}
|
||||
public class HexaKeyboard extends JPanel{
|
||||
public JButton[] button;
|
||||
public HexaKeyboard(){
|
||||
int i;
|
||||
GridLayout layout = new GridLayout(4,4);
|
||||
this.setLayout(layout);
|
||||
button = new JButton[16];
|
||||
for (i=0;i<16;i++){
|
||||
button[i]= new JButton(Integer.toHexString(i));
|
||||
button[i].setBackground(Color.WHITE);
|
||||
button[i].setMargin(new Insets(10,10,10,10));
|
||||
button[i].addMouseListener(new EcouteurClick(i));
|
||||
this.add(button[i]);
|
||||
}
|
||||
}
|
||||
public void resetHexaKeyboard(){
|
||||
int i;
|
||||
KeyBoardValueButtonClick=-1;
|
||||
for(i=0;i<16;i++){
|
||||
button[i].setBackground(Color.WHITE);
|
||||
}
|
||||
}
|
||||
public class EcouteurClick implements MouseListener{
|
||||
private int buttonValue;
|
||||
public EcouteurClick(int val){
|
||||
buttonValue=val;
|
||||
}
|
||||
public void mouseEntered(MouseEvent arg0) { }
|
||||
public void mouseExited(MouseEvent arg0) {}
|
||||
public void mousePressed(MouseEvent arg0) {}
|
||||
public void mouseReleased(MouseEvent arg0) {}
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
int i;
|
||||
if(KeyBoardValueButtonClick!=-1){//Button already pressed -> now realease
|
||||
KeyBoardValueButtonClick = -1;
|
||||
updateMMIOControlAndData(OUT_ADRESS_HEXA_KEYBOARD,0);
|
||||
for(i=0;i<16;i++)
|
||||
button[i].setBackground(Color.WHITE);
|
||||
}
|
||||
else{ // new button pressed
|
||||
KeyBoardValueButtonClick = buttonValue;
|
||||
button[KeyBoardValueButtonClick].setBackground(Color.GREEN);
|
||||
if( KeyboardInterruptOnOff && (Coprocessor0.getValue(Coprocessor0.STATUS) & 2)==0){
|
||||
mars.simulator.Simulator.externalInterruptingDevice = /*Exceptions.*/EXTERNAL_INTERRUPT_HEXA_KEYBOARD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* ....................Hexa Keyboard end here................................... */
|
||||
/* ....................Timer start here................................... */
|
||||
public void updateOneSecondCounter(char value) {
|
||||
if (value !=0){
|
||||
CounterInterruptOnOff=true;
|
||||
CounterValue=CounterValueMax;
|
||||
}
|
||||
else{
|
||||
CounterInterruptOnOff=false;
|
||||
}
|
||||
}
|
||||
public class OneSecondCounter{
|
||||
public OneSecondCounter(){
|
||||
CounterInterruptOnOff=false;
|
||||
}
|
||||
public void resetOneSecondCounter(){
|
||||
CounterInterruptOnOff=false;
|
||||
CounterValue=CounterValueMax;
|
||||
}
|
||||
}
|
||||
}
|
||||
package mars.tools;
|
||||
|
||||
import mars.Globals;
|
||||
import mars.mips.hardware.AddressErrorException;
|
||||
import mars.mips.hardware.Coprocessor0;
|
||||
import mars.mips.hardware.Memory;
|
||||
import mars.mips.hardware.MemoryAccessNotice;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.Observable;
|
||||
@SuppressWarnings("serial")
|
||||
/* Add these two lines in exceptions.java file
|
||||
* public static final int EXTERNAL_INTERRUPT_TIMER = 0x00000100; //Add for digital Lab Sim
|
||||
* public static final int EXTERNAL_INTERRUPT_HEXA_KEYBOARD = 0x00000200;// Add for digital Lab Sim
|
||||
*/
|
||||
|
||||
/*
|
||||
* Didier Teifreto LIFC Université de franche-Comté www.lifc.univ-fcomte.fr/~teifreto
|
||||
* didier.teifreto@univ-fcomte.fr
|
||||
*/
|
||||
public class DigitalLabSim extends AbstractMarsToolAndApplication {
|
||||
private static String heading = "Digital Lab Sim";
|
||||
private static String version = " Version 1.0 (Didier Teifreto)";
|
||||
private static final int IN_ADRESS_DISPLAY_1=Memory.memoryMapBaseAddress+0x10;
|
||||
private static final int IN_ADRESS_DISPLAY_2=Memory.memoryMapBaseAddress+0x11;
|
||||
private static final int IN_ADRESS_HEXA_KEYBOARD=Memory.memoryMapBaseAddress+0x12;
|
||||
private static final int IN_ADRESS_COUNTER=Memory.memoryMapBaseAddress+0x13;
|
||||
private static final int OUT_ADRESS_HEXA_KEYBOARD=Memory.memoryMapBaseAddress+0x14;
|
||||
|
||||
public static final int EXTERNAL_INTERRUPT_TIMER = 0x00000100; //Add for digital Lab Sim
|
||||
public static final int EXTERNAL_INTERRUPT_HEXA_KEYBOARD = 0x00000200;// Add for digital Lab Sim
|
||||
|
||||
// GUI Interface.
|
||||
private static JPanel panelTools;
|
||||
// Seven Segment display
|
||||
private SevenSegmentPanel sevenSegPanel;
|
||||
// Keyboard
|
||||
private static int KeyBoardValueButtonClick=-1; // -1 no button click
|
||||
private HexaKeyboard hexaKeyPanel;
|
||||
private static boolean KeyboardInterruptOnOff=false;
|
||||
// Counter
|
||||
private static int CounterValueMax=30;
|
||||
private static int CounterValue=CounterValueMax;
|
||||
private static boolean CounterInterruptOnOff=false;
|
||||
private static OneSecondCounter SecondCounter;
|
||||
|
||||
public DigitalLabSim(String title, String heading) {
|
||||
super(title,heading);
|
||||
}
|
||||
public DigitalLabSim() {
|
||||
super (heading+", "+version, heading);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
new DigitalLabSim(heading+", "+version,heading).go();
|
||||
}
|
||||
public String getName() {
|
||||
return "Digital Lab Sim";
|
||||
}
|
||||
protected void addAsObserver(){
|
||||
addAsObserver(IN_ADRESS_DISPLAY_1, IN_ADRESS_DISPLAY_1);
|
||||
addAsObserver(Memory.textBaseAddress, Memory.textLimitAddress);
|
||||
}
|
||||
public void update(Observable ressource, Object accessNotice){
|
||||
MemoryAccessNotice notice = (MemoryAccessNotice) accessNotice;
|
||||
int address=notice.getAddress();
|
||||
char value=(char)notice.getValue();
|
||||
if(address == IN_ADRESS_DISPLAY_1)
|
||||
updateSevenSegment(1, value);
|
||||
else
|
||||
if (address == IN_ADRESS_DISPLAY_2)
|
||||
updateSevenSegment(0, value);
|
||||
else
|
||||
if (address == IN_ADRESS_HEXA_KEYBOARD)
|
||||
updateHexaKeyboard(value);
|
||||
else
|
||||
if (address == IN_ADRESS_COUNTER)
|
||||
updateOneSecondCounter(value);
|
||||
if (CounterInterruptOnOff)
|
||||
if (CounterValue >0){
|
||||
CounterValue--;
|
||||
}
|
||||
else{
|
||||
CounterValue=CounterValueMax;
|
||||
if((Coprocessor0.getValue(Coprocessor0.STATUS) & 2)==0){
|
||||
mars.simulator.Simulator.externalInterruptingDevice = /*Exceptions.*/EXTERNAL_INTERRUPT_TIMER;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void reset(){
|
||||
sevenSegPanel.resetSevenSegment();
|
||||
hexaKeyPanel.resetHexaKeyboard();
|
||||
SecondCounter.resetOneSecondCounter();
|
||||
}
|
||||
protected JComponent buildMainDisplayArea() {
|
||||
panelTools=new JPanel(new GridLayout(1,2));
|
||||
sevenSegPanel=new SevenSegmentPanel();
|
||||
panelTools.add(sevenSegPanel);
|
||||
hexaKeyPanel = new HexaKeyboard();
|
||||
panelTools.add(hexaKeyPanel);
|
||||
SecondCounter= new OneSecondCounter();
|
||||
return panelTools;
|
||||
}
|
||||
private synchronized void updateMMIOControlAndData(int dataAddr, int dataValue) {
|
||||
if (!this.isBeingUsedAsAMarsTool || (this.isBeingUsedAsAMarsTool && connectButton.isConnected())) {
|
||||
synchronized (Globals.memoryAndRegistersLock) {
|
||||
try {
|
||||
Globals.memory.setByte(dataAddr, dataValue);
|
||||
}
|
||||
catch (AddressErrorException aee) {
|
||||
System.out.println("Tool author specified incorrect MMIO address!"+aee);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
if (Globals.getGui() != null && Globals.getGui().getMainPane().getExecutePane().getTextSegmentWindow().getCodeHighlighting() ) {
|
||||
Globals.getGui().getMainPane().getExecutePane().getDataSegmentWindow().updateValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
protected JComponent getHelpComponent() {
|
||||
final String helpContent =
|
||||
" This tool is composed of 3 parts : two seven-segment displays, an hexadecimal keyboard and counter \n"+
|
||||
"Seven segment display\n"+
|
||||
" Byte value at address 0xFFFF0010 : command right seven segment display \n "+
|
||||
" Byte value at address 0xFFFF0011 : command left seven segment display \n "+
|
||||
" Each bit of these two bytes are connected to segments (bit 0 for a segment, 1 for b segment and 7 for point \n \n"+
|
||||
"Hexadecimal keyboard\n"+
|
||||
" Byte value at address 0xFFFF0012 : command row number of hexadecimal keyboard (bit 0 to 3) and enable keyboard interrupt (bit 7) \n" +
|
||||
" Byte value at address 0xFFFF0014 : receive row and column of the key pressed, 0 if not key pressed \n"+
|
||||
" The mips program have to scan, one by one, each row (send 1,2,4,8...)"+
|
||||
" and then observe if a key is pressed (that mean byte value at adresse 0xFFFF0014 is different from zero). "+
|
||||
" This byte value is composed of row number (4 left bits) and column number (4 right bits)"+
|
||||
" Here you'll find the code for each key : 0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,0x14,0x24,0x44,0x84,0x18,0x28,0x48,0x88. \n"+
|
||||
" For exemple key number 2 return 0x41, that mean the key is on column 3 and row 1. \n"+
|
||||
" If keyboard interruption is enable, an exception is started, with cause register bit number 11 set.\n \n"+
|
||||
"Counter\n"+
|
||||
" Byte value at address 0xFFFF0013 : If one bit of this byte is set, the counter interruption is enable.\n"+
|
||||
" If counter interruption is enable, every 30 instructions, an exception is started with cause register bit number 10.\n" +
|
||||
" (contributed by Didier Teifreto, dteifreto@lifc.univ-fcomte.fr)"
|
||||
;
|
||||
JButton help = new JButton("Help");
|
||||
help.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JTextArea ja = new JTextArea(helpContent);
|
||||
ja.setRows(20);
|
||||
ja.setColumns(60);
|
||||
ja.setLineWrap(true);
|
||||
ja.setWrapStyleWord(true);
|
||||
JOptionPane.showMessageDialog(theWindow, new JScrollPane(ja),
|
||||
"Simulating the Hexa Keyboard and Seven segment display", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
});
|
||||
return help;
|
||||
}/* ....................Seven Segment display start here................................... */
|
||||
/* ...........................Seven segment display start here ..............................*/
|
||||
public void updateSevenSegment(int number,char value) {
|
||||
sevenSegPanel.display[number].modifyDisplay(value);
|
||||
}
|
||||
public class SevenSegmentDisplay extends JComponent {
|
||||
public char aff;
|
||||
public SevenSegmentDisplay(char aff){
|
||||
this.aff=aff;
|
||||
this.setPreferredSize(new Dimension(60,80));
|
||||
}
|
||||
public void modifyDisplay(char val){
|
||||
aff=val;
|
||||
this.repaint();
|
||||
}
|
||||
public void SwitchSegment(Graphics g,char segment){
|
||||
switch(segment){
|
||||
case 'a': //a segment
|
||||
int[]pxa1={12,9,12};
|
||||
int[]pxa2={36,39,36};
|
||||
int[]pya={5,8,11};
|
||||
g.fillPolygon(pxa1,pya, 3);
|
||||
g.fillPolygon(pxa2,pya, 3);
|
||||
g.fillRect(12,5,24,6);
|
||||
break;
|
||||
case 'b': //b segment
|
||||
int[]pxb={37,40,43};
|
||||
int[]pyb1={12,9,12};
|
||||
int[]pyb2={36,39,36};
|
||||
g.fillPolygon(pxb,pyb1, 3);
|
||||
g.fillPolygon(pxb,pyb2, 3);
|
||||
g.fillRect(37,12,6,24);
|
||||
break;
|
||||
case 'c': // c segment
|
||||
int[]pxc={37,40,43};
|
||||
int[]pyc1={44,41,44};
|
||||
int[]pyc2={68,71,68};
|
||||
g.fillPolygon(pxc,pyc1, 3);
|
||||
g.fillPolygon(pxc,pyc2, 3);
|
||||
g.fillRect(37,44,6,24);
|
||||
break;
|
||||
case 'd': // d segment
|
||||
int[]pxd1={12,9,12};
|
||||
int[]pxd2={36,39,36};
|
||||
int[]pyd={69,72,75};
|
||||
g.fillPolygon(pxd1,pyd, 3);
|
||||
g.fillPolygon(pxd2,pyd, 3);
|
||||
g.fillRect(12,69,24,6);
|
||||
break;
|
||||
case 'e': // e segment
|
||||
int[]pxe={5,8,11};
|
||||
int[]pye1={44,41,44};
|
||||
int[]pye2={68,71,68};
|
||||
g.fillPolygon(pxe,pye1, 3);
|
||||
g.fillPolygon(pxe,pye2, 3);
|
||||
g.fillRect(5,44,6,24);
|
||||
break;
|
||||
case 'f': // f segment
|
||||
int[]pxf={5,8,11};
|
||||
int[]pyf1={12,9,12};
|
||||
int[]pyf2={36,39,36};
|
||||
g.fillPolygon(pxf,pyf1, 3);
|
||||
g.fillPolygon(pxf,pyf2, 3);
|
||||
g.fillRect(5,12,6,24);
|
||||
break;
|
||||
case 'g': // g segment
|
||||
int[]pxg1={12,9,12};
|
||||
int[]pxg2={36,39,36};
|
||||
int[]pyg={37,40,43};
|
||||
g.fillPolygon(pxg1,pyg, 3);
|
||||
g.fillPolygon(pxg2,pyg, 3);
|
||||
g.fillRect(12,37,24,6);
|
||||
break;
|
||||
case 'h': // decimal point
|
||||
g.fillOval(49,68,8,8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void paint(Graphics g) {
|
||||
char c='a';
|
||||
while(c<='h'){
|
||||
if ((aff & 0x1) == 1)
|
||||
g.setColor(Color.RED);
|
||||
else
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
SwitchSegment(g,c);
|
||||
aff = (char)(aff >>>1);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SevenSegmentPanel extends JPanel {
|
||||
public SevenSegmentDisplay[] display;
|
||||
public SevenSegmentPanel(){
|
||||
int i;
|
||||
FlowLayout fl= new FlowLayout();
|
||||
this.setLayout(fl);
|
||||
display= new SevenSegmentDisplay[2];
|
||||
for (i=0;i<2;i++){
|
||||
display[i]= new SevenSegmentDisplay((char)(0));
|
||||
this.add(display[i]);
|
||||
}
|
||||
}
|
||||
public void modifyDisplay(int num,char val){
|
||||
display[num].modifyDisplay(val);
|
||||
display[num].repaint();
|
||||
}
|
||||
public void resetSevenSegment() {
|
||||
int i;
|
||||
for (i=0;i<2;i++)
|
||||
modifyDisplay(i, (char)0);
|
||||
}
|
||||
}
|
||||
/* ...........................Seven segment display end here ..............................*/
|
||||
/* ....................Hexa Keyboard start here................................... */
|
||||
public void updateHexaKeyboard(char row) {
|
||||
int key = KeyBoardValueButtonClick;
|
||||
if ((key !=-1)&& ((1 << (key / 4))==(row & 0xF))){
|
||||
updateMMIOControlAndData(OUT_ADRESS_HEXA_KEYBOARD,
|
||||
(char)(1 << (key / 4)) | (1 << (4+(key%4))));
|
||||
}
|
||||
else{
|
||||
updateMMIOControlAndData(OUT_ADRESS_HEXA_KEYBOARD, 0);
|
||||
}
|
||||
if ((row & 0xF0) != 0)
|
||||
KeyboardInterruptOnOff = true;
|
||||
else
|
||||
KeyboardInterruptOnOff = false;
|
||||
}
|
||||
public class HexaKeyboard extends JPanel{
|
||||
public JButton[] button;
|
||||
public HexaKeyboard(){
|
||||
int i;
|
||||
GridLayout layout = new GridLayout(4,4);
|
||||
this.setLayout(layout);
|
||||
button = new JButton[16];
|
||||
for (i=0;i<16;i++){
|
||||
button[i]= new JButton(Integer.toHexString(i));
|
||||
button[i].setBackground(Color.WHITE);
|
||||
button[i].setMargin(new Insets(10,10,10,10));
|
||||
button[i].addMouseListener(new EcouteurClick(i));
|
||||
this.add(button[i]);
|
||||
}
|
||||
}
|
||||
public void resetHexaKeyboard(){
|
||||
int i;
|
||||
KeyBoardValueButtonClick=-1;
|
||||
for(i=0;i<16;i++){
|
||||
button[i].setBackground(Color.WHITE);
|
||||
}
|
||||
}
|
||||
public class EcouteurClick implements MouseListener{
|
||||
private int buttonValue;
|
||||
public EcouteurClick(int val){
|
||||
buttonValue=val;
|
||||
}
|
||||
public void mouseEntered(MouseEvent arg0) { }
|
||||
public void mouseExited(MouseEvent arg0) {}
|
||||
public void mousePressed(MouseEvent arg0) {}
|
||||
public void mouseReleased(MouseEvent arg0) {}
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
int i;
|
||||
if(KeyBoardValueButtonClick!=-1){//Button already pressed -> now realease
|
||||
KeyBoardValueButtonClick = -1;
|
||||
updateMMIOControlAndData(OUT_ADRESS_HEXA_KEYBOARD,0);
|
||||
for(i=0;i<16;i++)
|
||||
button[i].setBackground(Color.WHITE);
|
||||
}
|
||||
else{ // new button pressed
|
||||
KeyBoardValueButtonClick = buttonValue;
|
||||
button[KeyBoardValueButtonClick].setBackground(Color.GREEN);
|
||||
if( KeyboardInterruptOnOff && (Coprocessor0.getValue(Coprocessor0.STATUS) & 2)==0){
|
||||
mars.simulator.Simulator.externalInterruptingDevice = /*Exceptions.*/EXTERNAL_INTERRUPT_HEXA_KEYBOARD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* ....................Hexa Keyboard end here................................... */
|
||||
/* ....................Timer start here................................... */
|
||||
public void updateOneSecondCounter(char value) {
|
||||
if (value !=0){
|
||||
CounterInterruptOnOff=true;
|
||||
CounterValue=CounterValueMax;
|
||||
}
|
||||
else{
|
||||
CounterInterruptOnOff=false;
|
||||
}
|
||||
}
|
||||
public class OneSecondCounter{
|
||||
public OneSecondCounter(){
|
||||
CounterInterruptOnOff=false;
|
||||
}
|
||||
public void resetOneSecondCounter(){
|
||||
CounterInterruptOnOff=false;
|
||||
CounterValue=CounterValueMax;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1459
-1498
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+935
-1106
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user