home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / decpro300 / prodf.mac < prev    next >
Text File  |  2020-01-01  |  9KB  |  326 lines

  1.     .TITLE    KERDF - Default file processing routines
  2.     .SBTTL    N Bush
  3.  
  4. ; Version 1.0.000
  5.  
  6.     .IDENT    /1.0.000/
  7.  
  8. ; Directives
  9.  
  10.     .LIBRARY /KERMLB/        ; Pro/Kermit macro library
  11.     .LIBRARY /LB:[1,5]RMSMAC/    ; RMS-11 macro library
  12.  
  13.     .SBTTL    Revision History
  14. ;
  15. ; 1.0.000    By: Nick Bush        On: 19-December-1983
  16. ;        Create this module
  17. ;
  18.  
  19.  
  20.     .SBTTL    .MCALLs for RSX and RMS directives
  21.  
  22. ; The following are the various MCALLs that KERXK uses.
  23.  
  24.     .MCALL    FAB$B            ; To build FAB for RMS
  25.     .MCALL    RAB$B            ; To build RAB for RMS
  26.     .MCALL    $OPEN            ; Open a file using RMS
  27.     .MCALL    $CLOSE            ; Close a file using RMS
  28.     .MCALL    $CONNECT        ; Connect RAB to FAB
  29.     .MCALL    $DISCONNECT        ; Disconnect RAB and FAB
  30.     .MCALL    $GET            ; Read a record
  31.     .MCALL    $PUT            ; Write a record
  32.     .MCALL    $UPDATE            ; Update record in place
  33.     .MCALL    $REWIND            ; Rewind stream
  34.     .MCALL    $CREATE            ; Create a file
  35.     .MCALL    $STORE            ; Store an RMS field
  36.     .MCALL    $FETCH            ; Fetch an RMS field
  37.     .MCALL    $COMPARE        ; Compare value with RMS field
  38.     .MCALL    ORG$            ; Declare type of file access we need
  39.  
  40.     ORG$    SEQ,<CRE,GET,PUT,UPD>    ; Type of access we need
  41.  
  42.  
  43. ; The following causes the KERMIT definitions to be read and defined
  44.  
  45.     .MCALL    KERDEF            ; Get the KERMIT definitions
  46.     KERDEF                ; Define all of the KERMIT symbols
  47.     .MCALL    BLOCK            ; Macro to define blocks
  48.     .MCALL    MSG            ; Text definition macro
  49.  
  50.     .SBTTL    Local symbol definitions
  51.  
  52. ; The following are some local symbol defintions used in the defaults file
  53. ;processing
  54.  
  55.     DF.MRS=    64.            ; Maximum record size is 64.
  56.  
  57. ; A record in the defaults file is of the form:
  58.  
  59. ;*** Insert box here
  60.  
  61.     BLOCK    DF            ; Define DF.xxx symbols for record offsets
  62.     .X    RTP            ; Record type code
  63.     .XX    RSZ            ; Size of data portion of record
  64.     .XX    OFS            ; Offset to data portion of record
  65.     .X    HLN,0            ; Length of header
  66.  
  67.     .SBTTL    Impure storage
  68.  
  69. ; The following are the local impure storage locations for KERDF.
  70.  
  71.     .PSECT    $OWN$,  D  
  72.  
  73. DF.FAB:    FAB$B                ; Define the FAB
  74.      F$FAC    FB$GET!FB$PUT!FB$UPD    ; Want to be able to do a few operations
  75.      F$FNA    M$DFLN            ; Address of name string
  76.      F$FNS    DFLN$L            ; Length of name string
  77.      F$LCH    DFLLUN            ; Logical unit number to use
  78.      F$MRS    DF.MRS            ; Maximum record size
  79.      F$ORG    FB$SEQ            ; Sequential file
  80.      F$RFM    FB$FIX            ; Fixed record length
  81.     FAB$E                ; End of FAB
  82.  
  83. DF.RAB:    RAB$B                ; Define the RAB
  84.      R$FAB    DF.FAB            ; Address of FAB
  85.      R$RAC    RB$SEQ            ; Sequential access
  86.      R$RBF    DF.BUF            ; Record buffer address
  87.      R$RSZ    DF.MRS            ; Recurd buffer size
  88.      R$UBF    DF.BUF            ; User buffer address
  89.      R$USZ    DF.MRS            ; Buffer size
  90.     RAB$E                ; End of RAB
  91.  
  92. DF.BUF:    .BLKB    DF.MRS            ; Record buffer
  93.  
  94. DFLOPN:    .BLKB    1            ; Flag whether file is open
  95. DFLRCR:    .BLKB    1            ; Flag whether record is current
  96.     .EVEN                ; Back to word boundary
  97.  
  98. ; Pure data
  99.  
  100.     .PSECT    $PLIT$,RO,D        ; Put in correct place
  101.  
  102. MSG    DFLN,<LB:[ZZKERMIT]ZZKERMIT.DAT> ; File name
  103.  
  104.     .SBTTL    DF.INI - Initialize the default file handling
  105.  
  106. ;++
  107. ; This routine will initialize the default file processing.  It will
  108. ;determine if the default file exists, and if not, it will create it
  109. ;as an empty file.  The file will be left in a state such that we can
  110. ;read and write to it.
  111. ;
  112. ; Usage:
  113. ;
  114. ; Macro:
  115. ;    JSR    PC,DF.INI
  116. ;    (Return here always)
  117. ;
  118. ;--
  119.  
  120.     .PSECT    $CODE$,  RO 
  121.  
  122. DF.INI::CLRB    DFLRCR            ; No current record at all
  123.  
  124. ; First try to open the file
  125.  
  126.     MOV    #DF.FAB,R0        ; Point at the FAB
  127.     $OPEN    R0            ; Open the file
  128.     $COMPARE #SU$SUC,STS,R0        ; Did we successfully open the file?
  129.     BEQ    10$            ; Yes, set up RAB
  130.  
  131. ; Here if we could not open the file for some reason.  Try to create a new
  132. ;one
  133.  
  134.     $CREATE    R0            ; Attempt to create the file
  135.     $COMPARE #SU$SUC,STS,R0        ; Could we?
  136.     BNE    15$            ; No, give up
  137.  
  138. ; Here after file has either been OPENed or CREATEd.  Connect up the RAB
  139.  
  140. 10$:    MOV    #DF.RAB,R0        ; Point at the RAB
  141.     $CONNECT R0            ; Connect it up
  142.     $COMPARE #SU$SUC,STS,R0        ; Did it work?
  143.     BEQ    20$            ; Yes, remember that
  144.  
  145.     MOV    #DF.FAB,R0        ; No, point back at FAB
  146.     $CLOSE    R0            ; Close the file
  147.  
  148. 15$:    CLRB    DFLOPN            ; And remember file is not open
  149.     RTS    PC            ; Give up
  150.  
  151. ; Here when file is open and RAB connected.  Remember the file is ok and return
  152.  
  153. 20$:    MOVB    #1,DFLOPN        ; Flag file is open
  154.     RTS    PC            ; And return
  155.  
  156.     .SBTTL    DF.FIN - Finish out default file processing
  157.  
  158. ;++
  159. ; This routine will terminate the default file processing.  It will
  160. ;close the defaults file.
  161. ;
  162. ; Usage:
  163. ;
  164. ; Macro:
  165. ;    JSR    PC,DF.FIN
  166. ;     (return here always)
  167. ;
  168. ;--
  169.  
  170. DF.FIN::TSTB    DFLOPN        ; File open?
  171.     BEQ    99$        ; No, nothing to close
  172.     MOV    #DF.RAB,R0    ; Point at RAB
  173.     $DISCONNECT R0        ; Disconnect it
  174.     MOV    #DF.FAB,R0    ; Point at FAB
  175.     $CLOSE    R0        ; Close the file
  176. 99$:    RTS    PC        ; And return
  177.  
  178.     .SBTTL    DF.RD - Read a record from the default file
  179.  
  180. ;++
  181. ; This routine will read a record from the default file.  The record
  182. ;is identified by a 16-bit value which is expected to be in the first
  183. ;two bytes of the record.  If the record is found, we will return a
  184. ;pointer to the first byte and the length in bytes.
  185. ;
  186. ; Usage:
  187. ;
  188. ; Macro:
  189. ;
  190. ;    MOV    #record.indicator,R0
  191. ;    JSR    PC,DF.RD
  192. ;     (Return)
  193. ;
  194. ; On return:
  195. ; If record found:
  196. ;
  197. ;    R0/ Address of first byte of record (after our header info)
  198. ;    R1/ Length of record (minus header) in bytes
  199. ;
  200. ; If record not found:
  201. ;
  202. ;    R0/ 0
  203. ;    R1/ -1
  204. ;
  205. ;--
  206.  
  207.     .PSECT    $CODE$,  RO 
  208.  
  209. DF.RD::    TSTB    DFLOPN        ; File open?
  210.     BEQ    80$        ; No, just say we couldn't find the record
  211.     MOV    #DF.RAB,R1    ; Point at RAB
  212.     $REWIND    R1        ; Back up to beginning of file
  213.     $COMPARE #SU$SUC,STS,R1    ; Did it work?
  214.     BNE    80$        ; No, punt
  215.  
  216. ; Now read through the file until we find the record we want
  217.  
  218. 20$:    $GET    R1        ; Read a record
  219.     $COMPARE #SU$SUC,STS,R1    ; Get it?
  220.     BNE    80$        ; No, must have hit eof
  221.  
  222.     CMP    R0,DF.BUF    ; Is this the record we want?
  223.     BNE    20$        ; If not the right record, try the next
  224.  
  225. ; Here when we have found the correct record.  Set up the pointers to the
  226. ;users data
  227.  
  228.     MOVB    DF.BUF+.DFOFS,R0 ; Get offset to first byte of user data
  229.     ADD    #DF.BUF,R0    ; Point to it
  230.     MOVB    DF.BUF+.DFRSZ,R1 ; And get the size of the data
  231.     MOVB    #1,DFLRCR    ; Flag current record is real
  232.     RTS    PC        ; And return
  233.  
  234. ; Here if we could not find the record for some reason.  Return the error
  235. ;indication to our caller, and remember that we have no current record.
  236.  
  237. 80$:    CLRB    DFLRCR        ; No current record
  238.     CLR    R0        ; No data to return
  239.     MOV    #-1,R1        ;  .  .  .
  240.     RTS    PC        ; Let caller worry about it
  241.  
  242.     .SBTTL    DF.WT - Write a record to the default file
  243.  
  244. ;++
  245. ; This routine will write a record to the default file.  The record
  246. ;is identified by a 16-bit value which will be written as the first
  247. ;two bytes of the record.
  248. ;
  249. ; Usage:
  250. ;
  251. ; Macro:
  252. ;
  253. ;    MOV    #record.indicator,R0
  254. ;    MOV    #Record.address,R1
  255. ;    MOV    #record.size,R2
  256. ;    JSR    PC,DF.WT
  257. ;     (Return)
  258. ;
  259. ;--
  260.  
  261.     .PSECT    $CODE$,  RO 
  262.  
  263. DF.WT::    TSTB    DFLOPN        ; File open?
  264.     BEQ    99$        ; No, just return
  265.     JSR    R1,$SAVE2    ; Save R1/R2
  266.     TSTB    DFLRCR        ; Check if current record data ok
  267.     BEQ    30$        ; No, we must first find this record
  268.     CMP    R0,DF.BUF+.DFRTP ; Correct record?
  269.     BNE    30$        ; No, attempt to read it first
  270.  
  271. ; Here if last record read is the one we wish to replace.  First we must
  272. ;copy the users data into our buffer, then we will just update the current
  273. ;record in the file
  274.  
  275. 10$:    MOV    R2,DF.BUF+.DFRSZ ; Store new record size
  276.     MOVB    #.DFHLN,DF.BUF+.DFOFS ; Store offset to record data
  277.     MOV    #DF.BUF+.DFHLN,R0 ; Point at data storage
  278.  
  279. 20$:    MOVB    (R1)+,(R0)+    ; Copy the data
  280.     SOB    R2,20$        ; All of it
  281.  
  282.     MOV    #DF.RAB,R0    ; Point at the RAB
  283.     $STORE    #DF.MRS,RSZ,R0    ; Store the record size
  284.     $UPDATE    R0        ; Update the record
  285.     RTS    PC        ; And return
  286.  
  287. ; Here if the last record was not valid or was not the same as the
  288. ;record being written.  First attempt to find the correct record.  If
  289. ;we can find it, we will just update it in place, otherwise, we will
  290. ;write the new record at the end of the file.
  291.  
  292. 30$:    MOV    R0,-(SP)    ; Save the record index
  293.     MOV    R1,-(SP)    ; And the address
  294.     JSR    PC,DF.RD    ; Attempt to find the record
  295.     TST    R1        ; See if we found it
  296.     BMI    40$        ; If negative, no luck
  297.     MOV    (SP)+,R1    ; Get back the address
  298.     MOV    (SP)+,R0    ; and the type
  299.     BR    10$        ; And re-write the record
  300.  
  301. ; Here if the record did not previously exist in the file.  Write
  302. ;it out at the end of the file.  The next-record context should be EOF, since
  303. ;DF.RD will have read to the end of the file.
  304.  
  305. 40$:    MOV    (SP)+,R1    ; Restore the registers
  306.     MOV    (SP)+,R0    ;  .  .  .
  307.     MOV    R0,DF.BUF+.DFRTP ; Store the record type
  308.  
  309.     MOVB    R2,DF.BUF+.DFRSZ ; And size
  310.  
  311.     MOVB    #.DFHLN,DF.BUF+.DFOFS ; And offset to data portion
  312.     MOV    #DF.BUF+.DFHLN,R0 ; Point at first data byte
  313.  
  314. 50$:    MOVB    (R1)+,(R0)+    ; Copy the byte
  315.     SOB    R2,50$        ; All of them
  316.  
  317.     MOV    #DF.RAB,R0    ; Point at RAB
  318.     $STORE    #DF.MRS,RSZ,R0    ; Store the record size
  319.     $PUT    R0        ; Write the record
  320.  
  321. 99$:    RTS    PC        ; And return
  322.  
  323.     .SBTTL    End of KERDF
  324.  
  325.     .END
  326.