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[]aregister a, general purpose(package private) byte[]bregister b, general purpose(package private) byte[]cregister c, Xprivate booleanCalculator_RunningCalculator is running - needed for power saving which was not there in the originalprivate booleanCalculator_ShutdownCalculator is not running - needed for end program.(package private) bytecarrycarry(package private) byte[]dregister d, Y(package private) intdel_grp(package private) intdel_romstatic StringDISPLAY_TEXT_CHANGED(package private) booleandisplayEnableDisplay enable - used to switch off the display so that intermediate result are not shown to the user.private @NotNull StringdisplayTextcurrently displayed text.private IOperationdo_op_clear_regclear register operationsprivate IOperationdo_op_clear_sclear s register operation(package private) byte[]eregister e, Zprivate static char[]EXPONENT_CHAR⁰ SUPERSCRIPT ZERO Unicode: U+2070, UTF-8: E2 81 B0private static intEXPONENT_SIGNlocation of the +/- sign of the exponent inside a register or memory.(package private) byte[]fregister f, T(package private) net.sourceforge.uiq3.ui.ICalculatorCanvasformCanvas class where we display our result or get our keycodesprivate intGroup_ReadGroup address read from file(package private) static @NonNls StringHP45_LST(package private) intIO_CountNumber of virtual CPU cycles until next IO run.private static intIO_SPEEDLarger numbers reduce the amount of IO performed so the system has more time to run the actual calculator.private intKey_FlagKey event processing statusprivate static intKey_Flag_DepressedKey event processing statusprivate static intKey_Flag_IdleKey event processing statusprivate static intKey_Flag_PressedKey event processing statusprivate static intKey_Flag_WaitKey event processing statusprivate longKey_TimeSystem time when last Key was clicked.private static LoggerLoggerClass logger instance.(package private) byte[]mregister m, scratch pad.(package private) static intMax_GroupROM Groups(package private) static intMax_RamRAM Size(package private) static intMax_RomROMs per groupprivate @NotNull IOperation[]op_fcnarray of all operator functions. not null after resetprivate intOpcode_ReadOpcode read from file(package private) static intOpcode_Sizemaximum amount of opcodes(package private) intpprivate intPointer_Readaddress read from file(package private) bytePrevious_Carryprevious carry(package private) intProgram_Counter(package private) intProgram_Group(package private) intProgram_Romprivate PropertyChangeSupportpropertyChangeSupportHandle property changes.(package private) byte[][]ramCalculator RAM.(package private) intram_addrram address(package private) static String[]REGISTER_NAMESnames of all registers(package private) intReturn_Program_Counterprivate intRom_ReadRom address read from file(package private) static intRom_SizeSize of each ROM(package private) byte[]sregister s(package private) static intS_Sizes register sizeprivate static StringTAGClass logger tag.(package private) short[][][]ucodeAll Rom modules(package private) static intWord_SizeSize of one register.
-
Constructor Summary
Constructors Constructor Description Calculator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(@NotNull String propertyName, PropertyChangeListener listener)Add a PropertyChangeListener for a specific property.voidaddPropertyChangeListener(PropertyChangeListener listener)Add a PropertyChangeListener to the listener list.(package private) bytedo_add(byte x, byte y)add support operation(package private) bytedo_sub(byte x, byte y)subtract support operationnet.sourceforge.uiq3.calculator.ICalculator.DisplayTypegetDisplayMode()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 StringgetDisplayText()returns the currently displayed textintgetLastStep()locate the last step to display the free steps or for debugging.(package private) intgetReadKey()get the last key read from the keyboard bufferprotected voidHandle_IO()Display result and read keyboard(package private) voidInit_Opcodes()Initialise OpcodesbooleanIs_Shutdown()Calculator is not running - needed for end program.booleanisRunning()booleanisWaiting()is waiting in interactive mode for user input.(package private) voidload(DataInputStream Data_In)(package private) static StringmemoryToString(byte @NotNull [] register)@NotNull StringmemoryToString(int address)private booleanParse_Address(@NotNull String oct)Parse address fieldprivate booleanParse_Opcode(@NotNull CharSequence bin)ParsevoidRead_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 StringregisterToString(byte @NotNull [] register)@NotNull StringregisterToString(int address)voidremovePropertyChangeListener(@NotNull String propertyName, PropertyChangeListener listener)Remove a PropertyChangeListener for a specific property.voidremovePropertyChangeListener(PropertyChangeListener listener)Remove a PropertyChangeListener from the listener list.voidreset()Reset the calculatorvoidresetAll()performs a full reset by deleting ram and the cache file as well a reloading the cache file.voidrun()Start virtual CPU(package private) voidsave(DataOutputStream Data_Out)voidsetDisplayMode(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) voidsetDisplayText(@NotNull String displayText)changes the currently displayed textvoidsetForm(net.sourceforge.uiq3.ui.ICalculatorCanvas value)Set Canvas to display result read keyboardvoidstop()Stop virtual CPUStringtoString()
-
-
-
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. Iflisteneris null, no exception is thrown and no action is taken.- Specified by:
addPropertyChangeListenerin 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:
addPropertyChangeListenerin 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. Iflistenerwas added more than once to the same event source, it will be notified one less time after being removed. Iflisteneris null, or was never added, no exception is thrown and no action is taken.- Specified by:
removePropertyChangeListenerin 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:
removePropertyChangeListenerin 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:
getDisplayModein 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:
setDisplayModein 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:
isRunningin 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:
isWaitingin 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:
getLastStepin 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:
resetin 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:
resetAllin 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:
stopin 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)
-
-