Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6573 leency 1
;             program to generate files            ;
2
;              path to folder in edit1             ;
3
;              count of files in edit2             ;
4
; to compile: nasm -f bin GenFiles.asm -o GenFiles ;
5
ORG 0
6
BITS 32
7
; ------------------------------------- ;
8
STACK_SIZE             equ 256
9
; ------------------------------------- ;
10
EM_REDRAW              equ 0b1
11
EM_KEY                 equ 0b10
12
EM_BUTTON              equ 0b100
13
EM_MOUSE               equ 0b100000
14
; ------------------------------------- ;
15
BUTTON_START           equ 2
16
; ------------------------------------- ;
17
ED_DISABLED            equ 0b100000000000
18
; ------------------------------------- ;
19
EDIT1_MAX_LENGTH       equ 1024
20
EDIT2_MAX_LENGTH       equ 10
21
FILE_NAME_LENGTH       equ 256
22
; ------------------------------------- ;
23
text_buffer1           equ END + STACK_SIZE
24
text_buffer2           equ END + STACK_SIZE + (EDIT1_MAX_LENGTH + 2)
25
file_name              equ END + STACK_SIZE + (EDIT1_MAX_LENGTH + 2) + (EDIT2_MAX_LENGTH + 2)
26
; ------------------------------------- ;
27
MENUET01                db 'MENUET01'
28
version                 dd 1
29
program.start           dd START
30
program.end             dd END
31
program.memory          dd END + STACK_SIZE + (EDIT1_MAX_LENGTH + 2) + (EDIT2_MAX_LENGTH + 2) + FILE_NAME_LENGTH
32
program.stack           dd END + STACK_SIZE
33
program.params          dd 0
34
program.path            dd 0
35
; ------------------------------------- ;
36
align 4
37
Events:
38
.0:                     dd  On_Idle
39
.1:                     dd  On_Redraw
40
.2:                     dd  On_Key
41
.3:                     dd  On_Button
42
.4:                     dd  0
43
.5:                     dd  0
44
.6:                     dd  On_Mouse
45
; ------------------------------------- ;
46
ButtonEvents:
47
.0:                     dd  0
48
.1:                     dd  On_ButtonClose
49
.2:                     dd  On_ButtonStart
50
; ------------------------------------- ;
51
count                   dd  0
52
; ------------------------------------- ;
53
pb:
54
.value                  dd 0
55
.left                   dd 8
56
.top                    dd 25
57
.width                  dd 269
58
.height                 dd 10
59
.style                  dd 0
60
.min                    dd 0
61
.max                    dd 0
62
.back_color             dd 0x00C8D0D4
63
.progress_color         dd 0x8072B7EB
64
.frame_color            dd 0x00406175
65
; ------------------------------------- ;
66
edit1:
67
.width                  dd 100
68
.left                   dd 48
69
.top                    dd 8
70
.color                  dd 0X00FFFFFF
71
.shift_color            dd 0
72
.focus_border_color     dd 0
73
.blur_border_color      dd 0
74
.text_color             dd 0
75
.max                    dd EDIT1_MAX_LENGTH
76
.text                   dd text_buffer1
77
.mouse_variable         dd 0
78
.flags                  dd 10b ; active
79
.size                   dd 0
80
.pos                    dd 0
81
.offset                 dd 0
82
.cl_curs_x              dd 0
83
.cl_curs_y              dd 0
84
.shift                  dd 0
85
.shift_old              dd 0
86
; ------------------------------------- ;
87
edit2:
88
.width                  dd 60
89
.left                   dd 216
90
.top                    dd 8
91
.color                  dd 0X00FFFFFF
92
.shift_color            dd 0
93
.focus_border_color     dd 0
94
.blur_border_color      dd 0
95
.text_color             dd 0
96
.max                    dd EDIT2_MAX_LENGTH
97
.text                   dd text_buffer2
98
.mouse_variable         dd 0
99
.flags                  dd 1000000000000000b ; only numbers
100
.size                   dd 0
101
.pos                    dd 0
102
.offset                 dd 0
103
.cl_curs_x              dd 0
104
.cl_curs_y              dd 0
105
.shift                  dd 0
106
.shift_old              dd 0
107
; ------------------------------------- ;
108
progressbar_progress    dd 0
109
progressbar_draw        dd 0
110
; ------------------------------------- ;
111
edit_box_draw           dd 0
112
edit_box_key            dd 0
113
edit_box_mouse          dd 0
114
edit_box_set_text       dd 0
115
; ------------------------------------- ;
116
status_string           dd sz_empty
117
; ------------------------------------- ;
118
box_lib                 dd 0
119
; ------------------------------------- ;
120
sz_box_lib              db "/sys/lib/box_lib.obj",0
121
; ------------------------------------- ;
122
sz_progressbar_draw     db 'progressbar_draw', 0
123
sz_progressbar_progress db 'progressbar_progress', 0
124
; ------------------------------------- ;
125
sz_edit_box             db "edit_box",0
126
sz_edit_box_key         db "edit_box_key",0
127
sz_edit_box_mouse       db "edit_box_mouse",0
128
sz_edit_box_set_text    db "edit_box_set_text",0
129
; ------------------------------------- ;
130
sz_path                 db "Path:",0
131
sz_count                db "Count:",0
132
sz_start                db "Start",0
133
sz_caption              db "Generate files",0
134
; ------------------------------------- ;
135
sz_empty                db "",0
136
sz_doing                db "doing",0
137
sz_done                 db "done ",0
138
sz_error                db "error",0
139
; ------------------------------------- ;
140
digits                  db "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
141
; ------------------------------------- ;
142
START:
143
; LoadLibrary:
144
        mov    eax, 68
145
        mov    ebx, 19
146
        mov    ecx, sz_box_lib
147
        int    64
148
        mov    [box_lib], eax
149
 
150
        push   dword[box_lib]
151
        push   sz_edit_box
152
        call   GetProcAddress
153
        mov    [edit_box_draw], eax
154
 
155
        push   dword[box_lib]
156
        push   sz_edit_box_key
157
        call   GetProcAddress
158
        mov    [edit_box_key], eax
159
 
160
        push   dword[box_lib]
161
        push   sz_edit_box_mouse
162
        call   GetProcAddress
163
        mov    [edit_box_mouse], eax
164
 
165
        push   dword[box_lib]
166
        push   sz_edit_box_set_text
167
        call   GetProcAddress
168
        mov    [edit_box_set_text], eax
169
 
170
        push   dword[box_lib]
171
        push   sz_progressbar_draw
172
        call   GetProcAddress
173
        mov    [progressbar_draw], eax
174
 
175
        push   dword[box_lib]
176
        push   sz_progressbar_progress
177
        call   GetProcAddress
178
        mov    [progressbar_progress], eax
179
; ------------------------------------- ;
180
; SetEventMask
181
        mov    eax, 40
182
        mov    ebx, EM_REDRAW | EM_KEY | EM_BUTTON | EM_MOUSE
183
        int    64
184
; ------------------------------------- ;
185
align 4
186
WaitEvent:
187
        mov    eax, 10
188
        int    64
189
        call   [eax * 4 + Events]
190
        jmp    WaitEvent
191
; ------------------------------------- ;
192
%macro CreateNextFile 0
193
; Base36(count)
194
        mov    eax, [count]
195
        mov    ecx, 36        ; because our base is 36
196
        mov    esi, file_name
197
        mov    edi, esi
198
        add    esi, 7         ; base36(0xFFFFFFFF) = 1Z141Z3 : 7 simbols
199
        mov    [esi], byte 0
200
%%next:
201
        xor    edx, edx
202
        div    ecx
203
        dec    esi
204
        mov    dl, [edx + digits]
205
        mov    [esi], dl
206
        test   eax, eax
207
        jnz    %%next
208
        mov    eax, esi
209
        sub    eax, edi
210
        mov    ecx, 7 + 1
211
        sub    ecx, eax
212
        rep    movsb
213
; ------------------------------------- ;
214
        push   dword file_name
215
        dec    esp
216
        mov    [esp], byte 0
217
        push   dword 0
218
        push   dword 0
219
        push   dword 0
220
        push   dword 0
221
        push   dword 2  ; SubFunction #2 Create/Rewrite file
222
        mov    ebx, esp
223
        mov    eax, 70  ; Function #70
224
        int    64
225
        add    esp, 25  ; restore stack
226
%endmacro
227
; ------------------------------------- ;
228
align 4
229
DoAction:
230
; convert text in edit2 to number
231
        mov    edx, [edit2.text]
232
        xor    eax, eax
233
        xor    ecx, ecx
234
.convert:
235
        mov    al, [edx]
236
        test   al, al
237
        jz     .converted
238
        lea    ecx, [ecx + ecx * 4]
239
        lea    ecx, [eax + ecx * 2 - 48]
240
        inc    edx
241
        jmp    .convert
242
.converted:
243
        mov    [count], ecx
244
; ------------------------------------- ;
245
        mov    [pb.max], ecx
246
        mov    [pb.value], dword 0
247
; draw progressbar
248
        push   pb
249
        call   [progressbar_draw]
250
; ------------------------------------- ;
251
        cmp    [count], dword 0
252
        jz     .done
253
; SetCurrentDirectory
254
        mov    eax, 30
255
        mov    ebx, 1
256
        mov    ecx, [edit1.text]
257
        int    64
258
;
259
        mov    [status_string], dword sz_doing
260
        call   DrawStatus
261
.do:
262
        CreateNextFile
263
        test   eax, eax
264
        jnz    .error
265
; increase progress
266
        push   pb
267
        call   [progressbar_progress]
268
; CheckEvent
269
        mov    eax, 11
270
        int    64
271
        call   [eax * 4 + Events]
272
        dec    dword [count]
273
        jnz   .do
274
.done:
275
        mov    [status_string], dword sz_done
276
        call   DrawStatus
277
								ret
278
.error:
279
        mov    [status_string], dword sz_error
280
        call   DrawStatus
281
								ret
282
; ------------------------------------- ;
283
DrawStatus:
284
        mov    eax, 4
285
        mov    ecx, 0xC0000000
286
        mov    ebx, (168 << 16) | 38
287
        mov    edx, [status_string]
288
        mov    edi, 0x00FFFFFF
289
        int    64
290
        ret
291
; ------------------------------------- ;
292
align 4
293
On_Idle:
294
        ret
295
; ------------------------------------- ;
296
align 4
297
On_Redraw:
298
; RedrawStart
299
        mov    eax, 12
300
        mov    ebx, 1
301
        int    64
302
; DrawWindow
303
        xor    eax, eax
304
        mov    ebx, 360
305
        mov    ecx, 74
306
        mov    edx, 0x34FFFFFF
307
        mov    edi, sz_caption
308
        xor    esi, esi
309
        int    64
310
; draw progressbar
311
        push   pb
312
        call   [progressbar_draw]
313
; draw edit1
314
        push   edit1
315
        call   [edit_box_draw]
316
; draw edit2
317
        push   edit2
318
        call   [edit_box_draw]
319
; DrawButton
320
        mov    eax, 8
321
        mov    ecx, (8   << 16) | 26
322
        mov    ebx, (288 << 16) | 53
323
        mov    edx, BUTTON_START
324
        mov    esi, 0x00DDDDDD
325
        int    64
326
; DrawTexts
327
        mov    eax, 4
328
        mov    ecx, 0x80000000
329
;   Path:
330
        mov    ebx, (8   << 16) | 11
331
        mov    edx, sz_path
332
        int    64
333
;   Count:
334
        mov    ebx, (176 << 16) | 11
335
        mov    edx, sz_count
336
        int    64
337
;   Start:
338
        mov    ebx, (302 << 16) | 18
339
        mov    edx, sz_start
340
        int    64
341
; draw status
342
        mov    ebx, (168 << 16) | 38
343
        mov    edx, [status_string]
344
        int    64
345
; RedrawFinish
346
        mov    eax, 12
347
        mov    ebx, 2
348
        int    64
349
        ret
350
; ------------------------------------- ;
351
align 4
352
On_Key:
353
; GetKeyCode
354
        mov    eax, 2
355
        int    64
356
; notify edit1 about key event
357
        push   edit1
358
        call   [edit_box_key]
359
; notify edit2 about key event
360
        push   edit2
361
        call   [edit_box_key]
362
        ret
363
; ------------------------------------- ;
364
align 4
365
On_Button:
366
; GetButtonNumber
367
        mov    eax, 17
368
        int    64
369
        movzx  eax, ah
370
        call   [eax * 4 + ButtonEvents]
371
        ret
372
; ------------------------------------- ;
373
align 4
374
On_ButtonClose:
375
; Terminate
376
        or     eax, -1
377
        int    64
378
        ; ret is not needed here because we are not back after terminate
379
; ------------------------------------- ;
380
align 4
381
On_ButtonStart:
382
        mov    [ButtonEvents.2], dword On_Idle        ; disable ButtonStart | because
383
        or     [edit1.flags], dword ED_DISABLED       ; disable edit1       |   we will
384
        or     [edit2.flags], dword ED_DISABLED       ; disable edit2       |     in Action
385
; redraw edit1 after change flag
386
        push   edit1
387
        call   [edit_box_draw]
388
; redraw edit2 after change flag
389
        push   edit2
390
        call   [edit_box_draw]
391
        call   DoAction
392
        mov    [ButtonEvents.2], dword On_ButtonStart ; enable ButtonStart
393
        and    [edit1.flags], dword ~ED_DISABLED      ; enable edit1
394
        and    [edit2.flags], dword ~ED_DISABLED      ; enable edit2
395
; redraw edit1 after change flag
396
        push   edit1
397
        call   [edit_box_draw]
398
; redraw edit2 after change flag
399
        push   edit2
400
        call   [edit_box_draw]
401
        ret
402
; ------------------------------------- ;
403
align 4
404
On_Mouse:
405
; notify edit1 about mouse event
406
        push   edit1
407
        call   [edit_box_mouse]
408
; notify edit2 about mouse event
409
        push   edit2
410
        call   [edit_box_mouse]
411
        ret
412
; ------------------------------------- ;
413
align 4
414
GetProcAddress:
415
        mov    edx, [esp + 8]
416
        xor    eax, eax
417
        test   edx, edx
418
        jz     .end
419
.next:
420
        xor    eax, eax
421
        cmp    [edx], dword 0
422
        jz     .end
423
        mov    esi, [edx]
424
        mov    edi, [esp + 4]
425
.next_:
426
        lodsb
427
        scasb
428
        jne    .fail
429
        test   al, al
430
        jnz    .next_
431
        jmp    .ok
432
.fail:
433
        add    edx, 8
434
        jmp    .next
435
.ok:
436
        mov    eax, [edx + 4]
437
.end:
438
        ret    8
439
; ------------------------------------- ;
440
align 4
441
END: