Rev 7129 | Rev 8089 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7129 | Rev 7132 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 7129 $ |
8 | $Revision: 7132 $ |
9 | 9 | ||
10 | iglobal |
10 | iglobal |
11 | full_file_name_table dd sysdir_name |
11 | full_file_name_table dd sysdir_name |
12 | .size dd 1 |
12 | .size dd 1 |
13 | endg |
13 | endg |
14 | 14 | ||
15 | uglobal |
15 | uglobal |
16 | sysdir_name rb 64 ; 'sys',0 |
16 | sysdir_name rb 64 ; 'sys',0 |
17 | sysdir_path rb 64 |
17 | sysdir_path rb 64 |
18 | sysdir_name1 rb 64 |
18 | sysdir_name1 rb 64 |
19 | sysdir_path1 rb 64 |
19 | sysdir_path1 rb 64 |
20 | endg |
20 | endg |
21 | ; Example: |
21 | ; Example: |
22 | ; align 64 |
22 | ; align 64 |
23 | ; sysdir_name1 db 'KolibriOS',0 |
23 | ; sysdir_name1 db 'KolibriOS',0 |
24 | ; align 64 |
24 | ; align 64 |
25 | ; sysdir_path1 db 'HD0/1',0 |
25 | ; sysdir_path1 db 'HD0/1',0 |
26 | 26 | ||
27 | proc Parser_params |
27 | proc Parser_params |
28 | locals |
28 | locals |
29 | buff rb 4 ; for test cd |
29 | buff rb 4 ; for test cd |
30 | endl |
30 | endl |
31 | mov ax, [OS_BASE+BOOT_BX_FROM_LOAD] |
31 | mov ax, [BOOT.bx_from_load] |
32 | mov ecx, sysdir_path |
32 | mov ecx, sysdir_path |
33 | mov [ecx-64], dword 'sys' |
33 | mov [ecx-64], dword 'sys' |
34 | mov [ecx-2], byte 3 |
34 | mov [ecx-2], byte 3 |
35 | mov [ecx-1], byte '/' |
35 | mov [ecx-1], byte '/' |
36 | cmp al, 'r' ; ram disk |
36 | cmp al, 'r' ; ram disk |
37 | jnz @f |
37 | jnz @f |
38 | mov [ecx], dword 'RD/?' |
38 | mov [ecx], dword 'RD/?' |
39 | mov [ecx+3], byte ah |
39 | mov [ecx+3], byte ah |
40 | mov [ecx+4], byte 0 |
40 | mov [ecx+4], byte 0 |
41 | ret |
41 | ret |
42 | 42 | ||
43 | @@: |
43 | @@: |
44 | cmp al, 'm' |
44 | cmp al, 'm' |
45 | jnz .hard_disk |
45 | jnz .hard_disk |
46 | mov [ecx], dword 'CD?/' |
46 | mov [ecx], dword 'CD?/' |
47 | mov [ecx+4], byte '1' |
47 | mov [ecx+4], byte '1' |
48 | mov [ecx+5], dword '/KOL' |
48 | mov [ecx+5], dword '/KOL' |
49 | mov [ecx+9], dword 'IBRI' |
49 | mov [ecx+9], dword 'IBRI' |
50 | mov [ecx+13], byte 0 |
50 | mov [ecx+13], byte 0 |
51 | .next_cd: |
51 | .next_cd: |
52 | mov [ecx+2], byte ah |
52 | mov [ecx+2], byte ah |
53 | inc ah |
53 | inc ah |
54 | cmp ah, '5' |
54 | cmp ah, '5' |
55 | je @f |
55 | je @f |
56 | lea edx, [buff] |
56 | lea edx, [buff] |
57 | pushad |
57 | pushad |
58 | stdcall read_file, read_firstapp, edx, 0, 4 |
58 | stdcall read_file, read_firstapp, edx, 0, 4 |
59 | popad |
59 | popad |
60 | cmp [edx], dword 'MENU' |
60 | cmp [edx], dword 'MENU' |
61 | jne .next_cd |
61 | jne .next_cd |
62 | @@: |
62 | @@: |
63 | ret |
63 | ret |
64 | 64 | ||
65 | .hard_disk: |
65 | .hard_disk: |
66 | sub al, '1' |
66 | sub al, '1' |
67 | mov [ecx], dword 'HD?/' |
67 | mov [ecx], dword 'HD?/' |
68 | mov [ecx+2], byte al |
68 | mov [ecx+2], byte al |
69 | mov [ecx+4], byte ah |
69 | mov [ecx+4], byte ah |
70 | mov [ecx+5], dword '/KOL' |
70 | mov [ecx+5], dword '/KOL' |
71 | mov [ecx+9], dword 'IBRI' |
71 | mov [ecx+9], dword 'IBRI' |
72 | mov [ecx+13], byte 0 |
72 | mov [ecx+13], byte 0 |
73 | ret |
73 | ret |
74 | endp |
74 | endp |
75 | 75 | ||
76 | cp866toUpper: |
76 | cp866toUpper: |
77 | ; convert cp866 character in al to uppercase |
77 | ; convert cp866 character in al to uppercase |
78 | cmp al, 'a' |
78 | cmp al, 'a' |
79 | jb .ret |
79 | jb .ret |
80 | cmp al, 'z' |
80 | cmp al, 'z' |
81 | jbe @f |
81 | jbe @f |
82 | cmp al, 0xA0 |
82 | cmp al, 0xA0 |
83 | jb .ret |
83 | jb .ret |
84 | cmp al, 0xB0 |
84 | cmp al, 0xB0 |
85 | jb @f |
85 | jb @f |
86 | cmp al, 0xE0 |
86 | cmp al, 0xE0 |
87 | jb .ret |
87 | jb .ret |
88 | cmp al, 0xF0 |
88 | cmp al, 0xF0 |
89 | jb .rus |
89 | jb .rus |
90 | cmp al, 0xF7 |
90 | cmp al, 0xF7 |
91 | ja .ret |
91 | ja .ret |
92 | and eax, -2 |
92 | and eax, -2 |
93 | .ret: |
93 | .ret: |
94 | ret |
94 | ret |
95 | 95 | ||
96 | @@: |
96 | @@: |
97 | sub eax, 32 |
97 | sub eax, 32 |
98 | ret |
98 | ret |
99 | 99 | ||
100 | .rus: |
100 | .rus: |
101 | sub eax, 0xE0-0x90 |
101 | sub eax, 0xE0-0x90 |
102 | ret |
102 | ret |
103 | 103 | ||
104 | utf16toUpper: |
104 | utf16toUpper: |
105 | ; convert UTF-16 character in ax to uppercase |
105 | ; convert UTF-16 character in ax to uppercase |
106 | cmp ax, 'a' |
106 | cmp ax, 'a' |
107 | jb .ret |
107 | jb .ret |
108 | cmp ax, 'z' |
108 | cmp ax, 'z' |
109 | jbe @f |
109 | jbe @f |
110 | cmp ax, 430h |
110 | cmp ax, 430h |
111 | jb .ret |
111 | jb .ret |
112 | cmp ax, 450h |
112 | cmp ax, 450h |
113 | jb @f |
113 | jb @f |
114 | cmp ax, 460h |
114 | cmp ax, 460h |
115 | jnc .ret |
115 | jnc .ret |
116 | sub eax, 80 |
116 | sub eax, 80 |
117 | .ret: |
117 | .ret: |
118 | ret |
118 | ret |
119 | 119 | ||
120 | @@: |
120 | @@: |
121 | sub eax, 32 |
121 | sub eax, 32 |
122 | ret |
122 | ret |
123 | 123 | ||
124 | uni2ansi_char: |
124 | uni2ansi_char: |
125 | ; convert UNICODE character in ax to ANSI character in al using cp866 encoding |
125 | ; convert UNICODE character in ax to ANSI character in al using cp866 encoding |
126 | cmp ax, 0x80 |
126 | cmp ax, 0x80 |
127 | jb .ret |
127 | jb .ret |
128 | cmp ax, 0xB6 |
128 | cmp ax, 0xB6 |
129 | jz .B6 |
129 | jz .B6 |
130 | cmp ax, 0x400 |
130 | cmp ax, 0x400 |
131 | jb .unk |
131 | jb .unk |
132 | cmp ax, 0x410 |
132 | cmp ax, 0x410 |
133 | jb @f |
133 | jb @f |
134 | cmp ax, 0x440 |
134 | cmp ax, 0x440 |
135 | jb .rus1 |
135 | jb .rus1 |
136 | cmp ax, 0x450 |
136 | cmp ax, 0x450 |
137 | jb .rus2 |
137 | jb .rus2 |
138 | cmp ax, 0x460 |
138 | cmp ax, 0x460 |
139 | jb @f |
139 | jb @f |
140 | .unk: |
140 | .unk: |
141 | mov al, '_' |
141 | mov al, '_' |
142 | .ret: |
142 | .ret: |
143 | ret |
143 | ret |
144 | 144 | ||
145 | .B6: |
145 | .B6: |
146 | mov al, 20 |
146 | mov al, 20 |
147 | ret |
147 | ret |
148 | 148 | ||
149 | .rus1: ; 0x410-0x43F -> 0x80-0xAF |
149 | .rus1: ; 0x410-0x43F -> 0x80-0xAF |
150 | add al, 0x70 |
150 | add al, 0x70 |
151 | ret |
151 | ret |
152 | 152 | ||
153 | .rus2: ; 0x440-0x44F -> 0xE0-0xEF |
153 | .rus2: ; 0x440-0x44F -> 0xE0-0xEF |
154 | add al, 0xA0 |
154 | add al, 0xA0 |
155 | ret |
155 | ret |
156 | 156 | ||
157 | @@: |
157 | @@: |
158 | push ecx edi |
158 | push ecx edi |
159 | mov ecx, 8 |
159 | mov ecx, 8 |
160 | mov edi, .table |
160 | mov edi, .table |
161 | repnz scasb |
161 | repnz scasb |
162 | mov ah, cl |
162 | mov ah, cl |
163 | pop edi ecx |
163 | pop edi ecx |
164 | jnz .unk |
164 | jnz .unk |
165 | mov al, 0xF7 |
165 | mov al, 0xF7 |
166 | sub al, ah |
166 | sub al, ah |
167 | ret |
167 | ret |
168 | 168 | ||
169 | .table db 1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh |
169 | .table db 1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh |
170 | 170 | ||
171 | ansi2uni_char: |
171 | ansi2uni_char: |
172 | ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding |
172 | ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding |
173 | movzx eax, al |
173 | movzx eax, al |
174 | cmp al, 0x80 |
174 | cmp al, 0x80 |
175 | jb @f ; 0x00-0x7F - trivial map |
175 | jb @f ; 0x00-0x7F - trivial map |
176 | cmp al, 0xB0 |
176 | cmp al, 0xB0 |
177 | jb .rus ; 0x80-0xAF -> 0x410-0x43F |
177 | jb .rus ; 0x80-0xAF -> 0x410-0x43F |
178 | cmp al, 0xE0 |
178 | cmp al, 0xE0 |
179 | jb .unk |
179 | jb .unk |
180 | cmp al, 0xF0 |
180 | cmp al, 0xF0 |
181 | jb .rus2 ; 0xE0-0xEF -> 0x440-0x44F |
181 | jb .rus2 ; 0xE0-0xEF -> 0x440-0x44F |
182 | cmp al, 0xF8 |
182 | cmp al, 0xF8 |
183 | jnc .unk |
183 | jnc .unk |
184 | mov al, [eax+uni2ansi_char.table-0xF0] |
184 | mov al, [eax+uni2ansi_char.table-0xF0] |
185 | add ax, 400h |
185 | add ax, 400h |
186 | ret |
186 | ret |
187 | 187 | ||
188 | @@: |
188 | @@: |
189 | cmp al, 20 |
189 | cmp al, 20 |
190 | jnz .ret |
190 | jnz .ret |
191 | mov al, 0xB6 |
191 | mov al, 0xB6 |
192 | .ret: |
192 | .ret: |
193 | ret |
193 | ret |
194 | 194 | ||
195 | .rus: |
195 | .rus: |
196 | add ax, 0x410-0x80 |
196 | add ax, 0x410-0x80 |
197 | ret |
197 | ret |
198 | 198 | ||
199 | .rus2: |
199 | .rus2: |
200 | add ax, 0x440-0xE0 |
200 | add ax, 0x440-0xE0 |
201 | ret |
201 | ret |
202 | 202 | ||
203 | .unk: |
203 | .unk: |
204 | mov al, '_' |
204 | mov al, '_' |
205 | ret |
205 | ret |
206 | 206 | ||
207 | cp866toUTF8_string: |
207 | cp866toUTF8_string: |
208 | ; in: |
208 | ; in: |
209 | ; esi -> cp866 string (could be zero terminated) |
209 | ; esi -> cp866 string (could be zero terminated) |
210 | ; edi -> buffer for UTF-8 string |
210 | ; edi -> buffer for UTF-8 string |
211 | ; ecx = buffer size (signed) |
211 | ; ecx = buffer size (signed) |
212 | lodsb |
212 | lodsb |
213 | call ansi2uni_char |
213 | call ansi2uni_char |
214 | push eax |
214 | push eax |
215 | call UTF16to8 |
215 | call UTF16to8 |
216 | pop eax |
216 | pop eax |
217 | js @f |
217 | js @f |
218 | test eax, eax |
218 | test eax, eax |
219 | jnz cp866toUTF8_string |
219 | jnz cp866toUTF8_string |
220 | @@: |
220 | @@: |
221 | ret |
221 | ret |
222 | 222 | ||
223 | ; SF=1 -> counter |
223 | ; SF=1 -> counter |
224 | ; ZF=1 -> zero char |
224 | ; ZF=1 -> zero char |
225 | 225 | ||
226 | UTF16to8_string: |
226 | UTF16to8_string: |
227 | ; in: |
227 | ; in: |
228 | ; esi -> UTF-16 string (could be zero terminated) |
228 | ; esi -> UTF-16 string (could be zero terminated) |
229 | ; edi -> buffer for UTF-8 string |
229 | ; edi -> buffer for UTF-8 string |
230 | ; ecx = buffer size (signed) |
230 | ; ecx = buffer size (signed) |
231 | xor eax, eax |
231 | xor eax, eax |
232 | @@: |
232 | @@: |
233 | lodsw |
233 | lodsw |
234 | push eax |
234 | push eax |
235 | call UTF16to8 |
235 | call UTF16to8 |
236 | pop eax |
236 | pop eax |
237 | js @f |
237 | js @f |
238 | test eax, eax |
238 | test eax, eax |
239 | jnz @b |
239 | jnz @b |
240 | @@: |
240 | @@: |
241 | ret |
241 | ret |
242 | 242 | ||
243 | UTF16to8: |
243 | UTF16to8: |
244 | ; in: |
244 | ; in: |
245 | ; eax = UTF-16 char |
245 | ; eax = UTF-16 char |
246 | ; edi -> buffer for UTF-8 char (increasing) |
246 | ; edi -> buffer for UTF-8 char (increasing) |
247 | ; ecx = byte counter (decreasing) |
247 | ; ecx = byte counter (decreasing) |
248 | dec ecx |
248 | dec ecx |
249 | js .ret |
249 | js .ret |
250 | cmp eax, 80h |
250 | cmp eax, 80h |
251 | jnc @f |
251 | jnc @f |
252 | stosb |
252 | stosb |
253 | test eax, eax ; SF=0 |
253 | test eax, eax ; SF=0 |
254 | .ret: |
254 | .ret: |
255 | ret |
255 | ret |
256 | 256 | ||
257 | @@: |
257 | @@: |
258 | dec ecx |
258 | dec ecx |
259 | js .ret |
259 | js .ret |
260 | cmp eax, 800h |
260 | cmp eax, 800h |
261 | jnc @f |
261 | jnc @f |
262 | shl eax, 2 |
262 | shl eax, 2 |
263 | shr al, 2 |
263 | shr al, 2 |
264 | or eax, 1100000010000000b |
264 | or eax, 1100000010000000b |
265 | xchg al, ah |
265 | xchg al, ah |
266 | stosw |
266 | stosw |
267 | ret |
267 | ret |
268 | 268 | ||
269 | @@: |
269 | @@: |
270 | dec ecx |
270 | dec ecx |
271 | js .ret |
271 | js .ret |
272 | shl eax, 4 |
272 | shl eax, 4 |
273 | shr ax, 2 |
273 | shr ax, 2 |
274 | shr al, 2 |
274 | shr al, 2 |
275 | or eax, 111000001000000010000000b |
275 | or eax, 111000001000000010000000b |
276 | bswap eax |
276 | bswap eax |
277 | shr eax, 8 |
277 | shr eax, 8 |
278 | stosb |
278 | stosb |
279 | shr eax, 8 |
279 | shr eax, 8 |
280 | stosw |
280 | stosw |
281 | ret |
281 | ret |
282 | 282 | ||
283 | utf8to16: |
283 | utf8to16: |
284 | ; in: esi -> UTF-8 char (increasing) |
284 | ; in: esi -> UTF-8 char (increasing) |
285 | ; out: ax = UTF-16 char |
285 | ; out: ax = UTF-16 char |
286 | lodsb |
286 | lodsb |
287 | test al, al |
287 | test al, al |
288 | jns .got |
288 | jns .got |
289 | shl al, 2 |
289 | shl al, 2 |
290 | jnc utf8to16 |
290 | jnc utf8to16 |
291 | @@: |
291 | @@: |
292 | shl ax, 8 |
292 | shl ax, 8 |
293 | lodsb |
293 | lodsb |
294 | test al, al |
294 | test al, al |
295 | jns .got |
295 | jns .got |
296 | shl al, 2 |
296 | shl al, 2 |
297 | jc @b |
297 | jc @b |
298 | shr ah, 2 |
298 | shr ah, 2 |
299 | shl ax, 3 |
299 | shl ax, 3 |
300 | jnc @f |
300 | jnc @f |
301 | shl eax, 3 |
301 | shl eax, 3 |
302 | lodsb |
302 | lodsb |
303 | test al, al |
303 | test al, al |
304 | jns .got |
304 | jns .got |
305 | shl al, 2 |
305 | shl al, 2 |
306 | jc @b |
306 | jc @b |
307 | shr eax, 2 |
307 | shr eax, 2 |
308 | ret |
308 | ret |
309 | 309 | ||
310 | @@: |
310 | @@: |
311 | shr ax, 5 |
311 | shr ax, 5 |
312 | ret |
312 | ret |
313 | 313 | ||
314 | .got: |
314 | .got: |
315 | xor ah, ah |
315 | xor ah, ah |
316 | ret |
316 | ret |
317 | 317 | ||
318 | strlen: |
318 | strlen: |
319 | ; in: esi -> source |
319 | ; in: esi -> source |
320 | ; out: ecx = length |
320 | ; out: ecx = length |
321 | push edi eax |
321 | push edi eax |
322 | or ecx, -1 |
322 | or ecx, -1 |
323 | mov edi, esi |
323 | mov edi, esi |
324 | xor eax, eax |
324 | xor eax, eax |
325 | repnz scasb |
325 | repnz scasb |
326 | inc ecx |
326 | inc ecx |
327 | not ecx |
327 | not ecx |
328 | pop eax edi |
328 | pop eax edi |
329 | ret |
329 | ret |