Subversion Repositories Kolibri OS

Rev

Rev 1816 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1815 yogev_ezra 1
;
2
;   MyKey. Version 0.1.
3
;
4
;   Author:         Asper
5
;   Date of issue:  04.12.2009
6
;   Compiler:       FASM
7
;   Target:         KolibriOS
8
;
9
 
10
use32
11
	org	0x0
12
 
13
	db	'MENUET00'	; 8 byte id
14
	dd	38		; required os
15
	dd	STARTAPP	; program start
16
	dd	I_END		; program image size
17
	dd	0x1000000	 ; required amount of memory
18
	dd	0x00000000	; reserved=no extended header
19
 
20
include "aspAPI.inc"
21
include 'macros.inc'
22
include 'editbox_ex.mac'
23
include 'load_lib.mac'
24
 
25
include 'debug.inc'
26
DEBUG	 equ 0;1
27
 
28
N_KEYCOLOR    equ 0x00EEEEEE ; Normal button color
29
C_KEYCOLOR    equ 0x00CBE1E1 ; Control button color
30
A_KEYCOLOR    equ 0x000099BB;258778 ; Active button color
31
C_TEXTCOLOR   equ 0x80000000 ; Button caption color
32
CA_TEXTCOLOR  equ 0x80FFFFFF ; Active button caption color
33
 
34
WIN_X	   equ 265
35
WIN_Y	   equ 50;175
36
WIN_W	   equ 595
37
WIN_H	   equ 415 ;570
38
WIN_COLOR  equ 0x04EEEEEE
39
 
40
BUT_W	   equ 192;100
41
BUT_H	   equ 23
42
BUT_SPACE  equ 0
43
 
44
MAX_HOTKEYS_NUM equ 15 ;  Bad bounding :/. Until we have normal listbox control.
45
PATH_MAX_CHARS equ 255
46
 
47
@use_library
48
 
49
STARTAPP:
50
	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
51
	cmp	eax,-1
52
	jz	close_app
53
	;mcall 68,11
54
	;or eax,eax
55
	;jz close_app
56
 
57
	mcall	66, 1, 1  ; Set keyboard mode to get scancodes.
58
	mcall	26, 2, 1, ascii_keymap
59
 
60
;get_mykey_window_slot_number:
61
;        mcall   5,  10 ;wait
62
;        mcall   18, 7
63
;        mov     [mykey_window], eax
64
 
65
set_event_mask:
66
	mcall	 40, 39
67
 
68
red:
69
;      .test_slot:
70
;        mov     eax, [mykey_window]              ; Test is receiver MyKey window
71
;        mov     ecx, [it_window]
72
;        cmp     eax, ecx
73
;        je      @f;still                           ; if yes still.
74
;      .activate_it_window:
75
;        mov     eax, 18
76
;        mov     ebx, 3
77
;        int     0x40
78
;      @@:
79
	call	draw_window
80
 
81
still:
82
	call	reset_modifiers
83
 
84
	mov	eax, 10 	      ; Wait for an event in the queue.
85
	int	0x40
86
 
87
	cmp	al,1		      ; redraw request ?
88
	jz	red
89
	cmp	al,2		      ; key in buffer ?
90
	jz	key
91
	cmp	al,3		      ; button in buffer ?
92
	jz	button
93
	cmp	al,6
94
	jz	mouse
95
 
96
	jmp	still
97
 
98
key:
99
	mov	eax, 2
100
	int	0x40
101
 
102
	push	eax
103
	mcall	66, 3
104
	mov	edx, eax
105
	and	edx, 0x00000FFF
106
	mov	dword [modifiers], edx
107
	pop	eax
108
 
109
	test	word [edit1.flags], 10b;ed_focus ; если не в фокусе, выходим
110
	jnz	.editbox_input
111
	test	word [edit2.flags], 10b;ed_focus ; если не в фокусе, выходим
112
	jz	@f
113
     .editbox_input:
114
	cmp	ah, 0x80 ;if key up
115
	ja	still
116
	cmp	ah, 42 ;LShift
117
	je	still
118
	cmp	ah, 54 ;RShift
119
	je	still
120
	cmp	ah, 56 ;Alt
121
	je	still
122
	cmp	ah, 29 ;Ctrl
123
	je	still
124
	cmp	ah, 69 ;Pause/Break
125
	je	still
126
 
127
;    cmp [keyUpr],0
128
;    jne still
129
 
130
    call Scan2ASCII
131
 
132
    push dword edit1
133
    call [edit_box_key]
134
 
135
    push dword edit2
136
    call [edit_box_key]
137
    jmp still
138
  @@:
139
 
140
      ;------------------------
141
	mov	cl, byte [hotkeys_num]
142
      .test_next_hotkey:
143
	dec	cl
144
	mov	bl, cl
145
	and	ebx, 0xFF
146
	shl	ebx, 5
147
	mov	esi, ebx
148
	add	ebx, dword Hotkeys.codes
149
 
150
	cmp	ah, byte [ebx]
151
	jne	@f
152
 
153
	mov	edx, dword [ebx]
154
	shr	edx, 8
155
	cmp	edx, dword [modifiers]
156
	jne	@f
157
 
158
	push	eax
159
	mov	eax, PATH_MAX_CHARS
160
	mul	cl
161
	mov	edx, eax
162
	add	edx, dword buf_cmd_params
163
	add	eax, dword buf_cmd_line
164
	mov	esi, eax
165
	pop	eax
166
	call	RunProgram
167
	jmp	.end_test
168
      @@:
169
	or	cl, cl ;cmp     cl, 0
170
	jnz	.test_next_hotkey ;jge     .test_next_hotkey
171
      .end_test:
172
      ;------------------------
173
 
174
	jmp	still
175
 
176
button:
177
	mov	eax, 17 	    ; Get pressed button code
178
	int	0x40
179
	cmp	ah, 1		    ; Test x button
180
	je	close_app
181
 
182
	cmp	ah, 2
183
	jne	@f
184
	call	AddHotKey
185
	jmp	red
186
       @@:
187
 
188
	cmp	ah, 5		    ; Test if pressed buttons
189
	jb	still		     ; is a HotKey button...
190
	mov	al, ah
191
	sub	al, 5
192
	cmp	al, byte [hotkeys_num]
193
	jnb	still		     ; ...so, if not then still,
194
 
195
 
196
	mov	byte [butt], ah 	  ; if yes then save pressed button ID
197
	and	eax, 0xFF;shr     ax, 8
198
	if DEBUG
199
	   dps	"Button = "
200
	   dph	eax
201
	end if
202
	mov	cl, byte PATH_MAX_CHARS
203
	mul	cl
204
	if DEBUG
205
	   dps	"  offset = "
206
	   dph	eax
207
	end if
208
	mov	ebx, eax
209
	add	ebx, dword buf_cmd_params
210
	add	eax, dword buf_cmd_line
211
 
212
	mov	dword [edit1.text], eax
213
	mov	dword [edit2.text], ebx
214
 
215
	mov	esi, eax
216
	call	strlen
217
	if DEBUG
218
	   dps	"  len = "
219
	   dph	ecx
220
	   newline
221
	end if
222
	mov	dword [edit1.size], ecx
223
	mov	dword [edit1.pos], ecx
224
 
225
	mov	esi, ebx
226
	call	strlen
227
	mov	dword [edit2.size], ecx
228
	mov	dword [edit2.pos], ecx
229
 
230
	jmp	red ;still
231
 
232
mouse:
233
	push	dword edit1
234
	call	[edit_box_mouse]
235
 
236
	push	dword edit2
237
	call	[edit_box_mouse]
238
 
239
	;test    word [edit1.flags],10b;ed_focus ; если не в фокусе, выходим
240
	;jne     still
241
	jmp	still
242
 
243
 
244
close_app:
245
    mov  eax,-1 		 ; close this program
246
    int  0x40
247
 
248
 
249
draw_window:
250
  start_draw_window WIN_X,WIN_Y,WIN_W,WIN_H,WIN_COLOR,labelt, 11;labellen-labelt
251
 
252
  push dword edit1
253
  call [edit_box_draw]
254
 
255
  push dword edit2
256
  call [edit_box_draw]
257
 
258
  stdcall draw_button,	 7,WIN_H-30,80,20,2,C_KEYCOLOR,AddKeyText,   0,C_TEXTCOLOR    ; Add Hot key.
259
 if 0
260
  stdcall draw_button,	90,WIN_H-30,80,20,3,C_KEYCOLOR,DeleteKeyText,0,C_TEXTCOLOR    ; Delete Hot key.
261
  stdcall draw_button, 173,WIN_H-30,80,20,4,C_KEYCOLOR,ManageKeyText,0,C_TEXTCOLOR    ; Manage Hot key.
262
 end if
263
 
264
  movzx ecx, byte [hotkeys_num]
265
  cmp	ecx, MAX_HOTKEYS_NUM
266
  jng	@f
267
  mov	ecx, MAX_HOTKEYS_NUM
268
 @@:
269
  mov	eax, 30
270
  mov	ebx, 5
271
 @@:
272
  or	cl, cl
273
  jz	@f
274
 
275
  mov	edx, ebx
276
  sub	edx, 5
277
  shl	edx, 5; edx=edx*32
278
  add	edx, dword Hotkeys
279
 
280
  cmp	bl, byte [butt]
281
  jne	.l1
282
  stdcall draw_button, 7,eax,BUT_W,BUT_H,ebx,A_KEYCOLOR,edx,0,CA_TEXTCOLOR ; F5
283
  jmp	.l2
284
 .l1:
285
  stdcall draw_button, 7,eax,BUT_W,BUT_H,ebx,N_KEYCOLOR,edx,0,C_TEXTCOLOR ; F5
286
 .l2:
287
 
288
  add	eax, BUT_H+BUT_SPACE
289
  inc	ebx
290
  dec	cl
291
  jmp	@b
292
 @@:
293
  end_draw_window
294
ret
295
 
296
 
297
AddHotKey:
298
	mov	al, byte [hotkeys_num]
299
	cmp	al, MAX_HOTKEYS_NUM
300
	jge	.end
301
	inc	al
302
	mov	byte [hotkeys_num], al
303
 
304
	mov  eax, 51
305
	mov  ebx, 1
306
	mov  ecx, start_input_thread
307
	mov  edx, dword input_thread_stack_top
308
	mcall
309
 
310
    .end:
311
  ret
312
 
313
 
314
reset_modifiers:
315
	pusha
316
	mov	esi, dword [it_hotkey_addr]
317
	test	esi, esi
318
	jz	.end_set_mods
319
 
320
	lodsd
321
 
322
	mov	cl, al ; set new hotkey
323
	shr	eax, 8
324
 
325
	xor    edx, edx
326
	push	cx
327
	mov    cl, 3
328
     .next_pair:
329
	shl    edx, 4
330
	mov    bl, al
331
	and    bl, 3
332
 
333
	or     bl, bl
334
	jz     .l1
335
 
336
	cmp    bl, 3 ; both?
337
	jne    @f
338
	or     dl, 2
339
	jmp    .l1
340
      @@:
341
	add    bl, 2
342
	or     dl, bl
343
      .l1:
344
	shr    eax, 2
345
	dec    cl
346
	test   cl, cl
347
	jnz    .next_pair
348
 
349
	mov    bx, dx
350
	and    bx, 0xF0F
351
	xchg   bl, bh
352
	and    dx, 0x0F0
353
	or     dx, bx
354
	pop    cx
355
 
356
	mcall	66, 4
357
     .end_set_mods:
358
     popa
359
ret
360
 
361
 
362
;######################## Input Thread code start  ##########################
363
 
364
start_input_thread:
365
 
366
;get_it_window_slot_number:
367
;        mcall   5,  10 ;wait
368
;        mcall   18, 7
369
;        mov     [it_window], eax
370
	mov	ecx, 1	   ; to get scancodes.
371
	  mov	  eax, 66
372
	  mov	  ebx, 1     ; Set keyboard mode
373
	  int	  0x40
374
	  mcall   26, 2, 1, ascii_keymap
375
	mov	dword [it_hotkey_addr], 0
376
 
377
it_set_editbox:
378
	mov	al, byte [hotkeys_num]
379
	sub	al, 1
380
	and	eax, 0xFF
381
	shl	eax, 5
382
	add	eax, dword Hotkeys.names
383
	mov	dword [it_edit.text], eax
384
 
385
	mov	esi, eax
386
	call	strlen
387
	mov	dword [it_edit.size], ecx
388
	mov	dword [it_edit.pos], ecx
389
 
390
 
391
it_set_event_mask:
392
	mcall	40, 39
393
it_red:
394
	call	it_draw_window
395
 
396
it_still:
397
	mov	eax, 10 	      ; Wait for an event in the queue.
398
	int	0x40
399
 
400
	cmp	al,1		      ; redraw request ?
401
	jz	it_red
402
	cmp	al,2		      ; key in buffer ?
403
	jz	it_key
404
	cmp	al,3		      ; button in buffer ?
405
	jz	button
406
	cmp	al,6
407
	jz	it_mouse
408
 
409
	jmp	it_still
410
 
411
it_key:
412
	mov	eax, 2
413
	int	0x40
414
 
415
	mov	byte [it_keycode], 0
416
	stdcall outtextxy, 10, 100, ctrl_key_names, 35, 0
417
	cmp	ah, 0x80 ;if key up
418
	ja	.end
419
	cmp	ah, 42 ;[Shift] (left)
420
	je	.end
421
	cmp	ah, 54 ;[Shift] (right)
422
	je	.end
423
	cmp	ah, 56 ;[Alt]
424
	je	.end
425
	cmp	ah, 29 ;[Ctrl]
426
	je	.end
427
	cmp	ah, 69 ;[Pause Break]
428
	je	.end
429
 
430
 
431
      ;------------------------
432
	mov	cl, byte [hotkeys_num]
433
      .test_next_hotkey:
434
	mov	bl, cl
435
	and	ebx, 0xFF
436
	shl	ebx, 5
437
	mov	esi, ebx
438
	add	ebx, dword Hotkeys.codes
439
	cmp	ah, byte [ebx]
440
	jne	@f
441
 
442
	push	eax
443
	mov	eax, PATH_MAX_CHARS
444
	mul	cl
445
	add	eax, dword buf_cmd_line
446
	mov	esi, eax
447
	pop	eax
448
	mov	edx, 0 ; no parametrs yet <- change it!
449
	call	RunProgram
450
	jmp	.end_test
451
      @@:
452
	dec	cl
453
	cmp	cl, 0
454
	jge	.test_next_hotkey
455
      .end_test:
456
      ;------------------------
457
 
458
	mov	byte [it_keycode], ah
459
	call	Scan2ASCII
460
 
461
	test	word [it_edit.flags], 10b;ed_focus ; если не в фокусе, выходим
462
	jz	.end
463
	push	dword it_edit
464
	call	[edit_box_key]
465
	jmp	it_still
466
      .end:
467
 
468
	call	it_test_key_modifiers
469
	mov	al, byte [it_keycode]
470
	test	al, al
471
	jz	@f
472
	shl	edx, 8
473
	mov	dl, al
474
 
475
	mov	eax, dword [it_hotkey_addr]
476
	test	eax, eax
477
	jnz	@f
478
	mov	al, byte [hotkeys_num]
479
	sub	al, 1
480
	and	eax, 0xFF
481
	shl	eax, 5
482
	add	eax, dword Hotkeys.codes
483
	mov	dword [eax], edx
484
	mov	dword [it_hotkey_addr], eax
485
 
486
	mov	cl, dl ; finally set hotkey
487
	shr	edx, 8
488
	mcall	66, 4
489
      @@:
490
 
491
	jmp	it_still
492
 
493
 
494
it_test_key_modifiers:
495
	push	eax
496
	mcall	66, 3 ;get control keys state
497
	mov	edx,  eax
498
	and	edx,  0x00000FFF
499
      .lshift:
500
	test	al, 1  ; LShift ?
501
	jz	.rshift
502
	stdcall outtextxy, 10, 100, ctrl_key_names, 6, 0x00FF0000
503
      .rshift:
504
	test	al, 2  ; RShift ?
505
	jz	.lctrl
506
	stdcall outtextxy, 184, 100, ctrl_key_names+29, 6, 0x00FF0000
507
      .lctrl:
508
	test	al, 4  ; LCtrl ?
509
	jz	.rctrl
510
	stdcall outtextxy, 52, 100, ctrl_key_names+7, 5, 0x00FF0000
511
      .rctrl:
512
	test	al, 8  ; RCtrl ?
513
	jz	.lalt
514
	stdcall outtextxy, 148, 100, ctrl_key_names+23, 5, 0x00FF0000
515
      .lalt:
516
	test	al, 0x10  ; LAlt ?
517
	jz	.ralt
518
	stdcall outtextxy, 88, 100, ctrl_key_names+13, 4, 0x00FF0000
519
      .ralt:
520
	test	al, 0x20  ; RAlt ?
521
	jz	@f
522
	stdcall outtextxy, 118, 100, ctrl_key_names+18, 4, 0x00FF0000
523
      @@:
524
	pop	eax
525
ret
526
 
527
it_mouse:
528
 
529
	push	dword it_edit
530
	call	[edit_box_mouse]
531
 
532
	jmp	it_still
533
 
534
it_draw_window:
535
  start_draw_window WIN_X,WIN_Y+250,225,70,WIN_COLOR,it_labelt, 26;labellen-labelt
536
 
537
  push dword it_edit
538
  call [edit_box_draw]
539
 
540
  stdcall outtextxy, 10, 100, ctrl_key_names, 35, 0
541
  ;stdcall draw_button,   7,WIN_H-30,80,20,2,C_KEYCOLOR,AddKeyText,   0,C_TEXTCOLOR    ; Add Hot key.
542
  end_draw_window
543
ret
544
 
545
 
546
;######################## Input Thread code end ##########################
547
 
548
 
549
Scan2ASCII:
550
	push	esi
551
	mov	esi, ascii_keymap
552
	shr	eax, 8
553
	add	esi, eax
554
	lodsb
555
	shl	eax, 8
556
	pop	esi
557
ret
558
 
559
 
560
;****************************************
561
;*  input:  esi = pointer to string     *
562
;*  output: ecx = length of the string  *
563
;****************************************
564
strlen:
565
      push	eax
566
      xor	ecx, ecx
567
      @@:
568
	lodsb
569
	or	al, al
570
	jz	@f
571
	inc	ecx
572
	jmp	@b
573
      @@:
574
      pop      eax
575
  ret
576
 
577
;********************************************
578
;*  input:  esi = pointer to the file name  *
579
;*          edx = pointer to the parametrs  *
580
;********************************************
581
 
582
RunProgram:
583
    pusha
584
    mov      dword [InfoStructure],    7   ; run program
585
    mov      dword [InfoStructure+4],  0   ; flags
586
    mov      dword [InfoStructure+8],  edx ; pointer to the parametrs
587
    mov      dword [InfoStructure+12], 0   ; reserved
588
    mov      dword [InfoStructure+16], 0   ; reserved
589
    mov      dword [InfoStructure+20], 0   ; reserved
590
    mov      dword [InfoStructure+21], esi ; pointer to the file name
591
    mov      eax, 70
592
    mov      ebx, InfoStructure
593
    int      0x40
594
    cmp      eax, 0
595
    jl	     .err_out
596
  .out:
597
    popa
598
    clc
599
    ret
600
  .err_out:
601
    print    "Can't load program"
602
    popa
603
    stc
604
    ret
605
 
606
 
607
; DATA AREA
608
 
609
; Application Title
610
labelt		db	'MyKey v.0.1'
611
;mykey_window    dd      0          ; Slot number of MyKey
612
 
613
 
614
;########### Input Thread data start ############
615
 
616
; Input Thread Title
617
it_labelt	db	"Input hotkey and it's name"
618
;labellen:
619
it_edit edit_box 180, 20, 30, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, 31, it_buf_cmd_line, 0, 0
620
it_buf_cmd_line   db MAX_HOTKEYS_NUM*32 dup(0)	; !Make it dinamyc!!!
621
;it_window        dd      0          ; Slot number of Input thread
622
it_keycode	  db	  0
623
it_hotkey_addr	  dd	  0
624
;########### Input Thread data end   ############
625
 
626
;Button names
627
AddKeyText     db 'Add',0
628
DeleteKeyText  db 'Delete',0
629
ManageKeyText  db 'Manage',0
630
 
631
 
632
hotkeys_num   db 0;15
633
;keyboard_mode db 0       ; Scan or ASCII keys to send ?  0 - ASCII , 1 - Scan
634
butt	      db 5	  ; Pressed button ID
635
modifiers     dd 0
636
 
637
;Data structures for loadlib.mac and editbox_ex.mac [
638
edit1 edit_box 350, 220, 30, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, PATH_MAX_CHARS+1, buf_cmd_line, 0, 0
639
edit2 edit_box 350, 220, 50, 0xffffff, 0xAA80, 0x0000ff, 0x0, 0x0, PATH_MAX_CHARS+1, buf_cmd_params, 0, 0
640
 
641
buf_cmd_line   db MAX_HOTKEYS_NUM*PATH_MAX_CHARS dup(0)  ; !Make it dinamyc!!!
642
buf_cmd_params db MAX_HOTKEYS_NUM*PATH_MAX_CHARS dup(0)  ; !Make it dinamyc!!!
643
 
644
sys_path:
645
system_dir0 db '/sys/lib/'
646
boxlib_name db 'box_lib.obj',0
647
 
648
err_message_found_lib	db "Can't find box_lib.obj",0
649
head_f_i:
650
head_f_l		db 'System error',0
651
err_message_import	db 'Error on import box_lib.obj',0
652
 
653
align 4
654
myimport:
655
edit_box_draw	dd  aEdit_box_draw
656
edit_box_key	dd  aEdit_box_key
657
edit_box_mouse	dd  aEdit_box_mouse
658
version_ed	dd  aVersion_ed
659
		dd  0,0
660
 
661
aEdit_box_draw	db 'edit_box',0
662
aEdit_box_key	db 'edit_box_key',0
663
aEdit_box_mouse db 'edit_box_mouse',0
664
aVersion_ed	db 'version_ed',0
665
 
666
;] Data structures for loadlib.mac and editbox_ex.mac
667
 
668
InfoStructure:
669
		     dd      0x0     ; subfunction number
670
		     dd      0x0     ; position in the file in bytes
671
		     dd      0x0     ; upper part of the position address
672
		     dd      0x0     ; number of     bytes to read
673
		     dd      0x0     ; pointer to the buffer to write data
674
		     db      0
675
		     dd      0	     ; pointer to the filename
676
 
677
 
678
I_END:			  ; End of application code and data marker
679
 
680
   rb 300 ;input thread stack size
681
input_thread_stack_top:
682
 
683
ascii_keymap:
684
	     db 128 dup(?)
685
ctrl_key_names db  'LShift LCtrl LAlt RAlt RCtrl RShift',0
686
 
687
Hotkeys:  ;(name = 32 b) + (modifiers = 3 b) + (keycode = 1 b) = 36 byte for 1 hotkey
688
    .names:
689
	     db 'My Favorite 1',0
690
	     rb 18
691
	     db 'My Favorite 2',0
692
	     rb 18
693
	     db 'My Favorite 3',0
694
	     rb 18
695
	     rb MAX_HOTKEYS_NUM*32-3
696
    .codes:
697
	     dd MAX_HOTKEYS_NUM dup (0)