PRICA - the PRInting CAlculator

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: http://www.swissmicros.com/dm42/decoder/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
Krauts In Space
Posts: 85
Joined: Wed Jan 03, 2018 2:48 pm
Location: Nuremberg, Germany

PRICA - the PRInting CAlculator

Post by Krauts In Space » Wed May 09, 2018 10:30 am

I always wondered "What to do with the large display?". So I had the idea of using it like a printer calculator.
Right now it's capable of simple arithmetics (+ - * /), but no exponents - plus former results can be recalled via up and down keys (depth of 9 results plus enter line). It's expandable for further functions.
Great efforts were in parsing the entered number. Ah, yes, and in debugging lots of side effects.
Due to excessive stack operations of the Bill's display routines I had to do many workarounds.
Maybe it's not the brightest piece of code - but here it is, ready to unleash into the community.
I hope my comments will help to understand it.
To run this, you will need Bills font generator and display routines
viewtopic.php?f=19&t=446&start=10#p5524
and the RCLA and STOA programs
viewtopic.php?f=15&t=1869&p=8019#p8026

Oh ... and just with battery screen refresh time is sloooooooow ...
Plugging calculator in is far quicker.

Here we go :)

Code: Select all

00 { 975-Byte Prgm }
01▸LBL "PRICA7" @ the PRInting CAlculator program
@
@ 7th evolution :) ... still in progress
@
@ used flags: ... 05 - chs (+/-) key pressed?
@ ................ 06 - function key (+ - * / sin cos ...) pressed?
@ ................ 07 - any key pressed?
@ ................ 09 - max# of digits (= 13) reached?
@ ................ 10 - decimal point set/unset
@
@ used registers: 11 - parsed ip from alpha
@ ............... 12 - parsed fp from alpha
@ ............... 13 -
@ ............... 14 -
@ ............... 15 -
@ ............... 16 - max# of digits to enter
@ ............... 17 - row number to recall former results
@ .................... up and down keys bring them into enter row
@ .................... any function and ENTER key sets it
@ .................... to 10 = enter row
@
@ used labels: .. 13 - 'enter' key
@ ............... 15 - '+/-'   key
@ ............... 17 - 'del'   key
@ ............... 18 - 'up'    key
@ ............... 23 - 'down'  key
@ ............... 33 - 'exit'  key
@ ............... 19 - '7'     key
@ ............... 20 - '8'     key
@ ............... 21 - '9'     key
@ ............... 24 - '4'     key
@ ............... 25 - '5'     key
@ ............... 26 - '6'     key
@ ............... 29 - '1'     key
@ ............... 30 - '2'     key
@ ............... 31 - '3'     key
@ ............... 34 - '0'     key
@ ............... 35 - '.'     key
@ ............... 22 - '/'     key
@ ............... 27 - '*'     key
@ ............... 32 - '-'     key
@ ............... 37 - '+'     key
@ ............... (label numbers corresponding to GETKEY scancodes
@ ...............  future versions sin, log, x↑2, ...)
@
@ ............... 80 - looping for keys
@ ............... 81 - displaying input on bottom row
@ ............... 82 - draw separating line above botton row
@ ............... 83 - redraw 'printed' results
@ ............... 84 - 'advance paper' == shift matrix entries,
@ .................... topmost number kicked out
@ ............... 98 - wipe numbers on graphics at stack position
@ ............... 33 - controlled exit of prica, but never reached
@ .................... bec pressing GETKEY stops execution
@
@ ............... numbered labels are for keys, graphics operation, etc.
@ ............... alpha labels (A..J, a..e) are for nested loops and
@ ............... jumps within numbered subroutines
@ ............... for better readability I preceeded two @-lines before
@ ............... global labels (00 - 99), one @-line before local
@ ............... labels (A..J, a..e).
@
@ ............... FTR: 'line' means thin graphics line on graph display
@ ..................... 'row' means any of 10 displayed numbers
@ ..................... (9 "printed" lines plus 1 enter line)
@
02 12 @
03 STO 05 @ pixel column to start 'printing' numbers
04 FIX 11 @ fixed number length while under development
05 14 @ max# of digits to enter (12 x 0..9, ., -)
06 STO 16 @
07 SF 28 @ set radix period
08 CF 29 @ no mantissa grouping
09 CF 06 @ no +/- pressed
10 10 @
11 1 @
12 DIM "PC" @ set printing paper length
13 CLST @
14 XEQ "FONTS" @ initializes 200*120 graphics font
15 2 @
16 STO "GrMod" @ initializes 200*120 graphics mode
17 XEQ 82 @ draw horizontal line above bottom row
18 XEQ 83 @ draw 'printing paper'
19 1 @
20 STO 12 @
21 CF 10 @ no decimal point pressed yet
22 CF 07 @ no key pressed yet
23 10 @
24 STO 17 @
25 XEQ 97 @
@
@
26▸LBL 80 @ key enter loop
@
27 FS? 07 @ any key pressed before?
28 GTO B @
29 RCL 05 @
30 110 @
31 XEQ 98 @ draw empty row at stack position
32 CLA @
33 INDEX "PC" @
34 10 @
35 1 @
36 STOIJ @
37 RCLEL @
38 CLA @
39 ARCL ST X @
40 RCL 05 @
41 110 @
42 XEQ "DISPLAY" @
43 CLA @
44 GTO C @
@
45▸LBL B @
46 SF 07 @
47 XEQ "STOA" @ store alpha
48 XEQ "RCLA" @ recall alpha
49 RCL 12 @
50 STO÷ 11 @
51 RCL 05 @
52 110 @
53 XEQ 81 @ redraw alpha on graphics screen
@
54▸LBL C @
55 GETKEY @
56 SF 07 @
57 ALENG @
58 13 @
@
@ alpha limited to 13 digits. with 13th digit,
@ no further numeric input possible
@ until @least 1 trailing digit deleted
@
59 X>Y? @
60 CF 09 @
61 X=Y? @
62 SF 09 @
63 R↓ @
64 R↓ @
65 SF 25 @ to prevent label-not-found error
@
@ no 'clean' style, sorry - else i'd have to create
@ a 1x74 matrix and fill it with label numbers for 'GTO IND'
@ possible, but it would bloat code ;)
@ maybe 'cleaned' in the next evolution of this
@ program
@
66 XEQ IND ST X @ goto label like key code
67 GTO 80 @
@
@
68▸LBL 34 @ keycode 34 == 0
@
69 FS? 09 @ if alpha contains 13 digits
70 RTN @ then go back to enter next key
71 48 @
72 XTOA @ append ascii code to alpha
73 RTN @
@
@
74▸LBL 29 @ keycode 29 == 1
@
75 FS? 09 @ if alpha contains 13 digits
76 RTN @ then go back to enter next key
77 49 @
78 XTOA @ append ascii code to alpha
79 RTN @
@
@
80▸LBL 30 @ keycode 30 == 2
@
81 FS? 09 @ if alpha contains 13 digits
82 RTN @ then go back to enter next key
83 50 @
84 XTOA @ append ascii code to alpha
85 RTN @
@
@
86▸LBL 31 @ keycode 31 == 3
@
87 FS? 09 @ if alpha contains 13 digits
88 RTN @ then go back to enter next key
89 51 @
90 XTOA @ append ascii code to alpha
91 RTN @
@
@
92▸LBL 24 @ keycode 24 == 4
@
93 FS? 09 @ if alpha contains 13 digits
94 RTN @ then go back to enter next key
95 52 @
96 XTOA @ append ascii code to alpha
97 RTN @
@
@
98▸LBL 25 @ keycode 25 == 5
@
99 FS? 09 @ if alpha contains 13 digits
100 RTN @ then go back to enter next key
101 53 @
102 XTOA @ append ascii code to alpha
103 RTN @
@
@
104▸LBL 26 @ keycode 26 == 6
@
105 FS? 09 @ if alpha contains 13 digits
106 RTN @ then go back to enter next key
107 54 @
108 XTOA @ append ascii code to alpha
109 RTN @
@
@
110▸LBL 19 @ keycode 19 == 7
@
111 FS? 09 @ if alpha contains 13 digits
112 RTN @ then go back to enter next key
113 55 @
114 XTOA @ append ascii code to alpha
115 RTN @
@
@
116▸LBL 20 @ keycode 20 == 8
@
117 FS? 09 @ if alpha contains 13 digits
118 RTN @ then go back to enter next key
119 56 @
120 XTOA @ append ascii code to alpha
121 RTN @
@
@
122▸LBL 21 @ keycode 21 == 9
@
123 FS? 09 @ if alpha contains 13 digits
124 RTN @ then go back to enter next key
125 57 @
126 XTOA @ append ascii code to alpha
127 RTN @
@
@
128▸LBL 35 @  keycode 35 == .
@
129 FS? 09 @  if alpha contains 13 digits
130 RTN @ ... then go back to enter next key
131 FS? 10 @  "decimal point flag" == dpf already set?
132 RTN @ ... yes? then dismiss key, go back, wait for new key
133 SF 10 @ . accept decimal point & set dpf
134 46 @
135 XTOA @ .. append ascii code to alpha
136 RTN @
@
@
137▸LBL 15 @  keycode 15 == +/-
@
138 ATOX @
139 45 @
140 X=Y? @ . number (1st digit) negative?
141 RTN @ .. drop it and leave, number becomes positive
142 R↓ @
143 45 @
144 XTOA @
145 R↓ @
146 XTOA @
147 -2 @
148 AROT @ . rotate former heading number and '-' back to head
149 RTN @
@
@
150▸LBL 17 @ keycode 17 == delete
@
151 -1 @
152 AROT @ . rotate alpha clockwise, bringing trailing char to head
153 ATOX @ . take it away
154 46 @
155 X=Y? @ . char == decimal point?
156 CF 10 @  clear dpf
157 RTN @
@
@
158▸LBL 13 @ keycode 13 == ENTER
@
159 CF 05 @
160 ALENG @
161 X≠0? @ ..... no empty input
162 GTO H @
163 INDEX "PC" @ if input empty (only ENTER pressed)
@ .............. get last "printed row"
164 10 @
165 1 @
166 STOIJ @
167 RCLEL @ .... get it in register X
168 CLA @
169 ARCL ST X @  and get it in alpha
@
170▸LBL H @
171 CF 07 @
172 CF 10 @
173 0 @
174 STO 11 @
175 STO 12 @
176 STO 14 @
@
177▸LBL a @
178 1 @
179 STO+ 14 @
180 ALENG @
181 X=0? @
182 GTO d @
183 -1 @
184 AROT @
185 ATOX @
186 45 @
187 X=Y? @
188 SF 05 @
189 FS? 05 @
190 GTO d @
191 R↓ @
192 46 @
193 X=Y? @
194 GTO b @
195 R↓ @
196 48 @
197 - @
198 STO 13 @
199 RCL 11 @
200 X=0? @
201 GTO c @
202 R↓ @
203 STO+ 11 @
204 10 @
205 STO÷ 11 @
206 GTO a @
@
207▸LBL b @
@
@ PRICA starts parsing at rightmost digit
@ assuming number is all ip, storing number in R11
@ when radix detected, R11 saved to R12
@ continuing parsing number and storing in R11
@ maybe not the brightest decision (;) ) but it helped me
@ to avoid a bunch of decisions with tailing (ip)
@ or heading zeroes (fp)
@
@ any advice for doing this more 'sophisticated' welcome ;)
@ 
208 RCL 11 @
209 STO 12 @
210 0 @
211 STO 11 @
212 STO 14 @
213 GTO a @
@
214▸LBL c @
215 R↓ @
216 10 @
217 ÷ @
218 STO 11 @
219 GTO a @
@
220▸LBL d @
221 RCL 14 @
222 FC? 05 @
223 1 @
224 FS? 05 @
225 2 @
226 - @
227 10↑X @
228 STO× 11 @
229 RCL 12 @
230 STO+ 11 @
231 1 @ ..... asuming entered number is positive
232 FS? 05 @  but if not
233 +/- @ ... make it to  -1
234 STO× 11 @ and multiply it into r11
@
235 FS?C 06 @
@
@ two ways to call lbl 13:
@ 1st: pressing enter key, parsing entered number,
@ .... "printing and advancing paper roll"
@ 2nd: pressing functionkey, parsing entered number,
@ .... and returning number in R 11 -> flag 06!
@ 
236 RTN @
237▸LBL e @
238 INDEX "PC" @
239 10 @
240 1 @
241 STOIJ @
242 RCL 11 @
243 STOEL @
244 XEQ 84 @ 'advance paper'
245 XEQ 83 @
246 XEQ 96 @
247 10 @
248 STO 17 @
249 XEQ 97 @
250 RTN @
@
@
251▸LBL 18 @ 'up' key
@
252 RCL 17 @
253 1 @
254 X=Y? @
255 RTN @
256 XEQ 96 @
257 1 @
258 STO- 17 @
259 XEQ 97 @
260 INDEX "PC" @
261 RCL 17 @
262 1 @
263 STOIJ @
264 RCLEL @
265 STO 11 @
266 CLA @
267 ARCL 11 @
268 RTN @
@
@
269▸LBL 23 @ 'down' key
@
270 RCL 17 @
271 10 @
272 X=Y? @
273 RTN @
274 XEQ 96 @
275 1 @
276 STO+ 17 @
277 XEQ 97 @
278 INDEX "PC" @
279 RCL 17 @
280 1 @
281 STOIJ @
282 RCLEL @
283 STO 11 @
284 CLA @
285 ARCL 11 @
286 RTN @
@
@
287▸LBL 81 @ redraw alpha on graphics
@
288 STO 14 @
289 X<>Y @
290 STO 15 @
291 X<>Y @
292 XEQ 98 @ ...... draw empty row at stack position
293 CLA @
294 XEQ "RCLA" @ .. recall alpha
295 RCL 15 @
296 RCL 14 @
297 XEQ "DISPLAY" @ and draw it on graphics
298 CLA @
299 XEQ "RCLA" @
300 RTN @
@
@
301▸LBL 82 @ ...... draw line above bottom row
@
302 CLLCD @
303 -107 @
304 0 @
305 PIXEL @
306 RTN @
@
@
307▸LBL 83 @ ...... redraw all 9 stack entities & bottom row
@
308 XEQ "STOA" @
309 10 @ .......... printing lines bottom to top
310 STO 08 @
@
@ INDEX "PC" should be here but this gave me dimension errors
@ bec of matrix operations in 'display' program, using INDEX too
@
311▸LBL F @
312 INDEX "PC" @
@
@ so i had to place it here
@
313 RCL 08 @
314 IP @
315 1 @
316 STOIJ @
317 CLA @
318 RCLEL @
319 STO 07 @
320 RCL 05 @
321 RCL 08 @
322 IP @
323 1 @
324 - @
325 12 @
326 × @
327 2 @
328 + @
329 STO 06 @
330 XEQ 98 @ draw empty row at stack position
331 CLA @
332 ARCL 07 @
333 RCL 05 @
334 RCL 06 @
@
@ graphics line = matrix row 1 - 12 * 2 +
@ for instance 9th matrix row starts 'printing'
@ 9 1 - 12 * 2 + == graphics line 98
@ 1st matrix row starts at graphics line 2
@
335 XEQ "DISPLAY" @
336 CLA @
337 DSE 08 @
338 GTO F @
339 XEQ "RCLA" @
340 RTN @
@
@
341▸LBL 84 @
@
@ 'advance paper'
@
342 INDEX "PC" @
343 1.009 @
344 STO 08 @
@
345▸LBL A @
346 RCL 08 @
347 1 @
348 + @
349 1 @
350 STOIJ @
351 RCLEL @
352 STO 07 @
353 RCL 08 @
354 1 @
355 STOIJ @
356 RCL 07 @
357 STOEL @
358 ISG 08 @
359 GTO A @
360 RTN @
@
@
361▸LBL 22 @ '/' key
@
@ division by zero not detected
@ currently it results (happy incident :) don't ask me how come)
@ in a division by 1
@
362 SF 06 @
363 XEQ 13 @ flag 06 grants parsing like with ENTER key
@ .......... but no 'paper advance'
364 INDEX "PC" @
365 9 @
366 1 @
367 STOIJ @
368 RCLEL @
369 RCL÷ 11 @
370 STO 11 @
371 ARCL 11 @
372 XEQ 13 @ now the result gets parsed, 'paper advance', etc.
373 RTN @
@
@
374▸LBL 27 @ '*' key
@
375 SF 06 @
376 XEQ 13 @ flag 06 grants parsing like with ENTER key
@ .......... but no 'paper advance'
377 INDEX "PC" @
378 9 @
379 1 @
380 STOIJ @
381 RCLEL @
382 STO× 11 @
383 ARCL 11 @
384 XEQ 13 @ now the result gets parsed, 'paper advance', etc.
385 RTN @
@
@
386▸LBL 32 @ '-' key
@
387 SF 06 @
388 XEQ 13 @ flag 06 grants parsing like with ENTER key
@ .......... but no 'paper advance'
389 INDEX "PC" @
390 9 @
391 1 @
392 STOIJ @
393 RCLEL @
394 RCL- 11 @
395 STO 11 @
396 ARCL 11 @
397 XEQ 13 @ now the result gets parsed, 'paper advance', etc.
398 RTN @
@
@
399▸LBL 37 @ '+' key
@
400 SF 06 @
401 XEQ 13 @ flag 06 grants parsing like with ENTER key
@ .......... but no 'paper advance'
402 INDEX "PC" @
403 9 @
404 1 @
405 STOIJ @
406 RCLEL @
407 STO+ 11 @
408 ARCL 11 @
409 XEQ 13 @ now the result gets parsed, 'paper advance', etc.
410 RTN @
@
@
411▸LBL 96 @ wipe filled square indicating old row
@ .......... where pointer was directed
@ .......... before it indicates new pointer position
@
412 CLA @
413 " " @
414 2 @
415 RCL 17 @
416 1 @
417 - @
418 12 @
419 × @
420 2 @
421 + @
422 XEQ "DISPLAY" @
423 RTN @
@
@
424▸LBL 97 @ draw filled square to indicate row
@ .......... where pointer is directed for recall of former results
@ .......... by default it is row 10 - enter
@
425 CLA @
426 31 @
427 XTOA @
428 2 @
429 RCL 17 @
430 1 @
431 - @
432 12 @
433 × @
434 2 @
435 + @
436 XEQ "DISPLAY" @
437 RTN @
@
@
438▸LBL 98 @ draw empty row at stack (x y) position
@
439 CLA @
440 "            " @  12 spaces
441 ├"            " @ plus 12 spaces should be enough
442 XEQ "DISPLAY" @
443 RTN @
@
@
444▸LBL 33 @ 'exit' key
@ .......... but exit never reached
@ .......... any proposal on EXIT key and GETKEY welcome
@
445 CLST @
446 FIX 03 @
447 SF 29 @
448 END @
Last edited by Krauts In Space on Wed May 09, 2018 2:04 pm, edited 4 times in total.
DM15L S/# 10584 FW v25
DM42 S/# 01015 FW v3.5

Krauts In Space
Posts: 85
Joined: Wed Jan 03, 2018 2:48 pm
Location: Nuremberg, Germany

Re: PRICA - the PRInting CAlculator

Post by Krauts In Space » Wed May 09, 2018 10:51 am

A faster refresh rate would be great - if this isn't an issue with the calculators clockspeed, but 24 MHz should be sufficient.
A larger font size also would be nice since it isn't a pleasure to work with such small numbers.
Simple arithmetics isn't really such a big thing for such a calculator - esp. without exponents.
But as expanding PRICA isn't a big thing, trigs and logarithms and roots and ... will become important.

If SM could implement a "printing" calculator into their FW I would appreciate this ;)
DM15L S/# 10584 FW v25
DM42 S/# 01015 FW v3.5

Post Reply