⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rxdoscmd.asm

📁 dos source
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        jz cmndLookup_20                                ; yes -->
        cmp al, '/'                                     ; end of command ?
        jz cmndLookup_20                                ; yes -->
        cmp al, '\'                                     ; end of command ?
        jnz cmndLookup_28                               ; not this command -->

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  return valid arg
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

cmndLookup_20:
        pop ax                                          ; leave si pointing at end 
        pop di
        mov bx, word ptr cs:[ di ]                      ; where to execute
        cmp byte ptr [ si ], '\'                        ; command ends with \ ?
        clc                                             ; NoCarry
        jmp short cmndLookup_36

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  find next entry in table
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

cmndLookup_28:
        inc di
        cmp byte ptr cs:[ di ], 0                       ; end of command ?
        jnz cmndLookup_28                               ; keep looking -->

        pop si
        pop bx                                          ; don't care about saved di
        inc di                                          ; get next word
        cmp word ptr cs:[ di ], -1                      ; end of command table ?
        jnz cmndLookup                                  ; no, lookup next -->

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  return invalid arg
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

cmndLookup_32:
        stc
        mov bx, offset _NotValidCommand                 ; default not valid command

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

cmndLookup_36:
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Installable Command Interface                                ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   ss:di  pointer to argument array                            ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   nz     if commadn executed                                  ;
        ;...............................................................;

checkInstallableCommandInterface:

        xor ax, ax
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Count Number of Arguments                                    ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   ss:di  pointer to argument array                            ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   ax     number of arguments in arg array                     ;
        ;...............................................................;

CountArgs:
        push es
        push di
        push cx

        mov cx, maxArgArray                             ; max number of entries
        setES ss

CountArgs_06:
        cmp word ptr ss:[ di ], 0000                    ; terminating arg ?
        jz CountArgs_08                                 ; yes, done -->
        inc di
        inc di                                          ; next arg
        loop CountArgs_06                               ; else, keep looking -->

CountArgs_08:
        mov ax, maxArgArray
        sub ax, cx                                      ; # arguments

        pop cx
        pop di
        pop es
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Check Number of Arguments                                    ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   bx/ dx are set with the number of expected arguments.       ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   cy     too many arguments message output                    ;
        ;...............................................................;

CheckNoArgs:
        xor dx, dx                                      ; no args
        xor bx, bx                                      ; no switches
        jmp short PreProcessCmndLine                    ; check

CheckOneArg:
        mov cx, 0001                                    ; must have one arg
        mov dx, 0001                                    ; must have one arg
        xor bx, bx                                      ; no switches
        jmp short PreProcessCmndLine                    ; check

CheckOptOneArg:
        mov cx, 0000                                    ; must have none, 
        mov dx, 0001                                    ;   or one arg
        xor bx, bx                                      ; no switches

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Pre Process Command Line                                     ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   ss:di  pointer to argument array                            ;
        ;   cx     acceptable min # args                                ;
        ;   dx     acceptable max # args                                ;
        ;   bx     pointer to switches                                  ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   cy     too many arguments message output                    ;
        ;...............................................................;

PreProcessCmndLine:

        push di
        push cx
        push dx

        call _GetSwitches                               ; switches ok ?
        jc _preProcessCmndLine_08                       ; no -->

        pop dx
        pop cx
        push dx
        push cx
        call CountArgs                                  ; see how many args remain
        call _TooManyArguments                          ; too many still left ?
        jc _preProcessCmndLine_08                       ; yes -->

        call nullTerminateArgs                          ; null terminate args
        or ax, ax                                       ; how many args passed

_preProcessCmndLine_08:
        pop dx
        pop cx
        pop di
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Tests for Too Many Arguments                                 ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   ss:di  pointer to argument array                            ;
        ;   ax     actual argument count                                ;
        ;   cx     acceptable min # args                                ;
        ;   dx     acceptable max # args                                ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   cy     too many arguments message output                    ;
        ;...............................................................;

_TooManyArguments:

        push di
        push ax
        push cx

        cmp ax, dx                                      ; 
        jz _TooManyArguments_16                         ; if expected # args -->
        jg _TooManyArguments_06                         ; if greater than expected -->
        cmp ax, cx
        jge _TooManyArguments_16                        ; if within min/max
        mov dx, offset CmndError_ParametersMissing
        jmp short _TooManyArguments_08

_TooManyArguments_06:
        mov dx, offset CmndError_TooManyParameters
        call DisplayLine

        pop cx
        push cx
        add cx, cx
        add di, cx                                      ; argument ptr that is extra
        mov dx, word ptr ss:[ di ]                      ; get arg address

_TooManyArguments_08:
        call DisplayLine                                ; show arg
        stc

_TooManyArguments_16:
        pop cx
        pop ax
        pop di
        ret

        ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
        ;  Test/ Process Switches                                       ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Usage:                                                       ;
        ;   ss:di  pointer to argument array                            ;
        ;   bx     pointer to switches to process (or null)             ;
        ;                                                               ;
        ;  Returns:                                                     ;
        ;   cy     if invalid use of switches                           ;
        ;                                                               ;
        ;          Otherwise, switch array passed is filled with info.  ;
        ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
        ;                                                               ;
        ;  Switch array consists of a switch letter followed by:        ;
        ;                                                               ;
        ;    'x'        switch letter                                   ;
        ;    flags      type of data value expected                     ;
        ;    min        min value expected                              ;
        ;    max        max value expected                              ;
        ;    actual     actual value passed in command                  ;
        ;                                                               ;
        ;    a flag bit is set if the flag was encountered in cmnd.     ;
        ;...............................................................;

_GetSwitches:
        
        Entry
        def _switches, bx
        
        push di
        push si
        push cx

        or bx, bx                                       ; switches expected ?
        jz _getSwitches_06                              ; no -->
        call _initSwitchTable                           ; init switches expected
        
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  walk through all args
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_getSwitches_06:
        mov si, word ptr ss:[ di ]                      ; get arg 
        or si, si                                       ; is it a null arg ?
        jz _getSwitches_36                              ; yes, exit -->

        mov al, byte ptr ss:[ si ]                      ; get value at arg
        cmp al, byte ptr [ _SwitchChar ]                ; switch arg ?
        jnz _getSwitches_12                             ; no -->

        getarg bx, _switches
        or bx, bx                                       ; any switches allowed ?
        jz _getSwitches_24                              ; if not allowed, drop from list

        mov ax, word ptr ss:[ si + 1 ]                  ; get switch characters
        call _matchSwitch                               ; is this switch valid ?
        jc _getSwitches_24                              ; not allowed -->

        or word ptr [ swFlags ][ bx ], SW_SWITCHSET     ; switch is set
        call deleteArg                                  ; remove this argument
        jz _getSwitches_36                              ; if no more args -->

_getSwitches_12:
        inc di
        inc di
        jmp _getSwitches_06

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  switch is illegal
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

_getSwitches_24:
        push si                                         ; save argument ptr
        mov dx, offset CmndError_BadSwitch
        call Displa

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -