home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.shrubbery.net
/
2015-02-07.ftp.shrubbery.net.tar
/
ftp.shrubbery.net
/
pub
/
pc
/
unix
/
unx.arc
/
UNSETRAW.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-06-02
|
3KB
|
140 lines
page 66, 132
; unsetraw.com
; usage: unsetraw {x}
; If x is given, sets raw mode; otherwise, sets cooked mode.
; Useful only to get back to cooked mode after stupid program has left
; console in raw mode (like, say, when you ^C out of more.com).
; It's a bit overblown because I used a more complicated program
; as a pattern.
; uses args
extrn _args:near, _shift:near
extrn argc:word, argv:word
dos macro fn
mov ah, fn
int 21h
endm
stdin equ 0
stdout equ 1
stderr equ 2
code segment para public 'CODE'
assume cs:code,ds:code
org 100h
main proc
jmp unsetraw
main endp
;----------------------------------------------
db 27
db '[2Junsetraw (C) 1984 Yoyodyne, Inc- a growing excited company.'
db 13, 10
db 'Usage: unsetraw {x}', 13, 10
db ' If x is given, sets console to RAW mode; else sets COOKED mode.'
db 13, 10
db ' Useful for recovering from programs which leave console in raw mode.'
db 13, 10
db 26
errs dw null ; error zero- no error
dw null, filenotfound, pathnotfound, nohand, access
dw null, null, null, null, null
dw null, null, null, null, baddrive
dw null, null
null db '?dos err', 0
filenotfound db 'File not found', 0
pathnotfound db 'Path not found', 0
nohand db 'No handles left', 0
access db 'Access denied', 0
baddrive db 'Invalid drive specification', 0
trueargc dw ?
;--- strlen ---
; Returns length of ES:DI in CX, points to null with DI.
strlen proc near
cld
push ax
mov cx, -1
mov al, 0
repnz scasb
not cx
pop ax
ret
strlen endp
dos_err proc near
mov bx, ax
add bx, ax
mov di, errs[bx]
push di
call strlen
pop dx
mov bx, stderr
DOS 40h
ret
dos_err endp
open_err proc near
call dos_err
mov al, 1
jmp exit
open_err endp
;-------------------------------------------------
unsetraw proc near
call _args
; if (argc > 0) ioctrl(stdout, binary)
; else ioctrl(stdout, ascii);
cmp argc, 0
jz set_ascii
; Set binary mode on stdout.
mov bx, stdout
mov al, 0
DOS 44h ; get tty bits
jc open_err
or dl, 32 ; set binary mode
mov dh, 0
mov al, 1
DOS 44h
jc open_err
mov al, 0
jmp exit
set_ascii:
; Set text mode on stdout.
mov al, 0
mov bx, 1
DOS 44h
jc open_err
and dx, 0cfh ; set text mode
mov al, 1
DOS 44h
jc open_err
mov al, 0 ; no error
exit:
mov ah, 4ch
int 21h ; terminate process, return status in AL.
unsetraw endp
code ends
end main