home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
txtutl
/
nobit71.arc
/
NOBIT7.ASM
next >
Wrap
Assembly Source File
|
1988-12-01
|
7KB
|
265 lines
TITLE NOBIT7 10-19-88 [12-1-88]
;Disassembled via ASMGEN.
;(Silly that a wee little program, doing such a wee simple little thing,
;shouldn't be released with source code.)
;This is the untweaked version .. a straight disassembly and comment.
;See NOBIT71.ASM for tweaked source!
;
;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 100H
NoBit7 proc near
JMP Start ;skip over data
DB 8,8,8,'Copyright (c) 1988, Ray Johns'
db ' - Why are you typing a .COM file ?',1AH
stdoutHandle dw 1 ;file handle (STDOUT)
inHandle dw 0
outHandle dw 0
logo DB CR,LF
DB 'NOBIT7 - 1.00 - Copyright (c) 1988, Ray Johns'
db CR,LF,LF
LOGOLEN = $ - logo
inputPrompt DB 'Input file : '
INPPLEN = $ - inputPrompt
openerr DB CR,LF,LF,'Cannot open file',CR,LF
LEN18C = $ - openerr
closerr DB CR,LF,LF,'Cannot close file',CR,LF
LEN1A1 = $ - closerr
noinput DB CR,LF,LF,'No input file',CR,LF
LEN1B7 = $ - noinput
workmsg DB CR,LF,LF,'Working '
LEN1C9 = $ - workmsg
ioerr DB CR,LF,LF,'I/O error',CR,LF
LEN1D4 = $ - ioerr
donemsg DB CR,LF,LF,'Complete',CR,LF
LEN1E2 = $ - donemsg
kbdbuff1EF 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
CALL Display_Logo
MOV CH,0 ;clear msb
MOV CL,DS:80H ;get PSP cmdline length byte
CMP CX,1 ;anything there?
JBE Need_FileName ;nope, prompt for a target filename
PUSH CX ;save target filename length
MOV AL,' ' ;scanning for a space
MOV DI,81H ;start at (supposed) first char
REPZ SCASB ;do the scan
POP CX ;restore filename length
JZ Need_FileName ;bad name, go prompt for one
MOV SI,81H ;back to filename start
CMP [SI],AL ;leading space?
JNZ Skp256 ;nope, ok
DEC CX ;adjust for leading space
INC SI ;bump past space
Skp256: PUSH CX ;save filename length
MOV DI,OFFSET bufftxt ;move filename into internal buffer
REPZ MOVSB
MOV CX,INPPLEN ;0DH ;msg length
MOV DX,OFFSET inputPrompt ;'Input: '
CALL Write ;display msg
POP CX ;restore filename length
MOV DX,OFFSET bufftxt ;write from here
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
Display_Logo proc near ;called once
MOV CX,LOGOLEN ;32H ;msg length
MOV DX,OFFSET logo ;'NOBIT7..' logo
CALL Write ;display msg
RET
Display_Logo endp
;Call if no target filename on the PSP command line. Called once
Get_User_Input proc near
MOV CX,INPPLEN ;0DH ;msg length
MOV DX,OFFSET inputPrompt ;'Input: '
CALL Write ;display prompt
MOV AH,0AH ;buffered kbd input
MOV DX,OFFSET kbdbuff1EF ;the buffer
INT 21H
CMP BYTE PTR bufflen,0 ;anything in length byte?
JZ NoInput_Error ;nope, error msg, die
MOV DI,OFFSET bufftxt ;start of user input
MOV AH,0 ;clear msb
MOV AL,bufflen ;snarf the length byte
ADD DI,AX ;point to the end
MOV BYTE PTR [DI],0 ;stuff an AsciiZ terminator at end
RET
NoInput_Error:
;User made a target filename null entry after the prompt.
;Message and die.
MOV CX,LEN1B7 ;12H ;msg length
MOV DX,OFFSET noinput ;'No input file'
CALL Write ;display msg
MOV AL,0DH ;error
JMP Terminate ;terminate, ERRORLEVEL 0DH
Get_User_Input endp
Open_Files proc near ;called once
MOV AX,3D00H ;open file for input (read only)
MOV DX,OFFSET bufftxt ;pointer to AsciiZ filename
INT 21H
JB Open_Error ;failed
MOV inHandle,AX ;save the input handle
MOV AX,3D01H ;open SAME file for output (write only)
MOV DX,OFFSET bufftxt ;pointer to AsciiZ filename
INT 21H
JB Open_Error ;failed
MOV outHandle,AX ;save the output handle
RET
Open_Error:
PUSH AX ;save error value
MOV CX,LEN18C ;15H ;msg length
MOV DX,OFFSET openerr ;'cannot open file'
CALL Write ;display msg
POP AX ;restore error value
JMP Terminate ;terminate, ERRORLEVEL in AL
Open_Files endp
;L02E3 L0274 CC
Process_File proc near
MOV CX,LEN1C9 ;0BH ;msg length
MOV DX,OFFSET workmsg ;'Working'
CALL Write ;display msg
Lup2EC: MOV AH,3FH ;read from file/device
MOV BX,inHandle ;this handle
MOV CX,0C800H ;most of remaining code space
MOV DX,OFFSET buff370 ;buffer just beyond code end
INT 21H
JB IoErr_End ;failed, die with error msg
CMP AX,0 ;file end?
JZ File_Eof ;yep, return
PUSH AX ;save bytes read
MOV CX,AX ;use as counter
MOV SI,OFFSET buff370 ;start at file read buffer top
Lup307: AND BYTE PTR [SI],7FH ;mask the byte to 7 bits
INC SI ;bump the pointer
LOOP Lup307 ;for all bytes read
MOV AH,40H ;write to file/device
MOV BX,outHandle ;this handle
POP CX ;restore orig bytes read
MOV DX,OFFSET buff370 ;buffer start
INT 21H
JB IoErr_End ;write failed, msg and die
MOV AH,6 ;direct kbd/display/IO
MOV DL,'.' ;display a dot to show we're working
INT 21H
JMP SHORT 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:
PUSH AX ;save error value in AL
MOV CX,LEN1A1 ;16H ;msg length
MOV DX,OFFSET closerr ;'cannot close file'
CALL Write ;display msg
POP AX ;restore error value
JMP SHORT Terminate ;terminate
; NOP
IoErr_End: ;jumped to twice
PUSH AX
MOV CX,LEN1D4 ;0EH ;msg length
MOV DX,OFFSET ioerr ;'I/O Error'
CALL Write ;display msg
POP AX
JMP SHORT Terminate
; NOP
Completed: ;jumped to once
MOV CX,LEN1E2 ;0DH ;msg length
MOV DX,OFFSET donemsg ;'Complete'
CALL Write ;display msg
MOV AL,0 ;ERRORLEVEL 0
JMP SHORT Terminate
; NOP
Terminate: ;jumped to 5 times
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,stdoutHandle ;this handle (Std Out)
INT 21H
RET
Write endp
buff370 DB 0
CSeg ENDS
END NoBit7