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