;******************************************************************
;
;MALINI.M68     -       Mail Initialization (run at bootup)
;
;                  Written by: Dave Heyliger - AMUS Staff
;
;       Purpose: fills EMAIL.SYS with user information. EMAIL.SYS
;                should be located in system memory.
;
;          Used: On bootup via AMOSL.INI. Place this command in
;                AMOSL.INI after the last SYSTEM command line.
;
;******************************************************************

       SEARCH  SYS                             ;get the usuals
       SEARCH  SYSSYM
       SEARCH  TRM

       VMAJOR=1.                               ;Original program by
       VMINOR=0.                               ;Dave Heyliger - AMUS
       VEDIT=0.

       PHDR    -2,0,PH$REE!PH$REU              ;may be run without LOG

       .OFINI
       .OFDEF  IDDB,D.DDB                      ;for EMAIL.USR file
       .OFDEF  SCRAP,20.                       ;scrap buffer workspace
       .OFSIZ  IMPSIZ

       GETIMP  IMPSIZ,A3                       ;A3 points to variables

       LEA     A4,IDDB(A3)                     ;A4 points to DDB
       MOVW    #[EMA],IDDB+D.FIL(A3)           ;move in DSK0:EMAIL.USR[7,2]
       MOVW    #[IL ],IDDB+D.FIL+2(A3)
       MOVW    #[USR],IDDB+D.EXT(A3)
       MOVW    #[DSK],IDDB+D.DEV(A3)
       CLRW    IDDB+D.DRV(A3)
       MOVW    #3402,IDDB+D.PPN(A3)
       INIT    @A4                             ;initialize DDB
       LOOKUP  @A4                             ;file there?
       BEQ     GOTFIL                          ;yup
       TYPECR  <       ?EMAIL.USR not found>   ;nope
       EXIT                                    ;quit

       ;look for DSK0:EMAIL.SYS in system memory - A1 points to it
GOTFIL: LEA     A2,SYSFIL                       ;point to ascii file
       LEA     A0,SCRAP(A3)                    ;A0 points to buffer area
       FILNAM  @A0                             ;create filename
       SRCH    @A0,A1                          ;A1 will contain mem pointer
       BEQ     SRCHOK                          ;search found EMAIL.USR
       TYPECR  <       ?EMAIL.SYS not found>
       EXIT

       ;found EMAIL.USR, EMAIL.SYS. Open the random file up for reading
SRCHOK: OPENR   @A4                             ;open the file
       READ    @A4                             ;read first block
       MOV     IDDB+D.BUF(A3),A2               ;point to first block buffer
       MOV     508.(A2),D3                     ;get number of blocks
RESET:  MOV     IDDB+D.BUF(A3),A2               ;point to buffer
       MOV     #128.,D4                        ;counter (128 * 4 per block)

       ;get the users name into system memory (not nec. sequential listing)
LOOP:   MOV     (A2)+,(A1)+                     ;move in random file block
       DEC     D4                              ;one less move
       BEQ     NXTBLK                          ;0 = next block
       BR      LOOP                            ;else get next word

       ;one random block now in memory, get next one in
NXTBLK: DEC     D3                              ;one less block
       BEQ     DONE                            ;0 = all done

       ;setup the next block record
NB:     INCW    IDDB+D.REC+2(A3)                ;next block
       READ    @A4                             ;read next block
       BR      RESET                           ;reset pointer and go!

DONE:   TYPECR  <AMUS EMAIL initialized.>
       EXIT

SYSFIL: ASCII   /EMAIL.SYS/
       EVEN
END