1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
**
** $Id: CloseIFF.S,v 21.1 92/05/15 03:23:45 chris Exp $
** $Revision: 21.1 $
**
** $Filename: CloseIFF.S $
** $Author: chris $
** $Release: 19.1 $
** $Date: 92/05/15 03:23:45 $
**
** iff.library/IFFL_CloseIFF
**
** COPYRIGHT (C) 1987-1992 BY CHRISTIAN A. WEBER, BRUGGERWEG 2,
** CH-8037 ZUERICH, SWITZERLAND. ALL RIGHTS RESERVED. NO PART
** OF THIS SOFTWARE MAY BE COPIED, REPRODUCED, OR TRANSMITTED
** IN ANY FORM OR BY ANY MEANS, WITHOUT THE PRIOR WRITTEN PER-
** MISSION OF THE AUTHOR. USE AT YOUR OWN RISK.
**
IDNT IFFL_CloseIFF
SECTION text,CODE
INCLUDE "IffLib.i"
XREF ClearError
XDEF CloseIFFFunc
******* iff.library/IFFL_CloseIFF *******************************************
*
* NAME
* IFFL_CloseIFF -- Close an IFF file and deallocate buffers
*
* SYNOPSIS
* IFFL_CloseIFF( iff )
* A1
*
* void IFFL_CloseIFF( IFFL_HANDLE )
*
* FUNCTION
* Returns the memory previously allocated by IFFL_OpenIFF().
*
* INPUTS
* iff - IFF file handle, from IFFL_OpenIFF()
*
* RESULTS
* For now, always results TRUE (this may change in the future).
*
* SEE ALSO
* IFFL_OpenIFF()
*
*****************************************************************************
CloseIFFFunc: movem.l d2-d3/a2/a5-a6,-(SP)
movea.l a6,a5 ; IFFBase für ClearError()
move.l a1,d0 ; Ist a1 == NULL ?
beq.b .End ; ja ---> don't free anything
cmpi.l #IFFFH_MAGIC,ifffh_Magic(a1)
beq.b .WriteMode
*** Read-Modus
move.l -(a1),d0 ; Grösse des reservierten Bereichs
movea.l iffb_SysBase(a5),a6
JSRLIB FreeMem ; Bereich freigeben
bra.b .End ; ---> fertig
*** Write-Modus
.WriteMode: movea.l a1,a2 ; A2 : IFF-Handle
movea.l iffb_DOSBase(a5),a6 ; A6 : DOSBase
move.l ifffh_File(a2),d1
beq.b .FileNotOpen ; File nicht offen --->
*** Pad-Word schreiben falls FORM-Länge nicht LONG-aligned ist
moveq.l #3,d0 ; LONG-Bitmaske
and.l ifffh_FormSize(a2),d0 ; Bits gesetzt ?
beq.b .NoPad ; noe --->
clr.l -(SP)
move.l SP,d2
moveq.l #2,d3 ; 1 WORD
JSRLIB Write
addq.l #4,SP
add.l d3,ifffh_FormSize(a2)
.NoPad:
*** An Offset 4 (FORM-Längen-Eintrag) des Files seeken
move.l ifffh_File(a2),d1
moveq.l #4,d2
moveq.l #OFFSET_BEGINNING,d3
JSRLIB Seek
tst.l d0
bmi.b .SeekError
*** FORM-Länge updaten
move.l ifffh_File(a2),d1
lea ifffh_FormSize(a2),a0
move.l a0,d2
moveq.l #4,d3
JSRLIB Write
.SeekError:
*** File schliessen
move.l ifffh_File(a2),d1
JSRLIB Close
.FileNotOpen:
*** IFF-Handle freigeben
movea.l a2,a1 ; IFF-Handle
moveq.l #ifffh_SIZEOF,d0 ; Grösse
movea.l iffb_SysBase(a5),a6
JSRLIB FreeMem
*** Routine beenden
.End: bsr ClearError ; IFFError zurücksetzen, D0 := 1
movem.l (SP)+,d2-d3/a2/a5-a6
rts
END
|