kolibrios-gitea/programs/develop/libraries/box_lib/trunk/load_lib.mac
Alexey Teplov ( ea836f1026 bugfix a macros load_lib.mac
git-svn-id: svn://kolibrios.org@1068 a494cfbc-eb01-0410-851d-a64ba20cac60
2009-05-08 17:45:28 +00:00

534 lines
16 KiB
Plaintext

;08.05.2009 - bugfix
;14.04.2009 - a macros for code load library the box_lib.obj from '/sys/lib/' or current dirrectory.
; The macros for load any library/libraries:
; Copyright (c) 2009, <Lrz>
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
; * Neither the name of the <organization> nor the
; names of its contributors may be used to endorse or promote products
; derived from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY Alexey Teplov aka <Lrz> ''AS IS'' AND ANY
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;*****************************************************************************
; This macros based on source code:
; <Lrz> - Alexey Teplov / Àëåêñåé Òåïëîâ
; Mario79, Mario - Marat Zakiyanov / Ìàðàò Çàêèÿíîâ
; Diamondz - Evgeny Grechnikov / Åâãåíèé Ãðå÷íèêîâ
;------------------------
; DESCRIPTION
; Macro load_library
; Logick of work.
; A first time we must to check system path, where I belive find a system library. System path is "/sys/lib/".
; If I cannot found my library, i must to check second way. Second way is current dirrectory.
; If we cannot load library, we must show the error message:
; "I'm sorry,the programm cannot found system library box_lib.obj."
; "The find was make on 2 ways: /sys/lib/ and current dirrectory."
;
;
;---------------------------------------------------------------------
; Macro sys_load_library
; A first time we must to check own path in current dirrectory the program, where I belive find a system library.
; If I cannot found my library, i must to check second way. Second way is system path a "/sys/lib/".
; If we cannot load library, we must show the error message:
; "I'm sorry,the programm cannot found system library box_lib.obj."
; "The find was make on 2 ways: /sys/lib/ and current dirrectory."
;
;---------------------------------------------------------------------
; How can I use it?
;---------------------------------------------------------------------
;-Example using single load library
;-universal load library/librarys
;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
;-if return code =-1 then exit, else normally work
; cmp eax,-1
; jz exit
;- Well, if you get
;
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;DATA äàííûå
;Âñåãäà ñîáëþäàòü ïîñëåäîâàòåëüíîñòü â èìåíè.
;system_path db '/sys/lib/'
;library_name db 'box_lib.obj',0
; Åñëè åñòü æåëàíèå ðàçúåäèíèòü, òî íóæíî èñïîëüçîâàòü ñëåäóþùèþ êîíñòðóêöèþ
;system_path db '/sys/lib/box_lib.obj',0
;... ëþáàÿ ïîñëåäîâàòåëüíîñòü äðóãèõ êîìàíä è îïðåäåëåíèé.
;library_name db 'box_lib.obj',0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;err_message_found_lib db 'Sorry I cannot found library box_lib.obj',0
;head_f_i:
;head_f_l db 'System error',0
;err_message_import db 'Error on load import library box_lib.obj',0
;myimport:
;
;edit_box_draw dd aEdit_box_draw
;edit_box_key dd aEdit_box_key
;edit_box_mouse dd aEdit_box_mouse
;version_ed dd aVersion_ed
;
;check_box_draw dd aCheck_box_draw
;check_box_mouse dd aCheck_box_mouse
;version_ch dd aVersion_ch
;
;option_box_draw dd aOption_box_draw
;option_box_mouse dd aOption_box_mouse
;version_op dd aVersion_op
; dd 0
; dd 0
;
;aEdit_box_draw db 'edit_box',0
;aEdit_box_key db 'edit_box_key',0
;aEdit_box_mouse db 'edit_box_mouse',0
;aVersion_ed db 'version_ed',0
;aCheck_box_draw db 'check_box_draw',0
;aCheck_box_mouse db 'check_box_mouse',0
;aVersion_ch db 'version_ch',0
;aOption_box_draw db 'option_box_draw',0
;aOption_box_mouse db 'option_box_mouse',0
;aVersion_op db 'version_op',0
;---------------------------------------------------------------------
macro @use_library
{
show_err_:
local red_win
local still
local button
local __sc
local start
local ex_lp
local lp
local correction
;/equ
err_message1 equ dword [esp+8]
head1 equ dword [esp+4]
__sc.frame equ dword [__sc+0]
__sc.grab equ dword [__sc+4]
__sc.grab_button equ dword [__sc+8]
__sc.grab_button_text equ dword [__sc+12]
__sc.grab_text equ dword [__sc+16]
__sc.work equ dword [__sc+20]
__sc.work_button equ dword [__sc+24]
__sc.work_button_text equ dword [__sc+28]
__sc.work_text equ dword [__sc+32]
__sc.work_graph equ dword [__sc+36]
;local on_x
;local on_y
;;;;;;;;;;;CALC WIDTH & HIGHT WINDOW & CENTER MONITOR POSITION;;;;;;;;;;
mov eax,48 ;get system color
mov ebx,3
mov ecx,__sc
mov edx,sizeof.system_colors
mcall
;---------------------------------------------------------------------
;get with text imul on 6 pix
xor eax,eax
mov esi,err_message1
mov ecx,30
align 4
lp: lodsb
test eax,eax
jz ex_lp
add ecx,7
jmp lp
;---------------------------------------------------------------------
ex_lp:
mcall 48,5 ;get system window
sub eax,ecx
sub bx,90
shl eax,15
shl ebx,15
mov ax,cx
mov bx,90
mov dword [on_x],eax
mov dword [on_y],ebx
; mov eax,dword [esp+4]
; mov dword [header_xx],eax
; mov eax,dword [esp+8]
; mov dword [message_xx],eax
jmp start
__sc system_colors
on_x dd ?
on_y dd ?
message_xx dd ?
header_xx dd ?
;;;;;;;;;;;DRAW WINDOW;;;;;;;;;;;;;;
start:
mcall 40,0x5 ;set mask on events rewraw window and get id button.
red_win:
;draw_window:
mcall 12,1
xor eax,eax
mov ebx,dword [on_x]
mov ecx,dword [on_y]
mov edx,__sc.work
or edx,0x33000000
mov esi,__sc.grab_text
mov edi,head1
mcall
mov eax,4
mov ebx,(10*65536+25)
mov ecx,__sc.grab_text
or ecx,0x90000000
mov edx,err_message1
mcall
mcall 12,2
align 4
still: ;main loop
mcall 10 ;wait event
dec eax
jz red_win
sub eax,2
jnz still ;go to main loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
button:
mcall 17 ;get id button
test ah,ah ;if in ah 0, then go to still
jz still
or dword [esp+40],-1; modify eax in stack (pushad)
ret
;---------------------------------------------------------------------
@library_name equ dword [esp+12]
@cur_dir_path equ dword [esp+8]
@library_path equ dword [esp+4]
align 4
@copy_path:
mov ebx,@library_name
mov esi,@cur_dir_path
mov edi,@library_path
xor eax,eax
cld
.lp1:
lodsb
stosb
test eax,eax
jnz .lp1
mov esi,edi
std
.lp2:
lodsb
cmp al,'/'
jnz .lp2
mov edi,esi
mov esi,ebx
add edi,2
cld
.lp3:
lodsb
stosb
test eax,eax
jnz .lp3
;---------------------------------------------------------------------
ret
}
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
{
local end_steep
local exit
;---------------------------------------------------------------------
; loading Box_Lib library
mcall 68,19,system_path ; load of sys directory
test eax,eax
jnz end_steep
copy_path library_name, cur_dir_path, library_path ;the macros making way /current pach a program/+ name system library
mcall 68,19,library_path ; load of alternative
test eax,eax
jnz end_steep
show_error_window err_message_found_lib, head_f_l ;show error message /create window
jmp exit
align 4
end_steep:
import_boxlib myimport, err_message_import, head_f_i ;import
exit:
;---------------------------------------------------------------------
}
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
{
local end_steep
local exit
;---------------------------------------------------------------------
; loading Box_Lib library
copy_path library_name, cur_dir_path, library_path ;the macros making way /current pach a program/+ name system library
mcall 68,19,library_path ; load of alternative
test eax,eax
jnz end_steep
mcall 68,19,system_path ; load of sys directory
test eax,eax
jnz end_steep
show_error_window err_message_found_lib, head_f_l ;show error message /create window
jmp exit
align 4
end_steep:
import_boxlib myimport, err_message_import, head_f_i ;import
exit:
;---------------------------------------------------------------------
}
macro sys_load_libraries _start,_end
{
local lp
local end_steep
local next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
library_name equ [ebp]
cur_dir_path equ [ebp+4]
library_path equ [ebp+8]
system_path equ [ebp+12]
err_message_found_lib equ [ebp+16]
head_f_l equ [ebp+20]
my_import equ [ebp+24]
err_message_import equ [ebp+28]
head_f_i equ [ebp+32]
adr_load_lib equ dword [ebp+36]
status_lib equ dword [ebp+40]
; show_error_window err_message_found_lib, head_f_l ;show error message /create window
; int 0x40
mov ebp,_start
mov ecx,((_end-_start)/ll_struc_size)
align 4
lp: push ecx
mcall 68,19,system_path ; load of sys directory
test eax,eax
jnz end_steep
copy_path library_name, cur_dir_path, library_path ;the macros making way /current pach a program/+ name system library
mcall 68,19,library_path ; load of alternative
test eax,eax
jnz end_steep
or status_lib,0x1 ; status of code - enable error - not found library
show_error_window err_message_found_lib, head_f_l ;show error message /create window
jmp next
align 4
end_steep:
mov adr_load_lib,eax ;save adr lib in memory
import_boxlib my_import, err_message_import, head_f_i ;import
test eax,eax
jz next
or status_lib,0x2 ; status of code - enable error - import error
next:
pop ecx
add ebp,ll_struc_size
dec ecx
jnz lp
}
macro load_libraries _start,_end
{
local lp
local end_steep
local next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
library_name equ [ebp]
cur_dir_path equ [ebp+4]
library_path equ [ebp+8]
system_path equ [ebp+12]
err_message_found_lib equ [ebp+16]
head_f_l equ [ebp+20]
my_import equ [ebp+24]
err_message_import equ [ebp+28]
head_f_i equ [ebp+32]
adr_load_lib equ dword [ebp+36]
status_lib equ dword [ebp+40]
mov ebp,_start
mov ecx,((_end-_start)/ll_struc_size)
align 4
lp: push ecx
copy_path library_name, cur_dir_path, library_path ;the macros making way /current pach a program/+ name system library
mcall 68,19,library_path ; load of alternative
test eax,eax
jnz end_steep
mcall 68,19,system_path ; load of sys directory
test eax,eax
jnz end_steep
or status_lib,0x1 ; status of code - enable error - not found library
show_error_window err_message_found_lib, head_f_l ;show error message /create window
jmp next
align 4
end_steep:
mov adr_load_lib,eax ;save adr lib in memory
import_boxlib my_import, err_message_import, head_f_i ;import
test eax,eax
jz next
or status_lib,0x2 ; status of code - enable error - import error
next:
pop ecx
add ebp,ll_struc_size
dec ecx
jnz lp
}
macro copy_path lib_name,dir_path,lib_path
{
pushad ;save all registers
push dword lib_name
push dword dir_path
push dword lib_path
call @copy_path
add esp,12
popad ;restore all registers
}
macro show_error_window err_message, head
{ pushad ;save all registers
push dword err_message
push dword head
call show_err_
add esp,8
popad ;restore all registers
}
macro import_boxlib myimport, err_message_import, head_f_i
{
local import_loop
local import_find
local lp
local import_find_next
local import_found
local import_done
local exit
local e.exit
local import_not_found
; initialize import
mov edx, eax
mov esi,myimport
import_loop:
lodsd
test eax, eax
jz import_done
push edx
import_find:
mov ebx, [ds:edx]
test ebx, ebx
jz import_not_found
push eax
lp:
mov cl, [ds:eax]
cmp cl, [ds:ebx]
jnz import_find_next
test cl, cl
jz import_found
inc eax
inc ebx
jmp lp
import_find_next:
pop eax
add edx, 8
jmp import_find
import_found:
pop eax
mov eax, [ds:edx+4]
mov [esi-4], eax
pop edx
jmp import_loop
import_not_found:
add esp,4
show_error_window err_message_import, head_f_i ;show error message /create window
jmp e.exit
import_done:
xor eax,eax
e.exit:
;---------------------------------------------------------------------
}
ll_struc_size = 44;($-library_name) ; constant size of struct
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
{
.library_name dd library_name
.cur_dir_path dd cur_dir_path
.library_path dd library_path
.system_path dd system_path
.err_message_found_lib dd err_message_found_lib
.head_f_l dd head_f_l
.my_import dd my_import
.err_message_import dd err_message_import
.head_f_i dd head_f_i
.adr_load_lib dd 0x0
.status_lib dd 0x0 ;status of load library
;
}