;*************************** AMUS Program Label ******************************
; Filename: MAKEAA.M68                                      Date: 1/29/92
; Category: UTIL         Hash Code: 771-757-245-776      Version:
; Initials: TREE/AM      Name: DELL COLEMAN
; Company: Alpha Automation Incorporated           Telephone #: 7138778039
; Related Files: AAI.M68
; Min. Op. Sys.: 2.0                           Expertise Level: BEG
; Special:
; Description: Will create A.A files in ALL PPn's specified by CMDLIN wildcard
; even if the PPn is empty.  Works on extended and traditional disks.
; .LIT=436-015-351-641 1.0(100)
;*****************************************************************************
;*ML MAKEAA - Make sure every PPn has an A.A file (even empty PPns)
;
; Written by:
;       Dell Coleman
;       Alpha Automation Incorporated
;       2000 West Loop South
;       Houston, Texas 77027
;       (713) 877-8039
;           and copyrighted by the same in 1992.
;
;       For a description of the workings of CMDLIN.SYS look at articles
;       3.4.5 & 3.4.7 in the software volume of the AMTS Journal
;
; Register Usage:
;       A1 - Next entry in device table chain
;       A2 - Input line address
;       A2 - Address of DDB for file output routines
;       A5 - Impure area address
;
; Edit history
;[100] 6 January 1992  Dell Coleman
;       Program written.
;
       SYM
       EXTERN  $ODTIM

       VMAJOR=1
       VMINOR=0
       VEDIT=100.

       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  TRM
       SEARCH  AAI
       COPY    CMDSYM                  ; CMDLIN.SYS stuff

       ASECT                           ; Our Impure area starts here
       .=IMP.SZ                        ; Continue from CMDSYM
MFDDDB: BLKB    D.DDB                   ; Used for input of MFDs
MFDBUF: BLKB    512.                    ; Buffer for MFDs
AADDB:  BLKB    D.DDB                   ; Used for A.A
AABUF:  BLKB    512.                    ; Buffer for A.A
CHRTBL: BLKB    DC.SIZ                  ; Device Characteristics table
SAVEA2: BLKL    1                       ; Save A2 (for CMDLIN)
SAVPPN: BLKW    1                       ; Save PPn (Make OFILE work)
IMP.SZ=.                                ; IMP.SZ is inpure area size

       .=0                             ; Beginning of program
       PSECT

MAKEAA: PHDR    -1,0,PH$REE!PH$REU
       GETIMP  IMP.SZ,A5,NOMEM         ; Branch to NOMEM if not enough memory

       JOBIDX  A6                      ; Addr of our JCB to A6
       MOVW    JOBUSR(A6),SAVPPN(A5)   ; Save PPn

       LEA     A6,AABUF(A5)            ; Addr of buffer to A6
       MOV     A6,D.BUF+AADDB(A5)      ; Put in DDB
       MOV     #512.,D.SIZ+AADDB(A5)   ; Put buffer size into DDB
       MOVB    #D$INI,D.FLG+AADDB(A5)  ; Tell INIT we have a buffer
       INIT    AADDB(A5)               ; INITialize DDB for CMDLIN

       MOV     A2,SAVEA2(A5)           ; Save A2 for CMDLIN
       .CMLOC  AADDB(A5)               ; Locate CMDLIN.SYS (Load if necessary)
       LEA     A0,DEFCMD               ; Addr of default command to A0
       MOV     #OP$PRT!OP$TRN,D7       ; CMDLIN flags
       .CMINI                          ; Initialize CMDLIN (No switches)
       JNE     ERRXIT                  ; Set error flag and exit (On error)
       AND     #IN$OFP,D7              ; Was output specified?
       JNE     NOOUT                   ; Branch if yes (error)

       LEA     A6,MFDBUF(A5)           ; Addr of buffer to A6
       MOV     A6,D.BUF+MFDDDB(A5)     ; Put in DDB
       MOV     #512.,D.SIZ+MFDDDB(A5)  ; Put buffer size into DDB
       MOVB    #D$INI,D.FLG+MFDDDB(A5) ; Tell INIT we have a buffer

       LEA     A1,DEVTBL               ; Address of device table to A1

NXTDEV: CTRLC   ERRXIT                  ; Check for ^C
       MOV     DT.NXT(A1),D7           ; Addr of next entry in devtbl to D7
       JEQ     EXIT                    ; Branch if end of table
       MOV     D7,A1                   ; Addr of DEVTBL entry to A1
       MOVW    DT.DEV(A1),D.DEV+MFDDDB(A5)     ; Device name to DDB
       MOVW    DT.DRV(A1),D.DRV+MFDDDB(A5)     ; Device number to DDB
       INIT    MFDDDB(A5)              ; INITialize DDB (for DEVCHR)
       DEVCHR  MFDDDB(A5),CHRTBL(A5)   ; Get device characteristics
       MOV     DC.FLG+CHRTBL(A5),D7    ; Characteristics flag word to D7
       AND     #<DC$FSD!DC$MNT>,D7     ; Remove all unwanted bits
       CMP     D7,#<DC$FSD!DC$MNT>     ; Is device file structured & mounted?
       BNE     NXTDEV                  ; Branch if not
       DIRACC  MFDDDB(A5),#DA$INI!DA$NEW       ; Get directory access

NXTPPN: CTRLC   ERRXIT                  ; Check for ^C
       DIRSCH  MFDDDB(A5),#DS$DIR      ; Get next PPn
       TSTW    D6                      ; End of entries?
       BMI     NXTDEV                  ; Branch if yes
                                       ; Copy MFD stuff for UFD search
       LEA     A2,AADDB(A5)            ; Address of DDB for UFD to A2
       LEA     A6,MFDDDB(A5)           ; Address of DDB for MFD to A6
       MOV     #D.DDB,D7               ; Size of DDB to D7
       DEC     D7                      ; Adjust for -1 stop
10$:    MOVB    0(A6)[D7],0(A2)[D7]
       DBF     D7,10$                  ; Decrement & test counter
       LEA     A2,AABUF(A5)            ; Get address of AADDB buffer
       MOV     A2,D.BUF+AADDB(A5)      ; Put in DDB
       DIRACC  AADDB(A5),#DA$NEW+DA$LVL        ; Switch to UFD from MFD
       MOVW    D.FIL+AADDB(A5),D.PPN+AADDB(A5) ; Standard file format DDB
       MOV     #<[A  ]_16.![   ]>,D.FIL+AADDB(A5) ; Set filename to A.A
       MOVW    #[A  ],D.EXT+AADDB(A5)
       DIRSCH  AADDB(A5),#DS$DAT+DS$CMP        ; Does A.A already exist?
       TSTW    D6                      ; End of entries?
       BPL     NXTPPN                  ; Branch if yes

       LEA     A0,DEFCMD               ; Addr of default command to A0
       LEA     A4,AADDB(A5)            ; Addr of DDB for .CMCMP
       MOV     #OP$PRT!OP$TRN,D7       ; CMDLIN flags
       MOV     SAVEA2(A5),A2           ; Restore A2
       .CMINI                          ; Re-initialize CMDLIN

30$:    CTRLC   ERRXIT                  ; Check for ^C
       .CMCMP                          ; Does this file spec match?
       BNE     50$                     ; Branch if yes
       .CMSKP                          ; Try next entry
       JNE     ERRXIT                  ; Error (exit)
       AND     #NX$END,D7              ; Check for at end
       JNE     NXTPPN                  ; Branch if yes
       BR      30$                     ; Try this entry

50$:    OFILE   AADDB(A5),OT$TRM!OT$OFD ; Print device spec on terminal
       TYPE    <[>
       PRPPN   D.PPN+AADDB(A5)         ; Print PPn on terminal
       TYPE    <]>
       .CMQRY                          ; Check for /Q answer
       JEQ     NXTPPN                  ; Branch if no

       OPENO   AADDB(A5)               ; Open A.A for output
       LEA     A2,AADDB(A5)            ; Address of DDB to A2
       LEA     A3,STRNG1               ; Address of 1st string to output
       BCALL   WRTDSK                  ; Write 1st part of string
       JOBIDX  A6                      ; Addr of out JCB to A6
       CLRW    JOBUSR(A6)              ; Logoff to make OFILE work properly
       OFILE   AADDB(A5),OT$DDB!OT$OFP ; Write PPn to A.A
       JOBIDX  A6                      ; Addr of out JCB to A6
       MOVW    SAVPPN(A5),JOBUSR(A6)   ; Log back on
       LEA     A3,STRNG2               ; Address of 2nd string to output
       BCALL   WRTDSK                  ; Write 2nd part of string
       CLR     D3                      ; Tell $ODTIM to use current date
       MOV     #^H8368,D5              ; $ODTIM flags
       CALL    $ODTIM                  ; Put current date into A.A
       LEA     A3,STRNG3               ; Address of 3rd string to output
       BCALL   WRTDSK                  ; Write 3rd part of string
       CLOSE   AADDB(A5)               ; Close file
       JMP     NXTPPN                  ; get next PPn to process

WRTDSK: CLR     D1                      ; Pre-clear D1
10$:    MOVB    (A3)+,D1                ; Byte to write to D1
       BEQ     20$                     ; Null indicates end of string
       FILOTB  AADDB(A5)               ; Write byte to A.A
       BEQ     10$                     ; Branch if NO errors
       CLOSE   AADDB(A5)               ; Close file
       DSKDEL  AADDB(A5)               ; Erase file
       BR      ERRXIT                  ; Exit
20$:    RTN                             ; Return to caller

ERRXIT: JOBIDX  A6                      ; Address of our JCB to A6
       TSTW    JOBERR(A6)              ; Error flag already set?
       BNE     EXIT                    ; Branch if yes
       SETERR  0,JE$MSC                ; Set error flag

EXIT:   EXIT

NOMEM:  TYPECR  <Insufficient free memory to execute>
       BR      ERRXIT
NOOUT:  TYPECR  <Output specifications are not allowed>
       BR      ERRXIT
       EVEN

DEFCMD: ASCIZ   /=*.*/

STRNG1: ASCIZ   /; /
STRNG2: ASCIZ   / created /
STRNG3: BYTE    ^H0D,^H0A
       ASCII   /; Every account should have an A.A file, so that MFD /
       ASCII   /files can be rebuilt/
       BYTE    ^H0D,^H0A
       ASCII   /; using Ultrascience MUFDIT program.  Do not remove /
       ASCII   /this file and be/
       BYTE    ^H0D,^H0A
       ASCII   /; certain the A.A file remains sequenced at the /
       ASCII   /beginning of the PPn./
       BYTE    ^H0D,^H0A
       ASCII   /; Alpha Automation Inc. - FNDUFD is also handy./
       BYTE    ^H0D,^H0A
       ASCII   /;/
       BYTE    ^H0D,^H0A
       ASCIZ   /; This PPn is used for the following purposes:/
       EVEN

       END