home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
bitstrip.asm
< prev
next >
Wrap
Assembly Source File
|
1990-10-21
|
6KB
|
287 lines
; Utility: BITSTRIP
;
; by Ralph Davis
;
; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
;
;***********************************************
CODESEG SEGMENT BYTE PUBLIC
ASSUME CS:CODESEG,DS:CODESEG,ES:CODESEG
;
;----------------------------------------------
STRIP PROC FAR
ORG 100H
START: JMP ENTER
KEY_BUFF DB 80,?
ASCIIZ DB 80 DUP (?)
FILE_BUFF DB 20000 DUP (?)
BYTES_READ DW ?
BAD_DOS DB 'INCORRECT DOS VERSION - MUST BE 2.0 OR GREATER'
DB 0DH,0AH,'$'
ERRMSG1 DB 'FILE NOT FOUND',0DH,0AH,'$'
ERRMSG2 DB 'ACCESS DENIED',0DH,0AH,'$'
ERRMSG3 DB 'READ ACCESS TO REQUESTED FILE NOT PERMITTED'
DB 0DH,0AH,'$'
ERRMSG4 DB 'INVALID FILE HANDLE',0DH,0AH,'$'
ERRMSG5 DB 'PATH NOT FOUND',0DH,0AH,'$'
ERRMSG6 DB 'TOO MANY FILES ARE OPEN',0DH,0AH,'$'
ERRMSG7 DB 'WRITE TO SPECIFIED FILE NOT PERMITTED'
DB 0DH,0AH,'$'
FILEMSG DB 'PLEASE ENTER DRIVE, PATH, AND FILENAME: ','$'
;
ENTER:
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
MOV AX,CS
MOV DS,AX
MOV ES,AX
CLC
CALL CHECK_DOS
JNC DOS_OK
MOV DX,OFFSET BAD_DOS
CALL PRINTMESS
JMP EXIT
DOS_OK:
MOV SI,80H
MOV DI,OFFSET ASCIIZ
XOR CX,CX
MOV CL,[SI]
CMP CL,0
JNZ YES_FILE
MOV DX,OFFSET FILEMSG
CALL PRINTMESS
MOV DX,OFFSET KEY_BUFF
MOV AH,0AH
INT 21H
CALL CRLF
INC DX
MOV BX,DX
ADD DL,BYTE PTR [BX]
ADC DX,0
INC DX
MOV BX,DX
MOV BYTE PTR [BX],0
JMP PROCESS_FILE
YES_FILE:
DEC CL
ADD SI,2
CLD
REP MOVSB
MOV BYTE PTR [DI],0
PROCESS_FILE:
CLC
MOV AL,2
CALL OPEN_FILE
MOV BX,AX
JC EXIT
READIT:
CLC
CALL READ_FILE
JC EXIT
CLC
CALL STRIP_BITS
CLC
MOV AL,1 ; Seek to beginning of block read
MOV DX,BYTES_READ
NEG DX ; Make negative for negative offset
XOR CX,CX
DEC CX
CALL FILESEEK
JC EXIT
CLC
CALL WRITE_FILE
JC EXIT
CMP BYTES_READ,20000
JNE EXIT ; No more left to read
JMP READIT
EXIT:
CALL CLOSE_FILE
POP DI
POP SI
POP DX
POP CX
POP BX
POP AX
INT 20H
STRIP ENDP
;-------------------------------------------
CHECK_DOS PROC NEAR
PUSH AX
MOV AH,30H
INT 21H
CMP AL,2
POP AX
RET
CHECK_DOS ENDP
;--------------------------------------------
OPEN_FILE PROC NEAR
PUSH DX
MOV AH,3DH
MOV DX,OFFSET ASCIIZ
INT 21H
JNC LEAVE
CMP AL,2
JNZ CHECK_PATH
MOV DX,OFFSET ERRMSG1
CALL PRINTMESS
STC
JMP LEAVE
CHECK_PATH:
CMP AL,3
JNZ CHECK_FILES
MOV DX,OFFSET ERRMSG5
CALL PRINTMESS
STC
JMP LEAVE
CHECK_FILES:
CMP AL,4
JNZ ACCESS_ERR
MOV DX,OFFSET ERRMSG6
CALL PRINTMESS
STC
JMP LEAVE
ACCESS_ERR:
CMP AL,5
JNZ BAD_CODE
MOV DX,OFFSET ERRMSG2
CALL PRINTMESS
STC
JMP LEAVE
BAD_CODE:
MOV DX,OFFSET ERRMSG3
CALL PRINTMESS
STC
LEAVE:
POP DX
RET
OPEN_FILE ENDP
;-----------------------------------------
READ_FILE PROC NEAR
PUSH AX
PUSH CX
PUSH DX
MOV CX,SIZE FILE_BUFF
MOV DX,OFFSET FILE_BUFF
MOV AH,3FH
INT 21H
JNC GOOD_READ
CMP AL,5
JNZ BAD_HANDLE
MOV DX,OFFSET ERRMSG3
CALL PRINTMESS
STC
JMP LEAVE_READ
BAD_HANDLE:
MOV DX,OFFSET ERRMSG4
CALL PRINTMESS
STC
JMP LEAVE_READ
GOOD_READ:
MOV BYTES_READ,AX
LEAVE_READ:
POP DX
POP CX
POP AX
RET
READ_FILE ENDP
;-------------------------------------------
CLOSE_FILE PROC NEAR
PUSH AX
PUSH DX
MOV AH,3EH
INT 21H
JNC LEAVE_CLOSE
MOV DX,OFFSET ERRMSG4
CALL PRINTMESS
STC
LEAVE_CLOSE:
POP DX
POP AX
RET
CLOSE_FILE ENDP
;-------------------------------------------
STRIP_BITS PROC NEAR
PUSH CX
PUSH BX
MOV BX,OFFSET FILE_BUFF
MOV CX,BYTES_READ
STRIPPER:
AND BYTE PTR [BX],7FH
INC BX
LOOP STRIPPER
POP BX
POP CX
RET
STRIP_BITS ENDP
;-------------------------------------------
WRITE_FILE PROC NEAR
PUSH AX
PUSH CX
PUSH DX
MOV AH,40H
MOV DX,OFFSET FILE_BUFF
MOV CX,BYTES_READ
INT 21H
JNC LEAVE_WRITE
CMP AL,5
JNZ HANDLE_BAD
MOV DX,OFFSET ERRMSG7
CALL PRINTMESS
STC
JMP LEAVE_WRITE
HANDLE_BAD:
MOV DX,OFFSET ERRMSG4
CALL PRINTMESS
STC
LEAVE_WRITE:
POP DX
POP CX
POP AX
RET
WRITE_FILE ENDP
;-------------------------------------------
FILESEEK PROC NEAR
; Expects file handle in BX, seek mode in AL
; 0 -- from beginning of file
; 1 -- from current offset
; 2 -- from end-of-file
; CX:DX offset to move file pointer
; Returns new offset in DX:AX
MOV AH,42H
INT 21H
RET
FILESEEK ENDP
;------------------------------------------------------
PRINTMESS PROC NEAR
PUSH AX
MOV AH,9
INT 21H
POP AX
RET
PRINTMESS ENDP
;------------------------------------------
CRLF PROC NEAR
PUSH AX
PUSH DX
MOV DL,0DH
MOV AH,2
INT 21H
MOV DL,0AH
MOV AH,2
INT 21H
POP DX
POP AX
RET
CRLF ENDP
;------------------------------------------
CODESEG ENDS
;********************************************
END START