10 REM *****************
15 REM * XMODEM 64 3.5 *
20 REM *  KARL SCHMITT *
25 REM *****************
30 POKE53281,.:POKE53280,.:PRINTCHR$(151)CHR$(14):OPEN5,2,3,CHR$(6)+CHR$(.)
35 OPEN15,8,15:U=212:D=256:W=1:E$=CHR$(147):C=250:S=64:P$=CHR$(19):O=8
40 BL$="":ER$="                  "+CHR$(13)
45 ACK=6:NAK=21:EOT=4:CAN=24:Z=131:V=132:F=255:M=288:P=12
50 C$=CHR$(.):R$=CHR$(18):J$=CHR$(13):O$=CHR$(18)+CHR$(32)+CHR$(157)+CHR$(146)
55 PRINTE$J$"XMODEM 64"J$
60 PRINT"DOWNLOAD & UPLOAD";:G$=CHR$(133):Q$=CHR$(34):I$=CHR$(20)
65 PRINT" TERMINAL PGM"J$J$"DISK VERSION 3.5"J$
70 PRINT"BY KARL SCHMITT"J$J$
75 PRINT"HIT <F1> FOR MAIN MENU."
80 PRINTJ$"USE XMODEM PROTOCOL FOR ALL TRANSFERS."J$J$:L$=CHR$(32)+CHR$(157)
85 PRINT"1. BULLETIN BOARD"J$J$"2. 64 TO 64"J$J$J$J$
90 PRINT"TYPE 1 OR 2 TO BEGIN.":GOSUB505:IFA$="1"THEN105
95 IFA$="2"THENB=W:GOTO105
100 GOTO90
105 DIMF%(F),T%(F),U%(P,V)
110 PRINTE$"PLEASE STAND BY FOR 9 SECONDS."J$J$"CREATING TRANSLATION TABLES."
115 FORJ=32TO64:T%(J)=J:NEXT:T%(13)=13:T%(20)=8:FORJ=65TO90:T%(J)=J+32:NEXT
120 FORJ=91TO95:T%(J)=J:NEXT:FORJ=193TO218:T%(J)=J-128:NEXT:T%(146)=P
125 T%(133)=P:T%(147)=19:T%(137)=3:T%(134)=17:T%(138)=19:FORJ=.TOF:K=T%(J)
130 IFK<>.THENF%(K)=J:F%(K+128)=J
135 NEXT
140 REM------------TERMINAL------------
145 PRINTCHR$(14)
150 PRINTE$" TERMINAL MODE"J$:IFA$=CHR$(CAN)THENPRINT"TRANSFER CANCELLED!"
155 IFFA=WTHENPRINT"WHEN HOST IS READY TO RECIEVE, HIT F1"J$"FOR MAIN MENU AND";
160 IFFA=WTHENFA=.:PRINT" START THE UPLOAD."J$
165 GET#5,A$:IFA$=""THEN180
170 PRINTL$CHR$(F%(ASC(A$)));:IFA$=Q$THENPOKEU,.
175 GOTO165
180 PRINTO$;:GETA$:IFA$=""THEN165
185 IFB=WTHEN:X=ASC(A$):IFX=13ORX=145ORX=157ORX=29ORX=17ORX=19THENPRINTL$;
190 IFB=WTHENPRINTA$;:IFA$=Q$THENPOKEU,.
195 IFA$=G$THENPRINTL$J$:GOTO320
200 PRINT#5,CHR$(T%(ASC(A$)));:GOTO165
205 REM-----------DOWNLOAD-------------
210 PRINTE$"IS HOST COMPUTER WAITING TO SEND? Y/N":GOSUB505:IFA$="N"THEN145
215 PRINTJ$:IFA$<>"Y"THEN210
220 G=3:K$="W":GOSUB345:PRINT:BL=.:N=.
225 PRINTJ$"DOWNLOADING  "F$J$
230 FORH=WTOP
235 CH=.:FORX=WTOV:GET#5,A$:E=ST:IFA$=""THENIFE=OTHENL=L+W
240 IFE=.THENL=.:GOTO255
245 IFL=MTHENL=.:GOSUB525:PRINTBL$"WAITING":GOTO230
250 GOTO235
255 IFX=WTHENIFA$=CHR$(EOT)THENPRINTER$"EOT":GOSUB520:GOTO310
260 U%(H,X)=ASC(A$+C$):CH=CH+U%(H,X):NEXT:CH=CH-U%(H,V)
265 IF(U%(H,W)+U%(H,2)+U%(H,3)AND F)<>.THENGOSUB525:PRINTER$"SOH ERROR":GOTO235
270 IFU%(H,V)<>(CHANDF)THENGOSUB525:PRINTER$"CHECKSUM ERROR":GOTO235
275 BL=BL+W:PRINTBL$"BLOCK"BL
280 IFU%(H,2)<>BLTHENBL=BL-1:GOSUB520:PRINTER$"DUPLICATE BL":GOTO235
285 IFH<>PTHENGOSUB520
290 NEXT:H=H-W
295 IFN=WTHENIFH=.THEN310
300 FORY=1TOH:FORX=EOTTOZ:PRINT#3,CHR$(U%(Y,X));:NEXT:NEXT
305 GOSUB520:GOTO230
310 FORA=WTOH:FORR=EOTTOZ:PRINT#3,CHR$(U%(A,R));:NEXT:NEXT:CLOSE3:GOTO550
315 REM-----------MENU-----------------
320 PRINTCHR$(142)E$
325 PRINTJ$"1. DOWNLOAD"J$"2. UPLOAD"J$"3. TERMINAL"J$"4. DIRECTORY"
330 PRINT"5. START UPLOAD"J$"6. END":GOSUB505
335 ONVAL(A$)GOTO210,375,145,475,585,515
340 GOTO325
345 PRINTE$:INPUT"FILENAME EXIT.";F$:IFF$="X"THEN320
350 PRINTE$:INPUT"FILETYPE (P)ROGRAM (S)EQUENTIAL E(X)IT";FT$:IFFT$="X"THEN320
355 FT$=LEFT$(FT$,W)
360 OPENG,8,G,"0:"+F$+","+FT$+","+K$:INPUT#15,A,B$:PRINTE$;A;B$:IFA=.THENRETURN
365 CLOSEG:GOTO325
370 REM-----------UPLOAD---------------
375 G=6:K$="R":GOSUB345:BL=.:FA=W
380 PRINTER$"READING      ":FORY=WTOP:U%(Y,W)=W
385 BL=BL+W:U%(Y,2)=BL:U%(Y,3)=F-BL:CH=W+U%(Y,2)+U%(Y,3):PRINTER$"BLOCK"BL
390 FORX=EOTTOZ:GET#6,B$:IFST=.THEN400
395 FL=Y:CH=CH+U%(Y,X):FORA=X+WTOZ:U%(Y,A)=.:NEXT:U%(Y,V)=CHANDF:GOTO405
400 U%(Y,X)=ASC(B$+C$):CH=CH+U%(Y,X):NEXT:U%(Y,V)=CHANDF:NEXT:Y=Y-W
405 IFFA=WTHEN145
410 GET#5,A$:IFA$<>CHR$(NAK)THEN410
415 BL=BL-Y:Y=.
420 PRINTER$"UPLOAD STATUS"J$"NAK"BL$"UPLOADING"
425 Y=Y+W:BL=BL+W
430 PRINTBL$"BLOCK"BL:FORX=WTOV:PRINT#5,CHR$(U%(Y,X));:NEXT
435 FORA=.TO1200:GET#5,A$:IFA$=""THENNEXT:GOTO430
440 IFA$=CHR$(ACK)THENIFY=PTHENPRINTER$"ACK":GOTO380
445 IFA$=CHR$(ACK)THENIFFL<>YTHENPRINTER$"ACK":GOTO425
450 IFA$=CHR$(ACK)THENIFFL=YTHENFL=.:GOSUB535:GOSUB540:CLOSE6:GOTO550
455 IFA$=CHR$(NAK)THENPRINTER$"NAK":GOTO430
460 IFA$=CHR$(CAN)THENCLOSE6:GOTO550
465 GOTO435
470 REM---------DIRECTORY--------------
475 PRINTE$:OPEN1,8,0,"$0":GET#1,A$,A$
480 GET#1,A$,A$:IFA$=""THEN500
485 GET#1,A$,B$:PRINTASC(A$+C$)+ASC(B$+C$)*D;
490 GET#1,A$:IFA$=""THENPRINT:GOTO480
495 PRINTA$;:GOTO490
500 CLOSE1:GOTO325
505 GETA$:IFA$=""THEN505
510 RETURN
515 END
520 PRINT#5,CHR$(ACK);:Q=.:RETURN
525 Q=Q+W:IFQ=11THENCLOSE3:A$=CHR$(CAN):PRINT#5,A$:GOTO550
530 PRINT#5,CHR$(NAK);:RETURN
535 PRINT#5,CHR$(EOT);:RETURN
540 GET#5,A$:IFA$=""THEN540
545 RETURN
550 PRINT"HIT ANY KEY FOR TERMINAL MODE"
555 SO=54272
560 POKESO+1,250:POKESO+5,10:POKESO+15,200
565 POKESO+24,15:FORCL=1TO12:POKESO+4,21:FORTM=1TO1250:NEXT:POKESO+4,20
570 GETB$:IFB$=""THEN560
575 SO=54272:FORCL=.TO24:POKESO+CL,.:NEXT
580 GOTO145
585 PRINTE$"IS HOST COMPUTER READY TO RECIEVE? Y/N"J$:GOSUB505:IFA$="N"THEN145
590 IFA$<>"Y"THEN585
595 PRINTE$"HAVE THE FIRST 16 (OR LESS) BLOCKS TO   UPLOAD BEEN READ YET?"
600 GOSUB505:IFA$="N"THEN145
605 IFA$<>"Y"THEN595
610 PRINTE$"UPLOADING  "F$:GOTO405
