📄 rxdoscmd.asm
字号:
mov bx, ax
mov cx, STDIN
call _assignGetCurrHandle
getarg di, __execCtrlBlock
mov word ptr [ exCtrlStdInHandle ][ di ], ax ; save old handle
Int21 ForceFileHandle ; redirect stdout
jmp _assignRedirect_06
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; pipe
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_assignRedirect_Pipe:
mov byte ptr [ si ], 00 ; set a null at terminator
storarg __contargarray, di ; continue argument array
mov word ptr [ di ], 0000 ; place an end marker in arg list
mov bx, word ptr [ __execCtrlBlock ][ bp ] ; execution control block
lea bx, offset [ exCtrlStdOutFileName ][ bx ] ; offset to filename
mov byte ptr [ bx ], 0
mov dx, bx
mov cx, OPEN_ACCESS_READWRITE ; create read/write
Int21 CreateUniqueFile ; if not found, create
ifc _assignRedirect_Error ; just display error -->
push ax
mov bx, ax
mov cx, STDOUT
call _assignGetCurrHandle
getarg di, __execCtrlBlock
mov word ptr [ exCtrlStdOutHandle ][ di ], ax ; save old handle
Int21 ForceFileHandle ; redirect stdout
pop bx ; this close frees file handle after
Int21 CloseFile ; force replicate handle
getarg di, __contargarray ; continue argument array
getarg bx, __execCtrlBlock ; execution control block
mov word ptr [ exCtrlArgArray. _pointer ][ bx ], di
or word ptr [ exCtrlFlags ][ bx ], exCtrlPiped ; say arg is piped.
jmp _assignRedirect_36 ; exit -->
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; append stdout
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_assignRedirect_AppendStdOut:
mov byte ptr [ si ], 00 ; set a null at terminator
storarg __contargarray, di ; continue argument array
call deleteArg ; kill '>' arg
call deleteArg ; kill '>' arg
mov bx, word ptr [ __execCtrlBlock ][ bp ] ; execution control block
lea dx, offset [ exCtrlStdOutFileName ][ bx ] ; offset to filename
call _asgnGetFileName ; arg to [dx]
Int21 OpenFile, OPEN_ACCESS_READWRITE ; try to open file
jnc _assignRedirect_Append_08
cmp ax, errFileNotFound ; if other than not found
jnz _assignRedirect_Error ; just display error -->
xor cx, cx
mov bx, word ptr [ __execCtrlBlock ][ bp ] ; execution control block
lea dx, offset [ exCtrlStdOutFileName ][ bx ] ; offset to filename
Int21 CreateFile ; if not found, create
jc _assignRedirect_Error ; just display error -->
_assignRedirect_Append_08:
push ax
xor cx, cx
xor dx, dx
mov bx, ax
Int21 MoveFilePointer, SEEK_END ; point to end of file
mov cx, STDOUT
call _assignGetCurrHandle
getarg bx, __execCtrlBlock
mov word ptr [ exCtrlStdOutHandle ][ bx ], ax ; save old handle
pop bx
push bx
Int21 ForceFileHandle ; redirect stdout
pop bx
Int21 CloseFile
jmp _assignRedirect_06
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; redirection error
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_assignRedirect_Error:
call DisplayErrorCode
stc
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; return
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_assignRedirect_36:
getarg di, __argarray ; argument array
Return
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Kill Arg From List ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Usage: ;
; cx handle whose value we want ;
; ax value of handle returned ;
;...............................................................;
_assignGetCurrHandle:
push es
push si
push bx
push cx
Int21 GetPSPAddress
pop si ; restore handle offset
mov es, bx ; set PSP address
les bx, dword ptr es:[ pspFileHandlePtr ] ; point to file handles
mov al, byte ptr es:[ bx + si ] ; recover existing handle
xor ah, ah
pop bx
pop si
pop es
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Copy Arg ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Usage: ;
; si pointer to argument ;
; di pointer to copy location ;
; ;
; Returns: ;
; zr no characters copies ;
;...............................................................;
_copyArg:
or si, si
jz _copyArg_36
or cx, cx ; address of next arg zero ?
sub cx, si ; real length
_copyArg_08:
lodsb ; get character
stosb
or al, al
jz _copyArg_36
loop _copyArg_08
_copyArg_36:
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Get Filename From A Piped Or Redirected Argument ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Usage: ;
; di points to arg list ;
; dx destination where to copy arg ;
; ;
; arg is removed from arg list (it is deleted) once copied ;
;...............................................................;
_asgnGetFileName:
push ax
push dx
push di
mov cx, word ptr [ di + 2 ] ; get arg that follows
mov si, word ptr [ di ] ; get current arg
mov di, dx
call _copyArg
pop di
call deleteArg ; kill arg
pop dx
pop ax
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Close Redirected Std Device ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Usage: ;
; al restore value for handle (or -1) ;
; bx stdout or stdin ;
;...............................................................;
_CloseRedirectedDevice:
cmp al, -1 ; std device redirected ?
jz _closeRedirect_42 ; no -->
push es
push bx
push ax
Int21 CloseFile ; close std device
Int21 GetPSPAddress
pop ax
pop si
mov es, bx ; set PSP address
les bx, dword ptr es:[ pspFileHandlePtr ] ; point to file handles
xchg al, byte ptr es:[ bx + si ] ; recover existing handle
pop es
_closeRedirect_42:
ret
;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Lookup Argument ;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
; ;
; Usage: ;
; ds:si pointer to argument (term by a null or switch char) ;
; cs:di pointer to supported commands ;
; ;
; Returns: ;
; bx pointer to command execution address ;
; cy argument not supported internally ;
;...............................................................;
CmndLookup:
push di
push si
inc di
inc di ; point to arg that follows
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; skip leading @ sign
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cmp byte ptr [ si ], '@' ; command begins with @ sign ?
jnz cmndLookup_12 ; no -->
inc si ; skip @ sign
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; compare argument against table
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cmndLookup_12:
mov al, byte ptr [ si ] ; from command
inc si
cmp al, ' '+1 ; if end of command
jc cmndLookup_18 ; see if all characters match -->
cmp al, byte ptr [ _SwitchChar ] ; switch character ?
jz cmndLookup_18 ; yes, end of arg -->
call _CmndParse_SeparatorCheck ; separator character ?
jz cmndLookup_18 ; yes, end of arg -->
call _lowerCase ; lower case ...
cmp al, byte ptr cs:[ di ] ; compare
jnz cmndLookup_18 ; if not this command -->
inc di ; else keep looking
jmp cmndLookup_12
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; if end, see if end of both args
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cmndLookup_18:
cmp byte ptr cs:[ di ], 0 ; end of command ?
jnz cmndLookup_28 ; not this command then -->
dec si
mov al, byte ptr [ si ] ; get last character
cmp al, ' '+1 ; end of command ?
jc cmndLookup_20 ; yes -->
cmp al, byte ptr [ _SwitchChar ] ; end of command ?
jz cmndLookup_20 ; yes -->
call _CmndParse_SeparatorCheck ; separator character ?
jz cmndLookup_20 ; yes -->
cmp al, '.' ; end of command ?
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -