Subversion Repositories Kolibri OS

Rev

Rev 135 | 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'
30
include 'macros.inc'       ; very useful stuff for MeOS
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
42
    int  0x40
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
55
    int  0x40
56
    jmp  still      ;   return to main loop
57
 
58
  button:           ; button
59
    mov  eax,17     ;   get id
60
    int  0x40
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
101
    int  0x40
102
    cmp  eax,2
103
    jnz  still
104
;   mov  eax,2
105
    int  0x40
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
144
    int  0x40
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
168
    int  0x40
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
31 halyavin 200
    int  0x40
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]
213
    int  0x40
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
225
    int  0x40
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
233
    int  0x40
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
247
    int  0x40
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]
253
    mov  edx, 0x03DDDDDD           ; color of work area RRGGBB
254
    int  0x40
255
 
256
                                   ; WINDOW LABEL
257
    mov  eax, 4                    ; function 4 : write text to window
258
    mov  ebx, 8*65536+8            ; [x start] *65536 + [y start]
259
    mov  ecx, 0x10ffffff           ; color of text RRGGBB
260
    mov  edx, header               ; pointer to text beginning
261
    mov  esi, header.size          ; text length
262
    int  0x40
263
 
264
    mov  eax, 8                    ; COPY BUTTON
265
    mov  ebx, 20*65536+375
266
    mov  ecx, 63*65536+16
267
    mov  edx, 2
268
    mov  esi, 0xCCCCCC
269
    int  0x40
270
 
271
    mov  ebx, 105*65536+290
272
    mov  ecx, 33*65536+12
273
    mov  edx, 4
274
    mov  esi, 0xEBEBEB
275
    int  0x40
276
 
277
    mov  ebx, 105*65536+290
278
    mov  ecx, 49*65536+12
279
    mov  edx, 5
280
    mov  esi, 0xEBEBEB
281
    int  0x40
282
 
193 diamond 283
    mov  esi, source_info.name  ;source
31 halyavin 284
    mov  edi, text+14
285
    mov  ecx, STRLEN
286
    rep  movsb
287
 
193 diamond 288
    mov  esi, dest_info.name  ;destination
31 halyavin 289
    mov  edi, text+STRLEN+59-45+14
290
    mov  ecx, STRLEN
291
    rep  movsb
292
 
293
    mov  ebx, 25*65536+36   ; print filenames
294
    xor  ecx, ecx
295
    mov  edx, text
296
    mov  esi, STRLEN+59-45
297
  newline:
298
    mov  eax, 4
299
    int  0x40
300
    add  ebx, 16
301
    add  edx, STRLEN+59-45
302
    cmp  [edx], byte 'x'
303
    jnz  newline
304
 
305
    mov  eax, 12                   ; function 12:tell os about windowdraw
306
    mov  ebx, 2                    ; 2, end of draw
307
    int  0x40
308
 
309
    ret
310
 
311
 
312
; DATA AREA
193 diamond 313
get_param_info:
314
 .subfunction	 dd   5 	      ; 5 - get parameters of file
315
 .start        dd   0        ; rezerved
316
 .size_high    dd   0 	      ; rezerved
317
 .size         dd   0	      ; rezerved
318
 .return	      dd   param_info
319
 .name:
320
     db  0
321
     dd  source_info.name
322
 
31 halyavin 323
source_info:                 ; SOURCE FILEINFO
193 diamond 324
 .subfunction	 dd   0 	      ; 0=READ
325
 .start        dd   0
326
 .size_high    dd   0
327
 .size         dd   0
328
 .return	      dd   0x10000
329
 .name:
330
     db   '/hd0/1/kernel/kernel.mnt',0   ; ASCIIZ dir & filename
331
     times (STRLEN-24) db 0
31 halyavin 332
 
333
dest_info:                   ; DESTINATION FILEINFO
193 diamond 334
 .subfunction	 dd   2 	      ; 0=WRITE
335
 .start        dd   0
336
 .size_high    dd   0
337
 .size         dd   0
338
 .return	      dd   0x10000
339
 .name:
340
     db   '/rd/1/kernel.mnt',0   ; ASCIIZ dir & filename
31 halyavin 341
    times (STRLEN-16) db 0
342
 
193 diamond 343
param_info:
344
     rb 40
345
 
346
 
347
;align 4
348
;source_info:                 ; SOURCE FILEINFO
349
;  .mode            dd 0      ; read file
350
;  .start_block     dd 0x0    ; block to read
351
;  .blocks          dd 0x700  ; num of blocks
352
;  .address         dd 0x20000
353
;  .workarea        dd 0x10000
354
;  source           db '/HD/1/KERNEL/KERNEL.MNT',0
355
;    times (STRLEN-23) db 0
356
;
357
;dest_info:                   ; DESTINATION FILEINFO
358
;  .mode            dd 1      ; write
359
;  .notused         dd 0x0    ; not used
360
;  .bytes2write     dd 0      ; bytes to write
361
;  .address         dd 0x20000
362
;  .workarea        dd 0x10000
363
;  destination      db '/RD/1/KERNEL.MNT',0
364
;    times (STRLEN-16) db 0
365
 
31 halyavin 366
  align 4
367
  addr  dd  0x0
368
  ya    dd  0x0
369
  temp  dd  0
370
 
371
 
372
lsz  text,\
373
  ru, '   ОТКУДА:    |   Россия, Ярославль                           ',\
374
  ru, '    КУДА:     |        Поддубный Иван, ivan-yar@bk.ru         ',\
375
  ru, '                         КОПИРОВАТЬ                           ',\
376
  ru, 'x',\ ; <- END MARKER, DONT DELETE
377
\
378
  en, 'SOURCE:       |   Russia, Yaroslavl                           ',\
379
  en, 'DESTINATION:  |        Poddubny Ivan, ivan-yar@bk.ru          ',\
380
  en, '                   COPY SOURCE -> DESTINATION                 ',\
381
  en, 'x',\ ; <- END MARKER, DONT DELETE
382
\
135 diamond 383
  de, 'QUELLE:       |   Russia, Yaroslavl                           ',\
384
  de, 'ZIEL:         |        Poddubny Ivan, ivan-yar@bk.ru          ',\
385
  de, '                   KOPIERE QUELLE -> ZIEL                     ',\
386
  de, 'x',\ ; <- END MARKER, DONT DELETE
387
\
31 halyavin 388
  fr, 'SOURCE:       |                                               ',\
389
  fr, 'DESTINATION:  |                                               ',\
390
  fr, '                           COPIER                             ',\
391
  fr, 'x'
392
 
393
 
394
lsz  header,\
395
  ru, 'КОПИРОВАТЬ ФАЙЛ',\
396
  en, 'SYSTREE FILE COPIER',\
135 diamond 397
  de, 'SYSTREE DATEIKOPIERER',\
31 halyavin 398
  fr, 'COPIER LE FICHIER'
399
 
400
 
401
;  This macro is used to define a string table in format 
402
macro strtbl name,[string]
403
 {
404
  common
405
    label name dword
406
  forward
407
    local str,size
408
    dd str,size
409
  forward
410
    str db string
411
    size = $ - str
412
 }
413
 
414
if lang eq ru
415
strtbl errors,\
416
       "файл скопирован успешно",\
417
       "(чтение) не задана база жд",\
418
       "(чтение) файловая система не поддерживается",\
419
       "(чтение) неизвестная файловая система",\
420
       "(чтение) не задан раздел жд",\
421
       "недостаточно памяти",\
422
       "(чтение) конец файла",\
423
       "(чтение) неизвестная ошибка",\
424
       "(запись) не задан раздел жд",\
425
       "(запись) файловая система не поддерживается",\
426
       "(запись) неизвестная файловая система",\
427
       "(запись) не задан раздел жд",\
428
       "?",\
429
       "(запись) файл не найден",\
430
       "(запись) неизвестная ошибка"
135 diamond 431
else if lang eq en
31 halyavin 432
strtbl errors,\
433
       "Success!",\
434
       "(read) no hd base or partition defined",\
435
       "(read) unsupported file system",\
436
       "(read) unknown file system",\
437
       "(read) hd partition not defined",\
438
       "out of memory",\
439
       "(read) end of file",\
440
       "(read) unknown error",\
441
       "(write) no hd base or partition defined",\
442
       "(write) unsupported file system",\
443
       "(write) unknown file system",\
444
       "(write) hd partition not defined",\
445
       "?",\
446
       "(write) end of file",\
447
       "(write) unknown error"
135 diamond 448
else
449
strtbl errors,\
450
       "Erfolgreich!",\
451
       "(lesen) Keine Festplatte oder Partition definiert",\
452
       "(lesen) Dateisystem nicht unterstuetzt",\
453
       "(lesen) Unbekanntes Dateisystem",\
454
       "(lesen) Keine Partition definiert",\
455
       "Zu wenig Speicher",\
456
       "(lesen) Dateiende erreicht",\
457
       "(lesen) Unbekanner Fehler",\
458
       "(schreiben) Keine Festplatte oder Partition definiert",\
459
       "(schreiben) Dateisystem nicht unterstuetzt",\
460
       "(schreiben) Unbekanntes Dateisystem",\
461
       "(schreiben) Keine Partition definiert",\
462
       "?",\
463
       "(schreiben) Dateiende erreicht",\
464
       "(schreiben) Unbekanner Fehler"
31 halyavin 465
end if
466
 
467
I_END: