100 PRINT"Sorted Directory 0.1 15-May-1981"
105 CLEAR, 1.2207,1000:TOP=1.52588
110 DEFINT A-Z
115 LIMDIR=300
120 DIM CODE(50)
130 DIM ARRAY(50)
140 DIM DIR$(LIMDIR)
150 DIM BUF(64)
400 DIRFORM$="\      \.\ \## ###  "
500 GOSUB 8000
600 :REMARKGOSUB 3000
900 WIDTH 80
1160  INPUT"Drive";DRIVE
1180  MASK$=CHR$(DRIVE)+"????????"+"???"
1200  GOSUB 7000
1280  DISPLAY=0
1300  GOSUB 7100
1310  PRINT :  PRINT"Sorting..."
1312 PRINT CHR$(7);
1320  GOSUB 7300
1330 PRINT CHR$(7)
1400  GOSUB 4000   :REMARK display sorted directory
1440 :REMARK GOSUB 4200   ' dump directory to disc
1500 END
4000 REM --- display sorted directory in columns
4010  K=1+(MAXDIR-1) MOD4 : L=0
4020  FOR I=1  TO K
4030   FOR J=I  TO MAXDIR  STEP K
4040    D$=DIR$(J) :  GOSUB 4100
4050   NEXT J
4060   PRINT
4070  NEXT I
4080  PRINT
4090 RETURN
4100 REM --- display directory entry d$
4110  PRINT  USING DIRFORM$;MID$(D$,2,8),MID$(D$,10,3),ASC(MID$(D$,13,1)),
   ASC(MID$(D$,16,1));
4120 RETURN
7000 REM --- create directory mask
7010 I=1
7020  FOR J=1  TO (LEN(MASK$)+1) MOD2
7030   V1=ASC(MID$(MASK$,I,1))
7040   IF I=LEN(MASK$)  THEN V2=0 :ELSE V2=ASC(MID$(MASK$,I+1,1))
7050   VV!=256*V2+V1
7060   IF VV!<=32767  THEN ARRAY(J)=VV! :ELSE ARRAY(J)=VV!-1
7070   I=I+2
7080  NEXT J
7090 RETURN
7100 REM --- read in entire directory
7110  FUNC=0:PARAM=0:CPM=0:BASE=0:V=0:I=0:J=0:K=0:D$="":RESULT=0
7120  FUNC=26 : BUFADR=128 :REMARK TOP+20  ' Set DMA address
7130  CPM=VARPTR(CODE(1)) :  CALL CPM(FUNC,BUFADR,RESULT)
7140  FUNC=17    :REMARK Search directory for first
7150  CPM=VARPTR(CODE(10)) :  CALL CPM(FUNC,ARRAY(1),RESULT)
7160  FOR I=1  TO 999
7170   IF RESULT<0  OR RESULT>3  THEN 7280
7180   BASE=BUFADR+32*RESULT
7190   D$=""
7200   FOR J=0  TO 31
7210    D$=D$+CHR$(PEEK(BASE+J))
7220   NEXT J
7230   IF DISPLAY=0  THEN  PRINT"."; 
  :ELSE  GOSUB 4200 :  IF I \ 4 = 0  THEN  PRINT
7240   DIR$(I)=D$
7250   FUNC=18   :REMARK Search directory for next
7260   CPM=VARPTR(CODE(10)) :  CALL CPM(FUNC,ARRAY(1),RESULT)
7270  NEXT I
7280  MAXDIR=I-1
7290 RETURN
7300 REM --- sort directory by shell sort
7310 DEF  FNCOMP(X,Y)=MID$(DIR$(X),2,11)<=MID$(DIR$(Y),2,11)
7320  GAP=MAXDIR
7330  GAP=GAP MOD2 :  IF GAP <=0  THEN 7410
7340  FOR J=GAP+1  TO MAXDIR
7350       FOR I=J-GAP  TO 0  STEP -GAP
7360   IF  FNCOMP(I,I+GAP)  THEN 7390
7370   SWAP DIR$(I),DIR$(I+GAP)
7380       NEXT I
7390  NEXT J
7400  GOTO 7330
7410 RETURN
8000 REM --- install CPM call routine
8010  ADR=0:I=0:V=0:CPMADR=0:CPMVAL=0
8020  VP=VARPTR(CODE(1))
8030  RESTORE 8110
8040  FOR I=0  TO 9999
8050   READ V:IF V=-1  THEN 8100
8060   IF V>=0  AND V<=255  THEN  POKE ADR,V : ADR=ADR+1 :  GOTO 8090
8070   IF V=1001  THEN ADR=VARPTR(CODE(1))
8080   IF V=1002  THEN ADR=VARPTR(CODE(10))
8090  NEXT I
8100  REM
8110 DATA 1001,197,6,0,78,235,22,0,94,205,5,0,225,119,35,54,0,201
8120 DATA 1002,197,6,0,78,205,5,0,225,119,35,54,0,201
8130 DATA -1
8140  IF VP<>VARPTR(CODE(1))  THEN  STOP
8150 RETURN
8160 REM --- read back memory
8170  FOR J=0  TO 31
8180  PRINT  PEEK(VARPTR(CODE(1))+J);
8190  IF J \ 16 = 15  THEN  PRINT
8200  NEXT J
8210 RETURN
8220 REM --- dump out DMA area
8230 FOR I=128  TO 255:PRINT" ";:P=PEEK(I)
8240 IF I \ 32 = 0  THEN  PRINT
8250 IF P>=32  AND P<=95THEN PRINT CHR$(P);:ELSE PRINT HEX$(P);
8260 NEXT I:PRINT:STOP
8270 REM --- ditto
8280 FOR I=BUFADR  TO BUFADR+127  STEP 32:PRINT
8290  FOR J=I  TO I+31:P=PEEK(J)
8300   IF P>=32  AND P<=127  THEN  PRINT  CHR$(P);:ELSE  PRINT ".";
8310  NEXT J,I
6682  --- ditto
8280 FOR I=BUFADR  TO BUFADR+127  STEP 32:PRINT
8290  FOR J=I  TO I
