home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / misc / bcpl.ark / RAND.B < prev    next >
Encoding:
Text File  |  1988-11-27  |  1.9 KB  |  75 lines

  1. // Random file IO package for CPM BCPL
  2.  
  3. section "RANDOMIO"
  4.  
  5. get "libhdr"
  6. get "randhdr"
  7.  
  8. manifest // bdos functions
  9. $( del=19; open=15; close=16; make=22
  10. readrand=33; writerand=34; filesize=35; setdma=26 $)
  11.  
  12. manifest // fcb offsets
  13. $( fcbsize=18
  14.    ex=12; s1=13; s2=14; rc=15; cr=32; r0=33; r1=34; r2=35 $)
  15.  
  16. let createblockfile(file) = valof
  17. $( let fcb = getvec(fcbsize)
  18.    if fcb=0 resultis 0
  19.    parse(file, fcb) // build the fcb
  20.    fcb%ex := 0
  21.    fcb%s1 := 0
  22.    fcb%s2 := 0
  23.    fcb%rc := 0
  24.    fcb%cr := 0
  25.    bdos(del, fcb*bytesperword) // delete possible pre-existing file
  26.    test (#xff & bdos(make, fcb*bytesperword)) = #xff // and make it
  27.          then $( freevec(fcb)     // failed
  28.                  resultis 0
  29.               $)
  30.          else resultis fcb
  31. $)
  32.  
  33. let updateblockfile(file) = valof
  34. $( let fcb = getvec(fcbsize)
  35.    if fcb=0 resultis 0
  36.    parse(file, fcb) // build the fcb
  37.    fcb%ex := 0
  38.    fcb%s1 := 0
  39.    fcb%s2 := 0
  40.    fcb%rc := 0
  41.    fcb%cr := 0
  42.    test (#xff & bdos(open, fcb*bytesperword)) = #xff // and open it
  43.          then $( freevec(fcb)
  44.                  resultis 0       // failed
  45.               $)
  46.          else resultis fcb
  47. $)
  48.  
  49. let closeblockfile(fcb) = valof
  50. $( let r = (#xff & bdos(close, fcb*bytesperword)) ~= #xff
  51.    freevec(fcb)
  52.    resultis r
  53. $)
  54.  
  55. let readblock(fcb, buff, rec) = valof
  56. $( bdos(setdma, buff*bytesperword)
  57.    fcb%r2 := 0
  58.    fcb%r1 := rec>>8
  59.    fcb%r0 := rec
  60.    resultis #xff & bdos(readrand, fcb*bytesperword)
  61. $)
  62.  
  63. let writeblock(fcb, buff, rec) = valof
  64. $( bdos(setdma, buff*bytesperword)
  65.    fcb%r2 := 0
  66.    fcb%r1 := rec>>8
  67.    fcb%r0 := rec
  68.    resultis #xff & bdos(writerand, fcb*bytesperword)
  69. $)
  70.  
  71. let blockfilesize(fcb) = valof
  72. $( bdos(filesize, fcb*bytesperword)
  73.    resultis (fcb%r0)+((fcb%r1)<<8)
  74. $)
  75.