;
; FORMS.M68
; Copyright (c) 1983,1984,1985 by Creed A. Erickson, Lancaster, PA
; Copyright (c) 1986 by Computer Systems Plus, Inc., Lancaster, PA
; All Rights Reserved
;
; Computer Systems Plus, Inc. hereby gives permission to any individual or
; group to use, reproduce, and/or distribute this software in either source
; or binary format provided that:
;
;               A. Such use, reproduction, and/or distribution is not for
;                  explicitly commercial purposes.
;       AND
;               B. All copyright notices are preserved.
;
; Computer Systems Plus, Inc. assumes no responsiblity for the use, abuse,
; or nonuse of this software.
;
; If you should find that you have critisms or kudos for this program
; you may direct them to the author at the address below.
;
; Computer Systems Plus, Inc. has written a small library of spooler
; routines that are oriented toward multiple printer installations.
; If you have need for such software please contact:
;
;               Creed Erickson
;               Computer Systems Plus, Inc.
;               1630 Manheim Pike
;               Lancaster, PA       17601
;               (717)-560-0140
;
;
; Supplied to AMUS to update/replace program of same name/function written
; by Steven G. McNaughton of Quaker State Oil Refining Corp. Research Center
;
; AMUS release version - 2.0(18)
; assembles to .LIT file with hash 775-455-375-770
;

       SEARCH  SYS
       SEARCH  SYSSYM

;  edit history (last edit listed first) :

; ***** Version 2.0 ****
;       [018]   clean up for release to AMUS public domain. 9-Jun-86 / CAE
;       [017]   change to print form name first. 7-Jun-86 / CAE
;       [016]   merge old spooler support in. 30-Apr-86 / CAE
;       [015]   hacked up 1.1(14) for itc spooler support. 29-Apr-86 / CAE

; ***** Version 1.1 **** fancier display version 2-Jan-84 / CAE

; ***** version 1.0 **** Conversion from "T" 22-Nov-83 / CAE

       VMAJOR  = 2
       VMINOR  = 0
       VEDIT   = 18.

       PHDR    -1,PV$RSM,PH$REU!PH$REE         ; reads system memory
                                               ; is reusable
                                               ; is reentrant
       BR      START
;
; BINARY COPYRIGHT NOTICE
;
       ASCIZ   /FORMS.LIT Copyright (C) 1986, Computer Systems Plus, Inc./

;
; handy little macro for doing tcrt's
;
DEFINE  XY      ROW,COL
       MOVW    #'ROW'.*256.+'COL'.,D1
       TCRT
       ENDM

;
; ITC system equates to get around errors in SYSSYM.UNV
;
       MS.FLG = 0
       MS.SRC = 2
       MS.DST = 10
       MS.SIZ = 16
       MS.PPN = 20
       MS.PRV = 22
       MS.COD = 24
       MS.SPR = 26
       MS.DAT = 36
;
; do pretty underlined header
;
START:
       CRLF
       TYPE    <                             > ; space out
       XY      -1,31                           ; end underline
       XY      -1,2                            ; back to beginning of line
       XY      -1,30                           ; begin underline
       TYPE    <CURRENTLY MOUNTED FORMS ARE:>  ; message
;
; determine spooler type
;
       MOV     #LPTQUE,A0                      ; get old spooler chain
       MOV     @A0,D7                          ; test for zero
       BEQ     NEWSPL                          ;   yep - use ITC spooler
OLDSPL:
       MOV     @A0,A0                          ; get next link
       MOV     A0,D7                           ; is it zero?
       BEQ     OLDXIT                          ;   yep - all done
       MOV     #4,D1                           ; preset offset to form
       LEA     A1,10(A0)                       ; index spooler name
       CALL    PRTLIN                          ; do it
       BR      OLDSPL                          ; and loop
OLDXIT:
       JMP     DONE

NEWSPL:
       PUSH                                    ; make a socket data area
       PUSH                                    ;  on our stack
       PUSH
       MOV     SP,A6                           ; get the index
       MOVW    #-100000,OM.FLG(A6)             ; load it up
       MOVW    #2000,OM.LEN(A6)
       MOVW    #12,OM.MAX(A6)
       CLRW    OM.MSR(A6)
       OPNMSG  @A6,D6                          ; open socket
       JNE     SCKERR                          ; handle any errors
       POP                                     ; remove socket data area
       POP                                     ;   from stack
       POP
       GETIMP  224,A0                          ; get ITC header/message memory
       CLR     MS.DST(A0)
       MOVW    #65533.,14(A0)                  ; set dest to spooler
       MOVW    #224,MS.SIZ(A0)                 ; set msg size
       MOVW    #0,MS.COD(A0)
       MOVW    #52525,MS.SPR(A0)               ; ITC spooler flag
       MOVW    #1,MS.SPR+2(A0)                 ; I think this is an opcode
       JOBIDX
       MOV     JOBNAM(A6),MS.DAT+2(A0)         ; tell my name
       LEA     A6,JOBTRM(A6)                   ;     and my terminal
       MOV     @A6,D7
       BEQ     NOTRM
       MOV     D7,A6
       MOV     -4(A6),34(A0)
NOTRM:
       CLRW    MS.FLG(A0)
       SNDMSG  @A0,D6,0                        ; ship request off to ITC splr
       BNE     MSGERR                          ; handle error
WL:
       CTRLC   XSIT                            ; allow user abort
       WTMSG   #20000.                         ; wait for a message
       BNE     DONE                            ; timed out - finished
       RCVMSG  @A0,D6,0                        ; woke up - get msg
       BNE     RCVERR                          ; somethings rotten !!
       CMPW    MS.SPR(A0),#52525               ; test spooler flg
       BNE     WL                              ; not what we want - retry
       MOV     #1,D0                           ; loop counter - 1
       MOV     #14,D1                          ; preset offset to form
       LEA     A1,32(A0)                       ; index spooler name
AGAIN:
       TSTW    -2(A1)                          ; end of spoolers ??
       BNE     DONE                            ; yes - finished
       CALL    PRTLIN                          ; otherwise display
       LEA     A1,116(A0)                      ; bump to second of pair
       DBF     D0,AGAIN                        ; loop if second not done
       BR      WL                              ; otherwise see if more

DONE:   CRLF
       EXIT

;
; error handleing/recovery needs work
;

SCKERR: TYPE    <OPEN SOCKET ERROR>
XSIT:   EXIT

MSGERR: TYPE    <SEND MSG ERROR>
       EXIT

RCVERR: TYPE    <RECV MSG ERROR>
       EXIT
;
; PRTLIN ... display form-name/spool-name
;
; PASSED:
;       A1 points to spooler name
;       D1 contains offset from A1 to get to form name
;
PRTLIN:
       CRLF
       PUSH    d1                      ; xy macro destroys d1 so save it
       XY      -1,11                   ; lo intensity
       TYPESP  < Form>
       XY      -1,12                   ; normal intensity
       POP     D1                      ; restore offset
       PUSH                            ; create ascii buffer on stack
       PUSH
;
; print form name first
;
       MOV     A1,D5                   ; D5 gets saved pointer to spool-name
       ADD     D1,A1                   ; add in offset to form-name
       MOV     SP,A2                   ; set a2 to ascii buffer
       UNPACK
       UNPACK
       TTYL    @SP                     ; print form name
       XY      -1,11                   ; lo
       TYPESP  < on>
       XY      -1,12                   ; hi
       MOV     SP,A2                   ; reset a2
       MOV     D5,A1                   ; restore ptr to spool-name
       UNPACK
       UNPACK
       TTYL    @SP                     ; print spool-name
       POP                             ; relinquish ascii buffer
       POP
       RTN                             ; back to caller


       END