;****************************************************************************
; RV.M68
;
; last update: 10/29/87 - worked on DISM68 version, changed to normal
;****************************************************************************



       ;search UNV files in MAC: account, PLUS AAA.UNV (AMUS Network)
       ;
       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  TRM
       SEARCH  AAA                     ;my personal UNV file


       ;define a version number
       ;
       VMAJOR=3.                       ;Version 3.0(101)
       VMINOR=1.


       ;define user variables:
       ;
       .OFINI                          ;initialize offset space
       .OFDEF  FNAME,10                ;filename packed RAD50
       .OFDEF  RVMOD,4                 ;pointer to REVUE.MOD
       .OFDEF  BUFFER,20.              ;misc. buffer
       .OFDEF  SLPFLG,4.               ;flag set to #123 if REVUEing
       .OFSIZ  IMPSIZ                  ;IMPSIZ contains final # of var. bytes


       ;define extra useful MACROs
       ;
DEFINE  BRIGHT=PRTTAB -1,12.
DEFINE  DIM=PRTTAB -1,11.


       ;define a program header
       ;
L0:     PHDR    -1,0,PH$REE!PH$REU


       ;define user variable workspace, have A3 point to the base of them
       ;
       GETIMP  IMPSIZ,A3               ;A3 points to all user variables


       ;process input line
       ;
       BYP                             ;bypass whitespace after ".RV.."
       LIN                             ;just ".RV" ?
       JNE     FILEIN                  ;nope, must be ".RV file"


       ;user just entered in ".RV", give user instructions
       ;
       CRLF                            ;first output a CRLF
       TYPE    <Usage: RV_filename.ext>;type how to user the program
       DIM                             ;dim the next part of the output
       TYPECR  <  (i.e., just like VUE)>       ;rest of output line
       BRIGHT                          ;back to "bright" terminal output
       CRLF                            ;output a CRLF

       TYPECR  <RV acts "just like VUE" except your keystrokes will be recorded in a file in.>
       TYPECR  <your PPN.   The first name of the file will match the first name of the file>
       TYPECR  <you are "RV-ing".   The extension of the file is ".RV".  At the end of your>
       TYPECR  <editing session, you have the option of deleting this keystroke file.    You>
       TYPECR  <should delete this keystroke file only upon a "Finish" or "Go".>
       CRLF

       TYPECR  <If an accidental Quit, JOB Crash, System Crash, or Power failuser has occured>
       TYPECR  <while you were "RV-ing" a file, you may restore this file.>
       CRLF

       DIM
       TYPECR  <BolderBITS (c) 1987>
       BRIGHT
       CRLF
       EXIT


       ;parse filespec and make sure extension is NOT ".RV" !!!
       ;
FILEIN: FILNAM  FNAME(A3),ZQL           ;get input filename into FNAME
                                       ;use "ZQL" for special bogus ext.
                                       ;if user just says RV_FILE
       CMPW    FNAME+4(A3),#[RV ]      ;is extension ".RV"?
       JNE     GOODEX                  ;nope, looking good!


       ;user entered in ".RV" as an extension. This is a no-no.
       ;
       MOV     #7,D1                   ;get a bell
       TTY                             ;"beep"!
       CRLF                            ;output CRLF
       TYPECR  <?Cannot employ RV.LIT on any file with a .RV extension.>
       CRLF                            ;plus a message
       EXIT                            ;and return user to the dot.


       ;filespec looks good, make a permanent memory module in their user
       ;memory called REVUE.MOD. This module is used to maintain all nec.
       ;variables used while REVUE.SYS is running (concurrently with VUE).
       ;The layout of REVUE.MOD is as follows (offsets in OCTAL)
       ;
       ; 0:            flag for "INIT already done".  off = 0    on = 123
       ; 1:            flag for "REVUE in progress"   off = 0    on = 123
       ; 2-151:        DDB for "*.RV" file
       ; 152-1151      512. byte block buffer area for "*.RV" file blocks
       ; 1152:         Pointer into Block Buffer where character should go
       ; 1156:         Block Count - # of blocks into "*.RV" file
       ; 1162:         Character Count - # characters entered in from VUE
       ; 1166:         Total Count - total # characters (up to 512)
       ; 1172:
       ; 1176:         Parsing flag in *.RV disk block set after q,CR,-1 chkd
       ; 1202:
       ; 1206:         bootstrap flag - set on LF TRMICP
       ;
GOODEX: PUSH    #1024.                  ;size of the memory module (1K)
       PUSH                            ;this PUSH is part of GETMEM
       GETMEM  @SP                     ;room for the module?
       BEQ     ROOM                    ;yup, make it. Else:


       ;no room for REVUE.MOD, so don't run the program.
       ;
       TYPECR  <?Insufficent space for REVUE to be initialized.>
       EXIT                            ;get the user back to the dot


       ;create a memory module in the User's Memory Partition called
       ;REVUE.MOD.
       ;
ROOM:   POP     A1                      ;A1 points to REVUE.MOD
       POP                             ;part of the GETMEM call
       PUSH    A1                      ;save pointer to REVUE.MOD
       MOV     A1,RVMOD(A3)            ;save pointer in variable RVMOD

       CLRW    @A1                     ;clear first word in REVUE.MOD
       MOVW    #[MOD],-(A1)            ;move in RAD50  "REVUE.MOD"
       MOVW    #[UE ],-(A1)            ;  (standard module setup)
       MOVW    #[REV],-(A1)
       POP     A1                      ;repoint to REVUE.MOD
       LEA     A4,2(A1)                ;A4 points to DDB in REUVE.MOD


       ;create "Dev#:FILENAME.RV[P,PN]" in DDB within REVUE.MOD
       ;
       LEA     A5,D.FIL(A4)            ;point to D.FIL in REVUE.MOD
       MOV     FNAME(A3),@A5           ;move in RAD50 filename
       MOVW    #[RV ],D.EXT(A4)        ;move in RAD50 ".RV" in extension
       JOBIDX  A6                      ;point to user
       MOVW    JOBDEV(A6),D.DEV(A4)    ;move in device
       MOVW    JOBDRV(A6),D.DRV(A4)    ;move in drive number
       MOVW    JOBUSR(A6),D.PPN(A4)    ;move in user's PPN


       ;now INIT the DDB ourselves (instead of calling the INIT routine)
       ;  First set the D$INI flag within the DDB and set INIT in .MOD.
       ;  Then establish the 512. byte buffer in the DDB by setting D.REC
       ;  and D.SIZ. Finally, set 1st byte in REVUE.MOD to #123.
       ;
       CLR     D.DVR(A4)               ;this is so LOOKUP will find DSK.DVR
       LEA     A0,D.FLG(A4)            ;point A0 to D.FLG
       MOVB    @A0,D4                  ;move the flag value into D4
       ORB     #D$INI,D4               ;set D$INI within the flag
       MOVB    D4,@A0                  ;replace the flag value
       LEA     A0,152(A1)              ;point A0 to block buffer area in DDB
       MOV     A0,D.BUF(A4)            ;move this pointer to D.REC
       MOV     #512.,D.SIZ(A4)         ;set the buffer size
       MOVB    #123,@A1                ;set INIT flag in REVUE.MOD


       ;now see if "*.RV" exists in the user PPN (LOOKUP will grab DSK.DVR
       ; since D.DVR was cleared to "0")
       ;
MAKE:   LOOKUP  @A4                     ;FILENAME.RV in user's PPN?
       JEQ     FNDRV                   ;yup, found *.RV

       ;didn't find *.RV, so make one!
       MOV     #20.,D.ARG(A4)          ;establish a 20 block random file
       DSKCTG  @A4                     ;allocate the file
       MOV     #0,1156(A1)             ;clear block count
       MOV     #0,1162(A1)             ;clear character count
       MOV     #0,1166(A1)             ;clear total character count


       ;Setup all pointers. Buffer pointer inside the block buffer is stored
       ; at 1152.
       ;
       LEA     A2,152(A1)              ;A2 points to block buffer area
       LEA     A6,1152(A1)             ;A6 points to "variable" space for A2
       MOV     A2,@A6                  ;save current block buffer pointer


       ;Now open the random file, read in the first block, initialize the
       ; entire block to "-1's" to help REVUE know when a restore is complete
       ;
       OPENR   @A4                     ;open "*.RV"
       READ    @A4                     ;read in the first block
       MOV     #-1,D3                  ;get the "-1's"
       MOV     #128.,D2                ;set the total number of lwords to set
10$:    MOV     D3,(A2)+                ;move in a -1
       DEC     D2                      ;one less lword to set
       BNE     10$                     ;but still more to do
       WRITE   @A4                     ;all done, write the -1's back out
       JMP     MSG                     ;and display journaling message

       ;found FILENAME.RV in user's PPN - ask them if they want it REVUEd
       ;
FNDRV:  CRLF                            ;screen format
       MOV     #7,D1                   ;get a bell
       TTY                             ;"beep"
       TAB                             ;tab over
       PRNAM   D.FIL(A4)               ;type out filespec
       TYPECR  < that was created by REVUE has been found in this PPN.>
       TYPESP  <       Would you like this file REVUEd? >
       ONEKEY                          ;set KBD to "one key" input mode
       KBD                             ;get "Y" or ?????
       CTRLC   EXIT                    ;if ^C, then EXIT


       ;user entered in responce, see if it is a "Y" or ???
       ;
       UCS                             ;uppercase the input
       CMPB    D1,#'Y                  ;"Y"?
;       BNE     NORV                    ;nope, don't revue the file
;       MOV     #123,SLPFLG(A3)         ;yes, set sleep flag
       BEQ     REVUE                   ;yes, revue the file

       ;user did NOT respond with the "Y" - erase the FILENAME.RV file
       ;
NORV:   LEA     A4,2(A1)                ;point to DDB in REVUE.MOD
       DSKDEL  @A4                     ;delete "*.RV" in user's PPN
       JMP     MAKE                    ;and then make one


       ;user wants a file restored. Set REVUE flag in REVUE.MOD
       ;and clear all counters. Open the random file.
       ;
REVUE:  CRLF                            ;for user's terminal
       MOV     RVMOD(A3),A1            ;point A1 to REVUE.MOD
       MOVB    #123,1(A1)              ;set REVUE flag
       CLR     1156(A1)                ;clear Block Count
       CLR     1162(A1)                ;clear Character Count
       CLR     1166(A1)                ;clear Total Character Count
       MOV     #123,1206(A1)           ;set Bootstrap flag
       OPENR   2(A1)                   ;open *.RV for random file i/o

       ;here's a fancy part: start REVUE by placing a LF in the user's input
       ;buffer. When VUE is called, it will automatically start REVUEing!
       ;
       CLR     D1                      ;clear character register
       MOVB    #12,D1                  ;move in a LF to D1 (req. by TRMICP)
       JOBIDX  A6                      ;A6 points to your JCB
       MOV     JOBTRM(A6),A5           ;A5 points to JOBTRM (req. by TRMICP)
       TRMICP                          ;place LF in input buffer


       ;whether or not restoring a file via REVUE, all users come here for
       ;fancy terminal screen output, indicating REVUE has been init for
       ;the JOB
       ;
MSG:    CRLF                            ;start of Fancy!
       BRIGHT                          ;bright output
       TYPESP  <REVUE has been initialized for>        ;fancy message
       LEA     A2,BUFFER(A3)           ;use BUFFER for JOBNAM buffer
       JOBIDX                          ;point A6 to JCB
       LEA     A1,JOBNAM(A6)           ;A1 points to RAD50 JOB name
       PUSH    A2                      ;save A2 pointer on stack
       UNPACK                          ;create ASCII  "JOBNAME"
       UNPACK
       CLRB    @A2                     ;end string w/ null
       POP     A2                      ;point to start of JOBNAME
       TTYL    @A2                     ;type it out
       TYPECR  < - keystrokes will be recorded.>       ; more message
       DIM                             ;dim output
       TYPECR  <BolderBITS (c) 1987>   ;more fancy stuff
       BRIGHT                          ;back to bright output
       CRLF                            ;final screen output
;       CMP     SLPFLG(A3),#123         ;sleep flag set?
;       BNE     VUELIN                  ;nope
       SLEEP   #10000.                 ;yes, let em see advertizement


       ;now create "VUE filename.ext" on an A2 command line.
       ;
VUELIN: LEA     A2,BUFFER(A3)           ;point A2 to BUFFER variable
       MOVB    #'V,(A2)+               ;create VUE....
       MOVB    #'U,(A2)+
       MOVB    #'E,(A2)+
       MOVB    #'L,(A2)+
       MOVB    #'I,(A2)+
       MOVB    #'T,(A2)+
       MOVB    #40,(A2)+               ;space
       LEA     A1,FNAME(A3)            ;point A1 to RAD50 filename
       UNPACK                          ;create filename
       UNPACK
       CMPW    FNAME+4(A3),#[ZQL]      ;no extension entered by user?
       BEQ     GETEND                  ;nope, so just get CRLF.
EOFN:   CMPB    -1(A2),#40              ;end of filename?
       BNE     GETEXT                  ;yup, get extension on command line
       DEC     A2                      ;else decrement A2
       BR      EOFN                    ;and check again
GETEXT: MOVB    #'.,(A2)+               ;so far, it's "VUE filename."
       LEA     A1,FNAME+4(A3)          ;point to "ext"
       UNPACK                          ;create extension
EOEXT:  CMPB    -1(A2),#40              ;end of filename?
       BNE     GETEND                  ;yup, get extension on command line
       DEC     A2                      ;else decrement A2
       BR      EOEXT                   ;and check again


       ;finish the command line, then use AMOS to VUE the file
       ;
GETEND: MOVB    #15,(A2)+               ;append CR
       MOVB    #12,(A2)+               ;append LF
       MOVB    #0,(A2)+                ;end command line with a null
       LEA     A2,BUFFER(A3)           ;repoint to start
       PUSH    A3                      ;SAVE POINTER TO VARIABLES!
       AMOS                            ;"VUE_filename.ext"


       ;when the user is finished with VUE, see if "*.RV" was created
       ;
       POP     A3                      ;A3 points to variables
       MOV     RVMOD(A3),A4            ;A4 points to REVUE.MOD
       MOV     A4,A1                   ;make a copy into A1
       LEA     A4,2(A4)                ;A4 points to DDB inside REVUE.MOD

       ;found a "*.RV" file. See if user wants to delete the file
       ;
FORG:   LEA     A0,152(A1)              ;move buffer index into A0
       CMPB    @A0,#-1                 ;nothing in the file?
       JEQ     DEL                     ;yup, nothing - erase it

       CLR     D4                      ;counter
10$:    INC     D4                      ;increment counter
       CMPB    (A0)+,#-1               ;find end of characters
       BEQ     20$                     ;found it
       CMP     D4,#512.                ;not yet, done with block?
       BEQ     CONFIR                  ;yup, better confirm
       BR      10$                     ;nope, still look

20$:    DEC     A0                      ;repoint to character "-1"
       CMPB    -1(A0),#15              ;a CR?
       BNE     CONFIR                  ;nope
       CMPB    -2(A0),#'f              ;yes, F,CR?
       JEQ     DEL                     ;yes, delete the file no questions
       CMPB    -2(A0),#'F              ; similar.......
       JEQ     DEL
       CMPB    -2(A0),#'g
       JEQ     DEL
       CMPB    -2(A0),#'G
       JEQ     DEL

CONFIR: CRLF                            ;for screen effects
       TYPESP  <Confirm deletion of your keystroke file>       ;ask 'em
       PRNAM   D.FIL(A4)
       TYPESP  < by entering in a 'Y':>
       ONEKEY                          ;set KBD to one key input mode
       KBD                             ;get Y or ???
       CTRLC   EXIT
       MLTKEY                          ;back to multiple key input
       UCS                             ;upper case the responce
       CMPB    D1,#'Y                  ;"Y"?
       JNE     EXIT                    ;nope, leave file in PPN


       ;user wants "*.RV" deleted. Delete the file from the PPN
       ;
DEL:    DSKDEL  @A4                     ;delete the file


EXIT:   CRLF
       EXIT


END