kolibrios-gitea/programs/other/ha/HOTANGLES.ASM
theonlymirage a623f90476 Update roadmap; new mode 3 for Hot Angles
git-svn-id: svn://kolibrios.org@7443 a494cfbc-eb01-0410-851d-a64ba20cac60
2018-10-09 15:03:03 +00:00

658 lines
16 KiB
NASM

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Hot Angles ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Compile with FASM
; Version 0.3.6: Oct 9, 2018
; Copyright (c) 2018, Efremenkov Sergey aka TheOnlyMirage
; All rights reserved.
; Redistribution and use in source and binary forms, with or without modification,
; are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation and/or
; other materials provided with the distribution.
; * Neither the name of the <organization> nor the names of its contributors may
; be used to endorse or promote products derived from this software without
; specific prior written permission.
; THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
; INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
; PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
; --------------------------------------------------------------------------------------
format binary as "" ;"kex"
use32
org 0x0 ; áàçîâûé àäðåñ ðàçìåùåíèÿ êîäà, âñåãäà 0x0
UNLOCKd = 0
LOCKd = 1
; çàãîëîâîê
db 'MENUET01' ;ìàãè÷åñêèé èäåíòèôèêàòîð
dd 0x01 ;âåðñèÿ
dd START_DEBUG ;àäðåñ òî÷êè ñòàðòà ïðîãðàììû
dd I_END ;àäðåñ êîíöà, ïî ôàêòó ðàçìåð ôàéëà ïðîãðàììû
dd 0x100000 ;òðåáóåìîå êîë-âî ïàìÿòè äëÿ çàãðóçêè ïðîãðàììû
dd 0x7fff0 ;íà÷àëüíîå çíà÷åíèå ðåãèñòðà esp - àäðåñ êîíöà îáëàñòè ñòýêà òàê êàê ñòýê ðàñòåò â ñòîðîíó ìåíüøèõ àäðåñîâ
dd 0, 0 ;àäðåñ ñòðîêè ïàðàìåòðîâ è àäðåñ ñòðîêè ïóòè èñïîëíÿåìîãî ôàéëà
include '../../macros.inc'
START_DEBUG:
call copyKill ;ïðîñòåéøàÿ çàùèòà îò ïîâòîðíîãî çàïóñêà
mcall 68, 11 ;èíèöèàëèçàöèÿ êó÷è
call loadConfig ;çàãðóæàåì êîíôèãóðàöèþ ïðèëîæåíèÿ
cmp byte[mode], 0 ;ôóíêöèÿ îòêëþ÷åíà - âûõîä
jne @f
mcall -1
@@:
;ðåæèì æåñòà ïî ãîðÿ÷åé êëàâèøå?
cmp byte[mode], 3 ;ïîäïèñûâàåìñÿ íà èíòåðåñíûå íàì ñîáûòèÿ â çàâèñèìîñòè îò ðåæèìà ðàáîòû
jne @f
mov ebx, 00000100000000000000000000100010b ;åñëè äà, òî ïîäïèñûâàåìñÿ íà êëàâèøè
mcall 40
jmp init03
@@:
;ðåæèì àêòèâàöèè ãîðÿ÷åé êëàâèøåé?
cmp byte[mode], 2 ;ïîäïèñûâàåìñÿ íà èíòåðåñíûå íàì ñîáûòèÿ â çàâèñèìîñòè îò ðåæèìà ðàáîòû
jne @f
mov ebx, 00000100000000000000000000100010b ;åñëè äà, òî ïîäïèñûâàåìñÿ íà êëàâèøè
mcall 40
jmp init02
@@:
; âî âñåõ îñòàëüíûõ ñëó÷àÿõ - êëàññè÷åñêèé ðåæèì ðàáîòû
;mode=1 êëàññè÷åñêèé ðåæèì ðàáîòû - ðåàêöèÿ ïðè íàâåäåíèè â óãîë
mov byte[mode], 1
mov ebx, 00000100000000000000000000100000b
mcall 40
jmp init01
init02:
mov dword[backAdr], mode02
call setHotKey
mode02:
mcall 10
cmp eax, 2 ;îáðàáîòêà íàæàòèÿ êëàâèøè
je hotkey
cmp byte[keyState], 0
je mode02
cmp eax, 6 ;îáðàáîòêà ïåðåìåùåíèé è íàæàòèÿ ìûøè
je mouse
jmp mode02
setHotKey: ;óñòàíîâèòü ãîðÿ÷óþ êëàâèøó
push eax ebx ecx edx
xor ecx, ecx
mov cl, byte[keyActivate] ;íàæàòèå ãîðÿ÷åé êëàâèøè
mov edx, 0x000
mcall 66, 4, ecx, edx
;mov cl, byte[keyActivate]
add cl, 128 ;îòïóñêàíèå ãîðÿ÷åé êëàâèøè
;mov edx, 0x000
mcall 66, 4, ecx, edx
pop edx ecx ebx eax
ret
hotkey:
mcall 2
cmp eax, 1 ;áóôåð êëàâèø ïóñò?
je hotkey.end
cmp al, 2 ;íàñ èíòåðåñóåò òîëüêî ñêàí êîä ãîðÿ÷åé êëàâèøè, èíà÷å âûõîäèì
jne hotkey.end
cmp ah, byte[keyActivate] ;åñëè íàæàòà íàøà ãîðÿ÷àÿ êëàâèøà
jne @f
;for mode 3 [
cmp byte[keyState], 1
je hotkey.e
push eax ebx
mcall 37, 0 ;çàïîìèíàåì òåêóùèå(íà÷àëüíûå) êîîðäèíàòû ìûøè
;mov dword[o.x], eax
mov word[o.y], ax
shr eax, 16
mov word[o.x], ax
pop ebx eax
mov byte[keyState], 1
mov byte[state], UNLOCKd
.e:
;]
;mov byte[state], UNLOCKd
jmp hotkey.end
@@:
push edx
xor edx, edx
mov dl, byte[keyActivate]
add dl, 128
cmp ah, dl ;åñëè îòïóùåíà íàøà ãîðÿ÷àÿ êëàâèøà
jne @f ;hotkey.end
;mov ecx, 0 ;ñòðîêè äëÿ îòëàäêè è òåñòà
;call run_command
mov byte[keyState], 0
mov byte[state], LOCKd
@@:
pop edx
.end:
jmp dword[backAdr]
init01:
mov dword[backAdr], mode01
mode01:
mov eax, 10 ; function 10 : wait until event
mcall ; event type is returned in eax
cmp eax, 6 ;îáðàáîòêà ïåðåìåùåíèé è íàæàòèÿ ìûøè
je mouse
jmp mode01
mouse:
push ebx
mcall 37, 0 ;ïîëó÷àåì òåêóùèå êîîðäèíàòû ìûøè
pop ebx
cmp eax, 0 ;ëåâûé âåðõíèé óãîë
jne @f
; -- çäåñü âûçûâàåì ñîîòâ. âûçîâ äëÿ ëåâîãî âåðõíåãî óãëà (X=0, Y=0)
push ecx
mov ecx, 0
call run_command
pop ecx
jmp dword[backAdr] ;finish
@@:
call get_screen_size ;èíà÷å îáíîâëÿåì ðàçìåðû ýêðàíà
cmp ax, word[screen.height] ;Ymouse = Yscreen ?
je Ytrue
;åñëè Y íå ðàâíû, òî íàñ èíòåðåñóåò Y=0 è X=ScreenWidth (ïðàâûé âåðõíèé óãîë)
cmp ax, 0
jne unlockend
shr eax, 16
cmp ax, word[screen.width]
jne unlockend
; -- çäåñü âûçûâàåì äëÿ ïðàâîãî âåðõåíåãî óãëà
push ecx
mov ecx, 2
call run_command
pop ecx
jmp dword[backAdr]
Ytrue:
;åñëè Y ðàâíû, òî íàñ èíòåðåñóåò X=0 (ëåâûé íèæíèé óãîë) èëè X=ScreenWidth (ïðàâûé íèæíèé)
shr eax, 16
cmp ax, 0
jne @f
; -- X=0, Y = Height (ëåâûé íèæíèé óãîë)
push ecx
mov ecx, 1
call run_command
pop ecx
jmp dword[backAdr]
@@:
cmp ax, word[screen.width]
jne unlockend
; -- (ïðàâûé íèæíèé óãîë)
push ecx
mov ecx, 3
call run_command
pop ecx
jmp dword[backAdr]
unlockend:
mov byte[state], UNLOCKd
jmp dword[backAdr]
;ïîëó÷èòü ðàçìåð ýêðàíà
get_screen_size:
push eax
mcall 14
;òåïåðü â eax = [xsize]*65536 + [ysize]
;mov dword[screen], eax
mov word[screen.height], ax
shr eax, 16
mov word[screen.width], ax
pop eax
ret
;çàïóñê ïðèëîæåíèÿ: ecx - àêòèâíûé óãîë: lu=0, ld=1, ru=2, rd=3
run_command:
cmp byte[state], UNLOCKd
jne run_command.end
; cmp byte[mode], 2 ;åñëè ðåæèì âòîðîé
; jne @f
push eax ebx ecx
cmp ecx, 0
jne @f
mov eax, dword[newData.lu]
mov dword[struct70.path_adr], eax
jmp .end_set_path
@@:
cmp ecx, 1
jne @f
mov eax, dword[newData.ld]
mov dword[struct70.path_adr], eax
jmp .end_set_path
@@:
cmp ecx, 2
jne @f
mov eax, dword[newData.ru]
mov dword[struct70.path_adr], eax
jmp .end_set_path
@@:
cmp ecx, 3
jne .end_set_path
mov eax, dword[newData.rd]
mov dword[struct70.path_adr], eax
jmp .end_set_path
.end_set_path:
;ïàðàìåòðû
;mov dword[struct.adr],
;åñëè àäðåñ 0, òî íè÷åãî íå äåëàòü
cmp dword[struct70.path_adr], 0
jne .next
;mov eax, testData.ld
;mov dword[struct70.path_adr], eax
jmp @f
.next:
;êîíåö êîäà äëÿ çàìåíû
mcall 70, struct70
@@:
mov byte[state], LOCKd
;mov byte[keyState], 0
pop ecx ebx eax
.end:
ret
struct70: ;Ôîðìàò èíôîðìàöèîííîé ñòðóêòóðû
.func dd 7 ; íîìåð ïîäôóíêöèè
.mask dd 0
.param_adr dd 0 ; óêàçàòåëü íà ASCIIZ-ñòðîêó ñ ïàðàìåòðàìè
.other dd 0, 0
.path db 0 ; "/rd/1/TINYPAD",0 ; ïóòü
.path_adr dd 0 ;testData.lu
;èìÿ êîíôèãóðàöèîííîãî ôàéëà
fileName: db 'SETTINGS/HOTANGLES.CFG', 0
loadConfig:
push eax ebx ecx edx
mcall 68, 27, fileName ;çàãðóæàåì êîíôèãóðàöèîííûé ôàéë â ÎÇÓ
cmp eax, 0
je loadConfig.exit ;åñëè ôàéëà êîíôèãóðàöèè íåò, òî çàâåðøàåì ðàáîòó ïðèëîæåíèÿ
;èíà÷å äàííûå çàãðóæåíû â ÎÇÓ, ðàçìåð â edx
cmp edx, 0 ;åñëè ôàéë ïóñò, â í¸ì íåò äàííûõ, òî çàâåðøàåì ðàáîòó
je loadConfig.exit
add edx, eax ;èíà÷å êëàä¸ì â edx - àäðåñ êîíöà ôàéëà
mov byte[mode], 0
cmp byte[eax], '0' ;121 ;'y' ;åñëè ïàðàìåòð àêòèâíîñòè ïðèëîæåíèÿ èìååò ñòàòóñ: íå àêòèâíî
je loadConfig.exit ;òî çàâåðøàåì ðàáîòó ïðèëîæåíèÿ
cmp byte[eax], 110 ;'n'
je loadConfig.exit
;èíà÷å âûñòàâëÿåì ðåæèì
cmp byte[eax], '2' ;ðåæèì àêòèâàöèè ïî ãîðÿ÷åé êëàâèøå
jne @f
mov byte[mode], 2
jmp loadConfig.modeEnd
@@:
cmp byte[eax], '3' ;ðåæèì æåñòà ïðè çàæàòîé êëàâèøå
jne @f
mov byte[mode], 3
jmp loadConfig.modeEnd
@@:
mov byte[mode], 1 ;âî âñåõ îñòàëüíûõ ñëó÷àÿõ - êëàññè÷åñêèé ðåæèì
.modeEnd:
push edi
push esi
; ñîõðàíÿåì â edi óêàçàòåëü íà íà÷àëî òàáëèöû àäðåñîâ íàøèõ êîìàíä
mov edi, newData
; ñîõðàíÿåì àäðåñà ñòðîê è äîáàâëÿåì 0 â êîíöå
mov esi, eax
.block:
inc esi
cmp byte[esi], 10 ;åñëè î÷åðåäíîé êîä ñèìâîëà 10 èëè 13, òî ïðîïóñêàåì ñèìâîëû
je loadConfig.propusk ;äî ïåðâîãî îòëè÷íîãî îò íèõ
cmp byte[esi], 13
je loadConfig.propusk
; ñèìâîë îòëè÷åí îò ïåðåíîñà ñòðîêè è âîçâðàòà êàðåòêè - åñëè ýòî íà çíàê ìèíóñ, òî çàïîìèíàåì åãî
mov dword[edi], esi
add edi, 4
;èä¸ì äî êîíöà ýòîé ñòðîêè: ïîêà íå âñòðåòèì î÷åðåäíîé 10, 13, 0 èëè file end
.while:
inc esi
cmp esi, edx ;òóò áóäåò ïðîáëåìà - òê ôàéë çàêîí÷èëñÿ, à íóëÿ íå áûëî !!! èñïðàâèòü
jae loadConfig.fileend
cmp byte[esi], 10
je loadConfig.ura
cmp byte[esi], 0
je loadConfig.ura
cmp byte[esi], 13
jne loadConfig.while
.ura:
mov byte[esi], 0
;cmp byte[esi-1], '-'
;jne @f
push esi ;åñëè ýòî áûë çíàê ìèíóñ, òî ìåíÿåì àäðåñ íà íîëü
mov esi, dword[edi-4]
cmp byte[esi], '-'
jne @f
cmp byte[esi+1], 0
jne @f
mov dword[edi-4], 0
@@:
pop esi
cmp edi, newDataEnd ;newData.end ;åñëè âñÿ òàáëèöà àäðåñîâ çàïîëíåíà, òî âûõîäèì èç öèêëà
jb loadConfig.block
.fileend:
pop esi
pop edi
jmp loadConfig.end
.propusk:
mov byte[esi], 0
jmp loadConfig.block
.exit:
pop edx ecx ebx eax
mcall -1 ;çàêðûòü ýòó ïðîãðàììó
.end:
pop edx ecx ebx eax
ret
;Âûíåñòè êîä íèæå â îòäåëüíûé îáùèé ìîäóëü
selfName db '@HOTANGLES',0
selfNameSize = 10 ;äî 11 byte
;
compareBytes:
push edi esi ecx ebx
xor eax, eax
mov ecx, selfNameSize ;max ðàçìåð ñòðîê 11
@@:
mov bl, byte[edi]
cmp bl, byte[esi]
jne compareBytes.no
inc edi
inc esi
cmp ecx, 0
je @f
dec ecx
jmp @b
.no:
mov eax, 1
@@:
pop ebx ecx esi edi
ret
;
copyKill:
push eax ebx ecx esi edi
;ñïåðâà ïðî÷ò¸ì ñâîþ èíôîðìàöèþ
mcall 9, buf, -1
mov eax, dword[buf+30]
mov dword[selfPID], eax
;óêàçàòåëè, êîòîðûå íèêîãäà íå ìåíÿþòñÿ:
mov esi, selfName ;ïåðâàÿ ñòðîêà - èìÿ òåêóùåãî ïðèëîæåíèÿ
mov edi, buf ;âòîðàÿ ñòðîêà - èìÿ òåêóùåãî ñëîòà
add edi, 10
mov ecx, 1
@@:
mcall 9, buf, ecx
mov dword[slotMax], eax
;åñëè ýòî ìû ñàìè, òî ïðîïóñêàåì ïðîâåðêó
mov eax, dword[buf+30]
cmp eax, dword[selfPID]
je copyKill.propusk
call compareBytes ;ñðàâíèâàåì 11 áàéò ñòðîê, ðåçóëüòàò â eax
cmp eax, 0
je copyKill.selfKill
.propusk:
inc ecx
cmp ecx, dword[slotMax]
ja @f
jmp @b
.selfKill:
pop edi esi ecx ebx eax
mcall -1
ret
@@:
pop edi esi ecx ebx eax
ret
;MODE 3
init03:
mov dword[radius2], 100; 10*10
mov dword[backAdr], mode03
call setHotKey
mode03:
mcall 10
cmp eax, 2 ;îáðàáîòêà íàæàòèÿ êëàâèøè
je hotkey
;cmp byte[keyState], 0
;je mode03
cmp eax, 6 ;îáðàáîòêà ïåðåìåùåíèé è íàæàòèÿ ìûøè
je mouse03
jmp mode03
mouse03:
cmp byte[keyState], 0 ;åñëè êëàâèøà íå çàæàòà, òî îáíîâèì íà÷àëüíûå êîîðäèíàòû
je mouse03.updateCoord
cmp byte[state], LOCKd ;åñëè óãîë çàáëîêèðîâàí, òî îáíîâèì íà÷àëüíûå êîîðäèíàòû
je mouse03.updateCoord
call checkPointInCircle ;èíà÷å åñëè ïðåîäîëåëè ðàäèóñ àêòèâàöèè, òî âûçûâàåì äåéñòâèå íóæíîãî óãëà
jmp @f
.updateCoord:
push eax ebx
mcall 37, 0 ;çàïîìèíàåì òåêóùèå(íà÷àëüíûå) êîîðäèíàòû ìûøè
;mov dword[o.x], eax
mov word[o.y], ax
shr eax, 16
mov word[o.x], ax
pop ebx eax
@@:
jmp dword[backAdr]
radius2 dd 0 ;êâàäðàò ðàäèóñà äëÿ mode 3
o: ;êîîðäèíàòû íà÷àëüíîé è òåêóùåé òî÷êè
.x: dw 0
.y: dw 0
.cx: dw 0
.cy: dw 0
;ïðîâåðêà âûõîäà çà ïðåäåëû êðóãà
; sqrt( (x2-x1)^2 + (y2-y1)^2 ) <= radius
; (x2-x1)^2 + (y2-y1)^2 <= radius^2
checkPointInCircle:
push eax ebx ecx edx
mcall 37, 0 ;ïîëó÷àåì òåêóùèå êîîðäèíàòû ìûøè
;mov dword[o.cx], eax
mov word[o.cy], ax
shr eax, 16
mov word[o.cx], ax
xor eax, eax
xor edx, edx
mov ax, word[o.x]
mov dx, word[o.cx]
cmp dx, ax
jae @f
sub ax, dx
mov dx, ax
jmp .xend
@@:
sub dx, ax
.xend:
mov eax, edx
mul dx
mov ebx, eax
xor eax, eax
xor edx, edx
mov ax, word[o.y]
mov dx, word[o.cy]
cmp dx, ax
jae @f
sub ax, dx
mov dx, ax
jmp .yend
@@:
sub dx, ax
.yend:
mov eax, edx
mul dx
add ebx, eax
cmp ebx, dword[radius2]
jbe @f
call activateCorner ;èíà÷å àêòèâèðóåì íóæíûé óãîë
@@:
pop edx ecx ebx eax
ret
;âûÿñíèòü â ñòîðîíó êàêîãî óãëà óøëè è àêòèâèðîâàòü åãî
activateCorner:
push eax ecx
xor eax, eax
mov ax, word[o.cx]
cmp ax, word[o.x]
je activateCorner.end ;åñëè êîîðäèíàòà ðàâíà, òî âûõîäèì (òàêîãî áûòü íå äîëæíî)
ja activateCorner.right
;èíà÷å ëåâàÿ ñòîðîíà
mov ax, word[o.cy]
cmp ax, word[o.y]
je activateCorner.end ;åñëè êîîðäèíàòà ðàâíà, òî âûõîäèì (òàêîãî áûòü íå äîëæíî)
jb activateCorner.leftup
;èíà÷å ëåâûé íèæíèé óãîë
mov ecx, 1
call run_command
mov byte[keyState], 0
mov byte[state], LOCKd
jmp activateCorner.end
.leftup:
;ëåâûé âåðõíèé óãîë
mov ecx, 0
call run_command
mov byte[keyState], 0
mov byte[state], LOCKd
jmp activateCorner.end
.right: ;ïðàâàÿ ñòîðîíà ýêðàíà
mov ax, word[o.cy]
cmp ax, word[o.y]
je activateCorner.end ;åñëè êîîðäèíàòà ðàâíà, òî âûõîäèì (òàêîãî áûòü íå äîëæíî)
jb activateCorner.rightup
;èíà÷å ïðàâûé íèæíèé óãîë
mov ecx, 3
call run_command
mov byte[keyState], 0
mov byte[state], LOCKd
jmp activateCorner.end
.rightup:
;ïðàâûé âåðõíèé óãîë
mov ecx, 2
call run_command
mov byte[keyState], 0
mov byte[state], LOCKd
jmp activateCorner.end
.end:
pop ecx eax
ret
keyActivate db 41 ;16 ;'Q' ;êëàâèøà àêòèâàöèè
keyState db 0 ;0-êëàâèøà íå àêòèâíà, 1 - êëàâèøà àêòèâíà
backAdr rd 1 ;àäðåñ äëÿ âîçâðàòà èç ïðîâåðêè ìûøè
;slotMax dd 0
;selfPID dd 0
;buf db 1024 dup(0)
slotMax rd 1
selfPID rd 1
buf rb 1024
;ñòðóêòóðêà äàííûõ äëÿ õðàíåíèÿ ïàðàìåòðîâ ýêðàíà
screen:
.width rw 1
.height rw 1
state: rb 1 ;ñîñòîÿíèå: 0=unlock, 1=lock
mode: rb 1 ;ðåæèì ðàáîòû ïðèëîæåíèÿ: 0=íå ðàáîòàåò, 1=êëàññè÷åñêèé, 2=ïî ãîðÿ÷åé êëàâèøå
newData: ;òàáëè÷êà àäðåñîâ êîìàíäíûõ ñòðîê
.lu rd 1
.ld rd 1
.ru rd 1
.rd rd 1
newDataEnd:
I_END: