diff --git a/programs/system/MyKey/trunk/ASPAPI.INC b/programs/system/MyKey/trunk/ASPAPI.INC index 74f9e9e29f..811503580b 100644 --- a/programs/system/MyKey/trunk/ASPAPI.INC +++ b/programs/system/MyKey/trunk/ASPAPI.INC @@ -17,7 +17,7 @@ macro start_draw_window x,y,xsize,ysize,areacolor,caption,capsize ; WINDOW LABEL mov eax, 4 ; function 4 : write text to window mov ebx, 8*65536+8 ; [x start] *65536 + [y start] - mov ecx, 0x00ffffff ; color of text RRGGBB + mov ecx, 0x0;0ffffff ; color of text RRGGBB mov edx, caption ; pointer to text beginning mov esi, capsize ; text length int 0x40 @@ -89,6 +89,10 @@ proc outtextxy stdcall, x:dword, y:dword, prompt:dword, prompt_len:dword, color: mov ecx, dword [color] mov edx, dword [prompt] mov esi, dword [prompt_len] + test esi, esi + jnz @f + or ecx, 0x80000000 + @@: int 0x40 popa ret @@ -138,6 +142,16 @@ macro rectangle x,y,xsize,ysize,color line x2,y,x2,y2,color } +macro rectangle2 x,y,xsize,ysize,color1,color2 +{ + x2=x+xsize + y2=y+ysize + line x,y,x2,y,color1 + line x,y,x,y2,color1 + line x,y2,x2,y2,color2 + line x2,y,x2,y2,color2 +} + macro putpixel x,y,color { mov eax, 1 diff --git a/programs/system/MyKey/trunk/MyKey.asm b/programs/system/MyKey/trunk/MyKey.asm index 69ae486c91..f0d079ecc2 100644 --- a/programs/system/MyKey/trunk/MyKey.asm +++ b/programs/system/MyKey/trunk/MyKey.asm @@ -1,8 +1,8 @@ ; -; MyKey. Version 0.1. +; MyKey. Version 0.2. ; ; Author: Asper -; Date of issue: 04.12.2009 +; Date of issue: 29.12.2009 ; Compiler: FASM ; Target: KolibriOS ; @@ -10,36 +10,45 @@ use32 org 0x0 - db 'MENUET00' ; 8 byte id + db 'MENUET01' ; 8 byte id dd 38 ; required os dd STARTAPP ; program start dd I_END ; program image size - dd 0x1000000 ; required amount of memory - dd 0x00000000 ; reserved=no extended header + dd 0x1000000 ; required amount of memory + dd 0x1000000 ; stack heap + dd 0x0 + dd app_path -include "aspAPI.inc" +include 'aspAPI.inc' +include 'string.inc' include 'macros.inc' include 'editbox_ex.mac' include 'load_lib.mac' +include 'dll.inc' include 'debug.inc' DEBUG equ 0;1 N_KEYCOLOR equ 0x00EEEEEE ; Normal button color C_KEYCOLOR equ 0x00CBE1E1 ; Control button color -A_KEYCOLOR equ 0x000099BB;258778 ; Active button color +A_KEYCOLOR equ 0x00FF6400;258778 ; Active button color C_TEXTCOLOR equ 0x80000000 ; Button caption color CA_TEXTCOLOR equ 0x80FFFFFF ; Active button caption color +A_TEXTCOLOR equ 0x00FFFFFF ; Active text color -WIN_X equ 265 -WIN_Y equ 50;175 -WIN_W equ 595 -WIN_H equ 415 ;570 -WIN_COLOR equ 0x04EEEEEE +WIN_X equ 265 +WIN_Y equ 50;175 +WIN_W equ 595 +WIN_H equ 415 ;570 +WIN_COLOR equ 0x040099BB;0x04EEEEEE -BUT_W equ 192;100 -BUT_H equ 23 -BUT_SPACE equ 0 +ITEM_BUTTON_W equ 192;100 +ITEM_BUTTON_H equ 23 +ITEM_BUTTON_SPACE equ 0 +FIRST_ITEM_BUTTON_ID equ 7 + +BUT_W equ 80 +BUT_H equ 20 MAX_HOTKEYS_NUM equ 15 ; Bad bounding :/. Until we have normal listbox control. PATH_MAX_CHARS equ 255 @@ -47,42 +56,66 @@ PATH_MAX_CHARS equ 255 @use_library STARTAPP: + ; Initialize memory + mcall 68, 11 + or eax,eax + jz close_app + ; Import libraries sys_load_library boxlib_name, sys_path, boxlib_name, system_dir0, err_message_found_lib, head_f_l, myimport,err_message_import, head_f_i cmp eax,-1 jz close_app - ;mcall 68,11 - ;or eax,eax - ;jz close_app + stdcall dll.Load,importTable + test eax, eax + jnz close_app + + ; Get memory for editboxes text + mcall 68, 12, MAX_HOTKEYS_NUM*PATH_MAX_CHARS + mov dword [buf_cmd_line], eax + mov dword [edit1.text], eax + mcall 68, 12, MAX_HOTKEYS_NUM*PATH_MAX_CHARS + mov dword [buf_cmd_params], eax + mov dword [edit2.text], eax + mcall 68, 12, MAX_HOTKEYS_NUM*32 + mov dword [it_buf_cmd_line], eax + mov dword [it_edit.text], eax + + call Load_HotkeyList mcall 66, 1, 1 ; Set keyboard mode to get scancodes. mcall 26, 2, 1, ascii_keymap -;get_mykey_window_slot_number: -; mcall 5, 10 ;wait -; mcall 18, 7 -; mov [mykey_window], eax +get_mykey_window_slot_number: + call draw_window + mcall 18, 7 + mov [mykey_window], eax set_event_mask: mcall 40, 39 red: -; .test_slot: -; mov eax, [mykey_window] ; Test is receiver MyKey window -; mov ecx, [it_window] -; cmp eax, ecx -; je @f;still ; if yes still. -; .activate_it_window: -; mov eax, 18 -; mov ebx, 3 -; int 0x40 -; @@: + .test_slot: + mcall 18, 7 + mov ebx, [mykey_window] + cmp eax, ebx + jne @f + + mov ecx, [it_window] + cmp ebx, ecx + je @f + .activate_it_window: + mov al, byte [it_alive] + test al, al + jz @f + mov byte [it_alive], 0 + + mcall 18, 3 ; Activate input thread window + @@: call draw_window still: call reset_modifiers - mov eax, 10 ; Wait for an event in the queue. - int 0x40 + mcall 10 ; Wait for an event in the queue. cmp al,1 ; redraw request ? jz red @@ -96,19 +129,16 @@ still: jmp still key: - mov eax, 2 - int 0x40 + mcall 2 push eax mcall 66, 3 - mov edx, eax - and edx, 0x00000FFF - mov dword [modifiers], edx + mov dword [modifiers], eax pop eax - test word [edit1.flags], 10b;ed_focus ; ¥á«¨ ­¥ ¢ 䮪ãá¥, ¢ë室¨¬ + test word [edit1.flags], 10b jnz .editbox_input - test word [edit2.flags], 10b;ed_focus ; ¥á«¨ ­¥ ¢ 䮪ãá¥, ¢ë室¨¬ + test word [edit2.flags], 10b jz @f .editbox_input: cmp ah, 0x80 ;if key up @@ -124,33 +154,30 @@ key: cmp ah, 69 ;Pause/Break je still -; cmp [keyUpr],0 -; jne still + mov esi, ascii_keymap + call Scan2ASCII - call Scan2ASCII + push dword edit1 + call [edit_box_key] - push dword edit1 - call [edit_box_key] - - push dword edit2 - call [edit_box_key] - jmp still - @@: + push dword edit2 + call [edit_box_key] + jmp still + @@: ;------------------------ mov cl, byte [hotkeys_num] - .test_next_hotkey: + .test_next_hotkey: dec cl mov bl, cl and ebx, 0xFF - shl ebx, 5 - mov esi, ebx + shl ebx, 2 add ebx, dword Hotkeys.codes - cmp ah, byte [ebx] + mov edx, dword [ebx] + cmp ah, dl jne @f - mov edx, dword [ebx] shr edx, 8 cmp edx, dword [modifiers] jne @f @@ -159,23 +186,22 @@ key: mov eax, PATH_MAX_CHARS mul cl mov edx, eax - add edx, dword buf_cmd_params - add eax, dword buf_cmd_line + add edx, dword [buf_cmd_params] + add eax, dword [buf_cmd_line] mov esi, eax pop eax call RunProgram jmp .end_test - @@: - or cl, cl ;cmp cl, 0 - jnz .test_next_hotkey ;jge .test_next_hotkey - .end_test: + @@: + or cl, cl + jnz .test_next_hotkey + .end_test: ;------------------------ jmp still button: - mov eax, 17 ; Get pressed button code - int 0x40 + mcall 17 ; Get pressed button code cmp ah, 1 ; Test x button je close_app @@ -184,41 +210,40 @@ button: call AddHotKey jmp red @@: + cmp ah, 5 + jne @f + call Load_HotkeyList + jmp red + @@: + cmp ah, 6 + jne @f + call WriteIni + xor edx, edx + mov esi, aRamSaver + call RunProgram + @@: - cmp ah, 5 ; Test if pressed buttons - jb still ; is a HotKey button... + cmp ah, FIRST_ITEM_BUTTON_ID ; Test if pressed buttons + jb still ; is a HotKey button... mov al, ah - sub al, 5 + sub al, FIRST_ITEM_BUTTON_ID cmp al, byte [hotkeys_num] - jnb still ; ...so, if not then still, + jnb still ; ...so, if not then still, mov byte [butt], ah ; if yes then save pressed button ID - and eax, 0xFF;shr ax, 8 - if DEBUG - dps "Button = " - dph eax - end if + and eax, 0xFF mov cl, byte PATH_MAX_CHARS mul cl - if DEBUG - dps " offset = " - dph eax - end if mov ebx, eax - add ebx, dword buf_cmd_params - add eax, dword buf_cmd_line + add ebx, dword [buf_cmd_params] + add eax, dword [buf_cmd_line] mov dword [edit1.text], eax mov dword [edit2.text], ebx mov esi, eax call strlen - if DEBUG - dps " len = " - dph ecx - newline - end if mov dword [edit1.size], ecx mov dword [edit1.pos], ecx @@ -227,70 +252,82 @@ button: mov dword [edit2.size], ecx mov dword [edit2.pos], ecx - jmp red ;still + jmp red mouse: push dword edit1 call [edit_box_mouse] - push dword edit2 call [edit_box_mouse] - ;test word [edit1.flags],10b;ed_focus ; ¥á«¨ ­¥ ¢ 䮪ãá¥, ¢ë室¨¬ - ;jne still jmp still close_app: - mov eax,-1 ; close this program - int 0x40 + mov eax,-1 ; close this program + int 0x40 draw_window: - start_draw_window WIN_X,WIN_Y,WIN_W,WIN_H,WIN_COLOR,labelt, 11;labellen-labelt + start_draw_window WIN_X,WIN_Y,WIN_W,WIN_H,WIN_COLOR,labelt, 11;labellen-labelt - push dword edit1 - call [edit_box_draw] + ;bar 5, 24, 585, 385, 0x800000 or 0x90D2 + ;rectangle2 6, 25, 585, 385, 0xFFFFFF, 0 - push dword edit2 - call [edit_box_draw] + ;bar 5, 24, BUT_W+4, 350, 0x008C00D2;0x800000 or A_KEYCOLOR + ;rectangle2 6, 25, BUT_W+4, 350, 0xFFFFFF, 0 - stdcall draw_button, 7,WIN_H-30,80,20,2,C_KEYCOLOR,AddKeyText, 0,C_TEXTCOLOR ; Add Hot key. - if 0 - stdcall draw_button, 90,WIN_H-30,80,20,3,C_KEYCOLOR,DeleteKeyText,0,C_TEXTCOLOR ; Delete Hot key. - stdcall draw_button, 173,WIN_H-30,80,20,4,C_KEYCOLOR,ManageKeyText,0,C_TEXTCOLOR ; Manage Hot key. - end if - movzx ecx, byte [hotkeys_num] - cmp ecx, MAX_HOTKEYS_NUM - jng @f - mov ecx, MAX_HOTKEYS_NUM - @@: - mov eax, 30 - mov ebx, 5 - @@: - or cl, cl - jz @f + push dword edit1 + call [edit_box_draw] + push dword edit2 + call [edit_box_draw] - mov edx, ebx - sub edx, 5 - shl edx, 5; edx=edx*32 - add edx, dword Hotkeys + stdcall draw_button, 7,WIN_H-BUT_H-10,BUT_W,BUT_H,2,0x0050D250,AddKeyText, 0,C_TEXTCOLOR ; Add Hotkey. + if 0 + stdcall draw_button, 90,WIN_H-BUT_H-10,BUT_W,BUT_H,3,C_KEYCOLOR,DeleteKeyText,0,C_TEXTCOLOR ; Delete Hotkey. + stdcall draw_button, 173,WIN_H-BUT_H-10,BUT_W,BUT_H,4,C_KEYCOLOR,ManageKeyText,0,C_TEXTCOLOR ; Manage Hotkey. + end if + stdcall draw_button, WIN_W-BUT_W*2-14,WIN_H-BUT_H-10,BUT_W,BUT_H,5,0x0050D250,ReloadKeyText, 0,C_TEXTCOLOR ; Save Hotkeys list. + stdcall draw_button, WIN_W-BUT_W-7,WIN_H-BUT_H-10,BUT_W,BUT_H,6,0x0050D250,SaveKeyText, 0,C_TEXTCOLOR ; Save Hotkeys list. - cmp bl, byte [butt] - jne .l1 - stdcall draw_button, 7,eax,BUT_W,BUT_H,ebx,A_KEYCOLOR,edx,0,CA_TEXTCOLOR ; F5 - jmp .l2 - .l1: - stdcall draw_button, 7,eax,BUT_W,BUT_H,ebx,N_KEYCOLOR,edx,0,C_TEXTCOLOR ; F5 - .l2: + movzx ecx, byte [hotkeys_num] + cmp ecx, MAX_HOTKEYS_NUM + jng @f + mov ecx, MAX_HOTKEYS_NUM + @@: + mov eax, 30 + mov ebx, FIRST_ITEM_BUTTON_ID + @@: + or cl, cl + jz @f - add eax, BUT_H+BUT_SPACE - inc ebx - dec cl - jmp @b - @@: - end_draw_window + mov edx, ebx + sub edx, FIRST_ITEM_BUTTON_ID + shl edx, 5; edx=edx*32 + add edx, dword Hotkeys + + cmp bl, byte [butt] + jne .l1 + stdcall draw_button, 7,eax,ITEM_BUTTON_W,ITEM_BUTTON_H,ebx,A_KEYCOLOR ,edx,0,CA_TEXTCOLOR + bar 220, 70, 350, 30, 0x00C8E1F0 ;0x800000 or A_KEYCOLOR + rectangle2 221, 71, 350, 30, 0xFFFFFF, 0 + mov esi, Hotkeys.code_names + sub edx, dword Hotkeys + shl edx, 1 + add esi, edx + stdcall outtextxy, 225, 80, esi, 64, C_TEXTCOLOR + jmp .l2 + .l1: + stdcall draw_button, 7,eax,ITEM_BUTTON_W,ITEM_BUTTON_H,ebx,N_KEYCOLOR,edx,0,C_TEXTCOLOR + .l2: + + add eax, ITEM_BUTTON_H+ITEM_BUTTON_SPACE + inc ebx + dec cl + jmp @b + @@: + end_draw_window ret @@ -301,14 +338,39 @@ AddHotKey: inc al mov byte [hotkeys_num], al - mov eax, 51 - mov ebx, 1 - mov ecx, start_input_thread - mov edx, dword input_thread_stack_top - mcall - + mcall 51, 1, dword start_input_thread, dword input_thread_stack_top .end: - ret +ret + + +Load_HotkeyList: + call ReadIni + + mov al, byte [butt] + mov ah, byte [hotkeys_num] + cmp al, ah + jle @f + mov al, ah + @@: + and eax, 0xFF + sub al, FIRST_ITEM_BUTTON_ID + mov cl, byte PATH_MAX_CHARS + mul cl + mov ebx, eax + add eax, dword [buf_cmd_line] + add ebx, dword [buf_cmd_params] + + + mov esi, eax + call strlen + mov dword [edit1.size], ecx + mov dword [edit1.pos], ecx + + mov esi, ebx + call strlen + mov dword [edit2.size], ecx + mov dword [edit2.pos], ecx +ret reset_modifiers: @@ -319,7 +381,8 @@ reset_modifiers: lodsd - mov cl, al ; set new hotkey + ; Set new hotkey for the main thread + mov cl, al shr eax, 8 xor edx, edx @@ -354,26 +417,19 @@ reset_modifiers: pop cx mcall 66, 4 + mov dword [it_hotkey_addr], 0 .end_set_mods: - popa + popa ret ;######################## Input Thread code start ########################## start_input_thread: - -;get_it_window_slot_number: -; mcall 5, 10 ;wait -; mcall 18, 7 -; mov [it_window], eax mov ecx, 1 ; to get scancodes. - mov eax, 66 - mov ebx, 1 ; Set keyboard mode - int 0x40 - mcall 26, 2, 1, ascii_keymap + mcall 26, 2, 1, it_ascii_keymap + mcall 66, 1 ; Set keyboard mode mov dword [it_hotkey_addr], 0 - it_set_editbox: mov al, byte [hotkeys_num] sub al, 1 @@ -386,7 +442,10 @@ it_set_editbox: call strlen mov dword [it_edit.size], ecx mov dword [it_edit.pos], ecx - +get_it_window_slot_number: + call it_draw_window + mcall 18, 7 + mov [it_window], eax it_set_event_mask: mcall 40, 39 @@ -394,26 +453,31 @@ it_red: call it_draw_window it_still: - mov eax, 10 ; Wait for an event in the queue. - int 0x40 + mcall 10 ; Wait for an event in the queue. cmp al,1 ; redraw request ? jz it_red cmp al,2 ; key in buffer ? jz it_key cmp al,3 ; button in buffer ? - jz button + jz it_button cmp al,6 jz it_mouse jmp it_still it_key: - mov eax, 2 - int 0x40 + mcall 2 mov byte [it_keycode], 0 stdcall outtextxy, 10, 100, ctrl_key_names, 35, 0 + + cmp ah, 1 ;Esc + jne @f + dec byte [hotkeys_num] + jmp close_app + @@: + cmp ah, 0x80 ;if key up ja .end cmp ah, 42 ;[Shift] (left) @@ -427,45 +491,26 @@ it_key: cmp ah, 69 ;[Pause Break] je .end - - ;------------------------ - mov cl, byte [hotkeys_num] - .test_next_hotkey: - mov bl, cl - and ebx, 0xFF - shl ebx, 5 - mov esi, ebx - add ebx, dword Hotkeys.codes - cmp ah, byte [ebx] - jne @f - - push eax - mov eax, PATH_MAX_CHARS - mul cl - add eax, dword buf_cmd_line - mov esi, eax - pop eax - mov edx, 0 ; no parametrs yet <- change it! - call RunProgram - jmp .end_test - @@: - dec cl - cmp cl, 0 - jge .test_next_hotkey - .end_test: - ;------------------------ - mov byte [it_keycode], ah + mov esi, it_ascii_keymap call Scan2ASCII - test word [it_edit.flags], 10b;ed_focus ; ¥á«¨ ­¥ ¢ 䮪ãá¥, ¢ë室¨¬ + test word [it_edit.flags], 10b jz .end push dword it_edit call [edit_box_key] jmp it_still .end: + mcall 26, 2, 1, it_ascii_keymap call it_test_key_modifiers + test dl, 3 + jz @f + push edx + mcall 26, 2, 2, it_ascii_keymap + pop edx + @@: + mov al, byte [it_keycode] test al, al jz @f @@ -475,10 +520,13 @@ it_key: mov eax, dword [it_hotkey_addr] test eax, eax jnz @f + + call it_set_keycode_name + mov al, byte [hotkeys_num] - sub al, 1 + dec al and eax, 0xFF - shl eax, 5 + shl eax, 2;5 add eax, dword Hotkeys.codes mov dword [eax], edx mov dword [it_hotkey_addr], eax @@ -495,35 +543,127 @@ it_test_key_modifiers: push eax mcall 66, 3 ;get control keys state mov edx, eax - and edx, 0x00000FFF .lshift: test al, 1 ; LShift ? jz .rshift - stdcall outtextxy, 10, 100, ctrl_key_names, 6, 0x00FF0000 + stdcall outtextxy, 10, 100, ctrl_key_names, 6, A_TEXTCOLOR .rshift: test al, 2 ; RShift ? jz .lctrl - stdcall outtextxy, 184, 100, ctrl_key_names+29, 6, 0x00FF0000 + stdcall outtextxy, 184, 100, ctrl_key_names+29, 6, A_TEXTCOLOR .lctrl: test al, 4 ; LCtrl ? jz .rctrl - stdcall outtextxy, 52, 100, ctrl_key_names+7, 5, 0x00FF0000 + stdcall outtextxy, 52, 100, ctrl_key_names+7, 5, A_TEXTCOLOR .rctrl: test al, 8 ; RCtrl ? jz .lalt - stdcall outtextxy, 148, 100, ctrl_key_names+23, 5, 0x00FF0000 + stdcall outtextxy, 148, 100, ctrl_key_names+23, 5, A_TEXTCOLOR .lalt: test al, 0x10 ; LAlt ? jz .ralt - stdcall outtextxy, 88, 100, ctrl_key_names+13, 4, 0x00FF0000 + stdcall outtextxy, 88, 100, ctrl_key_names+13, 4, A_TEXTCOLOR .ralt: test al, 0x20 ; RAlt ? jz @f - stdcall outtextxy, 118, 100, ctrl_key_names+18, 4, 0x00FF0000 + stdcall outtextxy, 118, 100, ctrl_key_names+18, 4, A_TEXTCOLOR @@: pop eax ret + +it_set_keycode_name: + pusha + mov al, byte [hotkeys_num] + dec al + and eax, 0xFF + shl eax, 6 + mov edi, Hotkeys.code_names + add edi, eax + + mov ecx, 64 + xor ax, ax + call strnset + mcall 66, 3 ;get control keys state + .lshift: + test al, 1 ; LShift ? + jz .rshift + mov esi, ctrl_key_names + mov ecx, 6 + call strncat + + mov esi, aPlus + mov ecx, 3 + call strncat + .rshift: + test al, 2 ; RShift ? + jz .lctrl + mov esi, ctrl_key_names+29 + mov ecx, 6 + call strncat + + mov esi, aPlus + mov ecx, 3 + call strncat + .lctrl: + test al, 4 ; LCtrl ? + jz .rctrl + mov esi, ctrl_key_names+7 + mov ecx, 5 + call strncat + + mov esi, aPlus + mov ecx, 3 + call strncat + .rctrl: + test al, 8 ; RCtrl ? + jz .lalt + mov esi, ctrl_key_names+23 + mov ecx, 5 + call strncat + + mov esi, aPlus + mov ecx, 3 + call strncat + .lalt: + test al, 0x10 ; LAlt ? + jz .ralt + mov esi, ctrl_key_names+13 + mov ecx, 4 + call strncat + + mov esi, aPlus + mov ecx, 3 + call strncat + .ralt: + test al, 0x20 ; RAlt ? + jz @f + mov esi, ctrl_key_names+18 + mov ecx, 4 + call strncat + + mov esi, aPlus + mov ecx, 3 + call strncat + @@: + mov esi, it_ascii_keymap + and edx, 0xFF + add esi, edx + mov ecx, 1 + call strncat + + popa +ret + + +it_button: + mcall 17 ; Get pressed button code + cmp ah, 1 ; Test x button + jne @f + jmp close_app + @@: + jmp it_still + it_mouse: push dword it_edit @@ -532,23 +672,188 @@ it_mouse: jmp it_still it_draw_window: - start_draw_window WIN_X,WIN_Y+250,225,70,WIN_COLOR,it_labelt, 26;labellen-labelt + start_draw_window 450,WIN_Y+250,225,70,WIN_COLOR,it_labelt, 26;labellen-labelt - push dword it_edit - call [edit_box_draw] + push dword it_edit + call [edit_box_draw] - stdcall outtextxy, 10, 100, ctrl_key_names, 35, 0 - ;stdcall draw_button, 7,WIN_H-30,80,20,2,C_KEYCOLOR,AddKeyText, 0,C_TEXTCOLOR ; Add Hot key. - end_draw_window + stdcall outtextxy, 43, 50, it_hint, 0, 0x323232 + stdcall outtextxy, 10, 100, ctrl_key_names, 0, 0 + ;stdcall draw_button, 7,WIN_H-30,80,20,2,C_KEYCOLOR,AddKeyText, 0,C_TEXTCOLOR ; Add Hot key. + end_draw_window + mov byte [it_alive], 1 ret - ;######################## Input Thread code end ########################## +; Read configuration file +ReadIni: + ; Get path + mov edi, ini_path + mov esi, app_path + call strlen + + .get_path: + cmp byte [app_path+ecx-1], '/' + je @f + loop .get_path + @@: + call strncpy + mov byte [ini_path+ecx], 0 + mov esi, aIni + call strlen + call strncat + + ; Get hotkey number + invoke ini_get_int, ini_path, aMain, aKeynum, 0 + + and eax, 0xFF + test al, al + jz .end + cmp al, MAX_HOTKEYS_NUM + jle @f + mov al, MAX_HOTKEYS_NUM + @@: + mov byte [hotkeys_num], al + + mov ecx, eax + xor eax, eax + .get_next_hotkey_values: + call set_next_hotkey_section_name + ; Get hotkey name + mov edi, eax + shl edi, 5 ; edi=eax*32 + add edi, dword Hotkeys + push eax ecx + invoke ini_get_str, ini_path, aHotkey, aName, edi, 32, 0 + pop ecx eax + ; Get hotkey code + mov edi, eax + shl edi, 2 ; edi=eax*4 + add edi, dword Hotkeys.codes + push eax ecx edx + invoke ini_get_int, ini_path, aHotkey, aKeycode, 0 + mov dword [it_hotkey_addr], edi + stosd + ; set hotkey + call reset_modifiers + pop edx ecx eax + ; Get hotkey code_name + mov edi, eax + shl edi, 6 ; edi=eax*64 + add edi, dword Hotkeys.code_names + push eax ecx + invoke ini_get_str, ini_path, aHotkey, aKeycodeName, edi, 64, 0 + pop ecx eax + ; Get hotkey path and param + push eax ecx + mov cl, byte PATH_MAX_CHARS + mul cl + mov edi, eax + push edi + add edi, dword [buf_cmd_line] + invoke ini_get_str, ini_path, aHotkey, aPath, edi, 32, 0 + pop edi + add edi, dword [buf_cmd_params] + invoke ini_get_str, ini_path, aHotkey, aParam, edi, 32, 0 + pop ecx eax + + inc al + dec ecx + test ecx, ecx + jnz .get_next_hotkey_values + .end: +ret + + +; Write configuration file +WriteIni: + mov edi, ini_path + ; Set hotkey number + movzx ecx, byte [hotkeys_num] + invoke ini_set_int, ini_path, aMain, aKeynum, ecx + + xor eax, eax + .get_next_hotkey_values: + call set_next_hotkey_section_name + ; Set hotkey name + push eax ecx + mov esi, eax + shl esi, 5 ; edi=eax*32 + add esi, dword Hotkeys + call strlen + invoke ini_set_str, ini_path, aHotkey, aName, esi, ecx + pop ecx eax + ; Set hotkey code + mov esi, eax + shl esi, 2 ; edi=eax*4 + add esi, dword Hotkeys.codes + push eax ecx edx + invoke ini_set_int, ini_path, aHotkey, aKeycode, dword [esi] + pop edx ecx eax + ; Set hotkey code_name + mov esi, eax + shl esi, 6 ; edi=eax*64 + add esi, dword Hotkeys.code_names + push eax ecx + call strlen + invoke ini_set_str, ini_path, aHotkey, aKeycodeName, esi, ecx + pop ecx eax + ; Set hotkey path and param + push eax ecx + ;inc al + mov cl, byte PATH_MAX_CHARS + mul cl + mov esi, eax + push esi + add esi, dword [buf_cmd_line] + call strlen + invoke ini_set_str, ini_path, aHotkey, aPath, esi, ecx + pop esi + add esi, dword [buf_cmd_params] + call strlen + invoke ini_set_str, ini_path, aHotkey, aParam, esi, ecx + pop ecx eax + + inc al + dec ecx + test ecx, ecx + jnz .get_next_hotkey_values + .end: +ret + + +set_next_hotkey_section_name: ;(eax - num) +; this code mainly from debug.inc + push eax ecx edi + mov edi, aHotkey + add edi, 6 ; + strlen("hotkey") + mov ecx, 10 + push -'0' + .l0: + xor edx, edx + div ecx + push edx + test eax, eax + jnz .l0 + .l1: + pop eax + add al, '0' + ;call debug_outchar + stosb + jnz .l1 + pop edi ecx eax +ret + + +;**************************************** +;* input: esi = pointer to keymap * +;* ah = scan code * +;* output: ah = ascii code * +;**************************************** Scan2ASCII: push esi - mov esi, ascii_keymap shr eax, 8 add esi, eax lodsb @@ -557,22 +862,6 @@ Scan2ASCII: ret -;**************************************** -;* input: esi = pointer to string * -;* output: ecx = length of the string * -;**************************************** -strlen: - push eax - xor ecx, ecx - @@: - lodsb - or al, al - jz @f - inc ecx - jmp @b - @@: - pop eax - ret ;******************************************** ;* input: esi = pointer to the file name * @@ -588,9 +877,7 @@ RunProgram: mov dword [InfoStructure+16], 0 ; reserved mov dword [InfoStructure+20], 0 ; reserved mov dword [InfoStructure+21], esi ; pointer to the file name - mov eax, 70 - mov ebx, InfoStructure - int 0x40 + mcall 70, InfoStructure cmp eax, 0 jl .err_out .out: @@ -607,8 +894,8 @@ RunProgram: ; DATA AREA ; Application Title -labelt db 'MyKey v.0.1' -;mykey_window dd 0 ; Slot number of MyKey +labelt db 'MyKey v.0.2' +mykey_window dd 0 ; Slot number of MyKey main thread ;########### Input Thread data start ############ @@ -617,29 +904,32 @@ labelt db 'MyKey v.0.1' it_labelt db "Input hotkey and it's name" ;labellen: it_edit edit_box 180, 20, 30, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, 31, it_buf_cmd_line, 0, 0 -it_buf_cmd_line db MAX_HOTKEYS_NUM*32 dup(0) ; !Make it dinamyc!!! -;it_window dd 0 ; Slot number of Input thread +it_buf_cmd_line dd 0 ;db MAX_HOTKEYS_NUM*32 dup(0) ; !Make it dynamic!!! +it_window dd 0 ; Slot number of the input thread +it_alive db 0 ; Flag of the input thread existance it_keycode db 0 it_hotkey_addr dd 0 +it_hint db 'or press Esc to cancel',0 ;########### Input Thread data end ############ ;Button names -AddKeyText db 'Add',0 -DeleteKeyText db 'Delete',0 -ManageKeyText db 'Manage',0 +AddKeyText db 'Add',0 +ReloadKeyText db 'Reload',0 +SaveKeyText db 'Save',0 +;DeleteKeyText db 'Delete',0 +;ManageKeyText db 'Manage',0 hotkeys_num db 0;15 -;keyboard_mode db 0 ; Scan or ASCII keys to send ? 0 - ASCII , 1 - Scan -butt db 5 ; Pressed button ID +butt db FIRST_ITEM_BUTTON_ID ; Pressed button ID modifiers dd 0 ;Data structures for loadlib.mac and editbox_ex.mac [ edit1 edit_box 350, 220, 30, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, PATH_MAX_CHARS+1, buf_cmd_line, 0, 0 edit2 edit_box 350, 220, 50, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, PATH_MAX_CHARS+1, buf_cmd_params, 0, 0 -buf_cmd_line db MAX_HOTKEYS_NUM*PATH_MAX_CHARS dup(0) ; !Make it dinamyc!!! -buf_cmd_params db MAX_HOTKEYS_NUM*PATH_MAX_CHARS dup(0) ; !Make it dinamyc!!! +buf_cmd_line dd 0 +buf_cmd_params dd 0 sys_path: system_dir0 db '/sys/lib/' @@ -663,6 +953,28 @@ aEdit_box_key db 'edit_box_key',0 aEdit_box_mouse db 'edit_box_mouse',0 aVersion_ed db 'version_ed',0 +align 16 +importTable: +library \ + libini, 'libini.obj';, \ +; boxlib, 'boxlib.obj' \ + +;import boxlib, \ +;edit_box_draw , 'edit_box', \ +;edit_box_key , 'edit_box_key', \ +;edit_box_mouse , 'edit_box_mouse', \ +;version_ed , 'version_ed' + + +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_get_color,'ini_get_color', \ +; ini_set_color,'ini_set_color' + + ;] Data structures for loadlib.mac and editbox_ex.mac InfoStructure: @@ -683,15 +995,33 @@ input_thread_stack_top: ascii_keymap: db 128 dup(?) ctrl_key_names db 'LShift LCtrl LAlt RAlt RCtrl RShift',0 +aPlus db ' + ',0 +aIni db 'mykey.ini',0 +aMain db 'main',0 +aKeynum db 'keynum',0 +aHotkey db 'hotkey',0,0,0 +aName db 'name',0 +aKeycode db 'keycode',0 +aKeycodeName db 'keycode_name',0 +aPath db 'path',0 +aParam db 'param',0 +aRamSaver db '/sys/rdsave',0 -Hotkeys: ;(name = 32 b) + (modifiers = 3 b) + (keycode = 1 b) = 36 byte for 1 hotkey +app_path rb 255 +ini_path rb 255 + +Hotkeys: ;(name = 32 b) + (modifiers = 3 b) + (keycode = 1 b) + (keycode_name = 64 b) = 100 bytes for 1 hotkey .names: - db 'My Favorite 1',0 - rb 18 - db 'My Favorite 2',0 - rb 18 - db 'My Favorite 3',0 - rb 18 + db 'My1',0 + rb 28 + db 'My2',0 + rb 28 + db 'My3',0 + rb 28 rb MAX_HOTKEYS_NUM*32-3 .codes: dd MAX_HOTKEYS_NUM dup (0) + .code_names: + rb MAX_HOTKEYS_NUM*64 + +it_ascii_keymap: diff --git a/programs/system/MyKey/trunk/ReadMe.txt b/programs/system/MyKey/trunk/ReadMe.txt index ffdb0922e3..2e35c86775 100644 --- a/programs/system/MyKey/trunk/ReadMe.txt +++ b/programs/system/MyKey/trunk/ReadMe.txt @@ -12,11 +12,10 @@ â íèæíåå - ïåðåäàâàåìûå åé ïàðàìåòðû. Íåîáõîäèìî ñäåëàòü: -a. Çàãðóçêà è ñîõðàíåíèå êîíôèãóðàöèîííîãî ôàéëà. -b. Óäàëåíèå ãîðÿ÷èõ êëàâèø. -c. Èçìåíåíèå óæå óñòàíîâëåííûõ ãîðÿ÷èõ êëàâèø. +a. Óäàëåíèå ãîðÿ÷èõ êëàâèø. +b. Èçìåíåíèå óæå óñòàíîâëåííûõ ãîðÿ÷èõ êëàâèø. -Íîìåð âåðñèè: 0.1 +Íîìåð âåðñèè: 0.2 ==Àâòîð== Asper @@ -38,11 +37,10 @@ on the keyboard. in the lower text field - parametrs have to be passed to program. ToDo: -a. Load and save of configuration file will be implemented in the next version. -b. Delete hotkeys. -c. Change hotkeys that are already set. +a. Delete hotkeys. +b. Change hotkeys that are already set. -Version number: 0.1 +Version number: 0.2 ==Author== Asper diff --git a/programs/system/MyKey/trunk/debug.inc b/programs/system/MyKey/trunk/debug.inc index 8564deb889..8303039e16 100644 --- a/programs/system/MyKey/trunk/debug.inc +++ b/programs/system/MyKey/trunk/debug.inc @@ -139,10 +139,12 @@ debug_outhex: ret SysMsgBoardChar: + push eax ebx ecx mov cl, al mov eax, 63 mov ebx, 1 int 0x40 + pop ecx ebx eax ret SysMsgBoardStr: diff --git a/programs/system/MyKey/trunk/dll.inc b/programs/system/MyKey/trunk/dll.inc new file mode 100644 index 0000000000..6ceb2d514d --- /dev/null +++ b/programs/system/MyKey/trunk/dll.inc @@ -0,0 +1,157 @@ +;----------------------------------------------------------------------------- +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 + + +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] + xor eax,eax + .next: or edx,edx + jz .end + cmp dword[edx],0 + 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/system/MyKey/trunk/mykey.ini b/programs/system/MyKey/trunk/mykey.ini new file mode 100644 index 0000000000..cdf6c45535 --- /dev/null +++ b/programs/system/MyKey/trunk/mykey.ini @@ -0,0 +1,46 @@ +[main] +keynum=7 + +[hotkey0] +name =FCE Ultra +keycode =1074 +keycode_name =LCtrl + m +path =/hd0/2/fce +param =/hd0/2/gd/city.nes + +[hotkey1] +name =Kolibri Packer +keycode=4143 +keycode_name=LAlt + v +path =/sys/kpack +param =mykey.bin mykey +[hotkey2] +name=kfar +keycode=4137 +keycode_name=LAlt + ` +path=file managers/kfar +param= +[hotkey3] +name=Minesweeper +keycode=1058 +keycode_name=LCtrl + g +path=games/mine +param= +[hotkey4] +name=Games directory +keycode=8226 +keycode_name=RAlt + g +path=file managers/eolite +param=/sys/games +[hotkey5] +name=KFM +keycode=1589 +keycode_name=RShift + LCtrl + ? +path=file managers/kfm +param= +[hotkey6] +name=System Message Board +keycode=4127 +keycode_name=LAlt + s +path=develop/board +param= diff --git a/programs/system/MyKey/trunk/string.inc b/programs/system/MyKey/trunk/string.inc new file mode 100644 index 0000000000..cef717338a --- /dev/null +++ b/programs/system/MyKey/trunk/string.inc @@ -0,0 +1,94 @@ +;**************************************** +;* input: esi = pointer to string * +;* output: ecx = length of the string * +;**************************************** +strlen: + push eax esi + xor ecx, ecx + @@: + lodsb + or al, al + jz @f + inc ecx + jmp @b + @@: + pop esi eax + ret + +;************************************************* +;* input: esi = pointer to the src string * +;* edi = pointer to the dest string * +;* ecx = number of bytes to copy * +;************************************************* +strncpy: + push eax ecx esi edi + @@: + lodsb + stosb + or al, al + jz @f + dec ecx + jz @f + jmp @b + @@: + pop edi esi ecx eax + ret + +;************************************************* +;* input: esi = pointer to the src string * +;* edi = pointer to the dest string * +;************************************************* +strcpy: + push esi edi + rep movsb + pop edi esi + ret + +;************************************************* +;* input: esi = pointer to the src string * +;* edi = pointer to the dest string * +;************************************************* +strcat: + push esi + call strlen + add esi, ecx + call strcpy + pop esi + ret + +;************************************************* +;* input: esi = pointer to the src string * +;* edi = pointer to the dest string * +;* ecx = number of bytes to copy * +;************************************************* +strncat: + push edi + push ecx esi + mov esi, edi + call strlen + add edi, ecx + pop esi ecx + call strncpy + pop edi + ret + +;************************************************* +;* input: edi = pointer to the dest string * +;* al = byte to set the string to * +;************************************************* +;strset: +; push edi +; rep stosb +; pop edi +; ret + +;************************************************* +;* input: edi = pointer to the dest string * +;* al = byte to set the string to * +;* ecx = number of bytes to set * +;************************************************* +strnset: + push edi ecx + rep stosb + pop ecx edi + ret diff --git a/programs/system/kerpack/trunk/calltrick2.asm b/programs/system/kerpack/trunk/calltrick2.asm deleted file mode 100644 index 36b04430ca..0000000000 --- a/programs/system/kerpack/trunk/calltrick2.asm +++ /dev/null @@ -1,32 +0,0 @@ - pop esi - push esi -loader_patch4: - mov ecx, 0 ; will be patched: number of calltrick entries -ctrloop: - lodsb -@@: - cmp al, 0xF - jnz .f - lodsb - cmp al, 80h - jb @b - cmp al, 90h - jb @f -.f: - sub al, 0E8h - cmp al, 1 - ja ctrloop -@@: - cmp byte [esi], 0 ; will be patched: code in calltrick entries -loader_patch5: - jnz ctrloop - lodsd -; "bswap eax" is not supported on i386 -; mov al,0/bswap eax = 4 bytes, following instructions = 9 bytes - shr ax, 8 - ror eax, 16 - xchg al, ah - sub eax, esi - add eax, [esp] - mov [esi-4], eax - loop ctrloop diff --git a/programs/system/kerpack/trunk/doexe2.asm b/programs/system/kerpack/trunk/doexe2.asm deleted file mode 100644 index 072f90a716..0000000000 --- a/programs/system/kerpack/trunk/doexe2.asm +++ /dev/null @@ -1,68 +0,0 @@ -filename equ 'kerpack.exe' - -virtual at 0 -file filename:3Ch,4 -load pehea dword from 0 -file filename:pehea,0F8h+28h*3 -load NumberOfSections word from 4+6 -load SizeOfOptionalHeader word from 4+14h -if NumberOfSections<>3 -error Expected three sections, .text, .bss and .reloc -end if -if SizeOfOptionalHeader<>0E0h -error Nonstandard PE header -end if -load RelocsRVA dword from 4+0A0h -load RelocsSize dword from 4+0A4h -load ImageBase dword from 4+34h -load TextRVA dword from 4+0F8h+0Ch -load TextSize dword from 4+0F8h+8 -load TextOffs dword from 4+0F8h+14h -load BSSSize dword from 4+0F8h+28h+10h -load RelocRVA dword from 4+0F8h+28h*2+0Ch -load RelocOffs dword from 4+0F8h+28h*2+14h -if BSSSize -error Second section expected to be .bss -end if -if RelocRVA<>RelocsRVA -error Third section expected to be .reloc -end if -;file 'test.exe':pehea+0F8h,28h -;load physofs dword from 4+14h -;load mem dword from 4+8 -;file 'test.exe':physofs+16,4 -;load sz dword from $-4 -end virtual - -file filename:TextOffs,TextSize - -while RelocsSize>8 -virtual at 0 -file filename:RelocOffs,8 -load CurRelocPage dword from 0 -load CurRelocChunkSize dword from 4 -end virtual -RelocsSize=RelocsSize-CurRelocChunkSize -CurRelocChunkSize = CurRelocChunkSize-8 -RelocOffs=RelocOffs+8 -while CurRelocChunkSize -virtual at 0 -file filename:RelocOffs,2 -RelocOffs=RelocOffs+2 -CurRelocChunkSize=CurRelocChunkSize-2 -load s word from 0 -end virtual -CurRelocType = s shr 12 -RelocItem = CurRelocPage + (s and 0xFFF) -if CurRelocType=0 -else if CurRelocType=3 -load z dword from RelocItem-TextRVA -store dword z-(TextRVA+ImageBase) at RelocItem-TextRVA -else -error Unexpected relocation type -end if -end while -end while - -store dword TextSize at 10h -store dword RelocRVA-TextRVA at 14h diff --git a/programs/system/kerpack/trunk/kerpack.asm b/programs/system/kerpack/trunk/kerpack.asm deleted file mode 100644 index 90568284c5..0000000000 --- a/programs/system/kerpack/trunk/kerpack.asm +++ /dev/null @@ -1,232 +0,0 @@ -; Kolibri kernel packer -; (C) copyright diamond 2006, 2007 -; -; This program 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 2 of the License, or -; (at your option) any later version. -; -; This program 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. - -; Uses LZMA compression library by Igor Pavlov -; (for more information on LZMA and 7-Zip visit http://www.7-zip.org) -; (plain-C packer is ported by diamond) - -format MS COFF - -extrn '_lzma_compress@16' as lzma_compress -extrn '_lzma_set_dict_size@4' as lzma_set_dict_size - -section '.text' code executable readable - -die_with_err: - pop esi -@@: - lodsb - test al, al - jz @f - mov cl, al - push 63 - pop eax - push 1 - pop ebx - int 40h - jmp @b -@@: - mov al, 63 - mov cl, 13 - int 40h - mov cl, 10 - int 40h - or eax, -1 - int 40h - -public _start -_start: - push 70 - pop eax - mov ebx, fn70_read - int 40h - cmp eax, 6 - jz read_ok -read_err: - call die_with_err - db 'KerPack: cannot load kernel.mnt',0 -read_ok: - push 18 - call lzma_set_dict_size -; find jump to 32-bit code - mov edi, infile - 1 -@@: - inc edi - cmp dword [edi], 0E88EE08Eh ; mov fs,ax/mov gs,ax - jnz @b - cmp dword [edi+4], 00BCD08Eh ; mov ss,ax/mov esp,00xxxxxx - jnz @b - add edi, 11 - mov [inptr], edi - sub edi, infile - mov [indelta], edi - lea eax, [ebx+0x10000] - mov [..loader_patch3+2], eax - sub ebx, edi - mov [insize], ebx - call preprocess_calltrick2 - mov al, [cti] - mov [loader_patch5-1], al - mov eax, [ctn] - mov [loader_patch4+1], eax - mov eax, [inptr] - add eax, outfile - infile + loader_size - 5 - push workmem - push [insize] - push eax - push [inptr] - call lzma_compress - add eax, loader_size-5 - mov [loader_patch1+6], eax - add eax, [indelta] - mov [outsize], eax - mov eax, [indelta] - mov ecx, dword [eax + outfile + loader_size - 4] - bswap ecx - mov [loader_patch2+4], ecx - add eax, 0x10000 - mov [loader_patch1+1], eax - mov esi, infile - mov edi, outfile - mov ecx, [indelta] - rep movsb - mov esi, loader_start - mov ecx, loader_size - rep movsb - push 70 - pop eax - mov ebx, fn70_write - int 40h - test eax, eax - jz @f - call die_with_err - db 'KerPack: cannot save kernel.mnt',0 -@@: - call die_with_err - db 'KerPack: all is OK',0 - -preprocess_calltrick2: -; input preprocessing - mov edi, ct1 - xor eax, eax - push edi - mov ecx, 256/4 - rep stosd - pop edi - mov ecx, ebx - mov esi, [inptr] - 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, [inptr] - 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 byte [eax+edi], 1 -input_pre_cont2: - loop input_pre2 -input_pre_done2: - mov [ctn], edx - xor eax, eax - mov ecx, 256 - repnz scasb - jnz pack_calltrick_done - not cl - mov [cti], cl -@@: - cmp ebx, inbuftmp - jz pack_calltrick_done - sub ebx, 4 - mov eax, [ebx] - mov [eax-4], cl - jmp @b -pack_calltrick_done: - ret - -include 'loader_lzma.asm' - -section '.data' data readable writeable - db 'MENUET01' - dd 1 - dd _start - dd bss_start ; i_end - dd bss_end ; memory - dd mtstack_end ; esp - dd 0 ; params - dd 0 ; icon -fn70_read: - dd 0 - dd 0 - dd 0 - dd 200*1024 - dd infile -filename db '/rd/1/kernel.mnt',0 -fn70_write: - dd 2 - dd 0 - dd 0 -outsize dd ? - dd outfile - db 0 - dd filename -section '.bss' readable writeable -bss_start: - align 4 -inptr dd ? -indelta dd ? -insize dd ? -ct1 rb 256 -ctn dd ? -cti db ? - -align 4 -mtstack rb 1000h -mtstack_end: - -infile rb 200*1024 -inbuftmp rb 200*1024 -outfile rb 200*1024 -workmem rb 6A8000h -bss_end: diff --git a/programs/system/kerpack/trunk/kerpack.bat b/programs/system/kerpack/trunk/kerpack.bat deleted file mode 100644 index 6e887f371e..0000000000 --- a/programs/system/kerpack/trunk/kerpack.bat +++ /dev/null @@ -1,7 +0,0 @@ -del kerpack -del kerpack.obj -del kerpack.exe -fasm memset.asm -fasm kerpack.asm -"C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\link.exe" /section:.bss,E /fixed:no /subsystem:native /merge:.data=.text /merge:.rdata=.text /nologo /entry:start /out:kerpack.exe /ltcg kerpack.obj /nodefaultlib lzmapack.lib memset.obj -fasm doexe2.asm kerpack diff --git a/programs/system/kerpack/trunk/loader_lzma.asm b/programs/system/kerpack/trunk/loader_lzma.asm deleted file mode 100644 index 3c4ab5b3b7..0000000000 --- a/programs/system/kerpack/trunk/loader_lzma.asm +++ /dev/null @@ -1,404 +0,0 @@ -loader_start: -; start address; this code will be injected after the init code -; (some commands below "B32" in the kernel) - mov edi, 0x280000 - lea ebx, [edi+loader_size1+16] - lea edx, [ebx+4] -loader_patch1: - mov esi, 0 ; will be patched: start address to copy - mov ecx, 0 ; will be patched: size of data to copy - push esi - rep movsb - jmp edx -loader_size1 = $ - loader_start - -loader_patch2: - dd 0x280000 + loader_size - dd 0 ; will be patched: start value for code - ; (LZMA-specific) - dd -1 - dd _RangeDecoderBitDecode_edx - loader_start + 0x280000 - dd _RangeDecoderBitDecode - loader_start + 0x280000 -RangeDecoderBitDecode equ dword [ebx] -RangeDecoderBitDecode_edx equ dword [ebx-4] -code_ equ ebx-12 -range equ ebx-8 - -rep1 equ ebx-28 -rep2 equ ebx-24 -rep3 equ ebx-20 -inptr_ldr equ ebx-16 - -pb equ 0 ; pos state bits -lp equ 0 ; literal pos state bits -lc equ 3 ; literal context bits -posStateMask equ ((1 shl pb)-1) -literalPosMask equ ((1 shl lp)-1) - -kNumPosBitsMax = 4 -kNumPosStatesMax = (1 shl kNumPosBitsMax) - -kLenNumLowBits = 3 -kLenNumLowSymbols = (1 shl kLenNumLowBits) -kLenNumMidBits = 3 -kLenNumMidSymbols = (1 shl kLenNumMidBits) -kLenNumHighBits = 8 -kLenNumHighSymbols = (1 shl kLenNumHighBits) - -LenChoice = 0 -LenChoice2 = 1 -LenLow = 2 -LenMid = (LenLow + (kNumPosStatesMax shl kLenNumLowBits)) -LenHigh = (LenMid + (kNumPosStatesMax shl kLenNumMidBits)) -kNumLenProbs = (LenHigh + kLenNumHighSymbols) - -kNumStates = 12 -kNumLitStates = 7 -kStartPosModelIndex = 4 -kEndPosModelIndex = 14 -kNumFullDistances = (1 shl (kEndPosModelIndex/2)) -kNumPosSlotBits = 6 -kNumLenToPosStates = 4 -kNumAlignBits = 4 -kAlignTableSize = (1 shl kNumAlignBits) -kMatchMinLen = 2 - -IsMatch = 0 -IsRep = 0xC0 ; (IsMatch + (kNumStates shl kNumPosBitsMax)) -IsRepG0 = 0xCC ; (IsRep + kNumStates) -IsRepG1 = 0xD8 ; (IsRepG0 + kNumStates) -IsRepG2 = 0xE4 ; (IsRepG1 + kNumStates) -IsRep0Long = 0xF0 ; (IsRepG2 + kNumStates) -PosSlot = 0x1B0 ; (IsRep0Long + (kNumStates shl kNumPosBitsMax)) -SpecPos = 0x2B0 ; (PosSlot + (kNumLenToPosStates shl kNumPosSlotBits)) -Align_ = 0x322 ; (SpecPos + kNumFullDistances - kEndPosModelIndex) -Lencoder = 0x332 ; (Align_ + kAlignTableSize) -RepLencoder = 0x534 ; (Lencoder + kNumLenProbs) -Literal = 0x736 ; (RepLencoder + kNumLenProbs) - -LZMA_BASE_SIZE = 1846 ; must be ==Literal -LZMA_LIT_SIZE = 768 - -kNumTopBits = 24 -kTopValue = (1 shl kNumTopBits) - -kNumBitModelTotalBits = 11 -kBitModelTotal = (1 shl kNumBitModelTotalBits) -kNumMoveBits = 5 - -uninit_base = 2C0000h - -p = uninit_base - -unpacker: - xor ebp, ebp - xor eax, eax - dec eax - lea edi, [rep1] - stosd - stosd - stosd - xchg eax, esi -; mov ecx, Literal + (LZMA_LIT_SIZE shl (lc+lp)) - mov ch, (Literal + (LZMA_LIT_SIZE shl (lc+lp)) + 0xFF) shr 8 - mov eax, kBitModelTotal/2 - mov edi, p - rep stosd - pop edi - push edi -.main_loop: -..loader_patch3: - cmp edi, dword 0 ; will be patched: end of data to unpack - jae .main_loop_done -if posStateMask - mov edx, edi - and edx, posStateMask -else - xor edx, edx -end if - push eax ; al = previous byte - lea eax, [ebp + ((p+IsMatch*4) shr (kNumPosBitsMax+2))] - shl eax, kNumPosBitsMax+2 -if posStateMask - call RangeDecoderBitDecode_edx -else - call RangeDecoderBitDecode -end if - pop eax - jc .1 - movzx eax, al -if literalPosMask - mov ah, dl - and ah, literalPosMask -end if -if ((LZMA_LIT_SIZE*4) and ((1 shl (8-lc)) - 1)) <> 0 - shr eax, 8-lc - imul eax, LZMA_LIT_SIZE*4 -else - and al, not ((1 shl (8-lc)) - 1) - imul eax, (LZMA_LIT_SIZE*4) shr (8-lc) -end if - add eax, p+Literal*4 - mov dl, 1 - cmp ebp, kNumLitStates - jb .literal - mov cl, [edi + esi] -.lx0: - add cl, cl - adc dh, 1 - call RangeDecoderBitDecode_edx - adc dl, dl - jc .lx1 - xor dh, dl - test dh, 1 - mov dh, 0 - jnz .lx0 -.literal: -@@: - call RangeDecoderBitDecode_edx - adc dl, dl - jnc @b -.lx1: - mov eax, ebp - cmp al, 4 - jb @f - cmp al, 10 - mov al, 3 - jb @f - mov al, 6 -@@: sub ebp, eax - xchg eax, edx -.stosb_main_loop: - stosb - jmp .main_loop -.1: - lea eax, [p + IsRep*4 + ebp*4] - call RangeDecoderBitDecode - jnc .10 - add eax, (IsRepG0 - IsRep)*4 ;lea eax, [p + IsRepG0*4 + ebp*4] - call RangeDecoderBitDecode - jc .111 - mov eax, ebp - shl eax, kNumPosBitsMax+2 - add eax, p + IsRep0Long*4 - call RangeDecoderBitDecode_edx - jc .1101 - cmp ebp, 7 - sbb ebp, ebp - lea ebp, [ebp+ebp+11] - mov al, [edi + esi] - jmp .stosb_main_loop -.111: - add eax, (IsRepG1 - IsRepG0) * 4 ;lea eax, [p + IsRepG1*4 + ebp*4] - call RangeDecoderBitDecode - xchg esi, [rep1] - jnc @f - add eax, (IsRepG2 - IsRepG1) * 4 ;lea eax, [p + IsRepG2*4 + ebp*4] - call RangeDecoderBitDecode - xchg esi, [rep2] - jnc @f - xchg esi, [rep3] -@@: -.1101: - mov eax, p + RepLencoder*4 - call LzmaLenDecode - push 8 - jmp .rmu -.10: - xchg esi, [rep1] - xchg esi, [rep2] - mov [rep3], esi - mov eax, p + Lencoder*4 - call LzmaLenDecode - push kNumLenToPosStates-1 - pop edx - cmp edx, ecx - jb @f - mov edx, ecx -@@: - push ecx - push kNumPosSlotBits - pop ecx - mov eax, p+PosSlot*4 - shl edx, cl - call RangeDecoderBitTreeDecode - mov esi, ecx - cmp ecx, kStartPosModelIndex - jb .l6 - mov edx, ecx - xor eax, eax - shr ecx, 1 - adc al, 2 - dec ecx - shl eax, cl - mov esi, eax - sub eax, edx - lea eax, [p + (SpecPos - 1)*4 + eax*4] - cmp edx, kEndPosModelIndex - jb .l59 -; call RangeDecoderDecodeDirectBits -;RangeDecoderDecodeDirectBits: - xor eax, eax -.l: - shr dword [range], 1 - add eax, eax - mov edx, [code_] - sub edx, [range] - jb @f - mov [code_], edx - add al, 1 shl kNumAlignBits -@@: - call update_decoder - dec ecx - cmp ecx, kNumAlignBits - jnz .l -; ret - add esi, eax - mov eax, p+Align_*4 -.l59: -; call RangeDecoderReverseBitTreeDecode_addesi -;_RangeDecoderReverseBitTreeDecode_addesi: -; in: eax->probs,ecx=numLevels -; out: esi+=length; destroys edx - push edi - xor edx, edx - inc edx - mov edi, edx -@@: - call RangeDecoderBitDecode_edx - jnc .591 - add esi, edi - stc -.591: - adc edx, edx - add edi, edi - loop @b - pop edi -; ret -.l6: - pop ecx - not esi - push 7 -.rmu: - cmp ebp, 7 - pop ebp - jb @f - add ebp, 3 -@@: -.repmovsb: - inc ecx - push esi - add esi, edi - rep movsb - lodsb - pop esi - jmp .stosb_main_loop -.main_loop_done: -include 'calltrick2.asm' - ret - -_RangeDecoderBitDecode: -; in: eax->prob -; out: CF=bit - push edx - mov edx, [range] - shr edx, kNumBitModelTotalBits - imul edx, [eax] - cmp [code_], edx - jae .ae - mov [range], edx - mov edx, kBitModelTotal - sub edx, [eax] - shr edx, kNumMoveBits - add [eax], edx -.n: - pushfd - call update_decoder - popfd - pop edx - ret -.ae: - sub [range], edx - sub [code_], edx - mov edx, [eax] - shr edx, kNumMoveBits - sub [eax], edx - stc - jmp .n - -update_decoder: - cmp byte [range+3], 0 ;cmp dword [range], kTopValue - jnz @f ;jae @f - shl dword [range], 8 - shl dword [code_], 8 - push eax - mov eax, [inptr_ldr] - mov al, [eax] - inc dword [inptr_ldr] - mov byte [code_], al - pop eax -@@: ret - -_RangeDecoderBitDecode_edx: - push eax - lea eax, [eax+edx*4] - call RangeDecoderBitDecode - pop eax - ret - -LzmaLenDecode: -; in: eax->prob, edx=posState -; out: ecx=len - -; LenChoice==0 -; add eax, LenChoice*4 -if kLenNumMidBits <> kLenNumLowBits -error in optimization -end if - mov cl, kLenNumMidBits - call RangeDecoderBitDecode - jnc .0 - add eax, (LenChoice2-LenChoice)*4 - call RangeDecoderBitDecode - jc @f -if (kLenNumMidBits <> 3) | (LenMid-LenChoice2 > 0x7F + kLenNumMidBits) - shl edx, cl - add edx, LenMid-LenChoice2 -else - lea edx, [ecx + edx*8 - kLenNumMidBits + LenMid-LenChoice2] -end if - push kLenNumLowSymbols - jmp RangeDecoderBitTreeDecode.1 -@@: - mov edx, LenHigh-LenChoice2 - mov cl, kLenNumHighBits - push kLenNumLowSymbols + kLenNumMidSymbols - jmp RangeDecoderBitTreeDecode.1 -.0: - shl edx, cl -if LenLow = 2 - inc edx - inc edx -else - add edx, LenLow -end if -RangeDecoderBitTreeDecode: -; in: eax+edx*4->probs,ecx=numLevels -; out: ecx=length; destroys edx - push 0 -.1: - lea eax, [eax+edx*4] - xor edx, edx - inc edx - push ecx -@@: - call RangeDecoderBitDecode_edx - adc edx, edx - loop @b - pop ecx - btc edx, ecx - pop ecx - add ecx, edx - ret - -loader_size = $ - loader_start diff --git a/programs/system/kerpack/trunk/lzmapack.lib b/programs/system/kerpack/trunk/lzmapack.lib deleted file mode 100644 index 3f2c501144..0000000000 Binary files a/programs/system/kerpack/trunk/lzmapack.lib and /dev/null differ diff --git a/programs/system/kerpack/trunk/memset.asm b/programs/system/kerpack/trunk/memset.asm deleted file mode 100644 index 1774128c90..0000000000 --- a/programs/system/kerpack/trunk/memset.asm +++ /dev/null @@ -1,11 +0,0 @@ -format MS COFF -section '.text' code readable executable -public _memset -_memset: - push edi - mov edi, [esp+8] - mov al, [esp+12] - mov ecx, [esp+16] - rep stosb - pop edi - ret