home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC6.DMS / in.adf / libsrc.lha / LIBSRC / files.asm < prev    next >
Encoding:
Assembly Source File  |  1994-04-17  |  4.2 KB  |  247 lines

  1.  
  2. * Maxon C++ Library:
  3. * Modul "files"
  4. * Jens Gelhar 19.03.93, 17.04.94
  5.  
  6.     xdef    _fopen,fopen__PCcPCc
  7.     xdef    _freopen,freopen__PCcPCcP06stream
  8.     xdef    _fclose,fclose__P06stream
  9.     xdef    _allocstream,allocstream__Ui
  10.     xdef    ___Filelist
  11.     xdef    _EXIT_1_close_sTiLl_open_files
  12.  
  13.     xref    _DOSBase,_std__in,_std__out,_std__err,_errno
  14.  
  15. Execbase    = 4
  16. AllocMem    = -198
  17. FreeMem    = -210
  18.  
  19. Open    = -30
  20. Close    = -36
  21. Seek    = -66
  22. IoErr    = -132
  23.  
  24. str_mode    = 6
  25. str_error    = 7
  26. str_bufptr    = 8
  27. str_flags    = 12
  28. str_sizeof    = 13
  29.  
  30. buf_close    = 24
  31.  
  32.  
  33. _EXIT_1_close_sTiLl_open_files:
  34.     move.l    ___Filelist,d0
  35.     beq.b    _ex_std
  36.     addq.l    #4,d0
  37.     move.l    d0,-(a7)
  38.     bsr    _fclose
  39.     addq.l    #4,a7
  40.     bra.b    _EXIT_1_close_sTiLl_open_files
  41. _ex_std    pea    _std__out
  42.     bsr    _fclose
  43.     move.l    #_std__in,(a7)
  44.     bsr    _fclose
  45.     move.l    #_std__err,(a7)
  46.     bsr    _fclose
  47.     addq.l    #4,a7
  48.     rts
  49.  
  50. _freopen:
  51. freopen__PCcPCcP06stream:
  52.     movem.l d2-d3/a6,-(a7)
  53.     move.l    _DOSBase,a6
  54.     move.l    3*4+8(a7),a0             ; Zugriffsart
  55.     move.l    3*4+4(a7),d1             ; Dateiname
  56.     bsr    openfile
  57.     tst.l    d0
  58.     beq.b    err
  59.     move.l    3*4+12(a7),a0
  60.     move.l    d0,(a0)
  61.     move.b    d1,str_mode(a0)
  62.     bset    #6,str_flags(a0)
  63.     clr.b    str_error(a0)
  64.     move.l    a0,d0
  65.     movem.l    (a7)+,d2-d3/a6
  66.     rts
  67.  
  68. _fopen:
  69. fopen__PCcPCc:    ; Stack-Parameter: Filename, Accessmode
  70.     movem.l d2-d3/a6,-(a7)
  71.     move.l    _DOSBase,a6
  72.     move.l    3*4+8(a7),a0        ; Zugriffsart
  73.     move.l    3*4+4(a7),d1        ; Dateiname
  74.     bsr.b    openfile
  75.     tst.l    d0
  76.     beq.b    err
  77.     move.l    d1,-(a7)
  78.     move.l    d0,-(a7)
  79.     bsr.b    allocstream__Ui
  80.     tst.l    d0
  81.     beq.b    memerr
  82.     move.l    d0,a0
  83.     addq.l    #4,a7
  84.     move.l    (a7)+,d1
  85.     move.b    d1,str_mode(a0)        ; Zugriffsart
  86. fopRet    movem.l    (a7)+,d2-d3/a6
  87.     rts
  88.  
  89. memerr:    ; allocstream schlug fehl:
  90.     move.l    _DOSBase,a6
  91.     move.l    (a1)+,d1        ; File wieder schließen
  92.     jsr    Close(a6)
  93.     addq.l    #4,a7
  94. err:    ; Datei nicht geöffnet:
  95.     move.l    _DOSBase,a6
  96.     jsr    IoErr(a6)
  97.     move.l    d0,_errno
  98.     moveq    #0,d0
  99.     bra.b    fopRet
  100.  
  101. _allocstream:
  102. allocstream__Ui:
  103.     ; Streamstruct für Filehandle 4(a7) allozieren
  104.     movem.l    d2/a2/a6,-(a7)
  105.     move.l    Execbase.w,a6
  106.     moveq    #str_sizeof+4,d0
  107.     move.l    #$10000,d1
  108.     jsr    AllocMem(a6)
  109.     tst.l    d0
  110.     beq.b    ast1
  111.     move.l    d0,a0
  112.     addq.l    #4,d0
  113.     move.l    3*4+4(a7),4(a0)          ; Filehandle eintragen
  114.     move.b    #$C0,str_flags+4(a0)
  115.     move.l    ___Filelist,(a0)
  116.     move.l    a0,___Filelist
  117. ast1    movem.l    (a7)+,d2/a2/a6
  118.     rts
  119.  
  120. openfile: ; Zugriffsart a0, Name d1: Filehandle nach d0, Modus (1=read, 2=write, 3 = rw) nach d1
  121.     move.b    (a0)+,d0
  122.     cmp.b    #'b',(a0)
  123.     bne.b    noB
  124.     addq.l    #1,a0
  125. noB:    cmp.b    #'r',d0
  126.     beq.b    fread
  127.     cmp.b    #'w',d0
  128.     beq.b    fwrite
  129.     cmp.b    #'a',d0
  130.     beq.b    fappend
  131.     moveq    #0,d0
  132.     rts
  133. fread:    cmp.b    #'+',(a0)
  134.     beq.b    freadwrite
  135.     move.l    #1005,d2
  136.     jsr    Open(a6)
  137.     moveq    #1,d1
  138.     rts
  139.  
  140. freadwrite:
  141.     move.l #1005,d2
  142.     jsr Open(a6)
  143.     moveq #3,d1
  144.     rts
  145.  
  146. fwrite:    cmp.b #'+',(a0)
  147.     beq.b frwnew
  148. fwnew:    move.l #1006,d2
  149.     jsr Open(a6)
  150.     moveq #2,d1
  151.     rts
  152.  
  153. frwnew:    ; neue Datei erzeugen für Lesen+schreiben:
  154.     move.l #1006,d2
  155.     move.l d1,-(a7)
  156.     jsr Open(a6)
  157.     move.l (a7)+,d1
  158.     tst.l d0
  159.     beq.b offen
  160.     move.l d1,-(a7)
  161.     move.l d0,d1
  162.     jsr Close(a6)
  163.     move.l (a7)+,d1
  164.     move.l #1005,d2
  165.     jsr Open(a6)
  166.     moveq #3,d1
  167. offen:    rts
  168.  
  169. fappend:
  170.     cmp.b #'+',(a0)
  171.     bne.b fapprw
  172.     bsr.b fapprw
  173.     moveq #3,d1
  174.     rts
  175. fapprw:    move.l d1,-(a7)
  176.     move.l #1005,d2
  177.     jsr Open(a6)
  178.     move.l (a7)+,d1
  179.     tst.l d0
  180.     beq.b fwnew
  181.     move.l d0,-(a7)
  182.     move.l d0,d1
  183.     moveq #0,d2
  184.     moveq #1,d3
  185.     jsr Seek(a6)
  186.     move.l (a7)+,d0
  187.     moveq #2,d1
  188.     rts
  189.  
  190. _fclose:
  191. fclose__P06stream:
  192.     movem.l d1-d3/a0/a1/a6,-(a7)
  193.     move.l 6*4+4(a7),d1
  194.     subq.l #4,d1
  195.     lea ___Filelist,a0
  196. loop:    cmp.l (a0),d1
  197.     beq.b found
  198.     move.l (a0),d0
  199.     beq.b notfound
  200.     move.l d0,a0
  201.     bra.b loop
  202. notfound:    ; Datei gibt's nicht offiziell:
  203.     cmp.l #_std__in-4,d1
  204.     beq.b found
  205.     cmp.l #_std__out-4,d1
  206.     beq.b found
  207.     cmp.l #_std__err-4,d1
  208.     beq.b found
  209.     moveq #-1,d0
  210.     bra.b fcret
  211. found:    move.l d1,a1
  212.     clr.l -(a7)
  213.     btst #6,str_flags+4(a1)
  214.     beq.b fc0
  215.     move.l 4(a1),(a7)       ; Filehandle
  216. fc0:    tst.b str_flags+4(a1)
  217.     bpl.b fc1
  218.     move.l (a1),(a0)        ; aus Liste aushängen
  219. fc1:    move.l str_bufptr+4(a1),d0
  220.     beq.b fc2
  221.     ; Puffer war eingerichtet:
  222.     move.l a1,-(a7)
  223.     move.l d0,a0
  224.     move.l buf_close(a0),a6
  225.     jsr (a6)
  226.     move.l (a7)+,a1
  227. fc2:    ; Struct freigeben:
  228.     tst.b str_flags+4(a1)
  229.     bpl.b fc3
  230.     moveq #str_sizeof+4,d0
  231.     move.l Execbase.w,a6
  232.     jsr FreeMem(a6)
  233. fc3:    move.l (a7)+,d1
  234.     beq.b fc4
  235.     move.l _DOSBase,a6
  236.     jsr Close(a6)           ; Datei endlich schließen
  237. fc4:    moveq #0,d0
  238. fcret:    movem.l (a7)+,d1-d3/a0/a1/a6
  239.     rts
  240.  
  241.     SECTION D,DATA
  242.  
  243. ___Filelist:    dc.l 0
  244.  
  245.     end
  246.  
  247.