home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / os2ntree.zip / DOSCALLS.ASM next >
Assembly Source File  |  1988-03-01  |  9KB  |  434 lines

  1.         NAME    DOSCALLS
  2.         TITLE    DOSCALLS
  3.  
  4.         PAGE    60,132
  5. ;
  6. ; This is coded for Microsoft C. The small memory model
  7. ; (for both _code and _data) are assumed. This is easily changed.
  8. ; This is for DOSNTREE.C
  9.  
  10. _data        SEGMENT    WORD PUBLIC 'data'
  11. dgroup        GROUP    _data
  12.  
  13. _data        ENDS
  14.  
  15.  
  16. _text        SEGMENT    BYTE PUBLIC 'code'
  17. igroup        GROUP    _text
  18.         ASSUME    CS:igroup,DS:dgroup
  19.  
  20.  
  21. ;   +-------------------------------------------------------------------+
  22. ;   |  dosfindfirst(filename,attribute)                    |
  23. ;   |  find first matching file                        |
  24. ;   +-------------------------------------------------------------------+
  25.  
  26.         public    _dosfindfirst
  27.  
  28. _dosfindfirst    proc near
  29.  
  30.         push    bp
  31.         mov    bp,sp
  32.  
  33.         mov    dx,[bp+4]        ; get filename string
  34.         mov    cx,[bp+6]        ; get attribute
  35.         mov    ah,4EH            ; find first file
  36.  
  37.         int    21h            ; call DOS
  38.  
  39.         jc    error_ret1        ; error return
  40.         xor    ax,ax            ; return 0 if OK
  41. error_ret1:    clc
  42.  
  43.         pop    bp
  44.         ret
  45.  
  46. _dosfindfirst    endp
  47.  
  48.  
  49. ;   +-------------------------------------------------------------------+
  50. ;   |  dosfindnext()                            |
  51. ;   |  returns next matching file                    |
  52. ;   +-------------------------------------------------------------------+
  53.  
  54.         public    _dosfindnext
  55.  
  56. _dosfindnext    proc near
  57.  
  58.         push    bp
  59.         mov    bp,sp
  60.  
  61.         mov    ah,4FH            ; find next file
  62.         int    21h            ; call DOS
  63.  
  64.         jc    error_ret2        ; return error
  65.         xor    ax,ax
  66. error_ret2:    clc
  67.  
  68.         pop    bp
  69.         ret
  70.  
  71. _dosfindnext    endp
  72.  
  73.  
  74. ;   +-------------------------------------------------------------------+
  75. ;   |  dossetdta(dta)                            |
  76. ;   |  set DTA to new location                        |
  77. ;   +-------------------------------------------------------------------+
  78.  
  79.         public    _dossetdta
  80.  
  81. _dossetdta    proc near
  82.  
  83.         push    bp
  84.         mov    bp,sp
  85.  
  86.  
  87.         mov    ah,2FH            ; get current DTA
  88.         int    21h
  89.         push    bx            ; save (we assume our DS)
  90.  
  91.         mov    dx,[bp+4]        ; get dta loc
  92.         mov    ah,1AH            ; set DTA
  93.         int    21h
  94.  
  95.         pop    ax            ; restore DTA
  96.  
  97.         pop    bp
  98.         ret
  99.  
  100. _dossetdta    endp
  101.  
  102.  
  103. ;   +-------------------------------------------------------------------+
  104. ;   |  curdrive()                            |
  105. ;   |  Returns current disk drive                    |
  106. ;   +-------------------------------------------------------------------+
  107.  
  108.         public    _curdrive
  109.  
  110. _curdrive    proc near
  111.  
  112.         push    bp
  113.         mov    bp,sp
  114.  
  115.         mov    ah,19h
  116.         int    21h
  117.         mov    ah,0
  118.         inc    al
  119.  
  120.         pop    bp
  121.         ret
  122.  
  123. _curdrive    endp
  124.  
  125.  
  126.  
  127. ;   +-------------------------------------------------------------------+
  128. ;   |  getdir(drive,buf)                        |
  129. ;   |  gets directory of specified drive into buffer            |
  130. ;   +-------------------------------------------------------------------+
  131.  
  132.         public    _getdir
  133.  
  134. _getdir        proc near
  135.  
  136.         push    bp
  137.         mov    bp,sp
  138.         push    si
  139.  
  140.         mov    dx,[bp+4]
  141.         mov    si,[bp+6]
  142.         add    si,3
  143.         mov    ah,47h
  144.         int    21h
  145.         jc    getdir_err
  146.         mov    ax,[bp+4]
  147.         add    al,'@'
  148.         mov    si,[bp+6]
  149.         mov    byte ptr ds:[si],al
  150.         inc    si
  151.         mov    byte ptr ds:[si],':'
  152.         inc    si
  153.         mov    byte ptr ds:[si],'\'
  154.         xor    ax,ax
  155. getdir_err:    clc
  156.         pop    si
  157.         pop    bp
  158.         ret
  159.  
  160. _getdir        endp
  161.  
  162.  
  163. ;   +-------------------------------------------------------------------+
  164. ;   |  changedir(dir)                            |
  165. ;   |  changes drive and directory                    |
  166. ;   +-------------------------------------------------------------------+
  167.  
  168.         public    _changedir
  169.  
  170. _changedir    proc near
  171.  
  172.         push    bp
  173.         mov    bp,sp
  174.  
  175.         mov    dx,[bp+4]
  176.         mov    ah,3BH
  177.         int    21h
  178.         jc    chdir_err
  179.  
  180.         mov    bx,[bp+4]
  181.         cmp    byte ptr [bx+1],':'    ; drive letter there?
  182.         je    drv_let            ; yes. change drive too
  183.  
  184.         xor    ax,ax
  185. chdir_exit:    pop    bp
  186.         ret
  187.  
  188. drv_let:    mov    dl,byte ptr [bx]
  189.         sub    dl,'A'
  190.         mov    ah,0EH            ; select disk
  191.         int    21h
  192.         xor    ax,ax
  193.         jmp    short chdir_exit
  194.  
  195. chdir_err:    clc
  196.         jmp    chdir_exit
  197.  
  198. _changedir    endp
  199.  
  200.  
  201. ;   +-------------------------------------------------------------------+
  202. ;   |  docopyfile(from,to)                        |
  203. ;   |  copy file from from to to                    |
  204. ;   |  errors returned:                            |
  205. ;   |     1: error opening source file                    |
  206. ;   |     2: error opening dest file                    |
  207. ;   |     3: error reading source file                    |
  208. ;   |     4: error writing dest file                    |
  209. ;   |     5: error allocating memory                    |
  210. ;   +-------------------------------------------------------------------+
  211.  
  212.         public    _docopyfile
  213.  
  214. _docopyfile    proc near
  215.  
  216.         push    bp
  217.         mov    bp,sp
  218.         push    ds
  219.         cmp    cs:alloced,0
  220.         jne    do_it_now        ; all set to go
  221.  
  222.         mov    ah,48h            ; request memory
  223.         mov    bx,1000h        ; 64K of memory
  224.         mov    cs:msize,bx        ; save size
  225.         int    21h            ; can we get it?
  226.         mov    dx,0FFFFH        ; this many usable
  227.         jnc    got_mem
  228.         mov    cs:msize,bx        ; save size
  229.         push    bx            ; save amt read
  230.         mov    ah,48h
  231.         int    21h            ; get memory
  232.         jnc    alloc_mem_ok        ; couldn't do it.
  233.         jmp    alloc_mem_err
  234. alloc_mem_ok:    pop    dx
  235.         mov    cl,4    
  236.         shl    dx,cl            ; make bytes
  237.  
  238. got_mem:    mov    cs:msize,dx        ; save memory size
  239.         mov    cs:mstart,ax        ; save memory
  240.         mov    cs:alloced,1        ; set flag
  241.  
  242. do_it_now:
  243.         mov    dx,[bp+4]        ; get name
  244.         mov    ah,3dh            ; open file
  245.         mov    al,0            ; read mode
  246.         int    21h            ; try to open
  247.         jnc    open_src_ok        ; error opening source
  248.         jmp    open_src_err
  249. open_src_ok:    mov    cs:inhandle,ax        ; save handle
  250.  
  251.         mov    dx,[bp+6]        ; get out name
  252.         mov    cx,0            ; normal file
  253.         mov    ah,3ch            ; create file
  254.         int    21h            ; do it.
  255.         jc    open_dst_err        ; error opening dest
  256.         mov    cs:outhandle,ax        ; save handle.
  257.  
  258. ; copy data in file
  259.         mov    ax,word ptr cs:mstart    ; get segment ptr
  260.         mov    ds,ax
  261. copy_loop:    mov    ah,3Fh            ; read file
  262.         mov    bx,cs:inhandle        ; this one
  263.         mov    cx,cs:msize        ; this much
  264.         mov    dx,0
  265.         int    21h            ; do it.
  266.         jc    read_src_err        ; if errors...
  267.         cmp    ax,0            ; at end of file?
  268.         je    at_eof            ; yup.
  269.         push    ax
  270.         mov    cx,ax            ; prepare to write
  271.         mov    bx,cs:outhandle        ; output
  272.         mov    ah,40H            ; write to file
  273.         mov    dx,0
  274.         int    21h            ; do it.
  275.         pop    bx
  276.         jc    write_dst_err        ; couldn't write
  277.         cmp    ax,bx            ; wrote the same amt read?
  278.         jne    write_dst_err
  279.         jmp    copy_loop
  280.  
  281. at_eof:
  282. ; copy creation date
  283.         mov    bx,cs:inhandle
  284.         mov    ah,57h            ; get/set time
  285.         mov    al,0            ; get time
  286.         int    21h            ; get files time
  287.         jc    read_src_err
  288.         mov    ah,57h            ; get/set
  289.         mov    al,1            ; set
  290.         mov    bx,cs:outhandle        ; handle
  291.         int    21h            ; set time
  292.         jc    write_dst_err        ; errors...
  293.  
  294. ; close files
  295.  
  296.         mov    ah,3eh            ; close
  297.         mov    bx,cs:inhandle
  298.         int    21h
  299.         jc    read_src_err        ; error reading
  300.         mov    ah,3eh            ; close
  301.         mov    bx,cs:outhandle
  302.         int    21h
  303.         jc    write_dst_err
  304.  
  305.         mov    ax,0
  306.  
  307. copy_exit:    pop    ds
  308.         clc
  309.         pop    bp
  310.         ret
  311.  
  312.  
  313. open_src_err:    mov    ax,1
  314.         jmp    short copy_exit
  315. open_dst_err:    mov    ax,2
  316.         jmp    short copy_exit
  317. read_src_err:    mov    ax,3
  318.         jmp    short copy_exit
  319. write_dst_err:    mov    ax,4
  320.         jmp    short copy_exit
  321. alloc_mem_err:    mov    ax,5
  322.         jmp    short copy_exit
  323.  
  324. alloced        dw    0        ; have we alloced yet?
  325. mstart        dw    0        ; starting segment
  326. msize        dw    0        ; segment size (bytes)
  327. inhandle    dw    0        ; in file handle
  328. outhandle    dw    0        ; out file handle
  329.  
  330. _docopyfile    endp
  331.  
  332.  
  333. ;   +-------------------------------------------------------------------+
  334. ;   |  setverify(flg)                            |
  335. ;   |  sets verify flag                            |
  336. ;   +-------------------------------------------------------------------+
  337.  
  338.         public    _setverify
  339.  
  340. _setverify    proc near
  341.  
  342.         push    bp
  343.         mov    bp,sp
  344.  
  345.         mov    ax,[bp+4]
  346.         mov    ah,2EH
  347.         int    21h
  348.  
  349.         pop    bp
  350.         ret
  351.  
  352. _setverify    endp
  353.  
  354.  
  355. ;   +-------------------------------------------------------------------+
  356. ;   |  getverify()                            |
  357. ;   |  Return verify flag                        |
  358. ;   +-------------------------------------------------------------------+
  359.  
  360.         public    _getverify
  361.  
  362. _getverify    proc near
  363.  
  364.         push    bp
  365.         mov    bp,sp
  366.  
  367.         mov    ah,54h
  368.         int    21h
  369.         mov    ah,0
  370.  
  371.         pop    bp
  372.         ret
  373.  
  374. _getverify    endp
  375.  
  376.  
  377. ;   +-------------------------------------------------------------------+
  378. ;   |  doschmod(name,attr)                        |
  379. ;   |  change file mode                            |
  380. ;   +-------------------------------------------------------------------+
  381.  
  382.         public    _doschmod
  383.  
  384. _doschmod    proc near
  385.  
  386.         push    bp
  387.         mov    bp,sp
  388.  
  389.         mov    dx,[bp+4]
  390.         mov    cx,[bp+6]
  391.  
  392.         mov    ah,43h
  393.         int    21h
  394.         jc    dc_err
  395.         xor    ax,ax
  396. dc_err:        clc
  397.         pop    bp
  398.         ret
  399. _doschmod    endp
  400.  
  401.  
  402. ;   +-------------------------------------------------------------------+
  403. ;   |  clussize(drive)                            |
  404. ;   |  returns size of cluster in bytes                    |
  405. ;   +-------------------------------------------------------------------+
  406.  
  407.         public    _clussize
  408.  
  409. _clussize    proc near
  410.  
  411.         push    bp
  412.         mov    bp,sp
  413.  
  414.         push    ds
  415.         mov    dx,[bp+4]    ; get drive
  416.         mov    ah,1ch
  417.         int    21h        ; get table info
  418.         pop    ds
  419.  
  420.         mov    bx,ax        ; save sec/alloc unit
  421.         mov    bh,0        ; zap hi part
  422.         mov    ax,cx        ; get sec size
  423.         mul    bx        ; dxax = alloc unit size
  424.         mov    dx,0        ; will be 0 anyways...
  425.  
  426.         pop    bp
  427.         ret
  428.  
  429. _clussize    endp
  430.  
  431. _text        ENDS
  432.         END
  433.  
  434.