Subversion Repositories Kolibri OS

Rev

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

  1.  
  2.  
  3. ; esi is ptr to nick
  4. ; ebx is ptr to window
  5. align 4
  6. user_add:
  7.  
  8.         cmp     [ebx + window.users], MAX_USERS
  9.         jae     fail
  10.  
  11.         mov     edi, [ebx + window.data_ptr]
  12.         add     edi, window_data.names
  13.         mov     ebp, [ebx + window.users]
  14.         inc     ebp     ; CHECKME
  15.  
  16.         push    esi edi
  17.   .restart:
  18.         mov     ecx, MAX_NICK_LEN
  19.   .loop1:
  20.         lodsb
  21.         cmp     al, '@'
  22.         jne     @f
  23.         mov     al, ' '         ; give @ highest priority
  24.   @@:
  25.         cmp     al, 'A'
  26.         jb      @f
  27.         cmp     al, 'Z'
  28.         ja      @f
  29.         add     al, 'a' - 'A'   ; convert to lowercase
  30.   @@:
  31.         dec     ecx
  32.         jz      .got_it
  33.  
  34.   .loop2:
  35.         mov     dl, [edi]
  36.         cmp     dl, 0
  37.         je      .got_it
  38.         cmp     dl, '@'
  39.         jne     @f
  40.         mov     dl, ' '         ; give @ highest priority
  41.   @@:
  42.         cmp     dl, 'A'
  43.         jb      @f
  44.         cmp     dl, 'Z'
  45.         ja      @f
  46.         add     dl, 'a' - 'A'   ; convert to lowercase
  47.   @@:
  48.         cmp     al, dl
  49.         jb      .got_it
  50.         je      .check_next
  51.  
  52.         pop     edi esi
  53.         add     edi, MAX_NICK_LEN
  54.         push    esi edi
  55.  
  56.         dec     ebp
  57.         jnz     .restart
  58.  
  59.   .check_next:
  60.         inc     edi
  61.         jmp     .loop1
  62.  
  63.   .got_it:
  64.         pop     edi esi
  65.  
  66. ; OK, insert it here..
  67.  
  68. ; mov all trailing usernames by MAX_NICK_LEN bytes
  69.         push    esi edi
  70.         mov     esi, [ebx + window.data_ptr]
  71.         add     esi, window_data.names + MAX_NICK_LEN * (MAX_USERS - 1)
  72.  
  73.         mov     ecx, esi
  74.         sub     ecx, edi
  75.         add     ecx, MAX_NICK_LEN
  76.         shr     ecx, 2
  77.         lea     edi, [esi + MAX_NICK_LEN]
  78.         std
  79.         rep     movsd
  80.         cld
  81.         pop     edi esi
  82.  
  83. ; Now insert our new username
  84.         mov     ecx, MAX_NICK_LEN-1
  85.   .fill:
  86.         lodsb
  87.         cmp     al, ' '
  88.         je      .done
  89.         cmp     al, '!'
  90.         je      .done
  91.         stosb
  92.         loop    .fill
  93.   .done:
  94.         xor     al, al
  95.         stosb
  96.  
  97.         inc     [ebx + window.users]
  98.  
  99.         ret
  100.  
  101.  
  102.  
  103.  
  104.  
  105. ; esi is ptr to nick
  106. ; ebx is ptr to window
  107. align 4
  108. user_remove:
  109.  
  110.         call    user_find
  111.         jz      fail
  112.  
  113.         lea     esi, [edi + MAX_NICK_LEN]
  114.         mov     ecx, [ebx + window.data_ptr]
  115.         add     ecx, window_data.names + MAX_NICK_LEN * MAX_USERS
  116.         sub     ecx, esi
  117.         shr     ecx, 2
  118.         rep     movsd
  119.  
  120.         dec     [ebx + window.users]
  121.         xor     eax, eax
  122.  
  123.         ret
  124.  
  125.  
  126.  
  127. ; IN:
  128. ; esi is ptr to nick
  129. ; ebx is ptr to window
  130. ; OUT:
  131. ; edi is ptr to nick in userlist
  132. align 4
  133. user_find:
  134.  
  135.         mov     eax, [ebx + window.users]
  136.         test    eax, eax
  137.         jz      fail
  138.         mov     edi, [ebx + window.data_ptr]
  139.         add     edi, window_data.names
  140.  
  141.   .loop:
  142.         push    esi edi
  143.         mov     ecx, MAX_NICK_LEN
  144.         repe    cmpsb
  145.         cmp     byte[edi-1], 0
  146.         je      .got_it
  147.         ; TODO: check byte[esi] too!
  148.         pop     edi esi
  149.         add     edi, MAX_NICK_LEN
  150.         dec     eax
  151.         jnz     .loop
  152.         jmp     fail
  153.  
  154.   .got_it:
  155.         pop     edi esi
  156.         test    edi, edi        ; to clear zero flag
  157.  
  158.         ret
  159.  
  160.  
  161. fail:
  162.  
  163.         xor     edi, edi
  164.         ret