diff --git a/programs/other/kpack/trunk/const_var.inc b/programs/other/kpack/trunk/const_var.inc index b70cb86a78..2e83264e91 100644 --- a/programs/other/kpack/trunk/const_var.inc +++ b/programs/other/kpack/trunk/const_var.inc @@ -8,7 +8,7 @@ aCompress db 'COMPRESS',0 aDecompress db 'DECOMPRESS',0 definoutname db 0 defpath db '/RD/1/' -curedit dd 0 +;curedit dd 0 info_str db 'KPack - Kolibri Packer, version 0.13',10 db 'Uses LZMA v4.32 compression library',10,10 @@ -56,4 +56,132 @@ RepNextStates: db 8,8,8,8,8,8,8,11,11,11,11,11 ShortRepNextStates: db 9,9,9,9,9,9,9,11,11,11,11,11 +;--------------------------------------------------------------------- +align 4 +ProcLib_import: +OpenDialog_Init dd aOpenDialog_Init +OpenDialog_Start dd aOpenDialog_Start +;OpenDialog__Version dd aOpenDialog_Version + dd 0 + dd 0 +aOpenDialog_Init db 'OpenDialog_init',0 +aOpenDialog_Start db 'OpenDialog_start',0 +;aOpenDialog_Version db 'Version_OpenDialog',0 +;--------------------------------------------------------------------- +align 4 +Box_lib_import: +edit_box_draw dd aEdit_box_draw +edit_box_key dd aEdit_box_key +edit_box_mouse dd aEdit_box_mouse +version_ed dd aVersion_ed + +option_box_draw dd aOption_box_draw +option_box_mouse dd aOption_box_mouse +version_op dd aVersion_op + +scrollbar_ver_draw dd aScrollbar_ver_draw +scrollbar_ver_mouse dd aScrollbar_ver_mouse +scrollbar_hor_draw dd aScrollbar_hor_draw +scrollbar_hor_mouse dd aScrollbar_hor_mouse +version_scrollbar dd aVersion_scrollbar + +menu_bar_draw dd aMenu_bar_draw +menu_bar_mouse dd aMenu_bar_mouse +version_menu_bar dd aVersion_menu_bar + + dd 0 + dd 0 + +aEdit_box_draw db 'edit_box',0 +aEdit_box_key db 'edit_box_key',0 +aEdit_box_mouse db 'edit_box_mouse',0 +aVersion_ed db 'version_ed',0 + +aOption_box_draw db 'option_box_draw',0 +aOption_box_mouse db 'option_box_mouse',0 +aVersion_op db 'version_op',0 + +aScrollbar_ver_draw db 'scrollbar_v_draw',0 +aScrollbar_ver_mouse db 'scrollbar_v_mouse',0 +aScrollbar_hor_draw db 'scrollbar_h_draw',0 +aScrollbar_hor_mouse db 'scrollbar_h_mouse',0 +aVersion_scrollbar db 'version_scrollbar',0 + +aMenu_bar_draw db 'menu_bar_draw',0 +aMenu_bar_mouse db 'menu_bar_mouse',0 +aVersion_menu_bar db 'version_menu_bar',0 +;--------------------------------------------------------------------- +head_f_i: +head_f_l db 'System error',0 + +err_message_found_lib1 db 'box_lib.obj - Not found!',0 +err_message_found_lib2 db 'proc_lib.obj - Not found!',0 + +err_message_import1 db 'box_lib.obj - Wrong import!',0 +err_message_import2 db 'proc_lib.obj - Wrong import!',0 + +system_dir_Boxlib db '/sys/lib/box_lib.obj',0 +system_dir_ProcLib db '/sys/lib/proc_lib.obj',0 +;--------------------------------------------------------------------- +align 4 +l_libs_start: +; load_library boxlib_name,cur_dir_path,buf_cmd_lin,system_path,\ +; err_message_found_lib,head_f_l,myimport,err_message_import,head_f_i + +library01 l_libs system_dir_Boxlib+9, cur_dir_path, library_path, system_dir_Boxlib, \ +err_message_found_lib1, head_f_l, Box_lib_import, err_message_import1, head_f_i + +library02 l_libs system_dir_ProcLib+9, cur_dir_path, library_path, system_dir_ProcLib, \ +err_message_found_lib2, head_f_l, ProcLib_import, err_message_import2, head_f_i + +load_lib_end: +;--------------------------------------------------------------------- +align 4 +OpenDialog_data: +.type dd 0 +.procinfo dd procinfo ;+4 +.com_area_name dd communication_area_name ;+8 +.com_area dd 0 ;+12 +.opendir_pach dd temp_dir_pach ;+16 +.dir_default_pach dd communication_area_default_pach ;+20 +.start_path dd open_dialog_path ;+24 +.draw_window dd draw_window ;+28 +.status dd 0 ;+32 +.openfile_pach dd fname_buf ;+36 +.filename_area dd filename_area ;+40 +.filter_area dd Filter +.x: +.x_size dw 420 ;+48 ; Window X size +.x_start dw 10 ;+50 ; Window X position +.y: +.y_size dw 320 ;+52 ; Window y size +.y_start dw 10 ;+54 ; Window Y position + +communication_area_name: + db 'FFFFFFFF_open_dialog',0 +open_dialog_path: + db '/sys/File Managers/opendial',0 +communication_area_default_pach: + db '/rd/1',0 + +path4 db '/rd/1/temp',0 + +Filter: +dd Filter.end - Filter.1 +.1: +;db 'BIN',0 +;db 'DAT',0 +.end: +db 0 + +start_temp_file_name: db 'temp.bin',0 + +;--------------------------------------------------------------------- +align 4 +edit1 edit_box 160, 62, 1+22, 0xffffff, 0xff, 0x80ff, 0, 0x8000, 256, inname, mouse_dd, 0, 11,11 +edit2 edit_box 160, 62, 17+22, 0xffffff, 0xff, 0x80ff, 0, 0x8000,256, outname, mouse_dd, 0, 7,7 +edit3 edit_box 160, 62, 33+22, 0xffffff, 0xff, 0x80ff, 0, 0x8000,256, path, mouse_dd, 0, 6,6 +editboxes_end: + +mouse_dd dd 0 ;--------------------------------------------------------------------- \ No newline at end of file diff --git a/programs/other/kpack/trunk/data.inc b/programs/other/kpack/trunk/data.inc index 729458aaf6..136efe0650 100644 --- a/programs/other/kpack/trunk/data.inc +++ b/programs/other/kpack/trunk/data.inc @@ -1,5 +1,4 @@ ;--------------------------------------------------------------------- -;rb 0xD3C ;unknown space area params: rb 256 ;--------------------------------------------------------------------- @@ -7,12 +6,11 @@ color_table rd 10 skinheight rd 1 innamelen rd 1 -inname rb 48 +inname rb 256 ;48 outnamelen rd 1 -outname rb 48 +outname rb 256 ;48 pathlen rd 1 -path rb 48 -curedit_y rd 1 +path rb 256 ;48 message_mem rb 80*20 message_cur_pos rd 1 @@ -45,7 +43,7 @@ fn70start rd 1 fn70size rd 1 fn70zero rd 1 fn70dest rd 1 -fullname rb 100 +fullname rb 256 ;--------------------------------------------------------------------- align 4 @@ -57,6 +55,24 @@ align 4 rb 4096 stacktop: ;--------------------------------------------------------------------- +cur_dir_path: + rb 4096 +;--------------------------------------------------------------------- +library_path: + rb 4096 +;--------------------------------------------------------------------- +temp_dir_pach: + rb 4096 +;--------------------------------------------------------------------- +fname_buf: + rb 4096 +;--------------------------------------------------------------------- +filename_area: + rb 256 +;--------------------------------------------------------------------- +procinfo: + rb 1024 +;--------------------------------------------------------------------- ; Deconpress area align 4 unpack.p rb 0x1F36*4 diff --git a/programs/other/kpack/trunk/kpack.asm b/programs/other/kpack/trunk/kpack.asm index 528e1e7567..38a71b8f4f 100644 --- a/programs/other/kpack/trunk/kpack.asm +++ b/programs/other/kpack/trunk/kpack.asm @@ -16,14 +16,20 @@ use32 dd 1 dd START dd IM_END -memf dd I_END + dd I_END ;memf dd stacktop dd params - dd 0 ;cur_dir_path + dd cur_dir_path ;--------------------------------------------------------------------- include '..\..\..\macros.inc' +include '../../../develop/libraries/box_lib/trunk/box_lib.mac' +include '../../../develop/libraries/box_lib/load_lib.mac' + @use_library START: + mcall 68,11 + mcall 40,100111b + call clear_messages ; set default path = /RD/1/ mov esi,defpath @@ -36,6 +42,7 @@ START: inc ebx mcall mov [skinheight],eax + jmp default ; check command line mov esi,params mov [esi+100h],byte 0 @@ -58,7 +65,7 @@ parse_opt: doit: call draw_window call pack - jmp waitevent + jmp still ;--------------------------------------------------------------------- clear_messages: xor eax,eax @@ -73,17 +80,18 @@ exit: mcall ;-------------------------------------- outeqin: - mov ecx,48/4+1 + mov ecx,256/4+1 mov esi,inname-4 mov edi,outname-4 rep movsd jmp doit ;--------------------------------------------------------------------- default: - mov [curedit],inname - mov ecx,[skinheight] - add ecx,5 - mov [curedit_y],ecx + +load_libraries l_libs_start,load_lib_end + cmp eax,-1 + je exit + mov esi,definoutname mov edi,esi xor ecx,ecx @@ -103,19 +111,42 @@ default: mov edi,outname rep movsb ;--------------------------------------------------------------------- -dodraw: +; mov edi,fname_buf +; mov esi,path4 +; call copy_1 + +;OpenDialog initialisation + push dword OpenDialog_data + call [OpenDialog_Init] +;--------------------------------------------------------------------- + call set_editbox_position_all +;--------------------------------------------------------------------- +red: call draw_window ;-------------------------------------- -waitevent: +still: mcall 10 dec eax - jz dodraw + jz red dec eax - jz keypressed + jz key dec eax - jnz waitevent + jz button + + push dword edit1 + call [edit_box_mouse] + + push dword edit2 + call [edit_box_mouse] + + push dword edit3 + call [edit_box_mouse] + + jmp still +;********************************************************************* +button: ; button pressed mcall 17 xchg al,ah @@ -129,14 +160,14 @@ waitevent: jnz nopack call pack - jmp waitevent + jmp still ;--------------------------------------------------------------------- nopack: dec eax jnz nounpack call unpack - jmp waitevent + jmp still ;--------------------------------------------------------------------- but7: call clear_messages @@ -149,799 +180,92 @@ but7: mov esi,usage_str mov ecx,usage_len call write_string - jmp waitevent + jmp still ;--------------------------------------------------------------------- nounpack: -; this is infile/outfile/path button - call clear_edit_points - mov esi,inname - mov ecx,[skinheight] - add ecx,5 dec eax - jz edit + jnz still - mov esi,outname - add ecx,0Ch - dec eax - jz edit + call OpenDialog_start + jmp still +;********************************************************************* +OpenDialog_start: + push dword OpenDialog_data + call [OpenDialog_Start] + cmp [OpenDialog_data.status],1 + jne @f - mov esi,path - add ecx,0Ch -;-------------------------------------- -edit: - cmp esi,[curedit] - mov [curedit],0 - jz waitevent + mov esi,filename_area + mov edi,inname + call copy_1 + sub edi,inname + mov [innamelen],edi - mov [curedit],esi - mov [curedit_y],ecx - mov al,1 - mov ebx,[esi-4] - mov edi,ebx - imul ebx,6 - add ebx,42h - add ecx,4 - xor edx,edx -;-------------------------------------- + mov esi,filename_area + mov edi,outname + call copy_1 + sub edi,outname + mov [outnamelen],edi + + mov esi,temp_dir_pach + mov edi,path + call copy_1 + sub edi,path + dec edi + mov [pathlen],edi + + call set_editbox_position_all + + call draw_editbox @@: - cmp edi,48 - jz waitevent + ret +;********************************************************************* +copy_1: + xor eax,eax + cld +@@: + lodsb + stosb + test eax,eax + jnz @r + ret +;********************************************************************* +set_editbox_position_all: + mov ebx,inname + mov edi,edit1 + call set_editbox_position - mcall - add ebx,6 - inc edi - jmp @b -;--------------------------------------------------------------------- -keypressed: + mov ebx,outname + mov edi,edit2 + call set_editbox_position + + mov ebx,path + mov edi,edit3 + call set_editbox_position + ret +;********************************************************************* +key: mcall 2 - xchg al,ah - mov edi,[curedit] - test edi,edi - jz waitevent - mov ebx,[edi-4] - cmp al,8 - jz backspace + push dword edit1 + call [edit_box_key] - cmp al,13 - jz onenter + push dword edit2 + call [edit_box_key] - cmp al,20h - jb waitevent + push dword edit3 + call [edit_box_key] - cmp ebx,48 - jz waitevent - - mov [edi+ebx],al - inc ebx - mov [edi-4],ebx -; clear point and draw symbol - lea edi,[edi+ebx-1] - imul ebx,6 - add ebx,40h-6 - shl ebx,16 - mov bl,6 - mov ecx,[curedit_y] - push ecx - shl ecx,16 - mov cl,9 - mcall 13,,,[color_table+20] - pop ecx - mov bx,cx - mcall 4,,[color_table+32],edi,1 - jmp waitevent -;--------------------------------------------------------------------- -backspace: - test ebx,ebx - jz waitevent - - dec ebx - mov [edi-4],ebx -; clear symbol and set point - imul ebx,6 - add ebx,40h - shl ebx,16 - mov bl,6 - mov ecx,[curedit_y] - push ecx - shl ecx,16 - mov cl,9 - mcall 13,,,[color_table+20] - xor edx,edx - shr ebx,16 - inc ebx - inc ebx - pop ecx - add ecx,4 - mcall 1 - jmp waitevent -;--------------------------------------------------------------------- + jmp still +;********************************************************************* onenter: - cmp [curedit],inname - jnz @f +; cmp [curedit],inname +; jnz @f push 2 pop eax jmp nounpack -;--------------------------------------------------------------------- -@@: - cmp [curedit],outname - jnz @f - - call pack - jmp waitevent -;--------------------------------------------------------------------- -@@: - call clear_edit_points - jmp waitevent -;--------------------------------------------------------------------- -pack: - call clear_edit_points - and [curedit],0 -; clear messages - call clear_messages -; display logo - mov esi,info_str - push info_len - pop ecx - call write_string -; load input file - mov esi,inname - call get_full_name - mov ebx,fn70block - mov [ebx],dword 5 - and [ebx+4],dword 0 - and [ebx+8],dword 0 - and [ebx+12],dword 0 - mov [ebx+16],dword file_attr - mcall 70 - test eax,eax - jz inopened -;--------------------------------------------------------------------- -infileerr: - mov esi,errload_str - push errload_len - pop ecx - jmp write_string -;--------------------------------------------------------------------- -inopened: - mov ebx,[insize] - test ebx,ebx - jz infileerr -; maximum memory requests: 2*insize + 2*(maxoutsize+400h) + worksize - mov esi,[memf] - mov [infile],esi - add esi,ebx - mov [inbuftmp],esi - add esi,ebx - mov [outfile],esi - mov [outfile1],esi - mov [outfilebest],esi - mov ecx,ebx - shr ecx,3 - add ecx,ebx - add ecx,400h - add esi,ecx - mov [outfile2],esi - add esi,ecx - mov [workmem],esi - add ecx,ebx - add ecx,ecx - add ecx,[memf] -; LZMA requires 0x448000 + dictsize*9.5 bytes for workmem, - and [lzma_dictsize],0 - push ecx - mov eax,ebx - dec eax - bsr ecx,eax - inc ecx - cmp ecx,28 - jb @f - - mov cl,28 -;-------------------------------------- -@@: - mov edx,ecx - xor eax,eax - inc eax - shl eax,cl - imul eax,19 - shr eax,1 - add eax,448000h - pop ecx - add ecx,eax - mcall 64,1 - test eax,eax - jz mem_ok -;-------------------------------------- -; try to use smaller dictionary -meml0: - cmp edx,4 - jbe memf1 - - dec edx - xor eax,eax - inc eax - mov ecx,edx - shl eax,cl - imul eax,19 - shr eax,1 - add eax,509000h - pop ecx - push ecx - add ecx,eax - mcall 64 - test eax,eax - jnz meml0 -;-------------------------------------- -; ok, say warning and continue - mov [lzma_dictsize],edx - mov esi,lzma_memsmall_str - push lzma_memsmall_len - pop ecx - call write_string - jmp mem_ok -;--------------------------------------------------------------------- -memf1: - mov esi,nomem_str - push nomem_len - pop ecx - jmp write_string -;--------------------------------------------------------------------- -mem_ok: - mov eax,[insize] - mov ebx,fn70block - mov [ebx],byte 0 - mov [ebx+12],eax - mov esi,[infile] - mov [ebx+16],esi - mcall 70 - test eax,eax - jnz infileerr - - mov eax,[outfile] - mov [eax],dword 'KPCK' ;'KCPK' - mov ecx,[insize] - mov [eax+4],dword ecx - mov edi,eax -; set LZMA dictionary size - mov eax,[lzma_dictsize] - test eax,eax - js no_lzma_setds - jnz lzma_setds - - mov ecx,[insize] - dec ecx - bsr eax,ecx - inc eax - cmp eax,28 - jb lzma_setds - - mov eax,28 -;-------------------------------------- -lzma_setds: - push eax - call lzma_set_dict_size -;-------------------------------------- -no_lzma_setds: - push compressing_len - pop ecx - mov esi,compressing_str - call write_string - mov esi,[outfile1] - mov edi,[outfile2] - movsd - movsd - movsd - call pack_lzma - mov [outsize],eax - mov eax,[outfile] - mov [outfilebest],eax - mov [method],use_lzma -;-------------------------------------- -@@: - call preprocess_calltrick - test eax,eax - jz noct1 - - call set_outfile - call pack_lzma - add eax,5 - cmp eax,[outsize] - jae @f - - mov [outsize],eax - mov eax,[outfile] - mov [outfilebest],eax - mov [method],use_lzma or use_calltrick1 -;-------------------------------------- -@@: -noct1: - call set_outfile - push [ctn] - mov al,[cti] - push eax - call preprocess_calltrick2 - test eax,eax - jz noct2 - - call set_outfile - call pack_lzma - add eax,5 - cmp eax,[outsize] - jae @f - - mov [outsize],eax - mov eax,[outfile] - mov [outfilebest],eax - mov [method],use_lzma or use_calltrick2 - pop ecx - pop ecx - push [ctn] - mov al,[cti] - push eax -;-------------------------------------- -@@: -noct2: - pop eax - mov [cti],al - pop [ctn] - add [outsize],12 - mov eax,[outsize] - cmp eax,[insize] - jb packed_ok - - mov esi,too_big_str - push too_big_len - pop ecx - jmp write_string -;--------------------------------------------------------------------- -packed_ok: -; set header - movzx eax,[method] - mov edi,[outfilebest] - mov [edi+8],eax - test al,use_calltrick1 or use_calltrick2 - jz @f - - mov ecx,[outsize] - add ecx,edi - mov eax,[ctn] - mov [ecx-5],eax - mov al,[cti] - mov [ecx-1],al -;-------------------------------------- -@@: - mov eax,[outsize] - mov ecx,100 - mul ecx - div [insize] - aam - xchg al,ah - add ax,'00' - mov [ratio],ax - mov esi,done_str - push done_len - pop ecx - call write_string -;-------------------------------------- -; save output file -saveout: - mov esi,outname - call get_full_name - mov ebx,fn70block - mov [ebx],byte 2 - mov eax,[outfilebest] - mov ecx,[outsize] - mov [ebx+12],ecx - mov [ebx+16],eax - mcall 70 - test eax,eax - jz @f -;-------------------------------------- -outerr: - mov esi,outfileerr_str - push outfileerr_len - pop ecx - jmp write_string -;--------------------------------------------------------------------- -@@: - xor eax,eax - mov ebx,fn70block - mov [ebx],byte 6 - mov [ebx+4],eax - mov [ebx+8],eax - mov [ebx+12],eax - mov [ebx+16],dword file_attr - mcall 70 - ret -;--------------------------------------------------------------------- -set_outfile: - mov eax,[outfilebest] - xor eax,[outfile1] - xor eax,[outfile2] - mov [outfile],eax - ret -;--------------------------------------------------------------------- -pack_calltrick_fail: - xor eax,eax - mov [ctn],0 - ret -;--------------------------------------------------------------------- -preprocess_calltrick: -; input preprocessing - xor eax,eax - mov edi,ct1 - mov ecx,256/4 - push edi - rep stosd - pop edi - mov ecx,[insize] - mov esi,[infile] - xchg eax,edx - mov ebx,[inbuftmp] -;-------------------------------------- -input_pre: - lodsb - sub al,0E8h - cmp al,1 - ja input_pre_cont - - cmp ecx,5 - jb input_pre_done - - lodsd - add eax,esi - sub eax,[infile] - cmp eax,[insize] - jae xxx - - cmp eax,1000000h - jae xxx - - sub ecx,4 -; bswap is not supported on i386 - xchg al,ah - ror eax,16 - xchg al,ah - mov [esi-4],eax - inc edx - mov [ebx],esi - add ebx,4 - jmp input_pre_cont -;--------------------------------------------------------------------- -xxx: - sub esi,4 - movzx eax,byte [esi] - mov [eax+edi],byte 1 -;-------------------------------------- -input_pre_cont: - loop input_pre -;-------------------------------------- -input_pre_done: - mov [ctn],edx - xor eax,eax - mov ecx,256 - repnz scasb - jnz pack_calltrick_fail - - not cl - mov [cti],cl -@@: - cmp ebx,[inbuftmp] - jz @f - - sub ebx,4 - mov eax,[ebx] - mov [eax-4],cl - jmp @b -;--------------------------------------------------------------------- -@@: - mov al,1 - ret -;--------------------------------------------------------------------- -pack_lzma: - mov eax,[outfile] - add eax,11 - push [workmem] ;workmem - push [insize] ;length - push eax ;destination - push [infile] ;source - call lzma_compress - mov ecx,[outfile] - mov edx,[ecx+12] - xchg dl,dh - ror edx,16 - xchg dl,dh - mov [ecx+12],edx - dec eax - ret -;--------------------------------------------------------------------- -preprocess_calltrick2: -; restore input - mov esi,[infile] - mov ecx,[ctn] - jecxz pc2l2 -;-------------------------------------- -pc2l1: - lodsb - sub al,0E8h - cmp al,1 - ja pc2l1 - - mov al,[cti] - cmp [esi],al - jnz pc2l1 - - lodsd - shr ax,8 - ror eax,16 - xchg al,ah - sub eax,esi - add eax,[infile] - mov [esi-4],eax - loop pc2l1 -;-------------------------------------- -pc2l2: -; input preprocessing - mov edi,ct1 - xor eax,eax - push edi - mov ecx,256/4 - rep stosd - pop edi - mov ecx,[insize] - mov esi,[infile] - mov ebx,[inbuftmp] - xchg eax,edx -;-------------------------------------- -input_pre2: - lodsb -;-------------------------------------- -@@: - cmp al,0Fh - jnz ip1 - - dec ecx - jz input_pre_done2 - - lodsb - cmp al,80h - jb @b - - cmp al,90h - jb @f -;-------------------------------------- -ip1: - sub al,0E8h - cmp al,1 - ja input_pre_cont2 -;-------------------------------------- -@@: - cmp ecx,5 - jb input_pre_done2 - - lodsd - add eax,esi - sub eax,[infile] - cmp eax,[insize] - jae xxx2 - - cmp eax,1000000h - jae xxx2 - - sub ecx,4 - xchg al,ah - rol eax,16 - xchg al,ah - mov [esi-4],eax - inc edx - mov [ebx],esi - add ebx,4 - jmp input_pre_cont2 -;--------------------------------------------------------------------- -xxx2: sub esi,4 - movzx eax,byte [esi] - mov [eax+edi],byte 1 -;-------------------------------------- -input_pre_cont2: - loop input_pre2 -;-------------------------------------- -input_pre_done2: - mov [ctn],edx - xor eax,eax - mov ecx,256 - repnz scasb - jnz pack_calltrick_fail - - not cl - mov [cti],cl -;-------------------------------------- -@@: - cmp ebx,[inbuftmp] - jz @f - - sub ebx,4 - mov eax,[ebx] - mov [eax-4],cl - jmp @b -;--------------------------------------------------------------------- -@@: - mov al,1 - ret -;--------------------------------------------------------------------- -unpack: - call clear_edit_points - and [curedit],0 -; clear messages - call clear_messages -; display logo - mov esi,info_str - push info_len - pop ecx - call write_string -; load input file - mov esi,inname - call get_full_name - mov ebx,fn70block - mov [ebx],dword 5 - and [ebx+4],dword 0 - and [ebx+8],dword 0 - and [ebx+12],dword 0 - mov [ebx+16],dword file_attr - mcall 70 - test eax,eax - jnz infileerr - - mov eax,[insize] - test eax,eax - jz infileerr - - mov ecx,[memf] - mov [infile],ecx - add ecx,eax - mov [outfile],ecx - mov [outfilebest],ecx - mcall 64,1 - test eax,eax - jnz memf1 - - mov ebx,fn70block - mov [ebx],byte 0 - mov eax,[insize] - mov [ebx+12],eax - mov esi,[infile] - mov [ebx+16],esi - mcall 70 - test eax,eax - jnz infileerr - - mov eax,[infile] - cmp [eax],dword 'KPCK' - jz @f -;-------------------------------------- -unpack_err: - mov esi,notpacked_str - push notpacked_len - pop ecx - jmp write_string -;--------------------------------------------------------------------- -@@: - mov ecx,[outfile] - add ecx,dword [eax+4] - mcall 64,1 - test eax,eax - jnz memf1 - - mov esi,[infile] - mov eax,[esi+8] - push eax - and al,0C0h - cmp al,0C0h - pop eax - jz unpack_err - - and al,not 0C0h - dec eax - jnz unpack_err - - mov eax,[esi+4] - mov [outsize],eax - push eax - push [outfile] - add esi,11 - push esi - mov eax,[esi+1] - xchg al,ah - ror eax,16 - xchg al,ah - mov [esi+1],eax - call lzma_decompress - mov esi,[infile] - test [esi+8],byte 80h - jnz uctr1 - - test [esi+8],byte 40h - jz udone - - add esi,[insize] - sub esi,5 - lodsd - mov ecx,eax - jecxz udone - - mov dl,[esi] - mov esi,[outfile] -;-------------------------------------- -uc1: - lodsb - sub al,0E8h - cmp al,1 - ja uc1 - - cmp [esi],dl - jnz uc1 - - lodsd - shr ax,8 - ror eax,16 - xchg al,ah - sub eax,esi - add eax,[outfile] - mov [esi-4],eax - loop uc1 - jmp udone -;--------------------------------------------------------------------- -uctr1: - add esi,[insize] - sub esi,5 - lodsd - mov ecx,eax - jecxz udone - - mov dl,[esi] - mov esi,[outfile] -;-------------------------------------- -uc2: - lodsb -;-------------------------------------- -@@: - cmp al,15 - jnz uf - - lodsb - cmp al,80h - jb @b - - cmp al,90h - jb @f -;-------------------------------------- -uf: - sub al,0E8h - cmp al,1 - ja uc2 -;-------------------------------------- -@@: - cmp [esi],dl - jnz uc2 - - lodsd - shr ax,8 - ror eax,16 - xchg al,ah - sub eax,esi - add eax,[outfile] - mov [esi-4],eax - loop uc2 -;-------------------------------------- -udone: - mov esi,unpacked_ok - push unpacked_len - pop ecx - call write_string - jmp saveout - -;--------------------------------------------------------------------- +;********************************************************************* get_full_name: push esi mov esi,path @@ -967,10 +291,7 @@ get_full_name: xor eax,eax stosb ret -;--------------------------------------------------------------------- -wsret: - ret -;--------------------------------------------------------------------- +;********************************************************************* write_string: ; in: esi=pointer, ecx=length mov edx,[message_cur_pos] @@ -1033,51 +354,110 @@ draw_messages: jb @b ret -;--------------------------------------------------------------------- +;********************************************************************* draw_window: ; start redraw mcall 12,1 mov edi,[skinheight] +;-------------------------------------- ; define window xor eax,eax mov ecx,100 shl 16+286 add ecx,edi mov edx,[color_table+20] add edx,13000000h - push edi +; push edi xor esi,esi - mcall ,<100,435>,,,,caption_str - pop edi + mcall ,<100,435>,,,,fullname ;temp_dir_pach ;caption_str +; pop edi + mcall 9,procinfo,-1 +;-------------------------------------- +; draw lines and frame + call draw_lines +; draw buttons + call draw_bittons +; infile, outfile, path strings +; call draw_strings +; draw messages + call draw_messages +; draw editbox's + mov eax,[procinfo+42] + sub eax,65+72+10 + mov [edit1.width],eax ; устанавливаем ширину текстовых полей + mov [edit2.width],eax + mov [edit3.width],eax + + call draw_editbox +; end redraw + mcall 12,2 + ret +;********************************************************************* +draw_editbox: + push dword edit1 + call [edit_box_draw] + push dword edit2 + call [edit_box_draw] + push dword edit3 + call [edit_box_draw] + ret +;********************************************************************* +set_editbox_position: + mov esi,ebx + cld +@@: + lodsb + test al,al + jne @r + sub esi,ebx + mov eax,esi + dec eax + mov [edi+48], eax ;ed_size + mov [edi+52], eax ;ed_pos + ret +;********************************************************************* +draw_lines: +; mov edi,[skinheight] ; lines - horizontal - mov ebx,8 shl 16+352 +; mov ebx,8 shl 16+352 +; mov ecx,edi +; shl ecx,16 +; or ecx,edi +; add ecx,2 shl 16+2 +; mcall 38,,,[color_table+36] +; mov esi,3 +;@@: +; add ecx,12 shl 16+12 +; mcall +; dec esi +; jnz @r +;-------------------------------------- +; lines - vertical +; sub ecx,36 shl 16 +; mcall ,<8,8> +; add ebx,52 shl 16+52 +; mcall +; add ebx,292 shl 16+292 +; mcall +;-------------------------------------- + mov edi,[skinheight] mov ecx,edi shl ecx,16 or ecx,edi - add ecx,2 shl 16+2 - mcall 38,,,[color_table+36] - add ecx,12 shl 16+12 - mcall - add ecx,12 shl 16+12 - mcall - add ecx,12 shl 16+12 - mcall -; lines - vertical - sub ecx,36 shl 16 - mcall ,<8,8> - add ebx,52 shl 16+52 - mcall - add ebx,292 shl 16+292 - mcall + add ecx,2 shl 16+2+12*3 +; add ecx,12*3 ; draw frame for messages data push ecx add ecx,52 shl 16+16 - mcall ,<8,425> + mcall 38,<8,425>,,[color_table+36] add ecx,224*(1 shl 16+1) mcall sub cx,224 mcall ,<8,8> mcall ,<426,426> pop ecx + ret +;********************************************************************* +draw_bittons: ; define compress button mov cx,18 mcall 8,<354,72>,,2,[color_table+36] @@ -1093,22 +473,24 @@ draw_window: shr ecx,16 lea ebx,[ecx+1A40002h] mcall 4,,[color_table+28],aQuestion,1 - mov al,8 +; mov al,8 pop esi ; define settings buttons - mov ebx,9 shl 16+50 +; mov ebx,9 shl 16+50 lea ecx,[edi+2] + add ecx,16*2 shl ecx,16 - mov cx,11 - push 4 - pop edx + mov cx,13 +; push 4 +; pop edx ;-------------------------------------- -@@: - mcall - add ecx,12 shl 16 - inc edx - cmp edx,6 - jbe @b +;@@: +; mcall +; add ecx,12 shl 16 +; inc edx +; cmp edx,6 +; jbe @b + mcall 8,<9,50>,,4 ; text on settings buttons lea ebx,[edi+5+0C0000h] mov al,4 @@ -1121,7 +503,7 @@ draw_window: @@: mcall add edx,esi - add ebx,12 + add ebx,16 cmp [edx-6],byte ' ' jnz @b ; text on compress and decompress buttons @@ -1130,52 +512,10 @@ draw_window: mcall ,,,aCompress lea ebx,[edi+1Ah+16A0000h] mcall ,,,aDecompress -; infile, outfile, path strings - mov edx,inname - lea ebx,[edi+400005h] -;-------------------------------------- -editdraw: - mcall 4,,[color_table+32],,[edx-4] - cmp edx,[curedit] - jnz cont - - mov al,1 - push ebx - push edx - movzx ecx,bx - shr ebx,16 - lea edx,[esi*2] - lea edx,[edx+edx*2] - lea ebx,[ebx+edx+2] - add ecx,4 - xor edx,edx -;-------------------------------------- -@@: - cmp esi,48 - jz @f - - mcall - add ebx,6 - inc esi - jmp @b -;--------------------------------------------------------------------- -@@: - pop edx - pop ebx -;-------------------------------------- -cont: - add edx,52 - add ebx,0Ch - cmp edx,path+52 - jb editdraw -; draw messages - call draw_messages -; end redraw - mcall 12,2 ret -;--------------------------------------------------------------------- +;********************************************************************* copy_name: - lea edx,[edi+48] + lea edx,[edi+256] ;-------------------------------------- @@: lodsb @@ -1193,7 +533,7 @@ copy_name: ;-------------------------------------- copy_name_done: dec esi - sub edx,48 + sub edx,256 sub edi,edx mov [edx-4],edi ;-------------------------------------- @@ -1208,29 +548,12 @@ skip_spaces: @@: dec esi ret +;********************************************************************* +;Pack procedures +include 'packpoc.inc' ;--------------------------------------------------------------------- -clear_edit_points: -; clear edit points (if is) - mov esi,[curedit] - test esi,esi - jz cleared_edit_points - - push eax - mov ebx,[esi-4] - imul ebx,6 - mov edi,ebx - add ebx,40h - shl ebx,16 - add ebx,48*6 - sub bx,di - mov ecx,[curedit_y] - shl ecx,16 - or cx,9 - mcall 13,,,[color_table+20] - pop eax -;-------------------------------------- -cleared_edit_points: - ret +;UnPack procedures +include 'upacproc.inc' ;--------------------------------------------------------------------- ;lzma_compress: include 'lzma_compress.inc' diff --git a/programs/other/kpack/trunk/packpoc.inc b/programs/other/kpack/trunk/packpoc.inc new file mode 100644 index 0000000000..1e8dc7e929 --- /dev/null +++ b/programs/other/kpack/trunk/packpoc.inc @@ -0,0 +1,512 @@ +;********************************************************************* +pack: +; call clear_edit_points +; and [curedit],0 +; clear messages + call clear_messages +; display logo + mov esi,info_str + push info_len + pop ecx + call write_string +; load input file + mov esi,inname + call get_full_name + mov ebx,fn70block + mov [ebx],dword 5 + and [ebx+4],dword 0 + and [ebx+8],dword 0 + and [ebx+12],dword 0 + mov [ebx+16],dword file_attr + mcall 70 + test eax,eax + jz inopened +;--------------------------------------------------------------------- +infileerr: + call return_memory + mov esi,errload_str + push errload_len + pop ecx + jmp write_string +;--------------------------------------------------------------------- +inopened: + mov ebx,[insize] + test ebx,ebx + jz infileerr +; maximum memory requests: 2*insize + 2*(maxoutsize+400h) + worksize +; mov esi,[memf] + xor esi,esi +; mov [infile],esi + add esi,ebx + mov [inbuftmp],esi + add esi,ebx + mov [outfile],esi + mov [outfile1],esi + mov [outfilebest],esi + + mov ecx,ebx + shr ecx,3 + add ecx,ebx + add ecx,400h + add esi,ecx + mov [outfile2],esi + add esi,ecx + mov [workmem],esi + add ecx,ebx + add ecx,ecx +; add ecx,[memf] +; LZMA requires 0x448000 + dictsize*9.5 bytes for workmem, + and [lzma_dictsize],0 + push ecx + mov eax,ebx + dec eax + bsr ecx,eax + inc ecx + cmp ecx,28 + jb @f + + mov cl,28 +;-------------------------------------- +@@: + mov edx,ecx + xor eax,eax + inc eax + shl eax,cl + imul eax,19 + shr eax,1 + add eax,448000h + pop ecx + add ecx,eax +; mcall 64,1 + +; test eax,eax +; jz mem_ok + + mcall 68,12 + + mov [infile],eax + add [inbuftmp],eax + add [outfile],eax + add [outfile1],eax + add [outfilebest],eax + add [outfile2],eax + add [workmem],eax +;-------------------------------------- +; try to use smaller dictionary +;meml0: +; cmp edx,4 +; jbe memf1 +; +; dec edx +; xor eax,eax +; inc eax +; mov ecx,edx +; shl eax,cl +; imul eax,19 +; shr eax,1 +; add eax,509000h +; pop ecx +; push ecx +; add ecx,eax +; mcall 64 +; test eax,eax +; jnz meml0 +;-------------------------------------- +; ok, say warning and continue +; mov [lzma_dictsize],edx +; mov esi,lzma_memsmall_str +; push lzma_memsmall_len +; pop ecx +; call write_string +; jmp mem_ok +;--------------------------------------------------------------------- +;memf1: +; mov esi,nomem_str +; push nomem_len +; pop ecx +; jmp write_string +;--------------------------------------------------------------------- +mem_ok: + mov eax,[insize] + mov ebx,fn70block + mov [ebx],byte 0 + mov [ebx+12],eax + mov esi,[infile] + mov [ebx+16],esi + mcall 70 + test eax,eax + jnz infileerr + + mov eax,[outfile] + mov [eax],dword 'KPCK' ;'KCPK' + mov ecx,[insize] + mov [eax+4],dword ecx + mov edi,eax +; set LZMA dictionary size + mov eax,[lzma_dictsize] + test eax,eax + js no_lzma_setds + jnz lzma_setds + + mov ecx,[insize] + dec ecx + bsr eax,ecx + inc eax + cmp eax,28 + jb lzma_setds + + mov eax,28 +;-------------------------------------- +lzma_setds: + push eax + call lzma_set_dict_size +;-------------------------------------- +no_lzma_setds: + push compressing_len + pop ecx + mov esi,compressing_str + call write_string + mov esi,[outfile1] + mov edi,[outfile2] + movsd + movsd + movsd + call pack_lzma + mov [outsize],eax + mov eax,[outfile] + mov [outfilebest],eax + mov [method],use_lzma +;-------------------------------------- +@@: + call preprocess_calltrick + test eax,eax + jz noct1 + + call set_outfile + call pack_lzma + add eax,5 + cmp eax,[outsize] + jae @f + + mov [outsize],eax + mov eax,[outfile] + mov [outfilebest],eax + mov [method],use_lzma or use_calltrick1 +;-------------------------------------- +@@: +noct1: + call set_outfile + push [ctn] + mov al,[cti] + push eax + call preprocess_calltrick2 + test eax,eax + jz noct2 + + call set_outfile + call pack_lzma + add eax,5 + cmp eax,[outsize] + jae @f + + mov [outsize],eax + mov eax,[outfile] + mov [outfilebest],eax + mov [method],use_lzma or use_calltrick2 + pop ecx + pop ecx + push [ctn] + mov al,[cti] + push eax +;-------------------------------------- +@@: +noct2: + pop eax + mov [cti],al + pop [ctn] + add [outsize],12 + mov eax,[outsize] + cmp eax,[insize] + jb packed_ok + + mov esi,too_big_str + push too_big_len + pop ecx + jmp write_string +;--------------------------------------------------------------------- +packed_ok: +; set header + movzx eax,[method] + mov edi,[outfilebest] + mov [edi+8],eax + test al,use_calltrick1 or use_calltrick2 + jz @f + + mov ecx,[outsize] + add ecx,edi + mov eax,[ctn] + mov [ecx-5],eax + mov al,[cti] + mov [ecx-1],al +;-------------------------------------- +@@: + mov eax,[outsize] + mov ecx,100 + mul ecx + div [insize] + aam + xchg al,ah + add ax,'00' + mov [ratio],ax + mov esi,done_str + push done_len + pop ecx + call write_string +;-------------------------------------- +; save output file +saveout: + mov esi,outname + call get_full_name + mov ebx,fn70block + mov [ebx],byte 2 + mov eax,[outfilebest] + mov ecx,[outsize] + mov [ebx+12],ecx + mov [ebx+16],eax + mcall 70 + test eax,eax + jz @f +;-------------------------------------- +outerr: + mov esi,outfileerr_str + push outfileerr_len + pop ecx + jmp write_string +;--------------------------------------------------------------------- +@@: + xor eax,eax + mov ebx,fn70block + mov [ebx],byte 6 + mov [ebx+4],eax + mov [ebx+8],eax + mov [ebx+12],eax + mov [ebx+16],dword file_attr + mcall 70 + + call return_memory + ret +;--------------------------------------------------------------------- +set_outfile: + mov eax,[outfilebest] + xor eax,[outfile1] + xor eax,[outfile2] + mov [outfile],eax + ret +;--------------------------------------------------------------------- +pack_calltrick_fail: + xor eax,eax + mov [ctn],0 + ret +;--------------------------------------------------------------------- +preprocess_calltrick: +; input preprocessing + xor eax,eax + mov edi,ct1 + mov ecx,256/4 + push edi + rep stosd + pop edi + mov ecx,[insize] + mov esi,[infile] + xchg eax,edx + mov ebx,[inbuftmp] +;-------------------------------------- +input_pre: + lodsb + sub al,0E8h + cmp al,1 + ja input_pre_cont + + cmp ecx,5 + jb input_pre_done + + lodsd + add eax,esi + sub eax,[infile] + cmp eax,[insize] + jae xxx + + cmp eax,1000000h + jae xxx + + sub ecx,4 +; bswap is not supported on i386 + xchg al,ah + ror eax,16 + xchg al,ah + mov [esi-4],eax + inc edx + mov [ebx],esi + add ebx,4 + jmp input_pre_cont +;--------------------------------------------------------------------- +xxx: + sub esi,4 + movzx eax,byte [esi] + mov [eax+edi],byte 1 +;-------------------------------------- +input_pre_cont: + loop input_pre +;-------------------------------------- +input_pre_done: + mov [ctn],edx + xor eax,eax + mov ecx,256 + repnz scasb + jnz pack_calltrick_fail + + not cl + mov [cti],cl +@@: + cmp ebx,[inbuftmp] + jz @f + + sub ebx,4 + mov eax,[ebx] + mov [eax-4],cl + jmp @b +;--------------------------------------------------------------------- +@@: + mov al,1 + ret +;--------------------------------------------------------------------- +pack_lzma: + mov eax,[outfile] + add eax,11 + push [workmem] ;workmem + push [insize] ;length + push eax ;destination + push [infile] ;source + call lzma_compress + mov ecx,[outfile] + mov edx,[ecx+12] + xchg dl,dh + ror edx,16 + xchg dl,dh + mov [ecx+12],edx + dec eax + ret +;--------------------------------------------------------------------- +preprocess_calltrick2: +; restore input + mov esi,[infile] + mov ecx,[ctn] + jecxz pc2l2 +;-------------------------------------- +pc2l1: + lodsb + sub al,0E8h + cmp al,1 + ja pc2l1 + + mov al,[cti] + cmp [esi],al + jnz pc2l1 + + lodsd + shr ax,8 + ror eax,16 + xchg al,ah + sub eax,esi + add eax,[infile] + mov [esi-4],eax + loop pc2l1 +;-------------------------------------- +pc2l2: +; input preprocessing + mov edi,ct1 + xor eax,eax + push edi + mov ecx,256/4 + rep stosd + pop edi + mov ecx,[insize] + mov esi,[infile] + mov ebx,[inbuftmp] + xchg eax,edx +;-------------------------------------- +input_pre2: + lodsb +;-------------------------------------- +@@: + cmp al,0Fh + jnz ip1 + + dec ecx + jz input_pre_done2 + + lodsb + cmp al,80h + jb @b + + cmp al,90h + jb @f +;-------------------------------------- +ip1: + sub al,0E8h + cmp al,1 + ja input_pre_cont2 +;-------------------------------------- +@@: + cmp ecx,5 + jb input_pre_done2 + + lodsd + add eax,esi + sub eax,[infile] + cmp eax,[insize] + jae xxx2 + + cmp eax,1000000h + jae xxx2 + + sub ecx,4 + xchg al,ah + rol eax,16 + xchg al,ah + mov [esi-4],eax + inc edx + mov [ebx],esi + add ebx,4 + jmp input_pre_cont2 +;--------------------------------------------------------------------- +xxx2: sub esi,4 + movzx eax,byte [esi] + mov [eax+edi],byte 1 +;-------------------------------------- +input_pre_cont2: + loop input_pre2 +;-------------------------------------- +input_pre_done2: + mov [ctn],edx + xor eax,eax + mov ecx,256 + repnz scasb + jnz pack_calltrick_fail + + not cl + mov [cti],cl +;-------------------------------------- +@@: + cmp ebx,[inbuftmp] + jz @f + + sub ebx,4 + mov eax,[ebx] + mov [eax-4],cl + jmp @b +;--------------------------------------------------------------------- +@@: + mov al,1 + ret +;********************************************************************* \ No newline at end of file diff --git a/programs/other/kpack/trunk/upacproc.inc b/programs/other/kpack/trunk/upacproc.inc new file mode 100644 index 0000000000..f311e98815 --- /dev/null +++ b/programs/other/kpack/trunk/upacproc.inc @@ -0,0 +1,199 @@ +;********************************************************************* +unpack: +; call clear_edit_points +; and [curedit],0 +; clear messages + call clear_messages +; display logo + mov esi,info_str + push info_len + pop ecx + call write_string + +; load input file + mov esi,inname + call get_full_name + mov ebx,fn70block + mov [ebx],dword 5 + and [ebx+4],dword 0 + and [ebx+8],dword 0 + and [ebx+12],dword 0 + mov [ebx+16],dword file_attr + mcall 70 + test eax,eax + jnz infileerr + + mov ecx,[insize] + test ecx,ecx + jz infileerr + +; mov ecx,[memf] +; mov [infile],ecx +; add ecx,eax +; mov [outfile],ecx +; mov [outfilebest],ecx +; mcall 64,1 +; test eax,eax +; jnz memf1 + + mcall 68,12 + + mov [infile],eax + + mov ebx,fn70block + mov [ebx],byte 0 + mov [ebx+16],eax + mov eax,[insize] + mov [ebx+12],eax + + mcall 70 + test eax,eax + jnz infileerr + + mov eax,[infile] + cmp [eax],dword 'KPCK' + jz @f +;-------------------------------------- +unpack_err: + call return_memory + mov esi,notpacked_str + push notpacked_len + pop ecx + jmp write_string +;--------------------------------------------------------------------- +@@: +; mov ecx,[outfile] +; add ecx,dword [eax+4] +; mcall 64,1 +; test eax,eax +; jnz memf1 + + mov ecx,[eax+4] + add ecx,[insize] + + mcall 68,20,,[infile] + + mov [infile],eax + add eax,[insize] + mov [outfile],eax + mov [outfilebest],eax + + + mov esi,[infile] + mov eax,[esi+8] + push eax + and al,0C0h + cmp al,0C0h + pop eax + jz unpack_err + + and al,not 0C0h + dec eax + jnz unpack_err + + mov eax,[esi+4] + mov [outsize],eax + push eax + push [outfile] + add esi,11 + push esi + mov eax,[esi+1] + xchg al,ah + ror eax,16 + xchg al,ah + mov [esi+1],eax + call lzma_decompress + mov esi,[infile] + test [esi+8],byte 80h + jnz uctr1 + + test [esi+8],byte 40h + jz udone + + add esi,[insize] + sub esi,5 + lodsd + mov ecx,eax + jecxz udone + + mov dl,[esi] + mov esi,[outfile] +;-------------------------------------- +uc1: + lodsb + sub al,0E8h + cmp al,1 + ja uc1 + + cmp [esi],dl + jnz uc1 + + lodsd + shr ax,8 + ror eax,16 + xchg al,ah + sub eax,esi + add eax,[outfile] + mov [esi-4],eax + loop uc1 + jmp udone +;--------------------------------------------------------------------- +uctr1: + add esi,[insize] + sub esi,5 + lodsd + mov ecx,eax + jecxz udone + + mov dl,[esi] + mov esi,[outfile] +;-------------------------------------- +uc2: + lodsb +;-------------------------------------- +@@: + cmp al,15 + jnz uf + + lodsb + cmp al,80h + jb @b + + cmp al,90h + jb @f +;-------------------------------------- +uf: + sub al,0E8h + cmp al,1 + ja uc2 +;-------------------------------------- +@@: + cmp [esi],dl + jnz uc2 + + lodsd + shr ax,8 + ror eax,16 + xchg al,ah + sub eax,esi + add eax,[outfile] + mov [esi-4],eax + loop uc2 +;-------------------------------------- +udone: + mov esi,unpacked_ok + push unpacked_len + pop ecx + call write_string + jmp saveout +;********************************************************************* +return_memory: + mov ecx,[infile] + test ecx,ecx + jz @f + mcall 68,13, + xor eax,eax + mov [infile],eax +@@: + ret +;********************************************************************* \ No newline at end of file