-
Notifications
You must be signed in to change notification settings - Fork 0
/
HP12c_Model.elm
255 lines (205 loc) · 5.38 KB
/
HP12c_Model.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
module HP12c_Model exposing (..)
import Array exposing (..)
import Keyboard
import HP12c_KeyTypes exposing (..)
type alias AutomaticMemoryStackRegisters =
{ reg_T : Float
, reg_Z : Float
, reg_Y : Float
, reg_X : Float
, reg_Last_X : Float
}
type AcceptNewDigitInto
= NewNumber
| IntegralPart
| FractionalPart
| ExponentForEEX
| STO_Reg
| STO_Dot_Reg
| RCL_Reg
| RCL_Dot_Reg
| GTO_Addrs
type alias ScratchRegisters =
{ reg_X_is_Positive : Bool
, integral_part_of_X : Int
, fractional_part_of_X : Int
, number_of_decimals : Int
, exponent_for_EEX : Int
, acceptNewDigitInto : AcceptNewDigitInto
}
type alias FinancialRegistersEntered =
{ reg_n_entered : Bool
, reg_i_entered : Bool
, reg_PV_entered : Bool
, reg_PMT_entered : Bool
, reg_FV_entered : Bool
}
type alias FinancialRegisters =
{ reg_n : Float
, reg_i : Float
, reg_PV : Float
, reg_PMT : Float
, reg_FV : Float
, regs_N : Array Float
}
numberOfFinacialRegisters_N : number
numberOfFinacialRegisters_N =
80
type alias DataStorageRegisters =
{ reg_R :
Array Float
-- 10
, reg_R_Decimal :
Array Float
-- 10
}
-- in hardware, these are aliases,
-- so for now, try to mimic hardware behaviour
type alias StatisticalRegisters =
{ reg_n :
Float
-- same as reg_R[1]
, reg_Σ_X :
Float
-- reg_R[2]
, reg_Σ_X_Squared :
Float
-- reg_R[3]
, reg_Σ_Y :
Float
-- reg_R[4]
, reg_Σ_Y_Squared :
Float
-- reg_R[5]
, reg_Σ_XY :
Float
-- reg_R[6]
}
type alias ProgramMemory =
{ prog_mem : Array Int
}
type InputMode
= White
| Orange
| Blue
type PrefixMode
= Orange_PrefixMode
| Blue_PrefixMode
| STO_Mode
type ErrorState
= Error_0_Mathematics
| Error_1_Storage_Register_Overflow
| Error_2_Statistics
| Error_3_IRR
| Error_4_Memory
| Error_5_Compound_Interest
| Error_6_Storage_Registers
| Error_7_IRR
| Error_8_Calendar
| Error_9_Service
| PrError
type CalculatorOperationalState
= AcceptingNumericalInputOnly
| AcceptingOperationsOrNumbers
| InPrefixMode PrefixMode
| RunningProgram
| Error ErrorState
type ComputationMode
= RPN_Mode
| ALG_Mode
| PRGM_MODE
type alias Model =
{ inputQueue : List Msg
, addToInputQueue : Bool
, inputMode : InputMode
, computationMode :
ComputationMode
--, calculatorOperationalState : CalculatorOperationalState
, scratchRegisters : ScratchRegisters
, automaticMemoryStackRegisters : AutomaticMemoryStackRegisters
, financialRegisters : FinancialRegisters
, financialRegistersEntered : FinancialRegistersEntered
, dataStorageRegisters : DataStorageRegisters
, statisticalRegisters : StatisticalRegisters
, programMemory : ProgramMemory
, keyCode : Keyboard.KeyCode
, shortcutVisible : Bool
, message : String
, displayString : String
, displayPrecision : Int
, unimplemented : Bool
}
initializeScratchRegisters : ScratchRegisters
initializeScratchRegisters =
{ reg_X_is_Positive = True
, integral_part_of_X = 0
, fractional_part_of_X = 0
, number_of_decimals = 0
, exponent_for_EEX = 0
, acceptNewDigitInto = IntegralPart
}
initializeAutomaticMemoryStackRegisters : AutomaticMemoryStackRegisters
initializeAutomaticMemoryStackRegisters =
{ reg_T = 0
, reg_Z = 0
, reg_Y = 0
, reg_X = 0
, reg_Last_X = 0
}
initializeFinancialRegisters : FinancialRegisters
initializeFinancialRegisters =
{ reg_n = 0
, reg_i = 0
, reg_PV = 0
, reg_PMT = 0
, reg_FV = 0
, regs_N = Array.initialize 80 (always 0)
}
initializeFinancialRegistersEntered : FinancialRegistersEntered
initializeFinancialRegistersEntered =
{ reg_n_entered = False
, reg_i_entered = False
, reg_PV_entered = False
, reg_PMT_entered = False
, reg_FV_entered = False
}
initializeDataStorageRegisters : DataStorageRegisters
initializeDataStorageRegisters =
{ reg_R = Array.initialize 10 (always 0)
, reg_R_Decimal = Array.initialize 10 (always 0)
}
initializeStatisticalRegisters : StatisticalRegisters
initializeStatisticalRegisters =
{ reg_n = 0
, reg_Σ_X = 0
, reg_Σ_X_Squared = 0
, reg_Σ_Y = 0
, reg_Σ_Y_Squared = 0
, reg_Σ_XY = 0
}
initializeProgramMemory : ProgramMemory
initializeProgramMemory =
{ prog_mem = Array.initialize 400 (always 0)
}
initialModel : Model
initialModel =
{ inputQueue = []
, addToInputQueue = True
, inputMode = White
, computationMode =
RPN_Mode
--, calculatorOperationalState = AcceptingOperationsOrNumbers
, scratchRegisters = initializeScratchRegisters
, automaticMemoryStackRegisters = initializeAutomaticMemoryStackRegisters
, financialRegisters = initializeFinancialRegisters
, financialRegistersEntered = initializeFinancialRegistersEntered
, dataStorageRegisters = initializeDataStorageRegisters
, statisticalRegisters = initializeStatisticalRegisters
, programMemory = initializeProgramMemory
, keyCode = 0
, shortcutVisible = False
, message = "No Keys"
, displayString = "0.00"
, displayPrecision = 2
, unimplemented = False
}