;***************************************************************************
;
;                                AUXSBR.SBR
;                               VERSION 1.1
;
;                      Written By: James A. Jarboe IV
;                             1401 19th Street
;                           Huntsville, TX 77340
;                               409-295-5767
;
;                                 10/02/88
;                    Copyright (c) James A. Jarboe IV
;                                  GR/AM
;****************************************************************************
;
; Get:
;       AUXSBR.BAS
;       AUXSBR.DOC
;         DUMB.M68
;
; Description:  Turns on terminal auxillary port and prints designated file
;               through the auxilliary port on the terminal, from within
;               a BASIC program
;
; What it does: Opens the file selected
;               turns the auxillary port on
;               changes current terminal driver to DUMB.TDV
;               dumps out the file to the terminal through the aux port
;               dumps it a character at a time
;               changes the terminal driver back to the original driver
;               turns the auxillary port off
;               closes the file
;               returns back to BASIC
;
; Requirements: DUMB.TDV must be in the terminal driver section of system
;               memory as
;                         TRMDEF PRINTER,AM300=3:DUMB,9600,20,20,20
;               OR
;                         TRMDEF AUXPRT,PSEUDO,DUMB,1,1,1
;
;               DUMB.TDV is a driver that just dumps data through.
;Example:
;-------------------------------------------------
;;**************
;;** DUMB.M68
;;**************
;;
;;      OBJNAM  DUMB.TDV
;;
;;DUMB: WORD    0
;;      RTN
;;      RTN
;;      RTN
;;      RTN
;;      END
;-------------------------------------------------
;
; USAGE:  XCALL AUXSBR,filename.ext,flag
;
;       Default extension is LST
;
; WHERE:
;        filename.ext = a String variable
;        flag         = a 1 BINARY NUMBER  returned to basic program
;
; EXAMPLE:
;       MAP1 FILENAME,S,24
;       MAP1 FLAG,B,1           ! 0 = all ok & printed
;                               ! 1 = filename not found
;                               ! 2 = filename is a RANDOM file
;                               ! 3 = DUMB.TDV not on a TRMDEF Statement
;
;
; Other requirments:
;       The terminal must be capable of turning on and off the auxilliary port
;       by software. In some instances (such as a file formatted with control
;       characters for printout on a DIABLO printer), the control codes could
;       affect the terminal display screen and other activities. Therefore,
;       it is best to use an auxilliary port on call that also turns off the
;       output to the terminal. This call is usually refered to as
;       "transparent print on" in the TCRT calls or ? TAB(-1,82);.
;       This is also dependent on the terminal driver attached to your
;       terminal. There are two solutions to this :
;       1). If your TCRT calls for your terminal "TAB(-1,82)" does not
;           turn your auxillary port on and your screen off in "transparent
;           print mode" then change your terminal driver to reflect the
;           correct control code to turn the terminal "transparent print"
;           on and off. The terminal manual usually has these control codes
;       2). If your TCRT codes are already set up in the Terminal driver
;           to turn the auxillary port on and the screen off in "transparent
;           print mode" and the TCRT call code I.E."TAB(-1,192)" is different
;           than TAB(-1,82) then change the AXON=82. to AXON=(your call). Do
;           the same for AXOFF=83.
;
;       Since some terminal drivers are different and since TCRT calls are
;       not consistant some alterations may have to be made.
;
;       I have tested this program using SOROC terminals (using simultaneous
;       print mode) and FREEDOM 100 terminals (transparent mode) with OKIDATA,
;       TI810, HP-LASERJET, AND DIABLO printers all work very well, using
;       baud rates at 300, 1200, and 9600, using a straight
;       1-25 = 1-25 DB-25 connector.  Even the DIABLO with a file formatted
;       using SuperVue microspace codes. The only change on the DIABLO was
;       to put it into PTR RDY mode with the DIP switches on the front panel.
;
;       If you would like to substitute a special driver instead of the DUMB.TDV
;       then place it in the place of DUMDVR: at the end of this program
;
;       Any questions, answers, are comments to:
;       James A. Jarboe IV
;       GR/AM
;       409-295-5767
;
;       WORKS ON AMOS 1.2 - 1.3 OPERATING SYSTEMS
;
;        sleep 7.5 secends when through printing for auxport running
;               at slower baud rate than main port's baud rate
;               I.E.  MAIN PORT BAUD RATE                    = 9600
;                     AUXILLARY PORT BAUD RATE & PRINTER     = 1200
;

VMAJOR=1
VEDIT=100               ; Written
VEDIT=101               ; Fancied up

       OBJNAM  AUXSBR.SBR

       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  TRM

DEFINE  CRTF    X                       ; define an easy way
       MOVW    #X+177400,D1            ; to print
       TCRT                            ; TAB(-1,?);
       ENDM

DEFINE  PRTTAB  AA,BB
       PUSH    D1
       MOVB    #AA,D1
       LSLW    D1,#10
       MOVB    #BB,D1
       TCRT
       POP     D1
ENDM

       ASECT
=0
XP.TOP: BLKW    1
TYPE1:  BLKW    1                       ; type of arg 1
ADDR1:  BLKL    1                       ; address of arg1
SIZE1:  BLKL    1                       ; size arg1
TYPE2:  BLKW    1                       ; type of arg 2
ADDR2:  BLKL    1                       ; address of arg2
SIZE2:  BLKL    1                       ; size of arg2
TYPE3:  BLKW    1
ADDR3:  BLKL    1
SIZE3:  BLKL    1

       PSECT
       .=0
ASECT
AREA:   BLKB    616.
BUFFER: BLKB    8.
PRTDVR: BLKB    8.
WASDVR: BLKB    8.
       EVEN
       ENDIMP=.
       PSECT
; TCRT CALLS
;
AXON=82.
AXOFF=83.

       PHDR    -1,0,PH$REE!PH$REU
;
; Check for variable & set up variables
;
SETUP:
       CMPW    XP.TOP(A3),#2           ; got 2 variables ?
       JNE     QTYVAR                  ; no
       CMPW    TYPE1(A3),#2            ; first one a string ?
       JNE     STRVAR                  ; no
       CMPW    TYPE2(A3),#6            ; is var 2 binary
       JNE     BINNUM                  ; no
       MOV     ADDR1(A3),A6
       CMPB    @A6,#0                  ; is var1 empty
       BNE     NEWDVR                  ; no
       MOV     ADDR2(A3),A6            ; send flag 1
       MOVW    #1,@A6                  ; back to basic
       RTN
NEWDVR:
       SAVE    A0
       JOBIDX  A0                      ; job index to a0
       MOV     JOBTRM(A0),A1           ; get job goodies
       MOV     T.TDV(A1),A1            ; point to current driver
       SUB     #4,A1                   ; get just the driver name
       LEA     A2,WASDVR(A4)           ; give it to wasdriver
       UNPACK                          ; unload rad50
       UNPACK                          ; to ascii
FSTDVR:
       MOV     TRMTDC,D0               ; address of first terminal driver
10$:                                    ; in memory
       CTRLC   20$                     ; if ^C then quit
       MOV     D0,A2                   ; move address to A2
       CMM     4(A2),DUMDVR            ; compare it to DUMB.TDV
       BEQ     AUXON                   ; found it ? ..
       MOV     @A2,D0                  ; no..get address of next driver
       BNE     10$                     ; do it again
       MOV     ADDR2(A3),A6            ; no DUMB.TDV found so
       MOVW    #3,@A6                  ; send a 3 back to basic in flag
20$:
       REST    A0
       RTN                             ; Return to basic

AUXON:
       CRTF    AXON                    ; turn aux port on
       JOBIDX  A0                      ; get job goodies
       MOV     JOBTRM(A0),A1           ; point to terminal driver place
       ADD     #10,A2                  ; add 10 to it
       MOV     A2,T.TDV(A1)            ; put new driver in action
       REST    A0
       MOV     A0,AREA(A4)             ; A0->DDB...
                                       ;
OPEN:                                   ; make our own ddb
       CLEAR   @A4,D.DDB               ; clear it...
       LEA     A6,D.DDB(A4)            ; A6->I/O buffer...
       MOV     A6,D.BUF(A4)            ; put into DDB...
       MOVB    #D$INI,D.FLG(A4)        ; set INITed...
       MOV     ADDR1(A3),A2            ; A2->filename...
       FSPEC   @A4,LST                 ; put filename into DDB, and
       LOOKUP  @A4                     ; lookup the file
       BEQ     10$                     ; if found then process
       CALL    AUXOFF                  ; not found .. turn aux off
       MOV     ADDR2(A3),A6            ; send flag of 1
       MOVW    #1,@A6                  ; back to basic
       RTN
10$:
       ;lets check for random files while we are here
       CMPW    D.WRK+6(A4),#-1         ; RANDOM ?
       BNE     20$                     ; no
       CALL    AUXOFF                  ; yes.. turn aux off
       MOV     ADDR2(A3),A6            ; send a flag of 2
       MOVW    #2,@A6                  ; back to basic
       RTN
20$:
       OPENI   @A4                     ; open it.
LOOP:
       CTRLC   EOF
       FILINB  @A4                     ; ask for next byte...
       TST     D.SIZ(A4)               ; anything left?
       BEQ     EOF                     ; br if not...
       TTY                             ; put it out
       BR      LOOP                    ; do it again
EOF:
       MOVB    #12.,D1                 ; send a form feed to auxport
       TTY                             ; put it out
       CLOSE   @A4                     ; close the file
QUIT:
       CALL    AUXOFF                  ; turn aux off
       SLEEP   #75000.                 ; sleep 7.5 sec [101]
                                       ; just in case auxport baud rate
                                       ; is slower than main port baud rate
                                       ; can comment out or increase or
                                       ; decrease time according to your
                                       ; specs
       MOV     ADDR2(A3),A6            ; send flag 0
       MOVW    #0,@A6                  ; back to basic
       RTN
;
; Turn Aux port off and reset orginal driver
;
AUXOFF:
       LEA     A2,WASDVR(A4)           ; point to original driver
       LEA     A1,PRTDVR(A4)           ; point to new place
       PACK                            ; repack it since
       PACK                            ; we unpacked it to see it
       MOV     TRMTDC,D0               ; tell us where Term drivers are
10$:
       MOV     D0,A2                   ; point to next driver
       CMM     4(A2),PRTDVR(A4)        ; compare memory to chosen driver
       BEQ     CHON                    ; found it ? ..
       MOV     @A2,D0                  ; no..get address of next driver
       BNE     10$                     ; do it again
       JMP     NOFNDV                  ; no find original driver
CHON:
       JOBIDX  A0                      ; get job goodies
       MOV     JOBTRM(A0),A1           ; point them to a1
       ADD     #10,A2                  ; add 10 to a2 to get driver
       MOV     A2,T.TDV(A1)            ; put original driver back in
       CRTF    AXOFF                   ; aux port off
       RTN
;
; Error Reporting
;
; Not enough variables
QTYVAR:
       PRTTAB  24.,1
       CRTF    11.
       TYPE    <Must pass >
       CRTF    12.
       TYPE    <2 >
       CRTF    11.
       TYPE    <variables >
       JMP     INAUX
;variable 2 must be a binary 1
BINNUM:
       TYPECR
       PRTTAB  24.,1
       CRTF    11.
       TYPE    <Variable >
       CRTF    12.
       TYPE    <2 >
       CRTF    11.
       TYPE    <must be a >
       CRTF    12.
       TYPE    <BINARY 1 >
       BR      INAUX
;variable 1 must be a string
STRVAR:
       TYPECR
       PRTTAB  24.,1
       TYPE    <First >
       CRTF    11.
       TYPE    <Variable must be a >
       CRTF    12.
       TYPE    <STRING >
       BR      INAUX
; could not find original driver !! bad bad problem !!
NOFNDV:
       TYPE    <Original Terminal Driver Could not be found >
INAUX:
       CRTF    11.
       TYPE    <in >
       CRTF    12.
       TYPE    <AUXSBR.SBR >
       SLEEP   #75000.
       RTN

DUMDVR: RAD50   /DUMB/                  ; if you want to use a different
       RAD50   /TDV/                   ; driver change data in DUMDVR
       EVEN                            ; even memory
       END