1000 KEY OFF
1001 DEFINT A-Z
1010 REM Trap error opening input file
1020 ON ERROR GOTO 1600
1030 CLS
1040 LOCATE 5,11
1050 PRINT STRING$(40," ")
1060 LOCATE 5,11
1070 INPUT "Enter name of input file: ", INFILE$
1080 OPEN INFILE$ FOR INPUT AS #1
1090 LOCATE 8,10
1100 PRINT STRING$(40," ")
1110 REM Trap error opening output file
1120 ON ERROR GOTO 1640
1130 LOCATE 8,10
1140 INPUT "Enter name of output file: ", OUTFILE$
1150 OPEN "R", #2,OUTFILE$, 1
1160 FIELD #2, 1 AS N$
1170 REM Trap error at end of file
1180 ON ERROR GOTO 1680
1190 REM Search for header line
1200 LINE INPUT #1,A$
1210 IF LEFT$(A$,5) <>"begin" THEN 1200
1220 LOCATE 11,10
1230 PRINT "Header = ";A$
1240 SP = ASC(" ")
1250 DIM BUF(100)
1260 RECNO# = 1
1270 REM Main loop
1280 LINE INPUT #1, A$
1290 P = 0
1300 COUNT = ASC(LEFT$(A$,1)) - SP
1310 IF COUNT = 64 THEN COUNT = 0
1320 IF COUNT = 0 THEN 1560
1330 ADJ = COUNT MOD 4
1340 FOR I = 2 TO LEN(A$) STEP 4
1350    X1 = ASC(MID$(A$,I,I)) - SP
1360    IF X1 = 64 THEN X1 = 0
1370    X2 = ASC(MID$(A$,I+1,I+1)) - SP
1380    IF X2 = 64 THEN X2 = 0
1390    X3 = ASC(MID$(A$,I+2,I+2)) - SP
1400    IF X3 = 64 THEN X3 = 0
1410    X4 = ASC(MID$(A$,I+3,I+3)) - SP
1420    IF X4 = 64 THEN X4 = 0
1430    P = P + 1
1440    BUF(P) = (X2\16) + (X1*4)
1450    P = P + 1
1460    BUF(P) = (X3\4) + ((X2 MOD 16) * 16)
1470    P = P + 1
1480    BUF(P) = X4 + ((X3 MOD 4) * 64)
1490 NEXT I
1500 FOR I = 1 TO P
1510   LSET N$ = CHR$(BUF(I))
1520   PUT #2, RECNO#
1530   RECNO# = RECNO# + 1
1540 NEXT I
1550 GOTO 1280
1560 END
1570 REM
1580 REM Error trapping routines
1590 REM
1600 LOCATE 22,20
1610 PRINT "Can't open input file"
1620 GOSUB 1740
1630 RESUME 1020
1640 LOCATE 22,20
1650 PRINT "Can't open output file"
1660 GOSUB 1740
1670 RESUME 1090
1680 LOCATE 22,20
1690 PRINT "Header line not found"
1700 GOSUB 1740
1710 LOCATE 24,1
1720 END
1740 FOR I = 1 TO 5000: NEXT I
1750 LOCATE 22,20
1760 PRINT STRING$(30," ")
1770 RETURN
