home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / DOS2FUN.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  9.8 KB  |  457 lines

  1.         page    58,132
  2.  
  3. ; dos2fun.asm
  4. ; contains: dos2append(),dos2create(),dos2delete(),dos2open(),dos2close(),
  5. ; contains: dos2read(),dos2write(),dosrename(),dosseek(),
  6. ;
  7.  
  8.         include    model.h
  9.         include    prologue.h
  10.         include equ.h
  11.  
  12.         name    dos2fun
  13.         pseg    dos2appe
  14.  
  15. ;==>--    long dos2append(table)
  16. ;
  17. ;;    ARGUMENTS:
  18. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  19. ;
  20. ;;    DESCRIPTION:
  21. ;      The file pointer is moved to the end of the file plus one byte
  22. ;      such that subsequent write operations will append the file.  The
  23. ;      file size may be determined by checking the return value.
  24. ;
  25. ;;    RETURNS:
  26. ;      0 == Error, else long integer location of file pointer following
  27. ;      the seek.
  28. ;
  29. ;;    AUTHOR:
  30. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  31. ;;;
  32.     cproc    dos2append,,dos2appe
  33.     if    _LDATA
  34.      push    ds
  35.      lds    si,parm1_
  36.     else
  37.      mov    si,parm1_
  38.     endif
  39.     mov    bx,[si+handle]        ;get handle to BX
  40.     xor    cx,cx            ;hi-order offset = 0
  41.     xor    dx,dx            ;lo-order offset
  42.     mov    ax,4202h        ;lseek EOF + (CX:DX)
  43.     int    21h
  44.     jc    dos2a2            ;if error, leave now
  45.     mov    [si+fcbrec],ax        ;hi-order part
  46.     mov    [si+_fcbr2],dx        ;lo-order
  47.     ifdef    AXBX32
  48.      mov    bx,ax
  49.      mov    ax,dx
  50.     endif
  51.     jmp    short dos2xit
  52. dos2a2:    xor    ax,ax            ;indicate error to user
  53.     ifdef    AXBX32
  54.      mov    bx,ax
  55.     else
  56.      mov    dx,ax
  57.     endif
  58. dos2xit:
  59.     if    _LDATA
  60.      pop    ds
  61.     endif
  62.     cproce
  63.  
  64. ;==>--    int dos2create(table)
  65. ;
  66. ;;    ARGUMENTS:
  67. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  68. ;
  69. ;;    DESCRIPTION:
  70. ;      Create a file, table->string must point to a string with drive,path
  71. ;      and filename.  table->dskfcb.dskattr.dattr.xxx must contain
  72. ;      the attribute(s) to set.
  73. ;
  74. ;;    RETURNS:
  75. ;      file handle or -1 if error.
  76. ;
  77. ;;    AUTHOR:
  78. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  79. ;
  80. ;;    MODIFICATIONS:
  81. ;
  82. ;;;
  83.     cproc    dos2create,,dos2crea
  84.     if    _LDATA
  85.      push    ds
  86.      lds    si,parm1_        ;ds:si points to table
  87.     else
  88.      mov    si,parm1_        ;ds:si points to table
  89.     endif
  90.     mov    cl,[si+fattr]
  91.     xor    ch,ch            ;cx = attribute
  92.     if    _LDATA
  93.      push    ds
  94.      lds    dx,[si+string]        ;ds:dx = filename
  95.     else
  96.      mov    dx,[si+string]        ;ds:dx = filename
  97.     endif
  98.     mov    ah,3ch            ;dos file create function
  99.     int    21h
  100.     if    _LDATA
  101.      pop    ds
  102.     endif
  103.     jnc    d2cre2            ;hop if no error
  104.     mov    [si+status],ax        ;error to status word
  105.     mov    ax,-1            ;error so return -1
  106.     jmp    short d2crexit
  107. d2cre2:    mov    [si+handle],ax        ;save file handle.
  108.     mov    [si+status],0        ;set status to 0
  109. d2crexit:
  110.     if    _LDATA
  111.      pop    ds
  112.     endif
  113.     cproce
  114.  
  115. ;==>--    unsigned dos2delete(table)
  116. ;
  117. ;;    ARGUMENTS:
  118. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  119. ;
  120. ;;    DESCRIPTION:
  121. ;      Deletes file specified in table->string
  122. ;
  123. ;;    RETURNS:
  124. ;      1 if successful, 0 if unsuccessful
  125. ;    
  126. ;;    AUTHOR:
  127. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  128. ;;;
  129.     cproc    dos2delete,,dos2dele
  130.     if    _LDATA
  131.      push    ds
  132.      lds    bx,parm1_        ;ds:bx points to DISKTABLE
  133.      push    ds
  134.      lds    dx,[bx+string]        ;ds:dx points to string
  135.     else
  136.      mov    bx,parm1_        ;ds:bx points to DISKTABLE
  137.      mov    dx,[bx+string]        ;ds:dx points to string
  138.     endif
  139.     mov    ah,41h            ;function to delete
  140.     int    21h
  141.     if    _LDATA
  142.      pop    ds
  143.     endif
  144.     jnc    d2del2            ;hop no error
  145.     mov    [bx+status],ax        ;indicate error code
  146.     xor    ax,ax
  147.     jmp    short d2delxit
  148. d2del2:
  149.     mov    [bx+status],0
  150.     mov    ax,1            ;indicate success
  151. d2delxit:
  152.     if    _LDATA
  153.      pop    ds
  154.     endif
  155.     cproce
  156.  
  157. ;==>--    int dos2open(table,mode)
  158. ;
  159. ;;    ARGUMENTS:
  160. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  161. ;      (int)            mode    -    open mode:
  162. ;                        0=Read,1=Write,2=Read/Write
  163. ;
  164. ;;    DESCRIPTION:
  165. ;      Open file, a drive,path and file name are specified by
  166. ;      table->string.  The mode parameter specifies the file mode.
  167. ;
  168. ;;    RETURNS:
  169. ;      dos file handle or -1 if error
  170. ;
  171. ;;    AUTHOR:
  172. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  173. ;
  174. ;;    MODIFICATIONS:
  175. ;
  176. ;;;
  177.     cproc    dos2open
  178.     if    _LDATA
  179.      push    ds
  180.      lds    si,parm1_        ;ds:si=structure
  181.      push    ds
  182.      lds    dx,[si+string]        ;ds:dx point to filename
  183.      mov    al,parm3_        ;al = mode
  184.      mov    ah,3dh            ;open a file function
  185.      int    21h
  186.      pop    ds            ;ds:si point to structure
  187.     else
  188.      mov    si,parm1_        ;ds:si=structure
  189.      mov    dx,[si+string]        ;ds:dx point to filename
  190.      mov    al,parm2_        ;al=mode
  191.      mov    ah,3dh
  192.      int    21h
  193.     endif
  194.     jnc    d2opn2            ;if no error AX=file handle
  195.     mov    [si+status],ax        ;else save error code
  196.     mov    ax,-1            ;indicate error
  197.     jmp     short    d2opex
  198. d2opn2:    mov    [si+handle],ax        ;save handle in structure
  199.     mov    [si+status],0        ;zero status byte
  200. d2opex:
  201.     if    _LDATA
  202.      pop    ds
  203.     endif
  204.     cproce
  205.  
  206. ;==>--    int dos2close(table)
  207. ;
  208. ;;    ARGUMENTS:
  209. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  210. ;
  211. ;;    DESCRIPTION:
  212. ;      Close file, use handle stored in DISKTABLE
  213. ;
  214. ;;    RETURNS:
  215. ;      1=success, 0=error, error code in table->status
  216. ;
  217. ;;    AUTHOR:
  218. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  219. ;;;
  220.     cproc    dos2close,,dos2clos
  221.     if    _LDATA
  222.      push    ds
  223.      lds    si,parm1_        ;DS:SI -> struc
  224.     else
  225.      mov    si,parm1_
  226.     endif
  227.     mov    bx,[si+handle]        ;get handle to close
  228.     mov    ah,3Eh
  229.     int    21h
  230.     jnc    d2clo2            ;hop no error
  231.     mov    [si+status],ax        ;else store status
  232.     xor    ax,ax            ;indicate error
  233.     jmp     short    d2cloxit
  234. d2clo2:    mov    [si+status],0
  235.     mov    ax,1            ;indicate success
  236. d2cloxit:
  237.     if    _LDATA
  238.      pop    ds
  239.     endif
  240.     cproce
  241.  
  242. ;==>--    unsigned dos2read(table)
  243. ;
  244. ;;    ARGUMENTS:
  245. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  246. ;
  247. ;;    DESCRIPTION:
  248. ;      Write to file, table->handle - handle to use, table->rbytes -
  249. ;      number of bytes to read, table->buffer points to address
  250. ;      to read to.
  251. ;
  252. ;;    RETURNS:
  253. ;      Number of bytes read, if 0 an error code is placed in
  254. ;      table->status.
  255. ;
  256. ;;    AUTHOR:
  257. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  258. ;
  259. ;;    MODIFICATIONS:
  260. ;
  261. ;;;
  262.     cproc    dos2read
  263.     if    _LDATA
  264.      push    ds
  265.      lds    si,parm1_        ;ds:si points to parameter
  266.     else
  267.      mov    si,parm1_        ;ds:si points to parameter
  268.     endif
  269.     mov    [si+abytes],0
  270.     mov    [si+status],0
  271.     mov    bx,[si+handle]        ;ax=files handle
  272.     mov    cx,[si+rbytes]        ;cx=number of bytes
  273.     if    _LDATA
  274.      push    ds        
  275.      lds    dx,[si+buffer]        ;ds:dx points to buffer
  276.     else
  277.      mov    dx,[si+buffer]        ;ds:dx points to buffer
  278.     endif
  279.     mov    ah,3fh            ;3f=read function
  280.     int    21h            ;call ms. dos
  281.     if    _LDATA
  282.      pop    ds            ;ds:si points to parameter
  283.     endif
  284.     jnc    rdok
  285.     mov    [si+status],ax
  286.     xor    ax,ax            ;indicate 0 bytes
  287.     jmp     short    rdex            ;and exit
  288. rdok:    mov    [si+abytes],ax        ;store number of bytes read
  289. rdex:
  290.     if    _LDATA
  291.      pop    ds
  292.     endif
  293.     cproce
  294.  
  295. ;==>--    unsigned dos2write(table)
  296. ;
  297. ;;    ARGUMENTS:
  298. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  299. ;
  300. ;;    DESCRIPTION:
  301. ;      Read from file, table->handle - handle to use, table->rbytes -
  302. ;      number of bytes to write, table->buffer points to address
  303. ;      to write from.
  304. ;
  305. ;;    RETURNS:
  306. ;      Number of bytes written, if 0 an error code is placed in
  307. ;      table->status.
  308. ;
  309. ;;    AUTHOR:
  310. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  311. ;
  312. ;;    MODIFICATIONS:
  313. ;
  314. ;;;
  315.     cproc    dos2write,,dos2writ
  316.     if    _LDATA
  317.      push    ds
  318.      lds    si,parm1_        ;ds:si points to parameter
  319.     else
  320.      mov    si,parm1_        ;ds:si points to parameter
  321.     endif
  322.     mov    [si+abytes],0
  323.     mov    [si+status],0
  324.     mov    bx,[si+handle]        ;bx=files handle
  325.     mov    cx,[si+rbytes]        ;cx=number of bytes
  326.     if    _LDATA
  327.      push    ds        
  328.      lds    dx,[si+buffer]        ;ds:dx points to buffer
  329.     else
  330.      mov    dx,[si+buffer]        ;ds:dx points to buffer
  331.     endif
  332.     mov    ah,40h            ;40=write function
  333.     int    21h            ;call ms. dos
  334.     if    _LDATA
  335.      pop    ds            ;ds:si points to parameter
  336.     endif
  337.     jnc    wtok
  338.     mov    [si+status],ax
  339.     xor    ax,ax            ;indicate 0 bytes
  340.     jmp     short    wtex            ;and exit
  341. wtok:    mov    [si+abytes],ax        ;store number of bytes read
  342. wtex:
  343.     if    _LDATA
  344.      pop    ds
  345.     endif
  346.     cproce
  347.  
  348.  
  349. ;==>--    int dosrename(from,to)
  350. ;
  351. ;;    ARGUMENTS:
  352. ;      (char *)    from    -    Existing filename
  353. ;      (char *)    to    -    New filename
  354. ;
  355. ;;    DESCRIPTION:
  356. ;      Rename file
  357. ;
  358. ;;    RETURNS:
  359. ;      0 if successful, else dos error code
  360. ;
  361. ;;    AUTHOR:
  362. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  363. ;;;
  364.     cproc    dosrename,,dosrenam
  365.     mov    ah,30h            ;get DOS version
  366.     int    21h
  367.     cmp    al,0
  368.     mov    ax,-1
  369.     jz    dosrenxit
  370.     if    _LDATA
  371.      push    ds
  372.      push    es
  373.      lds    dx,parm1_        ;ds:dx points to existing name
  374.      les    di,parm3_        ;es:di points to new name
  375.     else
  376.      push    es
  377.      mov    ax,ds
  378.      mov    es,ax            ;es==ds
  379.      mov    dx,parm1_        ;ds:dx points to existing name
  380.      mov    di,parm2_        ;es:di points to new name
  381.     endif
  382.     mov    ah,56h            ; function number in AH
  383.     int    21h
  384.     if    _LDATA
  385.      pop    es
  386.      pop    ds
  387.     else
  388.      pop    es
  389.     endif
  390.     jc    dosrenxit        ;if error return value
  391.     xor    ax,ax            ;else indicate success with 0
  392. dosrenxit:                ;Return 0
  393.     cproce
  394.  
  395. ;==>--    long dosseek(table,offset,mode)
  396. ;
  397. ;;    ARGUMENTS:
  398. ;      (struct DISKTABLE *)    table    -    points to DISKTABLE
  399. ;      (long)        offset    -    offset to seek
  400. ;      (int)            mode    -    seek mode:
  401. ;                        0=move pointer to offset bytes
  402. ;                          from the beginning of the
  403. ;                          file.
  404. ;                        1=move to current offset plus
  405. ;                          offset bytes.
  406. ;                        2=move to end of file plus
  407. ;                          offset bytes.
  408. ;
  409. ;;    DESCRIPTION:
  410. ;      Seek (Move file pointer)
  411. ;
  412. ;;    RETURNS:
  413. ;      New location of file pointer in bytes.  If unsuccessful, returns
  414. ;      (long) -1, with error code in tbl->status.
  415. ;
  416. ;;    AUTHOR:
  417. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  418. ;;;
  419.     cproc    dosseek
  420.     if    _LDATA
  421.      push    ds
  422.      lds    bx,parm1_        ;ds:bx points to DISKTABLE
  423.      mov    dx,parm3_        ;dx = low order part of offset
  424.      mov    cx,parm4_        ;cx = high order part of offset
  425.      mov    al,parm5_        ;al = mode
  426.     else
  427.      mov    bx,parm1_        ;ds:bx points to DISKTABLE
  428.      mov    dx,parm2_        ;dx = low order part of offset
  429.      mov    cx,parm3_        ;cx = high order part of offset
  430.      mov    al,parm4_        ;al = mode
  431.     endif
  432.     push    bx
  433.     mov    bx,[bx+handle]        ;bx=handle
  434.     mov    ah,42h
  435.     int    21h
  436.     pop    bx
  437.     jc    seeker
  438.     mov    [bx+status],0
  439.     mov    [bx+fcbrec],dx        ;new offset
  440.     mov    [bx+_fcbr2],ax
  441.     ifdef    AXBX32
  442.      mov    bx,ax
  443.      mov    ax,dx
  444.     endif
  445.     jmp    short seekxit
  446. seeker:    mov    [bx+status],ax
  447.     mov    ax,-1
  448.     mov    bx,ax
  449.     mov    dx,ax            ;all returns are -1
  450. seekxit:
  451.     if    _LDATA
  452.      pop    ds
  453.     endif
  454.     cproce
  455.     endps
  456.     end
  457.