Rev 111 | Rev 193 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | ; project name: SYSTREE FILE COPIER |
2 | ; version: 1.1b |
||
3 | ; last update: 18/07/2004 |
||
4 | ; compiler: FASM 1.52 |
||
5 | ; written by: Ivan Poddubny |
||
6 | ; e-mail: ivan-yar@bk.ru |
||
7 | ; copying-policy: GPL |
||
8 | |||
9 | ; History: |
||
10 | ; 18/07/2004 strings using "lsz" macro + french language (not 100%!) |
||
11 | ; 04/06/2004 Bugfix for memory - thanks to Ville |
||
12 | ; ... |
||
13 | |||
14 | use32 |
||
15 | org 0x0 |
||
16 | |||
17 | db 'MENUET01' ; 8 byte id |
||
18 | dd 0x01 ; header version |
||
19 | dd START ; start of code |
||
20 | dd I_END ; size of image |
||
21 | dd 0x20201 ; memory for app |
||
22 | dd 0x10000 ; esp |
||
23 | dd 0x0 , 0x0 ; I_Param , I_Icon |
||
24 | |||
25 | include 'lang.inc' |
||
26 | include 'macros.inc' ; very useful stuff for MeOS |
||
27 | STRLEN = 48 ; maximal length of filename |
||
28 | |||
29 | |||
30 | START: ; start of execution |
||
31 | |||
32 | red: |
||
33 | call draw_window ; at first, draw the window |
||
34 | |||
35 | still: ; main cycle of application begins here |
||
36 | |||
37 | mov eax,10 ; wait here for event |
||
38 | int 0x40 |
||
39 | |||
40 | dec eax ; redraw request ? |
||
41 | jz red |
||
42 | dec eax ; key in buffer ? |
||
43 | jz key |
||
44 | dec eax ; button in buffer ? |
||
45 | jz button |
||
46 | |||
47 | jmp still |
||
48 | |||
49 | key: ; key event handler |
||
50 | mov eax,2 ; just read it and ignore |
||
51 | int 0x40 |
||
52 | jmp still ; return to main loop |
||
53 | |||
54 | button: ; button |
||
55 | mov eax,17 ; get id |
||
56 | int 0x40 |
||
57 | |||
58 | cmp ah,1 ; button id=1 ? (close_btn) |
||
59 | jz close |
||
60 | |||
61 | cmp ah,2 ; copy ? |
||
62 | je copy_file |
||
63 | |||
64 | ; read_string: |
||
65 | |||
66 | cmp ah,5 ; user pressed dest button ? |
||
67 | jz dstbtn |
||
68 | cmp ah,4 ; user pressed src button ? |
||
69 | jnz still |
||
70 | |||
71 | srcbtn: |
||
72 | mov [addr],dword source |
||
73 | mov [ya],dword 36 |
||
74 | jmp rk |
||
75 | dstbtn: |
||
76 | mov [addr],dword destination |
||
77 | mov [ya],dword 36+16 |
||
78 | |||
79 | rk: |
||
80 | mov edi,[addr] ; load the address of the string |
||
81 | mov al,0 ; the symbol we will search for |
||
82 | mov ecx,STRLEN+1 ; length of the string (+1) |
||
83 | cld ; search forward |
||
84 | repne scasb ; do search now |
||
85 | inc ecx ; we've found a zero or ecx became 0 |
||
86 | mov eax,STRLEN+1 |
||
87 | sub eax,ecx ; eax = address of <0> character |
||
88 | mov [temp],eax ; position |
||
89 | |||
90 | call print_text |
||
91 | |||
92 | mov edi,[addr] ; address of string |
||
93 | add edi,[temp] ; cursor position |
||
94 | |||
95 | .waitev: |
||
96 | mov eax,10 |
||
97 | int 0x40 |
||
98 | cmp eax,2 |
||
99 | jnz still |
||
100 | ; mov eax,2 |
||
101 | int 0x40 |
||
102 | shr eax,8 |
||
103 | cmp eax,8 |
||
104 | jnz .nobs ; BACKSPACE |
||
105 | cmp edi,[addr] |
||
106 | jz .waitev |
||
107 | dec edi |
||
108 | mov [edi],byte 0 |
||
109 | call print_text |
||
110 | jmp .waitev |
||
111 | .nobs: |
||
112 | cmp eax,13 ; ENTER |
||
113 | je still |
||
114 | cmp eax,192 |
||
115 | jne .noclear |
||
116 | xor al,al |
||
117 | mov edi,[addr] |
||
118 | mov ecx,STRLEN |
||
119 | rep stosb |
||
120 | mov edi,[addr] |
||
121 | call print_text |
||
122 | jmp .waitev |
||
123 | |||
124 | .noclear: |
||
125 | mov [edi],al |
||
126 | |||
127 | call print_text |
||
128 | |||
129 | inc edi |
||
130 | mov esi,[addr] |
||
131 | add esi,STRLEN |
||
132 | cmp esi,edi |
||
133 | jnz .waitev |
||
134 | |||
135 | jmp still |
||
136 | |||
137 | |||
138 | close: |
||
139 | or eax,-1 ; close program |
||
140 | int 0x40 |
||
141 | |||
142 | |||
143 | ;==================================================== |
||
144 | ; copy_file |
||
145 | ; This piece of code copies src file to dst file, |
||
146 | ; then it pass the control to copy_error routine, |
||
147 | ; which returns to the main cycle of the app. |
||
148 | ; It's NOT a function! It's reached by direct jump |
||
149 | ; from the button handler. |
||
150 | ;==================================================== |
||
151 | copy_file: |
||
152 | ; at first we must get the size of the source file |
||
153 | mov [source_info.blocks],1 ; load only 512 bytes |
||
154 | mov eax,58 |
||
155 | mov ebx,source_info |
||
156 | int 0x40 |
||
157 | |||
158 | ; now eax contains error code |
||
159 | ; and ebx contains file size in bytes |
||
160 | test eax,eax ; check if eax is equal to zero (success) |
||
161 | je .ok_getsize ; eax = 0 => continue |
||
162 | cmp eax,6 |
||
163 | jna @f |
||
164 | mov eax,7 ; if error code is above 6, it will be 7 |
||
165 | @@: |
||
166 | cmp eax,5 ; file might be copied successfully altrough |
||
167 | ; the system reports an error 5 |
||
168 | jne copy_error ; print error code now |
||
169 | .ok_getsize: |
||
170 | |||
171 | ; allocate memory |
||
172 | push ebx ; save file size |
||
173 | mov ecx,ebx |
||
174 | add ecx,0x20000 ; size of memory needed = 0x20000+filesize |
||
175 | mov eax,64 ; func 64 |
||
176 | mov ebx,1 ; resize application memory |
||
177 | int 0x40 |
||
178 | pop ebx ; restore filesize |
||
179 | |||
180 | ; check if alloc function failed |
||
181 | test eax,eax ; non-zero value means error |
||
182 | je .ok_memory |
||
183 | mov eax,5 ; error 5 - out of memory |
||
184 | jmp copy_error ; print error code now |
||
185 | .ok_memory: |
||
186 | |||
187 | ; save number of blocks to source_info |
||
68 | halyavin | 188 | add ebx,511 |
189 | shr ebx,9 ; round up to 512 boundary |
||
31 | halyavin | 190 | mov [source_info.blocks],ebx |
191 | ; read the source file |
||
192 | mov eax,58 |
||
193 | mov ebx,source_info |
||
194 | int 0x40 |
||
195 | |||
196 | ; ebx = file size |
||
197 | ; save loaded file |
||
198 | mov [dest_info.bytes2write],ebx ; file size in bytes |
||
199 | mov eax,58 |
||
200 | mov ebx,dest_info |
||
201 | int 0x40 |
||
202 | |||
203 | ; check if 58 function failed |
||
204 | test eax,eax |
||
205 | je .ok_write |
||
206 | add eax,7 ; error number += 7 |
||
207 | cmp eax,6+7 |
||
208 | jna copy_error |
||
209 | mov eax,7+7 |
||
210 | jmp copy_error |
||
211 | .ok_write: |
||
212 | |||
213 | ; return to the initial amount of memory |
||
214 | mov eax,64 |
||
215 | mov ebx,1 |
||
216 | mov ecx,0x20201 |
||
217 | int 0x40 |
||
218 | |||
219 | xor eax,eax ; eax = message number (0-OK) |
||
220 | |||
221 | |||
222 | ; print message now |
||
223 | copy_error: |
||
224 | mov edi,eax |
||
225 | mov eax,4 |
||
226 | mov ebx,20*65536+83 |
||
227 | mov ecx,0x10ff0000 |
||
228 | mov edx,[errors+edi*8] |
||
229 | mov esi,[errors+edi*8+4] |
||
230 | int 0x40 |
||
231 | jmp still |
||
232 | |||
233 | |||
234 | ; print strings (source & destination) |
||
235 | print_text: |
||
236 | mov eax,13 |
||
237 | mov ebx,107*65536+STRLEN*6 |
||
238 | mov ecx,[ya] |
||
239 | shl ecx,16 |
||
240 | add ecx,9 |
||
241 | mov edx,0xf2f2f2 |
||
242 | int 0x40 |
||
243 | |||
244 | mov eax,4 |
||
245 | mov ebx,109*65536 |
||
246 | add ebx,[ya] |
||
247 | xor ecx,ecx |
||
248 | mov edx,[addr] |
||
249 | mov esi,STRLEN |
||
250 | int 0x40 |
||
251 | |||
252 | ret |
||
253 | |||
254 | |||
255 | ; ********************************************* |
||
256 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
||
257 | ; ********************************************* |
||
258 | |||
259 | |||
260 | draw_window: |
||
261 | |||
262 | mov eax, 12 ; function 12:tell os about windowdraw |
||
263 | mov ebx, 1 ; 1, start of draw |
||
264 | int 0x40 |
||
265 | |||
266 | ; DRAW WINDOW |
||
267 | xor eax, eax ; function 0 : define and draw window |
||
268 | mov ebx, 160*65536+415 ; [x start] *65536 + [x size] |
||
269 | mov ecx, 160*65536+100 ; [y start] *65536 + [y size] |
||
270 | mov edx, 0x03DDDDDD ; color of work area RRGGBB |
||
271 | int 0x40 |
||
272 | |||
273 | ; WINDOW LABEL |
||
274 | mov eax, 4 ; function 4 : write text to window |
||
275 | mov ebx, 8*65536+8 ; [x start] *65536 + [y start] |
||
276 | mov ecx, 0x10ffffff ; color of text RRGGBB |
||
277 | mov edx, header ; pointer to text beginning |
||
278 | mov esi, header.size ; text length |
||
279 | int 0x40 |
||
280 | |||
281 | mov eax, 8 ; COPY BUTTON |
||
282 | mov ebx, 20*65536+375 |
||
283 | mov ecx, 63*65536+16 |
||
284 | mov edx, 2 |
||
285 | mov esi, 0xCCCCCC |
||
286 | int 0x40 |
||
287 | |||
288 | mov ebx, 105*65536+290 |
||
289 | mov ecx, 33*65536+12 |
||
290 | mov edx, 4 |
||
291 | mov esi, 0xEBEBEB |
||
292 | int 0x40 |
||
293 | |||
294 | mov ebx, 105*65536+290 |
||
295 | mov ecx, 49*65536+12 |
||
296 | mov edx, 5 |
||
297 | mov esi, 0xEBEBEB |
||
298 | int 0x40 |
||
299 | |||
300 | mov esi, source |
||
301 | mov edi, text+14 |
||
302 | mov ecx, STRLEN |
||
303 | rep movsb |
||
304 | |||
305 | mov esi, destination |
||
306 | mov edi, text+STRLEN+59-45+14 |
||
307 | mov ecx, STRLEN |
||
308 | rep movsb |
||
309 | |||
310 | mov ebx, 25*65536+36 ; print filenames |
||
311 | xor ecx, ecx |
||
312 | mov edx, text |
||
313 | mov esi, STRLEN+59-45 |
||
314 | newline: |
||
315 | mov eax, 4 |
||
316 | int 0x40 |
||
317 | add ebx, 16 |
||
318 | add edx, STRLEN+59-45 |
||
319 | cmp [edx], byte 'x' |
||
320 | jnz newline |
||
321 | |||
322 | mov eax, 12 ; function 12:tell os about windowdraw |
||
323 | mov ebx, 2 ; 2, end of draw |
||
324 | int 0x40 |
||
325 | |||
326 | ret |
||
327 | |||
328 | |||
329 | ; DATA AREA |
||
330 | align 4 |
||
331 | source_info: ; SOURCE FILEINFO |
||
332 | .mode dd 0 ; read file |
||
333 | .start_block dd 0x0 ; block to read |
||
334 | .blocks dd 0x700 ; num of blocks |
||
335 | .address dd 0x20000 |
||
336 | .workarea dd 0x10000 |
||
337 | source db '/HD/1/KERNEL/KERNEL.MNT',0 |
||
338 | times (STRLEN-23) db 0 |
||
339 | |||
340 | dest_info: ; DESTINATION FILEINFO |
||
341 | .mode dd 1 ; write |
||
342 | .notused dd 0x0 ; not used |
||
343 | .bytes2write dd 0 ; bytes to write |
||
344 | .address dd 0x20000 |
||
345 | .workarea dd 0x10000 |
||
346 | destination db '/RD/1/KERNEL.MNT',0 |
||
347 | times (STRLEN-16) db 0 |
||
348 | |||
349 | align 4 |
||
350 | addr dd 0x0 |
||
351 | ya dd 0x0 |
||
352 | temp dd 0 |
||
353 | |||
354 | |||
355 | lsz text,\ |
||
356 | ru, ' ОТКУДА: | Россия, Ярославль ',\ |
||
357 | ru, ' КУДА: | Поддубный Иван, ivan-yar@bk.ru ',\ |
||
358 | ru, ' КОПИРОВАТЬ ',\ |
||
359 | ru, 'x',\ ; <- END MARKER, DONT DELETE |
||
360 | \ |
||
361 | en, 'SOURCE: | Russia, Yaroslavl ',\ |
||
362 | en, 'DESTINATION: | Poddubny Ivan, ivan-yar@bk.ru ',\ |
||
363 | en, ' COPY SOURCE -> DESTINATION ',\ |
||
364 | en, 'x',\ ; <- END MARKER, DONT DELETE |
||
365 | \ |
||
135 | diamond | 366 | de, 'QUELLE: | Russia, Yaroslavl ',\ |
367 | de, 'ZIEL: | Poddubny Ivan, ivan-yar@bk.ru ',\ |
||
368 | de, ' KOPIERE QUELLE -> ZIEL ',\ |
||
369 | de, 'x',\ ; <- END MARKER, DONT DELETE |
||
370 | \ |
||
31 | halyavin | 371 | fr, 'SOURCE: | ',\ |
372 | fr, 'DESTINATION: | ',\ |
||
373 | fr, ' COPIER ',\ |
||
374 | fr, 'x' |
||
375 | |||
376 | |||
377 | lsz header,\ |
||
378 | ru, 'КОПИРОВАТЬ ФАЙЛ',\ |
||
379 | en, 'SYSTREE FILE COPIER',\ |
||
135 | diamond | 380 | de, 'SYSTREE DATEIKOPIERER',\ |
31 | halyavin | 381 | fr, 'COPIER LE FICHIER' |
382 | |||
383 | |||
384 | ; This macro is used to define a string table in format |
||
385 | macro strtbl name,[string] |
||
386 | { |
||
387 | common |
||
388 | label name dword |
||
389 | forward |
||
390 | local str,size |
||
391 | dd str,size |
||
392 | forward |
||
393 | str db string |
||
394 | size = $ - str |
||
395 | } |
||
396 | |||
397 | if lang eq ru |
||
398 | strtbl errors,\ |
||
399 | "файл скопирован успешно",\ |
||
400 | "(чтение) не задана база жд",\ |
||
401 | "(чтение) файловая система не поддерживается",\ |
||
402 | "(чтение) неизвестная файловая система",\ |
||
403 | "(чтение) не задан раздел жд",\ |
||
404 | "недостаточно памяти",\ |
||
405 | "(чтение) конец файла",\ |
||
406 | "(чтение) неизвестная ошибка",\ |
||
407 | "(запись) не задан раздел жд",\ |
||
408 | "(запись) файловая система не поддерживается",\ |
||
409 | "(запись) неизвестная файловая система",\ |
||
410 | "(запись) не задан раздел жд",\ |
||
411 | "?",\ |
||
412 | "(запись) файл не найден",\ |
||
413 | "(запись) неизвестная ошибка" |
||
135 | diamond | 414 | else if lang eq en |
31 | halyavin | 415 | strtbl errors,\ |
416 | "Success!",\ |
||
417 | "(read) no hd base or partition defined",\ |
||
418 | "(read) unsupported file system",\ |
||
419 | "(read) unknown file system",\ |
||
420 | "(read) hd partition not defined",\ |
||
421 | "out of memory",\ |
||
422 | "(read) end of file",\ |
||
423 | "(read) unknown error",\ |
||
424 | "(write) no hd base or partition defined",\ |
||
425 | "(write) unsupported file system",\ |
||
426 | "(write) unknown file system",\ |
||
427 | "(write) hd partition not defined",\ |
||
428 | "?",\ |
||
429 | "(write) end of file",\ |
||
430 | "(write) unknown error" |
||
135 | diamond | 431 | else |
432 | strtbl errors,\ |
||
433 | "Erfolgreich!",\ |
||
434 | "(lesen) Keine Festplatte oder Partition definiert",\ |
||
435 | "(lesen) Dateisystem nicht unterstuetzt",\ |
||
436 | "(lesen) Unbekanntes Dateisystem",\ |
||
437 | "(lesen) Keine Partition definiert",\ |
||
438 | "Zu wenig Speicher",\ |
||
439 | "(lesen) Dateiende erreicht",\ |
||
440 | "(lesen) Unbekanner Fehler",\ |
||
441 | "(schreiben) Keine Festplatte oder Partition definiert",\ |
||
442 | "(schreiben) Dateisystem nicht unterstuetzt",\ |
||
443 | "(schreiben) Unbekanntes Dateisystem",\ |
||
444 | "(schreiben) Keine Partition definiert",\ |
||
445 | "?",\ |
||
446 | "(schreiben) Dateiende erreicht",\ |
||
447 | "(schreiben) Unbekanner Fehler" |
||
31 | halyavin | 448 | end if |
449 | |||
450 | I_END:->->->0> |