Rev 8711 | Rev 9265 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8711 | Rev 9045 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2013-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2013-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 8711 $ |
8 | $Revision: 9045 $ |
9 | 9 | ||
10 | 10 | ||
11 | ;------------------------------------------------------------------------------ |
11 | ;------------------------------------------------------------------------------ |
12 | align 4 |
12 | align 4 |
13 | sys_clipboard: |
13 | sys_clipboard: |
14 | xor eax, eax |
14 | xor eax, eax |
15 | dec eax |
15 | dec eax |
16 | ; check availability of main list |
16 | ; check availability of main list |
17 | cmp [clipboard_main_list], eax |
17 | cmp [clipboard_main_list], eax |
18 | je .exit_1 ; main list area not found |
18 | je .exit_1 ; main list area not found |
19 | 19 | ||
20 | test ebx, ebx ; 0 - Get the number of slots in the clipboard |
20 | test ebx, ebx ; 0 - Get the number of slots in the clipboard |
21 | jnz .1 |
21 | jnz .1 |
22 | ; get the number of slots |
22 | ; get the number of slots |
23 | mov eax, [clipboard_slots] |
23 | mov eax, [clipboard_slots] |
24 | jmp .exit_1 |
24 | jmp .exit_1 |
25 | ;------------------------------------------------------------------------------ |
25 | ;------------------------------------------------------------------------------ |
26 | align 4 |
26 | align 4 |
27 | .1: |
27 | .1: |
28 | dec ebx ; 1 - Read the data from the clipboard |
28 | dec ebx ; 1 - Read the data from the clipboard |
29 | jnz .2 |
29 | jnz .2 |
30 | ; verify the existence of slot |
30 | ; verify the existence of slot |
31 | cmp ecx, [clipboard_slots] |
31 | cmp ecx, [clipboard_slots] |
32 | jae .exit_2 |
32 | jae .exit_2 |
33 | ; get a pointer to the data of slot |
33 | ; get a pointer to the data of slot |
34 | shl ecx, 2 |
34 | shl ecx, 2 |
35 | add ecx, [clipboard_main_list] |
35 | add ecx, [clipboard_main_list] |
36 | mov esi, [ecx] |
36 | mov esi, [ecx] |
37 | mov ecx, [esi] |
37 | mov ecx, [esi] |
38 | ; allocate memory for application for copy the data of slots |
38 | ; allocate memory for application for copy the data of slots |
39 | push ecx |
39 | push ecx |
40 | stdcall user_alloc, ecx |
40 | stdcall user_alloc, ecx |
41 | pop ecx |
41 | pop ecx |
42 | ; copying data of slots |
42 | ; copying data of slots |
43 | mov edi, eax |
43 | mov edi, eax |
44 | cld |
44 | cld |
45 | rep movsb |
45 | rep movsb |
46 | jmp .exit_1 |
46 | jmp .exit_1 |
47 | ;------------------------------------------------------------------------------ |
47 | ;------------------------------------------------------------------------------ |
48 | align 4 |
48 | align 4 |
49 | .2: |
49 | .2: |
50 | dec ebx ; 2 - Write the data to the clipboard |
50 | dec ebx ; 2 - Write the data to the clipboard |
51 | jnz .3 |
51 | jnz .3 |
52 | 52 | ||
53 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
53 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
54 | stdcall is_region_userspace, edx, ecx |
54 | stdcall is_region_userspace, edx, ecx |
55 | jnz @f |
55 | jz @f |
56 | mov eax, -1 |
56 | mov eax, -1 |
57 | jmp .exit_1 |
57 | jmp .exit_1 |
58 | @@: |
58 | @@: |
59 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
59 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
60 | 60 | ||
61 | ; check the lock |
61 | ; check the lock |
62 | mov ebx, clipboard_write_lock |
62 | mov ebx, clipboard_write_lock |
63 | xor eax, eax |
63 | xor eax, eax |
64 | cmp [ebx], eax |
64 | cmp [ebx], eax |
65 | jne .exit_2 |
65 | jne .exit_2 |
66 | ; lock last slot |
66 | ; lock last slot |
67 | inc eax |
67 | inc eax |
68 | mov [ebx], eax |
68 | mov [ebx], eax |
69 | ; check the overflow pointer of slots |
69 | ; check the overflow pointer of slots |
70 | cmp [clipboard_slots], 1024 |
70 | cmp [clipboard_slots], 1024 |
71 | jae .exit_3 |
71 | jae .exit_3 |
72 | ; get memory for new slot |
72 | ; get memory for new slot |
73 | push ebx ecx edx |
73 | push ebx ecx edx |
74 | stdcall kernel_alloc, ecx |
74 | stdcall kernel_alloc, ecx |
75 | pop edx ecx ebx |
75 | pop edx ecx ebx |
76 | test eax, eax |
76 | test eax, eax |
77 | jz .exit_3 |
77 | jz .exit_3 |
78 | ; create a new slot |
78 | ; create a new slot |
79 | mov edi, eax |
79 | mov edi, eax |
80 | mov eax, [clipboard_slots] |
80 | mov eax, [clipboard_slots] |
81 | shl eax, 2 |
81 | shl eax, 2 |
82 | add eax, [clipboard_main_list] |
82 | add eax, [clipboard_main_list] |
83 | mov [eax], edi |
83 | mov [eax], edi |
84 | ; copy the data into the slot |
84 | ; copy the data into the slot |
85 | mov esi, edx |
85 | mov esi, edx |
86 | mov eax, ecx |
86 | mov eax, ecx |
87 | cld |
87 | cld |
88 | stosd ; store size of slot |
88 | stosd ; store size of slot |
89 | sub ecx, 4 |
89 | sub ecx, 4 |
90 | add esi, 4 |
90 | add esi, 4 |
91 | rep movsb ; store slot data |
91 | rep movsb ; store slot data |
92 | ; increase the counter of slots |
92 | ; increase the counter of slots |
93 | inc [clipboard_slots] |
93 | inc [clipboard_slots] |
94 | ; unlock last slot |
94 | ; unlock last slot |
95 | xor eax, eax |
95 | xor eax, eax |
96 | mov [ebx], eax |
96 | mov [ebx], eax |
97 | jmp .exit_1 |
97 | jmp .exit_1 |
98 | ;------------------------------------------------------------------------------ |
98 | ;------------------------------------------------------------------------------ |
99 | align 4 |
99 | align 4 |
100 | .3: |
100 | .3: |
101 | dec ebx ; 3 - Delete the last slot in the clipboard |
101 | dec ebx ; 3 - Delete the last slot in the clipboard |
102 | jnz .4 |
102 | jnz .4 |
103 | ; check the availability of slots |
103 | ; check the availability of slots |
104 | mov eax, [clipboard_slots] |
104 | mov eax, [clipboard_slots] |
105 | test eax, eax |
105 | test eax, eax |
106 | jz .exit_2 |
106 | jz .exit_2 |
107 | ; check the lock |
107 | ; check the lock |
108 | mov ebx, clipboard_write_lock |
108 | mov ebx, clipboard_write_lock |
109 | xor eax, eax |
109 | xor eax, eax |
110 | cmp [ebx], eax |
110 | cmp [ebx], eax |
111 | jne .exit_2 |
111 | jne .exit_2 |
112 | ; lock last slot |
112 | ; lock last slot |
113 | inc eax |
113 | inc eax |
114 | mov [ebx], eax |
114 | mov [ebx], eax |
115 | ; decrease the counter of slots |
115 | ; decrease the counter of slots |
116 | mov eax, clipboard_slots |
116 | mov eax, clipboard_slots |
117 | dec dword [eax] |
117 | dec dword [eax] |
118 | ; free of kernel memory allocated for the slot |
118 | ; free of kernel memory allocated for the slot |
119 | mov eax, [eax] |
119 | mov eax, [eax] |
120 | shl eax, 2 |
120 | shl eax, 2 |
121 | add eax, [clipboard_main_list] |
121 | add eax, [clipboard_main_list] |
122 | mov eax, [eax] |
122 | mov eax, [eax] |
123 | push ebx |
123 | push ebx |
124 | stdcall kernel_free, eax |
124 | stdcall kernel_free, eax |
125 | pop ebx |
125 | pop ebx |
126 | ; unlock last slot |
126 | ; unlock last slot |
127 | xor eax, eax |
127 | xor eax, eax |
128 | mov [ebx], eax |
128 | mov [ebx], eax |
129 | jmp .exit_1 |
129 | jmp .exit_1 |
130 | ;------------------------------------------------------------------------------ |
130 | ;------------------------------------------------------------------------------ |
131 | align 4 |
131 | align 4 |
132 | .4: |
132 | .4: |
133 | dec ebx ; 4 - Emergency discharge of clipboard |
133 | dec ebx ; 4 - Emergency discharge of clipboard |
134 | jnz .exit |
134 | jnz .exit |
135 | ; check the lock |
135 | ; check the lock |
136 | mov ebx, clipboard_write_lock |
136 | mov ebx, clipboard_write_lock |
137 | xor eax, eax |
137 | xor eax, eax |
138 | cmp [ebx], eax |
138 | cmp [ebx], eax |
139 | je .exit_2 |
139 | je .exit_2 |
140 | 140 | ||
141 | ; there should be a procedure for checking the integrity of the slots |
141 | ; there should be a procedure for checking the integrity of the slots |
142 | ; and I will do so in the future |
142 | ; and I will do so in the future |
143 | 143 | ||
144 | ; unlock last slot |
144 | ; unlock last slot |
145 | mov [ebx], eax |
145 | mov [ebx], eax |
146 | jmp .exit |
146 | jmp .exit |
147 | ;------------------------------------------------------------------------------ |
147 | ;------------------------------------------------------------------------------ |
148 | align 4 |
148 | align 4 |
149 | .exit_3: |
149 | .exit_3: |
150 | ; unlock last slot |
150 | ; unlock last slot |
151 | xor eax, eax |
151 | xor eax, eax |
152 | mov [ebx], eax |
152 | mov [ebx], eax |
153 | .exit_2: |
153 | .exit_2: |
154 | xor eax, eax |
154 | xor eax, eax |
155 | inc eax ; error |
155 | inc eax ; error |
156 | .exit_1: |
156 | .exit_1: |
157 | mov [esp + 32], eax |
157 | mov [esp + 32], eax |
158 | .exit: |
158 | .exit: |
159 | ret |
159 | ret |
160 | ;------------------------------------------------------------------------------ |
160 | ;------------------------------------------------------------------------------ |
161 | uglobal |
161 | uglobal |
162 | align 4 |
162 | align 4 |
163 | clipboard_slots dd ? |
163 | clipboard_slots dd ? |
164 | clipboard_main_list dd ? |
164 | clipboard_main_list dd ? |
165 | clipboard_write_lock dd ? |
165 | clipboard_write_lock dd ? |
166 | endg |
166 | endg |
167 | ;------------------------------------------------------------------------------ |
167 | ;------------------------------------------------------------------------------ |