Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ; --------------------------------------------------------------------------
  2. ; FILE: TCmdBuf.Asm
  3. ; DATE: September 27, 2008
  4. ; --------------------------------------------------------------------------
  5.  
  6. ; --------------------------------------------------------------------------
  7. ; Input:
  8. ;   ESI = ANSI token scanned
  9. ;   CL = ANSI text to match (1-based index into message table)
  10. ; Output:
  11. ;   CF=TRUE if first token exactly matches text at index in CL
  12. ;   CF=FALSE if no match (message given to the user)
  13. ; --------------------------------------------------------------------------
  14. align PROC_ALIGN
  15. TCmdBuf_VerifyToken:
  16.     movzx   ecx, cl
  17.  
  18. TCmdBuf_VerifyToken_ECX:
  19.     push    esi
  20.     call    TMsgTable_GetItem
  21.     pop     edi
  22.  
  23.     call    TString_AnsiEqual
  24.     jnc     .ret_false
  25.     ret
  26.  
  27. .ret_false:
  28.     call    TConsole_ScrollUp
  29.     call    TConsole_SetGameMsgAttr
  30.     mcLoad8bitsToReg32 ecx, 93
  31.     call    TConsole_Prout
  32.     call    TConsole_ScrollUp
  33.  
  34.     clc
  35.     ret
  36.  
  37. ; --------------------------------------------------------------------------
  38. ; Input:
  39. ;   ESI = ANSI token scanned
  40. ;   ECX = ANSI text to match (1-based index into message table)
  41. ; Output:
  42. ;   CF=TRUE if text at EDI has a prefix like ESI
  43. ; --------------------------------------------------------------------------
  44. align PROC_ALIGN
  45. TCmdBuf_Crop:
  46.     push    esi esi
  47.     call    TMsgTable_GetItem
  48.     mov     edi, esi
  49.     pop     esi
  50.  
  51.     mcZeroBits edx
  52.     mcZeroBits eax
  53.  
  54. .load_chars:
  55.     lodsb
  56.     mov     dl, [edi]
  57.     inc     edi
  58.  
  59.     cmp     dl, al
  60.     je      .check_zero
  61.  
  62.     mcOnRegZero eax, .match
  63.  
  64.     pop     esi
  65.     clc
  66.     ret
  67.  
  68. .check_zero:
  69.     mcOnRegNotZero eax, .load_chars
  70.  
  71. .match:
  72.     pop     esi
  73.     stc
  74.     ret
  75.  
  76. ; --------------------------------------------------------------------------
  77. ; Input:
  78. ;   AX = WCHAR to append
  79. ; --------------------------------------------------------------------------
  80. align PROC_ALIGN
  81. TCmdBuf_PutChar:
  82.     mov     ebx, [glb_pCmdBuf]
  83.     cmp     [ebx + TCmdBuf.cmdbuf_CmdColumn], CMDBUF_MAX_CHARS
  84.     je      .done
  85.  
  86.     mcLoadMember ecx, TCmdBuf.cmdbuf_CmdColumn
  87.     mov     [ebx + ecx*2], ax
  88.     inc     [ebx + TCmdBuf.cmdbuf_CmdColumn]
  89.  
  90. .done:
  91.     ret
  92.  
  93. ; --------------------------------------------------------------------------
  94. align PROC_ALIGN
  95. TCmdBuf_Parse:
  96.     mcZeroBits eax
  97.     call    TCmdBuf_PutChar
  98.  
  99.     mov     ebx, [glb_pCmdBuf]
  100.     mcStoreMember TCmdBuf.cmdbuf_NumTokens, eax
  101.     mcStoreMember TCmdBuf.cmdbuf_CmdColumn, eax
  102.  
  103.     dec     eax
  104.     mcStoreMember TCmdBuf.cmdbuf_TokenIterator, eax
  105.     inc     eax
  106.  
  107.     mov     esi, ebx
  108.     mov     edx, eax
  109.     mcLoadMemberRef edi, TCmdBuf.cmdbuf_CmdTokens
  110.  
  111. .load_char:
  112.     lodsw
  113.     mcOnRegZero eax, .done
  114.  
  115.     cmp     al, CHAR_BLANK
  116.     je      .separator
  117.  
  118.     mcOnRegNotZero edx, .load_char
  119.  
  120.     lea     edx, [esi - 2]
  121.     mov     [edi], edx
  122.     add     edi, 4
  123.     inc     [ebx + TCmdBuf.cmdbuf_NumTokens]
  124.     cmp     [ebx + TCmdBuf.cmdbuf_NumTokens], CMDBUF_MAX_TOKENS
  125.     je      .done
  126.     jmp     .load_char
  127.  
  128. .separator:
  129.     mcZeroBits edx
  130.     mov     [esi - 2], dx
  131.     jmp     .load_char
  132.  
  133. .done:
  134.     ret
  135.  
  136. ; --------------------------------------------------------------------------
  137. ; Input:
  138. ;   AL = character
  139. ; Output:
  140. ;   CF = TRUE if AL is a digit
  141. ; --------------------------------------------------------------------------
  142. align PROC_ALIGN
  143. TCmdBuf_IsDigit:
  144.     cmp     al, '0'
  145.     jb      .false
  146.  
  147.     cmp     al, '9'
  148.     ja      .false
  149.  
  150.     stc
  151.     ret
  152.  
  153. .false:
  154.     clc
  155.     ret
  156.  
  157. ; --------------------------------------------------------------------------
  158. ; Input:
  159. ;   ESI = token address
  160. ; Output:
  161. ;   CF = TRUE if token is a real value: "-100" or "5.6"
  162. ; --------------------------------------------------------------------------
  163. align PROC_ALIGN
  164. TCmdBuf_IsRealToken:
  165.     mcZeroBits ecx
  166.     mcZeroBits eax
  167.     mcZeroBits edi
  168.  
  169. .load_char:
  170.     mov     ax, [esi + ecx*2]
  171.     inc     ecx
  172.     mcOnRegZero eax, .true
  173.  
  174.     mcOnRegEqu al, '-', .minus
  175.     mcOnRegEqu al, '.', .period
  176.     ;
  177.     ; Check if digit
  178.     ;
  179.     call    TCmdBuf_IsDigit
  180.     jc      .load_char
  181.  
  182. .false:
  183.     clc
  184.     ret
  185.  
  186. .minus:
  187.     mcOnRegEqu ecx, 1, .load_char
  188.     jmp     .false
  189.  
  190. .period:
  191.     mcOnRegNotZero edi, .false
  192.     mov     edi, esi
  193.     jmp     .load_char
  194.  
  195. .true:
  196.     stc
  197.     ret
  198.  
  199. ; --------------------------------------------------------------------------
  200. ; Output:
  201. ;   ESI = token address or NULL
  202. ;   EAX = token type (CMD_TOKEN_ALPHA, CMD_TOKEN_REAL, CMD_TOKEN_EOL)
  203. ; --------------------------------------------------------------------------
  204. align PROC_ALIGN
  205. TCmdBuf_GetNextToken:
  206.     mov     ebx, [glb_pCmdBuf]
  207.     inc     [ebx + TCmdBuf.cmdbuf_TokenIterator]
  208.  
  209.     mcLoadMember ecx, TCmdBuf.cmdbuf_TokenIterator
  210.     cmp     ecx, [ebx + TCmdBuf.cmdbuf_NumTokens]
  211.     jae     .end_of_line
  212.  
  213.     mov     esi, [ebx + ecx*4 + TCmdBuf.cmdbuf_CmdTokens]
  214.     call    TCmdBuf_IsRealToken
  215.     jc      .real_value
  216.  
  217.     mcLoad8bitsToReg32 eax, CMD_TOKEN_ALPHA
  218.     ret
  219.  
  220. .real_value:
  221.     mcLoad8bitsToReg32 eax, CMD_TOKEN_REAL
  222.     ret
  223.  
  224. .end_of_line:
  225.     mcZeroBits eax
  226.     mcZeroBits esi
  227.     ret
  228.  
  229. ; --------------------------------------------------------------------------
  230. ; Input:
  231. ;   ESI = ANSI text
  232. ;   AL = character to find
  233. ; Output:
  234. ;   ECX = character offset (CF=TRUE)
  235. ; --------------------------------------------------------------------------
  236. align PROC_ALIGN
  237. TCmdBuf_AnsiFindChar:
  238.     mcZeroBits ecx
  239.  
  240. .test_char:
  241.     cmp     byte [esi + ecx], 0
  242.     je      .not_found
  243.  
  244.     cmp     [esi + ecx], al
  245.     je      .found
  246.  
  247.     inc     ecx
  248.     jmp     .test_char
  249.  
  250. .found:
  251.     stc
  252.     ret
  253.  
  254. .not_found:
  255.     clc
  256.     ret
  257.  
  258. ; --------------------------------------------------------------------------
  259. ; Output:
  260. ;   EBX = TCmdBuf instance
  261. ;   ESI = ANSI token scanned
  262. ; --------------------------------------------------------------------------
  263. align PROC_ALIGN
  264. TCmdBuf_Scan:
  265.     call    TCmdBuf_GetNextToken
  266.     mcStoreMember TCmdBuf.cmdbuf_KEY, al
  267.  
  268.     mcZeroBits edx
  269.     mcStoreMember TCmdBuf.cmdbuf_INUM, edx
  270.     mcStoreMember TCmdBuf.cmdbuf_AnsiTokenBuf, dl
  271.  
  272.     fldz
  273.     fstp    [ebx + TCmdBuf.cmdbuf_FNUM]
  274.  
  275.     mcOnRegZero esi, .done
  276.     ;
  277.     ; Convert the token into ANSI
  278.     ;
  279.     mcLoadMemberRef edi, TCmdBuf.cmdbuf_AnsiTokenBuf
  280.     mov     eax, edx
  281.  
  282. .convert_char:
  283.     lodsw
  284.     stosb
  285.     mcOnRegNotZero eax, .convert_char
  286.  
  287.     cmp     [ebx + TCmdBuf.cmdbuf_KEY], CMD_TOKEN_ALPHA
  288.     je      .done
  289.  
  290.     mcLoadMemberRef esi, TCmdBuf.cmdbuf_AnsiTokenBuf
  291.     mov     al, '.'
  292.     call    TCmdBuf_AnsiFindChar
  293.     jc      .set_fp_num
  294.     ;
  295.     ; Integer value scanned
  296.     ;
  297.     call    TCmdBuf_AnsiStr2Int32
  298.     mcStoreMember TCmdBuf.cmdbuf_INUM, eax
  299.  
  300.     fild    [ebx + TCmdBuf.cmdbuf_INUM]
  301.     fstp    [ebx + TCmdBuf.cmdbuf_FNUM]
  302.     jmp     .done
  303.  
  304. .set_fp_num:
  305.     ;
  306.     ; FP value scanned
  307.     ;
  308.     mcLoadMemberRef edi, TCmdBuf.cmdbuf_FNUM
  309.     call    TCmdBuf_AnsiStr2Double
  310.  
  311. .done:
  312.     mcLoadMemberRef esi, TCmdBuf.cmdbuf_AnsiTokenBuf
  313.     ret
  314.  
  315. ; --------------------------------------------------------------------------
  316. ; Input:
  317. ;   ESI = ANSI text
  318. ; Output:
  319. ;   ECX = number of characters in the string
  320. ; --------------------------------------------------------------------------
  321. align PROC_ALIGN
  322. TCmdBuf_AnsiStrLen:
  323.     push    edx
  324.  
  325.     mcZeroBits ecx
  326.     mcZeroBits edx
  327.  
  328. .check_char:
  329.     cmp     [esi + ecx], dl
  330.     je      .done
  331.  
  332.     inc     ecx
  333.     jmp     .check_char
  334.  
  335. .done:
  336.     pop     edx
  337.     ret
  338.  
  339. ; --------------------------------------------------------------------------
  340. ; Input:
  341. ;   ESI = ANSI text
  342. ; Output:
  343. ;   EAX = converted value
  344. ; --------------------------------------------------------------------------
  345. virtual at 0
  346. loc5:
  347.     .bNegative BOOL ?
  348.     .size = $
  349. end virtual
  350. ; --------------------------------------------------------------------------
  351. align PROC_ALIGN
  352. TCmdBuf_AnsiStr2Int32:
  353.     mcBeginLocals loc5.size
  354.  
  355.     mcZeroBits eax
  356.     mcZeroBits edx
  357.     mcStoreLocal loc5.bNegative, eax
  358.  
  359.     cmp     byte [esi], '-'
  360.     jne     .convert
  361.  
  362.     inc     [esp + loc5.bNegative]
  363.     inc     esi
  364.  
  365. .convert:
  366.     mov     dl, [esi]
  367.     mcOnRegZero edx, .apply_sign
  368.  
  369.     sub     dl, '0'
  370.     inc     esi
  371.     imul    eax, 10
  372.     add     eax, edx
  373.     jmp     .convert
  374.  
  375. .apply_sign:
  376.     cmp     byte [esp + loc5.bNegative], 0
  377.     je      .done
  378.  
  379.     neg     eax
  380.  
  381. .done:
  382.     mcEndLocals loc5.size
  383.     ret
  384.  
  385. ; --------------------------------------------------------------------------
  386. ; Input:
  387. ;   ESI = text
  388. ;   EDI = pointer to DOUBLE value
  389. ; --------------------------------------------------------------------------
  390. virtual at 0
  391. loc6:
  392.     .pszDot PCHAR ?
  393.     .pszValue PCHAR ?
  394.     .bNegative BOOL ?
  395.     .iPart1 INT32 ?
  396.     .iPart2 INT32 ?
  397.     .pDblResult PDOUBLE ?
  398.     .dblPart1 DOUBLE ?
  399.     .dblPart2 DOUBLE ?
  400.     .size = $
  401. end virtual
  402. ; --------------------------------------------------------------------------
  403. align PROC_ALIGN
  404. TCmdBuf_AnsiStr2Double:
  405.     mcBeginLocals loc6.size
  406.     mcStoreLocal loc6.pszValue, esi
  407.     mcStoreLocal loc6.pDblResult, edi
  408.  
  409.     mcZeroBits eax
  410.     mcStoreLocal loc6.bNegative, eax
  411.     mcStoreLocal loc6.pszDot, eax
  412.  
  413.     cmp     byte [esi], '-'
  414.     jne     .parse
  415.  
  416.     inc     [esp + loc6.bNegative]
  417.     inc     [esp + loc6.pszValue]
  418.     inc     esi
  419.  
  420. .parse:
  421.     lodsb
  422.     mcOnRegZero eax, .analysis
  423.     mcOnRegEqu al, '.', .dot
  424.     jmp     .parse
  425.  
  426. .dot:
  427.     lea     edx, [esi - 1]
  428.     mcStoreLocal loc6.pszDot, edx
  429.     jmp     .parse
  430.  
  431. .analysis:
  432.     cmp     byte [esp + loc6.pszDot], 0
  433.     jne     .combine_parts
  434.     ;
  435.     ; No decimal point
  436.     ;
  437.     mcLoadLocal esi, loc6.pszValue
  438.     call    TCmdBuf_AnsiStr2Int32
  439.     mcStoreLocal loc6.iPart1, eax
  440.  
  441.     fild    [esp + loc6.iPart1]
  442.     jmp     .apply_sign
  443.  
  444. .combine_parts:
  445.     mcLoadLocal edi, loc6.pszDot
  446.     mcZeroBits al
  447.     stosb
  448.  
  449.     fldz
  450.     fldz
  451.     fstp    [esp + loc6.dblPart1]
  452.     fstp    [esp + loc6.dblPart2]
  453.  
  454.     mov     esi, edi
  455.     call    TCmdBuf_AnsiStr2Int32
  456.     mcStoreLocal loc6.iPart2, eax
  457.  
  458.     mcLoadLocal esi, loc6.pszValue
  459.     call    TCmdBuf_AnsiStr2Int32
  460.     mcStoreLocal loc6.iPart1, eax
  461.  
  462.     mcLoadLocal esi, loc6.pszDot
  463.     inc     esi
  464.     call    TCmdBuf_AnsiStrLen
  465.     jecxz   .combine
  466.  
  467.     fild    [esp + loc6.iPart2]
  468. @@:
  469.     fld     [glb_dbl_Ten]
  470.     fdivp
  471.     loop    @r
  472.  
  473.     fstp    [esp + loc6.dblPart2]
  474.  
  475. .combine:
  476.     fild    [esp + loc6.iPart1]
  477.     fld     [esp + loc6.dblPart2]
  478.     faddp
  479.  
  480. .apply_sign:
  481.     cmp     byte [esp + loc6.bNegative], 0
  482.     je      .done
  483.  
  484.     fchs
  485.  
  486. .done:
  487.     mcLoadLocal edi, loc6.pDblResult
  488.     fstp    tbyte [edi]
  489.  
  490.     mcEndLocals loc6.size
  491.     ret
  492.  
  493. ; --------------------------------------------------------------------------
  494. ; Output:
  495. ;   CF = TRUE if buffer has no characters
  496. ; --------------------------------------------------------------------------
  497. align PROC_ALIGN
  498. TCmdBuf_IsEmpty:
  499.     mov     ebx, [glb_pCmdBuf]
  500.     cmp     [ebx + TCmdBuf.cmdbuf_CmdColumn], 0
  501.     sete    cl
  502.     shr     cl, 1
  503.     ret
  504.  
  505. ; --------------------------------------------------------------------------
  506. align PROC_ALIGN
  507. TCmdBuf_Backspace:
  508.     mov     ebx, [glb_pCmdBuf]
  509.     cmp     [ebx + TCmdBuf.cmdbuf_CmdColumn], 0
  510.     je      .done
  511.  
  512.     dec     [ebx + TCmdBuf.cmdbuf_CmdColumn]
  513.  
  514. .done:
  515.     ret
  516.  
  517. ; --------------------------------------------------------------------------
  518. align PROC_ALIGN
  519. TCmdBuf_Create:
  520.     invoke  HeapAlloc, [glb_Allocator], HEAP_NO_SERIALIZE, TCmdBuf.size
  521.     mov     [glb_pCmdBuf], eax
  522.  
  523.     mov     edi, eax
  524.     mcZeroBits eax
  525.     mov     ecx, TCmdBuf.size
  526.     rep     stosb
  527.     ret
  528.  
  529. ; --- EOF ---
  530.