*   UPDATED 10-22-71 BY J SLAYBAUGH
         SYSTEM   SIG7
         SYSTEM   BPM
         DEF      MAIL,MAILBOX,FMAILBX
         DEF      NOPRINT,MAILD
*
         REF      J:ACCN,JULIAN
*
**
**                DEFINE STANDARD REGISTERS AND CONDITION CODES
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
         PAGE
F:MAIL   DSECT    1
F:MAIL   M:DCB    (FILE,'MAILBOX'),;
                  (KEYED),(DIRECT),(KEYM,7),;
                  (INOUT),(SAVE),;
                  (ERR,ML:ERR),(ABN,ML:ABN)
         PAGE
MAILD    CSECT    0
ENVIR    DATA     %+1
         GEN,16,16 16,0
         RES      16
MSGBUF   RES      28
OPENFPT  DATA     X'14000000'+F:MAIL
         DATA     X'C1000009'
         DATA     ML:ERR            ERR RETURN
         DATA     ML:ABN            ABN RETURN
INOUT    DATA     4                 INOUT USUAL,OUT SOMETIMES
         DATA     X'2010202'        ACCOUNT WHERE MAILBOX
ACCOUNT  TEXT     ':SYS    '         IS TO BE BUILT.
MAXSIZ   EQU      80                20 WORD MESSAGE LIMIT
KEYBUF   RES      2
NOPRINT  DATA     0                 IF NONZERO, NO LP OUTPUT
SENDER   EQU      J:ACCN
BLANK    EQU      X'40'
         PAGE
MAIL     CSECT    1
**
**  MAILBOX ADDS A RECORD TO THE END OF THE RECIPIENTS MAILBOX FILE
**  IF D4 WAS SET TO 1 .
**  THE RECORD IS ALWAYS SENT TO THE LINE PRINTER
**
**       LI,SR3   FPT
**       BAL,SR4  MAILBOX
**
**   FPT          MESSAGE           ADDRESS OF TEXTC MESSAGE(NO INDIRCT)
**    +1          RECIPIENT         ADDRESS OF ACCOUNT NUMBER(2 WORDS)
**
MAILBOX  EQU      %
         LCI      0
         PSM,R0   ENVIR
         M:TIME   MSGBUF+1
         LI,SR3   MSGBUF+1
         BAL,SR4  JULIAN
         LI,R6    7                 7 BYTES FOR KEY
         STB,R6   SR1               TWO WORD DATE/TIME IS KEY- SR1,SR2
         STW,SR1  KEYBUF
         STW,SR2  KEYBUF+1
         B        CMAILBX
FMAILBX  EQU      %                 ENTRY FOR NO TIME UPDATE
         MTW,1    KEYBUF+1          MAKE KEY UNIQUE
         LCI      0
         PSM,R0   ENVIR
CMAILBX  EQU      %
         LW,SR3   ENVIR+12
         LW,SR4   ENVIR+13
         LW,R4    L(C' BY ')
         STW,R4   MSGBUF+4
         LW,R4    SENDER
         STW,R4   MSGBUF+5
         LW,R4    SENDER+1
         STW,R4   MSGBUF+6
         LI,R0    7                 SET R0 TO BYPASS CLOSE
         LW,R4    *SR3              LOCATION OF MSG TO R4
         LB,R7    *R4               BYTE 0 IS BYTE COUNT OF MSG
         CI,R7    MAXSIZ
         BG       EXIT              MSG TOO LONG
         AI,7     1
         LI,R6    6*4               6 WORD FIXED PREFIX
         AW,R6    R7                ADD MSG LENGTH FOR RECORD LNG
         SLS,R4   2                 BYTE ADDRESS
         LI,R5    MSGBUF+7
         SLS,R5   2                 BYTE ADDRESS
         STB,R7   R5                BYTE 0 IS CHARACTER COUNT
         MBS,R4   0
         LI,R5    BLANK
         STB,R5   MSGBUF+7
         AI,SR3   1                 LOCATE RECIPIENT
         LW,4     *SR3              PICK UP ACCT POINTER
         LW,R5    *R4               FIRST WORD OF ACCT
         XW,R5    ACCOUNT
         AI,R4    1
         LW,R7    *R4
         XW,R7    ACCOUNT+1
         LW,D4    ENVIR+17          WAS MAILBOX ADDITION REQUESTED
         BEZ      EXIT              NO
OPEN     EQU      %
         LI,D3    4
         STW,D3   INOUT
         CAL1,1   OPENFPT
CONT     LI,R0    0                 SET TO INDICATE FILE OPEN
WRIT     M:WRITE  F:MAIL,(BUF,MSGBUF+1),(SIZE,*R6),;
                  (ERR,ML:ERR),(ABN,ML:ABN),;
                  (KEY,KEYBUF),(NEWKEY)
EXIT     EQU      %
         MTW,0    NOPRINT
         BNEZ     EXIT05
         LW,4     ACCOUNT
         STW,4    MSGBUF+5
         LW,4     ACCOUNT+1
         STW,4    MSGBUF+6
         LW,R4    ='    '
         STW,R4   MSGBUF
         AI,R6    3
         STB,R6   MSGBUF
         M:PRINT  (MESS,MSGBUF)
EXIT05   EQU      %
         BDR,R0   XIT1
CLOSE    M:CLOSE  F:MAIL,(SAVE)
XIT1     EQU      %
         LCI      0
         STW,R5   ACCOUNT
         STW,R7   ACCOUNT+1
         PLM,R0   ENVIR
         B        *SR4
SLP      GEN,8,24 X'F',60           1 MINUTE SLEEP
         PAGE
**
**   ERROR AND ABNORMAL RETURNS
**
ML:ERR   EQU      %
         B        EXIT
ML:ABN   EQU      %
         LB,R4    SR3
         CI,R4    3                 NON EXISTENT FILE
         BNE      LP1
         LI,D3    2
         STW,D3   INOUT             OPEN FILE OUTPUT
         CAL1,1   OPENFPT
         B        CONT
LP1      CI,R4    X'16'             KEY ALREADY EXISTS
         BNE      LP2
         AWM,R1   KEYBUF+1
         B        WRIT
LP2      CI,R4    X'14'             MAYBE BUSY
         BNE      EXIT
         LI,R1    1
         LB,R4    SR3,R1
         SLS,R4   -1                7 BIT SUB CODE
         CI,R4    1
         BNE      EXIT              NOT BUSY
         CAL1,8   SLP               SLEEP A MINUTE
         AI,R2    1
         BGZ      EXIT
         B        OPEN
         END

