(s17H
PRINTING: FREE.M68 Page 1

;*; Updated on 27-Apr-93 at 6:51 PM by James A. Jarboe I V; edit time: 0:39:11
;*************************** AMUS Program Label ******************************
; Filename: FREE.M68                                        Date: 12/18/91
; Category: UTIL         Hash Code: 515-501-722-125      Version: 1.0(105)
; Initials: GR/AM        Name: JAMES A. JARBOE IV
; Company: EDUCATIONAL VIDEO NETWORK               Telephone #: 4092955767
; Related Files: NONE
; Min. Op. Sys.:1.x and 2.x                    Expertise Level: BEG
; Special: MUST USE 2.X ASSEMBLER.
; Description: Displays disk usage Statistics on 1.x and 2.x systems.
; Usage: .FREE {DSK#:},   Much more informative than the FREE.LIT provided
; 	with AMOS 2.x systems and it works with both AMOS 1.x and 2.x.
;*****************************************************************************
;*; Updated on 18-Dec-91 at 10:55 PM by James A. Jarboe I V; edit time: 0:46:11
;*****************************************************************************
; FREE.M68
; Displays Disk Usage Statistics
;
; History:
;
; Written:
; 07-Jun-84    David F. Pallmann
;
; Modified:
;      12/07/85  E. Oulashin - on next word, prev bit being set
;                caused contig to be zero'ed when there were
;                contiguous blocks.
;      02/24/86  E. Oulashin - corrected percentages on totals,
;                also fixed to round properly on percentages.
;      02/25/86  Dave Heyliger - AMUS
;                Changed total end-use figure report to produce
;                proper disk-use total.
;
;      01/09/89  Ed Schrayer - allow use for a single device only
;                or all devices as before, also prevent devide by zero
;
; [105] 18-Dec-91 by James A. Jarboe IV     GR/AM
;	Neat little program that needed to be upgraded to the 90's
; 	Made to work on 1.x and 2.x systems.
; 	Made to not include FOLDER and NRD's in totals for real devices.
;	Fixed total percentage rounding.
;	Added Version and edit levels.
;	Took out internal device offsets as there are now defined in SYSSYM
;
; [106] 12-Mar-93 by James A. Jarboe IV	    GR/AM
;	Update to flag extended devices.
; [107] 27-Apr-93 by James A. Jarboe IV     GR/AM
;	Updated to not abort when listing CD-ROM devices.
;
        SEARCH  SYS
        SEARCH  SYSSYM

	VMAJOR	=	1
	VMINOR	=	0
	VEDIT	=	107.		; 27-Apr-93 Current 		[106]


PRINTING: FREE.M68 Page 2

;MACROS

DEFINE	PRTTAB	ROW, COL
	MOVW	#<ROW_8.+COL>, D1
	TCRT
	ENDM

DEFINE  DEPACK  ADDR
        IF      NB,ADDR,LEA A1,ADDR
        SUB     #4,SP
        MOV     SP,A2
        UNPACK
        CLRB    @A2
        TTYL    @SP
        ADD     #4,SP
        ENDM

DEFINE  BITW    SRC,DST
        MOVW    DST,D7
        ANDW    SRC,D7
        ENDM

DEFINE	BIT	SRC, DST
	MOV	DST, D7
	ANDW	SRC, D7
	ENDM

DEFINE  BICW    SRC,DST
        MOVW    SRC,D6
        COMW    D6
        MOVW    DST,D7
        ANDW    D6,D7
        MOVW    D7,DST
        ENDM

DEFINE  ADDM    SRC,DST
        MOV     SRC,D7
        ADD     D7,DST
        ENDM

DEFINE  DIVIDE  SRC,DST
        DIV     SRC,DST
        AND     #177777,SRC
        ENDM

;DEVICE TABLE
;; Comment out as offsets are now defined in SYSSYM for 2.x		[105]
;      .OFINI
;      .OFDEF  DV.NXT,4                ;link to next device entry
;      .OFDEF  DV.FLG,2                ;flags--.
;              DV$LOG=10               ; logical unit
;              DV$SHR=1000             ; shareable device
;              DV$MNT=10000            ; mounted
;      .OFDEF  DV.DEV,2                ;device code RAD50
;      .OFDEF  DV.UNT,2                ;drive number RAD50
;      .OFSIZ  DV.SIZ			; Free device size.

PRINTING: FREE.M68 Page 3

;


;IMPURE AREA
					; 
        .OFINI
        .OFDEF  DISK,	D.DDB           ;DDB for reading bitmaps
	.OFDEF	FR.TBL, 0		; Start of free table.		[105]
        .OFDEF  FREE,	4               ; Free block count per disk.    [105]
        .OFDEF  CONTIG,	4               ; Contig count per disk.        [105]
	.OFDEF	FR.EXP, DF.SIZ-4.	; End of free table and room.   [105]
        .OFDEF  TFREE,	4               ; Total free count.
        .OFDEF  TEMP,	4		; Temporary bitmap count old style.
        .OFDEF  TCONTG,	4               ; Total contig count
        .OFDEF  COUNT,	4		;  <- not used 
        .OFDEF  BLOCKS,	4		; Total blocks per disk
	.OFDEF	ONEDSK,	D.DDB		; DDB for one device.
	.OFDEF	ONEFLG,	4		; Flag for one device.
	.OFDEF	FR.FLG, 4		; Flags.			[105]
		FR$S2X	=	1_0	;  2.x System.			[105]
		FR$FLD	=	1_1	;  Folder device.		[105]
	.OFDEF	LABBUF, 26.		; Label display buffer 		[106]
        .OFSIZ  MEMSIZ			; End of impure area.

; Make sure 2.x assembler is used so DSKFRE Monitor call and offsets are found.
; FREE will still on AMOS 1.x, this program just needs to be assembled
; with the 2.x assembler or d/SOFT's MACRO.
;
	ASSEMB1	=	1
	ASSEMB2	=	2

	IF	EQ, ASSEMB1-ASSEMB2, ASMERP "?Must use 2.x Assembler"
;


;START OF CODE

START:  PHDR    -2,0,PH$REE!PH$REU      ;program header
        GETIMP  MEMSIZ,A5               ;allocate impure area
	BYP				; Bypass junk			[105]
	CMPB	@A2, #'/		; User wants help?              [105]
	JEQ	BADUSE			; Yes..help em. 		[105]
	CMPB	@A2, #'?		; User wants help?		[105]
	JEQ	BADUSE			; Yes..help em.			[105]
	CALL	HEADER			; Do header			[105]

	CMPB	PH.VER+1, #2		; Is this a 2.x system?		[105]
	BLO	10$			; No..do everything the old way.[105]
	OR	#FR$S2X, FR.FLG(A5)	; Yes..set flag.		[105]

10$:    CLR     COUNT(A5)
        CLR     TFREE(A5)
        CLR     TCONTG(A5)
        CLR     BLOCKS(A5)
	CLR	ONEFLG(A5)
	LIN				; one or all devices ? ES

PRINTING: FREE.M68 Page 4

	JEQ	LOOP

ONEDEV:	BYP				; find first non-blank character
	FSPEC	ONEDSK(A5)		; Set up DDB area
	TST	D.FIL+ONEDSK(A5)	; If file name is included,
	JNE	BADUSE			; reject request.
	JOBIDX				; Get current job
	TSTW	D.DEV+ONEDSK(A5)	; Did user just use ":"
	BNE	10$			;  no...
	MOVW	JOBDEV(A6), D.DEV+ONEDSK(A5) ; yes..set default device.
10$:	TSTW	D.DRV+ONEDSK(A5)	; Is device set?
	BPL	20$			; Yes..
	MOVW	JOBDRV(A6), D.DRV+ONEDSK(A5) ; No..set default.
20$:	MOV	#1,ONEFLG(A5)		; and set a flag for single device
					; search only
;SCAN DEVICE TABLE

LOOP:   MOV     DEVTBL,A4               ;point A4 to first DEVTBL entry
10$:	BITW    #DV$MNT,DV.FLG(A4)      ;is device mounted?
        BEQ     20$                     ; no

	TST	ONEFLG(A5)		; are we scanning for only one device?
	BEQ	15$			; if not, report on all devices

	CMMW    DV.DEV(A4),ONEDSK+D.DEV(A5)	; did we match device name ?
	BNE	20$				; no - keep scanning
	CMMW    DV.UNT(A4),ONEDSK+D.DRV(A5)	; did we match drive # ?
	BNE	20$				; no - keep scanning
	CALL	DEVICE				; report on the device and
	BR	EXIT				; exit to amos

15$:
	BIT	#<FR$FLD>, FR.FLG(A5)	; Done folder devices?		[105]
	BNE	18$			; Yes..bypass DEVTBL check.	[105]
	MOV	A4, D7			; Get DEVTBL address.		[105]
	CMP	D7, SYSBAS		; Greater than System Base?	[105]
	BLO	18$			; No..never mind.		[105]
	CALL	TOTALS			; Yes..do totals for real disks.[105]
	OR	#FR$FLD, FR.FLG(A5)	; Set must be at folders flag.	[105]
	CRLF				; Bump screen.			[105]
	TYPECR	<Folder Devices:>	; Tellem..			[105]
	CALL	HEADER			; Redoe Header table		[105]

18$:	CALL    DEVICE                  ; process device specs

20$:    MOV     DV.NXT(A4),D0           ;get link to next device entry
	CTRLC	30$			;if early abort -- jump out
        BEQ     30$                     ;branch on zero (end of table)
        MOV     D0,A4                   ;set new address into A4
        BR      10$                     ;and continue processing
30$:	CALL    TOTALS

EXIT:   CRLF
        EXIT

PAGE

PRINTING: FREE.M68 Page 5


;PROCESS DEVICE
;
DEVICE: CALL    READ                    ;read bitmap
        CALL    SCAN                    ;calculate blocks free
10$:    CALL    DISPLY                  ;display stats
        RTN

PAGE
READ:
	MOVW    DV.DEV(A4),DISK+D.DEV(A5)
        MOVW    DV.UNT(A4),DISK+D.DRV(A5)
        INIT    DISK(A5)
        MOV     DISK+D.DVR(A5),A0
	MOV     24(A0),D5               ;D5 contains device size in blocks
	BIT	#FR$S2X, FR.FLG(A5)	; Is this a 2.x system?	 	[105]
	BEQ	10$			; No..read old way.		[105]
	ORB	#D$ERC!D$BYP, D.FLG+DISK(A5) ; Set do not abort         [107]
	CLEAR	FR.TBL(A5), DF.SIZ-4	; Preclear free table.          [107]
	DSKFRE	DISK(A5), FR.TBL(A5)	; Yes..read new way.		[105]
	ANDB	#^C<D$ERC!D$BYP>, D.FLG+DISK(A5) ; Reset for errors     [107]
	BR	99$			; Then return			[105]
10$:
        DSKBMR  DISK(A5)                ;read the bitmap
        MOV     DISK+D.ARG(A5),A3       ;point A3 to bitmap area
        BICW    #BM$LOK,-2(A3)          ;clear bitmap lock
99$:    RTN

PAGE
SCAN:
	BIT	#FR$S2X, FR.FLG(A5)	; 2.x System?			[105]
	BNE	60$			; Yes...already got all.	[105]
	MOV     #1,D0                   ;set bit mask
        CLR     FREE(A5)                ;clear free count
        CLR     TEMP(A5)                ;clear temporary contiguous count
        CLR     CONTIG(A5)              ;clear contiguous count
        MOV     #1,D1                   ;set previous bit
        MOV     D5,D2                   ;D2 is bit count
10$:    BITW    D0,@A3                  ;test bit
        BEQ     30$                     ; branch if zero
        TSTB    D1                      ;one: was previous bit a zero?
        BNE     20$                     ; no
        CMM     TEMP(A5),CONTIG(A5)     ;new contiguous count?
        BLOS    20$                     ; no
        MOV     TEMP(A5),CONTIG(A5)     ; yes
20$:    CLR     TEMP(A5)                ;clear temp contig count
        MOVB    #1,D1                   ;set previous bit
        BR      40$
30$:    INC     FREE(A5)                ;zero: increment free count
        INC     TEMP(A5)                ;increment contiguous count
        CLR     D1                      ;clear previous bit
40$:    DEC     D2                      ;decrement count
        BEQ     50$                     ;branch if done
        ROLW    D0,#1                   ;get next bit
        BCC     10$                     ;branch if okay
        ADD     #2,A3                   ;advance to next word

PRINTING: FREE.M68 Page 6

;       MOV     #1,D1                   ;reset start bit REMOVED 02/86 ENO 12/07/85 ENO
        BR      10$                     ;processs new word
50$:    TSTB    D1                      ;was previous bit a zero?
        BNE     60$                     ; no
        CMM     TEMP(A5),CONTIG(A5)     ;new contig count?
        BLOS    60$                     ; no
        MOV     TEMP(A5),CONTIG(A5)     ; yes
60$:    INC     COUNT(A5)
        ADD     D5,BLOCKS(A5)
        ADDM    FREE(A5),TFREE(A5)
        ADDM    CONTIG(A5),TCONTG(A5)
        RTN

PAGE
DISPLY:
	DEPACK  DV.DEV(A4)
        CLR     D1
        MOVW    DV.UNT(A4),D1
        DCVT    0,OT$TRM
        TYPE    :
        TAB

DS.SIZ: MOV     D5,D1
	TST	D1
	JEQ	NOREAD
        DCVT    6,OT$TRM!OT$ZER
	TYPE    < >

DS.FRE:
	MOV     FREE(A5),D1
        DCVT    7,OT$TRM!OT$ZER!OT$TSP
        MOV     D5,D0
        MUL     D1,#1000.               ; WAS 100. 02/86 ENO
        DIVIDE  D1,D0
        ADD     #5.,D1                  ; ADDED 02/86 ENO
        DIVIDE  D1,#10.                 ; ADDED 02/86 ENO
	PUSH	D1
	PRTTAB	-1,11.
        TYPE    (
	PRTTAB	-1,12.
	POP	D1
        DCVT    2,OT$TRM!OT$ZER
	PRTTAB	-1,11.
        TYPE    <%) >
	PRTTAB	-1,12.

DS.USE: 
	MOV     D5,D1
        SUB     FREE(A5),D1
        DCVT    7,OT$TRM!OT$ZER!OT$TSP
        MOV     D5,D0
        MUL     D1,#1000.               ; WAS 100. 02/86 ENO
        DIVIDE  D1,D0
        ADD     #5.,D1                  ; ADDED 02/86 ENO
        DIVIDE  D1,#10.                 ; ADDED 02/86 ENO
	PUSH	D1

PRINTING: FREE.M68 Page 7

	PRTTAB	-1,11.
        TYPE    (
	PRTTAB	-1,12.
	POP	D1
        DCVT    2,OT$TRM!OT$ZER
	PRTTAB	-1,11.
        TYPE    <%) >
	PRTTAB	-1,12.	
	
DS.CTG: MOV     CONTIG(A5),D1
        DCVT    7,OT$TRM!OT$ZER
        TYPE    < >

DS.LBL:
	CALL	CLRLAB
	CLRB	D.ERR+DISK(A5)
	CLR     DISK+D.REC(A5)
        READ    DISK(A5)
        MOV     DISK+D.BUF(A5),A0
	CMP	@A0, #^H0AAAA5555	; Is device labeled? 		[105]
	BEQ	5$			; Yes..show it.			[105]
	PRTTAB	-1,11.			;				[105]
	TYPE	<  --- Not Labeled ---  >;				[105]
	PRTTAB	-1,12.			;				[105]
	BR	25$			; Bypass label.			[105]
5$:
	PUSH	A0
   	ADD     #4,A0
        MOV     #24.,D0
	LEA	A6, LABBUF(A5)
10$:    MOVB    (A0)+,D1
        BEQ     20$
	MOVB	D1, (A6)+
        SOB     D0,10$

20$:	POP	A0
	TTYL	LABBUF(A5)
25$:	MOVB	LB.FLG(A0), D7
	ANDB	#LB$14D, D7
	BEQ	30$
	TYPE	<Ext>
30$:	CRLF
        RTN

CLRLAB:
	LEA	A6, LABBUF(A5)
	MOV	#23., D0
10$:	MOVB	#32., (A6)+
	SOB	D0, 10$
	CLRB	@A6
	RTN	

PAGE
TOTALS:
	BIT	#<FR$FLD>, FR.FLG(A5)	; Already done totals? 		[105]
	BEQ	10$			; No..lets do em.		[105]

PRINTING: FREE.M68 Page 8

	RTN				; Yes..return to caller.	[105]
10$:
	MOV     BLOCKS(A5),D1
	TST	D1
	JEQ	NOREAD
	PUSH	D1
	PRTTAB	-1,11.			; 				[105]
	TYPE	<============================================================================>
	PRTTAB	-1,12.			; 				[105]
	CRLF
	POP	D1
	
TOTSIZ: 
        TYPESP  Total
        DCVT    10,OT$TRM!OT$ZER
        TYPE    < >

TOTFRE:
	MOV     TFREE(A5),D1
        DCVT    7,OT$TRM!OT$ZER!OT$TSP
        MOV     BLOCKS(A5),D0
        DIVIDE  D0,#2000
        DIVIDE  D1,#2000
        MUL     D1,#1000.		; [105]
        DIVIDE  D1,D0			
	ADD     #5.,D1			; [105]
	DIVIDE  D1,#10.			; [105]
	PUSH	D1
	PRTTAB	-1,11.
        TYPE    (
	PRTTAB	-1,12.
	POP	D1
        DCVT    2,OT$TRM!OT$ZER
	PRTTAB	-1,11.
        TYPESP  %)
	PRTTAB	-1,12.

TOTUSE:
	MOV     BLOCKS(A5),D1
        SUB     TFREE(A5),D1
        DCVT    7,OT$TRM!OT$ZER!OT$TSP
        MOV     BLOCKS(A5),D0
        DIVIDE  D0,#2000
        DIVIDE  D1,#2000
        MUL     D1,#1000.		; [105]
        DIVIDE  D1,D0
	ADD     #5.,D1 			; [105]
	DIVIDE  D1,#10.			; [105]
	PUSH	D1
	PRTTAB	-1,11.
        TYPE    (
	PRTTAB	-1,12.
	POP	D1
        DCVT    2,OT$TRM!OT$ZER
	PRTTAB	-1,11.
        TYPECR  %)

PRINTING: FREE.M68 Page 9

	PRTTAB	-1,12.
        RTN

HEADER:
        TYPECR  <Device   Size       Free         In use     Contig  Label>
	PRTTAB	-1, 11.
        TYPE  <------  ------  ------------  ------------  ------  ------------------------>
	PRTTAB	-1, 12.
	CRLF
	RTN

BADUSE:	CRLF
	TYPECR	Usage:
	TYPECR	<       FREE        - For all devices.>
	TYPECR	<       FREE :      - For current device.>
	TYPECR	<       FREE DEV#:  - For a single device.>
	EXIT
NOREAD:	CRLF
	PRTTAB	-1,11.
	TYPE	<%>
	PRTTAB	-1,12.
	TYPE	<Device >
	OFILE	ONEDSK(A5),<OT$TRM!OT$OFD>
	TYPECR	< does not exist.>
	EXIT

        END