Rev 4850 | Rev 9045 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4850 | Rev 5363 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2013-2014. 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: 4850 $ |
8 | $Revision: 5363 $ |
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 | ; check the lock |
52 | ; check the lock |
53 | mov ebx, clipboard_write_lock |
53 | mov ebx, clipboard_write_lock |
54 | xor eax, eax |
54 | xor eax, eax |
55 | cmp [ebx], eax |
55 | cmp [ebx], eax |
56 | jne .exit_2 |
56 | jne .exit_2 |
57 | ; lock last slot |
57 | ; lock last slot |
58 | inc eax |
58 | inc eax |
59 | mov [ebx], eax |
59 | mov [ebx], eax |
60 | ; check the overflow pointer of slots |
60 | ; check the overflow pointer of slots |
61 | cmp [clipboard_slots], 1024 |
61 | cmp [clipboard_slots], 1024 |
62 | jae .exit_3 |
62 | jae .exit_3 |
63 | ; get memory for new slot |
63 | ; get memory for new slot |
64 | push ebx ecx edx |
64 | push ebx ecx edx |
65 | stdcall kernel_alloc, ecx |
65 | stdcall kernel_alloc, ecx |
66 | pop edx ecx ebx |
66 | pop edx ecx ebx |
67 | test eax, eax |
67 | test eax, eax |
68 | jz .exit_3 |
68 | jz .exit_3 |
69 | ; create a new slot |
69 | ; create a new slot |
70 | mov edi, eax |
70 | mov edi, eax |
71 | mov eax, [clipboard_slots] |
71 | mov eax, [clipboard_slots] |
72 | shl eax, 2 |
72 | shl eax, 2 |
73 | add eax, [clipboard_main_list] |
73 | add eax, [clipboard_main_list] |
74 | mov [eax], edi |
74 | mov [eax], edi |
75 | ; copy the data into the slot |
75 | ; copy the data into the slot |
76 | mov esi, edx |
76 | mov esi, edx |
77 | mov eax, ecx |
77 | mov eax, ecx |
78 | cld |
78 | cld |
79 | stosd ; store size of slot |
79 | stosd ; store size of slot |
80 | sub ecx, 4 |
80 | sub ecx, 4 |
81 | add esi, 4 |
81 | add esi, 4 |
82 | rep movsb ; store slot data |
82 | rep movsb ; store slot data |
83 | ; increase the counter of slots |
83 | ; increase the counter of slots |
84 | inc [clipboard_slots] |
84 | inc [clipboard_slots] |
85 | ; unlock last slot |
85 | ; unlock last slot |
86 | xor eax, eax |
86 | xor eax, eax |
87 | mov [ebx], eax |
87 | mov [ebx], eax |
88 | jmp .exit_1 |
88 | jmp .exit_1 |
89 | ;------------------------------------------------------------------------------ |
89 | ;------------------------------------------------------------------------------ |
90 | align 4 |
90 | align 4 |
91 | .3: |
91 | .3: |
92 | dec ebx ; 3 - Delete the last slot in the clipboard |
92 | dec ebx ; 3 - Delete the last slot in the clipboard |
93 | jnz .4 |
93 | jnz .4 |
94 | ; check the availability of slots |
94 | ; check the availability of slots |
95 | mov eax, [clipboard_slots] |
95 | mov eax, [clipboard_slots] |
96 | test eax, eax |
96 | test eax, eax |
97 | jz .exit_2 |
97 | jz .exit_2 |
98 | ; check the lock |
98 | ; check the lock |
99 | mov ebx, clipboard_write_lock |
99 | mov ebx, clipboard_write_lock |
100 | xor eax, eax |
100 | xor eax, eax |
101 | cmp [ebx], eax |
101 | cmp [ebx], eax |
102 | jne .exit_2 |
102 | jne .exit_2 |
103 | ; lock last slot |
103 | ; lock last slot |
104 | inc eax |
104 | inc eax |
105 | mov [ebx], eax |
105 | mov [ebx], eax |
106 | ; decrease the counter of slots |
106 | ; decrease the counter of slots |
107 | mov eax, clipboard_slots |
107 | mov eax, clipboard_slots |
108 | dec dword [eax] |
108 | dec dword [eax] |
109 | ; free of kernel memory allocated for the slot |
109 | ; free of kernel memory allocated for the slot |
110 | mov eax, [eax] |
110 | mov eax, [eax] |
111 | shl eax, 2 |
111 | shl eax, 2 |
112 | add eax, [clipboard_main_list] |
112 | add eax, [clipboard_main_list] |
113 | mov eax, [eax] |
113 | mov eax, [eax] |
114 | push ebx |
114 | push ebx |
115 | stdcall kernel_free, eax |
115 | stdcall kernel_free, eax |
116 | pop ebx |
116 | pop ebx |
117 | ; unlock last slot |
117 | ; unlock last slot |
118 | xor eax, eax |
118 | xor eax, eax |
119 | mov [ebx], eax |
119 | mov [ebx], eax |
120 | jmp .exit_1 |
120 | jmp .exit_1 |
121 | ;------------------------------------------------------------------------------ |
121 | ;------------------------------------------------------------------------------ |
122 | align 4 |
122 | align 4 |
123 | .4: |
123 | .4: |
124 | dec ebx ; 4 - Emergency discharge of clipboard |
124 | dec ebx ; 4 - Emergency discharge of clipboard |
125 | jnz .exit |
125 | jnz .exit |
126 | ; check the lock |
126 | ; check the lock |
127 | mov ebx, clipboard_write_lock |
127 | mov ebx, clipboard_write_lock |
128 | xor eax, eax |
128 | xor eax, eax |
129 | cmp [ebx], eax |
129 | cmp [ebx], eax |
130 | je .exit_2 |
130 | je .exit_2 |
131 | 131 | ||
132 | ; there should be a procedure for checking the integrity of the slots |
132 | ; there should be a procedure for checking the integrity of the slots |
133 | ; and I will do so in the future |
133 | ; and I will do so in the future |
134 | 134 | ||
135 | ; unlock last slot |
135 | ; unlock last slot |
136 | mov [ebx], eax |
136 | mov [ebx], eax |
137 | jmp .exit |
137 | jmp .exit |
138 | ;------------------------------------------------------------------------------ |
138 | ;------------------------------------------------------------------------------ |
139 | align 4 |
139 | align 4 |
140 | .exit_3: |
140 | .exit_3: |
141 | ; unlock last slot |
141 | ; unlock last slot |
142 | xor eax, eax |
142 | xor eax, eax |
143 | mov [ebx], eax |
143 | mov [ebx], eax |
144 | .exit_2: |
144 | .exit_2: |
145 | xor eax, eax |
145 | xor eax, eax |
146 | inc eax ; error |
146 | inc eax ; error |
147 | .exit_1: |
147 | .exit_1: |
148 | mov [esp + 32], eax |
148 | mov [esp + 32], eax |
149 | .exit: |
149 | .exit: |
150 | ret |
150 | ret |
151 | ;------------------------------------------------------------------------------ |
151 | ;------------------------------------------------------------------------------ |
152 | uglobal |
152 | uglobal |
153 | align 4 |
153 | align 4 |
154 | clipboard_slots dd ? |
154 | clipboard_slots dd ? |
155 | clipboard_main_list dd ? |
155 | clipboard_main_list dd ? |
156 | clipboard_write_lock dd ? |
156 | clipboard_write_lock dd ? |
157 | endg |
157 | endg |
158 | ;------------------------------------------------------------------------------ |
158 | ;------------------------------------------------------------------------------ |