;************************************************************************
;                                                                       *
;               DSPVER - Display File Version Information               *
;                                                                       *
;************************************************************************
;
;                                NOTICE
;
;        COPYRIGHT (C) 1985 - Distributed Management Systems, Inc.
;        ALL RIGHTS RESERVED.
;
; THIS  PROGRAM HAS BEEN  COPYRIGHTED BY DISTRIBUTED  MANAGEMENT SYSTEMS, INC.
; THE RECEIPT  OR POSSESSION OF THIS PROGRAM DOES  NOT CONVEY  ANY  RIGHTS  TO
; MANUFACTURE   OR  SELL ANYTHING THAT  IT MAY DESCRIBE,  IN WHOLE OR IN PART,
; WITHOUT THE SPECIFIC WRITTEN CONSENT OF DISTRIBUTED MANAGEMENT SYSTEMS, INC.
;
; Program usage:
;
;       .DSPVER filename{.ext}
;
;  where
;
;       filename is any valid AMOS/L program file specification.
;       {.ext} defaults to .LIT.
;
; Edit History:
;
;[101] 01/15/86 Added PH$M20 flag to characteristics table.             /BRH
;[100] 10/03/85 Designed and implemented by Brett R. Halle.
;

       SEARCH  SYS
       SEARCH  SYSSYM

; Version specification:
;
       VMAJOR  =       1
       VMINOR  =       0
       VEDIT   =       101.

; Impure area definition:
;
OFINI
OFDEF   DV.DDB, D.DDB                   ; File DDB.
OFDEF   DV.VER, PH.SIZ                  ; File program header.
OFSIZ   S..IMP                          ; Size of impure area in bytes.

; Macro's used by this program.
;
DEFINE  DIM
       MOVW    #177400+11., D1         ; Enter reduced intensity.
       TCRT
ENDM

DEFINE  UNDIM
       MOVW    #177400+12., D1         ; Enter normal intensity.
       TCRT
ENDM

DEFINE  UNLN
       MOVW    #177400+30., D1         ; Start underline mode.
       TCRT
ENDM

DEFINE  UNUNLN
       MOVW    #177400+31., D1         ; End underline mode.
       TCRT
ENDM

       PAGE

;****************
;     DSPVER    *
;****************
; Display file version information.
;
DSPVER: PHDR    -1,0,PH$REE!PH$REU      ; Program header.
       GETIMP  S..IMP, A5              ; Get impure area.

; Display program title.
;
       TYPE    <DSPVER - Version Display Utility, Version >
       VCVT    DSPVER+PH.VER, OT$TRM   ; Output our version number to CRT.
       CRLF
       TYPECR  <  Copyright (c) 1985 - DMSI. All Rights Reserved.>
       CRLF

; Get filespec and read in the program header.
;
       BYP                             ; Bypass leading spaces and tabs.
       FSPEC   DV.DDB(A5), LIT         ; Get file specification.
       INIT    DV.DDB(A5)              ; Init the DDB.
       OPENI   DV.DDB(A5)              ; Open up the file.
       MOV     #PH.SIZ-1, D0           ; Get size of program header.
       LEA     A2, DV.VER(A5)          ; Index the version buffer.
10$:    FILINB  DV.DDB(A5)              ; Read in a byte.
       TST     DV.DDB+D.SIZ(A5)        ; End of file?
       JEQ     BADHDR                  ;  Yes, bad file header.
       MOVB    D1, (A2)+               ;  No, add byte to version buffer.
       DBF     D0, 10$                 ; Get the entire program header.
       CLOSE   DV.DDB(A5)              ; Close the file.

; Check for valid program header.
;
       CMPW    DV.VER+PH.FLG(A5), #-1  ; Valid program header?
       BEQ     DSPHDR                  ;  Yes, display info.
       CMPW    DV.VER+PH.FLG(A5), #-2  ;  Maybe, can it be run logged out?
       JNE     BADHDR                  ;   No, bad file header.

       PAGE

;****************
;     DSPHDR    *
;****************
; Display file header.
;
DSPHDR: DIM                             ; Enter reduced intensity.
       TYPE    <Program header options set for >
       UNDIM                           ; Back to normal intensity.
       PFILE   DV.DDB(A5)              ; Display filename.
       TYPE    <:  >                   ; Pretty things up.

; Tell user if file may be run logged out.
;
       CMPW    DV.VER+PH.FLG(A5), #-2  ; Can file be run logged out?
       BNE     10$                     ;  No.
       UNLN                            ;  Yes, start underline mode.
       TYPE    <May be run logged out>
       UNUNLN                          ; End underline mode.

; Finish up with file name.
;
10$:    CRLF                            ; End of line.
       CRLF                            ; Blank line.

; Display version.
;
       DIM                             ; Enter reduced intensity.
       TYPE    <                Version: >
       UNDIM                           ; Back to normal intensity.
       VCVT    DV.VER+PH.VER(A5), OT$TRM ; Display version number.
       CRLF                            ; End of line.

;****************
;     DSPPRV    *
;****************
; Display privilege options.
;
DSPPRV: DIM                             ; Enter reduced intensity.
       TYPE    <             Privileges: >
       UNDIM                           ; Back to normal intensity.
       TSTW    DV.VER+PH.PRV(A5)       ; Any privilege options specified?
       BNE     10$                     ;  Yes.
       TYPE    <None>                  ;  No.
       BR      90$                     ;   We're done with privileges.

; Display all the privileges needed.
;
10$:    LEA     A0, PRVTBL              ; Index the privilege table.
       CLR     D0                      ; Clear enabled options counter.
20$:    TSTW    @A0                     ; End of table?
       BEQ     90$                     ;  Yes.
       MOVW    DV.VER+PH.PRV(A5), D6   ;  No, get privilege bits.
       ANDW    @A0, D6                 ;   Is this option set?
       BEQ     40$                     ;    No.
       TST     D0                      ; Is this the first item?
       BEQ     30$                     ;  Yes, no prefixing needed.
       TYPECR  <,>                     ;  No, terminate the previous line.
       TYPE    <                         >
30$:    ADD     #1, D0                  ; Bump item count.
       TTYL    2(A0)                   ; Output item description.
40$:    ADD     #S..FDC, A0             ; Bump to the next item.
       BR      20$                     ;  Go check it out.
90$:    TYPECR  <.>                     ; Make sure we end the line.

;****************
;    DSPCHR     *
;****************
; Display program characteristics.
;
DSPCHR: DIM                             ; Enter reduced intensity.
       TYPE    <        Characteristics: >
       UNDIM                           ; Back to normal intensity.
       TSTW    DV.VER+PH.CHR(A5)       ; Any characteristics specified?
       BNE     10$                     ;  Yes.
       TYPE    <None>                  ;  No.
       BR      90$                     ;   We're done with characteristics.

; Display all the characteristics.
;
10$:    LEA     A0, CHRTBL              ; Index the characteristic table.
       CLR     D0                      ; Clear enabled options counter.
20$:    TSTW    @A0                     ; End of table?
       BEQ     90$                     ;  Yes.
       MOVW    DV.VER+PH.CHR(A5), D6   ;  No, get characteristics bits.
       ANDW    @A0, D6                 ;   Is this option set?
       BEQ     40$                     ;    No.
       TST     D0                      ; Is this the first item?
       BEQ     30$                     ;  Yes, no prefixing needed.
       TYPECR  <,>                     ;  No, terminate the previous line.
       TYPE    <                         >
30$:    ADD     #1, D0                  ; Bump item count.
       TTYL    2(A0)                   ; Output item description.
40$:    ADD     #S..FDC, A0             ; Bump to the next item.
       BR      20$                     ;  Go check it out.
90$:    TYPECR  <.>                     ; Make sure we end the line.

       PAGE

;****************
;    ALLDUN     *
;****************
; All done.
;
ALLDUN: EXIT

;****************
;    BADHDR     *
;****************
; Bad file header detected.
;
BADHDR: TYPE    <?>
       PFILE   DV.DDB(A5)              ; Display filename.
       TYPECR  < does not have a valid program header.>
       EXIT

       PAGE

;****************
;     DATA      *
;****************
; Data used by this program.
;

; Misc equated symbols:
;
       S..FDC  =       48.             ; Size of flag/description entries.

; Macro to create a flag/description table entry.
;
DEFINE  FLGDSC  FLAG, DESC
10$$:   WORD    FLAG
       ASCIZ   ~DESC~
       BLKB    S..FDC-<.-10$$>
ENDM

; Characteristic bit table.
;
CHRTBL: FLGDSC  PH$REE, <Program is reentrant>
       FLGDSC  PH$REU, <Program is reusable>
       FLGDSC  PH$L12, <Must be logged into [1,2]>
       FLGDSC  PH$OPR, <Must be logged into DSK0:[1,2] (OPR:)>
       FLGDSC  PH$ERR, <Program uses JOBERR>
       FLGDSC  PH$M20, <Program requires 68020>                                ;[101]
       FLGDSC     100, <Undefined characteristic bit 6>
       FLGDSC     200, <Undefined characteristic bit 7>
       FLGDSC     400, <Undefined characteristic bit 8>
       FLGDSC    1000, <Undefined characteristic bit 9>
       FLGDSC    2000, <Undefined characteristic bit 10>
       FLGDSC    4000, <Undefined characteristic bit 11>
       FLGDSC   10000, <Undefined characteristic bit 12>
       FLGDSC   20000, <Undefined characteristic bit 13>
       FLGDSC   40000, <Undefined characteristic bit 14>
       FLGDSC  100000, <Undefined characteristic bit 15>
       WORD    0                       ; End of table.

; Privilege bit table.
;
PRVTBL: FLGDSC  PV$RSM, <Reads system memory>
       FLGDSC  PV$WSM, <Writes system memory>
       FLGDSC  PV$RPD, <Reads physical disk blocks>
       FLGDSC  PV$WPD, <Writes physical disk blocks>
       FLGDSC  PV$DIA, <Diagnostic program>
       FLGDSC      40, <Undefined privilege bit 5>
       FLGDSC     100, <Undefined privilege bit 6>
       FLGDSC     200, <Undefined privilege bit 7>
       FLGDSC     400, <Undefined privilege bit 8>
       FLGDSC    1000, <Undefined privilege bit 9>
       FLGDSC    2000, <Undefined privilege bit 10>
       FLGDSC    4000, <Undefined privilege bit 11>
       FLGDSC   10000, <Undefined privilege bit 12>
       FLGDSC   20000, <Undefined privilege bit 13>
       FLGDSC   40000, <Undefined privilege bit 14>
       FLGDSC  PV$PRV, <Changes privilege status>
       WORD    0                       ; End of table.

       END