;*********************************************************************
;
; WHOSON.M68    -       WHO'S ON the EMAIL System
;
;               Written by: Dave Heyliger - AMUS Staff
;
;       Purpose: To display all EMAIL user names at the dot
;                Bright display = on-line, Dim display = off-line
;
;       Used: Any time you like
;
;**********************************************************************

       SEARCH  SYS                             ;grab required system files
       SEARCH  SYSSYM
       SEARCH  TRM

       VMAJOR=1                                ;original by DAVE HEYLIGER
       VMINOR=0
       VEDIT=0

;program header
;
       PHDR    -1,0,PH$REE!PH$REU              ;reentrant,reusable

;variables in user's memory partition
;
       .OFINI
       .OFDEF  MEMPTR,4                        ;^EMAIL.SYS in system memory
       .OFDEF  SCRAP,90.                       ;scrap workspace
       .OFDEF  RADBUF,6                        ;RAD50 scrap workspace
       .OFDEF  ASCBUF,8.                       ;ascii buffer
       .OFSIZ  IMPSIZ

;MACRO definitions
;
DEFINE  PRTTAB  AA,BB                           ;define PRTTAB (#,#)
       MOVB    #'AA,D1                         ;move in left number
       LSLW    D1,#10                          ;shift over
       MOVB    #'BB,D1                         ;place in next number
       TCRT                                    ;perform call
ENDM

DEFINE  ONEKEY                                  ;one keystroke on KBD into D1
       PUSH    A6                              ;save used registers
       JOBIDX  A6                              ;get JOBIDX
       MOV     JOBTRM(A6),A6                   ;get JOBTRM status word
       ORW     #T$IMI,@A6                      ;one key entry
       POP     A6                              ;restore registers
ENDM

DEFINE  MNYKEY                                  ;many keys on KBD call (A2 ^)
       PUSH    A6                              ;save registers
       PUSH    D4
       MOVW    #T$IMI,D4                       ;get flag
       COMW    D4                              ;flip bits
       JOBIDX  A6                              ;your JCB pointer
       MOV     JOBTRM(A6),A6                   ;get JOBTRM status word
       ANDW    D4,@A6                          ;reset status word
       POP     D4                              ;restore reggies
       POP     A6
ENDM

DEFINE  NOECHO                  ;makes keyboard entries "invisible"
       PUSH    A1              ;black box
       PUSH    A6
       JOBIDX  A6              ;give A6 the JOBIDX
       MOV     JOBTRM(A6),A1   ;A1 points to the Terminal Status Word
       ORW     #T$ECS,@A1      ;second bit now contains a "1" (no echo)
       POP     A6
       POP     A1
ENDM

DEFINE  ECHO                    ;turns ECHO back on for keyboard input
       PUSH    A6              ;black box
       PUSH    A1
       PUSH    D4
       JOBIDX  A6              ;get the JOBIDX
       MOV     JOBTRM(A6),A1   ;A1 points to the Terminal Status Word
       MOVW    #T$ECS,D4       ;D4 contains 00000010
       COMW    D4              ;D4 contains 11111101
       ANDW    D4,@A1          ;second bit now contains a "0"
       POP     D4
       POP     A1
       POP     A6
ENDM

DEFINE  BRIGHT=PRTTAB -1,12.    ;bright intensity terminal output
DEFINE  DIM=PRTTAB -1,11.       ;dim intensity term. output
DEFINE  OFF=PRTTAB -1,29.       ;cursor off
DEFINE  ON=PRTTAB -1,28.        ;cursor on


       GETIMP  IMPSIZ,A3                       ;allocate memory

       ;set up the screen
       PRTTAB  -1,0
       TYPE    <                               AMUS EMAIL User List>
       CLR     D2                              ;who counter (row counter)
       ONEKEY                                  ;set for 1 key input

       ;find EMAIL.SYS
       CALL    FNDMEM                          ;get EMAIL.SYS

       ;setup pointers for scan, counters for screen control
       MOV     A4,A1                           ;A1 points to EMAIL.SYS
       MOV     508.(A1),D4                     ;D4 contains num of "blocks"
       MOV     #8.,D5                          ;column counter
LN:     MOV     #20.,D3                         ;look 20 times per "block"

       ;look for a name
SCNAME: CMP     @A1,#0                          ;found a name?
       JEQ     NXTNAM                          ;nope, try again

       ;found a name, see if on-line and adjust Bright or Dim output
       CMP     12.(A1),#0                      ;user on???
       BEQ     DIMUSR                          ;nope
       BRIGHT                                  ;"bright"
       BR      TYPUSR                          ;type em out
DIMUSR: DIM                                     ;"dim"

       ;type out user to the screen
TYPUSR: ADD     #4,D2                           ;get row
       MOVB    D2,D1                           ;setup for TCRT
       LSLW    D1,#10
       MOVB    D5,D1                           ;get column
       TCRT                                    ;tab here
       SUB     #4,D2                           ;get count

       LEA     A2,SCRAP(A3)                    ;point to buffer
       PUSH    A2                              ;save pointer
       UNPACK                                  ;get name
       UNPACK
       CLRB    @A2                             ;end name w/ a null
       POP     A2                              ;retrieve pointer
       TTYL    @A2                             ;type it out
       SUB     #4,A1                           ;repoint to start of name

       ;adjust counters
       INC     D2                              ;counter = counter + 1
       CMP     D2,#20.                         ;20 users out?
       JNE     NXTNAM                          ;nope

       ;adjust screen control etc...
       CLR     D2                              ;clear row counter
       ADD     #10.,D5                         ;create new column
       CMP     D5,#68.                         ;screen full?
       JLT     NXTNAM                          ;nope, time for next "block"

       ;full screen, apply screen control
       PRTTAB  24,1                            ;tab to here
       OFF                                     ;cursor off
       ONEKEY                                  ;keystroke to D1
       NOECHO                                  ;no keystoke echo
       TYPE    <Hit any key to continue... >   ;prompt
       KBD                                     ;get keystoke
       CTRLC   ALLOUT                          ;if ^C then return
       ECHO                                    ;echo back on
       MNYKEY                                  ;A2 pointer to KBD data
       ON                                      ;cursor on
       PRTTAB  4,1                             ;tab to here
       ERASE                                   ;clean up the screen
       MOV     #8.,D5                          ;reset column
       BR      GNB                             ;and get next block

       ;point to next slot in array
NXTNAM: ADD     #24.,A1                         ;bypass stats
DECD3:  DEC     D3                              ;one less scan to do
       BEQ     GNB                             ;if 0 get next block
       JMP     SCNAME                          ;else SCan for NAME

       ;get "next block" if block done
GNB:    DEC     D4                              ;one less block to search
       BEQ     ALLOUT                          ;if 0 all names out
       ADD     #56.,A1                         ;point to next "block"
       JMP     LN                              ;search again

       ;here when all done
ALLOUT: BRIGHT                                  ;bright display (normal)

EOWHO:  PRTTAB  24.,1                           ;tab here
       EXIT


;FIND MEMORY Subroutine - finds EMAIL.SYS in system memory
;---------------------------------------------------------
FNDMEM: LEA     A2,SYSFIL                       ;point to ascii file
       LEA     A0,SCRAP(A3)                    ;A0 points to buffer area
       FILNAM  @A0                             ;create filename
       SRCH    @A0,A4                          ;A4 will contain mem pointer
       BNE     10$                             ;didn't find EMAIL.SYS
       RTN                                     ;found it, A4 pointer

10$:    MOV     #7,D1                           ;get a bell
       TTY                                     ;beep
       TYPECR  <       ?EMAIL.SYS not installed.>
       EXIT

SYSFIL: ASCII   /EMAIL.SYS/
       EVEN
       END