Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

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