10 20 30 35 40 45 50 60 70 80 90 100 DIM IBUFF$[264],OBUFF$[264] 105 DIM K$[1],k$[1],I$[256] 110 DIM CR$[1],LF$[1],ESC$[1],BEL$[1] 115 DIM EL$[1],BS$[1],DEL$[1],NULL$[1] 120 DIM SP$[1] 125 INTEGER S1,S2,S3,S4,K,R,C,I,F 130 CR$[1]=CHR$ (13) @ LF$=CHR$ (10) 135 ESC$[1]=CHR$ (27) @ BEL$=CHR$ (7) 140 EL$[1]=CHR$ (154) @ BS$=CHR$ (155) 145 DEL$[1]=CHR$ (127) @ NULL$=CHR$ (0) 150 SP$=" " 155 DIM RP$[96],OP$[96],ID$[91],OD$[91] 160 DIM S$[256],DB$[256],SF$[17],DF$[40],T$[1],RT$[1],c$[1] 165 DIM SI$[1],SH$[1],SD$[1],SE$[1],SB$[1],TM$[1],AK$[1],NK$[1] 170 DIM RQCTL$[1],SQCTL$[1],RPADC$[1],SPADC$[1] 175 DIM MK$[1],SEOL$[1],REOL$[1],CRLF$[4] 180 INTEGER N,S,T,e,f,i,j,l,m,r,t 185 INTEGER n,rn,db,tmo,nk,bp,rr,rc,sr,sc 190 INTEGER RMAXL,SMAXL,MAXL,MINL,RTO,STO,RNPAD,SNPAD,REOL,SEOL,TMO,STM,RLIM 195 SI$="S" @ SH$="F" @ SD$="D" @ SE$="Z" @ SB$="B" 200 AK$="Y" @ NK$="N" @ TM$="T" @ ER$="E" 205 MK$=CHR$ (1) @ CRLF$="#M#J" 210 SEOL$,REOL$=CR$ @ RPADC$=NULL$ @ SQCTL$="#" 215 RMAXL=94 @ RTO,STO=20 @ RNPAD=0 @ SEOL=13 220 RLIM=10 @ STM=10000 @ rr=17 @ sr=15 @ rc,sc=10 225 db=1 250 DIM F$[80],CL$[61],CP$[24] 255 CL$="CONNECT, SEND, RECEIVE, SET, SHOW, EXIT, QUIT, CAT" 260 KP$="KERMIT-HP86" @ CP$=KP$ 265 DIM VC$[63],DT$[1],CN$[1],UL$[1],FTYP$[8] 270 VC$=".1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" 275 DT$="." @ CN$=":" @ UL$="_" @ Q$=CHR$ (34) 280 FTYP$="DATA" 300 ALPHALL @ PAGESIZE 24 @ CLEAR @ R=0 310 DIM EM$(24)[24] 320 EM$(0)="Transfer successfull" @ EM$(1)="Timeout receiving" 325 EM$(2)="NAK received" @ EM$(3)="Checksum error" @ EM$(4)="Incorrect packet" 330 EM$(5)="Timeout sending" @ EM$(6)="Cannot rename file" 335 EM$(7)="Disc write protected" @ EM$(8)="*File closed*" 340 EM$(9)="File does not exist" @ EM$(10)="Incorrect file type" 345 EM$(11)="*Random overflow*" @ EM$(12)="Read error" 350 EM$(13)="End of file" @ EM$(14)="Record does not exist" 355 EM$(15)="No M.S. device" @ EM$(16)="Directory full" 360 EM$(17)="Volume not found" @ EM$(18)="MSUS not found" 365 EM$(19)="Read verify error" @ EM$(20)="Disc full" 370 EM$(21)="Medium damaged" @ EM$(22)="Disc drive fault" 372 EM$(23)="Data type error" @ EM$(24)="Transfer aborted" 375 FSE$=CHR$ (60) @ FOR i=66 TO 72 @ FSE$=FSE$&CHR$ (i) @ NEXT i 380 FSE$=FSE$&CHR$ (120) @ FOR i=124 TO 130 @ FSE$=FSE$&CHR$ (i) @ NEXT i 390 DIM A$(9)[18],ST$(1)[9],st$(1)[8] 395 A$(0)="initialise " @ A$(1)="file header " 400 A$(2)="data " @ A$(3)="end of file " 405 A$(4)="break " @ A$(5)="error " 410 A$(6)="ACK " @ A$(7)="NAK " 415 A$(8)="file header/break " @ A$(9)="data/EOF " 420 ST$(0)="Sending" @ st$(0)="sent" @ ST$(1)="Receiving" @ st$(1)="received" 425 DIM RE$[4],PF$[18] 430 INTEGER RE,RL,NR 435 RE$=CR$&LF$ @ RE=LEN (RE$) @ RL=256 @ NR=40 @ FS=RL*NR/1024 @ PF$="" 440 DIM SL$[164],OO$[7],DX$[10],FC$[23],PT$[28],BR$[8],HS$[29] 445 SL$="TIMEOUT, RETRIES, SEND-CONVERT, DEBUG, PREFIX, END-OF-LINE, " 450 SL$=SL$&"RECORD-END, FILE-SIZE, RECORD-LENGTH, NO-OF-RECORDS, " 455 SL$=SL$&"DUPLEX, LOCAL-ECHO, FLOW-CONTROL, HANDSHAKE, PARITY" 460 OO$="OFF, ON" @ DX$="FULL, HALF" @ FC$="NONE, XON/XOFF, DTR/RTS" 462 PT$="NONE, ODD, EVEN, MARK, SPACE" @ BR$="110, 300" 463 HS$="NONE, BELL, LF, CR, XON, XOFF" 465 DIM SS$[47],RS$[32] 470 SS$="SEND "&Q$&"Source filename"&Q$&" <"&Q$&"Destination filespec"&Q$&">" 475 RS$="RECEIVE <"&Q$&"Destination filespec"&Q$&">" 480 DIM IO$[14],IC$[14],IV$[13] 485 IO$="Illegal option" @ IC$="Illegal string" @ IV$="Illegal value" 490 INTEGER BR,DX,LE,FC,HS,PT,SC,ps 495 BR,DX,LE=1 @ PT=3 @ FC,SC,ps=0 @ HS=4 @ GOSUB rs_set 500 510 520 530 540 550 560 570 580 590 600 com_proc: GOSUB dkeys 610 AWRITE 20,0 @ DISP CP$&" > Enter command ";! Display command prompt 620 RELEASE KEYBOARD 630 INPUT S$@ CP$=KP$ 640 TAKE KEYBOARD 645 AWRITE 19,0,RPT$ (" ",80) 646 AWRITE 22,0,RPT$ (" ",160) 650 GOSUB split 660 C=FNinlist(F$,CL$) 670 IF C=0 THEN AWRITE 22,0,"Invalid command - "&F$ 675 IF C<1 THEN 610 680 ON C GOSUB connect ,send_file ,rec_file ,set ,show_pars ,exit ,exit ,dir 690 GOTO com_proc 700 710 720 730 split: S$=TRIM$ (S$) 740 p=POS (S$,Q$) @ P=POS (S$,SP$) 745 IF p*P=0 THEN P=MAX (P,p) ELSE P=MIN (P,p) 750 IF P=0 THEN F$=S$ @ S$="" ELSE F$=S$[1,P-1] @ S$=S$[P,LEN (S$)] 760 RETURN 850 860 870 880 exit: CLEAR @ RELEASE KEYBOARD @ ABORTIO 10 @ DISP "Kermit finished" @ END 900 910 920 930 dir: ON ERROR GOSUB fserr @ f=0 935 S$=TRIM$ (S$) @ IF S$#"" THEN CAT S$ ELSE CAT 940 IF f#0 THEN AWRITE 19,0,EM$(f) @ RETURN 950 FOR I=1 TO 4 @ DISP @ NEXT I @ RETURN 1000 1010 1020 1030 1040 1050 connect: F,f=0 1070 C=0 @ START CRT AT R 1080 AWRITE 0,0 @ CLEAR 1090 DISP "HP86 Kermit - Terminal emulation mode" @ DISP 1100 DISP "Function key Escape character Action" 1110 DISP "--------------------------------------------------" 1120 DISP " k1 C Return to KERMIT" 1130 DISP " k7 B Transmit break" 1135 DISP " k14 Enable transmit" 1140 AWRITE 23,0 1150 DEL=5 1160 ON KEY# 1 GOTO EXIT1 1170 ON KEY# 7 GOSUB BREAK 1172 ON KEY# 14 GOSUB TX_EN 1180 ON EOT 10 GOSUB BUFFULL 1190 TAKE KEYBOARD 1200 k$=" " @ AWRITE 23,0,HGL?$ (k$,1) 1210 1220 1230 1240 START: STATUS 10,9 ; S1,S2 1250 1260 1270 IF BINAND (S1,128)=0 OR BINAND (S2,32)=0 THEN RSGET 1280 1290 1300 1310 K$=KEY$ @ IF K$="" THEN RSGET 1320 IF F=0 THEN KOUT ELSE F=0 1330 IF K$=ESC$ THEN 1500 1340 IF K$="C" OR K$="c" THEN EXIT1 1350 IF K$="B" OR K$="b" THEN GOSUB BREAK 1360 GOTO START 1370 KOUT: IF K$=BS$ THEN K$=DEL$ 1380 IF K$=EL$ THEN K$=CR$ @ f=HS#0 1390 IF K$=ESC$ THEN F=1 @ BEEP @ GOTO RSGET 1400 IF K$>DEL$ THEN RSGET 1405 IF LE=0 THEN 1500 1410 AWRITE 23,C,k$ 1420 IF K$ >= SP$ THEN 1450 1430 IF K$=CR$ THEN C=0 @ GOTO 1490 1440 IF K$=LF$ THEN 1470 1450 AWRITE 23,C,K$ 1460 C=C+1 @ IF C<80 THEN 1490 ELSE C=0 1470 R=R+1 @ IF R=204 THEN R=0 1480 AWRITE 24,0,RPT$ (SP$,80) @ START CRT AT R 1490 AWRITE 23,C @ AREAD k$ @ AWRITE 23,C,HGL?$ (k$,1) 1500 OUTPUT OBUFF$ USING "#,A" ; K$ 1502 IF f THEN OUTPUT OBUFF$ USING "#,A" ; HC$ 1506 STATUS OBUFF$,1 ; S1,S,S3 1508 IF S1=0 OR S3#0 THEN 1520 1510 TRANSFER OBUFF$ TO 10 INTR 1520 WAIT DEL 1530 1540 1550 1560 RSGET: STATUS IBUFF$,1 ; S3 1565 IF S3=0 THEN START 1570 AWRITE 23,C,k$ 1580 ENTER IBUFF$ USING "#,#K" ; I$ 1590 FOR I=1 TO LEN (I$) 1600 K$=I$[I,I] 1610 IF K$ >= SP$ THEN 1660 1620 IF K$=CR$ THEN C=0 @ GOTO 1700 1630 IF K$=LF$ THEN 1680 1640 IF K$=BEL$ THEN BEEP @ GOTO 1700 1650 GOTO 1700 1660 AWRITE 23,C,K$ 1670 C=C+1 @ IF C<80 THEN 1700 ELSE C=0 1680 R=R+1 @ IF R=204 THEN R=0 1690 AWRITE 24,0,RPT$ (SP$,80) @ START CRT AT R 1700 NEXT I 1710 AWRITE 23,C @ AREAD k$ @ AWRITE 23,C,HGL?$ (k$,1) 1720 GOTO START 1730 1740 1750 1760 BUFFULL: OFF EOT 10 @ STATUS 10,11 ; S4 1765 IF BINAND (S4,64)#0 THEN 1810 1770 IF f=0 THEN 1850 1780 f=0 @ STATUS 10,9 ; S@ S=BINAND (S,127) 1790 ABORTIO 10 @ CONTROL 10,9 ; S@ TRANSFER 10 TO IBUFF$ INTR 1800 GOTO 1850 1810 ENTER IBUFF$ USING "#,#K" ; I$@ TRANSFER 10 TO IBUFF$ INTR 1820 1830 DISP I$ 1840 DISP "BUFFER FULL POSSIBLE DATA LOSS !" 1850 ON EOT 10 GOSUB BUFFULL @ RETURN 1860 1870 1880 1890 EXIT1: 1900 RELEASE KEYBOARD @ OFF EOT 10 @ CLEAR 1910 RETURN 1920 1930 1940 1950 BREAK: REQUEST 10;8 @ RETURN 1960 1970 1980 1990 TX_EN: RESUME 10 @ RETURN 2000 2010 2020 2030 2040 2050 2060 2070 2080 2160 2170 2180 2190 send_file: S$=TRIM$ (S$) @ DF$="" 2195 IF S$="?" THEN AWRITE 22,0,SS$ @ RETURN 2200 p=FNfsplit(S$) @ IF p=0 THEN errfn 2210 SF$=TRIM$ (S$[2,p]) 2220 IF l
0 THEN S$=S$[1,p-1]
2320
2330
2340
2350 chckfn: l=LEN (S$) @ f=0 @ j=0
2360 S$=UPC$ (S$)
2370 IF POS (S$,DT$) THEN 2410
2380 p=POS (S$,SP$) @ IF p>0 THEN 2400
2390 p=POS (S$,UL$) @ IF p=0 THEN 2410
2400 S$[p,p]=DT$
2410 FOR i=1 TO l @ p=POS (VC$,S$[i,i])
2420 IF p=0 OR p=1 AND (f=1 OR j=0 OR j=l-1) THEN 2450
2430 IF p=1 THEN f=1
2440 j=j+1 @ DF$[j,j]=S$[i,i]
2450 NEXT i
2460 IF j=0 THEN DF$=SF$ @ GOTO 2800
2470 l=LEN (DF$) @ p=POS (DF$,DT$)
2480 IF p=0 THEN DF$=DF$&"." @ p=l
2490 IF p=l THEN DF$=DF$&FTYP$
2600
2610
2620
2630
2640
2650
2660
2670
2680
2690
2700
2710
2720
2730
2740
2750
2760
2770
2780
2790
2800 n,pc,st,k,SNPAD=0 @ RT$="" @ sr=15 @ rr=17
2805 GOSUB open_read @ IF f#0 THEN srexit
2810 GOSUB dsend @ ON KEY# 1 GOSUB abort
2815
2820
2830
2840 send_init: n=0 @ T$=SI$ @ T=0 @ IBUFF$=""
2845 GOSUB init_pack @ OD$=IN$
2890 GOSUB send_pack @ IF f#0 THEN srexit
2900
2910
2920
2930 GOSUB dcd_init
3010
3020
3030
3040 send_head: T$=SH$ @ T=1 @ OD$=DF$
3050 GOSUB send_pack @ IF f#0 THEN srexit
3060
3070
3080
3090 T$=SD$ @ T=2 @ DB$="" @ e=0 @ MAXL=SMAXL-3
3100 MINL=IP (MAXL/2) @ IF MINL<1 THEN MINL=1
3110 GOSUB get_data @ IF f#0 THEN RETURN
3120 IF OD$="" THEN send_eof
3130 GOSUB send_pack @ IF f#0 THEN srexit
3135 IF LEN (ID$)=0 THEN 3110
3140 IF ID$[1,1]#"Z" AND ID$[1,1]#"X" THEN 3110
3150
3160
3170
3180 send_eof: T$=SE$ @ T=3
3190 GOSUB send_pack @ IF f#0 THEN srexit
3200 T$=SB$ @ T=4 @ GOSUB send_pack
3210 GOTO srexit
3510
3520
3530
3540 errfn: CP$="Filename error" @ RETURN
4000
4010
4020
4030
4040
4050
4060
4070
4080 rec_file: S$=TRIM$ (S$)
4083 IF S$="?" THEN AWRITE 22,0,RS$ @ RETURN
4085 sr=17 @ rr=15 @ st=1 @ GOSUB dsend
4090 p=FNfsplit(S$) @ IF p=0 THEN ft=1 @ GOTO 4200
4100 DF$=TRIM$ (S$[2,p]) @ ft=0
4110 p=POS (DF$,DT$) @ IF p=0 THEN p=POS (DF$,CN$)
4120 IF p=0 THEN 4150
4130 VN$=DF$[p] @ IF p=1 OR LEN (VN$)>6 THEN errfn
4140 DF$=DF$[1,p-1]
4150 IF LEN (DF$)>10 THEN errfn
4155 AWRITE 4,2,ST$(1)&" as '"&DF$&"'"
4160
4170
4180
4200 rec_init: n,nf,pc,k=0 @ IBUFF$="" @ ON KEY# 1 GOSUB abort
4210 GOSUB init_pack @ A$=SI$ @ T=0
4220 GOSUB get_pack @ IF f#0 THEN srexit
4230 GOSUB dcd_init
4232
4234
4236
4240 rec_head: A$="FBSZ" @ DB$=""
4250 T=8 @ GOSUB get_pack
4260 IF RT$=SB$ OR f#0 THEN srexit
4262
4264
4266
4270 SF$=ID$ @ k=0
4272 IF ft=0 THEN 4330 ELSE DF$=SF$
4275 l=LEN (DF$) @ p=POS (DF$,DT$)
4280 IF l=0 THEN DF$=DFN$&DFT$ @ GOTO 4275
4285 IF p=0 THEN 4330
4290 IF p=l THEN DF$=DF$&DFT$ @ GOTO 4275
4295 IF p=1 THEN DF$=DFN$&DF$ @ GOTO 4275
4300 F$=DF$[1,p-1] @ IF LEN (F$)>6 THEN F$=F$[1,6]
4310 S$=DF$[p+1,l] @ IF LEN (S$)>3 THEN S$=S$[1,3]
4320 DF$=F$&SP$&S$ @ ft=LEN (F$)+1
4330 GOSUB open_write @ IF f#0 THEN srexit
4335 AWRITE 4,2,ST$(1)&" '"&SF$&"' as '"&DF$&"'"
4340
4350
4360
4370 rec_data: A$="DZF" @ T=9
4380 GOSUB get_pack @ IF f#0 THEN srexit
4390 IF RT$=SE$ THEN GOSUB close_write @ GOTO rec_head
4400 GOSUB put_data @ IF f#0 THEN srexit
4410 GOTO rec_data
5000
5010
5020
5030
5040
5050 show_pars: IF S$="" THEN sa
5060 set: GOSUB split @ S$=TRIM$ (S$)
5070 p=FNinlist(F$,SL$)
5080 IF p<1 THEN DF$=F$ @ I$=IO$ @ GOTO 5150
5090 I$=FNxlist$(SL$,p)
5100 IF C=5 THEN 5140
5110 DF$=S$ @ O=p
5115
5120 ON p GOSUB S0 ,S1 ,S2 ,S3 ,S4 ,S5 ,S6 ,S7 ,S8 ,S9 ,S10 ,S11 ,S12 ,S13 ,S14
5130 IF p<1 THEN 5150 ELSE p=O @ S$=DF$
5135
5140 ON p GOSUB s0 ,s1 ,s2 ,s3 ,s4 ,s5 ,s6 ,s7 ,s8 ,s9 ,s10 ,s11 ,s12 ,s13 ,s14
5150 IF p>-1 THEN AWRITE 22,0,I$&" - "&DF$
5160 RETURN
5500
5510
5520
5530
5540
5550 S0: RTO=FNpval(S$,RTO) @ RETURN
5560 S1: RLIM=FNpval(S$,RLIM) @ RETURN
5570 S2: ps=FNlset(S$,SC,OO$) @ RETURN
5580 S3: db=FNlset(S$,db,OO$) @ RETURN
5590 S4: p=0 @ IF LEN (S$)#1 THEN I$=IC$ @ RETURN
5600 SQCTL$=S$ @ RETURN
5610 S5: SEOL=FNpval(S$,SEOL) @ RETURN
5620 S6: T=0 @ DB$=""
5630 GOSUB split @ k=FNpval(F$,0)
5640 IF k=0 THEN RETURN
5650 DB$=DB$&CHR$ (k) @ T=T+1
5660 IF S$#"" AND T<4 THEN 5630
5670 RE=T @ RE$=DB$ @ p=7 @ RETURN
5680 S7: FS=FNpval(S$,FS) @ NR=FS*1024/RL @ RETURN
5690 S8: RL=FNpval(S$,RL) @ NR=FS*1024/RL @ RETURN
5700 S9: NR=FNpval(S$,NR) @ FS=NR*RL/1024 @ RETURN
5710 S10: DX=FNlset(S$,DX,DX$) @ LE=DX @ GOTO 5760
5720 S11: LE=FNlset(S$,LE,OO$) @ GOTO 5760
5730 S12: FC=FNlset(S$,FC,FC$) @ IF FC#0 THEN HS=0
5735 GOTO 5760
5740 S13: HS=FNlset(S$,HS,HS$) @ IF HS#0 THEN FC=0
5745 GOTO 5760
5750 S14: PT=FNlset(S$,PT,PT$)
5760 GOSUB rs_set @ RETURN
5770
6000
6010
6020
6030
6040
6110 sa: CLEAR
6120 FOR N=0 TO 14 @ n=N+1
6130 AWRITE 2+N DIV 2,40*(N MOD 2),FNxlist$(SL$,n)
6140 ON n GOSUB s0 ,s1 ,s2 ,s3 ,s4 ,s5 ,s6 ,s7 ,s8 ,s9 ,s10 ,s11 ,s12 ,s13 ,s14
6150 AWRITE 2+N DIV 2,15+40*(N MOD 2),DF$
6160 NEXT N
6170 RETURN
6200 s0: DF$=VAL$ (RTO) @ RETURN
6210 s1: DF$=VAL$ (RLIM) @ RETURN
6220 s2: DF$=FNxlist$(OO$,SC+1) @ RETURN
6230 s3: DF$=FNxlist$(OO$,db+1) @ RETURN
6240 s4: DF$=SQCTL$ @ RETURN
6250 s5: DF$=VAL$ (SEOL) @ RETURN
6260 s6: DF$=""
6262 FOR I=1 TO RE @ DF$=DF$&VAL$ (NUM (RE$[I,I]))&SP$ @ NEXT I
6265 RETURN
6270 s7: DF$=VAL$ (FS)&"k" @ RETURN
6280 s8: DF$=VAL$ (RL) @ RETURN
6290 s9: DF$=VAL$ (NR) @ RETURN
6300 s10: DF$=FNxlist$(DX$,DX+1) @ RETURN
6310 s11: DF$=FNxlist$(OO$,LE+1) @ RETURN
6320 s12: DF$=FNxlist$(FC$,FC+1) @ RETURN
6330 s13: DF$=FNxlist$(HS$,HS+1) @ RETURN
6340 s14: DF$=FNxlist$(PT$,PT+1) @ RETURN
10000
10010
10020
10030
10040
10050
10060
10070
10080 rec_pack: m=0 @ ID$=""
10090 ON TIMER# 1,TMO GOTO rto
10100 b_chk: STATUS IBUFF$,1 ; S
10105 K$=KEY$ @ IF K$#"" THEN rto
10110 IF S=0 THEN WAIT TMO/5 @ GOTO b_chk
10120 ENTER IBUFF$ USING "#,#K" ; I$
10130 l=LEN (I$) @ i=1
10140 n_chr: k$=I$[i,i]
10145 IF k$=MK$ THEN m=1 @ RP$="" @ j=0
10150 IF m=0 THEN i_chr
10160 IF k$=REOL$ THEN e_pck
10170 RP$=RP$&k$ @ j=j+1
10180 i_chr: i=i+1 @ IF i>l THEN b_chk ELSE n_chr
10190 e_pck: IF j<5 THEN 10100
10200 OFF TIMER# 1
10210 IF i