home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_100
/
142_01
/
crcbuild.a86
< prev
next >
Wrap
Text File
|
1985-03-10
|
20KB
|
1,009 lines
TITLE 'CRCBUILD.A86'
;
;CP/M-86 version by Bill Bolton,
; Software Tools RCPM,
; P.O. Box 357,
; Kenmore,
; QLD, 4069,
; Australia
;
;International 61-7-378-9530+
;Domestic (07) 378-9530 300bps CCITT V.21 standard
;
; *********** NOTE WELL ************
;
; This version uses the "old" CRC polynomial code as
; incorrectly described in EDN all those years back
; and generates the same CRCKs as most other CRC programs,
; including the CRC options in YAM, MODEM and MEX.
; The "new" CRC polynomial version of CRC, although
; a technically correct implementation of the polynomial,
; produces entirely different CRC values than those found in
; the CRCKLIST, CRCKFILE and -CATALOG files on most public
; domain disks. Even though the "old" polynomial code doesn't
; implement the polynomial correctly, it still works just as
; effectively as the correct polynomial for the purposes of
; identifying the integrity of files on a disk.
;
;This version is built on the 8086 small memory model and should
;be GENCMD with the following command
;
; GENCMD CRCBUILD
;
;Original CP/M-80 Version by JOHN L. RAFF WB2MDG/KAPP8107
;
;VERSION LIST, most recent version first
;
;04/Aug/84 CP/M-86 version created from CP/M-80 version. Removed
; all in line prints and restructured for 8086 small
; memory model. Removed a number of superfluous labels
; and some unused data storage. Now uses operating
; system 96 byte stack and tested for catalogs
; upto 99 entries. If there are more than 100 entries
; in a catalog, ID numbers after 99 will display
; oddly (the CP/M-80 version does this too).
; Version 1.0, Bill Bolton, Software Tools, Australia
;
;CRCBUILD IS A PROGRAM TO BUILD A CP/M FILE IN SIG/M
;-CATALOG FORMAT AND PRINT A CYCLIC-REDUNDANCY-CHECK
;NUMBER BASED ON THE CCITT STANDARD POLYNOMINAL:
; X^16 + X^15 + X^13 + X^7 + X^4 + X^2 + X + 1
;
; (well almost, see above comments)
;
;DEFINE TRUE AND FALSE
;
FALSE EQU 0
TRUE EQU NOT FALSE
;
;CONDITIONAL ASSEMBLY SWITCHES
;
NOSYS EQU FALSE ;TRUE IF SYS FILES NOT WANTED
;
BASE EQU 0
;
;DEFINE WRITE BUFFER SIZE (PRESENTLY SET FOR 8K)
;
BSIZE EQU 8*1024 ;DISK WRITE BUFFER SIZE
;
;BDOS EQUATES
;
RDCON EQU 1
WRCON EQU 2
PRINT EQU 9
READCONSOLE EQU 10 ;READ CONSOLE BUFFER
CSTAT EQU 11
OPEN EQU 15
CLOSE EQU 16
SRCHF EQU 17
SRCHN EQU 18
DELETE EQU 19
READ EQU 20
WRITE EQU 21
MAKE EQU 22
RENAME EQU 23
STDMA EQU 26
BDOS EQU 224
FCB EQU 5CH
FCBEXT EQU FCB+12
FCBRNO EQU FCB+32
FCB2 EQU 6CH
TBUF EQU 80H
STRLMT EQU 80 ;STRING LENGTH LIMIT
;
TAB EQU 07H ;ASCII tab
LF EQU 0AH ;ASCII line feed
CR EQU 0DH ;ASCII carriage return
EOF EQU 1AH ;CP/M end of file marker
;
SECT EQU 128 ;Size BDOS like to handle
CATSIZ EQU 2000H
M EQU Byte Ptr 0[BX]
;
;PROGRAM STARTS HERE
;
CSEG
ORG 0
;
BEGIN:
XOR AL,AL
MOV Byte Ptr NAMQUAN,AL ;ZERO THE QUANTITY OF FILES READ
; MOV BX,0 ;GET STACK...
; ADD BX,SP ;POINTER SO WE CAN..
; MOV Word Ptr STACK,BX ;SAVE IT
; MOV SP,(Offset STACK) ;INITIALIZE LOCAL STACK
BGN2:
CALL CRLF ;TURN UP A NEW LINE
MOV BX,(Offset SIGNON) ;Tell them who we are
CALL DISPLAY
MOV AL,Byte Ptr .FCB+1
CMP AL,' ' ;SEE IF NAME THERE
JNZ BEGIN2 ;YES, CONTINUE
MOV DX,FCB+2 ;PUT TOTAL DIRECTORY PATTERN
MOV BX,FCB+1 ;IN FCB
MOV M,'?' ;ALL "?"
MOV CX,10 ;4 CHARACTERS
CALL MOVER ;MOVE IT
JMPS BEGIN2 ;GO GET UM
;
THRNUM: ;CHECK FOR THREE ASCII NUMBERS
CALL TWONUM
JZ THR1
RET ;RETURN IF NOT NUMBERS
THR1:
CALL NUM
JNZ THR2
RET ;RETURN IF A NUMBER
THR2:
CMP AL,'.' ;CHECK FOR A PERIOD
JZ THR3
RET ;RETURN IF NOT A PERIOD
THR3:
DEC BX ;OTHERWISE BACK UP ONE CHARACTER
DEC CH ;AND ONE COUNT
CMP AL,AL ;SET ZERO FLAG
RET
;
TWONUM:
CALL NUM
JZ NUM
RET
;
NUM:
MOV AL,M ;GET THE CHARACTER
INC BX ;FOR NEXT CHARACTER
INC CH ;INCREMENT FOR NEXT COUNT
CMP AL,'0' ;IS IT LESS THAN 0
JB NUMNOT ;BRANCH IF IT IS
CMP AL,'9'+1 ;IS IT GREATER THAN 9?
JNB NUMNOT
CMP AL,AL ;SET ZERO FLAG
RET
;
NUMNOT:
CMP AL,'0' ;SHOULD NOT BE EQUAL, RESET ZERO FLAG
RET
;
BEG2NG:
MOV BX,(Offset WRONG)
CALL DISPLAY
BEGIN2:
MOV BX,(Offset ENTER)
CALL DISPLAY
MOV DX,(Offset STR4) ;POINT TO STRING 4
MOV AL,5 ;INDICATE SIZE OF BUFFER
MOV SI,DX
MOV [SI],AL
MOV CL,READCONSOLE ;READ CONSOLE BUFFER
INT BDOS ;GO GET THE STRING
MOV BX,(Offset STR4)+1 ;POINT TO QUANTITY CHARACTERS ENTERED
MOV CL,M ;GET THE COUNT
MOV AL,3 ;CHECK FOR THREE CHARACTERS
CMP AL,CL ;IN BUFFER
JNZ BEG2NG ;BRANCH IF NOT 3 CHARACTERS
MOV CH,0 ;ZERO COUNTER
LAHF ;POINT TO FIRST CHARACTER
INC BX
SAHF
BEG2A:
CALL NUM ;IS IT A DECIMAL NUMBER?
JNZ BEG2NG ;BRANCH IF NOT A DECIMAL NUMBER
MOV AL,CH ;CHECK QUANTITY OF CHARACTERS
CMP AL,3
JNZ BEG2A ;BRANCH IF NOT END OF CHARACTERS YET
MOV M,0 ;ENSURE TERMINATION OF STRING
MOV BX,(Offset STR4)+2 ;COPY NUMBER INTO FILE STRING
MOV DX,(Offset FNAME1)
MOV CX,3 ;COUNT
CALL MOVER
MOV AL,'F' ;INDICATE WRITE FILE OPEN
MOV Byte Ptr FFLAG,AL
;
;'DECLARE' FCB FOR OUTPUT FILE
;(TEMPORARILY NAMED -CATALOG.$$$)
;
JMP MAKCAT
;
PUTCATALOG:
LAHF
XCHG AL,AH
PUSH AX
MOV BX,Word Ptr CATLEN
XCHG BX,DX
MOV BX,Word Ptr CATPTR
MOV AL,BL
SUB AL,DL
MOV AL,BH
SBB AL,DH
JNB PUTCAT_1
JMP PUTCAT_5
;
PUTCAT_1:
MOV BX,0
MOV Word Ptr CATPTR,BX
PUTCAT_2:
XCHG BX,DX
MOV BX,Word Ptr CATLEN
MOV AL,DL
SUB AL,BL
MOV AL,DH
SBB AL,BH
JNB PUTCAT_4
MOV BX,Word Ptr CATADR
ADD BX,DX
XCHG BX,DX
MOV CL,STDMA
INT BDOS
MOV DX,(Offset FCBCAT)
MOV CL,WRITE
INT BDOS
OR AL,AL
JNZ PUTCAT_3
MOV DX,SECT
MOV BX,Word Ptr CATPTR
ADD BX,DX
MOV Word Ptr CATPTR,BX
JMPS PUTCAT_2
;
PUTCAT_3:
MOV CL,PRINT
MOV DX,(Offset FULLMSG)
INT BDOS
POP AX
XCHG AL,AH
JMP FILERR
;
PUTCAT_4:
MOV DX,TBUF
MOV CL,STDMA
INT BDOS
MOV BX,0
MOV Word Ptr CATPTR,BX
PUTCAT_5:
XCHG BX,DX
MOV BX,Word Ptr CATADR
ADD BX,DX
XCHG BX,DX
POP AX
XCHG AL,AH
SAHF
MOV SI,DX
MOV [SI],AL
MOV BX,Word Ptr CATPTR
LAHF
INC BX
SAHF
MOV Word Ptr CATPTR,BX
RET
;
MAKCAT:
XOR AL,AL
MOV Byte Ptr FCBCAT+12,AL
MOV Byte Ptr FCBCAT+32,AL
MOV BX,CATSIZ
MOV Word Ptr CATLEN,BX
MOV BX,0
MOV Word Ptr CATPTR,BX
MOV CL,DELETE
MOV DX,(Offset FCBCAT)
INT BDOS
MOV CL,MAKE
MOV DX,(Offset FCBCAT)
INT BDOS
INC AL
JNZ AGAIN
MOV CL,PRINT
MOV DX,(Offset SPACE)
INT BDOS
JMP FILERR
;
AGAIN:
; MOV SP,(Offset STACK) ;RE-INIT STACK POINTER
MOV AL,0 ;INDICATE IN BUILDING PHASE
MOV Byte Ptr WHICH,AL ;SAVE FLAG
CALL MFNAME ;SEARCH FOR NAMES
JNAE AGN_2
JMP NAMTST ;ANOTHER FOUND, PRINT NAME
;
AGN_2:
MOV AL,Byte Ptr MFFLG2 ;NOTHING FOUND, CHECK...
OR AL,AL ;... NAME FOUND FLAG
JZ DONE ;AT LEAST ONE WAS FOUND
JMP ABEXIT ;PRINT MSG, THEN EXIT
;
DONE: ;CLOSE -CATALOG.$$$
MOV BX,(Offset FNAME1)
MOV DX,(Offset DONEX)
MOV CX,3
CALL MOVER
MOV BX,(Offset FOOT1)
CALL DISPLAY
MOV AL,Byte Ptr NAMQUAN
CALL SHWDC
MOV BX,(Offset FOOT2)
CALL DISPLAY
DONE_2:
MOV BX,Word Ptr CATPTR
MOV AL,BL
AND AL,(SECT-1) AND 0FFH
JNZ DONE_3
MOV Word Ptr CATLEN,BX
DONE_3:
MOV AL,EOF
LAHF
XCHG AL,AH
PUSH AX
XCHG AL,AH
CALL PUTCATALOG
POP AX
XCHG AL,AH
SAHF
JNZ DONE_2
MOV CL,CLOSE
MOV DX,(Offset FCBCAT)
INT BDOS
INC AL
JNZ DONE_4
MOV CL,PRINT
MOV DX,(Offset CLSMSG)
INT BDOS
DONE_4:
MOV BX,(Offset STR4)+2 ;POINT TO BEGINNING OF STRING
MOV DX,(Offset FCBFINAL)+9 ;LOCATION OF NAME TYPE
MOV CX,3 ;QUANTITY TO MOVE
CALL MOVER
;
; ERASE ANY EXISTING OLD FILE
;
ERASE:
MOV CL,DELETE
MOV DX,(Offset FCBFINAL)
INT BDOS
;
; RENAME -CATALOG.$$$ TO -CATALOG.NNN
JMPS REN_2
;
RENS:
PUSH BX
MOV CX,16
LAHF
ADD BX,CX
RCR SI,1
SAHF
RCL SI,1
REN_1:
MOV SI,DX
MOV AL,[SI]
MOV M,AL
LAHF
INC DX
SAHF
LAHF
INC BX
SAHF
DEC CL
JNZ REN_1
POP DX
MOV CL,RENAME
INT BDOS
RET
;
REN_2:
MOV BX,(Offset FCBCAT)
MOV DX,(Offset FCBFINAL)
CALL RENS
;
;NOW EXIT TO CP/M
DONE_5:
MOV BX,(Offset DONEMSG) ;Display end then exit
CALL DISPLAY
JMP EXIT
;
;IGNORE FILES WITH .$$$ FILETYPE (THEY ARE USUALLY
;ZERO-LENGTH AND CLUTTER UP OUR DISPLAY. WE ALSO
;WANT TO IGNORE OUR OWN CRCKLIST.$$$ TEMPORARY FILE).
;
NAMTST:
MOV BX,FCB+9 ;POINT TO FILETYPE IN FCB
PUSH BX ;MAY NEED POINTER FOR BAD CHECK
CALL TSTBAD ;CHECK FOR .$$$ FILES
JNZ NAMTST_1
JMP AGAIN ;IF ZERO FLAG, IGNORE THEM
;
NAMTST_1:
POP BX ;RESTORE POINTER
CALL BADTYP ;CHECK FOR .BAD FILES
JNZ NAMTST_2
JMP AGAIN ;BRANCH IF IT IS
;
NAMTST_2:
MOV BX,(Offset NUMBER)
CALL DISPLAY
MOV AL,Byte Ptr NAMQUAN
INC AL ;INCREMENT COUNT
MOV Byte Ptr NAMQUAN,AL
CALL SHWDC ;SHOW THE COUNT
;
;MOVE 8 CHARACTERS FROM FCB+1 TO FNAME
;
MOV BX,FCB+1
MOV DX,(Offset FNAME)
MOV CX,8
CALL MOVER
;MOVE 3 CHARACTERS FROM FCB+9 TO FNAME+9
MOV BX,FCB+9
MOV DX,(Offset FNAME)+9
MOV CX,3
CALL MOVER
;NOW PRINT FILENAME.TYPE
MOV BX,(Offset FILEN)
CALL DISPLAY
FNAME2:
CALL OPN ;OPEN FILE AND BUILD CRC
JNZ FNAME_3
JMP AGAIN ;BRANCH IF BAD OPEN OR READ
;
FNAME_3:
JMP ABEXT_2 ;OTHERWISE GET OUT
;
;OPEN THE FILE
;
OPN:
MOV DX,FCB
MOV CL,OPEN
INT BDOS
INC AL
JNZ RDINIT
MOV BX,(Offset FAIL)
CALL DISPLAY
JMP BADRET ;INDICATE BAD OPEN
;
;INITIALIZE CRC TO ZERO AND SET BUFAD TO CAUSE INITIAL READ
;
RDINIT:
MOV BX,0
MOV Word Ptr REMAIN,BX ;INIT REMAINDER TO ZERO
MOV Word Ptr QUANEK,BX ;QUANTITY OF EIGHTH K
MOV BX,BASE+100H
MOV Word Ptr BUFAD,BX ;INIT BUFFER ADDRESS
;
;THIS IS THE READ LOOP
;
READIT:
MOV BX,Word Ptr BUFAD
MOV AL,BH ;TIME TO READ?
CMP AL,BASE SHR 8 ;END OF BUFFER?
JZ NORD
MOV CL,CSTAT
INT BDOS ;CHCK FOR OPERATOR ABORT
OR AL,AL
JZ READ2 ;BRANCH IF NOTHING FROM OPERATOR
MOV CL,RDCON
INT BDOS ;GET CHARACTER FROM OPERATOR
CMP AL,'C'-40H ;CONTROL C?
JNZ READ2
JMP ABEXT_2 ;BRANCH IF YES, EXIT
;
READ2:
MOV DX,FCB
MOV CL,READ ;READ ANOTHER SECTOR OF FILE
INT BDOS
OR AL,AL ;CHECK RETURN CODE
JNZ FINISH ;ERROR OR EOF
MOV BX,Word Ptr QUANEK ;GET QUANTITY OF EIGHTH K
INC BX ;ADD 1
MOV Word Ptr QUANEK,BX ;PUT BACK
MOV BX,BASE+80H ;BUFER LOCATION
;
NORD:
MOV AL,M ;GET FILE CHARACTER
MOV Byte Ptr MESS,AL ;SAVE FOR DIVP
INC BX
MOV Word Ptr BUFAD,BX ;UPDATE BUFFER ADDRESS
CALL DIVP ;CALCULATE NEW CRC
JMPS READIT ;GO READ MORE CHARACTERS
;
FINISH:
CMP AL,1 ;NORMAL END-OF-FILE?
JNZ FILERR ;NO, IT WAS A READ ERROR
MOV BX,Word Ptr QUANEK ;GET QUANTITY OF EIGHTH K
MOV CX,7
LAHF ;ROUND UP TO NEXT K
ADD BX,CX
SAHF
SHL BX,1 ;TURN INTO FULL K
SHL BX,1 ;IN "H" REGISTER
SHL BX,1
SHL BX,1
SHL BX,1
MOV AL,BH
CALL SHWDEC ;SHOW NUMBER OF K
MOV BX,(Offset KSIZE)
CALL DISPLAY
MOV AL,Byte Ptr REMAIN+1 ;GET MSP OF CRC
CALL HEXO ;PRINT IT
MOV AL,' '
CALL TYPER ;TYPE A SPACE
MOV AL,Byte Ptr REMAIN ;GET LSP OF CRC
CALL HEXO ;PRINT IT
GOODRET:
XOR AL,AL
RET ;RETURN TO CALLER WITH ZERO FLAG SET
;
FILERR:
MOV BX,(Offset FERROR)
CALL DISPLAY ;PRINT THE MESSAGE AND RETURN
BADRET: ;GENERAL BAD RETURN LOCATION
XOR AL,AL ;SET ZERO FLAG
INC AL ;RESET ZERO FLAG
RET ;RETURN TO CALLER
;
;---------------------------------------------
;AN 8086 ROUTINE FOR GENERATING A CYCLIC-
;REDUNDANCY-CHECK. CHARACTER LEAVES THAT
;CHARACTER IN LOCATION REM. BY FRED GUTMAN.
;FROM 'EDN' MAGAZINE, JUNE 5, 1979 ISSUE, PAGE 84.
;
DIVP:
MOV BX,Word Ptr REMAIN ;GET REMAINDER
MOV AL,BH
AND AL,128 ;Q-BIT MASK
LAHF ;SAVE STATUS
XCHG AL,AH
PUSH AX
SHL BX,1 ;2 X R(X)
MOV AL,Byte Ptr MESS ;MESSAGE BIT IN LSB
ADD AL,BL
MOV BL,AL
POP AX
XCHG AL,AH
SAHF
JZ QB2 ;IF Q-BIT IS ZERO
;
QB:
MOV AL,BH
XOR AL,0A0H ;MS HALF OF GEN. POLY
MOV BH,AL
MOV AL,BL
XOR AL,97H ;LS HALF OF GEN. POLY
MOV BL,AL
;
QB2:
MOV Word Ptr REMAIN,BX
RET
;
;--------------------------------------------
;
;HEX OUTPUT
;
HEXO:
LAHF ;SAVE FOR RIGHT DIGIT
XCHG AL,AH
PUSH AX
XCHG AL,AH
RCR AL,1 ;RIGHT..
RCR AL,1 ;..JUSTIFY..
RCR AL,1 ;..LEFT..
RCR AL,1 ;..DIGIT..
CALL NIBBL ;PRINT LEFT DIGIT
POP AX ;RESTORE RIGHT
XCHG AL,AH
;
NIBBL:
AND AL,0FH ;ISOLATE DIGIT
CMP AL,10 ;IS IS <10?
JB ISNUM ;YES, NOT ALPHA
ADD AL,7 ;ADD ALPHA BIAS
;
ISNUM:
ADD AL,'0' ;MAKE PRINTABLE
JMPS TYPER ;PRINT IT, THEN RETURN
;
;INLINE PRINT ROUTINE
;
DISPLAY:
MOV AL,M ;GET CHAR
CALL TYPER ;OUTPUT IT
INC BX ;POINT TO NEXT
MOV AL,M ;TEST
CMP AL,'$' ;..FOR END
JNZ DISPLAY
RET ;RET PAST MSG
;
;SEND CARRIAGE RETURN, LINE FEED TO OUTPUT
;
CRLF:
MOV AL,CR ;CARRIAGE RETURN
CALL TYPER
MOV AL,LF ;LINE FEED, FALL INTO 'TYPE'
;
;SEND CHARACTER IN A REGISTER TO OUTPUT
;
TYPER:
PUSH CX
PUSH DX
PUSH BX
AND AL,7FH ;STRIP PARITY BIT
MOV DL,AL
PUSH DX
CALL WRFILE ;WRITE TO FILE IF REQUESTED
POP DX
MOV CL,WRCON ;SEND CHRACTER TO CONSOLE
INT BDOS
POP BX
POP DX
POP CX
RET
;
; WRITE CHARACTER IN E REGISTER TO OUTPUT FILE
;
WRFILE:
MOV AL,Byte Ptr FFLAG ;GET FILE TRIGGER
CMP AL,'F' ;IS IT SET?
JZ WRF_1
RET ;NO?, RETURN
;
WRF_1:
MOV AL,DL ;GET CHARACTER BACK
CALL PUTCATALOG
RET ;TO CALLER
;
;MULTI-FILE ACCESS SUBROUTINE. ALLOWS PROCESSING
;OF MULTIPLE FILES <I.E. *.ASM> FROM DISK. THIS
;ROUTINE BUILDS THE PROPER NAME IN THE FCB EACH
;TIME IT IS CALLED. CARRY IS SET IF NO MORE NAMES
;CAN BE FOUND. THE ROUTINE IS COMMENTED IN PSEUDO
;CODE, EACH PSEUDO CODE STATEMENT IS IN <<...>>
;
MFNAME:
MOV CL,STDMA
MOV DX,BASE+80H
INT BDOS
XOR AL,AL
MOV Byte Ptr .FCBEXT,AL
MOV Byte Ptr .FCBRNO,AL
;<<IF FIRST TIME>>
MOV AL,Byte Ptr MFFLG1
OR AL,AL
JZ MFN01
;<<SAVE THE REQUESTED NAME>>
;SAVE ORIG REQUEST
MOV BX,FCB
MOV DX,(Offset MFREQ)
MOV CX,12
CALL MOVER
MOV AL,Byte Ptr .FCB
MOV Byte Ptr MFCUR,AL ;SAVE DISK IN CURR FCB
;<<SRCHF REQUESTED NAMD>>
MOV BX,(Offset MFREQ)
MOV DX,FCB
MOV CX,12
CALL MOVER
MOV CL,SRCHF
MOV DX,FCB
INT BDOS
;<<ELSE>>
JMPS MFN02
;
MFN01: ;<<SRCHF CURRENT NAME>>
MOV BX,(Offset MFCUR)
MOV DX,FCB
MOV CX,12
CALL MOVER
MOV CL,SRCHF
MOV DX,FCB
INT BDOS
;<<SRCHN REQUESTED NAME>>
MOV BX,(Offset MFREQ)
MOV DX,FCB
MOV CX,12
CALL MOVER
MOV CL,SRCHN
MOV DX,FCB
INT BDOS
;<<ENDIF>>
MFN02: ;<<RETURN CARRY IF NOT FOUND>>
INC AL
STC
JNZ MFN03
RET
;
;<<MOVE NAME FOUND TO CURRENT NAME>>
MFN03:
DEC AL
AND AL,3
ADD AL,AL
ADD AL,AL
ADD AL,AL
ADD AL,AL
ADD AL,AL
ADD AL,81H
MOV BL,AL
MOV BH,BASE SHR 8
PUSH BX ;SAVE NAME POINTER
MOV DX,(Offset MFCUR)+1
MOV CX,11
CALL MOVER
;<<MOVE NAME FOUND TO FCB>>
POP BX
MOV DX,FCB+1
MOV CX,11
CALL MOVER
;<<SETUP FCB>>
XOR AL,AL
MOV Byte Ptr .FCBEXT,AL
MOV Byte Ptr .FCBRNO,AL
MOV Byte Ptr MFFLG1,AL ;TURN OFF 1ST TIME SW
MOV Byte Ptr MFFLG2,AL ;FLAG INDICATING FOUND AT LEAST ONE
;<<RETURN>>
RET
;------------------------------------------------
;
;CHECK FOR .$$$ FILES
;
TSTBAD:
CALL TESTIT ;CHECK FIRST ONE FOR '$'
JZ TSTBAD_1
RET ;NO, RETURN
TSTBAD_1:
CALL TESTIT ;CHECK SECOND ONE
JZ TESTIT
RET ;NO, RETURN
;
;FALL INTO TESTIT TO CHECK THIRD
;
TESTIT:
MOV AL,M
AND AL,7FH ;STRIP ATTRIBUTE
CMP AL,'$' ;CHECK FOR $ FILETYPE
LAHF
INC BX
SAHF
RET
;
BADTYP: ;CHECK FOR BAD FILE TYPE
MOV AL,M
AND AL,7FH
CMP AL,'B'
JZ BADTYP_1
RET
;
BADTYP_1:
INC BX
MOV AL,M
AND AL,7FH
CMP AL,'A'
JZ BADTYP_2
RET
;
BADTYP_2:
INC BX
MOV AL,M
AND AL,7FH
CMP AL,'D'
RET ;RETURN WITH ZERO FLAG SET OR NOT
;
;MOVE (BC) BYTES FROM (HL) TO (DE)
;
MOVER:
MOV AL,M
MOV SI,DX
MOV [SI],AL
INC BX
INC DX
DEC CX
MOV AL,CH
OR AL,CL
JNZ MOVER
RET
;
;ABORTED - PRINT REASON. IF MAKING OUTPUT FILE,
;CLOSE THE INCOMPLETE FILE TO UPDATE CP/M'S BIT MAP,
;THEN ERASE IT.
;
ABEXIT:
MOV DX,(Offset NFOUND)
MOV CL,PRINT
INT BDOS ;PRINT MSG
;
ABEXT_2:
MOV AL,Byte Ptr FFLAG ;SEE IF WE ARE MAKING FILE
CMP AL,'F'
JNZ ABEXT_6 ;NO FILE, SKIP FILE STUFF
ABEXT_3:
MOV BX,Word Ptr CATPTR
MOV AL,BL
AND AL,(SECT-1) AND 0FFH
JNZ ABEXT_4
MOV Word Ptr CATLEN,BX
ABEXT_4:
MOV AL,EOF
LAHF
XCHG AL,AH
PUSH AX
XCHG AL,AH
CALL PUTCATALOG
POP AX
XCHG AL,AH
SAHF
JNZ ABEXT_3
MOV CL,CLOSE
MOV DX,(Offset FCBCAT)
INT BDOS
INC AL
JNZ ABEXT_5
MOV CL,PRINT
MOV DX,(Offset CLSMSG)
INT BDOS
ABEXT_5:
MOV CL,DELETE
MOV DX,(Offset FCBCAT)
INT BDOS
;
ABEXT_6:
MOV DX,(Offset ABORT)
MOV CL,PRINT
INT BDOS
;
;EXIT, RESTORING STACK AND RETURN TO CCP
;
EXIT:
; MOV BX,Word Ptr STACK
; MOV SP,BX
MOV CX,0
MOV DX,0
INT BDOS ;TO CCP
;
SHWDEC: ;3 DIGITS, UP TO 255, WITH LEADING 0 SUPPRESS
MOV CH,' ' ;SET FOR SPACE
MOV CL,0
SHWDE:
CMP AL,100 ;CHECK IF GREATER THAN 100
JB NOHUNS
INC CL
SUB AL,100
JMPS SHWDE
NOHUNS:
LAHF
XCHG AL,AH
PUSH AX
MOV AL,CL
OR AL,AL
JZ NOHN
MOV CH,'0' ;SET "0" FOR NEXT 0
NOHN:
ADD AL,CH ;ADD SPACE OR "0"
CALL TYPER
POP AX
XCHG AL,AH
MOV CL,0
CKTENS:
CMP AL,10
JB NO10S
INC CL
SUB AL,10
JMPS CKTENS
NO10S:
LAHF
XCHG AL,AH
PUSH AX
MOV AL,CL
OR AL,AL ;CHECK IF ANY 10S
JZ NO10X
MOV CH,'0'
NO10X:
ADD AL,CH ;ADD SPACE OR "0"
CALL TYPER
POP AX
XCHG AL,AH
ADD AL,'0'
JMP TYPER
;
SHWDC: ;2 DIGITS ONLY, 99 ONLY, NO 0 SUPRESS
MOV CL,'0' ;SET UP FOR '0' DIGIT
SHWDC1:
CMP AL,10 ;CHECK IF GREATER THAN 10
JB NOTENS ;BRANCH IF NO TENS DIGITS
INC CL ;INCREMENT TENS DIGIT COUNTER
SUB AL,10 ;SUBTRACT 10 FROM NUMBER
JMPS SHWDC1 ;BRANCH BACK TO TEST AGAIN
NOTENS:
LAHF ;SAVE THE UNITS DIGIT QUANTITY
XCHG AL,AH
PUSH AX
MOV AL,CL ;GET THE TENS DIGIT QUANTITY
CALL TYPER
POP AX ;RESTORE THE UNITS DIGIT QUANTITY
XCHG AL,AH
ADD AL,'0' ;ADD ASCII DIGITS NUMERAL OFFSET
JMP TYPER ;DISPLAY UNITS AND RETURN TO CALLER
;
DSEG
ORG 100H
;
FCBCAT DB 0,'-CATALOG$$$'
DB 0
RS 20
CATADR DW (Offset CATBUF)
CATLEN DW CATSIZ
CATPTR RS 2
;
SIGNON DB 'CRCBUILD, CP/M-86 Ver 1.0, 04/Aug/84, Bill Bolton',CR,LF
DB 'CTL-S pauses, CTL-C aborts',CR,LF,'$'
;
WRONG DB CR,LF,'Incorrect characters',CR,LF,'$'
;
ENTER DB 'Enter -CATALOG.xxx number (three digits) - ','$'
;
FOOT1 DB CR,LF,'Software Tools RCPM - MISC Volume Number - '
DONEX DB 'NNN, ','$'
;
FOOT2 DB ' Files cataloged.',CR,LF,'$'
;
DONEMSG DB CR,LF,'DONE$'
;
NUMBER DB CR,LF
FNAME1 DB 'NNN.','$'
;
FILEN DB ' '
FNAME DB 'XXXXXXXX.XXX ','$'
;
FAIL DB '++Open Failed++','$'
;
KSIZE DB 'K ','$'
;
FERROR DB TAB,TAB,'++ FILE READ ERROR ++',CR,LF,'$'
;
NFOUND DB '++ FILE NOT FOUND ++$'
;
ABORT DB CR,LF,CR,LF,'++ ABORTED ++$'
;
FULLMSG DB CR,LF
DB 'DISK FULL: CATALOG'
DB '$'
;
SPACE DB CR,LF
DB 'NO DIR SPACE: CATALOG'
DB '$'
;
CLSMSG DB CR,LF
DB 'CANNOT CLOSE CATALOG'
DB '$'
;
FCBFINAL RS 0
DB 0,'-CATALOGNNN'
DB 0
RS 20
;
;PROGRAM STORAGE AREA
;
FFLAG DB 0 ;FILE WRITE REQUEST FLAG
REMAIN DW 0 ;CRC REMAINDER STORAGE
QUANEK DW 0 ;QUANTITY OF EIGHTH K
MESS DB 0 ;CRC MESSAGE CHAR GOES HERE
MFFLG1 DB 1 ;1ST TIME SWITCH
MFFLG2 DB 1 ;FLAG INDICATING ONE NAME FOUND OR NOT
NAMQUAN DB 0 ;QUANTITY OF FILES READ
MFREQ RS 12 ;REQUESTED NAME
MFCUR RS 12 ;CURRENT NAME
WHICH RS 1 ;FLAG STORAGE FOR PHASE
BUFAD RS 2 ;READ BUFFER ADDRESS
STRCNT RS 2 ;STRING COUNT STORAGE
STRING RS 11 ;STRING STORAGE
STR1 RS 12 ;NAME STORAGE
STR2 RS 8 ;CHARACTERS AFTER NAME
STR3 RS 5 ;ASCII CRC CHARACTERS
STR4 RS 80 ;BUFFER
;
;DEFINE LOCATION OF FILE WRITE BUFFER
;
CATBUF EQU (Offset $)
;
END