More fun with my 8800C

Discuss construction, troubleshooting, and operation of the Altair 8800c computer

More fun with my 8800C

Postby BillO » May 19th, 2022, 2:04 pm

This is a port of a program I wrote some years back on my Tandy COCO 3 to try out working with stacks.

It implements an RPN (Reverse Polish Notation) scientific calculator. All through university I used HP RPN calculators and to me it's the most natural way to do long complex calculations. I actually use it quite a bit. Anytime I'm doing calculations for some electronics project, it up and ready to work for me.

I imagined that implementing it in BASIC-80 with it's double precision FP would give me a better calculator, however the value for "e" is wrong in BASIC-80 so natural logarithms are calculated incorrectly. Some day I may write a fix for this, but here it is for y'all to play around with in the meantime. Requires an ANSI compatible terminal for cursor placement and screen management as written.

Code: Select all
10 REM RPN CALCULATOR
20 REM PORTED AND UPDATED FROM A PROGRAM I WROTE FOR THE TRS-80 COCO 3
30 REM REQUIRES AN ANSI COMPLIANT TERMINAL FOR CURSOR PLACEMENT
40 REM 2022/05/19
50 REM
60 REM *** DEFINE CONTANTS ***
70 SV%=11
80 SV%=10
90 ES%=23
100 SH$="6"
110 PV$="8"
120 PH$="4"
130 EV$=RIGHT$(STR$(SV%),2)
140 EH$="30"
150 N%=ES%-SV%
160 REM
170 REM *** INITIALIZE VARS AND ARRAYS ***
180 REM
190 I%=0
200 DIM ST#(256)
210 REM
220 REM *** PAINT INITIAL SCREEN ***
230 REM
240 PRINT CHR$(27)+"[2J";:PRINT CHR$(27)+"[0;0H";
250 PRINT "AVAILABLE OPERATIONS                              | AVAILABLE COMMANDS"
260 PRINT "  +       %               LN (NATUAL LOG)   SIN   |   CL (CLEAR STACK)"
270 PRINT "  -       P (EXPONENT)    LOG               COS   |   PT (POP TOP OF STACK)"
280 PRINT "  *       EX (NAT EXP)    ! (FACTORIAL)     TAN   |"
290 PRINT "  /       S (SQR ROOT)    N (NEGATE)              |   ZZ  (QUIT)"
300 REM
310 REM *** TOKEN INPUT LOOP ***
320 REM
330 OP$="N"
340 PRINT CHR$(27)+"["+PV$+";"+PH$+"H";:PRINT "                   ";
350 PRINT CHR$(27)+"["+PV$+";"+PH$+"H";:INPUT A$
360 IF A$="CL" THEN GOSUB 1050:GOTO 570
370 IF A$="PT" THEN GOSUB 1040:GOTO 570
380 IF A$="+" THEN GOSUB 620
390 IF A$="-" THEN GOSUB 640
400 IF A$="*" THEN GOSUB 660
410 IF A$="/" THEN GOSUB 680
420 IF A$="P" THEN GOSUB 710
430 IF A$="%" THEN GOSUB 730
440 IF A$="EX" THEN GOSUB 760
450 IF A$="COS" THEN GOSUB 790
460 IF A$="SIN" THEN GOSUB 840
470 IF A$="S" THEN GOSUB 810
480 IF A$="TAN" THEN GOSUB 860
490 IF A$="!" THEN GOSUB 880
500 IF A$="LN" THEN GOSUB 920
510 IF A$="LOG" THEN GOSUB 950
520 IF A$="N" THEN ST#(I%)=-ST#(I%):OP$="Y"
530 IF A$="E" THEN A#=EXP(1):GOSUB 1010:OP$="Y"
540 IF A$="PI" THEN A#=3.141592653589794#:GOSUB 1010:OP$="Y"
550 IF A$="ZZ" THEN PRINT CHR$(27)+"[2J";:PRINT CHR$(27)+"[0;0H";:END
560 IF OP$="N" THEN A#=VAL(A$):GOSUB 1010
570 GOSUB 1200
580 GOTO 330
590 REM
600 REM *** FUNCTION AND OPERATION IMPLEMENTATION ***
610 REM
620 IF I%<2 THEN GOTO 1100
630 R#=ST#(I%-1)+ST#(I%):GOTO 1020
640 IF I%<2 THEN GOTO 1100
650 R#=ST#(I%-1)-ST#(I%):GOTO 1020
660 IF I%<2 THEN GOTO 1100
670 R#=ST#(I%-1)*ST#(I%):GOTO 1020
680 IF I%<2 THEN GOTO 1100
690 IF ST#(I%)=0 THEN GOTO 1130
700 R#=ST#(I%-1)/ST#(I%):GOTO 1020
710 IF I%<2 THEN GOTO 1100
720 R#=ST#(I%-1)^ST#(I%):GOTO 1020
730 IF I%<2 THEN GOTO 1100
740 IF ST#(I%)=0 THEN GOTO 1130
750 R#=ST#(I%-1)/(ST#(I%)/100):GOTO 1020
760 IF I%<1 THEN GOTO 1100
770 IF ST#(I%)>87.3365 THEN GOTO 1130
780 R#=EXP(ST#(I%)):GOTO 1030
790 IF I%<1 THEN GOTO 1100
800 R#=COS(ST#(I%)):GOTO 1030
810 IF I%<1 THEN GOTO 1100
820 IF ST#(I%)<0 THEN GOTO 1130
830 R#=SQR(ST#(I%)):GOTO 1030
840 IF I%<1 THEN GOTO 1100
850 R#=SIN(ST#(I%)):GOTO 1030
860 IF I%<1 THEN GOTO 1100
870 R#=TAN(ST#(I%)):GOTO 1030
880 IF I%<1 THEN GOTO 1100
890 IF ST#(I%)-ABS(INT(ST#(I%)))<>0 THEN GOTO 1110
900 IF ST#(I%)>33 THEN GOTO 1120
910 R#=1:FOR Q%=1 TO ST#(I%):R#=R#*Q%:NEXT Q%:GOTO 1030
920 IF I%<1 THEN GOTO 1100
930 IF ST#(I%)<0 THEN GOTO 1130
940 R#=LOG(ST#(I%)):GOTO 1030
950 IF I%<1 THEN GOTO 1100
960 IF ST#(I%)<0 THEN GOTO 1130
970 R#=LOG(ST#(I%))/LOG(10):GOTO 1030
980 REM
990 REM *** STACK MANIPULATION ***
1000 REM
1010 I%=I%+1:ST#(I%)=A#:RETURN
1020 I%=I%-1
1030 ST#(I%)=R#:GOTO 1060
1040 ST#(I%)=0:IF I%>0 THEN I%=I%-1:GOTO 1060
1050 FOR I%=256 TO 0 STEP -1:ST#(I%)=0:NEXT I%:I%=0
1060 OP$="Y":RETURN
1070 REM
1080 REM *** ERROR HANDLING ***
1090 REM
1100 MS$="INSUFFICISNT VALUES ON STACK FOR OPERATION":GOTO 1140
1110 MS$="OPERAND MUST BE A POSITIVE INTEGER":GOTO 1140
1120 MS$="OPERAND TOO LARGE":GOTO 1140
1130 MS$=STR$(ST#(I%))+" IS NOT A VALID OPERAND"
1140 PRINT CHR$(27)+"["+EV$+";"+EH$+"H";:PRINT MS$:GOSUB 1270
1150 PRINT CHR$(27)+"["+EV$+";"+EH$+"H";:PRINT "                                                           ";
1160 OP$="Y":RETURN
1170 REM
1180 REM *** SCREEN MANAGEMENT ***
1190 REM
1200 PRINT CHR$(27)+"["+RIGHT$(STR$(SV%),2)+";"+SH$+"H";:PRINT CHR$(27)+"[J";
1210 K%=SV%-1:M%=1:IF I%>N% THEN M%=I%-N%
1220 IF I%>0 THEN FOR J%=I% TO M% STEP -1:K%=K%+1:K$=RIGHT$(STR$(K%),2):PRINT CHR$(27)+"["+K$+";"+SH$+"H";:PRINT ST#(J%):NEXT J%
1230 RETURN
1240 REM
1250 REM *** TIMERS ***
1260 REM
1270 FOR T=0 TO 1500:NEXT T:RETURN


Edit: I should also mention that if you enter "E" you'll get (the wrong) value for e (the base of the natural log), if you enter "PI" you get the value of PI and if you enter anything other than a listed operation, command, constant (E or PI) or a number you will get zero. It actually really surprises me that Microsoft did not catch the bad value for e. Neither did the rest of the world as I can find no reference to it being bad. I saw it immediately. Go figure.
BillO
 
Posts: 136
Joined: November 11th, 2020, 6:29 am

Re: More fun with my 8800C

Postby BillO » June 7th, 2022, 2:12 pm

Fixed a couple of bugs. The code above has ben corrected. Below are the corrected lines.

Code: Select all
360 IF A$="CL" THEN GOSUB 1050:GOTO 570
370 IF A$="PT" THEN GOSUB 1040:GOTO 570

and

520 IF A$="N" THEN ST#(I%)=-ST#(I%):OP$="Y"
BillO
 
Posts: 136
Joined: November 11th, 2020, 6:29 am


Return to Altair 8800c

Who is online

Users browsing this forum: No registered users and 5 guests

cron