annotate level1/cmds/dirsort.asm @ 2307:2f90c1624ab4

Removed earlier port signal defintions, now S$Peer is used
author boisy
date Sun, 03 Jan 2010 14:29:29 +0000
parents 0e6b61d99cac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1958
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
1 ******************************************************************
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
2 * dirsort - Directory sorting utility
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
3 *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
4 * This is an asm version of a Basic09 directory sort
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
5 * that was published in a Coco newsletter.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
6 * Original and ml routine by Robert Gault, Nov. 2005
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
7 *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
8 * The program uses a version of Shellsort published
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
9 * in a May 1983, BYTE article by Terry Barron and
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
10 * George Diehr (both at University of Washington)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
11 *
2016
0e6b61d99cac minor formatting
boisy
parents: 1958
diff changeset
12 * Edt/Rev YYYY/MM/DD Modified by
1958
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
13 * Comment
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
14 * -------------------------------------------------------------
2016
0e6b61d99cac minor formatting
boisy
parents: 1958
diff changeset
15 * 1 2005/12/19 Robert Gault
1958
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
16 * Very fast and fairly simple
2016
0e6b61d99cac minor formatting
boisy
parents: 1958
diff changeset
17 *
0e6b61d99cac minor formatting
boisy
parents: 1958
diff changeset
18 * 2 2005/12/20 Robert Gault
1958
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
19 * Minor change of use /dd/defs/defsfile to use defsfile. The first
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
20 * was for my OS-9 system. The current one is for the NitrOS-9
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
21 * project.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
22
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
23 NAM dirsort
2016
0e6b61d99cac minor formatting
boisy
parents: 1958
diff changeset
24 TTL Directory sorting utility
0e6b61d99cac minor formatting
boisy
parents: 1958
diff changeset
25
1958
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
26 IFP1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
27 USE defsfile
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
28 ENDC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
29
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
30 * If you want built-in help change the next line.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
31 HELP SET FALSE
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
32
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
33 TyLg SET Prgrm+Objct program object code
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
34 * Re-entrant means multiple users possible
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
35 AtRev SET ReEnt+Rev re-entrant, revision 1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
36 Rev SET 1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
37
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
38 * Create module header, needed by all OS-9 modules
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
39 MOD Eom,Name,TyLg,AtRev,Start,Size
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
40 * Data area
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
41 DPptr RMB 2 pointer to our direct page
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
42 dirsize RMB 2 size of the directory less 64 bytes
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
43 count RMB 2 number of directory entries
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
44 entryI RMB 2 pointer to nameI
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
45 entryJ RMB 2 pointer to nameJ
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
46 entryID RMB 2 pointer to name(I+D)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
47 Tx RMB 32 buffer for transfer
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
48 i RMB 2 index
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
49 j RMB 2 index
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
50 NminusD RMB 2 holds last value of FOR I/NEXT loop
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
51 path RMB 1 value for path to the directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
52 D RMB 2 shellsort constant
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
53 RMB 40
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
54 stack EQU .
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
55 Size EQU . This initial data space will be increased as OS-9
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
56 * assigns space in pages of 256 bytes. Initially the stack will
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
57 * not be here.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
58 buffer EQU . This will be the start of the data array in memory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
59 * to be requested from OS-9 as needed.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
60
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
61 Name EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
62 FCS /dirsort/
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
63 FCB 1 edition number
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
64 * Ego stroking :) identifier
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
65 FCC /Written by Robert Gault, 2005/
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
66
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
67 * Default directory name, dot, or current directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
68 default FCB C$PERD,C$CR
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
69
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
70 * Solutions for N,2^INT(LN(N)) -1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
71 * We don't need general logs just specifc values so
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
72 * they were pre-calculated
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
73 Dtable FDB 2,0
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
74 FDB 7,1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
75 FDB 20,3
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
76 FDB 54,7
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
77 FDB 148,15
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
78 * If your directory has more entries than several hundred, you
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
79 * need to learn how to organize your disk/drive.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
80 FDB 403,31
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
81 FDB 1096,63
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
82 * This next will exceed normal memory limits but is needed
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
83 * for values up to about 2000. We could just put $FFFF/32=
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
84 * 2047 but there are size checks in the code.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
85 FDB 2980,127
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
86 DTEnd EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
87
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
88 Start EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
89 stu <DPptr save the direct page pointer
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
90 leas stack,u put the stack where we want it or it will be
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
91 * inside the directory buffer and crash the program.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
92 cmpd #0 are there any parameters?
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
93 beq noprm
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
94 l1 lda ,x+ skip over spaces, if any
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
95 cmpa #C$SPAC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
96 beq l1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
97 cmpa #C$CR if only spaces, same as noprm
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
98 bne a1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
99 noprm leax default,pcr point to default directory, dot
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
100 bra a9
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
101 IFNE HELP
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
102 a1 cmpa #'? if "?" then show syntax
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
103 lbeq syntax
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
104 cmpa #'- if attempt at options, syntax
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
105 lbeq syntax
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
106 leax -1,x
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
107 ELSE
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
108 a1 leax -1,x backstep to first character of directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
109 ENDC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
110 a9 lda #%11000011 directory, single user access, update
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
111 os9 I$Open attempt to open a path to the directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
112 lbcs error
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
113 sta <path save the path #
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
114 ldb #SS.Size get the size of the directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
115 os9 I$GetStt size reported in regs X&U
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
116 cmpx #0 MSB of size
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
117 lbne Tlarge too big to sort
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
118 tfr u,d evaluate the size
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
119 cmpd #128 two entries other than .. and .
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
120 lblo getreal can't sort 1 item or less
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
121 subd #64 reduce size by 64 bytes for .. and .
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
122 std <dirsize save size in bytes
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
123 addd #Size we need current data + directory buffer
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
124 os9 F$Mem request space for the buffer
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
125 lbcs Tlarge can't get enough memory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
126 lda <path recover path to the directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
127 ldx #0 MSB position
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
128 ldu #64 LSB, past the entries .. and .
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
129 os9 I$Seek skip over the entries
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
130 ldu <DPptr recover DP pointer
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
131 ldy <dirsize data size in bytes
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
132 leax buffer,u point to our buffer
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
133 os9 I$Read transfer the directory information to buffer
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
134 * Calculate the number of directory entries
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
135 * Divide size by 32 bytes per entry. INT(size/32)must=size/32 or
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
136 * the directory is corrupted. So, ignore remainder.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
137 ldx #0 initialize counter
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
138 ldd <dirsize this does not include . and ..
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
139 IFNE H6309
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
140 lsrd
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
141 lsrd
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
142 lsrd
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
143 lsrd
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
144 lsrd
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
145 ELSE
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
146 lsra
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
147 rorb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
148 lsra
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
149 rorb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
150 lsra
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
151 rorb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
152 lsra
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
153 rorb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
154 lsra
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
155 rorb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
156 ENDC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
157 std <count
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
158 leax Dtable,pcr precalculated constants
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
159 leay DTEnd,pcr
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
160 pshs y
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
161 l3 cmpd ,x
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
162 bls a4 if fewer or equal # of entries get D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
163 leax 4,x move to next table entry
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
164 cmpx ,s have we exhausted the table?
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
165 bne l3
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
166 leas 2,s restore the stack
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
167 lbra Tlarge should not be possible to get here in code
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
168 a4 leas 2,s restore the stack
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
169 ldd 2,x get shellsort D from table
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
170 std <D save working value
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
171 * Sort starts here
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
172 * Directory entries can't have duplicate names or the directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
173 * is corrupted. That means a<b is as good as a<=b when testing.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
174 s2 ldd #1 initialize FOR/NEXT loop
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
175 std <i
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
176 ldd <count same as n in Basic09 program
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
177 subd <D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
178 std <NminusD save value
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
179 * calculated pointer for entryID
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
180 s6 ldd <i FOR i=1 TO n-D STEP 1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
181 addd <D get pointer for entry(i+D)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
182 lbsr point get the pointer value
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
183 stx <entryID
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
184 tfr x,y
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
185 * calculate pointer for entryI
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
186 ldd <i
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
187 lbsr point
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
188 stx <entryI
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
189 * Compare the entry pointed to by regX against that for regY
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
190 lbsr compare is name(i) < name(i+D)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
191 bcs s20
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
192 ldx <entryID
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
193 leay Tx,u shellsort swap name holder
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
194 lbsr movexy name(Tx)=name(i+D)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
195 ldx <entryI
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
196 ldy <entryID
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
197 bsr movexy name(i+D)=name(i)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
198 ldd <i
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
199 cmpd <D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
200 bhi s4 this was a Basic09 IF/THEN
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
201 ldy <entryI inside the IF/THEN
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
202 leax Tx,u
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
203 bsr movexy name(i)=name(Tx)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
204 bra s20 ends the IF/THEN
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
205 s4 ldd <i initialize FOR/NEXT loop
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
206 subd <D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
207 std <j
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
208 s5 bsr point FOR j=i-D TO 1 STEP -D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
209 stx <entryJ
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
210 tfr x,y
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
211 leax Tx,u
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
212 lbsr compare is entry(Tx) > entry(j)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
213 bcc s10
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
214 ldd <j
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
215 addd <D name(j+D)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
216 bsr point
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
217 tfr x,y
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
218 ldx <entryJ
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
219 bsr movexy name(j+D)=name(j)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
220 ldd <j NEXT j
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
221 subd <D STEP -D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
222 std <j
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
223 cmpd #1 stop if less than 1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
224 bge s5
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
225 s10 leay Tx,u
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
226 ldd <j
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
227 addd <D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
228 bsr point
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
229 exg x,y
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
230 bsr movexy name(j+D)=name(Tx)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
231 s20 ldd <i NEXT i
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
232 addd #1 STEP +1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
233 std <i
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
234 cmpd <NminusD
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
235 bls s6 stop if i>(n-D)
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
236 ldd <D D=D/2
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
237 IFNE H6309
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
238 lsrd
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
239 ELSE
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
240 lsra
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
241 rorb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
242 ENDC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
243 std <D
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
244 cmpd #1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
245 lbhs s2 WHILE D>0
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
246 lda <path rewind to just after .. & .
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
247 ldx #0
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
248 ldu #64
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
249 os9 I$Seek
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
250 lda <path
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
251 ldu <DPptr
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
252 leax buffer,u write out sorted directory
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
253 ldy <dirsize
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
254 os9 I$Write
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
255 clrb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
256 os9 F$Exit release memory, close paths, and return to OS-9
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
257
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
258 IFNE H6309
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
259 movexy ldw #32
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
260 tfm x+,y+
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
261 rts
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
262 ELSE
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
263 movexy ldb #16 move the entry pointed to in regX to
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
264 pshs b
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
265 sw1 ldd ,x++ that pointed to by regY
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
266 std ,y++
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
267 dec ,s if not finished, continue
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
268 bne sw1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
269 puls b,pc
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
270 ENDC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
271
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
272 * Converts an index in regD to a memory offset in regX
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
273 * This could easily overflow but there are size checks
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
274 * in the above code so there is no overflow test.
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
275 point leax buffer,u
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
276 subd #1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
277 IFNE H6309
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
278 lsld
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
279 lsld
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
280 lsld
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
281 lsld
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
282 lsld
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
283 ELSE
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
284 lslb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
285 rola
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
286 lslb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
287 rola
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
288 lslb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
289 rola
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
290 lslb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
291 rola
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
292 lslb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
293 rola
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
294 ENDC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
295 leax d,x
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
296 rts
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
297
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
298 compare ldb #29 size of name field
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
299 pshs b save counter
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
300 cloop ldb ,y+ get character
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
301 lda ,x+ get character
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
302 beq c1 if deleted go
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
303 tstb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
304 beq c2 if deleted go
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
305 tsta
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
306 bmi c5 if last character go
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
307 tstb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
308 bmi c6 if last character go
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
309 pshs b
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
310 cmpa ,s+
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
311 beq c4 if equal, test next character
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
312 bra cx
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
313 c1 clra
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
314 bra cx return +
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
315 c2 coma
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
316 bra cx return -
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
317 c3 anda #$7f
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
318 andb #$7f
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
319 pshs b
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
320 cmpa ,s+
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
321 rts
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
322 c5 bsr c3
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
323 beq c2
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
324 bra cx
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
325 c6 bsr c3
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
326 beq c1
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
327 bra cx return result
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
328 c4 dec ,s
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
329 bne cloop
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
330 clra should not be able to get here in code
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
331 cx puls b,pc return result
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
332
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
333 error leax nodir,pcr
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
334 ldy #endnd-nodir
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
335 write lda #1 screen
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
336 os9 I$Write
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
337 clrb
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
338 os9 F$Exit
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
339 nodir EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
340 FCC /Directory does not exist!/
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
341 FCB C$CR,C$LF
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
342 endnd EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
343
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
344 Tlarge leax big,pcr
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
345 ldy #endbig-big
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
346 bra write
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
347 big EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
348 FCC /Either the directory is too large or there is insufficient /
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
349 FCC /memory./
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
350 FCB C$CR,C$LF
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
351 endbig EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
352
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
353 getreal leax huh,pcr
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
354 ldy #endhuh-huh
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
355 clr ,-s
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
356 bra write
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
357 huh EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
358 FCC /Get real! You can't sort less than 2 items./
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
359 FCB C$CR,C$LF
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
360 endhuh EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
361
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
362 IFNE HELP
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
363 syntax leax usage,pcr
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
364 ldy #enduse-usage
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
365 clr ,-s
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
366 lbra write
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
367 usage FCC /USAGE: dirsort will sort any directory. If no directory/
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
368 FCB C$CR,C$LF
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
369 FCC / name is given, the current directory will be sorted./
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
370 FCB C$CR,C$LF
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
371 FCC /EX: dirsort dirsort . dirsort ../
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
372 FCB C$CR,C$LF
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
373 FCC " dirsort /dd/cmds"
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
374 FCB C$CR,C$LF
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
375 enduse EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
376 ENDC
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
377
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
378 EMOD
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
379 Eom EQU *
df97c336e737 Converted to UNIX terminators
robert
parents: 1957
diff changeset
380 END