Subversion Repositories Kolibri OS

Rev

Rev 109 | 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
\
366
  fr, 'SOURCE:       |                                               ',\
367
  fr, 'DESTINATION:  |                                               ',\
368
  fr, '                           COPIER                             ',\
369
  fr, 'x'
370
 
371
 
372
lsz  header,\
373
  ru, 'КОПИРОВАТЬ ФАЙЛ',\
374
  en, 'SYSTREE FILE COPIER',\
375
  fr, 'COPIER LE FICHIER'
376
 
377
 
378
;  This macro is used to define a string table in format 
379
macro strtbl name,[string]
380
 {
381
  common
382
    label name dword
383
  forward
384
    local str,size
385
    dd str,size
386
  forward
387
    str db string
388
    size = $ - str
389
 }
390
 
391
if lang eq ru
392
strtbl errors,\
393
       "файл скопирован успешно",\
394
       "(чтение) не задана база жд",\
395
       "(чтение) файловая система не поддерживается",\
396
       "(чтение) неизвестная файловая система",\
397
       "(чтение) не задан раздел жд",\
398
       "недостаточно памяти",\
399
       "(чтение) конец файла",\
400
       "(чтение) неизвестная ошибка",\
401
       "(запись) не задан раздел жд",\
402
       "(запись) файловая система не поддерживается",\
403
       "(запись) неизвестная файловая система",\
404
       "(запись) не задан раздел жд",\
405
       "?",\
406
       "(запись) файл не найден",\
407
       "(запись) неизвестная ошибка"
408
else
409
strtbl errors,\
410
       "Success!",\
411
       "(read) no hd base or partition defined",\
412
       "(read) unsupported file system",\
413
       "(read) unknown file system",\
414
       "(read) hd partition not defined",\
415
       "out of memory",\
416
       "(read) end of file",\
417
       "(read) unknown error",\
418
       "(write) no hd base or partition defined",\
419
       "(write) unsupported file system",\
420
       "(write) unknown file system",\
421
       "(write) hd partition not defined",\
422
       "?",\
423
       "(write) end of file",\
424
       "(write) unknown error"
425
end if
426
 
427
I_END: