;
;  PROGRAM:  RECORD
;  AUTHOR:  RICHARD CONN
;  VERSION:  3.0
;  DATE:  4 Apr 84
;  PREVIOUS VERSIONS:  1.3 (5 Jan 83), 1.4 (6 Jan 83)
;  PREVIOUS VERSIONS:  1.0 (30 Dec 82), 1.1 (31 Dec 82), 1.2 (1 Jan 83)
;
VERS    EQU     30
z3env   SET     0f400h

;
;       RECORD enables and disables the disk output redirectable I/O
; drivers for ZCPR2.  This command takes two forms:
;
;               RECORD ON       <-- Turn on console recording
;               RECORD OFF      <-- Turn off console recording
;               RECORD ON P     <-- Turn on printer recording
;               RECORD OFF P    <-- Turn off printer recording
;
       ext     z3init,getiop
       ext     eprint

fcb     equ     5dh             ;FCB Input
fcb2    equ     6dh             ;FCB2 Input
cr      equ     0dh
lf      equ     0ah

;
; Environment Definition
;
       if      z3env ne 0
;
; External ZCPR3 Environment Descriptor
;
       jmp     start
       db      'Z3ENV' ;This is a ZCPR3 Utility
       db      1       ;External Environment Descriptor
z3eadr:
       dw      z3env
start:
       lhld    z3eadr  ;pt to ZCPR3 environment
;
       else
;
; Internal ZCPR3 Environment Descriptor
;
       MACLIB  Z3BASE.LIB
       MACLIB  SYSENV.LIB
z3eadr:
       jmp     start
       SYSENV
start:
       lxi     h,z3eadr        ;pt to ZCPR3 environment
       endif

;
; Start of Program -- Initialize ZCPR3 Environment
;
       call    z3init  ;initialize the ZCPR3 Env and the VLIB Env

;
;  Start of Program
;
       call    getiop          ;Check for I/O Driver Defn
       mov     a,h
       ora     l
       jnz     start0
       call    banner
       call    eprint
       db      cr,lf,'Abort -- I/O Driver Address NOT Defined',0
       ret
start0:
       call    status          ;Call Status Routine
       jz      nodriver        ;No Driver Available?
       cpi     80H             ;MUST have Disk Driver Module (> 80H) Loaded
       jnc     start1
       call    banner
       call    eprint
       db      cr,lf,'Abort -- Disk Driver Module NOT Loaded',0
       ret
nodriver:
       call    banner
       call    eprint
       db      cr,lf,'Abort -- No I/O Driver Module Loaded',0
       ret

start1:
       lda     fcb             ;Get first char
       cpi     'O'             ;Must be O
       jnz     help
       lda     fcb+1           ;Get 2nd char
       cpi     'N'             ;ON?
       jnz     off
on:
       lda     fcb2    ;Printer?
       cpi     'P'
       jnz     on1
       call    banner
       call    eprint
       db      '  ++ TTY Recording ON ++',0
       call    lopen   ;LST
       ret
on1:
       call    banner
       call    eprint
       db      '  ++ CRT Recording ON ++',0
       call    copen   ;CRT
       ret
off:
       lda     fcb2    ;Printer?
       cpi     'P'
       jnz     off1
       call    lclose  ;Close Output
       call    banner
       call    eprint
       db      '  ++ TTY Recording OFF ++',cr,lf,0
       ret
off1:
       call    cclose  ;Close Output
       call    banner
       call    eprint
       db      '  ++ CRT Recording OFF ++',cr,lf,0
       ret
;
;  Print Help Message
;
help:
       call    banner
       call    eprint
       db      cr,lf
       db      cr,lf,'RECORD turns on and off recording of screen displays'
       db      cr,lf,'on disk under ZCPR3 with the SYSIO Redirectable I/O '
       db      'Drivers'
       db      cr,lf,'engaged.'
       db      cr,lf
       db      cr,lf,'It is invoked by two forms:'
       db      cr,lf
       db      cr,lf,' RECORD ON  or RECORD ON PRINTER'
       db      cr,lf,' RECORD OFF or RECORD OFF PRINTER'
       db      cr,lf
       db      cr,lf,'Minimum Required Option Forms are ON, OF, and P:'
       db      cr,lf,' RECORD ON P = RECORD ON PRINTER'
       db      cr,lf,'If the P option is given, then TTY output is '
       db      'recorded,'
       db      cr,lf,'else CRT output is recorded.'
       db      cr,lf,0
       ret

;
;  I/O Driver Interface Routines
;
status:
       push    h               ;Save HL
       push    d               ;Save DE
       lxi     d,0             ;No Offset for Status
runio:
       call    getiop          ;Get I/O Base Address
       dad     d               ;Pt to Routine
       pop     d               ;Restore DE
       xthl                    ;Restore HL and Place Address on Stack
       ret                     ;"Run" Routine
copen:
       push    h               ;Save Regs
       push    d
       lxi     d,36            ;Offset for Console Open Routine
       jmp     runio           ;Run Routine
cclose:
       push    h               ;Save Regs
       push    d
       lxi     d,39            ;Offset for Console Close Routine
       jmp     runio
lopen:
       push    h               ;Save Regs
       push    d
       lxi     d,42            ;Offset for Printer Open Routine
       jmp     runio
lclose:
       push    h               ;Save Regs
       push    d
       lxi     d,45            ;Offset for Printer Close Routine
       jmp     runio

;
; Print Banner
;
banner:
       call    eprint
       db      'RECORD, Version '
       db      (vers/10)+'0','.',(vers mod 10)+'0',0
       ret

       end