10 REM *****************
15 REM * XMODEM 64 3.5 *
20 REM *  KARL SCHMITT *
25 REM *****************
30 REM * VIC-20 VERSON *
35 REM * BY JOHN DAVIS $
40 REM *****************
45 POKE39928,10:POKE39929,48:PRINTCHR$(151)CHR$(14):OPEN5,2,3,CHR$(6)+CHR$(.)
50 OPEN15,8,15:U=212:D=256:W=1:E$=CHR$(147):C=250:S=64:P$=CHR$(19):O=8
55 BL$="":ER$="                  "+CHR$(13)
60 ACK=6:NAK=21:EOT=4:CAN=24:Z=131:V=132:F=255:M=288:P=12
65 C$=CHR$(.):R$=CHR$(18):J$=CHR$(13):O$=CHR$(18)+CHR$(32)+CHR$(157)+CHR$(146)
70 PRINTE$"XMODEM VIC"J$
75 PRINT"DOWNLOAD & UPLOAD":G$=CHR$(133):Q$=CHR$(34):I$=CHR$(20)
80 PRINT" TERMINAL PGM"J$J$"DISK VERSION 3.5"J$J$
85 PRINT"BY KARL SCHMITT"J$"AND JOHN DAVIS"J$
90 PRINT"HIT <F1> FOR MAIN MENU"
95 PRINTJ$"USE XMODEM PROTOCOL   FOR ALL TRANSFERS."J$J$:L$=CHR$(32)+CHR$(157)
100 PRINT"1. FULL DUPLEX"J$"2. HALF DUPLEX"J$
105 PRINT"TYPE 1 OR 2 TO BEGIN.":GOSUB510:IFA$="1"THEN120
110 IFA$="2"THENB=W:GOTO120
115 GOTO105
120 DIMF%(F),T%(F),U%(P,V)
125 PRINTE$"PLEASE STAND BY FOR 9 SECONDS."J$J$"CREATING  TRANSLATION TABLES."
130 FORJ=32TO64:T%(J)=J:NEXT:T%(13)=13:T%(20)=8:FORJ=65TO90:T%(J)=J+32:NEXT
135 FORJ=91TO95:T%(J)=J:NEXT:FORJ=193TO218:T%(J)=J-128:NEXT:T%(146)=P
140 T%(133)=P:T%(147)=19:T%(137)=3:T%(134)=17:T%(138)=19:FORJ=.TOF:K=T%(J)
145 IFK<>.THENF%(K)=J:F%(K+128)=J
150 NEXT:QQ$=Q$+CHR$(157)+CHR$(32)+CHR$(157)
151 REM ENTER LETTERS A-Z & SYMBOLS @*+-\ ON LINE 153 WITH COMMODORE KEY DOWN
152 REM IT MAY BE NESSARY TO USE THE SHORT FORM OF SOME COMMANDS
153 A$="ABCDEFGHIJKLMNOPQRSTUVWXYZ@*+-\":FORX=1TOLEN(A$):T%(ASC(MID$(A$,X,1)))=X:NEXT
155 REM------------TERMINAL------------
160 PRINTCHR$(14)
165 PRINTE$" TERMINAL MODE"J$:IFA$=CHR$(CAN)THENPRINT"TRANSFER CANCELLED!"
170 IFFA=WTHENPRINT"WHEN HOST IS READY TO RECIEVE, HIT F1"J$"FOR MAIN MENU AND";
175 IFFA=WTHENFA=.:PRINT" START THE UPLOAD."J$
180 GET#5,A$:IFA$=""THEN195
185 PRINTL$CHR$(F%(ASC(A$)));:IFA$=Q$THENPRINTQQ$;
190 GOTO180
195 PRINTO$;:GETA$:IFA$=""THEN180
200 IFB=WTHEN:X=ASC(A$):IFX=13ORX=145ORX=157ORX=29ORX=17ORX=19THENPRINTL$;
205 IFB=WTHENPRINTA$;:IFA$=Q$THENPRINTQQ$;
210 IFA$=G$THENPRINTL$J$:GOTO325
215 PRINT#5,CHR$(T%(ASC(A$)));:GOTO180
220 REM-----------DOWNLOAD-------------
225 PRINTE$"IS HOST COMPUTER WAITING TO SEND? Y/N":GOSUB510:IFA$="N"THEN160
230 PRINTJ$:IFA$<>"Y"THEN225
235 G=3:K$="W":GOSUB350:PRINT:BL=.
240 PRINTJ$"DOWNLOADING  "F$J$:GOSUB535:BL=0
250 CH=W:GET#5,D$:IFD$=CHR$(W)THENL=.:GOTO255
251 IFD$=CHR$(EOT)THENGOSUB525:CLOSE3:PRINT:PRINT"DONE":GOSUB620:GOTO160
252 IFD$=CHR$(CAN)THENGOSUB525:CLOSE3:PRINT:PRINT"CANCELLED":GOSUB620:GOTO160
253 GOTO260
255 PRINT":";:FORZZ=1TO1000:NEXT
256 FORX=2TO131:GET#5,A$:A$=LEFT$(A$+CHR$(0),1):D$=D$+A$:CH=(CH+ASC(A$))AND255:NEXT
257 GOTO 290
260 GETA$:IFA$=J$THENQ=10:GOTO530
270 L=L+W:IFL=220THENL=.:GOSUB530:PRINTCHR$(18)"WAITING"CHR$(146)Q:GOTO250
275 GOTO250
290 GET#5,A$:BK=0:FORX=1TO3
295 BK=BK+ASC(MID$(D$,X,1))AND255:NEXT:IFBKTHENPRINT"SOH ERROR":GOSUB530:GOTO250
300 IFASC(A$)<>(CHAND255)THENPRINT"CHECKSUM ERROR":GOSUB530:GOTO250
305 BL=(BL+1)AND255
310 IFASC(MID$(D$,2,1))<>BLTHENPRINT:PRINT"BLOCK NUMBER ERROR":GOSUB530:BL=(BL-1+256)AND255:GOTO250
315 PRINTCHR$(18)"DOWNLOADED BLOCK"BL;CHR$(146);:PRINT#3,MID$(D$,4,128)
316 Q=.:GOSUB525:GOTO250
320 REM-----------MENU-----------------
325 PRINTE$
330 PRINTJ$"1. DOWNLOAD"J$"2. UPLOAD"J$"3. TERMINAL"J$"4. DIRECTORY"
335 PRINT"5. RE-START UPLOAD"J$"6. END":GOSUB510
340 ONVAL(A$)GOTO225,380,160,480,590,520
345 GOTO330
350 POKE39928,10:POKE39929,96:PRINTE$:INPUT"FILENAME E(X)IT.";F$:IFF$="X"THEN325
355 PRINTE$:INPUT"FILETYPE (P)ROGRAM (S)EQUENTIAL E(X)IT";FT$:IFFT$="X"THEN325
360 FT$=LEFT$(FT$,W):POKE39928,10:POKE39929,48
365 OPENG,8,G,"0:"+F$+","+FT$+","+K$:INPUT#15,A,B$:PRINTE$;A;B$:IFA=.THENRETURN
370 CLOSEG:GOTO330
375 REM-----------UPLOAD---------------
380 G=6:K$="R":GOSUB350:BL=.:FA=W
385 PRINTER$"READING      ":FORY=WTOP:U%(Y,W)=W
390 BL=BL+W:U%(Y,2)=BL:U%(Y,3)=F-BL:CH=W+U%(Y,2)+U%(Y,3):PRINTER$"BLOCK"BL
395 FORX=EOTTOZ:GET#6,B$:IFST=.THEN405
400 FL=Y:CH=CH+U%(Y,X):FORA=X+WTOZ:U%(Y,A)=.:NEXT:U%(Y,V)=CHANDF:GOTO410
405 U%(Y,X)=ASC(B$+C$):CH=CH+U%(Y,X):NEXT:U%(Y,V)=CHANDF:NEXT:Y=Y-W
410 IFFA=WTHEN160
415 GET#5,A$:IFA$<>CHR$(NAK)THEN415
420 BL=BL-Y:Y=.
425 PRINTER$"UPLOAD STATUS"J$"NAK"BL$"UPLOADING"
430 Y=Y+W:BL=BL+W
435 PRINTBL$"BLOCK"BL:FORX=WTOV:PRINT#5,CHR$(U%(Y,X));:NEXT
440 FORA=.TO1200:GET#5,A$:IFA$=""THENNEXT:GOTO435
445 IFA$=CHR$(ACK)THENIFY=PTHENPRINTER$"ACK":GOTO385
450 IFA$=CHR$(ACK)THENIFFL<>YTHENPRINTER$"ACK":GOTO430
455 IFA$=CHR$(ACK)THENIFFL=YTHENFL=.:GOSUB540:GOSUB545:CLOSE6:GOTO555
460 IFA$=CHR$(NAK)THENPRINTER$"NAK":GOTO435
465 IFA$=CHR$(CAN)THENCLOSE6:GOTO555
470 GOTO440
475 REM---------DIRECTORY--------------
480 PRINTE$:OPEN1,8,0,"$0":GET#1,A$,A$
485 GET#1,A$,A$:IFA$=""THEN505
490 GET#1,A$,B$:PRINTASC(A$+C$)+ASC(B$+C$)*D;
495 GET#1,A$:IFA$=""THENPRINT:GOTO485
500 PRINTA$;:GOTO495
505 CLOSE1:GOTO330
510 GETA$:IFA$=""THEN510
515 RETURN
520 POKE39928,10:POKE39929,96:END
525 PRINT#5,CHR$(ACK);:Q=.:PRINT" ACK":RETURN
530 Q=Q+W:IFQ>10THENCLOSE3:A$=CHR$(CAN):PRINT#5,A$:GOTO555
535 PRINT#5,CHR$(NAK);:RETURN
540 PRINT#5,CHR$(EOT);:RETURN
545 GET#5,A$:IFA$=""THEN545
550 RETURN
555 PRINT"HIT ANY KEY FOR TERMINAL MODE"
560 SO=54272
565 POKESO+1,250:POKESO+5,10:POKESO+15,200
570 POKESO+24,15:FORCL=1TO12:POKESO+4,21:FORTM=1TO1250:NEXT:POKESO+4,20
575 GETB$:IFB$=""THEN565
580 SO=54272:FORCL=.TO24:POKESO+CL,.:NEXT
585 GOTO160
590 PRINTE$"IS HOST COMPUTER READY TO RECIEVE? Y/N"J$:GOSUB510:IFA$="N"THEN160
595 IFA$<>"Y"THEN590
600 PRINTE$"HAVE THE FIRST 16 (OR LESS) BLOCKS TO   UPLOAD BEEN READ YET?"
605 GOSUB510:IFA$="N"THEN160
610 IFA$<>"Y"THEN600
615 PRINTE$"UPLOADING  "F$:GOTO410
620 CLOSE15:OPEN15,8,15:INPUT#15,A,B$,C,D:CLOSE15:PRINTA,B$,D;D:RETURN
