Package net.sourceforge.uiq3.hp45
Class Calculator
- java.lang.Object
-
- net.sourceforge.uiq3.hp45.Calculator
-
- All Implemented Interfaces:
Runnable
,net.sourceforge.uiq3.calculator.ICalculator
,net.sourceforge.uiq3.IPropertyNotifier
public abstract class Calculator extends Object implements net.sourceforge.uiq3.calculator.ICalculator
HP-45 Calculator Engine- Author:
- "Martin Krischik" «krischik@users.sourceforge.net»
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.sourceforge.uiq3.calculator.ICalculator
net.sourceforge.uiq3.calculator.ICalculator.AlphaRegisterType, net.sourceforge.uiq3.calculator.ICalculator.Companion, net.sourceforge.uiq3.calculator.ICalculator.DefaultImpls, net.sourceforge.uiq3.calculator.ICalculator.DisplayType
-
-
Field Summary
Fields Modifier and Type Field Description (package private) byte[]
a
register a, general purpose(package private) byte[]
b
register b, general purpose(package private) byte[]
c
register c, Xprivate boolean
Calculator_Running
Calculator is running - needed for power saving which was not there in the originalprivate boolean
Calculator_Shutdown
Calculator is not running - needed for end program.(package private) byte
carry
carry(package private) byte[]
d
register d, Y(package private) int
del_grp
(package private) int
del_rom
static String
DISPLAY_TEXT_CHANGED
(package private) boolean
displayEnable
Display enable - used to switch off the display so that intermediate result are not shown to the user.private @NotNull String
displayText
currently displayed text.private IOperation
do_op_clear_reg
clear register operationsprivate IOperation
do_op_clear_s
clear s register operation(package private) byte[]
e
register e, Zprivate static char[]
EXPONENT_CHAR
⁰ SUPERSCRIPT ZERO Unicode: U+2070, UTF-8: E2 81 B0private static int
EXPONENT_SIGN
location of the +/- sign of the exponent inside a register or memory.(package private) byte[]
f
register f, T(package private) net.sourceforge.uiq3.ui.ICalculatorCanvas
form
Canvas class where we display our result or get our keycodesprivate int
Group_Read
Group address read from file(package private) static @NonNls String
HP45_LST
(package private) int
IO_Count
Number of virtual CPU cycles until next IO run.private static int
IO_SPEED
Larger numbers reduce the amount of IO performed so the system has more time to run the actual calculator.private int
Key_Flag
Key event processing statusprivate static int
Key_Flag_Depressed
Key event processing statusprivate static int
Key_Flag_Idle
Key event processing statusprivate static int
Key_Flag_Pressed
Key event processing statusprivate static int
Key_Flag_Wait
Key event processing statusprivate long
Key_Time
System time when last Key was clicked.private static Logger
Logger
Class logger instance.(package private) byte[]
m
register m, scratch pad.(package private) static int
Max_Group
ROM Groups(package private) static int
Max_Ram
RAM Size(package private) static int
Max_Rom
ROMs per groupprivate @NotNull IOperation[]
op_fcn
array of all operator functions. not null after resetprivate int
Opcode_Read
Opcode read from file(package private) static int
Opcode_Size
maximum amount of opcodes(package private) int
p
private int
Pointer_Read
address read from file(package private) byte
Previous_Carry
previous carry(package private) int
Program_Counter
(package private) int
Program_Group
(package private) int
Program_Rom
private PropertyChangeSupport
propertyChangeSupport
Handle property changes.(package private) byte[][]
ram
Calculator RAM.(package private) int
ram_addr
ram address(package private) static String[]
REGISTER_NAMES
names of all registers(package private) int
Return_Program_Counter
private int
Rom_Read
Rom address read from file(package private) static int
Rom_Size
Size of each ROM(package private) byte[]
s
register s(package private) static int
S_Size
s register sizeprivate static String
TAG
Class logger tag.(package private) short[][][]
ucode
All Rom modules(package private) static int
Word_Size
Size of one register.
-
Constructor Summary
Constructors Constructor Description Calculator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(@NotNull String propertyName, PropertyChangeListener listener)
Add a PropertyChangeListener for a specific property.void
addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.(package private) byte
do_add(byte x, byte y)
add support operation(package private) byte
do_sub(byte x, byte y)
subtract support operationnet.sourceforge.uiq3.calculator.ICalculator.DisplayType
getDisplayMode()
Current display mode Display_Alpha Displays the content of the Alpha register. Display_L Displays the content of the L0 aka X register. Display_Formmated Displays the content of the L0 aka X register inside an alpha(package private) @NotNull String
getDisplayText()
returns the currently displayed textint
getLastStep()
locate the last step to display the free steps or for debugging.(package private) int
getReadKey()
get the last key read from the keyboard bufferprotected void
Handle_IO()
Display result and read keyboard(package private) void
Init_Opcodes()
Initialise Opcodesboolean
Is_Shutdown()
Calculator is not running - needed for end program.boolean
isRunning()
boolean
isWaiting()
is waiting in interactive mode for user input.(package private) void
load(DataInputStream Data_In)
(package private) static String
memoryToString(byte @NotNull [] register)
@NotNull String
memoryToString(int address)
private boolean
Parse_Address(@NotNull String oct)
Parse address fieldprivate boolean
Parse_Opcode(@NotNull CharSequence bin)
Parsevoid
Read_Listing_File(String fileName)
This reads a zip file that is expected to contain one entry which is the HP-45 firmware listing.(package private) static String
registerToString(byte @NotNull [] register)
@NotNull String
registerToString(int address)
void
removePropertyChangeListener(@NotNull String propertyName, PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific property.void
removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.void
reset()
Reset the calculatorvoid
resetAll()
performs a full reset by deleting ram and the cache file as well a reloading the cache file.void
run()
Start virtual CPU(package private) void
save(DataOutputStream Data_Out)
void
setDisplayMode(net.sourceforge.uiq3.calculator.ICalculator.DisplayType displayMode)
Current display mode Display_Alpha Displays the content of the Alpha register. Display_L Displays the content of the L0 aka X register. Display_Formatted Displays the content of the L0 aka X register inside an alpha(package private) void
setDisplayText(@NotNull String displayText)
changes the currently displayed textvoid
setForm(net.sourceforge.uiq3.ui.ICalculatorCanvas value)
Set Canvas to display result read keyboardvoid
stop()
Stop virtual CPUString
toString()
-
-
-
Field Detail
-
EXPONENT_SIGN
private static final int EXPONENT_SIGN
location of the +/- sign of the exponent inside a register or memory.- See Also:
- Constant Field Values
-
EXPONENT_CHAR
private static final char[] EXPONENT_CHAR
⁰ SUPERSCRIPT ZERO Unicode: U+2070, UTF-8: E2 81 B0
-
IO_SPEED
private static final int IO_SPEED
Larger numbers reduce the amount of IO performed so the system has more time to run the actual calculator.- See Also:
- Constant Field Values
-
Key_Flag_Depressed
private static final int Key_Flag_Depressed
Key event processing status
- Key_Flag_Idle
- Calculator is idle and ready to receive the next button from the key buffer
- Key_Flag_Pressed
- Calculator is processing the pressed event
- Key_Flag_Wait
- Waiting for the calcuator to process the event
- Key_Flag_Depressed
- Calculator is processing the de-pressed event
- See Also:
- Constant Field Values
-
Key_Flag_Idle
private static final int Key_Flag_Idle
Key event processing status
- Key_Flag_Idle
- Calculator is idle and ready to receive the next button from the key buffer
- Key_Flag_Pressed
- Calculator is processing the pressed event
- Key_Flag_Wait
- Waiting for the calcuator to process the event
- Key_Flag_Depressed
- Calculator is processing the de-pressed event
- See Also:
- Constant Field Values
-
Key_Flag_Pressed
private static final int Key_Flag_Pressed
Key event processing status
- Key_Flag_Idle
- Calculator is idle and ready to receive the next button from the key buffer
- Key_Flag_Pressed
- Calculator is processing the pressed event
- Key_Flag_Wait
- Waiting for the calcuator to process the event
- Key_Flag_Depressed
- Calculator is processing the de-pressed event
- See Also:
- Constant Field Values
-
Key_Flag_Wait
private static final int Key_Flag_Wait
Key event processing status
- Key_Flag_Idle
- Calculator is idle and ready to receive the next button from the key buffer
- Key_Flag_Pressed
- Calculator is processing the pressed event
- Key_Flag_Wait
- Waiting for the calcuator to process the event
- Key_Flag_Depressed
- Calculator is processing the de-pressed event
- See Also:
- Constant Field Values
-
Logger
private static final Logger Logger
Class logger instance.
-
TAG
private static final String TAG
Class logger tag.
-
HP45_LST
@NonNls static final @NonNls String HP45_LST
- See Also:
- Constant Field Values
-
Max_Group
static final int Max_Group
ROM Groups- See Also:
- Constant Field Values
-
Max_Ram
static final int Max_Ram
RAM Size- See Also:
- Constant Field Values
-
Max_Rom
static final int Max_Rom
ROMs per group- See Also:
- Constant Field Values
-
Opcode_Size
static final int Opcode_Size
maximum amount of opcodes
- See Also:
- Constant Field Values
-
Rom_Size
static final int Rom_Size
Size of each ROM- See Also:
- Constant Field Values
-
S_Size
static final int S_Size
s register size- See Also:
- Constant Field Values
-
Word_Size
static final int Word_Size
Size of one register.- See Also:
- Constant Field Values
-
REGISTER_NAMES
static final String[] REGISTER_NAMES
names of all registers
-
a
final byte[] a
register a, general purpose
-
b
final byte[] b
register b, general purpose
-
c
final byte[] c
register c, X
-
d
final byte[] d
register d, Y
-
e
final byte[] e
register e, Z
-
f
final byte[] f
register f, T
-
m
final byte[] m
register m, scratch pad.
-
ram
final byte[][] ram
Calculator RAM.
-
s
final byte[] s
register s
-
ucode
final short[][][] ucode
All Rom modules
-
Calculator_Running
private boolean Calculator_Running
Calculator is running - needed for power saving which was not there in the original
-
Calculator_Shutdown
private volatile boolean Calculator_Shutdown
Calculator is not running - needed for end program. If you are wondering why there is a Calculator_Running and and a Calculator_Shutdown - there is that little time between the calculator stop running and beeing full shutdown
-
displayText
@NotNull private @NotNull String displayText
currently displayed text.
-
DISPLAY_TEXT_CHANGED
public static final String DISPLAY_TEXT_CHANGED
- See Also:
- Constant Field Values
-
Group_Read
private int Group_Read
Group address read from file
-
Key_Flag
private int Key_Flag
Key event processing status
- Key_Flag_Idle
- Calculator is idle and ready to receive the next button from the key buffer
- Key_Flag_Pressed
- Calculator is processing the pressed event
- Key_Flag_Wait
- Waiting for the calculator to process the event
- Key_Flag_Depressed
- Calculator is processing the de-pressed event
-
Key_Time
private long Key_Time
System time when last Key was clicked.
-
Opcode_Read
private int Opcode_Read
Opcode read from file
-
Pointer_Read
private int Pointer_Read
address read from file
-
Rom_Read
private int Rom_Read
Rom address read from file
-
do_op_clear_reg
@Nullable private IOperation do_op_clear_reg
clear register operations
-
do_op_clear_s
@Nullable private IOperation do_op_clear_s
clear s register operation
-
op_fcn
@NotNull private @NotNull IOperation[] op_fcn
array of all operator functions. not null after reset
-
displayEnable
boolean displayEnable
Display enable - used to switch off the display so that intermediate result are not shown to the user.
-
form
@Nullable net.sourceforge.uiq3.ui.ICalculatorCanvas form
Canvas class where we display our result or get our keycodes
-
IO_Count
int IO_Count
Number of virtual CPU cycles until next IO run.
-
Previous_Carry
byte Previous_Carry
previous carry
-
Program_Counter
int Program_Counter
-
Program_Group
int Program_Group
-
Program_Rom
int Program_Rom
-
Return_Program_Counter
int Return_Program_Counter
-
carry
byte carry
carry
-
del_grp
int del_grp
-
del_rom
int del_rom
-
p
int p
-
ram_addr
int ram_addr
ram address
-
propertyChangeSupport
private final PropertyChangeSupport propertyChangeSupport
Handle property changes. We don't use the full feature with oldValue and new newValue as that would be overkill.
-
-
Method Detail
-
registerToString
static String registerToString(byte @NotNull [] register)
-
memoryToString
static String memoryToString(byte @NotNull [] register)
-
addPropertyChangeListener
public void addPropertyChangeListener(@NotNull PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list. The listener is registered for all properties. The same listener object may be added more than once, and will be called as many times as it is added. Iflistener
is null, no exception is thrown and no action is taken.- Specified by:
addPropertyChangeListener
in interfacenet.sourceforge.uiq3.IPropertyNotifier
- Parameters:
listener
- The PropertyChangeListener to be added
-
addPropertyChangeListener
public void addPropertyChangeListener(@NotNull @NotNull String propertyName, @NotNull PropertyChangeListener listener)
Add a PropertyChangeListener for a specific property. The listener will be invoked only when a call on firePropertyChange names that specific property. The same listener object may be added more than once. For each property, the listener will be invoked the number of times it was added for that property.- Specified by:
addPropertyChangeListener
in interfacenet.sourceforge.uiq3.IPropertyNotifier
- Parameters:
propertyName
- The name of the property to listen on.listener
- The PropertyChangeListener to be added- Since:
- 1.2
-
removePropertyChangeListener
public void removePropertyChangeListener(@NotNull PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties. Iflistener
was added more than once to the same event source, it will be notified one less time after being removed. Iflistener
is null, or was never added, no exception is thrown and no action is taken.- Specified by:
removePropertyChangeListener
in interfacenet.sourceforge.uiq3.IPropertyNotifier
- Parameters:
listener
- The PropertyChangeListener to be removed
-
removePropertyChangeListener
public void removePropertyChangeListener(@NotNull @NotNull String propertyName, @NotNull PropertyChangeListener listener)
Remove a PropertyChangeListener for a specific property. If `listener` was added more than once to the same event source for the specified property, it will be notified one less time after being removed.- Specified by:
removePropertyChangeListener
in interfacenet.sourceforge.uiq3.IPropertyNotifier
- Parameters:
propertyName
- The name of the property that was listened on.listener
- The PropertyChangeListener to be removed- Since:
- 1.2
-
getDisplayMode
@NotNull public net.sourceforge.uiq3.calculator.ICalculator.DisplayType getDisplayMode()
Current display mode- Display_Alpha
- Displays the content of the Alpha register.
- Display_L
- Displays the content of the L0 aka X register.
- Display_Formmated
- Displays the content of the L0 aka X register inside an alpha
- Specified by:
getDisplayMode
in interfacenet.sourceforge.uiq3.calculator.ICalculator
- Returns:
- current display mode
-
setDisplayMode
public void setDisplayMode(@NotNull net.sourceforge.uiq3.calculator.ICalculator.DisplayType displayMode)
Current display mode- Display_Alpha
- Displays the content of the Alpha register.
- Display_L
- Displays the content of the L0 aka X register.
- Display_Formatted
- Displays the content of the L0 aka X register inside an alpha
- Specified by:
setDisplayMode
in interfacenet.sourceforge.uiq3.calculator.ICalculator
- Parameters:
displayMode
- new display mode
-
getDisplayText
@NotNull @NotNull String getDisplayText()
returns the currently displayed text- Returns:
- Display_Text Test to display
-
setDisplayText
void setDisplayText(@NotNull @NotNull String displayText)
changes the currently displayed text- Parameters:
displayText
- Test to display
-
setForm
public void setForm(@Nullable net.sourceforge.uiq3.ui.ICalculatorCanvas value)
Set Canvas to display result read keyboard- Parameters:
value
- form in which the calculator is shown.
-
getReadKey
int getReadKey()
get the last key read from the keyboard buffer- Returns:
- key code.
-
Handle_IO
protected void Handle_IO()
Display result and read keyboard
-
Init_Opcodes
void Init_Opcodes()
Initialise Opcodes
-
isRunning
public boolean isRunning()
- Specified by:
isRunning
in interfacenet.sourceforge.uiq3.calculator.ICalculator
- Returns:
- true when calculator is running.
-
Is_Shutdown
@TestOnly public boolean Is_Shutdown()
Calculator is not running - needed for end program. If you are wondering why there is a Calculator_Running and and a Calculator_Shutdown - there is that little time between the calculator stop running and being fully shutdown.- Returns:
- when calculators is shut down
-
isWaiting
public boolean isWaiting()
is waiting in interactive mode for user input.- Specified by:
isWaiting
in interfacenet.sourceforge.uiq3.calculator.ICalculator
- Returns:
- true when in interactive mode.
-
getLastStep
public int getLastStep()
locate the last step to display the free steps or for debugging.
- Specified by:
getLastStep
in interfacenet.sourceforge.uiq3.calculator.ICalculator
- Returns:
- last step
-
load
void load(@NotNull DataInputStream Data_In) throws IOException
- Parameters:
Data_In
- file to read from- Throws:
IOException
- and I/O error while reading the file
-
Parse_Address
private boolean Parse_Address(@NotNull @NotNull String oct)
Parse address field- Parameters:
oct
- string to parse- Returns:
- address parsed
-
Parse_Opcode
private boolean Parse_Opcode(@NotNull @NotNull CharSequence bin)
Parse- Parameters:
bin
- line to parse- Returns:
- Opcode found
-
Read_Listing_File
public void Read_Listing_File(String fileName) throws IOException
This reads a zip file that is expected to contain one entry which is the HP-45 firmware listing. The instructions are parsed for later execution.- Parameters:
fileName
- File name to read from- Throws:
IOException
- file could not be read
-
reset
public void reset()
Reset the calculator- Specified by:
reset
in interfacenet.sourceforge.uiq3.calculator.ICalculator
-
resetAll
public void resetAll()
performs a full reset by deleting ram and the cache file as well a reloading the cache file.
- Specified by:
resetAll
in interfacenet.sourceforge.uiq3.calculator.ICalculator
-
save
void save(@NotNull DataOutputStream Data_Out) throws IOException
- Parameters:
Data_Out
- Output stream to write calculators state to.- Throws:
IOException
- and I/O while writing to Data_Out
-
do_add
byte do_add(byte x, byte y)
add support operation- Parameters:
x
- x valuey
- y value- Returns:
- x+y
-
do_sub
byte do_sub(byte x, byte y)
subtract support operation- Parameters:
x
- x valuey
- y value- Returns:
- x-y
-
run
public final void run()
Start virtual CPU
-
stop
public void stop()
Stop virtual CPU- Specified by:
stop
in interfacenet.sourceforge.uiq3.calculator.ICalculator
- See Also:
ICalculator.stop()
-
registerToString
@NotNull public @NotNull String registerToString(int address)
-
memoryToString
@NotNull public @NotNull String memoryToString(int address)
-
-