Subversion Repositories Kolibri OS

Rev

Rev 4850 | Rev 8711 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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