Post Reply 
(41C) Simple elevator simulator program
04-12-2023, 07:24 PM (This post was last modified: 04-16-2023 01:24 AM by acser.)
Post: #1
(41C) Simple elevator simulator program
Hello all,

This is a simple, single car elevator simulator program for the HP 41. There is only a button column in the elevator, but no elevator call buttons on floors (yet Smile).

Constructive ideas for simplification are most welcome (I am pretty sure there are plenty of opportunities).



Thanks in advance Smile
A

(P.S.: I am amazed how simple and well thought out the HP-41 FOCAL programming language is and now see why RPL has never been able to fully displace it. It also amazes me how easy it is to write a modern Python or other high level programming language program which will be larger than 671 bytes, the size of this one.)

Registers:

R00: Number of floors 1-20, only up to 20 floors are supported now
R01-R20 These are the individual buttons. 1 if button was pressed and is lit, 0:otherwise
R21: Direction of travel for elevator car: 0=Stopped, 1=Down, 2=Up
R22: Current floor indicator
R23: Are there any buttons pressed and lit on the the elevator button column LIT? 0 = Not lit, 1 = Lit
R24: Lowest floor pressed/lit (MINBT) value
R25: Highest floor pressed/lit (MAXBT) value

Code:

 01 LBL "EL"
 02 1
 03 STO 22
 04 "FLRS=?"
 05 PROMPT
 06 STO 00
 07 LBL "LOOP"
 08 -1
 09 "BTN=?"
 10 AVIEW
 11 PSE
 12 X<0?
 13 GTO "SKIP"
 14 1
 15 STO IND Y
 16 LBL "SKIP"
 17 XEQ "LIT?"
 18 STO 23
 19 "LIT="
 20 ARCL X
 21 AVIEW
 22 XEQ "MAXBT"
 23 RDN
 24 STO 25
 25 "MAXBT="
 26 ARCL X
 27 AVIEW
 28 PSE
 29 XEQ "MINBT"
 30 RDN
 31 STO 24
 32 "MINBT="
 33 ARCL X
 34 AVIEW
 35 PSE
 36 RCL 23
 37 X<=0?
 38 GTO "NOTLIT"
 39 RCL 21
 40 X!=0?
 41 GTO "NOTST"
 42 RCL 22
 43 RCL 24
 44 X>Y?
 45 XEQ "SETUP"
 46 RCL 22
 47 RCL 25
 48 X<Y?
 49 XEQ "SETDN"
 50 LBL "NOTST"
 51 RCL 23
 52 X=0?
 53 XEQ "SETST"
 54 LBL "NOTLIT"
 55 RCL 23
 56 1
 57 X!=Y?
 58 GTO "STAY"
 59 RCL 21
 60 X=0?
 61 GTO "STAY"
 62 RCL IND 22
 63 X=0?
 64 GTO "STAY"
 65 0
 66 STO IND 22
 67 "O/C="
 68 RCL 22
 69 ARCL X
 70 AVIEW
 71 XEQ "LIT?"
 72 STO 23
 73 XEQ "MAXBT"
 74 RDN
 75 STO 25
 76 XEQ "MINBT"
 77 RDN
 78 STO 24
 79 RCL 23
 80 X=0?
 81 XEQ "SETST"
 82 RCL 23
 83 X=0?
 84 GTO "STAY"
 85 RCL 22
 86 RCL 25
 87 X<Y?
 88 XEQ "SETDN"
 89 RCL 22
 90 RCL 24
 91 X>Y?
 92 XEQ "SETUP"
 93 LBL "STAY"
 94 RCL 24
 95 RCL 25
 96 X!=Y?
 97 GTO "MVEL"
 98 RCL 22
 99 X!=Y?
100 GTO "MVEL"
101 0
102 STO IND 22
103 LBL "MVEL"
104 XEQ "LIT?"
105 STO 23
106 RCL 23
107 X=0?
108 GTO "ENDMVEL"
109 2
110 RCL 21
111 X!=Y?
112 GTO "DN?"
113 1
114 ST+ 22
115 LBL "DN?"
116 RCL 21
117 1
118 X!=Y?
119 GTO "ENDMVEL"
120 1
121 ST- 22
122 LBL "ENDMVEL"
123 "END CFL="
124 RCL 22
125 ARCL X
126 AVIEW
127 PSE
128 GTO "LOOP"
129 LBL "LIT?"
130 RCL 00
131 LBL "L1"
132 RCL IND X
133 X>0?
134 RTN
135 RDN
136 1
137 -
138 X>0?
139 GTO "L1"
140 0
141 RTN
142 LBL "MINBT"
143 0
144 LBL "I1"
145 1
146 +
147 RCL IND X
148 X>0?
149 RTN
150 RDN
151 RCL 00
152 X<>Y
153 X<=Y?
154 GTO "I1"
155 0
156 RTN
157 LBL "MAXBT"
158 RCL 00
159 LBL "A1"
160 RCL IND X
161 X>0?
162 RTN
163 RDN
164 1
165 -
166 X>0?
167 GTO "A1"
168 0
169 RTN
170 LBL "SETST"
171 0
172 STO 21
173 RTN
174 LBL "SETDN"
175 1
176 STO 21
177 RTN
178 LBL "SETUP"
179 2
180 STO 21
181 RTN
182 END
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)