home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm86 / fmacs86.ark / FILES.A86 < prev    next >
Encoding:
Text File  |  1989-02-10  |  5.8 KB  |  276 lines

  1.     pagesize    86
  2.  
  3.     include    bufseg.a86    ;buffer definitions
  4.  
  5. data    dseg    byte public
  6.     extrn    textseg: word
  7. ;data    ends
  8.  
  9. code    cseg    byte public
  10.  
  11.     ;*** assume    cs:code, ds:data, es:data
  12.  
  13.     extrn    count_lines: near
  14.     extrn    read_mark?: near
  15.     extrn    adjust_marks_ins: near
  16.     extrn    paint_window: near
  17.     extrn    ccpm_create_file:near
  18.     extrn    ccpm_open_file:near
  19.     extrn    ccpm_close_file:near
  20.     extrn    ccpm_write_file:near
  21.     extrn    ccpm_read_file:near
  22.     extrn    ccpm_delete_file:near
  23.     extrn    ccpm_lseek_file:near
  24.  
  25.  
  26.     public    write_file
  27. write_file:
  28. ;enter with si->filename desired, al=mark.
  29. ;exit with al=0 if ok, al=1 if disk full, or al=2 if directory full.
  30.     push    si            ;save a pointer to the filename.
  31.  
  32.     push    ax            ;save the mark to write to.
  33.     mov    dx,si
  34.     mov    cx,0
  35. ;    mov    ah,3ch            ;create file.
  36. ;    int    21h
  37.     call    ccpm_create_file
  38.     pop    bx            ;get the mark back
  39.     jc    write_2_5        ;if any problem, report dir full.
  40.     xchg    bx,ax            ;put the mark in ax, handle in bx.
  41.  
  42.     push    ds
  43.     mov    ds,textseg        ;read_mark? assumes ds:textseg
  44.     push    bx
  45.     call    read_mark?
  46.     pop    bx
  47.     mov    dx,si            ;set the disk transfer address
  48. ;    mov    ah,40h            ;write out what they requested.
  49. ;    int    21h
  50.     call    ccpm_write_file
  51.     pop    ds
  52.     jc    write_2_4        ;if any problems, disk full.
  53.  
  54.     cmp    ax,cx            ;did we write the whole thing?
  55.     jne    write_2_4        ;no - disk full.
  56.  
  57. ;close the file.
  58. ;    mov    ah,3eh            ;close file.
  59. ;    int    21h
  60.     call    ccpm_close_file
  61.     jc    write_2_4        ;if any problems, say disk full.
  62.     pop    si
  63.     mov    al,0
  64.     ret
  65. write_2_4:
  66. ;    mov    ah,3eh            ;close file.
  67. ;    int    21h
  68.     call    ccpm_close_file
  69.     pop    si
  70.     mov    dx,si            ;delete their file.
  71. ;    mov    ah,41h
  72. ;    int    21h
  73.     call    ccpm_delete_file
  74.     mov    al,1
  75.     ret
  76. write_2_5:
  77.     pop    si
  78.     mov    al,2
  79.     ret
  80.  
  81.  
  82.     public    read_file
  83. read_file:
  84. ;enter with si->filename desired.
  85. ;exit with al=0 if ok, al=1 if file too large, or al=2 if file not found.
  86.     mov    dx,si
  87. ;    mov    ax,3d00h        ;open for reading.
  88. ;    int    21h
  89.     call    ccpm_open_file
  90.     jc    read_2_5
  91.     mov    bx,ax
  92.  
  93. ;    mov    ax,4202h        ;get the file's size.
  94.     mov    cx,0
  95.     mov    dx,cx
  96. ;    int    21h
  97.     mov    al,2
  98.     call    ccpm_lseek_file
  99.     mov    cx,ax            ;remember the file's size lobyte.
  100.  
  101.     push    ds
  102.     mov    ds,textseg
  103.     ;*** assume    ds:bufseg
  104.     mov    ax,bottop        ;get size of available memory.
  105.     sub    ax,topbot
  106.     pop    ds
  107.     ;*** assume    ds:data
  108.  
  109. ;check the size of the file (dx:cx) against buffer size (ax)
  110.     or    dx,dx            ;is file too big?
  111.     jne    read_2_2
  112.     cmp    ax,margin
  113.     jb    read_2_2        ;not enough memory.
  114.     sub    ax,margin
  115.     cmp    ax,cx            ;enough memory to read the file in?
  116.     jb    read_2_2        ;no.
  117.  
  118. ;if the file's empty, don't try to read it in.
  119.     jcxz    read_2_7
  120.  
  121. ;seek to the beginning again.
  122.  
  123.     push    cx
  124. ;    mov    ax,4200h        ;rewind the file.
  125.     mov    cx,0
  126.     mov    dx,cx
  127. ;    int    21h
  128.     mov    al,0
  129.     call    ccpm_lseek_file
  130.     pop    cx
  131.  
  132. ;read the file in.
  133.  
  134.     push    ds
  135.     mov    ds,textseg
  136.     ;*** assume    ds:bufseg
  137.     mov    dx,topbot        ;read the file before the cursor.
  138. ;    mov    ah,3fh
  139. ;    int    21h
  140.     call    ccpm_read_file
  141.     pop    ds
  142.     ;*** assume    ds:data
  143.     jc    read_2_4        ;problem with read - give up.
  144.  
  145.     cmp    cx,ax            ;compare the amount desired again the amount read.
  146.     pushf
  147.     mov    cx,ax            ;adjust for the amount read.
  148.     push    bx            ;preserve the file handle.
  149.     call    read_adjust
  150.     pop    bx
  151.     popf
  152.     jnz    read_2_4        ;if any not read, give up.
  153.  
  154.  
  155. ;close the file.
  156. read_2_7:
  157. ;    mov    ah,3eh            ;close the file.
  158. ;    int    21h
  159.     call    ccpm_close_file
  160.     jc    read_2_4        ;if any trouble, give up.
  161.     mov    al,0
  162.     jmps read_2_exit
  163. read_2_2:
  164.     mov    al,1            ;not enough memory.
  165.     jmps read_2_exit
  166. read_2_4:
  167. ;    mov    ah,3eh            ;close the file.
  168. ;    int    21h
  169.     call    ccpm_close_file
  170.     mov    al,3            ;other read error.
  171.     jmps read_2_exit
  172. read_2_5:
  173.     mov    al,2            ;file not found.
  174. read_2_exit:
  175.     ret
  176.  
  177.  
  178. read_adjust:
  179. ;update topbot, line counters.
  180.     push    cx            ;save count
  181.     mov    ds,textseg
  182.     ;*** assume    ds:bufseg
  183.     mov    ax,cx
  184.     call    adjust_marks_ins
  185.     mov    di,topbot
  186.     push    es
  187.     pop    ds
  188.     ;*** assume    ds:data
  189.     pop    cx            ;get the count back.
  190.     push    cx
  191.     call    count_lines        ;count NEWLINES in text we just read in.
  192.     mov    ds,textseg
  193.     ;*** assume    ds:bufseg
  194.     add    linesbefore,bx        ;the text is before the cursor, so add
  195.     add    linecount,bx
  196.     mov    buffer_modified,1
  197.     pop    cx            ;restore count
  198.     add    topbot,cx        ;add the amount of file that was read in.
  199.     push    es
  200.     pop    ds
  201.     ;*** assume    ds:data
  202.     call    paint_window
  203.     ret
  204.  
  205.  
  206.     public    compute_free
  207. compute_free:
  208. ;enter with dl=drive.
  209. ;exit with cy if invalid drive, or nc and:
  210. ;  ax=sectors/cluster,        ====================================
  211. ;  bx=free clusters,        >>>> must be changed under CCPM <<<<
  212. ;  cx=bytes/sector,        ====================================
  213. ;  dx=total clusters.
  214.     mov    dx,7fffh
  215.     mov    cx,128        ;>>>> temp. solution <<<<
  216.     mov    bx,7fffh
  217.     mov    ax,16
  218.     clc
  219.     ret
  220. ;*****************************
  221. ;**    mov    ah,30h            ;get the version number
  222. ;**    int    21h
  223. ;**    cmp    al,2            ;al<2 for versions 1.?
  224. ;**    jb    compute_free_5
  225. ;**    mov    ah,36h            ;get disk stats for version 2.0+
  226. ;**    int    21h            ;dl already set
  227. ;**    cmp    ax,-1            ;valid drive?
  228. ;**    jne    compute_free_4        ;yes.
  229. ;**    push    ds
  230. ;**compute_free_6:
  231. ;**    pop    ds
  232. ;**    stc
  233. ;**    ret
  234. ;**compute_free_5:
  235. ;**    push    ds
  236. ;**    mov    ah,1ch            ;get the fat.
  237. ;**    int    21h
  238. ;**    or    bx,bx
  239. ;**    je    compute_free_6
  240. ;**    mov    ah,0
  241. ;**    push    ax            ;save the sectors/cluster
  242. ;**    push    cx            ;save the bytes/sector
  243. ;**    mov    cx,dx            ;we need the count in cx.
  244. ;**    xor    ax,ax            ;start with no free clusters.
  245. ;**    mov    si,2            ;start at the first cluster.
  246. ;**compute_free_1:
  247. ;**    mov    di,si
  248. ;**    shr    di,1
  249. ;**    add    di,si
  250. ;**    mov    di,[bx+di]
  251. ;**    test    si,001
  252. ;**    jz    compute_free_2
  253. ;**    shr    di,1
  254. ;**    shr    di,1
  255. ;**    shr    di,1
  256. ;**    shr    di,1
  257. ;**compute_free_2:
  258. ;**    and    di,0fffh        ;seperate out the bits.
  259. ;**    jnz    compute_free_3        ;free? no.
  260. ;**    inc    ax            ;count a free cluster.
  261. ;**compute_free_3:
  262. ;**    inc    si            ;go to the next.
  263. ;**    loop    compute_free_1        ;until we've looked at them all.
  264. ;**    mov    bx,ax            ;save the free clusters in bx.
  265. ;**    pop    cx            ;restore bytes/sector
  266. ;**    pop    ax            ;restore sectors/cluster.
  267. ;**    pop    ds
  268. ;**compute_free_4:
  269. ;**    clc
  270. ;**    ret
  271.  
  272. ;code    ends
  273.  
  274.     end
  275.  
  276.