diff --git a/programs/develop/libraries/libs-dev/.test/001/test001.asm b/programs/develop/libraries/libs-dev/.test/001/test001.asm new file mode 100644 index 0000000000..5e232e662b --- /dev/null +++ b/programs/develop/libraries/libs-dev/.test/001/test001.asm @@ -0,0 +1,417 @@ + + use32 + org 0x0 + + db 'MENUET01' + dd 0x01 + dd START + dd I_END + dd 0x1000 + dd 0x1000 + dd 0x0 + dd 0x0 + +FALSE = 0 +TRUE = 1 + +include '../../../../../proc32.inc' +include '../../../../../macros.inc' +include '../../libio/libio.inc' +include '../dll.inc' + +yy dd 20 + +proc draw xx,color,key,val + pushad + + mov esi,[key] + mov edi,buf + cld + mov al,"'" + stosb + @@: lodsb + stosb + or al,al + jnz @b + mov word[edi-1],"'" + + mov esi,[val] + or esi,esi + je .noval + mov eax," = '" + stosd + @@: lodsb + stosb + or al,al + jnz @b + mov word[edi-1],"'" + .noval: + + or [color],0x80000000 + mcall 4,<[xx],[yy]>,[color],buf + add [yy],10 + popad + ret +endp + +proc callb_k f_name,sec_name,key_name,key_val + stdcall draw,224,0x0000FF,[key_name],[key_val] + mov eax,TRUE + ret +endp + +proc callb f_name,sec_name + stdcall draw,200,0xFF0000,[sec_name],0 + invoke ini.enum_keys,[f_name],[sec_name],callb_k + mov eax,TRUE + ret +endp + +;--------------------------------------------------------------------- +;--- ÍÀ×ÀËÎ ÏÐÎÃÐÀÌÌÛ ---------------------------------------------- +;--------------------------------------------------------------------- + +s_key1 db "LeftViewMode",0 +s_key2 db "RightViewMode",0 + +s_null db "",0 + +macro wildcard_test_data label1, label2, label3, [str1, str2, res] +{ + common + label label1 + forward + local ..lbl + dd ..lbl - $ + db str1,0 + ..lbl: + common + dd 0 + label label2 + forward + local ..lbl + dd ..lbl - $ + db str2,0 + ..lbl: + common + label label3 + forward + if res = "t" + dd 1 + else + dd 0 + end if +} + +wildcard_test_data _str1, _str2, _str3, \ + "" ,"" ,"t", "" ,"a" ,"f", \ + "a" ,"a" ,"t", "a" ,"b" ,"f", \ + "?" ,"b" ,"t", "??" ,"bc" ,"t", \ + "?c" ,"bc" ,"t", "b?" ,"bc" ,"t", \ + "[a-z]" ,"b" ,"t", "[A-Z]" ,"b" ,"f", \ + "*" ,"a" ,"t", "**" ,"a" ,"t", \ + "*" ,"" ,"t", "*bc*hij" ,"abcdfghij","t", \ + "*b*a*" ,"b" ,"f", "*bc*hik" ,"abcdfghij","f", \ + "abc*" ,"abc" ,"t", "abc**" ,"abc" ,"t", \ + "[^]]" ,"^" ,"t", "[^]]" ,"]" ,"f", \ + "[^abc]" ,"d" ,"t", "[^abc]" ,"b" ,"f", \ + "*???" ,"abc" ,"t", "*???" ,"ab" ,"f", \ + "*???" ,"abcd" ,"t", "*?*" ,"abcd" ,"t", \ + "*bc" ,"abc" ,"t", "*cc" ,"abc" ,"f", \ + "[a-c]*" ,"d" ,"f", "*[a-e]" ,"d" ,"t", \ + "*a*" ,"de" ,"f", "*[a-c]" ,"d" ,"f", \ + "[a-c]" ,"d" ,"f", "[b-d]" ,"a" ,"f", \ + "[]abc]" ,"b" ,"t", "[]abc]" ,"d" ,"f", \ + "[z-a]" ,"-" ,"t", "[z-a]" ,"b" ,"f", \ + "[A-]" ,"-" ,"t", "[A-]" ,"]" ,"f", \ + "[-a]" ,"-" ,"t", "[-[]" ,"-" ,"t", \ + "[-]" ,"-" ,"t", "[^-b]" ,"a" ,"t", \ + "[^-b]" ,"-" ,"f", "[-b]" ,"a" ,"f", \ + "[a-g]lorian","florian","t", "[a-g]*rorian","f" ,"f", \ + "*???*" ,"123" ,"t" + +START: + mcall 68,11 + + stdcall dll.Load,@IMPORT + or eax,eax + jnz exit + + mov esi,_str1 + 4 + mov edi,_str2 + 4 + mov ecx,_str3 + xor ebx,ebx + inc ebx + @@: invoke file.aux.match_wildcard,edi,esi,0 + cmp eax,[ecx] + je .ok + mcall -1 + .ok: inc ebx + add esi,[esi-4] + add edi,[edi-4] + add ecx,4 + cmp dword[esi-4],0 + jnz @b + + invoke ini.set_int,s_ini,s_sec,s_key1,100 + invoke ini.set_int,s_ini,s_sec,s_key2,101 + + invoke ini.get_int,s_ini,s_sec,s_key1,-1 + cmp eax,100 + jne exit + invoke ini.get_int,s_ini,s_sec,s_key2,-1 + cmp eax,101 + jne exit + + mov dword[buf],'102' + invoke ini.set_str,s_ini,s_sec,s_key1,buf,3 + mov dword[buf],'103' + invoke ini.set_str,s_ini,s_sec,s_key2,buf,3 + + invoke ini.get_str,s_ini,s_sec,s_key1,buf,1024,s_null + cmp dword[buf],'102' + jne exit + invoke ini.get_str,s_ini,s_sec,s_key2,buf,1024,s_null + cmp dword[buf],'103' + jne exit + + invoke ini.enum_sections,s_ini,callb + +; invoke file.open,s_ininame,O_WRITE+O_CREATE +; or eax,eax +; jnz @f +; int3 +; @@: mov [fh],eax +; invoke file.seek,[fh],SEEK_SET,8192 +; invoke file.write,[fh],s_ininame,16 +; invoke file.seteof,[fh] +; invoke file.close,[fh] + +red: + + call draw_window + +;--------------------------------------------------------------------- +;--- ÖÈÊË ÎÁÐÀÁÎÒÊÈ ÑÎÁÛÒÈÉ ---------------------------------------- +;--------------------------------------------------------------------- + +still: + mcall 10 + + cmp eax,1 + je red + cmp eax,2 + je key + cmp eax,3 + je button + + jmp still + +;--------------------------------------------------------------------- + + key: + mcall 2 + jmp still + +;--------------------------------------------------------------------- + + button: + mcall 17 + + cmp ah,1 + jne still + + exit: + mcall -1 + +;--------------------------------------------------------------------- +;--- ÎÏÐÅÄÅËÅÍÈÅ È ÎÒÐÈÑÎÂÊÀ ÎÊÍÀ ---------------------------------- +;--------------------------------------------------------------------- + +ctx dd ? + +draw_window: + invoke gfx.open,TRUE + mov [ctx],eax + mcall 0,<200,700>,<200,200>,0x33FFFFFF,,s_header + invoke gfx.pen.color,[ctx],0x00FF0000 + invoke gfx.line,[ctx],0,0,50,50 + invoke gfx.framerect,[ctx],10,10,100,70 + invoke gfx.brush.color,[ctx],0x000000FF + invoke gfx.fillrect,[ctx],15,15,95,65 + invoke gfx.pen.color,[ctx],0x00008800 + invoke gfx.brush.color,[ctx],0x00CCCCFF + invoke gfx.rectangle,[ctx],20,20,90,60 + invoke gfx.move.to,[ctx],13,5 + invoke gfx.line.to,[ctx],105,5 + invoke gfx.line.to,[ctx],105,75 + invoke gfx.line.to,[ctx],5,75 + invoke gfx.line.to,[ctx],5,13 + invoke gfx.line.to,[ctx],13,5 + invoke gfx.pen.color,[ctx],0x00888888 + invoke gfx.polyline,[ctx],poly_points,11 + invoke gfx.close,[ctx] + + mov [yy],10 + invoke ini.enum_sections,s_ini,callb + + invoke file.find_first,_f_path,_f_mask,FA_ANY-FA_FOLDER + cmp eax,0 + jle .finished + mov ebp,eax + mov [yy],10 + @@: lea edx,[ebp+FileInfo.FileName] + mcall 4,<450,[yy]>,0x80000000 + add [yy],10 + invoke file.find_next,ebp + cmp eax,0 + jg @b + invoke file.find_close,ebp + + .finished: + + ret + +_f_path db '/rd/1/lib',0 +_f_mask db '*ini*',0 + +;----------------------------------------------------------------------------- +proc mem.Alloc size ;///////////////////////////////////////////////////////// +;----------------------------------------------------------------------------- + push ebx ecx + mov eax,[size] + lea ecx,[eax+4+4095] + and ecx,not 4095 + mcall 68,12 + add ecx,-4 + mov [eax],ecx + add eax,4 + pop ecx ebx + ret +endp + +;----------------------------------------------------------------------------- +proc mem.ReAlloc mptr,size;/////////////////////////////////////////////////// +;----------------------------------------------------------------------------- + push ebx ecx esi edi eax + mov eax,[mptr] + mov ebx,[size] + or eax,eax + jz @f + lea ecx,[ebx+4+4095] + and ecx,not 4095 + add ecx,-4 + cmp ecx,[eax-4] + je .exit + @@: mov eax,ebx + call mem.Alloc + xchg eax,[esp] + or eax,eax + jz .exit + mov esi,eax + xchg eax,[esp] + mov edi,eax + mov ecx,[esi-4] + cmp ecx,[edi-4] + jbe @f + mov ecx,[edi-4] + @@: add ecx,3 + shr ecx,2 + cld + rep movsd + xchg eax,[esp] + call mem.Free + .exit: + pop eax edi esi ecx ebx + ret +endp + +;----------------------------------------------------------------------------- +proc mem.Free mptr ;////////////////////////////////////////////////////////// +;----------------------------------------------------------------------------- + mov eax,[mptr] + or eax,eax + jz @f + push ebx ecx + lea ecx,[eax-4] + mcall 68,13 + pop ecx ebx + @@: ret +endp + +;--------------------------------------------------------------------- +;--- ÄÀÍÍÛÅ ÏÐÎÃÐÀÌÌÛ ---------------------------------------------- +;--------------------------------------------------------------------- + +s_header db 'EXAMPLE APPLICATION',0 + +s_ini db '/rd/1/test001.ini',0 +s_sec db 'Panels',0 +s_key db 'param1',0 + +align 4 +poly_points dd \ + 140, 10, \ + 150, 10, \ + 150, 20, \ + 160, 20, \ + 160, 30, \ + 170, 30, \ + 170, 40, \ + 180, 40, \ + 180, 50, \ + 140, 50, \ + 140, 10 + +;--------------------------------------------------------------------- + +align 16 +@IMPORT: + +library \ + libini,'libini.obj',\ + libio ,'libio.obj',\ + libgfx,'libgfx.obj' + +import libini, \ + ini.get_str,'ini.get_str',\ + ini.set_str,'ini.set_str',\ + ini.get_int,'ini.get_int',\ + ini.set_int,'ini.set_int',\ + ini.enum_sections,'ini.enum_sections',\ + ini.enum_keys,'ini.enum_keys' + +import libio, \ + file.aux.match_wildcard,'file.aux.match_wildcard',\ + file.find_first,'file.find_first',\ + file.find_next,'file.find_next',\ + file.find_close,'file.find_close',\ + file.open,'file.open',\ + file.seek,'file.seek',\ + file.write,'file.write',\ + file.truncate,'file.truncate',\ + file.close,'file.close' + +import libgfx, \ + gfx.open ,'gfx.open',\ + gfx.close ,'gfx.close',\ + gfx.pen.color ,'gfx.pen.color',\ + gfx.brush.color ,'gfx.brush.color',\ + gfx.pixel ,'gfx.pixel',\ + gfx.move.to ,'gfx.move.to',\ + gfx.line.to ,'gfx.line.to',\ + gfx.line ,'gfx.line',\ + gfx.polyline ,'gfx.polyline',\ + gfx.polyline.to ,'gfx.polyline.to',\ + gfx.fillrect ,'gfx.fillrect',\ + gfx.fillrect.ex ,'gfx.fillrect.ex',\ + gfx.framerect ,'gfx.framerect',\ + gfx.framerect.ex,'gfx.framerect.ex',\ + gfx.rectangle ,'gfx.rectangle',\ + gfx.rectangle.ex,'gfx.rectangle.ex' + +I_END: + +fh dd ? + +buf rb 1024 diff --git a/programs/develop/libraries/libs-dev/.test/001/test001.ini b/programs/develop/libraries/libs-dev/.test/001/test001.ini new file mode 100644 index 0000000000..679f847422 --- /dev/null +++ b/programs/develop/libraries/libs-dev/.test/001/test001.ini @@ -0,0 +1,20 @@ +[section 1] +key 11=val 11 11 +key 12=val 12 + +[-s-e-c-t-i-o-n- -#-2-] +-k-e-y- -2-1- = -v-a-l- -2-1- +-k-e-y- -2-2- = -v-a-l- -2-2- + +[ section3 ] + key31 = val31 + key32 = val32 + +[ /section/ "#4" (the) ] + /key/ "41" = (val) <41> + /key/ "42" = (val) <42> + +[Panels] +LeftViewMode=102 +RightViewMode=103 +Param= diff --git a/programs/develop/libraries/libs-dev/.test/002/test002.asm b/programs/develop/libraries/libs-dev/.test/002/test002.asm new file mode 100644 index 0000000000..f4c2bf0332 --- /dev/null +++ b/programs/develop/libraries/libs-dev/.test/002/test002.asm @@ -0,0 +1,196 @@ +use32 +org 0x0 + +db 'MENUET01' +dd 0x01, START, I_END, 0x1000, 0x1000, @PARAMS, 0x0 + +;----------------------------------------------------------------------------- + +FALSE = 0 +TRUE = 1 + +include '../../../../../proc32.inc' +include '../../../../../macros.inc' +include '../dll.inc' + +include '../../libio/libio.inc' + +;----------------------------------------------------------------------------- + +START: + mcall 68, 11 + + stdcall dll.Load, @IMPORT + or eax, eax + jnz exit + + invoke file.open, @PARAMS, O_READ + or eax, eax + jz exit + mov [fh], eax + invoke file.size, @PARAMS + mov [img_data_len], ebx + stdcall mem.Alloc, ebx + or eax, eax + jz exit + mov [img_data], eax + invoke file.read, [fh], eax, [img_data_len] + cmp eax, -1 + je exit + cmp eax, [img_data_len] + jne exit + invoke file.close, [fh] + inc eax + jz exit + + invoke img.is_img, [img_data], [img_data_len] + or eax, eax + jz exit + invoke img.decode, [img_data], [img_data_len] + or eax, eax + jz exit + invoke img.to_rgb, eax + or eax, eax + jz exit + mov [rgb_img], eax + +;----------------------------------------------------------------------------- + +red: + call draw_window + +still: + mcall 10 + cmp eax, 1 + je red + cmp eax, 2 + je key + cmp eax, 3 + je button + jmp still + + key: + mcall 2 + jmp still + + button: + mcall 17 + cmp ah, 1 + jne still + + exit: + mcall -1 + +draw_window: + invoke gfx.open, TRUE + mov [ctx], eax + + mov edi, [rgb_img] + mov ebx, 200 * 65536 + mov bx, [edi + 0] + add bx, 9 + mov ecx, 200 * 65536 + mov cx, [edi + 4] + add cx, 5 + 21 + mcall 0, , , 0x33FF0000, , s_header + + mov ebx, [rgb_img] + mov ecx, [ebx + 0] + shl ecx, 16 + mov cx, [ebx + 4] + add ebx, 4 * 2 + mcall 7, , , <0, 0> + + invoke gfx.close, [ctx] + ret + +;----------------------------------------------------------------------------- +proc mem.Alloc, size ;//////////////////////////////////////////////////////// +;----------------------------------------------------------------------------- + push ebx ecx + mov ecx, [size] + add ecx, 4 + mcall 68, 12 + add ecx, -4 + mov [eax], ecx + add eax, 4 + pop ecx ebx + ret +endp + +;----------------------------------------------------------------------------- +proc mem.ReAlloc, mptr, size ;//////////////////////////////////////////////// +;----------------------------------------------------------------------------- + push ebx ecx edx + mov ecx, [size] + or ecx, ecx + jz @f + add ecx, 4 + @@: mov edx, [mptr] + or edx, edx + jz @f + add edx, -4 + @@: mcall 68, 20 + or eax, eax + jz @f + add ecx, -4 + mov [eax], ecx + add eax, 4 + @@: pop edx ecx ebx + ret +endp + +;----------------------------------------------------------------------------- +proc mem.Free, mptr ;///////////////////////////////////////////////////////// +;----------------------------------------------------------------------------- + push ebx ecx + mov ecx, [mptr] + or ecx, ecx + jz @f + add ecx, -4 + @@: mcall 68, 13 + pop ecx ebx + ret +endp + +;----------------------------------------------------------------------------- + +s_header db 'Image Viewer (test app)', 0 + +;----------------------------------------------------------------------------- + +align 16 +@IMPORT: + +library \ + libio , 'libio.obj' , \ + libgfx , 'libgfx.obj' , \ + libimg , 'libimg.obj' + +import libio , \ + file.size , 'file.size' , \ + file.open , 'file.open' , \ + file.read , 'file.read' , \ + file.close , 'file.close' + +import libgfx , \ + gfx.open , 'gfx.open' , \ + gfx.close , 'gfx.close' + +import libimg , \ + img.is_img , 'img.is_img' , \ + img.to_rgb , 'img.to_rgb' , \ + img.decode , 'img.decode' + +;----------------------------------------------------------------------------- + +I_END: + +img_data dd ? +img_data_len dd ? +fh dd ? +rgb_img dd ? + +ctx dd ? + +@PARAMS rb 512 diff --git a/programs/develop/libraries/libs-dev/.test/dll.inc b/programs/develop/libraries/libs-dev/.test/dll.inc new file mode 100644 index 0000000000..dbd5ff366c --- /dev/null +++ b/programs/develop/libraries/libs-dev/.test/dll.inc @@ -0,0 +1,90 @@ + +proc dll.Load, import_table:dword + mov esi,[import_table] + .next_lib: mov edx,[esi] + or edx,edx + jz .exit + push esi + mov esi,[esi+4] + mov edi,s_libdir.fname + @@: lodsb + stosb + or al,al + jnz @b + mcall 68,19,s_libdir + or eax,eax + jz .fail + stdcall dll.Link,eax,edx + stdcall dll.Init,[eax+4] + pop esi + add esi,8 + jmp .next_lib + .exit: xor eax,eax + ret + .fail: add esp,4 + xor eax,eax + inc eax + ret +endp + +proc dll.Link, exp:dword,imp:dword + push eax + mov esi,[imp] + test esi,esi + jz .done + .next: lodsd + test eax,eax + jz .done + stdcall dll.GetProcAddress,[exp],eax + or eax,eax + jz @f + mov [esi-4],eax + jmp .next + @@: mov dword[esp],0 + .done: pop eax + ret +endp + +proc dll.Init, dllentry:dword + pushad + mov eax,mem.Alloc + mov ebx,mem.Free + mov ecx,mem.ReAlloc + mov edx,dll.Load + stdcall [dllentry] + popad + ret +endp + +proc dll.GetProcAddress, exp:dword,sz_name:dword + mov edx,[exp] + .next: test edx,edx + jz .end + stdcall strcmp,[edx],[sz_name] + test eax,eax + jz .ok + add edx,8 + jmp .next + .ok: mov eax,[edx+4] + .end: ret +endp + +proc strcmp, str1:dword,str2:dword + push esi edi + mov esi,[str1] + mov edi,[str2] + xor eax,eax + @@: lodsb + scasb + jne .fail + or al,al + jnz @b + jmp .ok + .fail: or eax,-1 + .ok: pop edi esi + ret +endp + +s_libdir: + db '/sys/lib/' + .fname rb 32 diff --git a/programs/develop/libraries/libs-dev/libgfx/libgfx.asm b/programs/develop/libraries/libs-dev/libgfx/libgfx.asm new file mode 100644 index 0000000000..1f72c7371d --- /dev/null +++ b/programs/develop/libraries/libs-dev/libgfx/libgfx.asm @@ -0,0 +1,442 @@ +;;================================================================================================;; +;;//// libgfx.asm //// (c) mike.dld, 2006-2008 ///////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +format MS COFF + +public @EXPORT as 'EXPORTS' + +include '../../../../proc32.inc' +include '../../../../macros.inc' +purge section;mov,add,sub + +include 'libgfx_p.inc' + +section '.flat' code readable align 16 + +mem.alloc dd ? +mem.free dd ? +mem.realloc dd ? +dll.load dd ? + +;;================================================================================================;; +proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Library entry point (called after library load) ;; +;;------------------------------------------------------------------------------------------------;; +;> eax = pointer to memory allocation routine ;; +;> ebx = pointer to memory freeing routine ;; +;> ecx = pointer to memory reallocation routine ;; +;> edx = pointer to library loading routine ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 1 (fail) / 0 (ok) (library initialization result) ;; +;;================================================================================================;; + mov [mem.alloc], eax + mov [mem.free], ebx + mov [mem.realloc], ecx + mov [dll.load], edx + xor eax,eax + ret +endp + +;;================================================================================================;; +proc gfx.open _open? ;////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push ebx ecx + xor ecx, ecx + cmp byte[_open?], 0 + je .lp1 + mov eax, 12 + mov ebx, 1 + int 0x40 + jmp @f + .lp1: or ecx, GFX_FLAG_DONT_CLOSE + @@: invoke mem.alloc, sizeof.AGfxContext + xor ebx,ebx + mov [eax + AGfxContext.Flags], ecx + mov [eax + AGfxContext.NullPoint.X], ebx + mov [eax + AGfxContext.NullPoint.Y], ebx + mov [eax + AGfxContext.Caret.X], ebx + mov [eax + AGfxContext.Caret.Y], ebx + mov [eax + AGfxContext.Pen.Color], ebx + mov [eax + AGfxContext.Brush.Color], 0x00FFFFFF + pop ecx ebx + ret +endp + +;;================================================================================================;; +proc gfx.close _ctx ;/////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ebx + mov ebx, [_ctx] + mov ebx, [ebx + AGfxContext.Flags] + invoke mem.free, [_ctx] + test ebx, GFX_FLAG_DONT_CLOSE + jnz @f + mov eax, 12 + mov ebx, 2 + int 0x40 + @@: pop ebx eax + ret +endp + +;;================================================================================================;; +proc gfx.pen.color _ctx, _color ;/////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax + mov eax, [_ctx] + push [_color] + pop [eax + AGfxContext.Pen.Color] + pop eax + ret +endp + +;;================================================================================================;; +proc gfx.brush.color _ctx, _color ;///////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax + mov eax, [_ctx] + push [_color] + pop [eax + AGfxContext.Brush.Color] + pop eax + ret +endp + +;;================================================================================================;; +proc gfx.pixel _ctx, _x, _y ;/////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ebx ecx edx + mov eax, 1 + mov ebx, [_x] + mov ecx, [_y] + mov edx, [_ctx] + mov edx, [edx + AGfxContext.Pen.Color] + int 0x40 + pop edx ecx ebx eax + ret +endp + +;;================================================================================================;; +proc gfx.move.to _ctx, _x, _y ;///////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax + mov eax, [_ctx] + push [_x] [_y] + pop [eax + AGfxContext.Caret.Y] [eax+AGfxContext.Caret.X] + pop eax + ret +endp + +;;================================================================================================;; +proc gfx.line.to _ctx, _x, _y ;///////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax + mov eax, [_ctx] + stdcall gfx.line, eax, [eax + AGfxContext.Caret.X], [eax + AGfxContext.Caret.Y], [_x], [_y] + pop eax + stdcall gfx.move.to, [_ctx], [_x], [_y] + ret +endp + +;;================================================================================================;; +proc gfx.line _ctx, _x1, _y1, _x2, _y2 ;//////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ebx ecx edx + mov eax, 38 + mov ebx, [_x1 - 2] + mov bx, word[_x2] + mov ecx, [_y1 - 2] + mov cx, word[_y2] + mov edx, [_ctx] + mov edx, [edx + AGfxContext.Pen.Color] + int 0x40 + pop edx ecx ebx eax + stdcall gfx.move.to, [_ctx], [_x2], [_y2] + ret +endp + +;;================================================================================================;; +proc gfx.polyline _ctx, _points, _count ;/////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ecx + mov eax, [_points] + stdcall gfx.move.to, [_ctx], [eax + 0], [eax + 4] + mov ecx, [_count] + dec ecx + add eax, 8 + stdcall gfx.polyline.to, [_ctx], eax, ecx + pop ecx eax + ret +endp + +;;================================================================================================;; +proc gfx.polyline.to _ctx, _points, _count ;//////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ecx + mov eax, [_points] + mov ecx, [_count] + @@: stdcall gfx.line.to, [_ctx], [eax + 0], [eax + 4] + add eax, 8 + loop @b + pop ecx eax + ret +endp + +;;================================================================================================;; +proc gfx.fillrect _ctx, _x1, _y1, _x2, _y2 ;//////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ebx ecx edx + mov eax, 13 + mov ebx, [_x1 - 2] + mov bx, word[_x2] + sub bx, word[_x1] + inc bx + mov ecx, [_y1 - 2] + mov cx, word[_y2] + sub cx, word[_y1] + inc cx + mov edx, [_ctx] + mov edx, [edx + AGfxContext.Brush.Color] + int 0x40 + pop edx ecx ebx eax + ret +endp + +;;================================================================================================;; +proc gfx.fillrect.ex _ctx, _rect ;////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax + mov eax, [_rect] + stdcall gfx.fillrect, [_ctx], [eax + ARect.Left], [eax + ARect.Top], \ + [eax + ARect.Right], [eax + ARect.Bottom] + pop eax + ret +endp + +;;================================================================================================;; +proc gfx.framerect _ctx, _x1, _y1, _x2, _y2 ;/////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + stdcall gfx.move.to, [_ctx], [_x1], [_y1] + stdcall gfx.line.to, [_ctx], [_x2], [_y1] + stdcall gfx.line.to, [_ctx], [_x2], [_y2] + stdcall gfx.line.to, [_ctx], [_x1], [_y2] + stdcall gfx.line.to, [_ctx], [_x1], [_y1] + pop edx ecx ebx eax + ret +endp + +;;================================================================================================;; +proc gfx.framerect.ex _ctx, _rect ;///////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax + mov eax, [_rect] + stdcall gfx.framerect, [_ctx], [eax + ARect.Left], [eax + ARect.Top], \ + [eax + ARect.Right], [eax + ARect.Bottom] + pop eax + ret +endp + +;;================================================================================================;; +proc gfx.rectangle _ctx, _x1, _y1, _x2, _y2 ;/////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + stdcall gfx.framerect, [_ctx], [_x1], [_y1], [_x2], [_y2] + push [_y2] [_x2] [_y1] [_x1] + inc dword[esp + 0x00] + inc dword[esp + 0x04] + dec dword[esp + 0x08] + dec dword[esp + 0x0C] + stdcall gfx.fillrect, [_ctx] + ret +endp + +;;================================================================================================;; +proc gfx.rectangle.ex _ctx, _rect ;///////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax + mov eax, [_rect] + stdcall gfx.rectangle, [_ctx], [eax + ARect.Left], [eax + ARect.Top], \ + [eax + ARect.Right], [eax + ARect.Bottom] + pop eax + ret +endp + +;;================================================================================================;; +proc gfx.text _ctx, _text, _len, _x, _y ;/////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + ret +endp + +;;================================================================================================;; +proc gfx.text.width _ctx, _text, _len ;///////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + ret +endp + +;;================================================================================================;; +proc gfx.text.height _ctx, _text, _len ;//////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Exported functions section ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +align 16 +@EXPORT: + +export \ + lib_init , 'lib_init' , \ + 0x01000000 , 'version' , \ + gfx.open , 'gfx.open' , \ + gfx.close , 'gfx.close' , \ + gfx.pen.color , 'gfx.pen.color' , \ + gfx.brush.color , 'gfx.brush.color' , \ + gfx.pixel , 'gfx.pixel' , \ + gfx.move.to , 'gfx.move.to' , \ + gfx.line.to , 'gfx.line.to' , \ + gfx.line , 'gfx.line' , \ + gfx.polyline , 'gfx.polyline' , \ + gfx.polyline.to , 'gfx.polyline.to' , \ + gfx.fillrect , 'gfx.fillrect' , \ + gfx.fillrect.ex , 'gfx.fillrect.ex' , \ + gfx.framerect , 'gfx.framerect' , \ + gfx.framerect.ex , 'gfx.framerect.ex' , \ + gfx.rectangle , 'gfx.rectangle' , \ + gfx.rectangle.ex , 'gfx.rectangle.ex' diff --git a/programs/develop/libraries/libs-dev/libgfx/libgfx_p.inc b/programs/develop/libraries/libs-dev/libgfx/libgfx_p.inc new file mode 100644 index 0000000000..06d28fae03 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libgfx/libgfx_p.inc @@ -0,0 +1,42 @@ +;;================================================================================================;; +;;//// libgfx_p.inc //// (c) mike.dld, 2006-2008 /////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +struct APoint + X dd ? + Y dd ? +ends + +struct ARect + Left dd ? + Top dd ? + Right dd ? + Bottom dd ? +ends + +struct AGfxContext + NullPoint APoint + Caret APoint + Pen.Color dd ? + Brush.Color dd ? + Font.Face dd ? + Flags dd ? +ends + +GFX_FLAG_DONT_CLOSE = 00000001b diff --git a/programs/develop/libraries/libs-dev/libimg/bmp/bmp.asm b/programs/develop/libraries/libs-dev/libimg/bmp/bmp.asm new file mode 100644 index 0000000000..48788e74ed --- /dev/null +++ b/programs/develop/libraries/libs-dev/libimg/bmp/bmp.asm @@ -0,0 +1,719 @@ +;;================================================================================================;; +;;//// bmp.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; +;; ;; +;; References: ;; +;; 1. "Microsoft Windows Bitmap File Format Summary" ;; +;; from "Encyclopedia of Graphics File Formats" by O'Reilly ;; +;; http://www.fileformat.info/format/bmp/ ;; +;; ;; +;;================================================================================================;; + + +include 'bmp.inc' + +;;================================================================================================;; +proc img.is.bmp _data, _length ;//////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Determine if raw data could be decoded (is in BMP format) ;; +;;------------------------------------------------------------------------------------------------;; +;> _data = raw data as read from file/stream ;; +;> _length = data length ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;================================================================================================;; + cmp [_length], 2 + jb .nope + mov eax, [_data] + cmp word[eax], 'BM' + je .yep + + .nope: + xor eax, eax + ret + + .yep: + xor eax,eax + inc eax + ret +endp + +;;================================================================================================;; +proc img.decode.bmp _data, _length ;//////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Decode data into image if it contains correctly formed raw data in BMP format ;; +;;------------------------------------------------------------------------------------------------;; +;> _data = raw data as read from file/stream ;; +;> _length = data length ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) or pointer to image ;; +;;================================================================================================;; +locals + img dd ? +endl + + push ebx + + stdcall img.is.bmp, [_data], [_length] + or eax, eax + jz .error + + mov ebx, [_data] +; cmp [ebx + bmp.Header.info.Compression], bmp.BI_RGB +; je @f +; mov eax, [ebx + bmp.Header.file.Size] +; cmp eax, [_length] +; jne .error + + @@: stdcall img.create, [ebx + bmp.Header.info.Width], [ebx + bmp.Header.info.Height] + or eax, eax + jz .error + mov [img], eax + mov edx, eax + + invoke mem.alloc, sizeof.bmp.Image + or eax, eax + jz .error + mov [edx + Image.Extended], eax + mov esi, ebx + add esi, sizeof.bmp.FileHeader + mov edi, eax + mov ecx, sizeof.bmp.InfoHeader + rep movsb + + mov eax, [ebx + bmp.Header.info.Compression] + cmp eax, bmp.BI_RGB + jne @f + stdcall ._.rgb + jmp .decoded + @@: cmp eax, bmp.BI_RLE8 + jne @f + stdcall ._.rle + jmp .decoded + @@: cmp eax, bmp.BI_RLE4 + jne @f + stdcall ._.rle + jmp .decoded + @@: cmp eax, bmp.BI_BITFIELDS + jne @f + stdcall ._.bitfields + jmp .decoded + @@: cmp eax, bmp.BI_JPEG + jne @f + stdcall ._.jpeg + jmp .decoded + @@: cmp eax, bmp.BI_PNG + jne .error + stdcall ._.png + + .decoded: + or eax, eax + jz @f + stdcall img.destroy, [img] + jmp .error + + @@: stdcall img.flip, [img], FLIP_VERTICAL + mov eax, [img] + ret + + .error: + xor eax, eax + pop ebx + ret +endp + +;;================================================================================================;; +proc img.encode.bmp _img, _p_length ;/////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Encode image into raw data in BMP format ;; +;;------------------------------------------------------------------------------------------------;; +;> _img = pointer to image ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) or pointer to encoded data ;; +;< _p_length = encoded data length ;; +;;================================================================================================;; + xor eax, eax + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Below are private procs you should never call directly from your code ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +;;================================================================================================;; +proc img.decode.bmp._.rgb ;///////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = raw image data ;; +;> edx = image data ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + mov ecx, [edx + Image.Extended] + mov [ecx + bmp.Image.info.AlphaMask], 0 + mov edi, [edx + Image.Data] + + movzx eax, [ebx + bmp.Header.info.BitCount] + cmp eax, 32 + je .32bpp + cmp eax, 24 + je .24bpp + cmp eax, 16 + je .16bpp + cmp eax, 8 + je .8bpp + cmp eax, 4 + je .4bpp + cmp eax, 1 + je .1bpp + jmp .error + +;;------------------------------------------------------------------------------------------------;; + +img.decode.bmp._.rgb.32bpp: + mov [ecx + bmp.Image.info.RedMask], 00000000111111110000000000000000b ; 8-0-0 + mov [ecx + bmp.Image.info.GreenMask], 00000000000000001111111100000000b ; 0-8-0 + mov [ecx + bmp.Image.info.BlueMask], 00000000000000000000000011111111b ; 0-0-8 + stdcall img.decode.bmp._.bitfields + ret + +;;------------------------------------------------------------------------------------------------;; + +img.decode.bmp._.rgb.24bpp: + mov esi, ebx + add esi, [ebx + bmp.Header.file.OffBits] + mov ecx, [ebx + bmp.Header.info.Height] + + .next_line: + push ecx + mov ecx, [ebx + bmp.Header.info.Width] + xor edx, edx + + .next_line_pixel: + movsd + dec esi + inc edx + dec ecx + jnz .next_line_pixel + + and edx, 0x03 + add esi, edx + pop ecx + dec ecx + jnz .next_line + + jmp img.decode.bmp._.rgb.exit + +;;------------------------------------------------------------------------------------------------;; + +img.decode.bmp._.rgb.16bpp: + mov [ecx + bmp.Image.info.RedMask], 00000000000000000111110000000000b ; 5-0-0 + mov [ecx + bmp.Image.info.GreenMask], 00000000000000000000001111100000b ; 0-5-0 + mov [ecx + bmp.Image.info.BlueMask], 00000000000000000000000000011111b ; 0-0-5 + stdcall img.decode.bmp._.bitfields + ret + +;;------------------------------------------------------------------------------------------------;; + +img.decode.bmp._.rgb.8bpp: + mov esi, ebx + add esi, [ebx + bmp.Header.file.OffBits] + mov ecx, [ebx + bmp.Header.info.Height] + + .next_line: + push ecx + mov ecx, [ebx + bmp.Header.info.Width] + + .next_line_dword: + lodsb + and eax, 0x000000FF + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + stosd + dec ecx + jnz .next_line_dword + + pop ecx + dec ecx + jnz .next_line + + jmp img.decode.bmp._.rgb.exit + +;;------------------------------------------------------------------------------------------------;; + +img.decode.bmp._.rgb.4bpp: + mov esi, ebx + add esi, [ebx + bmp.Header.file.OffBits] + mov ecx, [ebx + bmp.Header.info.Height] + + .next_line: + push ecx + mov ecx, [ebx + bmp.Header.info.Width] + + .next_line_dword: + push ecx + lodsd + bswap eax + xchg edx, eax + mov ecx, 32 / 4 + + .next_pixel: + rol edx, 4 + mov al, dl + and eax, 0x0000000F + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + stosd + dec dword[esp] + jz @f + dec ecx + jnz .next_pixel + + @@: pop ecx + or ecx, ecx + jnz .next_line_dword + + pop ecx + dec ecx + jnz .next_line + + jmp img.decode.bmp._.rgb.exit + +;;------------------------------------------------------------------------------------------------;; + +img.decode.bmp._.rgb.1bpp: + mov esi, ebx + add esi, [ebx + bmp.Header.file.OffBits] + mov ecx, [ebx + bmp.Header.info.Height] + + .next_line: + push ecx + mov ecx, [ebx + bmp.Header.info.Width] + + .next_line_dword: + push ecx + lodsd + bswap eax + xchg edx, eax + mov ecx, 32 / 1 + + .next_pixel: + rol edx, 1 + mov al, dl + and eax, 0x00000001 + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + stosd + dec dword[esp] + jz @f + dec ecx + jnz .next_pixel + + @@: pop ecx + or ecx, ecx + jnz .next_line_dword + + pop ecx + dec ecx + jnz .next_line + + jmp img.decode.bmp._.rgb.exit + +;;------------------------------------------------------------------------------------------------;; + + img.decode.bmp._.rgb.exit: + xor eax, eax + ret + + img.decode.bmp._.rgb.error: + or eax, -1 + ret +endp + +;;================================================================================================;; +proc img.decode.bmp._.rle ;///////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = raw image data ;; +;> edx = image data ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + scanline_len dd ? + marker_x dd ? + marker_y dd ? + abs_mode_addr dd ? + enc_mode_addr dd ? +endl + + mov edi, [edx + Image.Data] + + mov [abs_mode_addr], .absolute_mode.rle8 + mov [enc_mode_addr], .encoded_mode.rle8 + cmp [ebx + bmp.Header.info.Compression], bmp.BI_RLE4 + jne @f + mov [abs_mode_addr], .absolute_mode.rle4 + mov [enc_mode_addr], .encoded_mode.rle4 + + @@: mov esi, ebx + add esi, [ebx + bmp.Header.file.OffBits] + mov eax, [edx + Image.Width] + shl eax, 2 + mov [scanline_len], eax + xor eax, eax + mov [marker_x], eax + mov [marker_y], eax + + .next_run: + xor eax, eax + lodsb + or al, al + jz .escape_mode + jmp [enc_mode_addr] + + .escape_mode: + lodsb + cmp al, 0 + je .end_of_scanline + cmp al, 1 + je .exit + cmp al, 2 + je .offset_marker + jmp [abs_mode_addr] + + .end_of_scanline: ; 0 + mov eax, [marker_x] + shl eax, 2 + neg eax + add eax, [scanline_len] + add edi, eax + mov [marker_x], 0 + inc [marker_y] + jmp .next_run + + .offset_marker: ; 2: dx, dy + lodsb + mov edx, [marker_x] + add edx, eax + cmp edx, [ebx + bmp.Header.info.Width] + jae .exit + mov [marker_x], edx + shl eax, 2 + add edi, eax + lodsb + and eax, 0x0FF + mov edx, [marker_y] + add edx, eax + cmp edx, [ebx + bmp.Header.info.Height] + jae .exit + mov [marker_y], edx + imul eax, [scanline_len] + add edi, eax + jmp .next_run + + .encoded_mode.rle8: ; N: b1 * N + mov edx, eax + lodsb + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + @@: dec edx + js .fix_marker + stosd + inc [marker_x] + jmp @b + + .absolute_mode.rle8: ; N: b1 .. bN + mov edx, eax + push eax + @@: dec edx + js @f + lodsb + and eax, 0x0FF + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + stosd + inc [marker_x] + jmp @b + @@: pop eax + test eax, 1 + jz .fix_marker + inc esi + jmp .fix_marker + + .encoded_mode.rle4: ; N: b1 * N + mov edx, eax + lodsb + mov ecx, eax + shr ecx, 4 + mov ecx, [ebx + ecx * 4 + bmp.Header.info.Palette] + and eax, 0x00F + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + @@: dec edx + js .fix_marker + test edx, 1 + jz .odd + mov [edi], ecx + add edi, 4 + inc [marker_x] + jmp @b + .odd: + stosd + inc [marker_x] + jmp @b + + .absolute_mode.rle4: ; N: b1 .. bN + mov edx, eax + push eax + @@: dec edx + js @f + lodsb + and eax, 0x0FF + mov ecx, eax + shr eax, 4 + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + stosd + inc [marker_x] + dec edx + js @f + mov eax, ecx + and eax, 0x00F + mov eax, [ebx + eax * 4 + bmp.Header.info.Palette] + stosd + inc [marker_x] + jmp @b + @@: pop eax + and eax, 0x03 + jz .fix_marker + cmp eax, 3 + je .fix_marker + inc esi + jmp .fix_marker + + .fix_marker: + mov eax, [marker_x] + @@: sub eax, [ebx + bmp.Header.info.Width] + jle .next_run + mov [marker_x], eax + inc [marker_y] + jmp @b + + .exit: + xor eax, eax + ret + + .error: + or eax, -1 + ret +endp + +;;================================================================================================;; +proc img.decode.bmp._.bitfields ;/////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = raw image data ;; +;> edx = image data ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + shift bmp.RgbByteQuad + unshift bmp.RgbByteQuad + mask bmp.RgbQuad + delta dd ? +endl + + push esi edi + mov esi, [edx + Image.Extended] + + mov ecx, [esi + bmp.Image.info.RedMask] + call .calc_shift + mov [shift.Red], al + mov [mask.Red], ecx + call .calc_unshift + mov [unshift.Red], al + mov ecx, [esi + bmp.Image.info.GreenMask] + call .calc_shift + mov [shift.Green], al + mov [unshift.Green], al + mov [mask.Green], ecx + call .calc_unshift + mov [unshift.Green], al + mov ecx, [esi + bmp.Image.info.BlueMask] + call .calc_shift + mov [shift.Blue], al + mov [unshift.Blue], al + mov [mask.Blue], ecx + call .calc_unshift + mov [unshift.Blue], al + mov ecx, [esi + bmp.Image.info.AlphaMask] + call .calc_shift + mov [shift.Alpha], al + mov [unshift.Alpha], al + mov [mask.Alpha], ecx + call .calc_unshift + mov [unshift.Alpha], al + + mov edi, [edx + Image.Data] + mov esi, ebx + add esi, [ebx + bmp.Header.file.OffBits] + + mov [delta], 4 + movzx eax, [ebx + bmp.Header.info.BitCount] + cmp eax, 32 + je @f + cmp eax, 16 + jne .error + mov [delta], 2 + +;;------------------------------------------------------------------------------------------------;; + + @@: mov ecx, [edx + Image.Height] + + .next_line: + push ecx + mov ecx, [edx + Image.Width] + + .next_pixel: + push ecx + + mov eax, [esi] + mov cl, [shift.Blue] + shr eax, cl + and eax, [mask.Blue] + mov cl, [unshift.Blue] + shl eax, cl + stosb + + mov eax, [esi] + mov cl, [shift.Green] + shr eax, cl + and eax, [mask.Green] + mov cl, [unshift.Green] + shl eax, cl + stosb + + mov eax, [esi] + mov cl, [shift.Red] + shr eax, cl + and eax, [mask.Red] + mov cl, [unshift.Red] + shl eax, cl + stosb + + mov eax, [esi] + mov cl, [shift.Alpha] + shr eax, cl + and eax, [mask.Alpha] + mov cl, [unshift.Alpha] + shl eax, cl + stosb + + add esi, [delta] + + pop ecx + dec ecx + jnz .next_pixel + + pop ecx + dec ecx + jnz .next_line + +;;------------------------------------------------------------------------------------------------;; + + .exit: + xor eax, eax + pop edi esi + ret + + .error: + or eax, -1 + pop edi esi + ret + +.calc_shift: + xor eax, eax + or ecx, ecx + jnz @f + retn + @@: test ecx, 1 + jnz @f + .zz: shr ecx, 1 + inc eax + jmp @b + @@: test ecx, 0100000000b + jnz .zz + retn +.calc_unshift: + xor eax, eax + or ecx, ecx + jnz @f + retn + @@: test ecx, 1 + jz @f + shr ecx, 1 + inc eax + jmp @b + @@: sub eax, 8 + neg eax + retn +endp + +;;================================================================================================;; +proc img.decode.bmp._.jpeg ;//////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = raw image data ;; +;> edx = image data ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img.decode.bmp._.png ;///////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = raw image data ;; +;> edx = image data ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + xor eax, eax + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Below is private data you should never use directly from your code ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +; diff --git a/programs/develop/libraries/libs-dev/libimg/bmp/bmp.inc b/programs/develop/libraries/libs-dev/libimg/bmp/bmp.inc new file mode 100644 index 0000000000..ea31d6c6f4 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libimg/bmp/bmp.inc @@ -0,0 +1,97 @@ +;;================================================================================================;; +;;//// bmp.inc //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +struct bmp.FileHeader + Type dw ? ; File type, always 4D42h ("BM") + Size dd ? ; Size of the file in bytes + dw 2 dup(?) ; Reserved; must be set to zero. + OffBits dd ? ; Starting position of image data in bytes +ends + +struct bmp.InfoHeader +; v2 (Windows 2.x) + Size dd ? ; Size of this header in bytes + Width dd ? ; Image width in pixels + Height dd ? ; Image height in pixels + Planes dw ? ; Number of color planes + BitCount dw ? ; Number of bits per pixel +; v3 (Windows 3.x) + Compression dd ? ; Compression method used + SizeImage dd ? ; Size of bitmap in bytes + XPelsPerMeter dd ? ; Horizontal resolution in pixels per meter + YPelsPerMeter dd ? ; Vertical resolution in pixels per meter + ClrUsed dd ? ; Number of colors in the image + ClrImportant dd ? ; Minimum number of important colors + union + Palette dd ? ; Image palette if BitCount in [1,4,8] +; v4 (Windows 95) + struct + RedMask dd ? ; Mask identifying bits of red component + GreenMask dd ? ; Mask identifying bits of green component + BlueMask dd ? ; Mask identifying bits of blue component + AlphaMask dd ? ; Mask identifying bits of alpha component + CSType dd ? ; Color space type + RedX dd ? ; X coordinate of red endpoint + RedY dd ? ; Y coordinate of red endpoint + RedZ dd ? ; Z coordinate of red endpoint + GreenX dd ? ; X coordinate of green endpoint + GreenY dd ? ; Y coordinate of green endpoint + GreenZ dd ? ; Z coordinate of green endpoint + BlueX dd ? ; X coordinate of blue endpoint + BlueY dd ? ; Y coordinate of blue endpoint + BlueZ dd ? ; Z coordinate of blue endpoint + GammaRed dd ? ; Gamma red coordinate scale value + GammaGreen dd ? ; Gamma green coordinate scale value + GammaBlue dd ? ; Gamma blue coordinate scale value + ends + ends +ends + +define bmp.BI_RGB 0 +define bmp.BI_RLE8 1 +define bmp.BI_RLE4 2 +define bmp.BI_BITFIELDS 3 +define bmp.BI_JPEG 4 +define bmp.BI_PNG 5 + +struct bmp.Header + file bmp.FileHeader + info bmp.InfoHeader +ends + +struct bmp.RgbByteQuad + Red db ? + Green db ? + Blue db ? + Alpha db ? +ends + +struct bmp.RgbQuad + Red dd ? + Green dd ? + Blue dd ? + Alpha dd ? +ends + +;;------------------------------------------------------------------------------------------------;; + +struct bmp.Image + info bmp.InfoHeader +ends diff --git a/programs/develop/libraries/libs-dev/libimg/bmp/ico.asm b/programs/develop/libraries/libs-dev/libimg/bmp/ico.asm new file mode 100644 index 0000000000..cefc8f19ac --- /dev/null +++ b/programs/develop/libraries/libs-dev/libimg/bmp/ico.asm @@ -0,0 +1,25 @@ +;;================================================================================================;; +;;//// ico.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; +;; ;; +;; References: ;; +;; 1. "Icons in Win32" ;; +;; by John Hornick, Microsoft Corporation ;; +;; http://msdn2.microsoft.com/en-us/library/ms997538.aspx ;; +;; ;; +;;================================================================================================;; diff --git a/programs/develop/libraries/libs-dev/libimg/gif/gif.asm b/programs/develop/libraries/libs-dev/libimg/gif/gif.asm new file mode 100644 index 0000000000..424e216035 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libimg/gif/gif.asm @@ -0,0 +1,564 @@ +;;================================================================================================;; +;;//// gif.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;; +;;================================================================================================;; +;;//// Partial (c) by Willow, Diamond and HidnPlayr //////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; +;; ;; +;; References: ;; +;; 1. GIF LITE v3.0 (2004-2007) ;; +;; by Willow and Diamond ;; +;; svn://kolibrios.org/programs/media/gifview/trunk/gif_lite.inc ;; +;; 2. "GIF File Format Summary" ;; +;; from "Encyclopedia of Graphics File Formats" by O'Reilly ;; +;; http://www.fileformat.info/format/gif/ ;; +;; 3. "LZW and GIF explained" (1987) ;; +;; by Steve Blackstock, IEEE ;; +;; http://www.cis.udel.edu/~amer/CISC651/lzw.and.gif.explained.html ;; +;; 4. "Graphics Interchange Format (tm)" (June 15, 1987) ;; +;; by CompuServe Incorporated ;; +;; http://examples.oreilly.de/english_examples/gff/CDROM/GFF/VENDSPEC/GIF/GIF87A.TXT ;; +;; 5. "Graphics Interchange Format (sm)" (July 31, 1990) ;; +;; by CompuServe Incorporated ;; +;; http://examples.oreilly.de/english_examples/gff/CDROM/GFF/VENDSPEC/GIF/GIF89A.TXT ;; +;; ;; +;;================================================================================================;; + + +include 'gif.inc' + +;;================================================================================================;; +proc img.is.gif _data, _length ;//////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Determine if raw data could be decoded (is in GIF format) ;; +;;------------------------------------------------------------------------------------------------;; +;> _data = raw data as read from file/stream ;; +;> _length = data length ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;================================================================================================;; + cmp [_length], 6 + jb .nope + mov eax, [_data] + cmp dword[eax], 'GIF8' + jne .nope + cmp word[eax + 4], '7a' + je .yep + cmp word[eax + 4], '9a' + je .yep + + .nope: + xor eax, eax + ret + + .yep: + xor eax, eax + inc eax + ret +endp + +;;================================================================================================;; +proc img.decode.gif _data, _length ;//////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Decode data into image if it contains correctly formed raw data in GIF format ;; +;;------------------------------------------------------------------------------------------------;; +;> _data = raw data as read from file/stream ;; +;> _length = data length ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) or pointer to image ;; +;;================================================================================================;; +locals + img dd ? + global_color_table dd ? +endl + + push ebx + + stdcall img.is.gif, [_data], [_length] + or eax, eax + jz .error + + mov ebx, [_data] +; cmp [ebx + bmp.Header.info.Compression], bmp.BI_RGB +; je @f +; mov eax, [ebx + bmp.Header.file.Size] +; cmp eax, [_length] +; jne .error + + test [ebx + gif.Header.lsd.Packed], gif.LSD.Packed.GlobalColorTableFlag + jz @f + lea eax, [ebx + sizeof.gif.Header] + mov [global_color_table], eax + mov cl, [ebx + gif.Header.lsd.Packed] + and cl, gif.LSD.Packed.SizeOfGlobalColorTableMask + shr cl, gif.LSD.Packed.SizeOfGlobalColorTableShift + inc cl + mov eax, 1 + shl eax, cl + lea eax, [eax * 3] + add ebx, eax + @@: add ebx, sizeof.gif.Header + + mov [img], 0 + +; @@: cmp byte[ebx + gif.Block.Introducer], gif.Block.Introducer.Extension +; jne .next_image +; cmp byte[ebx + gif.Extension.Label], gif.Extension.Label.Comment +; jne .error +; add ebx, sizeof.gif.Extension +; stdcall ._.skip_data +; mov ebx, eax +; jmp @b + + .next_image: + stdcall img._.new + or eax, eax + jz .error + mov edx, [img] + mov [eax + Image.Previous], edx + mov [img], eax + mov edx, eax + + mov ecx, sizeof.gif.Image + invoke mem.alloc, ecx + or eax, eax + jz .error + mov [edx + Image.Extended], eax + + stdcall ._.process_extensions + + cmp byte[ebx + gif.Block.Introducer], gif.Block.Introducer.ImageDescriptor + jne .error + movzx eax, [ebx + gif.ImageDescriptor.Width] + movzx ecx, [ebx + gif.ImageDescriptor.Height] + stdcall img._resize_data, [img], eax, ecx + or eax, eax + jz .error + + test [ebx + gif.ImageDescriptor.Packed], gif.ID.Packed.LocalColorTableFlag + jz @f + mov cl, [ebx + gif.ImageDescriptor.Packed] + and cl, gif.ID.Packed.SizeOfLocalColorTableMask + shr cl, gif.ID.Packed.SizeOfLocalColorTableShift + inc cl + mov eax, 1 + shl eax, cl + lea ecx, [eax * sizeof.gif.RgbTriplet] + lea eax, [ecx + sizeof.gif.Image] + invoke mem.realloc, [edx + Image.Extended], eax + or eax, eax + jz .error + mov [edx + Image.Extended], eax + lea esi, [ebx + sizeof.gif.ImageDescriptor] + lea edi, [eax + sizeof.gif.Image] + rep movsb + + @@: mov eax, [global_color_table] + test [ebx + gif.ImageDescriptor.Packed], gif.ID.Packed.LocalColorTableFlag + jz @f + lea eax, [ebx + sizeof.gif.ImageDescriptor] + @@: mov ebx, esi + stdcall ._.process_image, eax + + .decoded: + or eax, eax + jz @f + stdcall img.destroy, [img] + jmp .error + + @@: mov eax, [img] + ret + + .error: + xor eax, eax + pop ebx + ret +endp + +;;================================================================================================;; +proc img.encode.gif _img, _p_length ;/////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Encode image into raw data in GIF format ;; +;;------------------------------------------------------------------------------------------------;; +;> _img = pointer to image ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) or pointer to encoded data ;; +;< _p_length = encoded data length ;; +;;================================================================================================;; + xor eax, eax + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Below are private procs you should never call directly from your code ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +;;================================================================================================;; +proc img.decode.gif._.skip_data ;/////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = pointer to data blocks array ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = pointer to data right after data blocks array ;; +;;================================================================================================;; + push ecx + xor ecx, ecx + @@: mov cl, [esi] + or cl, cl + jz @f + lea esi, [esi + ecx + 1] + jmp @b + @@: pop ecx + ret +endp + +;;================================================================================================;; +proc img.decode.gif._.process_extensions ;////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = raw image data ;; +;> edx = image data ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push edx + mov esi, ebx + + .next_block: + mov al, [esi + gif.Block.Introducer] + cmp al, gif.Block.Introducer.Extension + je .ext_block +; cmp al, gif.Block.Introducer.ImageDescriptor +; je .exit +; cmp al, gif.Block.Introducer.EndOfFile +; je .exit + jmp .exit + + .ext_block: + mov al, [esi + gif.Extension.Label] + cmp al, gif.Extension.Label.PlainText + je .plain_text_ext + cmp al, gif.Extension.Label.GraphicsControl + je .graphics_control_ext + cmp al, gif.Extension.Label.Comment + je .comment_ext + cmp al, gif.Extension.Label.Application + je .application_ext + jmp .exit + + .plain_text_ext: + add esi, gif.PlainTextExtension.PlainTextData + stdcall img.decode.gif._.skip_data + jmp .next_ext_block + + .graphics_control_ext: + push edi + mov edi, [edx + Image.Extended] + add edi, gif.Image.gce + mov ecx, sizeof.gif.GraphicsControlExtension + rep movsb + pop edi + jmp .next_ext_block + + .comment_ext: + add esi, gif.CommentExtension.CommentData + stdcall img.decode.gif._.skip_data + jmp .next_ext_block + + .application_ext: + add esi, gif.ApplicationExtension.ApplicationData + stdcall img.decode.gif._.skip_data + jmp .next_ext_block + + .next_ext_block: + mov al, [ebx + gif.Block.Introducer] + cmp al, gif.Block.Introducer.EndOfData + jne .exit + inc ebx + jmp .next_block + + .exit: + mov ebx, esi + pop edx + ret +endp + +;;================================================================================================;; +proc img.decode.gif._.process_image _color_table ;////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> ebx = raw image data ;; +;> edx = image data ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + width dd ? + img_start dd ? + img_end dd ? + row_end dd ? + pass dd ? + codesize dd ? + compsize dd ? + workarea dd ? + block_ofs dd ? + bit_count dd ? + CC dd ? + EOI dd ? +endl + + invoke mem.alloc, 16 * 1024 + mov [workarea], eax + or eax, eax + jz .error + + mov ecx, [edx + Image.Width] + mov [width], ecx + mov eax, [edx + Image.Height] + imul eax, ecx +; lea eax, [eax * 3] + shl eax, 2 + mov [img_end], eax + inc eax + mov [row_end], eax + and [pass], 0 + mov eax, [edx + Image.Extended] + test [eax + gif.Image.info.Packed], gif.ID.Packed.InterleaceFlag + jz @f +; lea ecx, [ecx * 3] + shl ecx, 2 + mov [row_end], ecx + + @@: mov esi, ebx + mov edi, [edx + Image.Data] + + push edi + movzx ecx, byte[esi] + inc esi + mov [codesize], ecx + inc [codesize] + mov edi, [workarea] + xor eax, eax + lodsb ; eax - block_count + add eax, esi + mov [block_ofs], eax + mov [bit_count], 8 + mov eax, 1 + shl eax, cl + mov [CC], eax + mov ecx, eax + inc eax + mov [EOI], eax + mov eax, gif.Null shl 16 + .filltable: + stosd + inc eax + loop .filltable + pop edi + mov [img_start], edi + add [img_end], edi + add [row_end], edi + .reinit: + mov edx, [EOI] + inc edx + push [codesize] + pop [compsize] + call .get_symbol + cmp eax, [CC] + je .reinit + call .output + .cycle: + movzx ebx, ax + call .get_symbol + cmp eax, edx + jae .notintable + cmp eax, [CC] + je .reinit + cmp eax, [EOI] + je .end + call .output + .add: + mov ecx, [workarea] + mov [ecx + edx * 4], ebx + cmp edx, 0x00000FFF + jae .cycle + inc edx + bsr ebx, edx + cmp ebx, [compsize] + jne .noinc + inc [compsize] + .noinc: + jmp .cycle + .notintable: + push eax + mov eax, ebx + call .output + push ebx + movzx eax, bx + call .output + pop ebx eax + jmp .add + .end: + mov edi, [img_end] + xor eax, eax + + .exit: + cmp [workarea], 0 + je @f + invoke mem.free, [workarea] + @@: xor eax, eax + ret + + .error: + cmp [workarea], 0 + je @f + invoke mem.free, [workarea] + @@: xor eax, eax + inc eax + ret + +;;------------------------------------------------------------------------------------------------;; + +img.decode.gif._.process_image.get_symbol: + mov ecx, [compsize] + push ecx + xor eax, eax + + .shift: + ror byte[esi], 1 + rcr eax,1 + dec [bit_count] + jnz .loop1 + inc esi + cmp esi, [block_ofs] + jb .noblock + push eax + xor eax, eax + lodsb + test eax, eax + jnz .nextbl + mov eax, [EOI] + sub esi, 2 + add esp, 8 + jmp .exit + + .nextbl: + add eax, esi + mov [block_ofs], eax + pop eax + + .noblock: + mov [bit_count], 8 + + .loop1: + loop .shift + pop ecx + rol eax, cl + + .exit: + xor ecx, ecx + retn + +;;------------------------------------------------------------------------------------------------;; + +img.decode.gif._.process_image.output: + push esi eax edx + mov edx, [workarea] + + .next: + pushw [edx + eax * 4] + mov ax, [edx + eax * 4 + 2] + inc ecx + cmp ax, gif.Null + jnz .next + shl ebx, 16 + mov bx, [esp] + + .loop2: + pop ax + + lea esi, [eax * 3] + add esi, [_color_table] + + mov esi, [esi] + bswap esi + shr esi, 8 + mov [edi], esi + add edi, 4 + + cmp edi, [row_end] + jb .norowend + mov eax, [width] +; lea eax, [eax * 3] + shl eax, 2 + push eax + sub edi, eax + add eax, eax + cmp [pass], 3 + je @f + add eax, eax + cmp [pass], 2 + je @f + add eax, eax + @@: add edi, eax + pop eax + cmp edi, [img_end] + jb .nextrow + mov edi, [img_start] + inc [pass] + add edi, eax + cmp [pass], 3 + je @f + add edi, eax + cmp [pass], 2 + je @f + add edi, eax + add edi, eax + @@: + + .nextrow: + add eax, edi + mov [row_end], eax + xor eax, eax + + .norowend: + loop .loop2 + pop edx eax esi + retn + +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Below is private data you should never use directly from your code ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +; diff --git a/programs/develop/libraries/libs-dev/libimg/gif/gif.inc b/programs/develop/libraries/libs-dev/libimg/gif/gif.inc new file mode 100644 index 0000000000..bc3a3928fc --- /dev/null +++ b/programs/develop/libraries/libs-dev/libimg/gif/gif.inc @@ -0,0 +1,137 @@ +;;================================================================================================;; +;;//// gif.inc //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +struct gif.FileHeader ; GIF87a + Signature db 3 dup(?) ; Header Signature (always "GIF") + Version db 3 dup(?) ; GIF format version("87a" or "89a") +ends + +struct gif.LogicalScreenDescriptor ; GIF87a + ScreenWidth dw ? ; Width of Display Screen in Pixels + ScreenHeight dw ? ; Height of Display Screen in Pixels + Packed db ? ; Screen and Color Map Information + BackgroundColor db ? ; Background Color Index + AspectRatio db ? ; Pixel Aspect Ratio +ends + +gif.LSD.Packed.SizeOfGlobalColorTableMask = 000000111b +gif.LSD.Packed.SizeOfGlobalColorTableShift = 0 +gif.LSD.Packed.ColorTableSortFlag = 000001000b +gif.LSD.Packed.ColorTableSortShift = 3 +gif.LSD.Packed.ColorResolutionMask = 001110000b +gif.LSD.Packed.ColorResolutionShift = 4 +gif.LSD.Packed.GlobalColorTableFlag = 010000000b +gif.LSD.Packed.GlobalColorTableShift = 7 + +struct gif.Header + file gif.FileHeader + lsd gif.LogicalScreenDescriptor +ends + +struct gif.RgbTriplet ; GIF87a + Red db ? ; Red Color Element + Green db ? ; Green Color Element + Blue db ? ; Blue Color Element +ends + +struct gif.Block + Introducer db ? +ends + +gif.Block.Introducer.EndOfData = 0x00 +gif.Block.Introducer.Extension = 0x21 +gif.Block.Introducer.ImageDescriptor = 0x2C +gif.Block.Introducer.EndOfFile = 0x3B + +struct gif.ImageDescriptor ; GIF87a + b gif.Block ; Introducer = 2Ch (',') + Left dw ? ; X position of image on the display + Top dw ? ; Y position of image on the display + Width dw ? ; Width of the image in pixels + Height dw ? ; Height of the image in pixels + Packed db ? ; Image and Color Table Data Information +ends + +gif.ID.Packed.SizeOfLocalColorTableMask = 000000111b +gif.ID.Packed.SizeOfLocalColorTableShift = 0 +gif.ID.Packed.SortFlag = 000100000b +gif.ID.Packed.SortShift = 5 +gif.ID.Packed.InterleaceFlag = 001000000b +gif.ID.Packed.InterleaceShift = 6 +gif.ID.Packed.LocalColorTableFlag = 010000000b +gif.ID.Packed.LocalColorTableShift = 7 + +struct gif.Extension + b gif.Block ; Introducer = 21h ('|') + Label db ? ; Extension label +ends + +gif.Extension.Label.PlainText = 0x01 +gif.Extension.Label.GraphicsControl = 0xF9 +gif.Extension.Label.Comment = 0xFE +gif.Extension.Label.Application = 0xFF + +struct gif.PlainTextExtension ; GIF89a + e gif.Extension ; Label = 01h + BlockSize db ? ; Size of Extension Block (always 0Ch) + TextGridLeft dw ? ; X position of text grid in pixels + TextGridTop dw ? ; Y position of text grid in pixels + TextGridWidth dw ? ; Width of the text grid in pixels + TextGridHeight dw ? ; Height of the text grid in pixels + CellWidth db ? ; Width of a grid cell in pixels + CellHeight db ? ; Height of a grid cell in pixels + TextFgColorIndex db ? ; Text foreground color index value + TextBgColorIndex db ? ; Text background color index value + PlainTextData db ? ; The Plain Text data (*) +; Terminator db ? ; Block Terminator (always 0) +ends + +struct gif.GraphicsControlExtension ; GIF89a + e gif.Extension ; Label = F9h + BlockSize db ? ; Size of remaining fields (always 04h) + Packed db ? ; Method of graphics disposal to use + DelayTime dw ? ; Hundredths of seconds to wait + ColorIndex db ? ; Transparent Color Index +; Terminator db ? ; Block Terminator (always 0) +ends + +struct gif.CommentExtension ; GIF89a + e gif.Extension ; Label = FEh + CommentData db ? ; Pointer to Comment Data sub-blocks (*) +; Terminator db ? ; Block Terminator (always 0) +ends + +struct gif.ApplicationExtension ; GIF89a + e gif.Extension ; Label = FFh + BlockSize db ? ; Size of Extension Block (always 0Bh) + Identifier db 8 dup(?) ; Application Identifier + AuthentCode db 3 dup(?) ; Application Authentication Code + ApplicationData db ? ; Point to Application Data sub-blocks (*) +; Terminator db ? ; Block Terminator (always 0) +ends + +;;------------------------------------------------------------------------------------------------;; + +struct gif.Image + gce gif.GraphicsControlExtension + info gif.ImageDescriptor +ends + +gif.Null equ 0x1000 diff --git a/programs/develop/libraries/libs-dev/libimg/libimg.asm b/programs/develop/libraries/libs-dev/libimg/libimg.asm new file mode 100644 index 0000000000..9cef637227 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libimg/libimg.asm @@ -0,0 +1,501 @@ +;;================================================================================================;; +;;//// libimg.asm //// (c) mike.dld, 2007-2008 ///////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +format MS COFF + +public @EXPORT as 'EXPORTS' + +include '../../../../struct.inc' +include '../../../../proc32.inc' +include '../../../../macros.inc' +purge section,mov;add,sub + +include 'libimg.inc' + +section '.flat' code readable align 16 + +include 'bmp/bmp.asm' +include 'gif/gif.asm' + +mem.alloc dd ? +mem.free dd ? +mem.realloc dd ? +dll.load dd ? + +;;================================================================================================;; +proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Library entry point (called after library load) ;; +;;------------------------------------------------------------------------------------------------;; +;> eax = pointer to memory allocation routine ;; +;> ebx = pointer to memory freeing routine ;; +;> ecx = pointer to memory reallocation routine ;; +;> edx = pointer to library loading routine ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 1 (fail) / 0 (ok) (library initialization result) ;; +;;================================================================================================;; + mov [mem.alloc], eax + mov [mem.free], ebx + mov [mem.realloc], ecx + mov [dll.load], edx + + .ok: xor eax,eax + ret +endp + +;;================================================================================================;; +proc img.is_img _data, _length ;//////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push ebx + mov ebx, img._.formats_table + @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length] + or eax, eax + jnz @f + add ebx, sizeof.FormatsTableEntry + cmp dword[ebx], 0 + jnz @b + xor eax, eax + @@: pop ebx + ret +endp + +;;================================================================================================;; +proc img.info _data, _length ;////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img.from_file _filename ;////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to image ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img.to_file _img, _filename ;////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img.from_rgb _rgb_data ;/////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to image ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to rgb_data (array of [rgb] triplets) ;; +;;================================================================================================;; + push esi edi + stdcall img._.validate, [_img] + or eax, eax + jnz .error + + mov esi, [_img] + mov ecx, [esi + Image.Width] + imul ecx, [esi + Image.Height] + lea eax, [ecx * 3 + 4 * 3] + invoke mem.alloc, eax + or eax, eax + jz .error + + mov edi, eax + push eax + mov eax, [esi + Image.Width] + stosd + mov eax, [esi + Image.Height] + stosd + mov esi, [esi + Image.Data] + + @@: dec ecx + js @f + movsd + dec edi + jmp @b + + @@: pop eax + pop edi esi + ret + + .error: + xor eax, eax + pop edi esi + ret +endp + +;;================================================================================================;; +proc img.decode _data, _length ;//////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to image ;; +;;================================================================================================;; + push ebx + mov ebx, img._.formats_table + @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length] + or eax, eax + jnz @f + add ebx, sizeof.FormatsTableEntry + cmp dword[ebx], 0 + jnz @f + jmp .error + @@: stdcall [ebx + FormatsTableEntry.Decode], [_data], [_length] + + .error: + ret +endp + +;;================================================================================================;; +proc img.encode _img, _p_length ;/////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to encoded data ;; +;< [_p_length] = data length ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img.create _width, _height ;/////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to image ;; +;;================================================================================================;; + push ecx + + stdcall img._.new + or eax, eax + jz .error + + push eax + + stdcall img._resize_data, eax, [_width], [_height] + or eax, eax + jz .error.2 + + pop eax + ret + + .error.2: +; pop eax + stdcall img._.delete; eax + xor eax, eax + + .error: + pop ecx + ret +endp + +;;================================================================================================;; +proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;================================================================================================;; + ;TODO: link Next and Previous + stdcall img._.delete, [_img] + ret +endp + +;;================================================================================================;; +proc img._resize_data _img, _width, _height ;/////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push ebx + mov ebx, [_img] + mov eax, [_height] + imul eax, [_width] + shl eax, 2 + invoke mem.realloc, [ebx + Image.Data], eax + or eax, eax + jz .error + + mov [ebx + Image.Data], eax + push [_width] + pop [ebx + Image.Width] + push [_height] + pop [ebx + Image.Height] + + .error: + pop ebx + ret +endp + +;;================================================================================================;; +proc img.lock_bits _img, _start_line, _end_line ;/////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to bits ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img.unlock_bits _img, _lock ;////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;//// image processing //////////////////////////////////////////////////////////////////////////;; + +;;================================================================================================;; +proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;================================================================================================;; +locals + scanline_len dd ? +endl + + push esi edi + stdcall img._.validate, [_img] + or eax, eax + jnz .error + + mov esi, [_img] + mov ecx, [esi + Image.Height] + mov eax, [esi + Image.Width] + shl eax, 2 + mov [scanline_len], eax + + test [_flip_kind], FLIP_VERTICAL + jz .dont_flip_vert + + imul eax, ecx + sub eax, [scanline_len] + shr ecx, 1 + mov esi, [esi + Image.Data] + lea edi, [esi + eax] + + .next_line_vert: + push ecx + + mov ecx, [scanline_len] + @@: lodsd + xchg eax, [edi] + mov [esi - 4], eax + add edi, 4 + add ecx, -4 + jnz @b + + mov eax, [scanline_len] + shl eax, 1 + sub edi, eax + + pop ecx + dec ecx + jnz .next_line_vert + + .dont_flip_vert: + + test [_flip_kind], FLIP_HORIZONTAL + jz .exit + + ;TODO: horz flip code + + .exit: + xor eax, eax + inc eax + pop edi esi + ret + + .error: + xor eax, eax + pop edi esi + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Below are private procs you should never call directly from your code ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +;;================================================================================================;; +proc img._.validate, _img ;///////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + xor eax, eax + ret +endp + +;;================================================================================================;; +proc img._.new ;//////////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 / pointer to image ;; +;;================================================================================================;; + invoke mem.alloc, sizeof.Image + ret +endp + +;;================================================================================================;; +proc img._.delete _img ;//////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;================================================================================================;; + push edx + mov edx, [_img] + cmp [edx + Image.Data], 0 + je @f + invoke mem.free, [edx + Image.Data] + @@: cmp [edx + Image.Extended], 0 + je @f + invoke mem.free, [edx + Image.Extended] + @@: invoke mem.free, edx + pop edx + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Below is private data you should never use directly from your code ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +img._.formats_table: + .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp +; .ico dd img.is.ico, img.decode.ico, img.encode.ico +; .cur dd img.is.cur, img.decode.cur, img.encode.cur + .gif dd img.is.gif, img.decode.gif, img.encode.gif +; .png dd img.is.png, img.decode.png, img.encode.png +; .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg + dd 0 + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Exported functions section ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +align 16 +@EXPORT: + +export \ + lib_init , 'lib_init' , \ + 0x00010001 , 'version' , \ + img.is_img , 'img.is_img' , \ + img.info , 'img.info' , \ + img.from_file , 'img.from_file' , \ + img.to_file , 'img.to_file' , \ + img.from_rgb , 'img.from_rgb' , \ + img.to_rgb , 'img.to_rgb' , \ + img.decode , 'img.decode' , \ + img.encode , 'img.encode' , \ + img.create , 'img.create' , \ + img.destroy , 'img.destroy' , \ + img.lock_bits , 'img.lock_bits' , \ + img.unlock_bits , 'img.unlock_bits' diff --git a/programs/develop/libraries/libs-dev/libimg/libimg.inc b/programs/develop/libraries/libs-dev/libimg/libimg.inc new file mode 100644 index 0000000000..1222fe8354 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libimg/libimg.inc @@ -0,0 +1,39 @@ +;;================================================================================================;; +;;//// libimg.inc //// (c) mike.dld, 2007-2008 ///////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +struct FormatsTableEntry + Is dd ? + Decode dd ? + Encode dd ? +ends + +struct Image + Checksum dd ? ; ((Width ROL 16) OR Height) XOR Data[0] + Width dd ? + Height dd ? + Next dd ? + Previous dd ? + Data dd ? + Extended dd ? +ends + +FLIP_VERTICAL = 0x01 +FLIP_HORIZONTAL = 0x02 +FLIP_BOTH = FLIP_VERTICAL or FLIP_HORIZONTAL diff --git a/programs/develop/libraries/libs-dev/libini/libini.asm b/programs/develop/libraries/libs-dev/libini/libini.asm new file mode 100644 index 0000000000..c3d1ab9c3e --- /dev/null +++ b/programs/develop/libraries/libs-dev/libini/libini.asm @@ -0,0 +1,1151 @@ +;;================================================================================================;; +;;//// libini.asm //// (c) mike.dld, 2006-2008 ///////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; +;; ;; +;; 2008-02-07 (mike.dld) ;; +;; changes: ;; +;; - renamed all *.aux.* to *._.* to match overall libraries design ;; +;; 2007-09-26 (mike.dld) ;; +;; bug-fixes: ;; +;; - value was not correctly trimmed (reported by diamond) ;; +;; 2007-08-01 (mike.dld) ;; +;; bug-fixes: ;; +;; - serious defect in ini.set_str causing displaced write operations ;; +;; (reported by diamond) ;; +;; - another serious defect in ini.enum_keys introduced with refactoring ;; +;; changes: ;; +;; - callback for enum_keys now takes additional parameter - key value ;; +;; - handling trailing spaces in section/key/value ;; +;; 2007-05-19 (mike.dld) ;; +;; bug-fixes: ;; +;; - last char still wasn't read correctly ;; +;; - digits of number were reversed when using ini.set_int ;; +;; - now using 'ini.aux.unget_char' instead of dangerous 'dec esi' ;; +;; changes: ;; +;; - all non-public functions now start with ini.aux.* ;; +;; - added ini.enum_sections and ini.enum_keys ;; +;; - removed ini.query_sec (use ini.enum_* instead) ;; +;; ;; +;;================================================================================================;; + +format MS COFF + +public @EXPORT as 'EXPORTS' + +include '../../../../proc32.inc' +include '../../../../macros.inc' +include '../libio/libio.inc' +purge section ; mov,add,sub + +section '.flat' code readable align 16 + +include 'libini_p.inc' + +mem.alloc dd ? +mem.free dd ? +mem.realloc dd ? +dll.load dd ? + +;;================================================================================================;; +proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Library entry point (called after library load) ;; +;;------------------------------------------------------------------------------------------------;; +;> eax = pointer to memory allocation routine ;; +;> ebx = pointer to memory freeing routine ;; +;> ecx = pointer to memory reallocation routine ;; +;> edx = pointer to library loading routine ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 1 (fail) / 0 (ok) (library initialization result) ;; +;;================================================================================================;; + mov [mem.alloc], eax + mov [mem.free], ebx + mov [mem.realloc], ecx + mov [dll.load], edx + + invoke dll.load, @IMPORT + or eax, eax + jz .ok + + xor eax, eax + inc eax + ret + + .ok: xor eax,eax + ret +endp + +;;================================================================================================;; +proc ini._.unget_char _f ;////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + ;push ecx + ;mov ecx,[f] + ;inc [ecx+INIFILE.cnt] + ;dec esi + ;pop ecx + ;ret + push eax ecx + mov ecx, [_f] + inc [ecx + IniFile.cnt] + dec esi + mov eax, [ecx + IniFile.bsize] + cmp [ecx + IniFile.cnt], eax + jle @f + stdcall ini._.unload_block, [_f] + @@: ;mov al,[esi-1] + pop ecx eax + ret +endp + +;;================================================================================================;; +proc ini._.get_char _f ;//////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + mov ecx, [_f] + dec [ecx + IniFile.cnt] + jns @f + stdcall ini._.preload_block, [_f] + dec [ecx + IniFile.cnt] + @@: lodsb + ret +endp + +;;================================================================================================;; +proc ini._.skip_nonblanks _f ;////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + mov ecx, [_f] + @@: stdcall ini._.get_char, [_f] + cmp al, 32 + je @b + cmp al, 13 + je @b + cmp al, 10 + je @b + cmp al, 9 + je @b + @@: stdcall ini._.unget_char, [_f] + ;inc [ecx+INIFILE.cnt] + ret +endp + +;;================================================================================================;; +proc ini._.skip_spaces _f ;///////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + mov ecx, [_f] + @@: stdcall ini._.get_char, [_f] + cmp al, 32 + je @b + cmp al, 9 + je @b + @@: stdcall ini._.unget_char, [_f] + ;inc [ecx+INIFILE.cnt] + ret +endp + +;;================================================================================================;; +proc ini._.skip_line _f ;/////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + mov ecx, [_f] + @@: stdcall ini._.get_char, [_f] + or al, al + jz @f + cmp al, 13 + je @f + cmp al, 10 + jne @b + @@: stdcall ini._.unget_char, [_f] + ;inc [ecx+INIFILE.cnt] + ret +endp + +;;================================================================================================;; +proc ini._.unload_block _f ;//////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ebx ecx + mov ebx, [_f] + mov eax, [ebx + IniFile.pos] + add eax, -ini.BLOCK_SIZE + invoke file.seek, [ebx + IniFile.fh], SEEK_SET, eax + stdcall ini._.preload_block, ebx + add esi, eax ; ini.BLOCK_SIZE + mov [ebx + IniFile.cnt], 0 + pop ecx ebx eax + ret +endp + +;;================================================================================================;; +proc ini._.preload_block _f ;/////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ebx ecx + mov ebx, [_f] + @@: mov esi, [ebx + IniFile.buf] + push edi + mov edi, esi + mov ecx, ini.BLOCK_SIZE / 4 + xor eax, eax + rep stosd + pop edi + invoke file.tell, [ebx + IniFile.fh] + mov [ebx + IniFile.pos], eax + invoke file.read, [ebx + IniFile.fh], esi, ini.BLOCK_SIZE + mov esi,[ebx + IniFile.buf] + cmp eax,ini.BLOCK_SIZE + jl @f + ;dec eax + @@: mov [ebx + IniFile.cnt], eax;ini.BLOCK_SIZE-1 + mov [ebx + IniFile.bsize], eax + pop ecx ebx eax + ret +endp + +;;================================================================================================;; +proc ini._.reload_block _f ;//////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push eax ebx ecx + mov ebx, [_f] + push [ebx + IniFile.bsize] + push esi [ebx + IniFile.cnt] + invoke file.seek, [ebx + IniFile.fh], SEEK_SET, [ebx + IniFile.pos] + stdcall ini._.preload_block, ebx + pop [ebx + IniFile.cnt] esi + pop eax + sub eax,[ebx + IniFile.bsize] + sub [ebx + IniFile.cnt], eax + pop ecx ebx eax + ret +endp + +; f_info - contains current file block number +; esi - position in block from where to shift +; ecx - number of bytes to shift by + +;;================================================================================================;; +proc ini._.shift_content _f, _delta ;/////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Shift file content starting from cursor position (~ delete) ;; +;? Content is copied by 'delta' bytes up/down ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (ok) / -1 (fail) ;; +;;================================================================================================;; +locals + buf dd ? +endl + + xor eax, eax + cmp [_delta], 0 + je .skip + + push ebx ecx + invoke mem.alloc, ini.BLOCK_SIZE + or eax, eax + jz .fail + mov [buf], eax + + cmp [_delta], 0 + jl .down + + mov ebx, [_f] + mov ecx, [ebx + IniFile.cnt] + mov ebx, [ebx + IniFile.fh] + invoke file.tell, ebx +; push eax + sub eax, ecx +; dec eax + invoke file.seek, ebx, SEEK_SET, eax + @@: invoke file.seek, ebx, SEEK_CUR, [_delta] + invoke file.eof?, ebx + or eax, eax + jnz .done + invoke file.read, ebx, [buf], ini.BLOCK_SIZE + mov ecx, eax + mov eax, [_delta] + neg eax + sub eax,ecx;ini.BLOCK_SIZE + invoke file.seek,ebx,SEEK_CUR,eax + invoke file.write,ebx,[buf],ecx;ini.BLOCK_SIZE + jmp @b + .done: + mov eax, [_delta] + neg eax + invoke file.seek, ebx, SEEK_CUR, eax + invoke file.seteof, ebx +; pop eax +; invoke file.seek, ebx, SEEK_SET;, eax + stdcall ini._.reload_block, [_f] + invoke mem.free, [buf] + pop ecx ebx + .skip: + ret + .fail: + or eax, -1 + pop ecx ebx + ret + + .down: + neg [_delta] + + mov ebx, [_f] + mov ecx, [ebx + IniFile.cnt] + mov ebx, [ebx + IniFile.fh] + invoke file.tell, ebx +; push eax + sub eax, ecx + lea edx, [eax - 1] + push edx + @@: invoke file.seek, ebx, SEEK_SET, edx + invoke file.eof?, ebx + or eax, eax + jnz @f + add edx, ini.BLOCK_SIZE + jmp @b + @@: cmp edx, [esp] + je .skip.2 + add edx, -ini.BLOCK_SIZE + cmp edx, [esp] + jl @f + invoke file.seek, ebx, SEEK_SET, edx + invoke file.read, ebx, [buf], ini.BLOCK_SIZE + mov ecx, eax + mov eax, [_delta] + sub eax, ecx + invoke file.seek, ebx, SEEK_CUR, eax + invoke file.write, ebx, [buf], ecx + jmp @b + @@: + .skip.2: + add esp, 4 +; mov eax,[delta] +; neg eax +; invoke file.seek,ebx,SEEK_CUR,eax +; pop eax +; invoke file.seek,ebx,SEEK_SET;,eax + stdcall ini._.reload_block, [_f] + invoke mem.free, [buf] + pop ecx ebx + ret +endp + +;;================================================================================================;; +proc ini._.get_value_length _f ;//////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push ebx ecx edx eax + mov ebx, [_f] + invoke file.tell, [ebx + IniFile.fh] + push esi [ebx + IniFile.cnt] [ebx + IniFile.pos] + sub eax, [ebx + IniFile.cnt] + mov edx, eax + + stdcall ini._.skip_line, [_f] + invoke file.tell, [ebx + IniFile.fh] + sub eax, [ebx + IniFile.cnt] + sub eax, edx + mov [esp + 4 * 3], eax + +; pop eax + invoke file.seek, [ebx + IniFile.fh], SEEK_SET;, eax + stdcall ini._.preload_block, [_f] + pop [ebx + IniFile.cnt] esi + pop eax edx ecx ebx + ret +endp + +;;================================================================================================;; +proc ini._.string_copy ;//////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + @@: lodsb + or al, al + jz @f + stosb + jmp @b + @@: ret +endp + +;;================================================================================================;; +proc ini._.find_next_section _f ;/////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push ebx edi + + @@: stdcall ini._.skip_nonblanks, [_f] + cmp al, '[' + je @f + or al, al + jz .exit_error + stdcall ini._.skip_line, [_f] + or al, al + jz .exit_error + jmp @b + @@: + pop edi ebx + xor eax, eax + ret + + .exit_error: + pop edi ebx + or eax, -1 + ret +endp + +;;================================================================================================;; +proc ini._.find_section _f, _sec_name ;///////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Find section in file ;; +;? Search is performed from the beginning of file ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (ok) / -1 (fail) ;; +;< [f.pos] = new cursor position (right after ']' char if eax = 0, at the end of file otherwise) ;; +;;================================================================================================;; + push ebx edi + + mov ecx, [_f] + invoke file.seek, [ecx + IniFile.fh], SEEK_SET, 0 + stdcall ini._.preload_block, [_f] + + .next_section: + stdcall ini._.find_next_section, [_f] + or eax, eax + jnz .exit_error + + stdcall ini._.get_char, [_f] +; inc esi +; dec [ecx + IniFile.cnt] + stdcall ini._.skip_spaces, [_f] + mov edi, [_sec_name] + @@: stdcall ini._.get_char, [_f] + cmp al, ']' + je @f + or al, al + jz .exit_error + cmp al, 13 + je .next_section + cmp al, 10 + je .next_section + scasb + je @b + cmp byte[edi - 1], 0 + jne .next_section + dec edi + stdcall ini._.unget_char, [_f] + stdcall ini._.skip_spaces, [_f] + stdcall ini._.get_char, [_f] + cmp al, ']' + jne .next_section + @@: + cmp byte[edi], 0 + jne .next_section + pop edi ebx + xor eax, eax + ret + + .exit_error: + pop edi ebx + or eax, -1 + ret +endp + +;;================================================================================================;; +proc ini._.find_key _f, _key_name ;///////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Find key in section ;; +;? Search is performed within current section starting from cursor position ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (ok) / -1 (fail) ;; +;< [f.pos] = new cursor position (right after '=' char if eax = 0, at the end of file or right ;; +;< before '[' char otherwise) ;; +;;================================================================================================;; + push ebx edi + + .next_value: + mov edi, [_key_name] + stdcall ini._.skip_line, [_f] + stdcall ini._.skip_nonblanks, [_f] + or al, al + jz .exit_error + cmp al, '[' + je .exit_error + @@: stdcall ini._.get_char, [_f] + or al, al + jz .exit_error + cmp al, '=' + je @f + scasb + je @b + cmp byte[edi - 1], 0 + jne .next_value + dec edi + stdcall ini._.unget_char, [_f] + stdcall ini._.skip_spaces, [_f] + stdcall ini._.get_char, [_f] + cmp al, '=' + je @f + jmp .next_value + @@: + cmp byte[edi], 0 + jne .next_value + + pop edi ebx + xor eax, eax + ret + + .exit_error: + pop edi ebx + or eax, -1 + ret +endp + +;;================================================================================================;; +proc ini._.low.read_value _f_addr, _buffer, _buf_len ;////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; + push edi eax + mov edi, [_buffer] + stdcall ini._.skip_spaces, [_f_addr] + @@: dec [_buf_len] + jz @f + stdcall ini._.get_char, [_f_addr] + cmp al, 13 + je @f + cmp al, 10 + je @f + stosb + or al, al + jnz @b + @@: stdcall ini._.unget_char, [_f_addr] + mov byte[edi], 0 + dec edi + @@: cmp byte[edi], 32 + ja @f + mov byte[edi], 0 + dec edi + cmp edi, [_buffer] + jae @b + @@: pop eax edi + ret +endp + +;;================================================================================================;; +proc ini.enum_sections _f_name, _callback ;///////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> _callback = callback function address: func(f_name, sec_name) ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + f IniFile + f_addr dd ? + sec_buf dd ? +endl + + push ebx esi edi + + cld + + invoke mem.alloc, ini.MAX_NAME_LEN + or eax, eax + jz .exit_error.2 + mov [sec_buf], eax + + xor eax, eax + mov [f.fh], eax + mov [f.buf], eax + invoke file.open, [_f_name], O_READ + cmp eax, 32 + jb .exit_error + mov [f.fh], eax + invoke mem.alloc, ini.MEM_SIZE + or eax, eax + jz .exit_error + mov [f.buf], eax + lea ebx, [f] + mov [f_addr], ebx + + invoke file.seek, [f.fh], SEEK_SET, 0 + stdcall ini._.preload_block, [f_addr] + + .next_section: + stdcall ini._.find_next_section, [f_addr] + or eax, eax + jnz .exit_error + + stdcall ini._.get_char, [f_addr] + stdcall ini._.skip_spaces, [f_addr] +; inc esi +; dec [f.cnt] + mov edi, [sec_buf] + @@: stdcall ini._.get_char, [f_addr] + cmp al, ']' + je @f + or al, al + jz .exit_ok + cmp al, 13 + je .next_section + cmp al, 10 + je .next_section + stosb + jmp @b + @@: xor al, al + stosb + add edi, -2 + @@: cmp byte[edi], 32 + ja @f + mov byte[edi], 0 + dec edi + jmp @b + @@: + pushad + mov eax, [f_addr] + stdcall [_callback], [_f_name], [sec_buf] + or eax, eax + popad + jnz .next_section + + .exit_ok: + invoke file.close, [f.fh] + invoke mem.free, [f.buf] + invoke mem.free, [sec_buf] + xor eax, eax + pop edi esi ebx + ret + + .exit_error: + invoke file.close, [f.fh] + invoke mem.free, [f.buf] + invoke mem.free, [sec_buf] + .exit_error.2: + or eax, -1 + pop edi esi ebx + ret +endp + +;;================================================================================================;; +proc ini.enum_keys _f_name, _sec_name, _callback ;////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> _callback = callback function address: func(f_name, sec_name, key_name, key_value) ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + f IniFile + f_addr dd ? + key_buf dd ? + val_buf dd ? +endl + + push ebx esi edi + + cld + + invoke mem.alloc, ini.MAX_NAME_LEN + or eax, eax + jz .exit_error.3 + mov [key_buf], eax + invoke mem.alloc, ini.MAX_VALUE_LEN + or eax, eax + jz .exit_error.2 + mov [val_buf], eax + + xor eax, eax + mov [f.fh], eax + mov [f.buf], eax + invoke file.open, [_f_name], O_READ + cmp eax, 32 + jb .exit_error + mov [f.fh], eax + invoke mem.alloc, ini.MEM_SIZE + or eax, eax + jz .exit_error + mov [f.buf], eax + lea ebx, [f] + mov [f_addr], ebx + stdcall ini._.find_section, ebx, [_sec_name] + or eax, eax + jnz .exit_error + + .next_key: + stdcall ini._.skip_line, [f_addr] + stdcall ini._.skip_nonblanks, [f_addr] + or al, al + jz .exit_error + cmp al, '[' + je .exit_error + mov edi, [key_buf] + @@: stdcall ini._.get_char, [f_addr] + or al, al + jz .exit_error + cmp al, '=' + je @f + stosb + jmp @b + @@: + xor al, al + stosb + add edi, -2 + @@: cmp byte[edi], 32 + ja @f + mov byte[edi], 0 + dec edi + jmp @b + @@: stdcall ini._.low.read_value, [f_addr], [val_buf], ini.MAX_VALUE_LEN + pushad + stdcall [_callback], [_f_name], [_sec_name], [key_buf], [val_buf] + or eax, eax + popad + jnz .next_key + + @@: invoke file.close, [f.fh] + invoke mem.free, [f.buf] + xor eax, eax + stosb + pop edi esi ebx + ret + + .exit_error: + invoke file.close, [f.fh] + invoke mem.free, [f.buf] + invoke mem.free, [val_buf] + .exit_error.2: + invoke mem.free, [key_buf] + .exit_error.3: + or eax, -1 + pop edi esi ebx + ret +endp + +;;================================================================================================;; +proc ini.get_str _f_name, _sec_name, _key_name, _buffer, _buf_len, _def_val ;/////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + f IniFile + f_addr dd ? +endl + + push ebx esi edi + + xor eax, eax + mov [f.fh], eax + mov [f.buf], eax + invoke file.open, [_f_name], O_READ + cmp eax, 32 + jb .exit_error + mov [f.fh], eax + invoke mem.alloc, ini.MEM_SIZE + or eax, eax + jz .exit_error + mov [f.buf], eax + lea ebx, [f] + mov [f_addr], ebx + stdcall ini._.find_section, ebx, [_sec_name] + or eax, eax + jnz .exit_error + + stdcall ini._.find_key, ebx, [_key_name] + or eax, eax + jnz .exit_error + + stdcall ini._.low.read_value, [f_addr], [_buffer], [_buf_len] +; mov edi, [_buffer] +; @@: dec [_buf_len] +; jz @f +; stdcall ini.aux.get_char, [f_addr] +; or al, al +; jz @f +; cmp al, 13 +; je @f +; cmp al, 10 +; je @f +; stosb +; jmp @b + @@: invoke file.close, [f.fh] + invoke mem.free, [f.buf] + xor eax, eax + stosb + pop edi esi ebx + ret + + .exit_error: + invoke file.close, [f.fh] + invoke mem.free, [f.buf] + mov esi, [_def_val] + mov edi, [_buffer] + @@: lodsb + stosb + or al, al + jnz @b + or eax, -1 + pop edi esi ebx + ret +endp + +;;================================================================================================;; +proc ini.set_str _f_name, _sec_name, _key_name, _buffer, _buf_len ;///////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + f IniFile + f_addr dd ? +endl + + push ebx esi edi + + xor eax, eax + mov [f.fh], eax + mov [f.buf], eax + invoke file.open, [_f_name], O_READ + O_WRITE + O_CREATE + cmp eax, 32 + jb .exit_error + mov [f.fh], eax + invoke mem.alloc, ini.MEM_SIZE + or eax, eax + jz .exit_error + mov [f.buf], eax + lea ebx, [f] + mov [f_addr], ebx + + stdcall ini._.find_section, ebx, [_sec_name] + or eax, eax + jnz .create_section + + stdcall ini._.find_key, ebx, [_key_name] + or eax, eax + jnz .create_key + + .modify_key: + + stdcall ini._.get_value_length, [f_addr] + sub eax, [_buf_len] + stdcall ini._.shift_content, [f_addr], eax + + .modify_key.ex: + invoke file.tell, [f.fh] + sub eax, [f.cnt] +; dec eax + invoke file.seek, [f.fh], SEEK_SET, eax + invoke file.write, [f.fh], [_buffer], [_buf_len] + + pop edi esi ebx + xor eax, eax + ret + + .create_key: + mov edi, [f.buf] + add edi, ini.BLOCK_SIZE + push edi + + .create_key.ex: +; mov word[edi], 0x0A0D +; add edi,2 + mov esi, [_key_name] + call ini._.string_copy + mov byte[edi], '=' + inc edi + mov esi, [_buffer] + mov ecx, [_buf_len] + rep movsb + mov word[edi], 0x0A0D + add edi, 2 + mov eax, edi + + pop edi + sub eax, edi + mov [_buffer], edi + mov [_buf_len], eax + neg eax + stdcall ini._.shift_content, [f_addr], eax + + jmp .modify_key.ex + + .create_section: + mov edi, [f.buf] + add edi, ini.BLOCK_SIZE + push edi + + mov esi, [_sec_name] +; mov dword[edi], 0x0A0D + ('[' shl 16) +; add edi, 3 + mov byte[edi], '[' + inc edi + call ini._.string_copy +; mov byte[edi], ']' +; inc edi + mov dword[edi], ']' + (0x0A0D shl 8) + add edi, 3 + + jmp .create_key.ex + + .exit_error: + pop edi esi ebx + or eax, -1 + ret +endp + +;;================================================================================================;; +proc ini.get_int _f_name, _sec_name, _key_name, _def_val ;////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + f IniFile + f_addr dd ? +endl + + push ebx esi edi + + xor eax, eax + mov [f.fh], eax + mov [f.buf], eax + invoke file.open, [_f_name], O_READ + cmp eax, 32 + jb .exit_error + mov [f.fh], eax + invoke mem.alloc, ini.MEM_SIZE + or eax, eax + jz .exit_error + mov [f.buf], eax + lea ebx, [f] + mov [f_addr], ebx + stdcall ini._.find_section, ebx, [_sec_name] + or eax, eax + jnz .exit_error + + stdcall ini._.find_key, ebx, [_key_name] + or eax, eax + jnz .exit_error + + stdcall ini._.skip_nonblanks, [f] + xor eax, eax + xor ebx, ebx + xor edx, edx + stdcall ini._.get_char, [f_addr] + cmp al, '-' + jne .lp1 + inc bh + @@: stdcall ini._.get_char, [f_addr] + .lp1: cmp al, '0' + jb @f + cmp al, '9' + ja @f + inc bl + add eax, -'0' + imul edx, 10 + add edx, eax + jmp @b + @@: + or bl, bl + jz .exit_error + or bh, bh + jz @f + neg edx + @@: invoke file.close, [f.fh] + invoke mem.free, [f.buf] + mov eax, edx + pop edi esi ebx + ret + + .exit_error: + invoke file.close, [f.fh] + invoke mem.free, [f.buf] + mov eax, [_def_val] + pop edi esi ebx + ret +endp + +;;================================================================================================;; +proc ini.set_int _f_name, _sec_name, _key_name, _val ;////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;> --- TBD --- ;; +;;------------------------------------------------------------------------------------------------;; +;< --- TBD --- ;; +;;================================================================================================;; +locals + buf rb 16 +endl + + push ecx edx edi + + lea edi, [buf] + add edi, 15 + mov eax, [_val] + or eax, eax + jns @f + mov byte[edi], '-' + neg eax + inc edi + @@: mov ecx, 10 + @@: xor edx, edx + idiv ecx + add dl, '0' + mov [edi], dl + dec edi + or eax, eax + jnz @b + lea eax, [buf] + add eax, 15 + sub eax, edi + inc edi + + stdcall ini.set_str, [_f_name], [_sec_name], [_key_name], edi, eax + + pop edi edx ecx + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Imported functions section ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +align 16 +@IMPORT: + +library \ + libfile , 'libio.obj' + +import libfile , \ + file.size , 'file.size' , \ ; f_name + file.open , 'file.open' , \ ; f_name f_mode + file.read , 'file.read' , \ ; f_descr buffer buf_len + file.write , 'file.write' , \ ; f_descr buffer buf_len + file.seek , 'file.seek' , \ ; f_descr f_origin f_where + file.eof? , 'file.eof?' , \ ; f_descr + file.seteof , 'file.seteof' , \ ; f_descr + file.tell , 'file.tell' , \ ; f_descr + file.close , 'file.close' ; f_descr + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Exported functions section ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +align 16 +@EXPORT: + +export \ + lib_init , 'lib_init' , \ + 0x00040005 , 'version' , \ + ini.enum_sections , 'ini.enum_sections' , \ + ini.enum_keys , 'ini.enum_keys' , \ + ini.get_str , 'ini.get_str' , \ + ini.get_int , 'ini.get_int' , \ + ini.set_str , 'ini.set_str' , \ + ini.set_int , 'ini.set_int' diff --git a/programs/develop/libraries/libs-dev/libini/libini_p.inc b/programs/develop/libraries/libs-dev/libini/libini_p.inc new file mode 100644 index 0000000000..d8831635f5 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libini/libini_p.inc @@ -0,0 +1,32 @@ +;;================================================================================================;; +;;//// libini_p.inc //// (c) mike.dld, 2007-2008 /////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +ini.MAX_NAME_LEN = 1024 +ini.MAX_VALUE_LEN = 4096 +ini.MEM_SIZE = 4096 +ini.BLOCK_SIZE = ini.MEM_SIZE / 2 + +struct IniFile + fh dd ? + buf dd ? + cnt dd ? + pos dd ? + bsize dd ? +ends diff --git a/programs/develop/libraries/libs-dev/libio/libio.asm b/programs/develop/libraries/libs-dev/libio/libio.asm new file mode 100644 index 0000000000..71762d672e --- /dev/null +++ b/programs/develop/libraries/libs-dev/libio/libio.asm @@ -0,0 +1,803 @@ +;;================================================================================================;; +;;//// libio.asm //// (c) mike.dld, 2006-2008 ////////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; +;; ;; +;; 2007-12-10 (mike.dld) ;; +;; changes: ;; +;; - almost fully incompatible with previous version since return values were changed. ;; +;; now they are more C-like ;; +;; notes: ;; +;; - `file.err` is not yet available ;; +;; 2007-09-26 (mike.dld) ;; +;; changes: ;; +;; - modified `file.size` a bit (according to changes in FileInfo struct) ;; +;; - added `file.find_first`, `file.find_next`, `file.find_close` ;; +;; notes: ;; +;; - `file.aux.match_wildcard` is exported only for testing purposes, don't ;; +;; use it since it may be removed or renamed in next versions ;; +;; ;; +;;================================================================================================;; + + +format MS COFF + +public @EXPORT as 'EXPORTS' + +include '../../../../proc32.inc' +include '../../../../macros.inc' +purge section;mov,add,sub + +include 'libio.inc' +include 'libio_p.inc' + +section '.flat' code readable align 16 + +mem.alloc dd ? +mem.free dd ? +mem.realloc dd ? +dll.load dd ? + +;;================================================================================================;; +proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Library entry point (called after library load) ;; +;;------------------------------------------------------------------------------------------------;; +;> eax = pointer to memory allocation routine ;; +;> ebx = pointer to memory freeing routine ;; +;> ecx = pointer to memory reallocation routine ;; +;> edx = pointer to library loading routine ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 1 (fail) / 0 (ok) (library initialization result) ;; +;;================================================================================================;; + mov [mem.alloc], eax + mov [mem.free], ebx + mov [mem.realloc], ecx + mov [dll.load], edx + xor eax, eax + ret +endp + +;;================================================================================================;; +proc file.aux.match_wildcard _str, _wcard ;///////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Match string against wildcard ;; +;? Based on http://user.cs.tu-berlin.de/~schintke/references/wildcards/ ;; +;? 1997-2001 (c) Florian Schintke ;; +;;------------------------------------------------------------------------------------------------;; +;> _str = pointer to string (filename in most cases) ;; +;> _wcard = pointer to string (mask expressed using wilcards (?, *, [..])) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true (match result) ;; +;;================================================================================================;; + push ecx edx esi edi + mov dl, 1 ; fit + mov esi, [_wcard] + mov edi, [_str] + .loop_wildcard: + mov al, [esi] + or al, al + jz .loop_wildcard_exit + or dl, dl + jz .loop_wildcard_exit + cmp byte[edi], 0 + je .loop_wildcard_exit + + cmp al, '[' + je .process_set + cmp al, '?' + je .process_question + cmp al, '*' + je .process_asterisk + + xor dl, dl + cmp [edi], al + jne @f + inc dl + @@: inc edi + + .loop_wildcard_next: + inc esi + jmp .loop_wildcard + + + .process_set: + inc esi + xor dl, dl ; fit + xor dh, dh ; negation + mov cl, 1 ; at_beginning + cmp byte[esi], '^' + jne .loop_set_wildcard + inc dh + inc esi + + .loop_set_wildcard: + mov al, [esi] + cmp al, ']' + jne @f + or cl, cl + jz .loop_set_wildcard_exit + @@: or dl, dl + jnz .loop_set_wildcard_fit + cmp al, '-' + jne .loop_set_wildcard_not_range + mov ch, [esi - 1] + cmp [esi + 1], ch + jbe .loop_set_wildcard_not_range + cmp byte[esi + 1], ']' + je .loop_set_wildcard_not_range + or cl, cl + jnz .loop_set_wildcard_not_range + cmp [edi], ch + jb .loop_set_wildcard_fit + mov ch, [esi + 1] + cmp [edi], ch + ja .loop_set_wildcard_fit + mov dl, 1 + inc esi + jmp .loop_set_wildcard_fit + + .loop_set_wildcard_not_range: + cmp [edi], al + jne .loop_set_wildcard_fit + mov dl, 1 + + .loop_set_wildcard_fit: + inc esi + xor cl, cl + jmp .loop_set_wildcard + + .loop_set_wildcard_exit: + or dh, dh + jz @f + xor dl, 1 + @@: or dl, dl + jz @f + inc edi + @@: + jmp .loop_wildcard_next + + .process_question: + inc edi + jmp .loop_wildcard_next + + .process_asterisk: + mov dl, 1 + inc esi + + .loop_asterisk_del_shit: + lodsb + cmp byte[edi], 0 + je .loop_asterisk_del_shit_exit + cmp al, '?' + jne @f + inc edi + jmp .loop_asterisk_del_shit + @@: cmp al, '*' + je .loop_asterisk_del_shit + + .loop_asterisk_del_shit_exit: + + @@: cmp al, '*' + jne @f + lodsb + jmp @b + @@: + dec esi + cmp byte[edi], 0 + jne .process_asterisk_skip_exit + xor dl, dl + or al, al + jnz @f + inc dl + @@: dec esi + jmp .loop_wildcard_next + + .process_asterisk_skip_exit: + stdcall file.aux.match_wildcard, edi, esi + or eax, eax + jnz .process_asterisk_not_match + + .loop_asterisk_match: + inc edi + + .loop_asterisk_char_match: + mov al, [esi] + cmp [edi], al + je .loop_asterisk_char_match_exit + cmp byte[esi], '[' + je .loop_asterisk_char_match_exit + cmp byte[edi], 0 + je .loop_asterisk_char_match_exit + inc edi + jmp .loop_asterisk_char_match + + .loop_asterisk_char_match_exit: + cmp byte[edi], 0 + je @f + stdcall file.aux.match_wildcard, edi, esi + or eax, eax + jnz .loop_asterisk_match_exit + jmp .loop_asterisk_match + @@: + xor dl, dl + + .loop_asterisk_match_exit: + + .process_asterisk_not_match: + cmp byte[esi], 0 + jne @f + cmp byte[edi], 0 + jne @f + mov dl, 1 + @@: + dec esi + jmp .loop_wildcard_next + + .loop_wildcard_exit: + or dl, dl + jz .exit + @@: cmp byte[esi], '*' + jne .exit + inc esi + jmp @b + + .exit: + cmp byte[esi], 0 + je @f + xor dl, dl + @@: cmp byte[edi], 0 + je @f + xor dl, dl + @@: + movzx eax, dl + + pop edi esi edx ecx + ret +endp + +;;================================================================================================;; +proc file.aux.find_matching_file _ffb ;///////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Find file with matching attributes (`FindFileBlock.Options.Attributes`) and mask ;; +;? (`FindFileBlock.Options.Mask`) starting from Nth (`FindFileBlock.InfoBlock.Position`) file in ;; +;? directory (`FindFileBlock.InfoBlock.FileName`) ;; +;;------------------------------------------------------------------------------------------------;; +;> _ffb = pointer to FindFileBlock ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) / pointer to `FileInfo` with matched file data ;; +;;================================================================================================;; + push ebx edx + mov edx, [_ffb] + .loop_find: + lea ebx, [edx + FindFileBlock.InfoBlock] + mcall 70 + or eax, eax + jnz .loop_find_error + mov eax, [edx + FindFileBlock.Info.Attributes] + and eax, [edx + FindFileBlock.Options.Attributes] + jz .loop_find_next + lea eax, [edx + FindFileBlock.Info.FileName] + stdcall file.aux.match_wildcard, eax, [edx + FindFileBlock.Options.Mask] + or eax, eax + jnz .loop_find_exit + + .loop_find_next: + inc [edx + FindFileBlock.InfoBlock.Position] + jmp .loop_find + + .loop_find_error: + xor eax, eax + pop edx ebx + ret + + .loop_find_exit: + lea eax, [edx + FindFileBlock.Info] + pop edx ebx + ret +endp + +;;================================================================================================;; +proc file.find_first _dir, _mask, _attr ;/////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Find first file with matching attributes and mask in specified directory ;; +;;------------------------------------------------------------------------------------------------;; +;> _dir = pointer to string (directory path to search in) ;; +;> _mask = pointer to string (file mask, with use of wildcards) ;; +;> _attr = file attributes mask (combination of FA_* constants) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) / pointer to `FileInfo` with matched file data (acts as find descriptor) ;; +;;================================================================================================;; + push ebx edx + + invoke mem.alloc, sizeof.FindFileBlock + or eax, eax + jz .exit.error + mov edx, eax + mov ebx, [_attr] + mov [edx + FindFileBlock.Options.Attributes], ebx + mov ebx, [_mask] + mov [edx + FindFileBlock.Options.Mask], ebx + + lea ebx, [edx + FindFileBlock.InfoBlock] + mov [ebx + FileInfoBlock.Function], F70_READ_D + mov [ebx + FileInfoBlock.Count], 1 + lea eax, [edx + FindFileBlock.Header] + mov [ebx + FileInfoBlock.Buffer], eax + mov eax, [_dir] + mov [ebx + FileInfoBlock.FileName], eax + + stdcall file.aux.find_matching_file, edx + pop edx ebx + ret + + .exit.error: + xor eax, eax + pop edx ebx + ret +endp + +;;================================================================================================;; +proc file.find_next _findd ;//////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Find next file matching criteria ;; +;;------------------------------------------------------------------------------------------------;; +;> _findd = find descriptor (see `file.find_first`) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) / pointer to `FileInfo` with matched file data (acts as find descriptor) ;; +;;================================================================================================;; + mov eax, [_findd] + add eax, -sizeof.FileInfoHeader + inc [eax + FindFileBlock.InfoBlock.Position] + stdcall file.aux.find_matching_file, eax + ret +endp + +;;================================================================================================;; +proc file.find_close _findd ;/////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Close find descriptor and free memory ;; +;;------------------------------------------------------------------------------------------------;; +;> _findd = find descriptor (see `file.find_first`) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = result of memory freeing routine ;; +;;================================================================================================;; + mov eax, [_findd] + add eax, -sizeof.FileInfoHeader + invoke mem.free, eax + ret +endp + +;;================================================================================================;; +proc file.size _name ;////////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Get file size ;; +;;------------------------------------------------------------------------------------------------;; +;> _name = path to file (full or relative) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = -1 (error) / file size (in bytes, up to 2G) ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; +locals + loc_info FileInfoBlock +endl + + lea ebx, [loc_info] + invoke mem.alloc, 40 + push eax + mov [ebx + FileInfoBlock.Function], F70_GETATTR_FD + mov [ebx + FileInfoBlock.Buffer], eax + mov byte[ebx + FileInfoBlock.FileName - 1], 0 + mov eax, [_name] + mov [ebx + FileInfoBlock.FileName], eax + mcall 70 + pop ebx + push eax + mov eax, ebx + mov ebx, [ebx + FileInfo.FileSizeLow] + invoke mem.free, eax + pop eax + ret +endp + +;;================================================================================================;; +proc file.open _name, _mode ;/////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Open file ;; +;;------------------------------------------------------------------------------------------------;; +;> _name = path to file (full or relative) ;; +;> _mode = mode to open file in (combination of O_* constants) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = 0 (error) / file descriptor ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; +locals + loc_info FileInfoBlock + loc_buf rb 40 +endl + + push ebx esi edi + + xor ebx, ebx + invoke mem.alloc, sizeof.InternalFileInfo + or eax, eax + jz .exit_error + mov ebx, eax + push [_mode] + pop [ebx + InternalFileInfo.Mode] + mov [ebx + InternalFileInfo.Position], 0 + lea edi, [ebx + InternalFileInfo.FileName] + mov esi, [_name] + mov ecx, 260 / 4 + cld + rep movsd + + .get_info: + push ebx + mov [loc_info.Function], F70_GETATTR_FD + lea eax, [loc_buf] + mov [loc_info.Buffer], eax + mov byte[loc_info.FileName - 1], 0 + mov eax, [_name] + mov [loc_info.FileName], eax + lea ebx, [loc_info] + mcall 70 + pop ebx + or eax, eax + jz @f + cmp eax, 6 + jne .exit_error.ex + @@: + mov eax, ebx + pop edi esi ebx + ret + + .exit_error.ex: + test [_mode], O_CREATE + jz .exit_error + push ebx + mov [loc_info.Function], F70_CREATE_F + xor eax, eax + mov [loc_info.Position], eax + mov [loc_info.Flags], eax + mov [loc_info.Count], eax + lea ebx, [loc_info] + mcall 70 + pop ebx + or eax, eax + jz .get_info + + .exit_error: + invoke mem.free, ebx + xor eax, eax + pop edi esi ebx + ret +endp + +;;================================================================================================;; +proc file.read _filed, _buf, _buflen ;////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Read data from file ;; +;;------------------------------------------------------------------------------------------------;; +;> _filed = file descriptor (see `file.open`) ;; +;> _buf = pointer to buffer to put read data to ;; +;> _buflen = buffer size (number of bytes to be read from file) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = -1 (error) / number of bytes read ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; +locals + loc_info FileInfoBlock +endl + + push ebx esi edi + + mov ebx, [_filed] + test [ebx + InternalFileInfo.Mode], O_READ + jz .exit_error + + xor eax, eax + mov [loc_info.Function], F70_READ_F + mov [loc_info.Flags], eax + mov byte[loc_info.FileName - 1], al + push [ebx+InternalFileInfo.Position] [_buflen] [_buf] + pop [loc_info.Buffer] [loc_info.Count] [loc_info.Position] + lea eax, [ebx + InternalFileInfo.FileName] + mov [loc_info.FileName], eax + lea ebx, [loc_info] + mcall 70 + or eax, eax + jz @f + cmp eax, 6 + jne .exit_error + @@: + mov eax, ebx + mov ebx, [_filed] + add [ebx + InternalFileInfo.Position], eax + pop edi esi ebx + ret + + .exit_error: + or eax, -1 + pop edi esi ebx + ret +endp + +;;================================================================================================;; +proc file.write _filed, _buf, _buflen ;///////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Write data to file ;; +;;------------------------------------------------------------------------------------------------;; +;> _filed = file descriptor (see `file.open`) ;; +;> _buf = pointer to buffer to get write data from ;; +;> _buflen = buffer size (number of bytes to be written to file) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = -1 (error) / number of bytes written ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; +locals + loc_info FileInfoBlock +endl + + push ebx esi edi + + mov ebx, [_filed] + test [ebx + InternalFileInfo.Mode], O_WRITE + jz .exit_error + + stdcall file.eof?, [_filed] + or eax, eax + js .exit_error + jz @f + stdcall file.truncate, [_filed] + @@: + mov [loc_info.Function], F70_WRITE_F + xor eax, eax + mov [loc_info.Flags], eax + mov byte[loc_info.FileName - 1], al + push [ebx + InternalFileInfo.Position] [_buflen] [_buf] + pop [loc_info.Buffer] [loc_info.Count] [loc_info.Position] + lea eax, [ebx + InternalFileInfo.FileName] + mov [loc_info.FileName], eax + lea ebx, [loc_info] + mcall 70 + or eax, eax + jnz .exit_error + @@: + mov eax, ebx + mov ebx, [_filed] + add [ebx + InternalFileInfo.Position],eax + pop edi esi ebx + ret + + .exit_error: + or eax, -1 + pop edi esi ebx + ret +endp + +;;================================================================================================;; +proc file.seek _filed, _where, _origin ;//////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Set file pointer position ;; +;;------------------------------------------------------------------------------------------------;; +;> _filed = file descriptor (see `file.open`) ;; +;> _where = position in file (in bytes) counted from specified origin ;; +;> _origin = origin from where to set the position (one of SEEK_* constants) ;; +;> SEEK_SET - from beginning of file ;; +;> SEEK_CUR - from current pointer position ;; +;> SEEK_END - from end of file ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = -1 (error) / 0 ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; + push ebx ecx edx + + mov ecx, [_filed] + lea eax, [ecx + InternalFileInfo.FileName] + stdcall file.size, eax + or eax, eax + jnz .exit_error + mov edx, [_where] + cmp [_origin], SEEK_SET + jne .n_set + mov [ecx + InternalFileInfo.Position], edx + jmp .exit_ok + + .n_set: + cmp [_origin], SEEK_CUR + jne .n_cur + add [ecx + InternalFileInfo.Position], edx + jmp .exit_ok + + .n_cur: + cmp [_origin], SEEK_END + jne .exit_error + neg edx + add edx, ebx + mov [ecx + InternalFileInfo.Position], edx + + .exit_ok: + + cmp [ecx + InternalFileInfo.Position], 0 + jge @f + mov [ecx + InternalFileInfo.Position], 0 + @@: +; cmp ebx, [ecx+InternalFileInfo.Position] +; jae @f +; mov [ecx + InternalFileInfo.Position], ebx +; @@: + xor eax, eax + pop edx ecx ebx + ret + + .exit_error: + or eax, -1 + pop edx ecx ebx + ret +endp + +;;================================================================================================;; +proc file.eof? _filed ;///////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Determine if file pointer is at the end of file ;; +;;------------------------------------------------------------------------------------------------;; +;> _filed = file descriptor (see `file.open`) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = false / true ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; + push ebx ecx + + mov ecx, [_filed] + lea eax, [ecx + InternalFileInfo.FileName] + stdcall file.size, eax + or eax, eax + jnz .exit_error + + xor eax, eax + cmp [ecx + InternalFileInfo.Position], ebx + jb @f + inc eax + @@: pop ecx ebx + ret + + .exit_error: + or eax, -1 + pop ecx ebx + ret +endp + +;;================================================================================================;; +proc file.truncate _filed ;///////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Truncate file size to current file pointer position ;; +;;------------------------------------------------------------------------------------------------;; +;> _filed = file descriptor (see `file.open`) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = -1 (error) / 0 ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; +locals + loc_info FileInfoBlock +endl + + push ebx esi edi + + mov ebx, [_filed] + test [ebx + InternalFileInfo.Mode], O_WRITE + jz .exit_error + + mov [loc_info.Function], F70_SETSIZE_F + mov eax, [ebx + InternalFileInfo.Position] + mov [loc_info.Position], eax + xor eax, eax + mov [loc_info.Flags], eax + mov [loc_info.Count], eax + mov [loc_info.Buffer], eax + mov byte[loc_info.FileName - 1], al + lea eax, [ebx + InternalFileInfo.FileName] + mov [loc_info.FileName], eax + lea ebx, [loc_info] + mcall 70 + cmp eax, 2 + je .exit_error + cmp eax, 8 + je .exit_error + @@: xor eax, eax + pop edi esi ebx + ret + + .exit_error: + or eax, -1 + pop edi esi ebx + ret +endp + +file.seteof equ file.truncate + +;;================================================================================================;; +proc file.tell _filed ;///////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Get current file pointer position ;; +;;------------------------------------------------------------------------------------------------;; +;> _filed = file descriptor (see `file.open`) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = -1 (error) / file pointer position ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; + mov eax, [_filed] + mov eax, [eax + InternalFileInfo.Position] + ret +endp + +;;================================================================================================;; +proc file.close _filed ;//////////////////////////////////////////////////////////////////////////;; +;;------------------------------------------------------------------------------------------------;; +;? Close file ;; +;;------------------------------------------------------------------------------------------------;; +;> _filed = file descriptor (see `file.open`) ;; +;;------------------------------------------------------------------------------------------------;; +;< eax = -1 (error) / file pointer position ;; +;;------------------------------------------------------------------------------------------------;; +;# call `file.err` to obtain extended error information ;; +;;================================================================================================;; + mov eax, [_filed] + mov [eax + InternalFileInfo.Mode], 0 + mov [eax + InternalFileInfo.FileName], 0 + invoke mem.free, eax + xor eax, eax + ret +endp + + +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; +;! Exported functions section ;; +;;================================================================================================;; +;;////////////////////////////////////////////////////////////////////////////////////////////////;; +;;================================================================================================;; + + +align 16 +@EXPORT: + +export \ + lib_init , 'lib_init' , \ + 0x00030003 , 'version' , \ + file.find_first , 'file.find_first' , \ + file.find_next , 'file.find_next' , \ + file.find_close , 'file.find_close' , \ + file.size , 'file.size' , \ + file.open , 'file.open' , \ + file.read , 'file.read' , \ + file.write , 'file.write' , \ + file.seek , 'file.seek' , \ + file.tell , 'file.tell' , \ + file.eof? , 'file.eof?' , \ + file.seteof , 'file.seteof' , \ + file.truncate , 'file.truncate' , \ + file.close , 'file.close' diff --git a/programs/develop/libraries/libs-dev/libio/libio.inc b/programs/develop/libraries/libs-dev/libio/libio.inc new file mode 100644 index 0000000000..d94ca37efa --- /dev/null +++ b/programs/develop/libraries/libs-dev/libio/libio.inc @@ -0,0 +1,112 @@ +;;================================================================================================;; +;;//// libio.inc //// (c) mike.dld, 2007-2008 ////////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +O_BINARY = 00000000b +O_READ = 00000001b +O_WRITE = 00000010b +O_CREATE = 00000100b +O_SHARE = 00001000b +O_TEXT = 00010000b + +SEEK_SET = 0 +SEEK_CUR = 1 +SEEK_END = 2 + +struct FileDateTime + union + time dd ? + struct + sec db ? + min db ? + hour db ? + ends + ends + union + date dd ? + struct + day db ? + month db ? + year dw ? + ends + ends +ends + +struct FileInfoBlock + Function dd ? + Position dd ? + Flags dd ? + Count dd ? + Buffer dd ? + db ? + FileName dd ? +ends + +struct FileInfoHeader + Version dd ? + FilesRead dd ? + FilesCount dd ? + rd 5 +ends + +struct FileInfoA + Attributes dd ? + Flags dd ? + DateCreate FileDateTime + DateAccess FileDateTime + DateModify FileDateTime + union + FileSize dq ? + struct + FileSizeLow dd ? + FileSizeHigh dd ? + ends + ends + FileName rb 252 +ends + +struct FileInfoW + Attributes dd ? + Flags dd ? + DateCreate FileDateTime + DateAccess FileDateTime + DateModify FileDateTime + union + FileSize dq ? + struct + FileSizeLow dd ? + FileSizeHigh dd ? + ends + ends + FileName rw 260 +ends + +virtual at 0 + FileInfo FileInfoA + FileInfo fix FileInfoA + sizeof.FileInfo fix sizeof.FileInfoA +end virtual + +FA_READONLY = 00000001b +FA_HIDDEN = 00000010b +FA_SYSTEM = 00000100b +FA_LABEL = 00001000b +FA_FOLDER = 00010000b +FA_ARCHIVED = 00100000b +FA_ANY = 00111111b diff --git a/programs/develop/libraries/libs-dev/libio/libio_p.inc b/programs/develop/libraries/libs-dev/libio/libio_p.inc new file mode 100644 index 0000000000..344b4557f3 --- /dev/null +++ b/programs/develop/libraries/libs-dev/libio/libio_p.inc @@ -0,0 +1,63 @@ +;;================================================================================================;; +;;//// libio_p.inc //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////;; +;;================================================================================================;; +;; ;; +;; This file is part of Common development libraries (Libs-Dev). ;; +;; ;; +;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;; +;; General Public License as published by the Free Software Foundation, either version 3 of the ;; +;; License, or (at your option) any later version. ;; +;; ;; +;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without ;; +;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; +;; General Public License for more details. ;; +;; ;; +;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;; +;; see . ;; +;; ;; +;;================================================================================================;; + + +F70_READ_F = 0 +F70_READ_D = 1 +F70_CREATE_F = 2 +F70_WRITE_F = 3 +F70_SETSIZE_F = 4 +F70_GETATTR_FD = 5 +F70_SETATTR_FD = 6 +F70_START_F = 7 +F70_DELETE_FD = 8 +F70_CREATE_D = 9 + +F70_ERR_OK = 0 +F70_ERR_INVALID_DRIVE_SPEC = 1 +F70_ERR_FUNC_NOT_SUPPORTED = 2 +F70_ERR_UNKNOWN_FS = 3 +F70_ERR_FILE_NOT_FOUND = 5 +F70_ERR_END_OF_FILE = 6 +F70_ERR_INVALID_POINTER = 7 +F70_ERR_NO_DISK_SPACE = 8 +F70_ERR_FAT_CORRUPTED = 9 +F70_ERR_ACCESS_DENIED = 10 +F70_ERR_DEVICE_ERROR = 11 +F70_ERR_NOT_ENOUGH_MEMORY = 30 +F70_ERR_NOT_EXECUTABLE = 31 +F70_ERR_TOO_MANY_PROCESSES = 32 + +struct FindOptions + Attributes dd ? + Mask dd ? +ends + +struct FindFileBlock + Header FileInfoHeader + Info FileInfo + InfoBlock FileInfoBlock + Options FindOptions +ends + +struct InternalFileInfo + Mode dd ? + Position dd ? + FileName rb 260 +ends