summaryrefslogtreecommitdiff
path: root/Source/FindChunk.S
blob: 0b065a0756977f2c7f8eb2b8fd914db4217d8c3f (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
**
**	$Id: FindChunk.S,v 1.1 92/05/12 22:26:33 chris Exp $
**	$Revision: 1.1 $
**
**	$Filename: FindChunk.S $
**	$Author: chris $
**	$Release: 19.1 $
**	$Date: 92/05/12 22:26:33 $
**
**	iff.library/IFFL_FindChunk
**
**	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_FindChunk
		SECTION	text,CODE

		INCLUDE	"IffLib.i"

		XDEF	FindChunkFunc


******* iff.library/IFFL_FindChunk ******************************************
*
*   NAME
*	IFFL_FindChunk -- find an IFF-chunk
*
*   SYNOPSIS
*	chunk = IFFL_FindChunk( iff, chunkname )
*	D0                      A1   D0
*
*	APTR IFFL_FindChunk( IFFL_HANDLE, ULONG )
*
*   FUNCTION
*	Find a specific chunk in an IFF file
*
*   INPUTS
*	iff       - IFF file handle, from IFFL_OpenIFF()
*	chunkname - 4 characters packed ASCII ('BODY', 'VHDR' ...)
*	            if chunkname is 0, FindChunk() returns a pointer to the
*	            first byte after the end of the current FORM. This can
*	            be used by ANIM readers for jumping from FORM to FORM.
*
*   RESULTS
*	Pointer to the beginning of the chunk (that means to the chunk
*	name itself, followed by the chunk size); zero if chunk not found
*
*   BUGS
*	none known
*
*   SEE ALSO
*	IFFL_GetBMHD(), IFFL_GetColorTab()
*
*****************************************************************************

FindChunkFunc:	movea.l	4(a1),a0	; FORM-Länge
		addq.l	#8,a1		; FORM.... überspringen
		adda.l	a1,a0		; A0 zeigt jetzt ans Ende
		addq.l	#4,a1		; FORM-Typ überspringen
		tst.l	d0		; Chunk-ID == 0 ?
		bne.s	1$		; nein --->
		movea.l	a0,a1		; Sonst Ende des FORMs
		bra.s	99$		; zurückgeben

1$:		cmp.l	(a1),d0		; Chunk gefunden ?
		beq.s	99$		; ja!
		move.l	4(a1),d1	; Länge dieses Chunks
		addq.l	#1,d1		; auf WORD ...
		bclr	#0,d1		; ... aufrunden
		lea	8(a1,d1.l),a1	; Name & Länge dazu und zu A1 dazu
		cmpa.l	a0,a1		; FORM-Ende erreicht ?
		bcs.s	1$		; noch nicht --->
		suba.l	a1,a1		; Code für "nicht gefunden"
99$:
		move.l	a1,d0		; Resultat nach D0, set/reset Z-Flag
		rts

		END