Subversion Repositories Kolibri OS

Rev

Rev 3245 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2.  
  3. SC_OK   = 0
  4. SC_EXIT = 1
  5. SC_PUTC = 2
  6. SC_PUTS = 3
  7. SC_GETC = 4
  8. SC_GETS = 5
  9. SC_CLS  = 6
  10. SC_PID = 7
  11. SC_PING = 8
  12.  
  13. SHM_WRITE =  0x01
  14. SHM_OPEN_ALWAYS = 0x04
  15.  
  16. ;============================
  17.  
  18. align 4
  19. sc_name    rb 64
  20. sc_pid     dd 0
  21. sc_buffer  dd 0
  22. sc_process dd 0
  23.  
  24. ;============================
  25.  
  26. if used _sc_pid2name
  27. align 4
  28. _sc_pid2name:
  29.  
  30.  push esp
  31.  push ebx
  32.  
  33.  xor ecx, ecx
  34.  mov eax, [sc_pid]
  35.  mov ebx, 10
  36. @@:
  37.  xor edx, edx
  38.  div ebx
  39.  push edx
  40.  inc ecx
  41.  test eax, eax
  42.  jnz @b
  43.  
  44. mov edi, sc_name
  45.  
  46. @@:
  47.  pop eax
  48.  add al, '0'
  49.  stosb
  50.  loop @b
  51.  
  52.  
  53.  mov al, '-'
  54.  stosb
  55.  mov al, 'S'
  56.  stosb
  57.  mov al, 'H'
  58.  stosb
  59.  mov al, 'E'
  60.  stosb
  61.  mov al, 'L'
  62.  stosb
  63.  mov al, 'L'
  64.  stosb
  65.  mov al,  0
  66.  stosb
  67.  
  68.  
  69.  pop ebx
  70.  pop esp
  71.  
  72.  ret
  73. end if
  74.  
  75. ;============================
  76.  
  77. if used _sc_init
  78. align 4
  79. ; void __stdcall sc_init();
  80. _sc_init:
  81.  
  82.  push esp
  83.  push ebx
  84.  
  85.  mov eax, 68
  86.  mov ebx, 11
  87.  int 0x40
  88.  
  89.  mov eax, 68 ; ¢ë¤¥«¨âì ¯ ¬ïâì
  90.  mov ebx, 12
  91.  mov ecx, 1024
  92.  int 0x40
  93.  
  94.  mov [sc_process], eax
  95.  
  96.  mov eax, 9 ; ¯®«ãç¨âì ¨­ä®à¬ æ¨î ® ⥪ã饬 ¯à®æ¥áá¥
  97.  mov ebx, [sc_process]
  98.  mov ecx, -1
  99.  int 0x40
  100.  
  101.  mov dword eax, [ebx+30] ; ¯®«ãç ¥¬ PID ⥪饣® ¯à®æ¥áá 
  102.  mov [sc_pid], eax
  103.  
  104.  mov eax, 68 ; ®á¢®¡®¤¨âì ¯ ¬ïâì
  105.  mov ebx, 13
  106.  mov ecx, [sc_process]
  107.  int 0x40
  108.  
  109.  call _sc_pid2name
  110.  
  111.  mov eax, 68 ; ®âªàëâì ¨¬¥­®¢ ­­ãî ®¡« áâì
  112.  mov ebx, 22
  113.  mov dword ecx, sc_name
  114.  mov edx, 4096
  115.  mov esi, SHM_OPEN_ALWAYS or SHM_WRITE
  116.  int 0x40
  117.  
  118.  mov [sc_buffer], eax
  119.  
  120.  pop ebx
  121.  pop esp
  122.  
  123.  ret
  124. end if
  125.  
  126. ;============================
  127.  
  128. if used _sc_puts
  129. align 4
  130. ; void __stdcall sc_puts(char *str);
  131. _sc_puts:
  132.  
  133.  push esp
  134.  push ebx
  135.  
  136.  mov esi, [esp+12]
  137.  mov edi, [sc_buffer]
  138.  mov al, SC_PUTS
  139.  stosb
  140.  
  141. @@:
  142.  lodsb
  143.  stosb
  144.  test al, al
  145.  jnz @b
  146.  
  147.  mov ebx, [sc_buffer]
  148.  
  149. @@:
  150.  mov byte dl, [ebx]
  151.  test dl, dl
  152.  jz @f
  153.  push ebx
  154.  mov eax, 5
  155.  mov ebx, 5
  156.  int 0x40
  157.  pop ebx
  158.  jmp @b
  159.  
  160. @@:
  161.  
  162.  pop ebx
  163.  pop esp
  164.  ret 4
  165. end if
  166.  
  167. ;============================
  168.  
  169. if used _sc_exit
  170. align 4
  171. ; void __stdcall sc_exit();
  172. _sc_exit:
  173.  push ebx
  174.  push esp
  175.  
  176.  mov ebx, [sc_buffer]
  177.  mov byte [ebx], SC_EXIT
  178.  
  179. @@:
  180.  mov byte dl, [ebx]
  181.  test dl, dl
  182.  jz @f
  183.  push ebx
  184.  mov eax, 5
  185.  mov ebx, 5
  186.  int 0x40
  187.  pop ebx
  188.  jmp @b
  189.  
  190. @@:
  191.  mov eax, 68 ;§ ªàëâì ¨¬¥­®¢ ­­ãî ®¡« áâì
  192.  mov ebx, 23
  193.  mov dword ecx, sc_name
  194.  int 0x40
  195.  
  196.  pop esp
  197.  pop ebx
  198.  ret
  199. end if
  200.  
  201.  
  202. ;============================
  203.  
  204. if used _sc_gets
  205. align 4
  206. ; void __stdcall sc_gets(char *str);
  207. _sc_gets:
  208.  
  209.  push esp
  210.  push ebx
  211.  
  212.  mov edi, [esp+12]
  213.  
  214.  mov ebx, [sc_buffer]
  215.  mov byte [ebx], SC_GETS
  216.  
  217. @@:
  218.  mov byte dl, [ebx]
  219.  test dl, dl
  220.  jz @f
  221.  push ebx
  222.  mov eax, 5
  223.  mov ebx, 5
  224.  int 0x40
  225.  pop ebx
  226.  jmp @b
  227.  
  228. @@:
  229.  
  230.  
  231.  mov esi, [sc_buffer]
  232.  inc esi
  233.  
  234. @@:
  235.  lodsb
  236.  stosb
  237.  test al, al
  238.  jnz @b
  239.  
  240.  pop ebx
  241.  pop esp
  242.  ret 4
  243. end if
  244.  
  245. ;============================
  246.  
  247. if used _sc_pid
  248. _sc_pid:
  249. ;int __stdcall sc_pid (void);
  250.         push    ebx ecx
  251.  
  252.         mov     ecx, [sc_buffer]
  253.         mov     byte [ecx], SC_PID
  254.  
  255. @@:
  256.         mov     eax, 5
  257.         mov     ebx, 5
  258.         int     0x40
  259.  
  260.         cmp     byte [ecx], 0
  261.         je      @f
  262.         call    _sc_ping
  263.         test    eax, eax
  264.         jnz     .err
  265.  
  266. @@:
  267.         mov     eax, [ecx+1]
  268.         pop     ecx ebx
  269.         ret
  270.  
  271. .err:
  272.         pop     ecx ebx
  273.         xor     eax, eax
  274.         dec     eax
  275.         ret
  276. end if
  277.  
  278. ;============================
  279.  
  280. if used _sc_ping
  281. _sc_ping:
  282. ;int __stdcall sc_ping (void);
  283.         push    ebx ecx
  284.  
  285.         mov     ecx, [sc_buffer]
  286.         mov     byte [ecx], SC_PING
  287.  
  288.         mov     eax, 5
  289.         mov     ebx, 200
  290.         int     0x40
  291.  
  292.         xor     eax, eax
  293.         cmp     byte [ecx], 0
  294.         je      @f
  295.         dec     eax
  296.  
  297. @@:
  298.         pop     ecx ebx
  299.         ret
  300. end if
  301.