;****************************************************************************
;*									    *
;*				    USYM				    *
;*		     USTAT 3.x Symbolic Definition File			    *
;*									    *
;****************************************************************************
;Copyright (C) 1988, 1989 UltraSoft Corporation.  All Rights Reserved.
;
;Written by: David Pallmann
;
;This file is required by USTAT,USTAT0,USTAT1,USTAT2,USTAT3,USTAT4, & USTAT5
;
;Edit History:
;3.0(100)  01-Jan-88  created. /DFP
;3.0(101)  10-Mar-88  fix bug where we used TEMP but meant TEMP(A5). /DFP
;3.0(102)  14-Apr-88  add support in the header for 68030 systems. /DFP
;3.0(103)  16-Apr-88  fix bug where ersatz name was displayed with junk. /DFP
;3.0(104)  18-Apr-88  fix larvae (small bug) where checking for the user name
;		      capability forgot to take AMOS 2.0 into account. /DFP
;3.1(105)  20-Apr-88  add OPERATOR mode for users logged into [1,2]. /DFP
;3.2(106)  27-Apr-88  add PRINT QUEUE statistics to header. /DFP
;3.3(107)  28-Apr-88  add CACHE HIT RATE statistics to header. /DFP
;3.3(108)  02-May-88  fix terminal buffer display to 30 chars. /DFP
;3.3(109)  02-May-88  add command-line feature. /DFP
;3.4(110)  13-May-88  add AM72 graphics terminal support. /DFP
;3.4(111)  24-May-88  add support in Terminal Status screen for 38.4, 57.6K baud. /DFP
;3.4(112)  31-May-88  correct 68030/020/010 check. /DFP
;3.4(113)  20-Jul-88  correct bug which showed junk in Cache Hit Rate area. /DFP
;3.4(114)  20-Jul-88  change PP.NAM to PP.PNM because of 1.3D conflict. /DFP
;3.4(115)  02-Aug-88  fix problem with page forward and ^E. /DFP
;3.5(116)  10-May-89  make D)isk screen AMOS 2.0 compatible. /DFP
;3.6(117)  10-May-89  filter non-printable characters in T)erminal display. /DFP
;3.7(118)  13-May-89  fix ^T/^E in D)evice screen. /DFP
;3.8(119)  02-Jul-89  fix big bad bug where disk stats wrong under AMOS 1.x. /DFP
;3.9(120)  24-Aug-90  1. look at number of terminal rows via TRMCHR. /DFP
;		      2. add X command to toggle 24 vs. 42 line mode.

;--- Version number of USTAT.  Incorporated into program header when PHDR
;    macro is encountered below.

	VMAJOR	=3
	VMINOR	=9.
	VSUB	=0
	VEDIT	=120.
	VWHO	=0

;--- Make sure we have the 2.0 assembler, by deliberately generating an
;    assembly error if the 1.x assembler is being used.  The 1.x assembler
;    can't handle long symbol names, and would not assemble USTAT properly
;    if allowed to.

	LONG.VAR.1=1
	LONG.VAR.2=2
	IF EQ,LONG.VAR.1-LONG.VAR.2,ASMERP "?The 2.0 assembler is required"

;--- Define the bit for the 68030 if the user's assembler system pre-dates it.

	IF	NDF,SY$M30,SY$M30=100000

;--- The following structure is header information used to update the
;    optional statistics header

	.OFINI
	.OFDEF	HD.DAT,	4		; system date
	.OFDEF	HD.TIM,	4		; system time
	.OFDEF	HD.UPT,	4		; uptime
	.OFDEF	HD.JOB,	2		; job count
	.OFDEF	HD.ALC,	2		; number of allocated jobs
	.OFDEF	HD.ACT,	2		; active job count
	.OFDEF	HD.CPB,	2		; CPU-bound job count
	.OFDEF	HD.IOB,	2		; I/O-bound job count
	.OFDEF	HD.QUE,	4		; free queue blocks
	.OFDEF	HD.DKQ,	4		; disk queue (users waiting)
	.OFDEF	HD.PRQ,	4		; print queue (files printing)
	.OFDEF	HD.CAD,	4		; addr of disk cache
	.OFDEF	HD.CAC,	6		; cache performance percentage
		CACHE.TOTAL=24		;  total reads offset
		CACHE.READS=30		;  cache reads offset
	.OFSIZ	HD.SIZ

;--- The following structure holds job information so that we know when
;    something changed, and needs updating.  One "job information block"
;    is maintained for each job on the system.

	.OFINI
	.OFDEF	JB.FLG,	4		; flags:
		JB$NEW	=1		;  new display line
	.OFDEF	JB.NAM,	4		; job name (RAD50)
	.OFDEF	JB.TRM,	4		; job attached terminal name (RAD50)
	.OFDEF	JB.DEV,	2		; log device
	.OFDEF	JB.DRV,	2		; log drive
	.OFDEF	JB.PPN,	2		; log account
	.OFDEF	JB.PRG,	4		; program name (RAD50)
	.OFDEF	JB.STS,	2		; run state
	.OFDEF	JB.MEM,	4		; job memory
	.OFDEF	JB.CPU,	4		; CPU time
	.OFDEF	JB.DSR,	4		; disk reads
	.OFDEF	JB.DSW,	4		; disk writes
	.OFDEF	JB.USN,	20.		; user name
	.OFDEF	JB.PRI,	2		; priority
	.OFDEF	JB.OWN,	4		; name of owner job (RAD50)
	.OFDEF	JB.TYP,	2		; JOBTYP flags
	.OFDEF	JB.BAS,	4		; base of memory
	.OFDEF	JB.JCB,	4		; JCB address
	.OFDEF	JB.TCB,	4		; TCB address
	.OFSIZ	JB.SIZ			; size of job information block

;--- Define terminal storage structure

	.OFINI
	.OFDEF	TM.FLG,	4		; flags:
		TM$NEW	=1		;  new display line
	.OFDEF	TM.NAM,	4		; terminal name (RAD50)
	.OFDEF	TM.JOB,	4		; attached job (RAD50)
	.OFDEF	TM.IDV,	4		; IDV name (RAD50)
	.OFDEF	TM.TDV,	4		; TDV name (RAD50)
	.OFDEF	TM.PRT,	4		; port number
	.OFDEF	TM.BAD,	2		; baud rate code
	.OFDEF	TM.ILB,	40.		; input line buffer
	.OFSIZ	TM.SIZ

;--- Define device storage structure

	.OFINI
	.OFDEF	DT.FLG,	4		; flags:
		DT$NEW	=1		;  new display line
	.OFDEF	DT.DEV,	2		; device code (RAD50)
	.OFDEF	DT.DRV,	2		; drive number
	.OFDEF	DT.MAX,	4		; device size
	.OFDEF	DT.INU,	4		; blocks in use
	.OFDEF	DT.FRE,	4		; blocks free
	.OFDEF	DT.NOT,	2		; notes
	.OFDEF	DT.DVR,	4		; address of driver
	.OFSIZ	DT.SIZ

;--- Define printer storage structure					[106]

	.OFINI
	.OFDEF	PP.FLG,	4		; flags:			[106]
		PP$NEW	=1		;  new display line		[106]
	.OFDEF	PP.NAM,	4		; printer name (RAD50)		[106]
	.OFDEF	PP.CNT,	2		; files queued			[106]
	.OFDEF	PP.DEV,	2		; device of file being printed	[106]
	.OFDEF	PP.DRV,	2		; drive of file being printed	[106]
	.OFDEF	PP.PNM,	4		; name of file being printed	[106][114]
	.OFDEF	PP.EXT,	2		; extension of file being printed [106]
	.OFDEF	PP.PPN,	2		; PPN of file being printed	[106]
	.OFSIZ	PP.SIZ			; 				[106]

;--- Define the maximum number of jobs, terminals & devices USTAT can handle

	MAX	=300.

;--- Calculate size of array element large enough to hold a job, terminal, or
;    device entry.

	ELEMENT	=JB.SIZ
	IF	LT,ELEMENT-TM.SIZ,ELEMENT=TM.SIZ
	IF	LT,ELEMENT-DT.SIZ,ELEMENT=DT.SIZ

;--- Define variable storage - a memory partition is allocated in user
;    memory containing these variables.

	.OFINI
	.OFDEF	FLAGS,	4		; flags:
		F$HIGH	=1		;  current intensity is high
		F$ON	=2		;  cursor is on
		F$GRAFIX=4		;  in graphics mode
		F$HEADER=10		;  header enabled
		F$UPDATE=20		;  full-screen update
		F$USER	=40		;  show user name on job screen
		F$STATUS=100		;  status line has been displayed
		F$WIDE	=200		;  wide display
		F$AM70	=400		;  color attributes (AM70 type)
		F$COLOR	=1000		;  true color terminal (PC type)
		F$ERSATZ=2000		;  show ersatz names in job screen
		F$AUTO	=4000		;  auto-scan
		F$LOG	=10000		;  alert if PPN changes
		F$PROG	=20000		;  alert if program changes
		F$32	=40000		;  os has AMOS/32 data structures
		F$OPR	=100000		;  operator mode		[105]
	.OFDEF	TERM.FLAGS,TC.SIZ	; term. characteristic data
	.OFDEF	HD.TBL,	HD.SIZ		; header table
	.OFDEF	JB.TBL,	0		; (job table,
	.OFDEF	TM.TBL,	0		; terminal table,
	.OFDEF	DT.TBL,	0		; device table,
	.OFDEF	PP.TBL,	ELEMENT*MAX	; printer table)		[106]
	.OFDEF	TEMP,	100.		; work buffer
	.OFDEF	JOB.ROW,1		; row to start job display at
	.OFDEF	ROW,	1		; current display row
	.OFDEF	JOB.ARROW,1		; job arrow row (current)
	.OFDEF	JOB.UPDATE,1		; job arrow row (update)
	.OFDEF	OPR.MARKER,1		; operator marker row
	.OFDEF	UNUSED,	1		; unused (even up address)	
	.OFDEF	JOB.OFFSET,2		; job offset
	.OFDEF	DELAY,	4		; delay time (1/4 seconds)
	.OFDEF	MODE,	2		; display mode:
		M$JOB	=0		;  show job status
		M$TERM	=2		;  show terminal status
		M$DEV	=4		;  show device status
		M$PRINT	=10		;  show printer status
	.OFDEF	DISK,	D.DDB		; disk DDB
	.OFDEF	LAST.ROW,1		; last row we can display on
	.OFDEF	ARROW.COL,1		; column to plot arrow at
	.OFDEF	CMDADR,	4		; address of command line
	.OFDEF	INFO,	DI.SIZ		; data returned by DSKINF call
	.OFDEF	DEV.COUNT,2		; device count
	.OFDEF	TRM.COUNT,2		; terminal count
	.OFSIZ	MEMSIZ

;--- Define the format of the old spooler printer list

        .OFINI
        .OFDEF  PR.LNK,	4               ; link to next printer
        .OFDEF  PR.QUE,	4               ; link to print queue
        .OFDEF  PR.NAM,	4               ; printer name RAD50
        .OFDEF  PR.FRM,	4               ; form name RAD50
        .OFDEF  PR.BLK,	2               ; blocks remaining
        .OFDEF  PR.FLG,	2               ; flags--.
                PR$DEF	=20             ;  default printer
        .OFDEF  PR.JCB,	4		; controlling JCB addr
        .OFSIZ  PR.SIZ

;--- Define the format of the old spooler printer queue

        .OFINI
        .OFDEF  PQ.LNK,	4               ; link to next block
        .OFDEF  PQ.NAM,	4               ; filename RAD50
        .OFDEF  PQ.EXT,	2               ; extension RAD50
        .OFDEF  PQ.DEV,	2               ; device code
        .OFDEF  PQ.PPN,	2               ; PPN
        .OFDEF  PQ.DRV,	2               ; drive number
        .OFDEF  PQ.CPY,	2               ; copies
        .OFDEF  PQ.FLG,	2               ; flags--.
                PQ$CUR	=40000          ;  currently being printed
                PQ$KIL	=100000         ;  flagged to be killed
        .OFDEF  PQ.FRM,	4               ; form name RAD50
        .OFDEF  PQ.BLK,	2               ; blocks remaining
        .OFSIZ  PQ.SIZ

;--- Register symbol names.  Each register assigned a symbolic name here
;    should not be used anywhere else in the program.

	MEM	=A5			; variable base register

	JCB	=A4			; pointer to true Job Control Block
	TCB	=A4			;                 Term Control Block
	DCB	=A4			; 		  Device Control Block
	PCB	=A4			;                 Printer Control Block

	JIB	=A3			; pointer to our Job Info. Block
	TIB	=A3			;                Terminal Info. Block
	DIB	=A3			; 		 Device Info. Block
	PIB	=A3			;                Printer Info. Block

;--- ASCII characters

	LF	=12
	CR	=15
	ESC	=33

;--- Terminal function macros

DEFINE	TCALL	CODE
	MOVW	#-1_8.+^D<CODE>,D1
	TCRT
	ENDM

DEFINE CLS=TCALL 0
DEFINE CLREOL=TCALL 9
DEFINE CLREOS=TCALL 10
DEFINE LO=TCALL 11
DEFINE HI=TCALL 12
DEFINE DELLIN=TCALL 15
DEFINE INSLIN=TCALL 16
DEFINE BLKON=TCALL 21
DEFINE BLKOFF=TCALL 22
DEFINE GMODE=TCALL 23
DEFINE TMODE=TCALL 24
DEFINE CON=TCALL 28
DEFINE COFF=TCALL 29
DEFINE UNDON=TCALL 30
DEFINE UNDOFF=TCALL 31
DEFINE REVON=TCALL 32
DEFINE REVOFF=TCALL 33
DEFINE STSLIN=TCALL 54
DEFINE WIDE=TCALL 80
DEFINE NARROW=TCALL 81
DEFINE ENDLIN=TCALL 129

DEFINE	FBLACK
	CLR	D1
	CALL	SET.COLOR
	ENDM

DEFINE	FWHITE
	MOV	#1,D1
	CALL	SET.COLOR
	ENDM

DEFINE	FBLUE
	MOV	#2,D1
	CALL	SET.COLOR
	ENDM

DEFINE	FMAGENTA
	MOV	#3,D1
	CALL	SET.COLOR
	ENDM

DEFINE	FRED
	MOV	#4,D1
	CALL	SET.COLOR
	ENDM

DEFINE	FYELLOW
	MOV	#5,D1
	CALL	SET.COLOR
	ENDM

DEFINE	FGREEN
	MOV	#6,D1
	CALL	SET.COLOR
	ENDM

DEFINE	FCYAN
	MOV	#7,D1
	CALL	SET.COLOR
	ENDM

DEFINE BLACK=TCALL 132
DEFINE WHITE=TCALL 133
DEFINE BLUE=TCALL 134
DEFINE MAGENTA=TCALL 135
DEFINE RED=TCALL 136
DEFINE YELLOW=TCALL 137
DEFINE GREEN=TCALL 138
DEFINE CYAN=TCALL 139
DEFINE RBLACK=TCALL 140
DEFINE RWHITE=TCALL 141
DEFINE RBLUE=TCALL 142
DEFINE RMAGENTA=TCALL 143
DEFINE RRED=TCALL 144
DEFINE RYELLOW=TCALL 145
DEFINE RGREEN=TCALL 146
DEFINE RCYAN=TCALL 147

DEFINE	DING
	TTYI
	BYTE	7,0
	EVEN
	ENDM

;--- Macro to address cursor

DEFINE	CURSOR	ROW,COL
	MOVB	ROW,D1
	ROLW	D1,#8.
	MOVB	COL,D1
	TCRT
	ENDM

;--- Macro to address cursor and output text

DEFINE	TYPEAT	ROW,COL,TEXT
	CURSOR	#^D<ROW>,#^D<COL>
	TYPE	<TEXT>
	ENDM

;--- Macros to turn on and off cursor and high intensity, without performing
;    any redundant escape sequences.  A system of flags is used to determine
;    current status of the cursor, intensity, and graphics mode

DEFINE LOW=CALL SET.LOW
DEFINE HIGH=CALL SET.HIGH
DEFINE GRAFIX=CALL SET.GRAFIX
DEFINE TEXT=CALL SET.TEXT
DEFINE CURON=CALL SET.CURON
DEFINE CUROFF=CALL SET.CUROFF

;--- macro to jump if a character was entered

DEFINE	KEY	ADDR
	TCKI
	JEQ	ADDR
	ENDM

;--- macros to output a RAD50 word as 3 ASCII chars, and to output a longword
;    as 6 ASCII characters

DEFINE	OUTDEV	ADDR
	LEA	A1,ADDR
	LEA	A2,TEMP(MEM)
	UNPACK
	CLRB	@A2
	TTYL	TEMP(MEM)
	ENDM

DEFINE	OUTNAM	ADDR
	LEA	A1,ADDR
	LEA	A2,TEMP(MEM)
	UNPACK
	UNPACK
	CLRB	@A2
	TTYL	TEMP(MEM)
	ENDM

DEFINE	OUTNM2	ADDR
	LEA	A1,ADDR
	LEA	A2,TEMP(MEM)
	UNPACK
	UNPACK
1$$:	CMMB	-(A2),#40
	BEQ	1$$
	CLRB	1(A2)
	TTYL	TEMP(MEM)
	ENDM

;--- Bit Test macros nostalgic of the AM100

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

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

;--- Macros to move data between different size data areas

DEFINE	MOVBL	SRC,DST
	CLR	D7
	MOVB	SRC,D7
	MOV	D7,DST
	ENDM

DEFINE	MOVWL	SRC,DST
	CLR	D7
	MOVW	SRC,D7
	MOV	D7,DST
	ENDM

;--- Macros to return from subroutines based on condition codes

DEFINE	REQ
	BNE	1$$
	RTN
1$$:
	ENDM

DEFINE	RNE
	BEQ	1$$
	RTN
1$$:
	ENDM

;--- Macros to copy and compare strings

DEFINE	MOVSTR	SRC,DST
	SAVE	A0,A1
	LEA	A0,SRC
	LEA	A1,DST
1$$:	MOVB	(A0)+,(A1)+
	BNE	1$$
	REST	A0,A1
	ENDM

DEFINE	CMPSTR	SRC,DST
	SAVE	A0,A1
	LEA	A0,SRC
	LEA	A1,DST
	CALL	CMPSTR
	REST	A0,A1
	ENDM