home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
txtutl
/
nobit71.arc
/
NOBIT71.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-12-01
|
6KB
|
256 lines
TITLE NOBIT7 10-19-88 [12-1-88]
;NOBIT7.COM disassembled via ASMGEN.
;
;(Silly that a wee little program, doing such a wee simple little thing,
; shouldn't be released with source code.)
;Tweaked to within an inch of its life (mostly in lower case).
;Not significantly faster, but carved a couple hundred bytes out of it.
;
;All rights remain with the author, Ray Johns.
;David Kirschbaum
;Toad Hall
;kirsch@braggvax.ARPA
LF EQU 0AH
CR EQU 0DH
;
CSeg SEGMENT
ASSUME DS:CSeg, SS:CSeg ,CS:CSeg ,ES:CSeg
org 80H
cmdlen label byte ;PSP command line
ORG 100H
NoBit7 proc near
JMP Start ;skip over data
inHandle dw 0
outHandle dw 0
logo DB 'NOBIT7 - 1.01 - Copyright (c) 1988, Ray Johns',CR,LF,LF
DB 'Input file : '
LOGOLEN = $ - logo
openerr DB CR,LF,'Cannot open file',CR,LF
LEN18C = $ - openerr
closerr DB CR,LF,'Cannot close file',CR,LF
LEN1A1 = $ - closerr
noinput DB CR,LF,'No input file',CR,LF
LEN1B7 = $ - noinput
workmsg DB CR,LF,'Working '
LEN1C9 = $ - workmsg
ioerr DB CR,LF,'I/O error',CR,LF
LEN1D4 = $ - ioerr
donemsg DB CR,LF,'Complete',CR,LF
LEN1E2 = $ - donemsg
kbdbuff DB 41H ;buffer for user keyboard input
;(41H is max bytes to be input)
bufflen DB 0
bufftxt DB 42H DUP(0)
NoBit7 endp
Start proc near
CLD
MOV DX,OFFSET logo ;'NOBIT7..' logo
;plus 'Input: ' msg
MOV CX,LOGOLEN ;msg length
CALL Write ;display msg
mov si,offset cmdlen ;start at PSP command line
cld ;insure fwd
lodsb ;snarf cmdline length
or al,al ;no PSP command?
jz Need_FileName ;none, go prompt for one
mov bx,200DH ;BH=space,BL=CR
mov di,offset bufftxt ;move name into internal buffer
mov dx,di ;remember that start
NameLup:
lodsb ;grab cmdline char
cmp al,bh ;space?
je NameLup ;yep, gobble them
cmp al,bl ;CR (terminator)?
je Name_Done ;yep, done
stosb ;stuff in internal buffer
jmp NameLup ;keep going
Name_Done:
mov byte ptr [di],0 ;AsciiZ the name
sub di,dx ;start - end
mov cx,di ; = name length
CALL Write ;display filename
JMP SHORT Skp271 ;skip over user input
;Come here if no target file on command line.
Need_FileName:
CALL Get_User_Input ;prompt user for filename (may die)
Skp271: CALL Open_Files ;try to open the file(s) (may die)
CALL Process_File ;do the conversion (may die)
CALL Close_Files ;close up (may die)
JMP Completed ;say completed, terminate
Start endp
;Call if no target filename on the PSP command line. Called once
Get_User_Input proc near
MOV DX,OFFSET kbdbuff ;the buffer
mov si,dx ;point SI there also
MOV AH,0AH ;buffered kbd input
INT 21H
inc si ;bump SI to the length byte
lodsb ;snarf length byte, bump SI
or al,al ;anything in length byte?
JZ NoInput_Error ;nope, error msg, die
;SI now points to first char of input text
xor ah,ah ;clear msb
add si,ax ;point to the end
mov [si],ah ;stuff AsciiZ terminator
RET
NoInput_Error:
;User made a target filename null entry after the prompt.
;Message and die.
MOV DX,OFFSET noinput ;'No input file'
MOV CX,LEN1B7 ;msg length
MOV AL,0DH ;error
JMP Terminate ;terminate, ERRORLEVEL 0DH
Get_User_Input endp
Open_Files proc near ;called once
MOV DX,OFFSET bufftxt ;pointer to AsciiZ filename
MOV AX,3D00H ;open file for input (read only)
INT 21H
JB Open_Error ;failed
MOV inHandle,AX ;save the input handle
;DX still points to Asciiz filename .. we're gonna open it TWICE ..
;once for read and once for write .. ugh ..
MOV AX,3D01H ;open SAME file for output (write only)
INT 21H ;(DX is unchanged)
JB Open_Error ;failed
MOV outHandle,AX ;save the output handle
RET
Open_Error:
MOV DX,OFFSET openerr ;'cannot open file'
MOV CX,LEN18C ;msg length
JMP Terminate ;terminate, ERRORLEVEL in AL
Open_Files endp
Process_File proc near ;called once
MOV DX,OFFSET workmsg ;'Working'
MOV CX,LEN1C9 ;msg length
CALL Write ;display msg
MOV DX,OFFSET buff370 ;buffer just beyond code end
;(doesn't change)
Lup2EC:
MOV CX,0C800H ;most of remaining code space
MOV BX,inHandle ;this handle
MOV AH,3FH ;read from file/device
INT 21H
JB IoErr_End ;failed, die with error msg
;DOS returns bytes actually read in AX
or ax,ax ;file end?
JZ File_Eof ;yep, return
mov bx,ax ;save bytes read in BX
inc ax ;bump in case it's odd
shr ax,1 ;/2 for words
MOV CX,AX ;use as counter
MOV SI,dx ;start at file read buffer top
mov ax,7F7FH ;masking constant
MaskLup:
AND [SI],ax ;mask both bytes to 7 bits
INC SI ;bump the pointer
inc si ;by words
LOOP MaskLup ;for all bytes read
mov cx,bx ;restore orig bytes read
MOV BX,outHandle ;output handle
MOV AH,40H ;write to file/device
INT 21H ;(DX is still unchanged)
JB IoErr_End ;write failed, msg and die
mov bx,dx ;save DX a sec
MOV AH,6 ;direct kbd/display/IO
MOV DL,'.' ;display a dot to show we're working
INT 21H
mov dx,bx ;restore DX buffer offset
JMP Lup2EC ;back for another buffer full
File_Eof:
RET
Process_File endp
Close_Files proc near ;called once
MOV AH,3EH ;close file handle
MOV BX,inHandle ;input file
INT 21H
JB CloseErr_End ;failed
MOV AH,3EH ;close file handle
MOV BX,outHandle ;output file
INT 21H
JB CloseErr_End ;failed
RET
Close_Files endp
Shut_Down proc near ;lump these together to be neat
CloseErr_End:
MOV DX,OFFSET closerr ;'cannot close file'
MOV CX,LEN1A1 ;msg length
JMP SHORT Terminate ;msg, terminate
IoErr_End: ;jumped to twice
MOV DX,OFFSET ioerr ;'I/O Error'
MOV CX,LEN1D4 ;msg length
JMP SHORT Terminate ;msg, terminate
Completed: ;jumped to once
MOV DX,OFFSET donemsg ;'Complete'
MOV CX,LEN1E2 ;msg length
xor al,al ;ERRORLEVEL 0
Terminate: ;jumped to 5 times
push ax ;save error value
call Write ;display msg in DX, CX
pop ax ;restore errorlevel
MOV AH,4CH ;Terminate process (errorlevel in AL)
INT 21H
Shut_Down endp
;Call with DX=pointer to write buffer, CX=nr bytes to write.
Write proc near
MOV AH,40H ;write to file/device
MOV BX,1 ;to Std Out
INT 21H
RET
Write endp
buff370 label byte ;read/write buffer beyond code
CSeg ENDS
END NoBit7