Package io.matita08
Class Constants
java.lang.Object
io.matita08.Constants
Configuration constants and command-line argument processing for the CPU Simulator.
This class provides centralized configuration management with comprehensive command-line
argument parsing capabilities, allowing users to customize various aspects of the CPU
simulation including memory size, instruction set, addressing mode, and display formatting.
The Constants class supports dynamic configuration through a sophisticated argument parser:
- Value Configuration: Maximum register values and display radix
- Memory Configuration: Central memory size with validation
- Architecture Configuration: Address size (1 or 2 words)
- Instruction Set Selection: Fully qualified operation enum class name
- Help System: Built-in usage information and error handling
Command-line options are processed using an internal parser that supports both short (-r) and long (--radix) option formats with comprehensive error handling and validation. Invalid configurations display helpful error messages and usage information.
Configuration values are immutable once initialized and thread-safe for access throughout the application lifecycle.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic intGets the address size configuration in single-value units.static intGets the central memory size in addressable locations.static StringGets the fully qualified class name of the operation enumeration.static intgetRadix()Gets the radix (number base) used for value display.static intGets the maximum value that can be represented in a single register.static booleanParses command-line arguments to configure the simulator.
-
Method Details
-
getValueMax
public static int getValueMax()Gets the maximum value that can be represented in a single register. This value affects arithmetic operations, overflow detection, and memory addressing limits.- Returns:
- the maximum single-register value
-
getAddressSize
public static int getAddressSize()Gets the address size configuration in single-value units. This determines the addressing architecture of the simulated CPU:- 1 = Single-word addressing (simple architecture)
- 2 = Double-word addressing (extended address space)
- Returns:
- the address size (1 or 2)
-
getMCSize
public static int getMCSize()Gets the central memory size in addressable locations. This determines the total number of memory locations available for program storage and execution.- Returns:
- the size of central memory
-
getOperationEnumName
Gets the fully qualified class name of the operation enumeration. This class is dynamically loaded to provide the instruction set for the CPU simulator and must implement the expected operation interface.- Returns:
- the fully qualified operation enum class name
-
getRadix
public static int getRadix()Gets the radix (number base) used for value display. This affects how numerical values are formatted in the user interface.- Returns:
- the display radix
-
init
Parses command-line arguments to configure the simulator. This method processes configuration options using a sophisticated parser that supports both short and long option formats with comprehensive validation and error handling.Supported command-line options:
- -r, --radix VALUE: Set display number base (default: 10)
- -a, --address SIZE: Set address size 1 or 2 (default: 2)
- -o, --operations CLASS: Set operation enum class name
- -s, --size VALUE: Set maximum register value (default: 8)
- -mc SIZE: Set central memory size (default: 32, max: valueMax * addressSize)
- -h, --help: Display usage information and exit
The parser validates all provided values and automatically corrects out-of-range values where possible. Invalid options or malformed arguments result in error messages and help display.
Processing behavior:
- Unknown options trigger help display and return true
- Malformed numeric values throw parsing exceptions
- Out-of-range values are clamped to valid ranges with warnings
- Missing option arguments cause array bounds exceptions
- Parameters:
args- command-line arguments array from main method- Returns:
- true if help was displayed or parsing failed (application should exit), false if initialization completed successfully
-