home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Du Jour
/
SoftwareDuJour.iso
/
BUSINESS
/
DBASE
/
DBAPG.ARC
/
FIX-DOS.ASM
< prev
next >
Wrap
Assembly Source File
|
1984-08-12
|
6KB
|
278 lines
; Subroutine.: FIX.ASM
; Author.....: Bob Doolittle
; Date.......: 08/12/84
; Notice.....: Copyright 1984, Ashton-Tate, All Rights Reserved.
; Notes......: PC/MS-DOS version.
;
M EQU Byte Ptr 0[BX]
;
CSEG SEGMENT
ASSUME CS:CSEG,DS:CSEG
ORG 100H
;
;BDOS equates
;
BDOS EQU 21H ;BDOS entry point
TBUF EQU 80H ;Default buffer
FCB EQU 5CH ;Default FCB
CFS EQU 35 ;Compute file size
CONIN EQU 1 ;Console in
CONOUT EQU 2 ;Console out
PSTR EQU 9 ;Print string
STRIN EQU 10 ;String input function
OPEN EQU 15 ;Open file
CLOSE EQU 16 ;Close file
READ EQU 20 ;Read sequential
WRITE EQU 21 ;Write sequential
MAKE EQU 22 ;Make file
DELETE EQU 19 ;Delete file
READR EQU 33 ;Read random
;
;ASCII equates
;
CR EQU 13
LF EQU 10
;
START: MOV Byte Ptr FLG,0 ;Initialize CRLF flag to destroy CRLF
MOV BX,FCB+1
MOV AL,Byte Ptr [BX]
CMP AL,20H ;Was input file on command line
JNZ ST2 ;Yes
MOV DX,(Offset MES1) ;No, print message and abort
MOV AH,PSTR
INT BDOS
JMP EXIT
;
ST2: MOV DX,(Offset MES4) ;Print CRLF message
MOV AH,PSTR
INT BDOS
MOV AH,CONIN ;Get response
INT BDOS
AND AL,5FH ;Make upper case
CMP AL,'Y'
JNZ ST7
MOV AL,1
MOV Byte Ptr FLG,AL
ST7: MOV AH,PSTR ;Ask for # of bytes
MOV DX,(Offset MES6)
INT BDOS
MOV DX,(Offset CBUF) ;Get response
MOV AH,STRIN
INT BDOS
MOV BX,(Offset CBUF)+2
CALL CONV ;Convert to binary in HL
CALL DIV ;Divide by 128
MOV Word Ptr QUO,BX ;Save quotient and remainder
CALL CRLF
CALL CLEAR ;Clear FCB+32-35, FCB+15 and FCB+12
MOV BX,FCB
MOV DX,(Offset FCB1)
MOV CL,9
MOVE: MOV AL,M ;Move file name and drive from FCB to FCB1
MOV SI,DX
MOV [SI],AL
INC BX
INC DX
DEC CL
JNZ MOVE
MOV DX,FCB
MOV AH,OPEN ;Open file
INT BDOS
INC AL ;Was open successful?
JNZ ST3 ;Yes
MOV DX,(Offset MES2) ;No, print message and abort
MOV AH,PSTR
INT BDOS
JMP EXIT
ST3: MOV DX,(Offset MES5) ;Working message
MOV AH,PSTR
INT BDOS
MOV DX,FCB
MOV AH,CFS ;Compute file size
INT BDOS
MOV BX,FCB+33
MOV AX,Word Ptr [BX]
MOV REC,AX
DEC Word Ptr [BX]
MOV AH,READR
MOV DX,FCB
INT BDOS ;Read last record
MOV BX,TBUF-1
MOV CL,0 ;Initialize counter
LOP: INC BX ;Scan to 1st EOF mark and keep count
INC CL
CMP M,1AH ;Is it EOF?
JNZ LOP ;No, keep looping
PUSH CX ;Save count to EOF in last record
CALL CLEAR ;Clear again
MOV DX,(Offset FCB1)
MOV AH,DELETE ;Delete any possible previous out file
INT BDOS
MOV DX,FCB
MOV AH,OPEN ;Re-open the input file
INT BDOS
MOV DX,(Offset FCB1)
MOV AH,MAKE ;Make output file
INT BDOS
;
FIRS: MOV DX,FCB ;Scan off quotient records
MOV AH,READ
INT BDOS
OR AL,AL
JZ FST1 ;Read OK
MOV DX,(Offset MES3)
MOV AH,PSTR
INT BDOS
POP CX ;Balance stack
JMP EXIT
;
FST1: MOV BX,Word Ptr REC ;Bump record count down
DEC BX
MOV Word Ptr REC,BX
MOV BX,Word Ptr QUO ;Get DIV result
OR BH,BH ;Have we read sector with remainder ?
JZ FST2 ;Yes
DEC BH ;No
MOV Word Ptr QUO,BX
MOV DX,(Offset FCB1) ;Write sector
MOV AH,WRITE
INT BDOS
JMP SHORT FIRS
FST2: ADD BL,80H ;BX now has filter start address
FST3: CALL FILTER
INC BX
OR BH,BH
JZ FST3 ;Filter to end of sector
MOV DX,(Offset FCB1)
MOV AH,WRITE ;Write to output file
INT BDOS
LOOP: MOV DX,FCB
MOV AH,READ ;Read a record to default buffer
INT BDOS
OR AL,AL ;Was read successful?
JZ LO4 ;Yes
ERR: MOV DX,(Offset MES3)
MOV AH,PSTR ;No, print message and abort
INT BDOS
POP CX ;Balance stack
JMP SHORT EXIT
;
LO4: DEC Word Ptr REC ;Decrement record count
JNZ GOAH ;Not at last record
POP CX ;Get back count
MOV BX,TBUF
;
LO1: DEC CL ;Are we at EOF
JZ LO2 ;Yes
CALL FILTER
INC BX
JMP SHORT LO1 ;Loop
;
LO2: MOV DX,(Offset FCB1)
MOV AH,WRITE ;Write last record
INT BDOS
MOV DX,(Offset FCB1)
MOV AH,CLOSE ;Close output file
INT BDOS
EXIT: MOV AH,0 ;Finished
INT BDOS
;
GOAH: MOV BX,TBUF
MOV CX,80H ;Initialize record count
GO1: CALL FILTER ;Scan the record
INC BX
LOOP GO1
MOV DX,(Offset FCB1)
MOV AH,WRITE ;Write record to output file
INT BDOS
JMP SHORT LOOP ;Loop to read next record
;
FILTER: AND M,7FH ;Strip bit 7
CMP M,20H ;Is it < space ?
JNAE L_1
RET ;No
L_1: TEST Byte Ptr FLG,0FFH ;Are we killing CRLF ?
JZ FIL1 ;Yes
MOV AL,M
CMP AL,CR
JNZ L_2
RET ;Don't change
L_2: CMP AL,LF
JNZ FIL1
RET ;Don't change
FIL1: MOV M,20H ;Replace anything < space by space
RET
;
CONV: MOV DX,0 ;Convert # pointed to by HL to binary in HL
XCHG BX,DX ;Conversion stops when # < '0' is found
MOV SI,DX ;Result returned in BX
MOV AH,0
CONV1: MOV AL,[SI]
SUB AL,'0'
JNS L_4
RET
L_4: CMP AL,10
CMC
JNB L_5
RET
L_5: INC SI
SHL BX,1
MOV CX,BX
SHL BX,1
SHL BX,1
ADD BX,CX
ADD BX,AX
JMP SHORT CONV1
;
DIV: MOV AX,BX ;Divide BX by 128
MOV CL,128
DIV CL
MOV BH,AL ;Quotient in BH, remainder in BL
MOV BL,AH
RET
;
CLEAR: XOR AL,AL ;Zero key fields in FCB
MOV BX,FCB+32
MOV M,AL
INC BX
MOV M,AL
INC BX
MOV M,AL
INC BX
MOV M,AL
MOV BX,FCB+15
MOV Byte Ptr [BX],AL
MOV BX,FCB+12
MOV Byte Ptr [BX],AL
RET
;
CRLF: MOV DL,CR
MOV AH,CONOUT
INT BDOS
MOV DL,LF
MOV AH,CONOUT
INT BDOS
RET
MES1 DB CR,LF,' USAGE: FIX [d:]<filename.typ>'
DB CR,LF,'where d is an optional drive designator'
DB CR,LF,'and filename.typ is the file name and type'
DB CR,LF,'of the file to be processed. The output'
DB CR,LF,'file will be named filename.FIX.$'
MES2 DB CR,LF,'Cannot find file on specified drive.$'
MES3 DB CR,LF,'Read past EOF.$'
MES4 DB CR,LF,'Do you want to preserve CRLFs (Y or N) ? $'
MES5 DB CR,LF,'Working...$'
MES6 DB CR,LF,'What is the size of the header (in bytes)? $'
CBUF DB 10,0
DB 0,0,0,0,0,0,0,0,0,0,0,0
REC DW 0 ;Storage for record count
QUO DW 0 ;Storage for quotient and remainder
FLG DB 0 ;CRLF flag
FCB1 DB 0,' FIX'
DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
CSEG ENDS
END START