## Sunday, December 15, 2019

### Tandy PC-4: What Can You Do With 1,568 Bytes in Basic?

Tandy PC-4: What Can You Do With 1,568 Bytes in Basic?

On December 1, 2019, reviewed the Tandy Pocket Computer PC-4.  (link here:  http://edspi31415.blogspot.com/2019/12/retro-review-tandy-pc-4-pocket-computer.html ).  The PC-4 comes with 544 bytes, but with an OR-1 RAM card, the memory goes up to 1,568 bytes.

How much can I fit in 1,568 bytes?  Here's an attempt.

P0:  Factorial

10 PRINT "N!"
20 INPUT "N",N
25 F=0
30 FOR I=1 TO N
40 F= LOG(I)+F
50 NEXT I
60 E= INT(F)
70 R=10↑( FRAC(F))
80 PRINT N;"! ="
90 PRINT R;"*10↑";E

100 PRINT "AX↑2+BX+C=0"
105 INPUT "A",A
110 INPUT "B",B
115 INPUT "C",C
120 D=B↑2-4*A*C
125 S=-B/(2*A)
130 T=SQR( ABS(D))/(2*A)
135 IF D<0 300="" font="" then="">
200 R=S-T
205 T=S+T
210 S=R
215 PRINT "X1 =";S
220 PRINT "X2 =";T
225 GOTO 400
300 PRINT "REAL: ";S
305 PRINT "IMAG: ";T
400 PRINT "AGAIN?"
405 INPUT "0 FOR NO ",R
410 IF R≠0 THEN 105
415 END

P2:  Horizontal Curve

10 MODE 4     (Degrees Mode)
15 INPUT "TAN. LNGTH",T    (tangent length)
20 INPUT "ANGLE",D
25 R=T/ TAN(D/2)
30 L=R*D*π/180
35 C=2*R* SIN(D/2)
45 PRINT "L=";L     (arc length)
50 PRINT "C =";C    (chord length)
55 END

P3:  Amortizing a Monthly Loan (Annual Principal and Interest)

50 SET F2  (Fix 2)
100 INPUT "LOAN",L
105 INPUT "RATE",I
110 I=I/1200
115 INPUT "YEARS",T
120 N=12*T
125 U=(1-(1+I)↑(-N))/I
130 P= RND(L/U,-2)   (note the -2 in the round command)
135 PRINT "PMT: \$";P
140 B=L
200 FOR Y=1 TO T
201 S=0
202 C=0
205 FOR K=1 TO 12
210 E= RND(B*I,-2)
215 S=S+E
220 A=P-E
225 C=C+A
230 B=B-A
235 NEXT K
240 PRINT "YEAR: ";Y
245 PRINT "INT= \$";S
250 PRINT "PRN= \$";C
255 PRINT "BAL= \$";B
260 NEXT Y
270 PRINT "LAST= ";P+B   (last payment)
275 SET N   (floating decimal)
280 END

P4:  Linear Regression, Y=A+BX with correlation, R

100 VAC    (clear variables A-Z)
200 N=N+1   (N: counter)
205 PRINT "POINT ";N
210 PRINT "X",X
215 PRINT "Y",Y
220 C=C+X:F=F+X↑2
230 D=D+Y:G=G+Y↑2
240 E=E+X*Y
245 INPUT "DONE? NO=0 ",Z
250 IF Z=0 THEN 200
300 H = SQR((F-C↑2/N)/N)
305 I= SQR((G-D↑2/N)/N)
310 B=((N*E-C*D)/(N*F-C↑2))
315 A=(D-B*C)/N:R=B*H/I
325 PRINT "SLP=";B
330 PRINT "ITC=";A
335 PRINT "CORR=";R
340 END

P5:  Snell's Law

10 MODE 4      (degrees mode)
15 INPUT "N1",M    (index of refraction - 1st medium)
20 INPUT "INCIDENCE",T   (angle of incidence)
25 INPUT "N2",N     (index of refraction - 2nd medium)
30 H = ASN(M/N* SIN(T))
35 R= SIN(T-H)↑2/ SIN(T+H)↑2
40 R=1/2*R*100
50 PRINT "REFRACTION=";H;"°"
55 PRINT "REFLECT=";R;"%"
60 END

°  (degree character):  EXT mode, SHIFT C
% (percent character):  EXT mode, SHIFT Q

P6:  Rectangular/Polar Conversions

100 MODE 4
105 INPUT "1.P>R 2.R>P",C
110 IF C=1 THEN 200
115 IF C=2 THEN 300
120 GOTO 105
205 INPUT "ANGLE,"T
210 X=R* COS(T)
215 Y=R* SIN(T)
220 PRINT "X=";X
225 PRINT "Y=";Y
230 GOTO 900
300 INPUT "X",X
305 INPUT "Y",Y
310 R= SQR(X↑2+Y↑2)
315 IF X>0 THEN 500
320 IF X<0 600="" font="" then="">
325 IF X=0 THEN 700
500 IF Y≥0 THEN T= ATN(Y/X)
505 IF Y<0 t="ATN(Y/X)+360</font" then="">
510 GOTO 800
600 IF Y≥0 THEN T= ATN(Y/ ABS(X))+180
605 IF Y<0 t="ATN(Y/X)+180</font" then="">
610 GOTO 800
700 IF Y>0 THEN T=90
705 IF Y=0 THEN T=0
710 IF Y<0 t="270</font" then="">
715 GOTO 800
805 PRINT "ANGLE=";T
900 PRINT "AGAIN (NO=0)",C
905 IF C≠0 THEN 105
910 END

P7:  Area and Circumference on a Circle

10 INPUT "R",R
25 PRINT "C=";2*π*R
35 PRINT "A=";π*R↑2

Remaining:  8 bytes

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

### Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation

Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation The HP 16C’s #B Function The #B function is the HP 16C’s number of...