Subversion Repositories Kolibri OS

Rev

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

  1. init_cmd_hist_buffer:
  2. ;-------------------------------------------------------------------------------
  3.         push    eax ebx ecx
  4.  
  5.         mcall   68, 12, 4096    ;allocate 4KB block
  6.         mov     [cmd_hist_buffer.ptr], eax
  7.         mov     [cmd_hist_buffer.size], ecx
  8.  
  9.         mov     edi, eax
  10.         xor     eax, eax
  11.         stosd
  12.         stosd
  13.         mov     [cmd_hist_buffer.new_node_offset], eax
  14.         mov     [cmd_hist_buffer.last_node_offset], eax
  15.         mov     [cmd_hist_buffer.cur_node_offset], eax
  16.         mov     [cmd_hist_buffer.tmp_line_flag], al
  17.         mov     [cmd_hist_buffer.n_flag], al
  18.  
  19.         pop     ecx ebx eax
  20.         ret
  21. ;-------------------------------------------------------------------------------
  22.  
  23. enlarge_cmd_hist_buffer:
  24. ;-------------------------------------------------------------------------------
  25.         pusha
  26.  
  27.         mov     ecx, [cmd_hist_buffer.size]
  28.         add     ecx, 4096
  29.         mov     edx, [cmd_hist_buffer.ptr]
  30.         mcall   68, 20          ;reallocate the buffer (prev. size + 4KB)
  31.         test    eax, eax
  32.         jz      .err
  33.         mov     [cmd_hist_buffer.ptr], eax
  34.         mov     [cmd_hist_buffer.size], ecx
  35.  
  36. .ok:
  37.         clc
  38.         popa
  39.         ret
  40.  
  41. .err:
  42.         stc
  43.         popa
  44.         ret
  45. ;-------------------------------------------------------------------------------
  46.  
  47. add_cmd_hist_line:
  48. ;-------------------------------------------------------------------------------
  49. ;in:
  50. ;eax = ptr to ASCIIZ string of line
  51. ;-------------------------------------------------------------------------------
  52.         pusha
  53.  
  54.         mov     esi, eax
  55.         mov     edx, eax
  56.         xor     ecx, ecx
  57.  
  58. @@:
  59.         inc     ecx
  60.         lodsb
  61.         test    al, al
  62.         jz      @f
  63.         jmp     @b
  64.  
  65. @@:
  66.         dec     ecx
  67.         jz      .ok
  68.  
  69.         inc     ecx
  70.  
  71.         mov     eax, [cmd_hist_buffer.new_node_offset]
  72.         lea     eax, [eax+ecx+2*4]
  73.         cmp     [cmd_hist_buffer.size], eax
  74.         jae     @f
  75.         call    enlarge_cmd_hist_buffer
  76.         jc      .err
  77.  
  78. @@:
  79.         mov     edi, [cmd_hist_buffer.new_node_offset]
  80.         mov     eax, [cmd_hist_buffer.ptr]
  81.         add     edi, eax
  82.         cmp     eax, edi                ;if eax = edi, then it's the first node
  83.         jne     @f
  84.         xor     eax, eax
  85.         dec     eax
  86.         stosd                           ;save previous node link = -1 for the first node
  87.         stosd                           ;save next node link = -1 for the first node
  88.         jmp     .cp_str
  89.  
  90. @@:
  91.         mov     ebx, [cmd_hist_buffer.last_node_offset]
  92.         mov     [edi], ebx              ;save previous node link for a new node
  93.         add     ebx, eax
  94.         mov     eax, [cmd_hist_buffer.new_node_offset]
  95.         mov     [ebx+4], eax            ;update next node link for a last node
  96.         mov     [cmd_hist_buffer.last_node_offset], eax
  97.         mov     [cmd_hist_buffer.cur_node_offset], eax
  98.         add     edi, 4
  99.         xor     eax, eax
  100.         dec     eax
  101.         stosd
  102.  
  103. .cp_str:
  104.         mov     esi, edx
  105.  
  106.         push    ecx
  107.         rep     movsb
  108.         pop     ecx
  109.  
  110.         add     ecx, 2*4
  111.         add     [cmd_hist_buffer.new_node_offset], ecx
  112.  
  113.  
  114. .ok:
  115.         clc
  116.  
  117. .err:
  118.         mov     [cmd_hist_buffer.tmp_line_flag], 0
  119.  
  120.         popa
  121.         ret
  122. ;-------------------------------------------------------------------------------
  123.  
  124. add_cmd_hist_tmp_line:
  125. ;-------------------------------------------------------------------------------
  126. ;in:
  127. ;eax = ptr to ASCIIZ string of line
  128. ;-------------------------------------------------------------------------------
  129.         pusha
  130.  
  131.         mov     esi, eax
  132.         mov     edx, eax
  133.         xor     ecx, ecx
  134.  
  135. @@:
  136.         inc     ecx
  137.         lodsb
  138.         test    al, al
  139.         jz      @f
  140.         jmp     @b
  141.  
  142. @@:
  143.         mov     eax, [cmd_hist_buffer.new_node_offset]
  144.         lea     eax, [eax+ecx+2*4]
  145.         cmp     [cmd_hist_buffer.size], eax
  146.         jae     @f
  147.         call    enlarge_cmd_hist_buffer
  148.         jc      .err
  149.  
  150. @@:
  151.         mov     edi, [cmd_hist_buffer.new_node_offset]
  152.         mov     [cmd_hist_buffer.tmp_line_flag], 1
  153.         mov     eax, [cmd_hist_buffer.ptr]
  154.         add     edi, eax
  155.         xor     eax, eax
  156.         stosd
  157.         stosd           ;two zeroes - marker (prefix) of tmp line
  158.  
  159. .cp_str:
  160.         mov     esi, edx
  161.  
  162.         rep     movsb
  163.  
  164. .ok:
  165.         clc
  166.  
  167. .err:
  168.         popa
  169.         ret
  170. ;-------------------------------------------------------------------------------
  171.  
  172. get_cmd_hist_line:
  173. ;-------------------------------------------------------------------------------
  174. ;out:
  175. ;eax = ptr to ASCIIZ string of current line
  176. ;-------------------------------------------------------------------------------
  177.         push    ebx
  178.  
  179.         mov     eax, [cmd_hist_buffer.ptr]
  180.         mov     ebx, [cmd_hist_buffer.cur_node_offset]
  181.  
  182.         lea     eax, [eax + ebx + 2*4]
  183.  
  184.         pop     ebx
  185.         ret
  186. ;-------------------------------------------------------------------------------
  187.  
  188. get_cmd_hist_tmp_line:
  189. ;-------------------------------------------------------------------------------
  190. ;out:
  191. ;eax = ptr to ASCIIZ string of current line or 0 (no tmp line)
  192. ;-------------------------------------------------------------------------------
  193.         cmp     [cmd_hist_buffer.tmp_line_flag], 0
  194.         je      @f
  195.  
  196.         mov     eax, [cmd_hist_buffer.new_node_offset]
  197.         add     eax, [cmd_hist_buffer.ptr]
  198.         add     eax, 2*4
  199.  
  200. @@:
  201.         ret
  202. ;-------------------------------------------------------------------------------
  203.  
  204. prev_cmd_hist_line:
  205. ;-------------------------------------------------------------------------------
  206. ;out:
  207. ;CF = 0 - OK, CF = 1 (no previous lines)
  208. ;-------------------------------------------------------------------------------
  209.         push    eax ebx
  210.  
  211.         mov     eax, [cmd_hist_buffer.ptr]
  212.         mov     ebx, [cmd_hist_buffer.cur_node_offset]
  213.  
  214.         lea     eax, [eax+ebx]
  215.         mov     eax, [eax]
  216.         inc     eax
  217.         jz      .ret_cf
  218.         dec     eax
  219.         mov     [cmd_hist_buffer.cur_node_offset], eax
  220.  
  221.         clc
  222.         pop     ebx eax
  223.         ret
  224.  
  225. .ret_cf:
  226.         stc
  227.         pop     ebx eax
  228.         ret
  229. ;-------------------------------------------------------------------------------
  230.  
  231. next_cmd_hist_line:
  232. ;-------------------------------------------------------------------------------
  233. ;out:
  234. ;CF = 0 - OK, CF = 1 (no next lines)
  235. ;-------------------------------------------------------------------------------
  236.         push    eax ebx
  237.  
  238.         mov     eax, [cmd_hist_buffer.ptr]
  239.         mov     ebx, [cmd_hist_buffer.cur_node_offset]
  240.  
  241.         lea     eax, [eax+ebx]
  242.         mov     eax, [eax+4]
  243.         inc     eax
  244.         jz      .ret_cf
  245.         dec     eax
  246.         mov     [cmd_hist_buffer.cur_node_offset], eax
  247.  
  248.         clc
  249.         pop     ebx eax
  250.         ret
  251.  
  252. .ret_cf:
  253.         stc
  254.         pop     ebx eax
  255.         ret
  256. ;-------------------------------------------------------------------------------
  257.  
  258.