0010 REM *****************************************************
0020 REM *                                                   *
0030 REM *               KERMIT RDOS                         *
0040 REM *             ===================                   *
0050 REM *                                                   *
0060 REM *  KERMIT PROTOCOL MANUAL CLOSELY EXEPT FOR USER    *
0070 REM *  INTERACTION, WHICH USES A MORE INTERACTIVE       *
0080 REM *  DIALOGUE .                                       *
0090 REM *  THIS VERSION IS A MODIFICATION FOR RDOS OF THE   *
0100 REM *  VERSION OF TORBJORN ALM & PER LINDBERG FOR THE   *
0110 REM *  ABC-800.                                         *
0120 REM *                                                   *
0130 REM *  MODIFIER LE 06/12/85    REMI CASTONGUAY          *
0140 REM *                                                   *
0150 REM *  MODIFIER LEGEREMENT POUR L'ECLIPSE               *
0160 REM *****************************************************
0170 REM
0180 DIM RECPKT$[80],PACKET$[80],INBUFF$[512],SP$[25],B$[90],QUO$[1],H$[1]
0190 DIM DUMMY$[1],FILE$[60],S$[80],F$[1],AA$[60],FNQ$[10]
0200 DIM SPAR$[100],INCHR$[90],TYPE$[100],X$[1],MESSAG$[90],REPLY$[90]
0210 DIM BUFFER$[90],DATAX$[80],DATA$[80],DEBUG$[3]
0220 DIM H1$[1],H2$[2],H3$[3],H4$[4],CONTRO$[32]
0230 LET MAXPCK=78 \ SOH=1 \ MAXTRY=500 \ MYPAD=0 \ MYCHAR=0 \ MYEOL=13
0240 LET MYTIME=5 \ MAXTIM=20 \ MINTIM=2 \ TRUE=-1 \ FALSE=0
0250 LET SP=32 \ DEL=127 \ EOL=13 \ OK=0 \ BLOC=0 \ CTES=0
0260 LET SP$=FILL$(32) \ QUO$="#" \ MYQUOT=ASC(QUO$)
0270 LET PORT=2 \ RET%=3 \ ER=0 \ TIMINT=5 \ ETC=38 \ FIN=0
0272 LET LREC=0
0280 FOR I=0 TO 31
0290   LET CONTRO$[0]=CHR$(I,1)
0300 NEXT I
0310 CLOSE
0320 STMA 7,0
0330 LET DEBUG=0 \ DEBUG$="OFF" \ ENV%=PORT
0340 PRINT @(-30)
0350 GOSUB 5180 : PRINT MENU - INPUT COMMAND
0360 ON F THEN GOTO 4800, 0410, 0490, 0570, 0620
0370 ON IKEY THEN GOTO 0250
0380 REM **************************
0390 REM  RECEIVE FILES FROM REMOTE
0400 REM **************************
0410 GOSUB 3500 : STATE TABLE SWITCHER FOR RECEIVE FILES
0420 IF STATE THEN PRINT @(19,1);"OK ";SP$ ELSE PRINT @(19,1);"RCEIV FAILED";SP$
0430 PRINT "<PUSH ANY KEY TO CONTINUE>"
0440 INPUT USING "","",@(-10,1),X$
0450 GOTO 0310
0460 REM **************************
0470 REM SEND FILE TO REMOTE
0480 REM **************************
0490 GOSUB 4940 : INPUT FILE NAMES - CHECK FILES
0500 IF NFILE<0 THEN GOTO 0310
0510 GOSUB 2100 : SEND SUPERVISOR
0520 IF STATE THEN PRINT @(19,1);"OK";SP$ ELSE PRINT @(19,1);"SEND FAILED";SP$
0530 PRINT "<PUSH ANY KEY TO CONTINUE>"
0540 INPUT USING "","",@(-10,1),X$
0550 GOTO 0310
0560 REM *************************
0570 REM END OF KERMIT SESSION
0580 REM *************************
0590 PRINT @(15,20);"END OF KERMIT SESSION"
0600 CLOSE
0610 END
0620 IF DEBUG THEN GOTO 0650
0630 LET DEBUG=1 \ DEBUG$="ON "
0640 GOTO 0350
0650 LET DEBUG=0 \ DEBUG$="OFF"
0660 GOTO 0350
0670 REM *******************************
0680 REM SEND MY PARAMETERS TO OTHER END
0690 REM *******************************
0700 LET SPAR$=CHR$(MAXPCK+32,1),CHR$(MYTIME+32,1),CHR$(MYPAD+32,1)
0702 LET SPAR$[0]=CHR$(OR(MYCHAR,64)),CHR$(MYEOL+32,1),CHR$(MYQUOT,1)
0705 LET SPAR$[0]="&","1"," "
0710 RETURN
0720 REM **************************
0730 REM UNPACK DATA FROM OTHER END
0740 REM **************************
0750 LET SPSIZ=MIN(ASC(S$[1,1])-32,80)
0760 LET TIMINT=ASC(S$[2,2])-32
0770 LET PAD=ASC(S$[3,3])-32
0780 LET PADCHR=ASC(S$[4,4])-32
0790 LET PADCHR=OR(PADCHR,64)
0800 LET EOL=ASC(S$[5,5])-32
0810 LET QUOTE=ASC(S$[6,6])-32
0820 RETURN
0830 REM ***********************
0840 REM UNPACK A PACKET TO FILE
0850 REM B$  = PACKET BUFFER
0860 REM ***********************
0870 LET B$=""
0880 FOR I=1 TO LEN(PACKET$)
0890   LET H$=PACKET$[I,I]
0900   LET K=POS("#&",H$,1)
0910   ON K THEN GOSUB 0960, 1030
0920   LET B$[0]=H$
0930 NEXT I
0940 WRITE FILE[2],B$[1,LEN(B$)]
0950 RETURN
0960 REM
0970 GOSUB 1220
0980 IF POS("&#",H$,1) THEN RETURN
0990 LET H=OR(ASC(H$),64)
1000 IF AND(ASC(H$),64) THEN LET H=H-64
1010 LET H$=CHR$(H)
1020 RETURN
1030 REM
1040 GOSUB 1220
1050 IF H$="#" THEN GOSUB 1080
1060 GOSUB 1140
1070 RETURN
1080 REM
1090 GOSUB 1220
1100 LET K=POS("&#",H$,1)
1110 ON K THEN GOTO 1140, 1140
1120 GOSUB 1170
1130 RETURN
1140 REM
1150 LET H$=CHR$(OR(ASC(H$),128))
1160 RETURN
1170 REM
1180 LET H=OR(ASC(H$),64)
1190 IF AND(ASC(H$),64) THEN LET H=H-64
1200 LET H$=CHR$(H)
1210 RETURN
1220 REM
1230 LET I=I+1 \ H$=PACKET$[I,I]
1240 RETURN
1250 REM **************************
1260 REM FILL BUFFER, RETURN SIZE
1270 REM **************************
1280 LET B$=""
1290 IF EOF(2) THEN GOTO 1440
1300 IF LEN(INBUFF$)=0 THEN IF LREC THEN GOTO 1501 ELSE GOSUB 1460
1310 IF EOF(2) THEN GOTO 1440
1320 LET H$=INBUFF$[1,1] \ H1$=""
1330 IF ASC(H$)>127 THEN GOSUB 5350 ELSE LET H2$=H$
1340 LET I=LEN(H2$) \ H$=H2$[I,I]
1350 IF POS("#&",H$,1) THEN GOSUB 5400 ELSE LET H3$=H2$
1360 LET I=LEN(H3$) \ H$=H3$[I,I]
1370 IF POS(CONTRO$,H$,1) THEN GOSUB 5450 ELSE LET H4$=H3$
1380 LET B$[0]=H4$
1390 IF LEN(INBUFF$)>=2 THEN LET INBUFF$=INBUFF$[2] ELSE LET INBUFF$=""
1400 IF LEN(B$)>=SPSIZ-8 THEN GOTO 1420
1410 GOTO 1290
1420 LET PACKET$=B$
1430 RETURN
1440 LET STATE=ASC("Z")
1450 RETURN
1460 BLOCK READ FILE[2,BLOC],INBUFF$
1470 LET BLOC=BLOC+1
1480 RETURN
1490 LET B$[0]=H$
1500 GOTO 1390
1501 REM
1502 IF TOBUFF=LAST THEN GOTO 1440
1504 LET TOBUFF=TOBUFF+1
1506 READ FILE[2],INBUFF$[1,LREC]
1508 GOTO 1310
1510 REM ***************************************
1520 REM SEND PACKET TO OTHER END - CALL BY NAME
1530 REM ***************************************
1540 STMA 8,4
1550 STMA 6,0
1560 STMA 6,1
1570 STMA 6,2
1580 LET BUFFER$=CHR$(SOH),CHR$(LENGTH+35),CHR$(NUM+32),CHR$(TYPE),DATA$
1590 LET CHKSUM=LENGTH+NUM+TYPE+67
1600 LET I=1
1610 IF I>LENGTH THEN GOTO 1650
1620 LET CHKSUM=CHKSUM+ASC(DATA$[I,I])
1630 LET I=I+1
1640 GOTO 1610
1650 LET CHKSUM=AND((CHKSUM+AND(CHKSUM,192)/64),63)
1660 LET BUFFER$=BUFFER$,CHR$(CHKSUM+32),CHR$(EOL),CHR$(10)
1670 LET MESSAG$=BUFFER$
1680 GOSUB 5540 : GET LA LIGNE AU COMPLET
1690 LET H$=CHR$(TYPE)
1700 PRINT @(15,1);"SEND PACKET ";COMP;"  ";H$;"  ";NUMTRY
1710 RETURN
1720 REM *******************************************************
1730 REM            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
1740 REM *******************************************************
1760 STMA 6,0
1770 STMA 6,1
1780 STMA 6,2
1790 IF TIMINT>MAXTIM THEN LET TIMINT=MYTIME
1800 IF TIMINT<MINTIM THEN LET TIMINT=MYTIME
1810 LET T=0 \ V=0
1820 IF T=SOH THEN GOTO 1850
1830 GOSUB 5120 : GET LINE CHAR ONE BY ONE
1840 IF T<>SOH THEN GOTO 2070
1850 GOSUB 5120 : GET LINE CHAR ONE BY ONE
1860 IF T<0 THEN GOTO 1850 ELSE IF T=SOH THEN GOTO 2020
1870 LET CHKSUM=T \ L=T-35 \ LENGTH=T
1875 IF L+5<>LEN(INCHR$) THEN GOTO 2070
1880 GOSUB 5120 : GET LINE CHAR ONE BY ONE
1890 IF T<0 THEN GOTO 1880 ELSE IF T=SOH THEN GOTO 2020
1900 LET CHKSUM=CHKSUM+T \ NUM=T-32
1910 GOSUB 5120 : GET LINE CHAR ONE BY ONE
1920 IF T<0 THEN GOTO 1910 ELSE IF T=SOH THEN GOTO 2020
1930 LET CHKSUM=CHKSUM+T \ TYPE=T \ DATAX$=""
1940 FOR I=1 TO L
1950   GOSUB 5120 : GET LINE CHAR ONE BY ONE
1960   IF T<0 THEN GOTO 1950 ELSE IF T=SOH THEN GOTO 2020
1970   LET CHKSUM=CHKSUM+T
1980   LET DATAX$[0]=CHR$(T,1)
1990 NEXT I
2000 GOSUB 5120 : GET LINE CHAR ONE BY ONE
2010 IF T<0 THEN GOTO 2000
2020 LET CHKSUM=AND((CHKSUM+AND(CHKSUM,192)/64),63)
2030 IF CHKSUM<>T-32 THEN GOTO 2070
2040 LET H$=CHR$(TYPE)
2050 PRINT @(15,40);"RECEIVE PACKET   ";COMP;" ";H$;"  ";NUMTRY
2060 RETURN
2070 LET TYPE=0
2080 RETURN
2090 REM ***************
2100 REM SEND SUPERVISOR
2110 REM ***************
2120 LET STATE=ASC("S") \ N=0 \ NUMTRY=0 \ COMP=0 \ TOBUFF=0
2130 IF DEBUG THEN GOSUB 2330
2140 LET H$=CHR$(STATE)
2150 LET K=POS("DFZSBCA",H$,1)+1
2160 ON K THEN GOTO 2170, 2190, 2210, 2230, 2250, 2270, 2290, 2310
2170 LET STATE=FALSE
2180 RETURN
2190 GOSUB 2820 : SEND DATA FILE
2200 GOTO 2140
2210 GOSUB 2580 : SEND FILE HEADER
2220 GOTO 2140
2230 GOSUB 3090 : SEND END-OF-FILE
2240 GOTO 2140
2250 GOSUB 2360 : SENAMETERS, GET OTHER SIDE'S BACK
2260 GOTO 2140
2270 GOSUB 3320 : SEND BREAK (EOT)
2280 GOTO 2140
2290 LET STATE=TRUE
2300 RETURN
2310 LET STATE=FALSE
2320 RETURN
2330 OPEN FILE[6,0],"LOG.LOG"
2340 RETURN
2350 REM *****************************************
2360 REM SENAMETERS, GET OTHER SIDE'S BACK
2370 REM *****************************************
2380 IF NUMTRY>MAXTRY THEN GOTO 2550
2390 LET NUMTRY=NUMTRY+1
2400 GOSUB 0680 : SEND MY PARAMETERS TO OTHER END
2410 LET PACKET$=SPAR$
2420 LET TYPE=ASC("S") \ NUM=N \ LENGTH=9 \ DATA$=PACKET$
2430 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
2440 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
2450 LET RECPKT$=DATAX$
2460 IF TYPE<>ASC("Y") THEN IF TYPE<>ASC("S") THEN GOTO 2380
2470 IF N<>NUM THEN GOTO 2380
2480 LET S$=RECPKT$
2490 GOSUB 0730 : UNPACK DATA FROM OTHER END
2500 IF EOL=0 THEN LET EOL=13
2510 IF QUOTE=0 THEN LET QUOTE=ASC(QUO$)
2520 LET NUMTRY=0 \ N=AND((N+1),63) \ COMP=COMP+1
2530 LET STATE=ASC("F")
2540 RETURN
2550 LET STATE=ASC("A")
2560 RETURN
2570 REM ****************
2580 REM SEND FILE HEADER
2590 REM ****************
2600 IF OK=1 THEN GOSUB 5000
2610 PRINT @(11,40);"SENDING FILE: ";FILE$
2620 IF NUMTRY>MAXTRY THEN GOTO 2790
2630 LET NUMTRY=NUMTRY+1
2640 LET LENGTH=LEN(FILE$)
2650 LET TYPE=ASC("F") \ NUM=N \ DATA$=FILE$
2660 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
2670 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
2680 LET RECPKT$=DATAX$
2690 LET H$=CHR$(TYPE)
2700 LET K=POS("NY",H$,1)+1
2710 ON K THEN GOTO 2650, 2650, 2730, 2780
2720 LET NUM=AND((NUM-1),63)
2730 IF N<>NUM THEN RETURN
2740 LET NUMTRY=0 \ N=AND((N+1),63) \ COMP=COMP+1
2750 GOSUB 1260 : FILL BUFFER, RETURN SIZE
2760 LET SIZ=LEN(PACKET$)
2770 LET STATE=ASC("D")
2780 RETURN
2790 LET STATE=ASC("A")
2800 RETURN
2810 REM **************
2820 REM SEND DATA FILE
2830 REM **************
2840 LET TYPE=ASC("D") \ NUM=N \ LENGTH=SIZ \ DATA$=PACKET$
2850 IF NUMTRY>MAXTRY THEN GOTO 3040
2860 LET NUMTRY=NUMTRY+1
2870 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
2880 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
2890 LET RECPKT$=DATAX$
2900 LET H$=CHR$(TYPE)
2910 LET K=POS("NY",H$,1)+1
2920 ON K THEN GOTO 2930, 2930, 2960, 2930
2930 LET TYPE=ASC("D")
2940 LET LENGTH=SIZ \ DATA$=B$ \ NUM=N
2950 GOTO 2850
2960 IF N<>NUM THEN GOTO 2930
2970 LET OLDTRY=NUMTRY \ NUMTRY=0 \ N=AND((N+1),63) \ COMP=COMP+1
2980 GOSUB 1260 : FILL BUFFER, RETURN SIZE
2990 LET PACKET$=B$
3000 LET SIZ=LEN(PACKET$)
3010 IF SIZ=0 THEN GOTO 3060
3020 LET STATE=ASC("D")
3030 RETURN
3040 LET STATE=ASC("A")
3050 RETURN
3060 LET STATE=ASC("Z")
3070 RETURN
3080 REM ****************
3090 REM SEND END-OF-FILE
3100 REM ****************
3110 IF NUMTRY>MAXTRY THEN GOTO 3270
3120 LET NUMTRY=NUMTRY+1
3130 LET TYPE=ASC("Z") \ NUM=N \ LENGTH=0 \ DATA$=""
3140 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
3150 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
3160 LET RECPKT$=DATAX$
3170 LET H$=CHR$(TYPE)
3180 LET K=POS("NY",H$,1)+1
3190 ON K THEN GOTO 3270, 3200, 3210, 3260
3200 LET NUM=AND((NUM-1),63)
3210 IF N<>NUM THEN RETURN
3220 LET NUMTRY=0 \ N=AND((N+1),63) \ COMP=COMP+1
3230 CLOSE FILE[2]
3240 IF NFILE<>1 THEN GOTO 3290
3250 LET STATE=ASC("F") \ OK=1
3260 RETURN
3270 LET STATE=ASC("A")
3280 RETURN
3290 LET STATE=ASC("B")
3300 RETURN
3310 REM ****************
3320 REM SEND BREAK (EOT)
3330 REM ****************
3340 IF NUMTRY>MAXTRY THEN GOTO 3470
3350 LET TYPE=ASC("B") \ NUM=N \ LENGTH=0 \ DATA$=""
3360 LET NUMTRY=NUMTRY+1
3370 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
3380 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
3390 LET RECPKT$=DATAX$
3400 LET H$=CHR$(TYPE)
3410 LET K=POS("NY",H$,1)+1
3420 ON K THEN GOTO 3470, 3430, 3440, 3460
3430 LET NUM=AND((NUM-1),63)
3440 IF N<>NUM THEN RETURN
3450 LET NUMTRY=0 \ N=AND((N+1),63) \ STATE=ASC("C") \ COMP=COMP+1
3460 RETURN
3470 LET STATE=ASC("A")
3480 RETURN
3490 REM **************************************
3500 REM STATE TABLE SWITCHER FOR RECEIVE FILES
3510 REM **************************************
3520 LET FIL=0 \ STATE=ASC("R") \ N=0 \ NUMTRY=0 \ COMP=0
3530 IF DEBUG THEN GOSUB 3680
3550 LET H$=CHR$(STATE)
3560 LET K=POS("DFRCA",H$,1)+1
3570 ON K THEN GOTO 3575, 3580, 3600, 3620, 3640, 3660
3575 LET STATE=FALSE
3577 RETURN
3580 GOSUB 4380 : RECEIVE DATA
3590 GOTO 3550
3600 GOSUB 3950 : RECEIVE FILE HEADER
3610 GOTO 3550
3620 GOSUB 3710 : RECEIVE INITIALIZATION
3630 GOTO 3550
3640 LET STATE=TRUE
3650 RETURN
3660 LET STATE=FALSE
3670 RETURN
3680 OPEN FILE[6,0],"LOG.LOG"
3690 RETURN
3700 REM **********************
3710 REM RECEIVE INITIALIZATION
3720 REM **********************
3730 IF NUMTRY>MAXTRY THEN GOTO 3920
3740 LET NUMTRY=NUMTRY+1
3750 LET MESSAG$=""
3760 GOSUB 5540 : GET LA LIGNE AU COMPLET
3770 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
3780 LET PACKET$=DATAX$
3790 IF TYPE<>ASC("S") THEN GOTO 3880
3800 LET S$=PACKET$
3810 GOSUB 0730 : UNPACK DATA FROM OTHER END
3820 GOSUB 0680 : SEND MY PARAMETERS TO OTHER END
3830 LET PACKET$=SPAR$
3840 LET TYPE=ASC("Y") \ NUM=N \ LENGTH=9 \ DATA$=PACKET$
3850 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
3860 LET OLDTRY=NUMTRY \ NUMTRY=0 \ N=AND((N+1),63) \ STATE=ASC("F")
3865 LET COMP=COMP+1
3870 RETURN
3880 LET TYPE=ASC("N") \ NUM=N \ LENGTH=0 \ DATA$="" \ NUMTRY=NUMTRY+1
3890 IF NUMTRY>MAXTRY THEN GOTO 3920
3900 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
3910 GOTO 3770
3920 LET STATE=ASC("A")
3930 RETURN
3940 REM *******************
3950 REM RECEIVE FILE HEADER
3960 REM *******************
3970 IF NUMTRY>MAXTRY THEN GOTO 4350
3980 LET NUMTRY=NUMTRY+1
3990 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
4000 LET PACKET$=DATAX$
4010 LET H$=CHR$(TYPE)
4020 LET K=POS("SZFB",H$,1)+1
4030 ON K THEN GOTO 4040, 4070, 4150, 4220, 4300, 4330
4040 LET STATE=ASC("N") \ NUM=N \ LENGTH=0 \ DATA$=""
4050 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4060 GOTO 3990
4070 LET OLDTRY=OLDTRY+1
4080 IF OLDTRY>MAXTRY THEN GOTO 4040
4090 LET STATE=ASC("R") \ N,COMP=0
4100 RETURN
4110 LET PACKET$=SPAR$ \ TYPE=ASC("Y") \ NUM=N \ LENGTH=6 \ DATA$=PACKET$
4120 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4130 LET NUMTRY=0
4140 RETURN
4150 LET OLDTRY=OLDTRY+1
4160 IF OLDTRY>MAXTRY THEN GOTO 4040
4170 IF NUM<>AND((N+1),63) THEN GOTO 4040
4180 LET TYPE=ASC("Y") \ NUM=N \ LENGTH=0 \ DATA$=""
4190 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4200 LET NUMTRY=0
4210 RETURN
4220 IF NUM<>N THEN GOTO 4040
4230 LET AA$=PACKET$
4240 PRINT @(11,40);"FILE NAME: ";AA$
4250 GOSUB 5310 : CREATE NEW FILE
4260 LET TYPE=ASC("Y") \ NUM=N \ LENGTH=0 \ DATA$=""
4270 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4280 LET OLDTRY=NUMTRY \ NUMTRY=0 \ N=AND((N+1),63) \ STATE=ASC("D")
4285 LET COMP=COMP+1
4290 RETURN
4300 IF NUM<>N THEN GOTO 4040
4310 LET TYPE=ASC("Y") \ NUM=N \ LENGTH=0 \ DATA$="" \ STATE=ASC("C") \ FIN=1
4320 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4330 RETURN
4340 PRINT @(15,1);"COULD NOT CREATE";PACKET$
4350 LET STATE=ASC("A")
4360 RETURN
4370 REM ************
4380 REM RECEIVE DATA
4390 REM ************
4400 IF NUMTRY>MAXTRY THEN GOTO 4780
4410 LET NUMTRY=NUMTRY+1
4420 GOSUB 1730 :            RECEIVE PACKET, STORE LEN,NUM ET RETURN TYPE
4430 LET PACKET$=DATAX$
4440 LET H$=CHR$(TYPE)
4450 LET K=POS("DFZ",H$,1)+1
4460 ON K THEN GOTO 4750, 4470, 4600, 4690, 4770
4470 IF NUM=N THEN GOTO 4550 ELSE LET OLDTRY=OLDTRY+1
4480 IF OLDTRY>MAXTRY THEN GOTO 4780
4490 IF NUM=AND((N-1),63) THEN GOTO 4510
4500 IF NUM<>N THEN GOTO 4750
4510 LET TYPE=ASC("Y") \ LENGTH=0 \ DATA$="" \ NUMTRY=NUMTRY+1
4520 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4530 LET NUMTRY=0
4540 RETURN
4550 GOSUB 0840 : UNPACK A PACKET TO FILE
4560 LET TYPE=ASC("Y") \ LENGTH=0 \ DATA$="" \ NUM=N
4570 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4580 LET OLDTRY=NUMTRY \ NUMTRY=0 \ N=AND((N+1),63) \ STATE=ASC("D")
4585 LET COMP=COMP+1
4590 RETURN
4600 LET OLDTRY=OLDTRY+1
4610 IF OLDTRY>MAXTRY THEN GOTO 4780
4620 IF NUM=AND((N-1),63) THEN GOTO 4650
4630 LET STATE=ASC("A")
4640 RETURN
4650 LET TYPE=ASC("Y") \ LENGTH=0 \ DATA$=""
4660 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4670 LET NUMTRY=0
4680 RETURN
4690 IF NUM<>N THEN GOTO 4780
4700 LET TYPE=ASC("Y") \ NUM=N \ LENGTH=0 \ DATA$=""
4710 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4720 CLOSE FILE[2]
4730 LET N=AND((N+1),63) \ STATE=ASC("F") \ COMP=COMP+1
4740 RETURN
4750 LET TYPE=ASC("N") \ LENGTH=0 \ DATA$=""
4760 GOSUB 1520 : SEND PACKET TO OTHER END - CALL BY NAME
4770 GOTO 4400
4780 LET STATE=ASC("A")
4790 RETURN
4800 REM *****************************************
4810 REM SET PORT I/O
4820 REM *****************************************
4830 IF PORT=2 THEN GOTO 4850
4835 LET PORT,ENV%=2
4840 GOTO 0350
4850 LET PORT,ENV%=5
4860 GOTO 0350
4930 REM ******************************
4940 REM INPUT FILE NAMES - CHECK FILES
4950 REM ******************************
4960 INPUT USING "",@(13,1),"SPECIFY FILE NAMES:",@(-10,-60),AA$
4970 IF LEN(AA$)<>0 THEN GOTO 5000
4980 LET NFILE=0
4990 RETURN
5000 REM
5010 LET K=POS(AA$,",",1)
5020 IF K THEN LET FILE$=AA$[1,K-1] \ AA$=AA$[(K+1),LEN(AA$)] \ NFILE=1 \ BLOC=0
5030 IF K THEN GOTO 5050 : ON ERR THEN GOTO 3970
5040 LET FILE$=AA$ \ NFILE=0 \ BLOC,W=0
5045 LET K=POS(FILE$,"/",1)
5047 IF K THEN GOTO 5100
5050 REM ON ERR THEN GOTO 3970
5060 OPEN FILE[2,4],FILE$
5070 RETURN
5080 PRINT @(14,1);"FILE ";FILE$;" DOES NOT EXIST - ABORT !!!!!!"
5090 LET NFILE=-1
5095 RETURN
5100 LET LREC=VAL(FILE$[K+1,LEN(FILE$)],W)
5101 LET FILE$=FILE$[1,K-1],FILL$(32)
5102 OPEN FILE[2,6],FILE$
5104 POSITION FILE[2,6]
5105 READ FILE[2],LAST
5106 POSITION FILE[2,0]
5107 IF LREC=300 THEN POSITION FILE[2,LREC]
5108 RETURN
5110 REM ************************
5120 REM GET LINE CHAR ONE BY ONE
5130 REM ************************
5140 LET V=V+1
5150 LET T=ASC(INCHR$[V,V])
5160 RETURN
5170 REM **************************
5180 REM PRINT MENU - INPUT COMMAND
5190 REM **************************
5200 PRINT @(1,1);"   K E R M I T    F O R    S U P E R D O S "
5210 PRINT @(-28);@(-28)
5220 PRINT @(4,1);"P   PORT I/O                         DEBUG: ";DEBUG$
5230 PRINT @(5,1);"R   RECEIVE FILES FROM HOST          PORT: ";PORT
5240 PRINT @(6,1);"S   SEND FILES TO HOST"
5250 PRINT @(7,1);"D   DEBUG MODE"
5260 PRINT @(8,1);"E   EXIT KERMIT"
5270 INPUT USING "",@(11,1),"SPECIFY FUNCTION :",@(-10,-1),F$
5280 LET F=(POS("PpRrSsEeDd",F$,1)+1)/2
5290 IF F=0 THEN GOTO 5270 ELSE RETURN
5300 REM ***************
5310 REM CREATE NEW FILE
5320 REM ***************
5322 LET K=POS(AA$,".",1)
5324 IF K THEN LET AA$=AA$[1,K-1],FILL$(32)
5330 OPEN FILE[2,0],AA$
5340 RETURN
5350 REM ****************
5360 REM QUOTE 8 BIT
5370 REM ****************
5380 LET H2$="&",CHR$(AND(ASC(H$),127)) \ H1$="&"
5390 RETURN
5400 REM ***************************
5410 REM QUOTE A CHAR "#" AND "&"
5420 REM ***************************
5430 LET H3$=H1$,"#",H$
5440 RETURN
5450 REM *********************
5460 REM QUOTE CHAR CONTROL
5470 REM *********************
5480 IF I>1 THEN LET H4$=H3$[1,I-1] ELSE LET H4$=""
5490 LET H=OR(ASC(H$),64)
5500 IF AND(ASC(H$),64) THEN LET H=H-64
5510 LET H4$=H4$,"#",CHR$(H,1)
5520 RETURN
5530 REM *******************************
5540 REM GET LA LIGNE AU COMPLET
5550 REM *******************************
5560 IF FIN THEN GOTO 5640
5570 LET REPLY$=""
5580 IF DEBUG THEN WRITE FILE[6],MESSAG$
5590 STMD 1,ENV%,50,MESSAG$,REPLY$
5600 IF SYS(22)=0 THEN IF CTES>30 THEN GOTO 0600 ELSE GOTO 5660
5610 IF DEBUG THEN WRITE FILE[6],REPLY$
5620 LET INCHR$=REPLY$[1,LEN(REPLY$)] \ CTES=0
5630 RETURN
5640 STMD 1,ENV%,0,MESSAG$
5650 RETURN
5660 LET CTES=CTES+1
5670 GOTO 5590
 
