diff --git a/programs/system/MyKey/trunk/ASPAPI.INC b/programs/system/MyKey/trunk/ASPAPI.INC new file mode 100644 index 0000000000..74f9e9e29f --- /dev/null +++ b/programs/system/MyKey/trunk/ASPAPI.INC @@ -0,0 +1,149 @@ +include 'proc32.inc' + +macro start_draw_window x,y,xsize,ysize,areacolor,caption,capsize +{ + ;pusha + mov eax, 12 ; function 12:tell os about windowdraw + mov ebx, 1 ; 1, start of draw + int 0x40 + ; DRAW WINDOW + mov eax, 0 ; function 0 : define and draw window + mov ebx, x*65536+xsize ; [x start] *65536 + [x size] + mov ecx, y*65536+ysize ; [y start] *65536 + [y size] + mov edx, areacolor ; color of work area RRGGBB + mov esi, 0x00334455 ; color of grab bar RRGGBB + mov edi, 0x00ddeeff ; color of frames RRGGBB + int 0x40 + ; 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 edx, caption ; pointer to text beginning + mov esi, capsize ; text length + int 0x40 + ;popa +} + +macro end_draw_window +{ + mov eax, 12 ; end of redraw + mov ebx, 2 + int 0x40 +} + +macro change_window_place_size x,y,xsize,ysize +{ + mov eax, 67 ; function 67 : replace and/or resize window + mov ebx, x + mov ecx, y + mov edx, xsize + mov esi, ysize + int 0x40 +} + +proc draw_button stdcall, x:dword, y:dword, xsize:dword, ysize:dword, \ + id:dword, butcolor:dword, text:dword, textlen:byte, textcolor:dword + + pusha + mov ebx, dword [x] + shl ebx, 16 + add ebx, dword [xsize] ; [x start] *65536 + [x size] + + mov ecx, dword [y] + shl ecx, 16 + add ecx, dword [ysize] ; [y start] *65536 + [y size] + + mov edx, dword [id] ; button id + mov esi, dword [butcolor] ; button color RRGGBB + mov eax, 8 ; function 8 : define and draw button + int 0x40 + + mov ebx, dword [x] + add ebx, 5 + shl ebx, 16 + mov eax, dword [ysize] + sub eax, 5 + shr eax, 1 + add ebx, eax + add ebx, dword [y] ;mov ebx, (x+5)*65536+y+(ysize-5)/2 ; Draw button text + + mov ecx, dword [textcolor] + mov edx, dword [text] + xor eax, eax + mov al, byte [textlen] + mov esi, eax + mov eax, 4 + int 0x40 + popa +ret +endp + +;macro outtextxy x,y,prompt,prompt_len,color +;{ +proc outtextxy stdcall, x:dword, y:dword, prompt:dword, prompt_len:dword, color:dword + pusha + mov eax, 4 + mov ebx, dword [x] ; draw info text with function 4 + shl ebx, 16 + or ebx, dword [y] + mov ecx, dword [color] + mov edx, dword [prompt] + mov esi, dword [prompt_len] + int 0x40 + popa +ret +endp +;} + +;proc bar x:dword, y:dword, xsize:dword, ysize:dword, color:dword +macro bar x, y, xsize, ysize, color +{ + pusha + mov eax, 13 + ;mov ebx, [x] + ;shl ebx, 16 + ;add ebx, [xsize] + ;mov ecx, [y] + ;shl ecx, 16 + ;add ecx, [ysize] + ;mov edx, [color] + mov ebx, x*65536+xsize + mov ecx, y*65536+ysize + mov edx, color + + int 0x40 + popa +;ret +;endp +} + +macro line x1,y1,x2,y2,color +{ + pusha + mov eax, 38 + mov ebx, x1*65536+x2 + mov ecx, y1*65536+y2 + mov edx, color + int 0x40 + popa +} + +macro rectangle x,y,xsize,ysize,color +{ + x2=x+xsize + y2=y+ysize + line x,y,x2,y,color + line x,y,x,y2,color + line x,y2,x2,y2,color + line x2,y,x2,y2,color +} + +macro putpixel x,y,color +{ + mov eax, 1 + mov ebx, x + mov ecx, y + mov edx, color + int 0x40 +} + diff --git a/programs/system/MyKey/trunk/MyKey.asm b/programs/system/MyKey/trunk/MyKey.asm new file mode 100644 index 0000000000..69ae486c91 --- /dev/null +++ b/programs/system/MyKey/trunk/MyKey.asm @@ -0,0 +1,697 @@ +; +; MyKey. Version 0.1. +; +; Author: Asper +; Date of issue: 04.12.2009 +; Compiler: FASM +; Target: KolibriOS +; + +use32 + org 0x0 + + db 'MENUET00' ; 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 + +include "aspAPI.inc" +include 'macros.inc' +include 'editbox_ex.mac' +include 'load_lib.mac' + +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 +C_TEXTCOLOR equ 0x80000000 ; Button caption color +CA_TEXTCOLOR equ 0x80FFFFFF ; Active button caption color + +WIN_X equ 265 +WIN_Y equ 50;175 +WIN_W equ 595 +WIN_H equ 415 ;570 +WIN_COLOR equ 0x04EEEEEE + +BUT_W equ 192;100 +BUT_H equ 23 +BUT_SPACE equ 0 + +MAX_HOTKEYS_NUM equ 15 ; Bad bounding :/. Until we have normal listbox control. +PATH_MAX_CHARS equ 255 + +@use_library + +STARTAPP: + 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 + + 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 + +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 +; @@: + call draw_window + +still: + call reset_modifiers + + mov eax, 10 ; Wait for an event in the queue. + int 0x40 + + cmp al,1 ; redraw request ? + jz red + cmp al,2 ; key in buffer ? + jz key + cmp al,3 ; button in buffer ? + jz button + cmp al,6 + jz mouse + + jmp still + +key: + mov eax, 2 + int 0x40 + + push eax + mcall 66, 3 + mov edx, eax + and edx, 0x00000FFF + mov dword [modifiers], edx + pop eax + + test word [edit1.flags], 10b;ed_focus ; ᫨ 䮪, 室 + jnz .editbox_input + test word [edit2.flags], 10b;ed_focus ; ᫨ 䮪, 室 + jz @f + .editbox_input: + cmp ah, 0x80 ;if key up + ja still + cmp ah, 42 ;LShift + je still + cmp ah, 54 ;RShift + je still + cmp ah, 56 ;Alt + je still + cmp ah, 29 ;Ctrl + je still + cmp ah, 69 ;Pause/Break + je still + +; cmp [keyUpr],0 +; jne still + + call Scan2ASCII + + push dword edit1 + call [edit_box_key] + + push dword edit2 + call [edit_box_key] + jmp still + @@: + + ;------------------------ + mov cl, byte [hotkeys_num] + .test_next_hotkey: + dec cl + mov bl, cl + and ebx, 0xFF + shl ebx, 5 + mov esi, ebx + add ebx, dword Hotkeys.codes + + cmp ah, byte [ebx] + jne @f + + mov edx, dword [ebx] + shr edx, 8 + cmp edx, dword [modifiers] + jne @f + + push eax + mov eax, PATH_MAX_CHARS + mul cl + mov edx, eax + 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: + ;------------------------ + + jmp still + +button: + mov eax, 17 ; Get pressed button code + int 0x40 + cmp ah, 1 ; Test x button + je close_app + + cmp ah, 2 + jne @f + call AddHotKey + jmp red + @@: + + cmp ah, 5 ; Test if pressed buttons + jb still ; is a HotKey button... + mov al, ah + sub al, 5 + cmp al, byte [hotkeys_num] + 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 + 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 + + 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 + + mov esi, ebx + call strlen + mov dword [edit2.size], ecx + mov dword [edit2.pos], ecx + + jmp red ;still + +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 + + +draw_window: + start_draw_window WIN_X,WIN_Y,WIN_W,WIN_H,WIN_COLOR,labelt, 11;labellen-labelt + + push dword edit1 + call [edit_box_draw] + + push dword edit2 + call [edit_box_draw] + + 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 + + mov edx, ebx + sub edx, 5 + shl edx, 5; edx=edx*32 + add edx, dword Hotkeys + + 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: + + add eax, BUT_H+BUT_SPACE + inc ebx + dec cl + jmp @b + @@: + end_draw_window +ret + + +AddHotKey: + mov al, byte [hotkeys_num] + cmp al, MAX_HOTKEYS_NUM + jge .end + 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 + + .end: + ret + + +reset_modifiers: + pusha + mov esi, dword [it_hotkey_addr] + test esi, esi + jz .end_set_mods + + lodsd + + mov cl, al ; set new hotkey + shr eax, 8 + + xor edx, edx + push cx + mov cl, 3 + .next_pair: + shl edx, 4 + mov bl, al + and bl, 3 + + or bl, bl + jz .l1 + + cmp bl, 3 ; both? + jne @f + or dl, 2 + jmp .l1 + @@: + add bl, 2 + or dl, bl + .l1: + shr eax, 2 + dec cl + test cl, cl + jnz .next_pair + + mov bx, dx + and bx, 0xF0F + xchg bl, bh + and dx, 0x0F0 + or dx, bx + pop cx + + mcall 66, 4 + .end_set_mods: + 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 + mov dword [it_hotkey_addr], 0 + +it_set_editbox: + mov al, byte [hotkeys_num] + sub al, 1 + and eax, 0xFF + shl eax, 5 + add eax, dword Hotkeys.names + mov dword [it_edit.text], eax + + mov esi, eax + call strlen + mov dword [it_edit.size], ecx + mov dword [it_edit.pos], ecx + + +it_set_event_mask: + mcall 40, 39 +it_red: + call it_draw_window + +it_still: + mov eax, 10 ; Wait for an event in the queue. + int 0x40 + + 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 + cmp al,6 + jz it_mouse + + jmp it_still + +it_key: + mov eax, 2 + int 0x40 + + mov byte [it_keycode], 0 + stdcall outtextxy, 10, 100, ctrl_key_names, 35, 0 + cmp ah, 0x80 ;if key up + ja .end + cmp ah, 42 ;[Shift] (left) + je .end + cmp ah, 54 ;[Shift] (right) + je .end + cmp ah, 56 ;[Alt] + je .end + cmp ah, 29 ;[Ctrl] + je .end + 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 + call Scan2ASCII + + test word [it_edit.flags], 10b;ed_focus ; ᫨ 䮪, 室 + jz .end + push dword it_edit + call [edit_box_key] + jmp it_still + .end: + + call it_test_key_modifiers + mov al, byte [it_keycode] + test al, al + jz @f + shl edx, 8 + mov dl, al + + mov eax, dword [it_hotkey_addr] + test eax, eax + jnz @f + mov al, byte [hotkeys_num] + sub al, 1 + and eax, 0xFF + shl eax, 5 + add eax, dword Hotkeys.codes + mov dword [eax], edx + mov dword [it_hotkey_addr], eax + + mov cl, dl ; finally set hotkey + shr edx, 8 + mcall 66, 4 + @@: + + jmp it_still + + +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 + .rshift: + test al, 2 ; RShift ? + jz .lctrl + stdcall outtextxy, 184, 100, ctrl_key_names+29, 6, 0x00FF0000 + .lctrl: + test al, 4 ; LCtrl ? + jz .rctrl + stdcall outtextxy, 52, 100, ctrl_key_names+7, 5, 0x00FF0000 + .rctrl: + test al, 8 ; RCtrl ? + jz .lalt + stdcall outtextxy, 148, 100, ctrl_key_names+23, 5, 0x00FF0000 + .lalt: + test al, 0x10 ; LAlt ? + jz .ralt + stdcall outtextxy, 88, 100, ctrl_key_names+13, 4, 0x00FF0000 + .ralt: + test al, 0x20 ; RAlt ? + jz @f + stdcall outtextxy, 118, 100, ctrl_key_names+18, 4, 0x00FF0000 + @@: + pop eax +ret + +it_mouse: + + push dword it_edit + call [edit_box_mouse] + + jmp it_still + +it_draw_window: + start_draw_window WIN_X,WIN_Y+250,225,70,WIN_COLOR,it_labelt, 26;labellen-labelt + + 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 +ret + + +;######################## Input Thread code end ########################## + + +Scan2ASCII: + push esi + mov esi, ascii_keymap + shr eax, 8 + add esi, eax + lodsb + shl eax, 8 + pop esi +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 * +;* edx = pointer to the parametrs * +;******************************************** + +RunProgram: + pusha + mov dword [InfoStructure], 7 ; run program + mov dword [InfoStructure+4], 0 ; flags + mov dword [InfoStructure+8], edx ; pointer to the parametrs + mov dword [InfoStructure+12], 0 ; reserved + 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 + cmp eax, 0 + jl .err_out + .out: + popa + clc + ret + .err_out: + print "Can't load program" + popa + stc + ret + + +; DATA AREA + +; Application Title +labelt db 'MyKey v.0.1' +;mykey_window dd 0 ; Slot number of MyKey + + +;########### Input Thread data start ############ + +; Input Thread Title +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_keycode db 0 +it_hotkey_addr dd 0 +;########### Input Thread data end ############ + +;Button names +AddKeyText db 'Add',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 +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!!! + +sys_path: +system_dir0 db '/sys/lib/' +boxlib_name db 'box_lib.obj',0 + +err_message_found_lib db "Can't find box_lib.obj",0 +head_f_i: +head_f_l db 'System error',0 +err_message_import db 'Error on import box_lib.obj',0 + +align 4 +myimport: +edit_box_draw dd aEdit_box_draw +edit_box_key dd aEdit_box_key +edit_box_mouse dd aEdit_box_mouse +version_ed dd aVersion_ed + dd 0,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 + +;] Data structures for loadlib.mac and editbox_ex.mac + +InfoStructure: + dd 0x0 ; subfunction number + dd 0x0 ; position in the file in bytes + dd 0x0 ; upper part of the position address + dd 0x0 ; number of bytes to read + dd 0x0 ; pointer to the buffer to write data + db 0 + dd 0 ; pointer to the filename + + +I_END: ; End of application code and data marker + + rb 300 ;input thread stack size +input_thread_stack_top: + +ascii_keymap: + db 128 dup(?) +ctrl_key_names db 'LShift LCtrl LAlt RAlt RCtrl RShift',0 + +Hotkeys: ;(name = 32 b) + (modifiers = 3 b) + (keycode = 1 b) = 36 byte 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 + rb MAX_HOTKEYS_NUM*32-3 + .codes: + dd MAX_HOTKEYS_NUM dup (0) diff --git a/programs/system/MyKey/trunk/ReadMe.txt b/programs/system/MyKey/trunk/ReadMe.txt new file mode 100644 index 0000000000..ffdb0922e3 --- /dev/null +++ b/programs/system/MyKey/trunk/ReadMe.txt @@ -0,0 +1,51 @@ +== MyKey== + + MyKey - . + : +1. "Add" +2. + Ctrl, Alt, Shift. +3. . +4. + . +5. , + - . + + : +a. . +b. . +c. . + + : 0.1 + +==== +Asper + + + +==About program MyKey== + + MyKey - is intended to fast load applications by pressing key combinations +on the keyboard. + To add a new hotkey: +1. Press "Add" button. +2. In the appeared dialog window input a new key or a key combination + with Ctrl, Alt, Shift modifiers. +3. Input key name. +4. After that close the dialog window and in the main window select + added button. +5. In the upper text field input path and name of the program to be executed, + 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. + +Version number: 0.1 + +==Author== +Asper + + +mailto: asper.85@mail.ru diff --git a/programs/system/MyKey/trunk/config.inc b/programs/system/MyKey/trunk/config.inc new file mode 100644 index 0000000000..dc70bf9760 --- /dev/null +++ b/programs/system/MyKey/trunk/config.inc @@ -0,0 +1 @@ +__CPU_type fix p5 diff --git a/programs/system/MyKey/trunk/debug.inc b/programs/system/MyKey/trunk/debug.inc new file mode 100644 index 0000000000..8564deb889 --- /dev/null +++ b/programs/system/MyKey/trunk/debug.inc @@ -0,0 +1,162 @@ +;include 'kinc/imports.inc' + +macro debug_print str +{ + local ..string, ..label + + jmp ..label + ..string db str,0 + ..label: + + pushf + pushad + ;mov edx,..string + mov esi, ..string + ;call debug_outstr + call SysMsgBoardStr + popad + popf +} + +dps fix debug_print + +macro debug_print_dec arg +{ + pushf + pushad + if ~arg eq eax + mov eax,arg + end if + call debug_outdec + popad + popf +} + +dpd fix debug_print_dec + +;--------------------------------- +debug_outdec: ;(eax - num, edi-str) + push 10 ;2 + pop ecx ;1 + push -'0' ;2 + .l0: + xor edx,edx ;2 + div ecx ;2 + push edx ;1 + test eax,eax ;2 + jnz .l0 ;2 + .l1: + pop eax ;1 + add al,'0' ;2 + call debug_outchar ; stosb + jnz .l1 ;2 + ret ;1 +;--------------------------------- + +debug_outchar: ; al - char + pushf + pushad + ;mov cl,al + ;mov eax,63 + ;mov ebx,1 + ;int 0x40 + mov bl, al + mov eax, 1 + call SysMsgBoardChar + popad + popf +ret + +;debug_outstr: +; mov eax,63 +; mov ebx,1 +; @@: +; mov cl,[edx] +; test cl,cl +; jz @f +; int 40h +; inc edx +; jmp @b +; @@: +; ret + + +macro newline +{ + dps <13,10> +} + +macro print message +{ + dps message + newline +} + +macro pregs +{ + dps "EAX: " + dpd eax + dps " EBX: " + dpd ebx + newline + dps "ECX: " + dpd ecx + dps " EDX: " + dpd edx + newline +} + +macro debug_print_hex arg +{ + pushf + pushad + if ~arg eq eax + mov eax, arg + end if + call debug_outhex + popad + popf +} +dph fix debug_print_hex + +debug_outhex: + ; eax - number + pushf + pushad + mov edx, 8 + .new_char: + rol eax, 4 + movzx ecx, al + and cl, 0x0f + mov cl, [__hexdigits + ecx] + pushad + mcall 63, 1 + popad + dec edx + jnz .new_char + popad + popf +ret + +SysMsgBoardChar: + mov cl, al + mov eax, 63 + mov ebx, 1 + int 0x40 +ret + +SysMsgBoardStr: + push eax + @@: + lodsb + or al, al + jz @f + call SysMsgBoardChar + jmp @b + @@: + pop eax +ret + + +__hexdigits: + db '0123456789ABCDEF' \ No newline at end of file diff --git a/programs/system/MyKey/trunk/editbox_ex.mac b/programs/system/MyKey/trunk/editbox_ex.mac new file mode 100644 index 0000000000..5e85004670 --- /dev/null +++ b/programs/system/MyKey/trunk/editbox_ex.mac @@ -0,0 +1,79 @@ +ed_struc_size=72 +struc edit_box width,left,top,color,shift_color,focus_border_color,\ + blur_border_color,text_color,max,text,mouse_variable,flags,size,pos +{ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;Bit mask from editbox +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ed_figure_only= 1000000000000000b ; ᨬ +ed_always_focus= 100000000000000b +ed_focus= 10b ;䮪 ਫ +ed_shift_on= 1000b ;᫨ ⠭ - shift,᫨ ⠭, 㦥 - 㤥ন shift +ed_shift_on_off=1111111111110111b +ed_shift= 100b ;砥 ⨨ shift .. ᫨ +ed_shift_off= 1111111111111011b +ed_shift_bac= 10000b ; ⪨ 뤥 shift .. ⠭ 뤥 +ed_shift_bac_cl=1111111111101111b ;⪠ 㤠 뤥 +ed_shift_cl= 1111111111100011b +ed_shift_mcl= 1111111111111011b +ed_left_fl= 100000b +ed_right_fl= 1111111111011111b +ed_offset_fl= 1000000b +ed_offset_cl= 1111111110111111b +ed_insert= 10000000b +ed_insert_cl= 1111111101111111b +ed_mouse_on = 100000000b +ed_mous_adn_b= 100011000b +ed_mouse_on_off=1111111011111111b +ed_height=14 ; + +.width dd width +.left dd left +.top dd top +.color dd color +.shift_color dd shift_color +.focus_border_color dd focus_border_color +.blur_border_color dd blur_border_color +.text_color dd text_color +.max dd max +.text dd text +.mouse_variable dd mouse_variable +.flags dd flags+0 +.size dd size+0 +.pos dd pos+0 +.offset dd 0 +.cl_curs_x dd 0 +.cl_curs_y dd 0 +.shift dd 0 +.shift_old dd 0 +} +struc check_box left,top,ch_text_margin,ch_size,color,border_color,text_color,text,ch_text_length,flags +{ ; ࠬ஢ 祪 +ch_flag_en=10b +.left: dw left ;+0 ; +.top: dw top ; +.ch_text_margin: dd ch_text_margin ;ﭨ אַ㣮쭨 祪 +.ch_size: dd ch_size ;ࠧ 祪 , ਬ 12 +.color: dd color ;梥 祪 +.border_color: dd border_color ;梥 ࠬ +.text_color: dd text_color ;梥 +.text: dd text ; ணࠬ ᯮ ⥪ +.ch_text_length: dd ch_text_length ; ப ᨬ +.flags: dd flags+0 ; 䫠 +} +struc option_box point_gr,left,top,op_text_margin,op_size,color,border_color,text_color,text,op_text_length,flags +{ ; ࠬ஢ 祪 +op_flag_en=10b +.option_group: dd point_gr +.left: dw left ;+0 ; +.top: dw top ; +.ch_text_margin: dd op_text_margin ;ﭨ אַ㣮쭨 祪 +.ch_size: dd op_size ;ࠧ 祪 , ਬ 12 +.color: dd color ;梥 祪 +.border_color: dd border_color ;梥 ࠬ +.text_color: dd text_color ;梥 +.text: dd text ; ணࠬ ᯮ ⥪ +.ch_text_length: dd op_text_length ; ப ᨬ +.flags: dd flags+0 ; 䫠 +} + diff --git a/programs/system/MyKey/trunk/load_lib.mac b/programs/system/MyKey/trunk/load_lib.mac new file mode 100644 index 0000000000..bda5c92e2e --- /dev/null +++ b/programs/system/MyKey/trunk/load_lib.mac @@ -0,0 +1,634 @@ +;08.05.2009 - bugfix +;14.04.2009 - a macros for code load library the box_lib.obj from '/sys/lib/' or current dirrectory. +; The macros for load any library/libraries: +; Copyright (c) 2009, +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are met: +; * Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; * Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; * Neither the name of the nor the +; names of its contributors may be used to endorse or promote products +; derived from this software without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY Alexey Teplov aka ''AS IS'' AND ANY +; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +; DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +;***************************************************************************** +; This macros based on source code: +; - Alexey Teplov / +; Mario79, Mario - Marat Zakiyanov / +; Diamondz - Evgeny Grechnikov / +;------------------------ +; DESCRIPTION +; Macro load_library +; Logick of work. +; A first time we must to check system path, where I belive find a system library. System path is "/sys/lib/". +; If I cannot found my library, i must to check second way. Second way is current dirrectory. +; If we cannot load library, we must show the error message: +; "I'm sorry,the programm cannot found system library box_lib.obj." +; "The find was make on 2 ways: /sys/lib/ and current dirrectory." +; +; +;--------------------------------------------------------------------- +; Macro sys_load_library +; A first time we must to check own path in current dirrectory the program, where I belive find a system library. +; If I cannot found my library, i must to check second way. Second way is system path a "/sys/lib/". +; If we cannot load library, we must show the error message: +; "I'm sorry,the programm cannot found system library box_lib.obj." +; "The find was make on 2 ways: /sys/lib/ and current dirrectory." +; +;--------------------------------------------------------------------- +; How can I use it? +;--------------------------------------------------------------------- +;-Example using single load library +;-universal load library/librarys +;load_library library_name__, cur_dir_path__, library_path__, system_path__, \ +;err_message_found_lib__, head_f_l__, myimport, err_message_import__, head_f_i__ +;-if return code =-1 then exit, else normally work +; cmp eax,-1 +; jz exit +;- Well, if you get +; +;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +;DATA +; . +;system_path__ db '/sys/lib/' +;library_name__ db 'box_lib.obj',0 +; , +;system_path__ db '/sys/lib/box_lib.obj',0 +;... . +;library_name__ db 'box_lib.obj',0 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;err_message_found_lib__ db 'Sorry I cannot found library box_lib.obj',0 +;head_f_i__: +;head_f_l__ db 'System error',0 +;err_message_import__ db 'Error on load import library box_lib.obj',0 + +;myimport: +; +;edit_box_draw dd aEdit_box_draw +;edit_box_key dd aEdit_box_key +;edit_box_mouse dd aEdit_box_mouse +;version_ed dd aVersion_ed +; +;check_box_draw dd aCheck_box_draw +;check_box_mouse dd aCheck_box_mouse +;version_ch dd aVersion_ch +; +;option_box_draw dd aOption_box_draw +;option_box_mouse dd aOption_box_mouse +;version_op dd aVersion_op + +; dd 0 +; dd 0 +; +;aEdit_box_draw db 'edit_box',0 +;aEdit_box_key db 'edit_box_key',0 +;aEdit_box_mouse db 'edit_box_mouse',0 +;aVersion_ed db 'version_ed',0 + +;aCheck_box_draw db 'check_box_draw',0 +;aCheck_box_mouse db 'check_box_mouse',0 +;aVersion_ch db 'version_ch',0 + +;aOption_box_draw db 'option_box_draw',0 +;aOption_box_mouse db 'option_box_mouse',0 +;aVersion_op db 'version_op',0 + +;--------------------------------------------------------------------- +macro @use_library +{ + +local __sc +local lp +local lp1 +local correction +;local end_tr +local exit_ +;/equ +err_message1 equ dword [esp+8] +head1 equ dword [esp+4] + + +__sc.frame equ dword [__sc+0] +__sc.grab equ dword [__sc+4] +__sc.grab_button equ dword [__sc+8] +__sc.grab_button_text equ dword [__sc+12] +__sc.grab_text equ dword [__sc+16] +__sc.work equ dword [__sc+20] +__sc.work_button equ dword [__sc+24] +__sc.work_button_text equ dword [__sc+28] +__sc.work_text equ dword [__sc+32] +__sc.work_graph equ dword [__sc+36] + +;;;;;;;;;;;CALC WIDTH & HIGHT WINDOW & CENTER MONITOR POSITION;;;;;;;;;; +show_err_: +;check memory + push dword [arrea_xx] + pop eax + test eax,eax + jnz @f + + mcall 68,11 + mcall 68,12,4096 + push eax + pop dword [arrea_xx] + + push head1 + pop dword[eax] + + push 0x0 + pop dword[eax+4] + +@@: + mov eax,48 ;get system color + mov ebx,3 + mov ecx,__sc + mov edx,sizeof.system_colors + mcall +;----------------------------------- + xor eax,eax + mov esi,err_message1 + mov ecx,30 +align 4 +lp: add ecx,7 + lodsb + test eax,eax + jnz lp + + push dword [arrea_xx] + pop ebp + +align 4 +@@: add ebp,4 + mov eax,dword [ebp] + + test eax,eax + jnz @b + + push err_message1 + pop dword[ebp] + + mov dword [ebp+4],eax + + mcall 48,5 ;get system window + cmp word[on_x],cx + jae @f; + + sub eax,ecx + shl eax,15 + mov ax,cx + mov dword [on_x],eax + +@@: + add word [on_y],12 + sub bx,word [on_y] + shl ebx,15 + mov bx,word [on_y] + mov dword [on_y],ebx + + ret + + +;;;;;;;;;;;DRAW WINDOW;;;;;;;;;;;;;; +align 4 +start__: + mcall 40,0x5 ;set mask on events rewraw window and get id button. +.red_win: +;draw_window: + mcall 12,1 + + xor eax,eax + mov ebp,dword [arrea_xx] ; set point + mov ebx,dword [on_x] + mov ecx,dword [on_y] + mov edx,__sc.work + or edx,0x33000000 + mov esi,__sc.grab_text + xor edi,edi + mov edi,dword [ebp] ;head1 + mcall + + mov ebx,(10*65536+25-12) + add ebp,4 ;inc index + +@@: + mov eax,4 + add bx,12 + mov ecx,__sc.grab_text + or ecx,0x90000000 + mov edx,dword [ebp] ;err_message1 + mcall + + add ebp,4 ;inc index + + mov eax,dword [ebp] + test eax,eax + jnz @b + + mcall 12,2 +align 4 + +.still: ;main loop + mcall 10 ;wait event + dec eax + jz .red_win + sub eax,2 + jnz .still ;go to main loop +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +.button: + mcall 17 ;get id button + test ah,ah ;if in ah 0, then go to still + jz .still + mcall -1 + ret + +align 4 +__sc system_colors +on_x dd 0x0 +on_y dd 0x0000004E +arrea_xx dd 0x0 +rb 0x50 +end_tr: + +;--------------------------------------------------------------------- +@library_name equ dword [esp+12] +@cur_dir_path equ dword [esp+8] +@library_path equ dword [esp+4] + +align 4 +@copy_path: + mov ebx,@library_name + mov esi,@cur_dir_path + mov edi,@library_path + + xor eax,eax + cld +.lp1: + lodsb + stosb + test eax,eax + jnz .lp1 + mov esi,edi + + std +.lp2: + lodsb + cmp al,'/' + jnz .lp2 + mov edi,esi + mov esi,ebx + add edi,2 + + + cld +.lp3: + lodsb + stosb + test eax,eax + jnz .lp3 +;--------------------------------------------------------------------- + ret +} + + + +macro sys_load_library library_name__, cur_dir_path__, library_path__, system_path__, err_message_found_lib__, head_f_l__, myimport, err_message_import__, head_f_i__ +{ +local end_steep +local exit +;--------------------------------------------------------------------- +; loading Box_Lib library + + mcall 68,19,system_path__ ; load of sys directory + test eax,eax + jnz end_steep + + copy_path library_name__, cur_dir_path__, library_path__ ;the macros making way /current pach a program/+ name system library + + mcall 68,19,library_path__ ; load of alternative + test eax,eax + jnz end_steep + show_error_window err_message_found_lib__, head_f_l__ ;show error message /create window + jmp exit + + +align 4 +end_steep: + + import_boxlib myimport, err_message_import__, head_f_i__ ;import +exit: + test eax,eax + jz @f + + mcall 51,1,start__,end_tr ; + or eax,-1 +@@: + +;--------------------------------------------------------------------- +} + + +macro load_library library_name__, cur_dir_path__, library_path__, system_path__, err_message_found_lib__, head_f_l__, myimport, err_message_import__, head_f_i__ +{ +local end_steep +local exit +;--------------------------------------------------------------------- +; loading Box_Lib library + + copy_path library_name__, cur_dir_path__, library_path__ ;the macros making way /current pach a program/+ name system library + + mcall 68,19,library_path__ ; load of alternative + test eax,eax + jnz end_steep + + mcall 68,19,system_path__ ; load of sys directory + test eax,eax + jnz end_steep + + show_error_window err_message_found_lib__, head_f_l__ ;show error message /create window + jmp exit + +align 4 +end_steep: + + import_boxlib myimport, err_message_import__, head_f_i__ ;import +exit: + test eax,eax + jz @f + + mcall 51,1,start__,end_tr ; + or eax,-1 +@@: + +;--------------------------------------------------------------------- +} +macro sys_load_libraries _start,_end +{ +local exit_lp2 +local lp2 +local lp +local end_steep +local next +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +library_name__ equ [ebp] +cur_dir_path__ equ [ebp+4] +library_path__ equ [ebp+8] +system_path__ equ [ebp+12] +err_message_found_lib__ equ [ebp+16] +head_f_l__ equ [ebp+20] +my_import equ [ebp+24] +err_message_import__ equ [ebp+28] +head_f_i__ equ [ebp+32] +adr_load_lib equ dword [ebp+36] +status_lib equ dword [ebp+40] + + mov ebp,_start + mov ecx,((_end-_start)/ll_struc_size) + +align 4 +lp: push ecx + mcall 68,19,system_path__ ; load of sys directory + test eax,eax + jnz end_steep + + copy_path library_name__, cur_dir_path__, library_path__ ;the macros making way /current pach a program/+ name system library + + mcall 68,19,library_path__ ; load of alternative + test eax,eax + jnz end_steep + + or status_lib,0x1 ; status of code - enable error - not found library + + show_error_window err_message_found_lib__, head_f_l__ ;show error message /create window + jmp next + +align 4 +end_steep: + mov adr_load_lib,eax ;save adr lib in memory + import_boxlib my_import, err_message_import__, head_f_i__ ;import + + test eax,eax + jz next + + or status_lib,0x2 ; status of code - enable error - import error + +next: + pop ecx + add ebp,ll_struc_size + dec ecx + jnz lp + +;---------------------------------- + mov ebp,_start + mov ecx,((_end-_start)/ll_struc_size) + +align 4 +lp2: + mov eax,status_lib + test eax,eax + jz @f + + mcall 51,1,start__,end_tr ; + or eax,-1 + jmp exit_lp2 + +@@: + add ebp,ll_struc_size + dec ecx + jnz lp2 +exit_lp2: +} + +macro load_libraries _start,_end +{ +local lp2 +local exit_lp2 +local lp +local end_steep +local next +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +library_name__ equ [ebp] +cur_dir_path__ equ [ebp+4] +library_path__ equ [ebp+8] +system_path__ equ [ebp+12] +err_message_found_lib__ equ [ebp+16] +head_f_l__ equ [ebp+20] +my_import equ [ebp+24] +err_message_import__ equ [ebp+28] +head_f_i__ equ [ebp+32] +adr_load_lib equ dword [ebp+36] +status_lib equ dword [ebp+40] + + mov ebp,_start + mov ecx,((_end-_start)/ll_struc_size) + +align 4 +lp: push ecx + + copy_path library_name__, cur_dir_path__, library_path__ ;the macros making way /current pach a program/+ name system library + + mcall 68,19,library_path__ ; load of alternative + test eax,eax + jnz end_steep + + mcall 68,19,system_path__ ; load of sys directory + test eax,eax + jnz end_steep + + or status_lib,0x1 ; status of code - enable error - not found library + + show_error_window err_message_found_lib__, head_f_l__ ;show error message /create window + jmp next + +align 4 +end_steep: + mov adr_load_lib,eax ;save adr lib in memory + + import_boxlib my_import, err_message_import__, head_f_i__ ;import + + test eax,eax + jz next + + or status_lib,0x2 ; status of code - enable error - import error + +next: + pop ecx + add ebp,ll_struc_size + dec ecx + jnz lp + +;----------------------------------------------- + mov ebp,_start + mov ecx,((_end-_start)/ll_struc_size) + +align 4 +lp2: + mov eax,status_lib + test eax,eax + jz @f + + mcall 51,1,start__,end_tr ; + or eax,-1 + jmp exit_lp2 + +@@: + add ebp,ll_struc_size + dec ecx + jnz lp2 +exit_lp2: + +} + + +macro copy_path lib_name,dir_path,lib_path +{ + pushad ;save all registers + push dword lib_name + push dword dir_path + push dword lib_path + + call @copy_path + + add esp,12 + popad ;restore all registers +} + +macro show_error_window err_message, head +{ pushad ;save all registers + push dword err_message + push dword head + + call show_err_ + + add esp,8 + popad ;restore all registers + or eax,-1 ; +} + + +macro import_boxlib myimport, err_message_import__, head_f_i__ +{ +local import_loop +local import_find +local lp +local import_find_next +local import_found +local import_done +local exit +local e.exit +local import_not_found +; initialize import + + mov edx, eax + mov esi,myimport +import_loop: + lodsd + test eax, eax + jz import_done + push edx +import_find: + mov ebx, [ds:edx] + test ebx, ebx + jz import_not_found + push eax +lp: + mov cl, [ds:eax] + cmp cl, [ds:ebx] + jnz import_find_next + test cl, cl + jz import_found + inc eax + inc ebx + jmp lp +import_find_next: + pop eax + add edx, 8 + jmp import_find +import_found: + pop eax + mov eax, [ds:edx+4] + mov [esi-4], eax + pop edx + jmp import_loop +import_not_found: + add esp,4 + show_error_window err_message_import__, head_f_i__ ;show error message /create window + jmp e.exit +import_done: + xor eax,eax +e.exit: +;--------------------------------------------------------------------- +} +ll_struc_size = 44;($-library_name__) ; constant size of struct +struc l_libs library_name__, cur_dir_path__, library_path__, system_path__, err_message_found_lib__, head_f_l__, my_import, err_message_import__, head_f_i__; struct for loading libraries +{ +.library_name__ dd library_name__ ; +.cur_dir_path__ dd cur_dir_path__ ; + +.library_path__ dd library_path__ ; , , , , +.complete_path dd system_path__ ; + +.err_message_found_lib__ dd err_message_found_lib__ +.head_f_l__ dd head_f_l__ +.my_import dd my_import +.err_message_import__ dd err_message_import__ +.head_f_i__ dd head_f_i__ + +.adr_load_lib dd 0x0 +.status_lib dd 0x0 ;status of load library +; +} diff --git a/programs/system/MyKey/trunk/macros.inc b/programs/system/MyKey/trunk/macros.inc new file mode 100644 index 0000000000..d4689a5d31 --- /dev/null +++ b/programs/system/MyKey/trunk/macros.inc @@ -0,0 +1,543 @@ +@^ fix macro comment { +^@ fix } + +; ------------------------- +macro library [lname,fname] +{ + forward + dd __#lname#_library_table__,__#lname#_library_name__ + common + dd 0 + forward + align 4 + __#lname#_library_name__ db fname,0 +} + +macro import lname,[name,sname] +{ + common + align 4 + __#lname#_library_table__: + forward + if used name + name dd __#name#_import_name__ + end if + common + dd 0 + forward + if used name + align 4 + __#name#_import_name__ db sname,0 + end if +} + +macro export [name,sname] +{ + forward + dd __#name#_export_name__,name + common + dd 0 + forward + align 4 + __#name#_export_name__ db sname,0 +} +; ------------------------- + +macro m2m dest,src { + push src + pop dest +} + + +macro iglobal { + IGlobals equ IGlobals, + macro __IGlobalBlock { } + +macro uglobal { + UGlobals equ UGlobals, + macro __UGlobalBlock { } + +endg fix } ; Use endg for ending iglobal and uglobal blocks. + + +macro IncludeIGlobals{ + macro IGlobals dummy,[n] \{ __IGlobalBlock + purge __IGlobalBlock \} + match I, IGlobals \{ I \} } + +macro IncludeUGlobals{ + macro UGlobals dummy,[n] \{ + \common + \local begin, size + begin = $ + virtual at $ + \forward + __UGlobalBlock + purge __UGlobalBlock + \common + size = $ - begin + end virtual + rb size + \} + match U, UGlobals \{ U \} } + +uglobal +endg + +iglobal +endg + + +; new application structure +macro meos_app_start + { + use32 + org 0x0 + + db 'MENUET01' + dd 0x01 + dd __start + dd __end + dd __memory + dd __stack + + if used __params & ~defined __params + dd __params + else + dd 0x0 + end if + + dd 0x0 + } +MEOS_APP_START fix meos_app_start + +macro code + { + __start: + } +CODE fix code + +macro data + { + __data: + IncludeIGlobals + } +DATA fix data + +macro udata + { + if used __params & ~defined __params + __params: + db 0 + __end: + rb 255 + else + __end: + end if + __udata: + IncludeUGlobals + } +UDATA fix udata + +macro meos_app_end + { + align 32 + rb 2048 + __stack: + __memory: + } +MEOS_APP_END fix meos_app_end + + +; macro for defining multiline text data +struc mstr [sstring] + { + forward + local ssize + virtual at 0 + db sstring + ssize = $ + end virtual + dd ssize + db sstring + common + dd -1 + } + +; macro for defining multiline text data +struc mls [sstring] + { + forward + local ssize + virtual at 0 + db sstring ; mod + ssize = $ + end virtual + db ssize + db sstring + common + db -1 ; mod + } + + + +; strings +macro sz name,[data] { ; from MFAR [mike.dld] + common + if used name + name db data + .size = $-name + end if +} + +macro lsz name,[lng,data] { ; from MFAR [mike.dld] + common + if used name + label name + forward + if lang eq lng + db data + end if + common + .size = $-name + end if +} + +macro szc name,elsz,[data] { ; from MFAR [mike.dld] + common + local s,m + m = 0 + if used name + label name + forward + virtual at 0 + db data + s = $ + end virtual + d#elsz s + if m < s + m = s + end if + db data + common + .size = $-name + .maxl = m + end if +} + +macro lszc name,elsz,[lng,data] { ; from MFAR [mike.dld] + common + local s,m,c + m = 0 + c = 0 + if used name + label name + forward + if lang eq lng + virtual at 0 + db data + s = $ + end virtual + d#elsz s + if m < s + m = s + end if + db data + c = c+1 + end if + common + .size = $-name + .maxl = m + .count = c + end if +} + + +; easy system call macro +macro mpack dest, hsrc, lsrc +{ + if (hsrc eqtype 0) & (lsrc eqtype 0) + mov dest, (hsrc) shl 16 + lsrc + else + if (hsrc eqtype 0) & (~lsrc eqtype 0) + mov dest, (hsrc) shl 16 + add dest, lsrc + else + mov dest, hsrc + shl dest, 16 + add dest, lsrc + end if + end if +} + +macro __mov reg,a,b { ; mike.dld + if (~a eq)&(~b eq) + mpack reg,a,b + else if (~a eq)&(b eq) + mov reg,a + end if +} + + +include 'config.inc' +;__CPU_type equ p5 +SYSENTER_VAR equ 0 + +macro mcall a,b,c,d,e,f { ; mike.dld, updated by Ghost for Fast System Calls + local ..ret_point + __mov eax,a + __mov ebx,b + __mov ecx,c + __mov edx,d + __mov esi,e + __mov edi,f + + if __CPU_type eq p5 + int 0x40 + else + if __CPU_type eq p6 + push ebp + mov ebp, esp + push ..ret_point ; it may be 2 or 5 byte + sysenter + ..ret_point: + pop edx + pop ecx + + else + if __CPU_type eq k6 + push ecx + syscall + pop ecx + else + display 'ERROR : unknown CPU type (set to p5)', 10, 13 + __CPU_type equ p5 + int 0x40 + end if + end if + end if +} + + +; ------------------------- +macro header a,[b] { + common + use32 + org 0 + db 'MENUET',a + forward + if b eq + dd 0 + else + dd b + end if } +macro section name { align 16 + label name } +macro func name { + if ~used name + display 'FUNC NOT USED: ',`name,13,10 + else + align 4 + name: + ;diff16 `name,0,name +;pushad +;pushfd +;dps `name +;newline +;mcall 5,1 +;popfd +;popad +} +macro endf { end if } + +macro diff16 title,l1,l2 + { + local s,d + s = l2-l1 + display title,': 0x' + repeat 8 + d = '0' + s shr ((8-%) shl 2) and $0F + if d > '9' + d = d + 'A'-'9'-1 + end if + display d + end repeat + display 13,10 + } + +macro diff10 title,l1,l2 + { + local s,d,z,m + s = l2-l1 + z = 0 + m = 1000000000 + display title,': ' + repeat 10 + d = '0' + s / m + s = s - (s/m)*m + m = m / 10 + if d <> '0' + z = 1 + end if + if z <> 0 + display d + end if + end repeat + display 13,10 + } + +; optimize the code for size +__regs fix + +macro add arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + inc arg1 + else + add arg1,arg2 + end if + else + add arg1,arg2 + end if + } + +macro sub arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + dec arg1 + else + sub arg1,arg2 + end if + else + sub arg1,arg2 + end if + } + +macro mov arg1,arg2 + { + if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0')) + if (arg2) = 0 + xor arg1,arg1 + else if (arg2) = 1 + xor arg1,arg1 + inc arg1 + else if (arg2) = -1 + or arg1,-1 + else if (arg2) > -128 & (arg2) < 128 + push arg2 + pop arg1 + else + mov arg1,arg2 + end if + else + mov arg1,arg2 + end if + } + + +macro RGB [a] { + common + match (r=,g=,b),a \{ + \dd ((r) shl 16) or ((g) shl 8) or (b) + \} +} + + +struc POINT _t,_dx,_dy { + .x _t _dx + .y _t _dy +} + +; structure definition helper +include 'struct.inc' + +struct RECT + left dd ? + top dd ? + right dd ? + bottom dd ? +ends + +struct BOX + left dd ? + top dd ? + width dd ? + height dd ? +ends + +; structures used in MeOS +struct process_information + cpu_usage dd ? ; +0 + window_stack_position dw ? ; +4 + window_stack_value dw ? ; +6 + dw ? ; +8 + process_name rb 12 ; +10 + memory_start dd ? ; +22 + used_memory dd ? ; +26 + PID dd ? ; +30 + box BOX ; +34 + slot_state dw ? ; +50 + dw ? ; +52 + client_box BOX ; +54 + wnd_state db ? ; +70 + rb (1024-71) +ends + +struct system_colors + frame dd ? + grab dd ? + grab_button dd ? + grab_button_text dd ? + grab_text dd ? + work dd ? + work_button dd ? + work_button_text dd ? + work_text dd ? + work_graph dd ? +ends + +struct FILEDATE + Second db ? + Minute db ? + Hour db ? + db ? + Day db ? + Month db ? + Year dw ? +ends + +struct FILEINFO + Attributes dd ? + IsUnicode db ? + db 3 dup(?) + DateCreate FILEDATE + DateAccess FILEDATE + DateModify FILEDATE + Size dq ? +ends + +; constants + +; events +EV_IDLE = 0 +EV_TIMER = 0 +EV_REDRAW = 1 +EV_KEY = 2 +EV_BUTTON = 3 +EV_EXIT = 4 +EV_BACKGROUND = 5 +EV_MOUSE = 6 +EV_IPC = 7 +EV_STACK = 8 + +; event mask bits for function 40 +EVM_REDRAW = 1b +EVM_KEY = 10b +EVM_BUTTON = 100b +EVM_EXIT = 1000b +EVM_BACKGROUND = 10000b +EVM_MOUSE = 100000b +EVM_IPC = 1000000b +EVM_STACK = 10000000b diff --git a/programs/system/MyKey/trunk/proc32.inc b/programs/system/MyKey/trunk/proc32.inc new file mode 100644 index 0000000000..23c56b03c1 --- /dev/null +++ b/programs/system/MyKey/trunk/proc32.inc @@ -0,0 +1,268 @@ + +; Macroinstructions for defining and calling procedures + +macro stdcall proc,[arg] ; directly call STDCALL procedure + { common + if ~ arg eq + reverse + pushd arg + common + end if + call proc } + +macro invoke proc,[arg] ; indirectly call STDCALL procedure + { common + if ~ arg eq + reverse + pushd arg + common + end if + call [proc] } + +macro ccall proc,[arg] ; directly call CDECL procedure + { common + size@ccall = 0 + if ~ arg eq + reverse + pushd arg + size@ccall = size@ccall+4 + common + end if + call proc + if size@ccall + add esp,size@ccall + end if } + +macro cinvoke proc,[arg] ; indirectly call CDECL procedure + { common + size@ccall = 0 + if ~ arg eq + reverse + pushd arg + size@ccall = size@ccall+4 + common + end if + call [proc] + if size@ccall + add esp,size@ccall + end if } + +macro proc [args] ; define procedure + { common + match name params, args> + \{ define@proc name, \{ prologue name,flag,parmbytes,localbytes,reglist \} + macro locals + \{ virtual at ebp-localbytes+current + macro label . \\{ deflocal@proc .,:, \\} + struc db [val] \\{ \common deflocal@proc .,db,val \\} + struc dw [val] \\{ \common deflocal@proc .,dw,val \\} + struc dp [val] \\{ \common deflocal@proc .,dp,val \\} + struc dd [val] \\{ \common deflocal@proc .,dd,val \\} + struc dt [val] \\{ \common deflocal@proc .,dt,val \\} + struc dq [val] \\{ \common deflocal@proc .,dq,val \\} + struc rb cnt \\{ deflocal@proc .,rb cnt, \\} + struc rw cnt \\{ deflocal@proc .,rw cnt, \\} + struc rp cnt \\{ deflocal@proc .,rp cnt, \\} + struc rd cnt \\{ deflocal@proc .,rd cnt, \\} + struc rt cnt \\{ deflocal@proc .,rt cnt, \\} + struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} + macro endl + \{ purge label + restruc db,dw,dp,dd,dt,dq + restruc rb,rw,rp,rd,rt,rq + restruc byte,word,dword,pword,tword,qword + current = $-(ebp-localbytes) + end virtual \} + macro ret operand + \{ match any, operand \\{ retn operand \\} + match , operand \\{ match epilogue:reglist, epilogue@proc: + \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} + macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 + end if \} } + +macro defargs@proc [arg] + { common + if ~ arg eq + forward + local ..arg,current@arg + match argname:type, arg + \{ current@arg equ argname + label ..arg type + argname equ ..arg + if dqword eq type + dd ?,?,?,? + else if tbyte eq type + dd ?,?,? + else if qword eq type | pword eq type + dd ?,? + else + dd ? + end if \} + match =current@arg,current@arg + \{ current@arg equ arg + arg equ ..arg + ..arg dd ? \} + common + args@proc equ current@arg + forward + restore current@arg + common + end if } + +macro deflocal@proc name,def,[val] + { common + match vars, all@vars \{ all@vars equ all@vars, \} + all@vars equ all@vars name + forward + local ..var,..tmp + ..var def val + match =?, val \{ ..tmp equ \} + match any =dup (=?), val \{ ..tmp equ \} + match tmp : value, ..tmp : val + \{ tmp: end virtual + initlocal@proc ..var,def value + virtual at tmp\} + common + match first rest, ..var, \{ name equ first \} } + +macro initlocal@proc name,def + { virtual at name + def + size@initlocal = $ - name + end virtual + position@initlocal = 0 + while size@initlocal > position@initlocal + virtual at name + def + if size@initlocal - position@initlocal < 2 + current@initlocal = 1 + load byte@initlocal byte from name+position@initlocal + else if size@initlocal - position@initlocal < 4 + current@initlocal = 2 + load word@initlocal word from name+position@initlocal + else + current@initlocal = 4 + load dword@initlocal dword from name+position@initlocal + end if + end virtual + if current@initlocal = 1 + mov byte [name+position@initlocal],byte@initlocal + else if current@initlocal = 2 + mov word [name+position@initlocal],word@initlocal + else + mov dword [name+position@initlocal],dword@initlocal + end if + position@initlocal = position@initlocal + current@initlocal + end while } + +macro endp + { purge ret,locals,endl + finish@proc + purge finish@proc + restore regs@proc + match all,args@proc \{ restore all \} + restore args@proc + match all,all@vars \{ restore all \} } + +macro local [var] + { common + locals + forward done@local equ + match varname[count]:vartype, var + \{ match =BYTE, vartype \\{ varname rb count + restore done@local \\} + match =WORD, vartype \\{ varname rw count + restore done@local \\} + match =DWORD, vartype \\{ varname rd count + restore done@local \\} + match =PWORD, vartype \\{ varname rp count + restore done@local \\} + match =QWORD, vartype \\{ varname rq count + restore done@local \\} + match =TBYTE, vartype \\{ varname rt count + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + rq count+count + restore done@local \\} + match , done@local \\{ virtual + varname vartype + end virtual + rb count*sizeof.\#vartype + restore done@local \\} \} + match :varname:vartype, done@local:var + \{ match =BYTE, vartype \\{ varname db ? + restore done@local \\} + match =WORD, vartype \\{ varname dw ? + restore done@local \\} + match =DWORD, vartype \\{ varname dd ? + restore done@local \\} + match =PWORD, vartype \\{ varname dp ? + restore done@local \\} + match =QWORD, vartype \\{ varname dq ? + restore done@local \\} + match =TBYTE, vartype \\{ varname dt ? + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + dq ?,? + restore done@local \\} + match , done@local \\{ varname vartype + restore done@local \\} \} + match ,done@local + \{ var + restore done@local \} + common + endl } diff --git a/programs/system/MyKey/trunk/struct.inc b/programs/system/MyKey/trunk/struct.inc new file mode 100644 index 0000000000..947a84e89a --- /dev/null +++ b/programs/system/MyKey/trunk/struct.inc @@ -0,0 +1,180 @@ + +; Macroinstructions for defining data structures + +macro struct name + { fields@struct equ name + match child parent, name \{ fields@struct equ child,fields@\#parent \} + sub@struct equ + struc db [val] \{ \common fields@struct equ fields@struct,.,db, \} + struc dw [val] \{ \common fields@struct equ fields@struct,.,dw, \} + struc du [val] \{ \common fields@struct equ fields@struct,.,du, \} + struc dd [val] \{ \common fields@struct equ fields@struct,.,dd, \} + struc dp [val] \{ \common fields@struct equ fields@struct,.,dp, \} + struc dq [val] \{ \common fields@struct equ fields@struct,.,dq, \} + struc dt [val] \{ \common fields@struct equ fields@struct,.,dt, \} + struc rb count \{ fields@struct equ fields@struct,.,db,count dup (?) \} + struc rw count \{ fields@struct equ fields@struct,.,dw,count dup (?) \} + struc rd count \{ fields@struct equ fields@struct,.,dd,count dup (?) \} + struc rp count \{ fields@struct equ fields@struct,.,dp,count dup (?) \} + struc rq count \{ fields@struct equ fields@struct,.,dq,count dup (?) \} + struc rt count \{ fields@struct equ fields@struct,.,dt,count dup (?) \} + macro db [val] \{ \common \local anonymous + fields@struct equ fields@struct,anonymous,db, \} + macro dw [val] \{ \common \local anonymous + fields@struct equ fields@struct,anonymous,dw, \} + macro du [val] \{ \common \local anonymous + fields@struct equ fields@struct,anonymous,du, \} + macro dd [val] \{ \common \local anonymous + fields@struct equ fields@struct,anonymous,dd, \} + macro dp [val] \{ \common \local anonymous + fields@struct equ fields@struct,anonymous,dp, \} + macro dq [val] \{ \common \local anonymous + fields@struct equ fields@struct,anonymous,dq, \} + macro dt [val] \{ \common \local anonymous + fields@struct equ fields@struct,anonymous,dt, \} + macro rb count \{ \local anonymous + fields@struct equ fields@struct,anonymous,db,count dup (?) \} + macro rw count \{ \local anonymous + fields@struct equ fields@struct,anonymous,dw,count dup (?) \} + macro rd count \{ \local anonymous + fields@struct equ fields@struct,anonymous,dd,count dup (?) \} + macro rp count \{ \local anonymous + fields@struct equ fields@struct,anonymous,dp,count dup (?) \} + macro rq count \{ \local anonymous + fields@struct equ fields@struct,anonymous,dq,count dup (?) \} + macro rt count \{ \local anonymous + fields@struct equ fields@struct,anonymous,dt,count dup (?) \} + macro union \{ fields@struct equ fields@struct,,union,< + sub@struct equ union \} + macro struct \{ fields@struct equ fields@struct,,substruct,< + sub@struct equ substruct \} + virtual at 0 } + +macro ends + { match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt + restruc rb,rw,rd,rp,rq,rt + purge db,dw,du,dd,dp,dq,dt + purge rb,rw,rd,rp,rq,rt + purge union,struct + match name=,fields,fields@struct \\{ fields@struct equ + make@struct name,fields + fields@\\#name equ fields \\} + end virtual \} + match any, sub@struct \{ fields@struct equ fields@struct> \} + restore sub@struct } + +macro make@struct name,[field,type,def] + { common + if $ + display 'Error: definition of ',`name,' contains illegal instructions.',0Dh,0Ah + err + end if + local define + define equ name + forward + local sub + match , field \{ make@substruct type,name,sub def + define equ define,.,sub, \} + match any, field \{ define equ define,.#field,type, \} + common + match fields, define \{ define@struct fields \} } + +macro define@struct name,[field,type,def] + { common + local list + list equ + forward + if ~ field eq . + name#field type def + sizeof.#name#field = $ - name#field + else + rb sizeof.#type + end if + local value + match any, list \{ list equ list, \} + list equ list + common + sizeof.#name = $ + restruc name + match values, list \{ + struc name value \\{ + match any, fields@struct \\\{ fields@struct equ fields@struct,.,name, \\\} + match , fields@struct \\\{ label . + forward + match , value \\\\{ field type def \\\\} + match any, value \\\\{ field type value + if ~ field eq . + rb sizeof.#name#field - ($-field) + end if \\\\} + common \\\} \\} \} } + +macro enable@substruct + { macro make@substruct substruct,parent,name,[field,type,def] + \{ \common + \local define + define equ parent,name + \forward + \local sub + match , field \\{ match any, type \\\{ enable@substruct + make@substruct type,name,sub def + purge make@substruct + define equ define,.,sub, \\\} \\} + match any, field \\{ define equ define,.\#field,type, \\} + \common + match fields, define \\{ define@\#substruct fields \\} \} } + +enable@substruct + +macro define@union parent,name,[field,type,def] + { common + virtual at 0 + forward + if ~ field eq . + virtual at 0 + parent#field type def + sizeof.#parent#field = $ - parent#field + end virtual + if sizeof.#parent#field > $ + rb sizeof.#parent#field - $ + end if + else if sizeof.#type > $ + rb sizeof.#type - $ + end if + common + sizeof.#name = $ + end virtual + struc name [value] \{ \common + label .\#name + last@union equ + forward + match any, last@union \\{ virtual at .\#name + field type def + end virtual \\} + match , last@union \\{ match , value \\\{ field type def \\\} + match any, value \\\{ field type value \\\} \\} + last@union equ field + common rb sizeof.#name - ($ - .\#name) \} } + +macro define@substruct parent,name,[field,type,def] + { common + virtual at 0 + forward + if ~ field eq . + parent#field type def + sizeof.#parent#field = $ - parent#field + else + rb sizeof.#type + end if + local value + common + sizeof.#name = $ + end virtual + struc name value \{ + label .\#name + forward + match , value \\{ field type def \\} + match any, value \\{ field type value + if ~ field eq . + rb sizeof.#parent#field - ($-field) + end if \\} + common \} } diff --git a/programs/system/kerpack/trunk/calltrick2.asm b/programs/system/kerpack/trunk/calltrick2.asm new file mode 100644 index 0000000000..36b04430ca --- /dev/null +++ b/programs/system/kerpack/trunk/calltrick2.asm @@ -0,0 +1,32 @@ + 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 new file mode 100644 index 0000000000..072f90a716 --- /dev/null +++ b/programs/system/kerpack/trunk/doexe2.asm @@ -0,0 +1,68 @@ +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 new file mode 100644 index 0000000000..90568284c5 --- /dev/null +++ b/programs/system/kerpack/trunk/kerpack.asm @@ -0,0 +1,232 @@ +; 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 new file mode 100644 index 0000000000..6e887f371e --- /dev/null +++ b/programs/system/kerpack/trunk/kerpack.bat @@ -0,0 +1,7 @@ +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 new file mode 100644 index 0000000000..3c4ab5b3b7 --- /dev/null +++ b/programs/system/kerpack/trunk/loader_lzma.asm @@ -0,0 +1,404 @@ +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 new file mode 100644 index 0000000000..3f2c501144 Binary files /dev/null and b/programs/system/kerpack/trunk/lzmapack.lib differ diff --git a/programs/system/kerpack/trunk/memset.asm b/programs/system/kerpack/trunk/memset.asm new file mode 100644 index 0000000000..1774128c90 --- /dev/null +++ b/programs/system/kerpack/trunk/memset.asm @@ -0,0 +1,11 @@ +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 diff --git a/programs/system/notify/trunk/@notify.asm b/programs/system/notify/trunk/@notify.asm new file mode 100644 index 0000000000..5ea061706f --- /dev/null +++ b/programs/system/notify/trunk/@notify.asm @@ -0,0 +1,149 @@ + +; +; @notify, pop-up windows +; by Sourcerer, 20.01.2011 +; +;--------------------------------------------------------------------- + + use32 ; включить 32-битный режим ассемблера + org 0x0 ; адресация с нуля + + db 'MENUET01' ; 8-байтный идентификатор MenuetOS + dd 0x01 ; версия заголовка (всегда 1) + dd START ; адрес первой команды + dd I_END ; размер программы + dd 0x1000 ; количество памяти + dd 0x1000 ; адрес вершины стэка + dd I_PARAM ; адрес буфера для параметров + dd 0x0 ; зарезервировано + + +include 'macros.inc' ; + +;--------------------------------------------------------------------- +;--- НАЧАЛО ПРОГРАММЫ ---------------------------------------------- +;--------------------------------------------------------------------- + +START: + +red: ; перерисовать окно + + call draw_window ; вызываем процедуру отрисовки окна + +;--------------------------------------------------------------------- +;--- ЦИКЛ ОБРАБОТКИ СОБЫТИЙ ---------------------------------------- +;--------------------------------------------------------------------- + + + + still: ; main cycle + mov eax, 23 + mov ebx, 500 + mcall + + cmp eax, 0 + je exit + cmp eax, 1 + je red + cmp eax, 2 + je key + cmp eax, 3 + je button + + + + + + button: ; button event handler + mov al, 17 ; get button identifier + mcall + + cmp ah, 1 + jne still ; return if button id != 1 + + or eax, -1 ; exit application + mcall + + key: ; key event handler + mov al, 2 ; get key code + mcall + + jmp still + + exit: + mcall -1 + +;--------------------------------------------------------------------- +;--- ОПРЕДЕЛЕНИЕ И ОТРИСОВКА ОКНА ---------------------------------- +;--------------------------------------------------------------------- + +draw_window: + +mcall 12, 1 ; функция 12: сообщить ОС об отрисовке окна + +mov eax,14 ;получим ширину экрана +mov ebx, 4 +mcall +shr eax, 16 +and eax,0x0000FFFF +sub eax,300 ;отнимем от нее 300 +shl eax, 16 ;и превратим в координаты окна по оси X +add eax,300 +mov ebx, eax + +mov eax, 0 ;и выведем это окно +mov ecx, 30 ;высотой 25 пикс +mov edx, 0x41000000 ;черного цвета и без заголовка +mov esi, 0x01000000 +mcall + +;вывод сеточки +mov eax, 1 ;функция вывода точки +mov edx, 0 ;черного цвета +mov ecx, 30 ;высота окна - 30 пкс +mov esi, 0 ;счетчик сдвига сетки + +drawx: ;рисование линии +sub ecx, 1 ;уменьшаем счетчик линий +cmp ecx, 0 ;закончились линии? +je fin ;значит, хватит рисовать +mov ebx, 300 ;иначе - у нас ширина сетки 300 пкс +cmp esi,1 ;имелся ли сдвиг сетки в прошлой линии? +je sw;если да, то перейдем к sw +mov esi,1 ;иначе - сдвиг был выключен, включим сдвиг +jmp drawy ;перейдем к рисованию + +sw: +mov esi,0 ;выключаем сдвиг сетки + +drawy: ;рисование +sub ebx, 2 ;ставить точки будем через одну +cmp ebx, 0 ;дорисовали ли мы линию? +je drawx ;если да, то переходим к новой +sub ebx, esi ;применяем сдвиг +mcall ;рисуем +add ebx, esi ;возвращаем счетчик на место +jmp drawy ;рисуем новую точку + +fin: ;дорисовали + +mcall 4, <3, 12>, 0x80000000, I_PARAM, 0 ;тень за текстом +mcall 4, <5, 12>, 0x80000000, I_PARAM, 0 ; +mcall 4, <4, 11>, 0x80000000, I_PARAM, 0 ; +mcall 4, <4, 13>, 0x80000000, I_PARAM, 0 ; + mcall 4, <4, 12>, 0x80EFEFEF, I_PARAM, 0 ;текст + + + mcall 12, 2 ; конец рисования + + + ret ; выходим из процедуры + + +;--------------------------------------------------------------------- +;--- ДАННЫЕ ПРОГРАММЫ ---------------------------------------------- +;--------------------------------------------------------------------- + +I_PARAM rb 256 + +I_END: ; метка конца программы diff --git a/programs/system/notify/trunk/@notify.c-- b/programs/system/notify/trunk/@notify.c-- new file mode 100644 index 0000000000..c2df829e2d --- /dev/null +++ b/programs/system/notify/trunk/@notify.c-- @@ -0,0 +1,45 @@ +#include "..\lib\kolibri.h--" +#include "..\lib\memory.h--" +// Kolibri Notify Daemon. v0.1 by SoUrcerer + +dword id; +void main() +{ + + word key; +id=GetScreenWidth(); + +loop() + { + switch(WaitEvent()) + { + case evButton: + id=GetButtonID(); + ExitProcess(); + break; + + case evKey: + key = GetKey(); + ExitProcess(); + break; + + case evReDraw: + draw_window(); + break; + } + Pause (500); + ExitProcess(); + } +} + +void draw_window() +{ + WindowRedrawStatus(1); + DefineAndDrawWindow(id-300,0,300,44,0x30000000,0x1012141F,0,0,"Kolibri Notify"); +// DefineButton(0,300,0,96,0x30000001,0x0) ; + WriteText(7,7,0x80,0xFFFFFF,"Kolibri Notify",0); + WriteText(7,25,0x80,0xEFEFEF,I_Param,0); + WindowRedrawStatus(2); +} + +stop: diff --git a/programs/system/spanel/trunk/build.bat b/programs/system/spanel/trunk/build.bat new file mode 100644 index 0000000000..7e0d468c20 --- /dev/null +++ b/programs/system/spanel/trunk/build.bat @@ -0,0 +1 @@ +fasm spanel.asm spanel \ No newline at end of file diff --git a/programs/system/spanel/trunk/spanel.asm b/programs/system/spanel/trunk/spanel.asm new file mode 100644 index 0000000000..84485b04c1 --- /dev/null +++ b/programs/system/spanel/trunk/spanel.asm @@ -0,0 +1,265 @@ +; +; PANEL SETUP +; +; Compile with FASM for Menuet +; + +use32 + + org 0x0 + + db 'MENUET01' ; 8 byte id + dd 0x01 ; header version + dd START ; start of code + dd I_END ; size of image + dd 0x8000 ; memory for app + dd 0x8000 ; esp + dd 0x0 , 0x0 ; I_Param , I_Icon + +include '..\..\macros.inc' + +START: ; start of execution + + call draw_window + +still: + + mov eax,10 ; wait here for event + int 0x40 + + cmp eax,1 ; redraw request ? + je red + cmp eax,2 ; key in buffer ? + je key + cmp eax,3 ; button in buffer ? + je button + + jmp still + + red: ; redraw + call draw_window + jmp still + + key: ; key + mov eax,2 ; just read it and ignore + int 0x40 + + shr eax,8 + cmp eax,'0' + jb still + cmp eax,'9' + jg still + + mov edi,[ent] + add edi,text + mov esi,edi + inc esi + mov ecx,3 + cld + rep movsb + + mov [edi],al + + call draw_window + jmp still + + button: ; button + mov eax,17 ; get id + int 0x40 + + cmp ah,1 ; button id=1 ? + jne noclose + mov eax,-1 ; close this program + int 0x40 + noclose: + + cmp ah,10 + jne no_apply + + mov esi,text+17 + mov edi,I_END+10 + mov ecx,12 + newfe: + mov ebx,[esi] + mov [edi],ebx + mov [edi+4],byte ';' + add edi,5 + add esi,55 + loop newfe + mov [edi],byte 'x' + + mov eax,70 + mov ebx,dat_write + int 0x40 + + + mov esi,1 + newread: + inc esi + mov eax,9 + mov ebx,I_END + mov ecx,esi + int 0x40 + cmp esi,eax + jg all_terminated + + mov eax,[ebx+10] + and eax,not 0x20202000 + cmp eax,'@PAN' + jne newread + mov eax,[ebx+14] + and eax,not 0x2020 + cmp eax,'EL ' + jne newread + + mov eax,18 + mov ebx,2 + mov ecx,esi + int 0x40 + + mov eax,5 + mov ebx,5 + int 0x40 + + mov esi,1 + + jmp newread + + all_terminated: + + mov eax,5 + mov ebx,25 + int 0x40 + + mov eax, 70 + mov ebx, panel_start + int 0x40 + + no_apply: + + cmp ah,11 + jb no_entry + shr eax,8 + sub eax,11 + imul eax,55 + add eax,17 + mov [ent],eax + mov [text+eax],dword '0000' + call draw_window + jmp still + no_entry: + + + jmp still + + +ent dd 17 + +panel_start: + dd 7 + dd 0 + dd 0 + dd 0 + dd 0 + db '/RD/1/@PANEL',0 + +dat_write: + dd 2 + dq 0 + dd 5*12+1 + dd I_END+10 + db 'PANEL.DAT',0 + +; ********************************************* +; ******* WINDOW DEFINITIONS AND DRAW ******** +; ********************************************* + + +draw_window: + + + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,1 ; 1, start of draw + int 0x40 + + ; DRAW WINDOW + mov eax,0 ; function 0 : define and draw window + mov ebx,100*65536+385 ; [x start] *65536 + [x size] + mov ecx,100*65536+190 ; [y start] *65536 + [y size] + mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl + mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl + mov edi,0x005080d0 ; color of frames RRGGBB + int 0x40 + + ; WINDOW LABEL + mov eax,4 ; function 4 : write text to window + mov ebx,8*65536+8 ; [x start] *65536 + [y start] + mov ecx,0x10ddeeff ; color of text RRGGBB + mov edx,labelt ; pointer to text beginning + mov esi,labellen-labelt ; text length + int 0x40 + + mov eax,8 + mov ebx,25*65536+335 ;160 + mov ecx,162*65536+12 + mov edx,10 + mov esi,0x80a0c0 ;0x6677cc + int 0x40 + + mov eax,8 + mov ebx,340*65536+20 + mov ecx,34*65536+10 + mov edx,11 + newb: + int 0x40 + add ecx,10*65536 + inc edx + cmp edx,23 + jb newb + + mov ebx,25*65536+35 ; draw info text with function 4 + mov ecx,0x224466 + mov edx,text + mov esi,55 + newline: + mov eax,4 + int 0x40 + add ebx,10 + add edx,55 + cmp [edx],byte 'x' + jne newline + + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,2 ; 2, end of draw + int 0x40 + + ret + + +; DATA AREA + + +text: + +db 'width 0000 : 0 for full screen width <' +db 'buttons 0000 : 0 no frames , 1 frames <' +db 'soften_up 0001 : 0 no , 1 yes <' +db 'soften_down 0001 : 0 no , 1 yes <' +db 'minimize_left 0001 : 0 no , 1 yes <' +db 'minimize_right 0001 : 0 no , 1 yes <' +db 'icons_position 0100 : position in pixels <' +db 'menu_enable 0001 : 0 no , 1 yes <' +db 'setup_enable 0001 : 0 no , 1 yes <' +db 'graph_text 0001 : 0 graphics , 1 text <' +db 'soften_middle 0001 : 0 no , 1 yes <' +db 'icons 0001 : 0 start , 1 activate <' +db ' ' +db ' APPLY ' +db 'x' + + +labelt: + db 'PANEL SETUP' +labellen: + +I_END: diff --git a/programs/system/test/trunk/build.bat b/programs/system/test/trunk/build.bat new file mode 100644 index 0000000000..304c33de37 --- /dev/null +++ b/programs/system/test/trunk/build.bat @@ -0,0 +1 @@ +fasm test.asm test \ No newline at end of file diff --git a/programs/system/test/trunk/test.asm b/programs/system/test/trunk/test.asm new file mode 100644 index 0000000000..6554d17db0 --- /dev/null +++ b/programs/system/test/trunk/test.asm @@ -0,0 +1,200 @@ +; +; PROTECTION TEST +; + +use32 + + org 0x0 + + db 'MENUET01' ; 8 byte id + dd 0x01 ; header version + dd START ; start of code + dd I_END ; size of image + dd 0x10000 ; memory for app + dd 0xfff0 ; esp + dd 0x0 , 0x0 ; I_Param , I_Icon + +include '..\..\macros.inc' + +START: ; start of execution + + call draw_window ; at first, draw the window + +still: + + mov eax,10 ; wait here for event + int 0x40 + + cmp eax,1 ; redraw request ? + jz red + cmp eax,2 ; key in buffer ? + jz key + cmp eax,3 ; button in buffer ? + jz button + + jmp still + + red: ; redraw + call draw_window + + jmp still + + key: ; key + mov eax,2 ; just read it and ignore + int 0x40 + + jmp still + + button: ; button + mov eax,17 + int 0x40 + + cmp ah,1 ; button id=1 ? + jnz noclose + mov eax,0xffffffff ; close this program + int 0x40 + noclose: + + cmp ah,2 + jnz notest2 + cli + notest2: + + cmp ah,3 + jnz notest3 + sti + notest3: + + cmp ah,4 + jnz notest4 + mov [0x10000],byte 1 + notest4: + + cmp ah,5 + jnz notest5 + jmp dword 0x10000 + notest5: + + cmp ah,6 + jnz notest6 + mov esp,0 + push eax + notest6: + + cmp ah,7 + jnz notest7 + in al,0x60 + notest7: + + cmp ah,8 + jnz notest8 + out 0x60,al + notest8: + + + + + jmp still + + +; ********************************************* +; ******* WINDOW DEFINITIONS AND DRAW ******** +; ********************************************* + + +draw_window: + + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,1 ; 1, start of draw + int 0x40 + + ; DRAW WINDOW + mov eax,0 ; function 0 : define and draw window + mov ebx,100*65536+300 ; [x start] *65536 + [x size] + mov ecx,100*65536+240 ; [y start] *65536 + [y size] + mov edx,0x02ffffff ; color of work area RRGGBB + mov esi,0x80597799 ; color of grab bar RRGGBB,8->color glide + mov edi,0x00597799 ; color of frames RRGGBB + int 0x40 + + ; 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 edx,tlabel ; pointer to text beginning + mov esi,labellen-tlabel ; text length + int 0x40 + + ; CLOSE BUTTON + mov eax,8 ; function 8 : define and draw button + mov ebx,(300-19)*65536+12 ; [x start] *65536 + [x size] + mov ecx,5*65536+12 ; [y start] *65536 + [y size] + mov edx,1 ; button id + mov esi,0x5977bb ; button color RRGGBB + int 0x40 + + + mov eax,8 ; function 8 : define and draw button + mov ebx,25*65536+9 ; [x start] *65536 + [x size] + mov ecx,74*65536+9 ; [y start] *65536 + [y size] + mov edx,2 ; button id + mov esi,0x5977bb ; button color RRGGBB + newb: + int 0x40 + add ecx,20*65536 + inc edx + cmp edx,9 + jb newb + + cld + mov ebx,25*65536+36 ; draw info text with function 4 + mov ecx,0x000000 + mov edx,text + mov esi,40 + newline: + mov eax,4 + int 0x40 + add ebx,10 + add edx,40 + cmp [edx],byte 'x' + jnz newline + + + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,2 ; 2, end of draw + int 0x40 + + ret + + +; DATA AREA + + +text: + + db 'APPLICATION USES 0x10000 BYTES OF MEMORY' + db ' ' + db 'OPEN DEBUG BOARD FOR PARAMETERS ' + db ' ' + db ' CLI ' + db ' ' + db ' STI ' + db ' ' + db ' MOV [0x10000],BYTE 1 ' + db ' ' + db ' JMP DWORD 0x10000 ' + db ' ' + db ' MOV ESP,0 & PUSH EAX ' + db ' ' + db ' IN Al,0x60 ' + db ' ' + db ' OUT 0x60,AL ' + db 'x ' + + + +tlabel: + db 'MENUET PROTECTION TEST' +labellen: + +I_END: