2K Calculator

See all articles from CATS v3 n4
Author(s): Monte Copeland
Publication: CATS Newsletter
Pub Details: CATS v3 n4 (Volume 3, Issue 4)
Date: July 1985
Pages: 4

ZX-T/S 1000

South Florida ZXUG
Boynton Beach, FL 33425-0951

Here’s an idea for you 2K TS1000 users. This program turns your 1000/2040 system into a printing calculator, This is also a very educational program, in that it uses the Hewlett-Packard type of Reverse Polish Notation. Any of you who are learning FORTH, take note; this may be just the sort of practice you need.

COMMANDS

"D"       display stack
"C"       clear stack
"P"       print top of stack
<ENTER>   push # on stack
"K"       add
"J"       subtract
"B"       multiply
"V"       divide

To enter a number you press ENTER, then type the number or expression and press ENTER again. The structure of the program is; a case statement within an infinite loop. After you key in the program, SAVE it by typing GOTO 3000. This will make the program “auto-starting.”

This program may not be the most practical way to get a printout of your calculations. It does, however, demonstrate some great features. It shows RPN, the use of a push-down stack, and how to program a case statement from BASIC.

  10 DIM S(50)
12 LET SP=0
15 GO TO 2E3
40 IF INKEY$="" THEN GO TO 40
50 LET I=CODE INKEY$
60 LET BSP=SP-1
100 IF I<>118 THEN GO TO 200
110 INPUT X
120 LPRINT X
130 LET SP=SP+1
140 LET S(SP)=X
150 GO TO 2E3
200 IF I<>61 THEN GO TO 300
220 LET SP=0
225 LPRINT "STACK CLEAR"
230 GO TO 2E3
240 NEXT N
300 IF I<>41 THEN GO TO 400
320 FOR N=SP TO 1 STEP -1
330 LPRINT N;" ";S(N)
360 GO TO 2E3
400 IF I<>53 THEN GO TO 500
410 LPRINT "STACK TOP = ";S(SP)
420 GO TO 2E3
500 IF I<>48 THEN GO TO 600
510 LET S(BSP)=S(BSP)+S(SP)
520 LET SP=BSP
525 LPRINT "+"
530 GO TO 2E3
600 IF I<>47 THEN GO TO 700
610 LET S(BSP)=S(BSP)-S(SP)
620 LET SP=BSP
625 LPRINT "-"
630 GO TO 2E3
700 IF I<>39 THEN GO TO 800
710 LET S(BSP)=S(BSP)*S(SP)
720 LET SP=BSP
725 LPRINT "*"
730 GO TO 2E3
800 IF I<>59 THEN GO TO 900
810 LET S(BSP)=S(BSP)/S(SP)
820 LET SP=BSP
825 LPRINT "/"
830 GO TO 2E3
900 IF I<>38 THEN GO TO 2E3
910 REM SLOW
930 CLEAR
940 STOP
2000 IF INKEY$="" THEN GO TO 2E3
2010 GO TO 40
3000 SAVE "▒"
3010 LPRINT "OK"
3020 GO TO 0

Puzzle Solutions!

Here are two member’s solutions to last month’s puzzle. Though none of them does the job in exactly the way I had in mind, each of the four uses some unusual programming trick (OK, algorithm) to get the job done.

From the Barasches:

10    FOR A=1 TO 3
20 FOR B=1 TO 3
30 PRINT A;",";
40 NEXT B
50 NEXT A

(Nested loops)

10    INPUT A$
20 DIM B$(LEN A$)
30 FOR K=1 TO LEN A$
40 LET B$(K)=A$(J-K+1)
50 NEXT K
60 PRINT B$,A$

(complex string slicing)

From Al Strauss:

  10 LET A$="X,"
20 LET X=1
25 FOR N=1 TO 3
30 PRINT VAL A$(1);A$(2);
35 NEXT N
40 LET X=X+1
45 IF X=11 THEN STOP
50 GOTO 25

(Use of VAL with string slicing)

  10 LET A$="ABLE WAS I ERE I SA
W ELBA"
15 LET X=LEN A$
20 FOR N=X TO 1 STEP -1
30 PRINT A$(N);
40 NEXT N

(Loop with STEP -1)

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.