CODE: [Copy to clipboard]
; ****************************************************************
; *
; * ROUTINE: CTTY - Change console
; *
; * SYNTAX: CTTY device
; *
; * FUNCTION: If a valid console device is specified, CTTY will
; * duplicate the device handle to STDIN, STDOUT and
; * STDERR. This routine returns to LODCOM1.
; *
; * INPUT: command line at offset 81H
; *
; * OUTPUT: none
; *
; ****************************************************************
CTTY:
push ds ;AN000; Get local ES
pop es ;AN000;
mov si,81H ;AC000; Get command argument for CTTY
mov di,offset trangroup:parse_ctty ;AC000; Get adderss of PARSE_CTTY
xor cx,cx ;AC000; clear cx,dx
xor dx,dx ;AC000;
invoke cmd_parse ;AC000; call parser
cmp ax,end_of_line ;AN000; are we at end of line?
jz ctty_error ;AN000; yes - error
cmp ax,result_no_error ;AN000; did an error occur
jnz ctty_error ;AN000; YES -ERROR
push si ;AN000; save position in line
lds si,parse1_addr ;AN000; get address of filespec
mov di,offset trangroup:srcbuf ;AN000; get address of srcbuf
ctty_move_filename: ;AN000; put filespec in srcbuf
lodsb ;AN000; get a char from buffer
stosb ;AN000; store in srcbuf
cmp al,end_of_line_out ;AN000; it char a terminator?
jnz ctty_move_filename ;AN000; no - keep moving
pop si ;AN000; get line position back
mov di,offset trangroup:parse_ctty ;AC000; Get adderss of PARSE_CTTY
call parse_check_eol ;AN000; are we at end of line?
jz nocolon ;AN000; yes - continue
ctty_error:
jmp short isbaddev ;AC000; yes - exit
nocolon:
mov dx,offset trangroup:srcbuf ;AN000; get address of srcbuf
MOV AX,(OPEN SHL 8) OR 2 ; Read and write
INT 21h ; Open new device
JC ISBADDEV
MOV BX,AX
MOV AX,IOCTL SHL 8
INT 21h
TEST DL,80H
JNZ DEVISOK
CLOSEDEV: ;AN007;
MOV AH,CLOSE ; Close initial handle
INT 21h
ISBADDEV:
MOV DX,OFFSET TRANGROUP:BADDEV_ptr
invoke std_printf
JMP SHORT RESRET
DEVISOK:
push dx ;AN007; save device info
mov ax,acrlf_ptr ;AN021; get message number for 0d, 0a
mov dh,util_msg_class ;AN021; this is a utility message
push bx ;AN021; save handle
invoke Tsysgetmsg ;AN021; get the address of the message
mov dx,si ;AN021; get address into dx
mov ax,(write shl 8) ;AN007; write to device
mov cx,2 ;AN007; write two bytes
int 21h ;AN007;
pop bx ;AN021; get back handle
pop dx ;AN007; get back device info
jc closedev ;AN007; if error, quit
XOR DH,DH
OR DL,3 ; Make sure has CON attributes
MOV AX,(IOCTL SHL 8) OR 1
INT 21h
PUSH BX ; Save handle
MOV CX,3
XOR BX,BX
ICLLOOP: ; Close basic handles
MOV AH,CLOSE
INT 21h
INC BX
LOOP ICLLOOP
POP BX ; Get handle
MOV AH,XDUP
INT 21h ; Dup it to 0
MOV AH,XDUP
INT 21h ; Dup to 1
MOV AH,XDUP
INT 21h ; Dup to 2
MOV AH,CLOSE ; Close initial handle
INT 21h
RESRET:
MOV DS,[RESSEG]
ASSUME DS:RESGROUP
PUSH DS
MOV AX,WORD PTR DS:[PDB_JFN_Table] ; Get new 0 and 1
MOV [IO_SAVE],AX
MOV AX,OFFSET DATARES:TrnLodCom1_Trap
PUSH AX
ZMMMM PROC FAR
RET ; Force header to be checked
ZMMMM ENDP
[