Subversion Repositories Kolibri OS

Rev

Rev 1064 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1068 Lrz 1
;08.05.2009 - bugfix
1064 Lrz 2
;14.04.2009 - a macros for code load library the box_lib.obj from '/sys/lib/' or current dirrectory.
3
; The macros for load any library/libraries:
4
; Copyright (c) 2009, 
5
; All rights reserved.
6
;
7
; Redistribution and use in source and binary forms, with or without
8
; modification, are permitted provided that the following conditions are met:
9
;       * Redistributions of source code must retain the above copyright
10
;       notice, this list of conditions and the following disclaimer.
11
;       * Redistributions in binary form must reproduce the above copyright
12
;       notice, this list of conditions and the following disclaimer in the
13
;       documentation and/or other materials provided with the distribution.
14
;       * Neither the name of the  nor the
15
;       names of its contributors may be used to endorse or promote products
16
;       derived from this software without specific prior written permission.
17
;
18
; THIS SOFTWARE IS PROVIDED BY Alexey Teplov aka  ''AS IS'' AND ANY
19
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
; DISCLAIMED. IN NO EVENT SHALL  BE LIABLE FOR ANY
22
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
;*****************************************************************************
29
; This macros based on source code:
30
;  - Alexey Teplov / Алексей Теплов
31
; Mario79, Mario - Marat Zakiyanov / Марат Закиянов
32
; Diamondz - Evgeny Grechnikov / Евгений Гречников
33
;------------------------
34
; DESCRIPTION
35
; Macro load_library
36
; Logick of work.
37
; A first time we must to check system path, where I belive find a system library. System path is "/sys/lib/".
38
; If I cannot found my library, i must to check second way. Second way is current dirrectory.
39
; If we cannot load library, we must show the error message:
40
; "I'm sorry,the programm cannot found system library box_lib.obj."
41
; "The find was make on 2 ways: /sys/lib/ and current dirrectory."
1068 Lrz 42
;
1064 Lrz 43
;
44
;---------------------------------------------------------------------
1068 Lrz 45
; Macro sys_load_library
1064 Lrz 46
; A first time we must to check own path in current dirrectory the program, where I belive find a system library.
47
; If I cannot found my library, i must to check second way. Second way is system path a "/sys/lib/".
48
; If we cannot load library, we must show the error message:
49
; "I'm sorry,the programm cannot found system library box_lib.obj."
50
; "The find was make on 2 ways: /sys/lib/ and current dirrectory."
1068 Lrz 51
;
52
;---------------------------------------------------------------------
53
; How can I use it?
54
;---------------------------------------------------------------------
55
;-Example using single load library
56
;-universal load library/librarys
57
;load_library  library_name, cur_dir_path, library_path, system_path, \
58
;err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
59
;-if return code =-1 then exit, else normally work
60
;        cmp     eax,-1
61
;        jz      exit
62
;- Well, if you get
63
;
64
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
65
;DATA данные
66
;Всегда соблюдать последовательность в имени.
67
;system_path      db '/sys/lib/'
68
;library_name     db 'box_lib.obj',0
69
; Если есть желание разъединить, то нужно использовать следующию конструкцию
70
;system_path      db '/sys/lib/box_lib.obj',0
71
;... любая последовательность других команд и определений.
72
;library_name     db 'box_lib.obj',0
73
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1064 Lrz 74
 
1068 Lrz 75
;err_message_found_lib   db 'Sorry I cannot found library box_lib.obj',0
76
;head_f_i:
77
;head_f_l        db 'System error',0
78
;err_message_import      db 'Error on load import library box_lib.obj',0
79
 
80
;myimport:
81
;
82
;edit_box_draw   dd      aEdit_box_draw
83
;edit_box_key    dd      aEdit_box_key
84
;edit_box_mouse  dd      aEdit_box_mouse
85
;version_ed      dd      aVersion_ed
86
;
87
;check_box_draw  dd      aCheck_box_draw
88
;check_box_mouse dd      aCheck_box_mouse
89
;version_ch      dd      aVersion_ch
90
;
91
;option_box_draw  dd      aOption_box_draw
92
;option_box_mouse dd      aOption_box_mouse
93
;version_op       dd      aVersion_op
94
 
95
;                dd      0
96
;                dd      0
97
;
98
;aEdit_box_draw  db 'edit_box',0
99
;aEdit_box_key   db 'edit_box_key',0
100
;aEdit_box_mouse db 'edit_box_mouse',0
101
;aVersion_ed     db 'version_ed',0
102
 
103
;aCheck_box_draw  db 'check_box_draw',0
104
;aCheck_box_mouse db 'check_box_mouse',0
105
;aVersion_ch      db 'version_ch',0
106
 
107
;aOption_box_draw  db 'option_box_draw',0
108
;aOption_box_mouse db 'option_box_mouse',0
109
;aVersion_op       db 'version_op',0
110
 
111
;---------------------------------------------------------------------
112
macro @use_library
1064 Lrz 113
{
1068 Lrz 114
show_err_:
115
local red_win
116
local still
117
local button
118
local __sc
119
local start
120
local ex_lp
121
local lp
122
local correction
123
;/equ
124
err_message1     equ    dword [esp+8]
125
head1            equ    dword [esp+4]
126
 
127
 
128
__sc.frame                equ  dword [__sc+0]
129
__sc.grab                 equ  dword [__sc+4]
130
__sc.grab_button          equ  dword [__sc+8]
131
__sc.grab_button_text     equ  dword [__sc+12]
132
__sc.grab_text            equ  dword [__sc+16]
133
__sc.work                 equ  dword [__sc+20]
134
__sc.work_button          equ  dword [__sc+24]
135
__sc.work_button_text     equ  dword [__sc+28]
136
__sc.work_text            equ  dword [__sc+32]
137
__sc.work_graph           equ  dword [__sc+36]
138
 
139
;local on_x
140
;local on_y
141
 
142
;;;;;;;;;;;CALC WIDTH & HIGHT WINDOW & CENTER MONITOR POSITION;;;;;;;;;;
143
        mov     eax,48             ;get system color
144
        mov     ebx,3
145
        mov     ecx,__sc
146
        mov     edx,sizeof.system_colors
147
        mcall
148
;---------------------------------------------------------------------
149
;get with text imul on 6 pix
150
        xor     eax,eax
151
        mov     esi,err_message1
152
        mov     ecx,30
153
align 4
154
lp:     lodsb
155
        test    eax,eax
156
        jz      ex_lp
157
        add     ecx,7
158
        jmp     lp
159
;---------------------------------------------------------------------
160
ex_lp:
161
        mcall   48,5    ;get system window
162
        sub     eax,ecx
163
        sub     bx,90
164
 
165
        shl     eax,15
166
        shl     ebx,15
167
 
168
        mov     ax,cx
169
 
170
        mov     bx,90
171
 
172
        mov     dword [on_x],eax
173
        mov     dword [on_y],ebx
174
 
175
;        mov     eax,dword [esp+4]
176
;        mov     dword [header_xx],eax
177
 
178
;        mov     eax,dword [esp+8]
179
;        mov     dword [message_xx],eax
180
 
181
        jmp     start
182
__sc     system_colors
183
on_x    dd      ?
184
on_y    dd      ?
185
message_xx      dd      ?
186
header_xx       dd      ?
187
;;;;;;;;;;;DRAW WINDOW;;;;;;;;;;;;;;
188
start:
189
        mcall   40,0x5         ;set mask on events rewraw window and get id button.
190
red_win:
191
;draw_window:
192
        mcall 12,1
193
 
194
        xor     eax,eax
195
        mov     ebx,dword [on_x]
196
        mov     ecx,dword [on_y]
197
        mov     edx,__sc.work
198
        or      edx,0x33000000
199
        mov     esi,__sc.grab_text
200
        mov     edi,head1
201
        mcall
202
 
203
        mov     eax,4
204
        mov     ebx,(10*65536+25)
205
        mov     ecx,__sc.grab_text
206
        or      ecx,0x90000000
207
        mov     edx,err_message1
208
        mcall
209
        mcall 12,2
210
align 4
211
still:                          ;main loop
212
        mcall   10              ;wait event
213
        dec  eax
214
        jz   red_win
215
        sub  eax,2
216
        jnz  still   ;go to main loop
217
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
218
button:
219
        mcall   17      ;get id button
220
        test    ah,ah      ;if in ah 0, then go to still
221
        jz      still
222
        or      dword [esp+40],-1; modify eax in stack (pushad)
223
        ret
224
 
225
;---------------------------------------------------------------------
226
@library_name     equ    dword [esp+12]
227
@cur_dir_path     equ    dword [esp+8]
228
@library_path     equ    dword [esp+4]
229
 
230
align 4
231
@copy_path:
232
        mov     ebx,@library_name
233
        mov     esi,@cur_dir_path
234
        mov     edi,@library_path
235
 
236
        xor     eax,eax
237
        cld
238
.lp1:
239
        lodsb
240
        stosb
241
        test    eax,eax
242
        jnz     .lp1
243
        mov     esi,edi
244
 
245
        std
246
.lp2:
247
        lodsb
248
        cmp     al,'/'
249
        jnz     .lp2
250
        mov     edi,esi
251
        mov     esi,ebx
252
        add     edi,2
253
 
254
 
255
        cld
256
.lp3:
257
        lodsb
258
        stosb
259
        test    eax,eax
260
        jnz     .lp3
261
;---------------------------------------------------------------------
262
	ret
263
}
264
 
265
 
266
 
267
macro sys_load_library library_name, cur_dir_path, library_path, system_path, err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
268
{
1064 Lrz 269
local end_steep
1068 Lrz 270
local exit
1064 Lrz 271
;---------------------------------------------------------------------
272
; loading Box_Lib library
273
 
274
        mcall   68,19,system_path   ; load of sys directory
275
        test    eax,eax
276
        jnz     end_steep
277
 
1068 Lrz 278
        copy_path   library_name, cur_dir_path, library_path    ;the macros making way /current pach a program/+ name system library
1064 Lrz 279
 
280
        mcall   68,19,library_path ; load of alternative
281
        test    eax,eax
282
        jnz     end_steep
283
        show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
1068 Lrz 284
        jmp     exit
1064 Lrz 285
 
1068 Lrz 286
 
287
align 4
1064 Lrz 288
end_steep:
289
 
290
        import_boxlib myimport, err_message_import, head_f_i  ;import
1068 Lrz 291
exit:
1064 Lrz 292
;---------------------------------------------------------------------
293
}
294
 
295
 
1068 Lrz 296
macro load_library library_name, cur_dir_path, library_path, system_path, err_message_found_lib, head_f_l, myimport, err_message_import, head_f_i
1064 Lrz 297
{
298
local end_steep
1068 Lrz 299
local exit
1064 Lrz 300
;---------------------------------------------------------------------
301
; loading Box_Lib library
302
 
1068 Lrz 303
        copy_path  library_name, cur_dir_path, library_path     ;the macros making way /current pach a program/+ name system library
1064 Lrz 304
 
305
        mcall   68,19,library_path ; load of alternative
306
        test    eax,eax
307
        jnz     end_steep
308
 
309
        mcall   68,19,system_path ; load of sys directory
310
        test    eax,eax
311
        jnz     end_steep
312
 
313
        show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
1068 Lrz 314
        jmp     exit
1064 Lrz 315
 
1068 Lrz 316
align 4
1064 Lrz 317
end_steep:
318
 
319
        import_boxlib myimport, err_message_import, head_f_i  ;import
1068 Lrz 320
exit:
1064 Lrz 321
;---------------------------------------------------------------------
322
}
1068 Lrz 323
macro sys_load_libraries _start,_end
1064 Lrz 324
{
1068 Lrz 325
local lp
1064 Lrz 326
local end_steep
1068 Lrz 327
local next
328
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329
library_name            equ [ebp]
330
cur_dir_path            equ [ebp+4]
331
library_path            equ [ebp+8]
332
system_path             equ [ebp+12]
333
err_message_found_lib   equ [ebp+16]
334
head_f_l                equ [ebp+20]
335
my_import               equ [ebp+24]
336
err_message_import      equ [ebp+28]
337
head_f_i                equ [ebp+32]
338
adr_load_lib            equ dword [ebp+36]
339
status_lib              equ dword [ebp+40]
1064 Lrz 340
 
1068 Lrz 341
;        show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
342
;        int 0x40
343
 
344
        mov     ebp,_start
345
        mov     ecx,((_end-_start)/ll_struc_size)
346
 
347
align 4
348
lp:     push    ecx
1064 Lrz 349
        mcall   68,19,system_path   ; load of sys directory
350
        test    eax,eax
351
        jnz     end_steep
352
 
1068 Lrz 353
        copy_path  library_name, cur_dir_path, library_path     ;the macros making way /current pach a program/+ name system library
1064 Lrz 354
 
355
        mcall   68,19,library_path ; load of alternative
356
        test    eax,eax
357
        jnz     end_steep
358
 
1068 Lrz 359
        or      status_lib,0x1          ; status of code - enable error - not found library
360
 
1064 Lrz 361
        show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
1068 Lrz 362
        jmp      next
1064 Lrz 363
 
1068 Lrz 364
align 4
1064 Lrz 365
end_steep:
1068 Lrz 366
        mov     adr_load_lib,eax        ;save adr lib in memory
367
        import_boxlib my_import, err_message_import, head_f_i  ;import
1064 Lrz 368
 
1068 Lrz 369
        test    eax,eax
370
        jz      next
371
 
372
        or      status_lib,0x2          ; status of code - enable error - import error
373
 
374
next:
375
        pop     ecx
376
        add     ebp,ll_struc_size
377
        dec     ecx
378
        jnz     lp
1064 Lrz 379
}
380
 
1068 Lrz 381
macro load_libraries _start,_end
382
{
383
local lp
384
local end_steep
385
local next
386
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
387
library_name            equ [ebp]
388
cur_dir_path            equ [ebp+4]
389
library_path            equ [ebp+8]
390
system_path             equ [ebp+12]
391
err_message_found_lib   equ [ebp+16]
392
head_f_l                equ [ebp+20]
393
my_import               equ [ebp+24]
394
err_message_import      equ [ebp+28]
395
head_f_i                equ [ebp+32]
396
adr_load_lib            equ dword [ebp+36]
397
status_lib              equ dword [ebp+40]
1064 Lrz 398
 
1068 Lrz 399
        mov     ebp,_start
400
        mov     ecx,((_end-_start)/ll_struc_size)
1064 Lrz 401
 
1068 Lrz 402
align 4
403
lp:     push    ecx
1064 Lrz 404
 
1068 Lrz 405
        copy_path    library_name, cur_dir_path, library_path   ;the macros making way /current pach a program/+ name system library
1064 Lrz 406
 
1068 Lrz 407
        mcall   68,19,library_path  ; load of alternative
1064 Lrz 408
        test    eax,eax
1068 Lrz 409
        jnz     end_steep
410
 
411
        mcall   68,19,system_path   ; load of sys directory
412
        test    eax,eax
413
        jnz     end_steep
1064 Lrz 414
 
1068 Lrz 415
        or      status_lib,0x1          ; status of code - enable error - not found library
1064 Lrz 416
 
1068 Lrz 417
        show_error_window  err_message_found_lib, head_f_l    ;show error message /create window
418
        jmp      next
1064 Lrz 419
 
1068 Lrz 420
align 4
421
end_steep:
422
        mov     adr_load_lib,eax        ;save adr lib in memory
423
 
424
        import_boxlib my_import, err_message_import, head_f_i  ;import
425
 
1064 Lrz 426
        test    eax,eax
1068 Lrz 427
        jz      next
428
 
429
        or      status_lib,0x2          ; status of code - enable error - import error
430
 
431
next:
432
        pop     ecx
433
        add     ebp,ll_struc_size
434
        dec     ecx
435
        jnz     lp
1064 Lrz 436
}
437
 
1068 Lrz 438
 
439
macro copy_path lib_name,dir_path,lib_path
1064 Lrz 440
{
1068 Lrz 441
        pushad  ;save all registers
442
        push    dword lib_name
443
        push    dword dir_path
444
        push    dword lib_path
1064 Lrz 445
 
1068 Lrz 446
        call    @copy_path
447
 
448
        add     esp,12
449
        popad   ;restore all registers
1064 Lrz 450
}
451
 
1068 Lrz 452
macro show_error_window  err_message, head
453
{       pushad  ;save all registers
454
        push    dword err_message
455
        push    dword head
456
 
457
        call    show_err_
458
 
459
        add     esp,8
460
        popad   ;restore all registers
461
}
462
 
463
 
1064 Lrz 464
macro import_boxlib myimport, err_message_import, head_f_i
465
{
466
local import_loop
467
local import_find
468
local lp
469
local import_find_next
470
local import_found
471
local import_done
472
local exit
1068 Lrz 473
local e.exit
474
local import_not_found
1064 Lrz 475
; initialize import
1068 Lrz 476
 
1064 Lrz 477
        mov     edx, eax
478
        mov     esi,myimport
479
import_loop:
480
        lodsd
481
        test    eax, eax
482
        jz      import_done
483
        push    edx
484
import_find:
485
        mov     ebx, [ds:edx]
486
        test    ebx, ebx
1068 Lrz 487
        jz      import_not_found
1064 Lrz 488
        push    eax
489
lp:
490
        mov     cl, [ds:eax]
491
        cmp     cl, [ds:ebx]
492
        jnz     import_find_next
493
        test    cl, cl
494
        jz      import_found
495
        inc     eax
496
        inc     ebx
497
        jmp     lp
498
import_find_next:
499
        pop     eax
500
        add     edx, 8
501
        jmp     import_find
502
import_found:
503
        pop     eax
504
        mov     eax, [ds:edx+4]
505
        mov     [esi-4], eax
506
        pop     edx
507
        jmp     import_loop
1068 Lrz 508
import_not_found:
1064 Lrz 509
        add     esp,4
510
        show_error_window  err_message_import, head_f_i    ;show error message /create window
1068 Lrz 511
        jmp     e.exit
1064 Lrz 512
import_done:
1068 Lrz 513
        xor     eax,eax
514
e.exit:
1064 Lrz 515
;---------------------------------------------------------------------
1068 Lrz 516
}
517
ll_struc_size = 44;($-library_name)    ; constant   size of struct
518
struc l_libs library_name, cur_dir_path, library_path, system_path, err_message_found_lib, head_f_l, my_import, err_message_import, head_f_i; struct for loading libraries
519
{
520
.library_name            dd library_name
521
.cur_dir_path            dd cur_dir_path
522
.library_path            dd library_path
523
.system_path             dd system_path
524
.err_message_found_lib   dd err_message_found_lib
525
.head_f_l                dd head_f_l
526
.my_import               dd my_import
527
.err_message_import      dd err_message_import
528
.head_f_i                dd head_f_i
529
.adr_load_lib            dd 0x0
530
.status_lib              dd 0x0          ;status of load library
531
;
532
 
533
}