         TITLE 'Tell us what Zippy says'
*++
*
* Print random Zippy quote.
*
* By John Wilson, 06-Apr-88, extracted from my program
* ETS4:MAIL.S, 13-Oct-86.
*
*--
T       EQU     0       ! define AC's
A       EQU     1
B       EQU     2
C       EQU     3
D       EQU     4
O       EQU     14
P       EQU     15
RC      EQU     15      ! return code from calls to MTS
*
        MACRO                   ! Jump to SYStem
&LAB    JSYS    &DEST,&ARGS
&LAB    DS      0H
        AIF     ('&ARGS' EQ '').NOARG
        LA      A,&ARGS         ! point at arg list with R1
.NOARG  L       P,=V(&DEST)     ! point at routine
        BASR    O,P             ! lose!  (MTSux)
        MEND
*
* Pure code begins here
*
BEG     ENTER   (12),SA=R13A    ! set up regs, declare USING
*
*        JSYS  SPRINT,ZIPSAYS     ! warm them up
*        JSYS  SPRINT,BLANK       ! blank line
*
* Open Zippy file, get line # of last line
*
REST    LA      A,=C'GZ7V:ZIPPY.SAYS ' ! point at filename
        JSYS    GETFD           ! get FDUB ptr
        ST      T,ZFDUB         ! save it
        JSYS    GETLST,ZIPLAST  ! get length of file
*
* Using elapsed time as a random number,
* index into the file to get a random quote
* (somehow this seems redundant)
*
        JSYS    TIME,ZIPRAND    ! get time
        L       A,ZLINE         ! load length of file
        XR      T,T             ! SXT T
        D       T,=F'1000'      ! chop to multiple of 1.000 (1000)
        LM      B,C,BUF         ! get elapsed time, uSec
        LPR     B,B             ! force positive
        DR      B,A             ! find random starting line #
        LA      C,1(,B)         ! copy it, add 1
*                               ! fencepost, bag entry 0.000 (comment)
        M       B,=F'1000'      ! cvt to internal form
        ST      C,ZLINE         ! save
*
* Read in randomness, and copy it to the screen.
*
* Stop at first read error
* (hopefully this will be RC=4, "nonexistent line")
*
WZIP1   JSYS    READ,ZIPREAD    ! read next line
        LTR     RC,RC           ! done yet?
        BNZ     WZIP2           ! skip if so
        JSYS    SPRINT,ZPRINT   ! write to screen
        L       A,ZLINE         ! get line #
        LA      A,010(,A)       ! +.010 (internal)
        ST      A,ZLINE         ! poke it back
        B       WZIP1           ! loop
*
* Finished - release the file
*
WZIP2   JSYS    CLOSEFIL,=A(ZFDUB) ! close the file
        L       T,ZFDUB         ! get FDUB ptr
        JSYS    FREEFD          ! release it
         EXIT  ,                  ! disable the MTS, for now
        MTS                     ! see you soon
        B       REST            ! restart
*
* Pure data
*
ZIPSAYS  DC    A(ZSAYS,LZSAYS,ZERO,ZLINE) ! banner
BLANK    DC    A(ZSAYS,ONE,ZERO,ZLINE) ! blank line
ZSAYS    DC    C' Zippy says:'    ! banner text
LZSAYS   DC    Y(L'ZSAYS)         ! length
ZIPLAST DC      A(ZFDUB,ZLINE)  ! GETLST arglist for Zippy
ZIPREAD DC      A(BUF,LEN,@I,ZLINE,ZFDUB) ! READ for Zippy
@I      DC      F'2'            ! indexed read
ZIPRAND DC      A(ZIPKEY,ZERO,BUF) ! get elapsed time in uSec
ZIPKEY  DC      F'16'           ! ... key for above
ZPRINT  DC      A(BUF,LEN,@NOCC,DUMMY) ! SPRINT the line
@NOCC   DC      F'64'           ! no carriage control
*
ZERO    DC      F'0'
ONE      DC    H'1'
        LTORG
*
LEN     DS      H       ! length of line goes here
ZFDUB   DS      F               ! FDUB ptr for ZIPPY.SAYS
DUMMY   DS      F               ! for line number
ZLINE   DS      F               ! line # in ZIPPY.SAYS
R13A    DS      18F             ! R13 save area
BUF     DS      CL80            ! line buffer
*
        END     BEG
