summaryrefslogtreecommitdiff
path: root/Source/PopChunk.S
blob: fdf5d38c2e7e492e2488e749fd49dfde1b6a15a5 (plain)
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
130
131
132
133
134
**
**	$Id: PopChunk.S,v 21.2 92/05/17 03:31:01 chris Exp $
**	$Revision: 21.2 $
**
**	$Filename: PopChunk.S $
**	$Author: chris $
**	$Date: 92/05/17 03:31:01 $
**
**	iff.library/IFFL_PopChunk
**
**	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_PopChunk
		SECTION	text,CODE

		INCLUDE	"IffLib.i"

		XREF	SetError,ClearError
		XDEF	PopChunkFunc


******* iff.library/IFFL_PopChunk *******************************************
*
*    NAME
*	IFFL_PopChunk -- Pop top context node off context stack.
*
*    SYNOPSIS
*	success = IFFL_PopChunk( iff )
*	D0                       A0
*
*	BOOL IFFL_PopChunk( IFFL_HANDLE )
*
*    FUNCTION
*	Pops top context chunk and updates the file accordingly.
*	The function is normally called only for writing files and signals
*	the end of a chunk.
*
*    INPUTS
*	iff - IFF handle
*
*    RESULTS
*	Non-zero  if successful or 0 if not successful (call IFFL_IFFError()
*	to get an IFFL_ERROR_... error code.
*
*    SEE ALSO
*	IFFL_PushChunk(), IFFL_WriteChunkBytes()
*
*****************************************************************************

PopChunkFunc:	movem.l	d2-d3/a2/a5-a6,-(SP)
		movea.l	a6,a5			; IFFBase für ClearError()
		movea.l	a0,a2			; A2 :  IFF-Handle
		movea.l	iffb_DOSBase(a5),a6	; A6 :  DOSBase

	*** Pad-Byte schreiben falls Chunk-Länge ungerade ist

		btst.b	#0,ifffh_ChunkSize+3(a2)
		beq.b	.NoOddChunkSize

		move.l	ifffh_File(a2),d1
		move.l	a2,d2			; Hier hat's ein 0 Byte
		moveq.l	#1,d3			; Länge: 1 Byte
		JSRLIB	Write
		cmp.l	d3,d0
		bne.b	.WriteError
		add.l	d3,ifffh_ChunkSize(a2)
.NoOddChunkSize:

	*** ParentChunk-Grösse += Chunk-Grösse

		moveq.l	#8,d0			; Chunkheadersize
		add.l	ifffh_ChunkSize(a2),d0	; plus Chunksize
		add.l	d0,ifffh_ChunkSize+8(a2) ; und zur Parent-Chunk-Size dazu

	*** An den Anfang des Chunks seeken

		move.l	ifffh_File(a2),d1
		moveq.l	#4,d2			; Grössen-Eintrag im Chunk-Header
		add.l	ifffh_ChunkFPos(a2),d2	; Plus Chunk-Anfang
		moveq.l	#OFFSET_BEGINNING,d3
		JSRLIB	Seek
		tst.l	d0
		bmi.b	.SeekError

	*** Richtige Chunk-Grösse eintragen

		move.l	ifffh_File(a2),d1
		lea	ifffh_ChunkSize(a2),a0
		move.l	a0,d2
		moveq.l	#4,d3			; 1 Langwort
		JSRLIB	Write			; schreiben
		cmp.l	d3,d0
		bne.b	.WriteError

	*** An das Ende des Chunks seeken

		move.l	ifffh_File(a2),d1
		moveq.l	#0,d2
		moveq.l	#OFFSET_END,d3
		JSRLIB	Seek
		tst.l	d0
		bmi.b	.SeekError

	*** Chunk vom Stack holen (Stack eins nach unten rutschen)

		lea	iffh_CStack(a2),a1	; Destination
		lea	8(a1),a0		; Source
		moveq	#(iffh_CStackEnd-iffh_CStack-8)/4-1,d0
.StackDown:	move.l	(a0)+,(a1)+
		dbf	d0,.StackDown

	*** Okay

		bsr	ClearError		; Setzt auch D0 auf TRUE
		bra.b	.End

	*** Schreibfehler oder Seekfehler

.SeekError:
.WriteError:	moveq.l	#IFFL_ERROR_WRITE,d0
		bsr	SetError		; Setzt auch D0 auf FALSE

	*** Routine beenden

.End:		movem.l	(SP)+,d2-d3/a2/a5-a6
		rts


		END