@@ -39,22 +39,24 @@ sort_vat_entry_temp_end := ti.mpLcdCrsrImage + 12 + 15
39
39
40
40
sort_v at :
41
41
ld iy , ti. flags
42
- ld a , (iy + sort_flag)
43
- push af
44
- call sort_vat_internal
45
- pop af
46
- ld (iy + sort_flag) , a
47
- ret
48
-
49
- sort_vat_internal:
50
- res sort_first_item_found , (iy + sort_flag)
42
+ or a , a
43
+ sbc hl , hl
44
+ ld (sort_first_item_found_ptr) , hl
51
45
ld hl , (ti.progPtr)
52
46
.sort_next:
53
47
call .find_next_item
54
48
ret nc
55
49
.found_item:
56
- bit sort_first_item_found , (iy + sort_flag)
57
- jp z , .first_found
50
+ push hl
51
+ ld hl , (sort_first_item_found_ptr)
52
+ compare_hl_zero
53
+ pop hl
54
+ jr nz , .not_first
55
+ ld (sort_first_item_found_ptr) , hl ; to make it only execute once
56
+ call .skip_name
57
+ ld (sort_end_of_part_ptr) , hl
58
+ jr .sort_next
59
+ .not_first:
58
60
push hl
59
61
call .skip_name
60
62
pop de
@@ -135,13 +137,6 @@ sort_vat_internal:
135
137
ld (sort_end_of_part_ptr) , hl
136
138
jp .sort_next
137
139
138
- .first_found:
139
- set sort_first_item_found , (iy + sort_flag)
140
- ld (sort_first_item_found_ptr) , hl ; to make it only execute once
141
- call .skip_name
142
- ld (sort_end_of_part_ptr) , hl
143
- jp .sort_next
144
-
145
140
.skip_to_next:
146
141
ld bc ,- 6
147
142
add hl , bc
@@ -156,71 +151,45 @@ sort_vat_internal:
156
151
ret
157
152
158
153
.compare_names: ; hl and de pointers to strings output=carry if de is first
159
- res sort_first_hidden , (iy + sort_flag)
160
- res sort_second_hidden , (iy + sort_flag)
161
-
154
+ ld b , (hl)
155
+ ld a , (de)
156
+ ld c , 0
157
+ cp a , b ; check if same length
158
+ jr z , .hl_longer
159
+ jr nc , .hl_longer ; b = smaller than a
160
+ inc c ; to remember that b was larger
161
+ ld b , a ; b was larger than a
162
+ .hl_longer:
163
+ push bc
164
+ ld b , 64
162
165
dec hl
163
166
dec de
164
- ld b , 64
165
167
ld a , (hl)
166
168
cp a , b
167
169
jr nc , .first_not_hidden ; check if files are hidden
168
170
add a , b
169
- ld (hl) , a
170
- set sort_first_hidden , (iy + sort_flag)
171
171
.first_not_hidden:
172
+ ld c , a
172
173
ld a , (de)
173
174
cp a , b
174
175
jr nc , .second_not_hidden
175
176
add a , b
176
- ld (de) , a
177
- set sort_second_hidden , (iy + sort_flag)
178
177
.second_not_hidden:
179
- push hl
180
- push de
181
- inc hl
182
- inc de
183
- ld b , (hl)
184
- ld a , (de)
185
- ld c , 0
186
- cp a , b ; check if same length
187
- jr z , .compare_names_continue
188
- jr nc , .compare_names_continue ; b = smaller than a
189
- inc c ; to remember that b was larger
190
- ld b , a ; b was larger than a
191
- .compare_names_continue:
178
+ cp a , c
179
+ pop bc
180
+ jr .start
181
+ . loop :
192
182
dec hl
193
183
dec de
194
184
ld a , (de)
195
185
cp a , (hl)
196
- jr nz , .match
197
- djnz .compare_names_continue
198
- pop de
199
- pop hl
200
- call .reset_hidden_flags
186
+ .start:
187
+ ret nz
188
+ djnz . loop
201
189
dec c
202
190
ret nz
203
191
ccf
204
192
ret
205
- .match:
206
- pop de
207
- pop hl
208
- .reset_hidden_flags:
209
- push af
210
- bit sort_first_hidden , (iy + sort_flag)
211
- jr z , .first_not_hidden_check
212
- ld a , (hl)
213
- sub a , 64
214
- ld (hl) , a
215
- .first_not_hidden_check:
216
- bit sort_second_hidden , (iy + sort_flag)
217
- jr z , .second_not_hidden_check
218
- ld a , (de)
219
- sub a , 64
220
- ld (de) , a
221
- .second_not_hidden_check:
222
- pop af
223
- ret
224
193
225
194
.find_next_item: ; carry = found, nc = notfound
226
195
ex de , hl
0 commit comments