New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / exec / initstruct.c
bloba892f78b731ab3b4d87085fa118629f1abd9bd45
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Initialize a structure.
6 Lang: english
7 */
8 #include "exec_intern.h"
9 #include <aros/libcall.h>
10 #include <exec/alerts.h>
11 #include <proto/exec.h>
13 /*****************************************************************************
15 NAME */
17 AROS_LH3(void, InitStruct,
19 /* SYNOPSIS */
20 AROS_LHA(APTR, initTable, A1),
21 AROS_LHA(APTR, memory, A2),
22 AROS_LHA(ULONG, size, D0),
24 /* LOCATION */
25 struct ExecBase *, SysBase, 13, Exec)
27 /* FUNCTION
28 Initialize some library base or other structure depending on the
29 information in the init table. The init table consists of
30 instructions starting with an action byte followed by more
31 information. The instruction byte looks like:
33 iisscccc where ii is the instruction code:
34 0 - copy following c+1 elements
35 1 - repeat following element c+1 times
36 2 - take next byte as offset, then copy
37 3 - take the next 3 bytes (in the machine's
38 particular byte ordering) as offset, then
39 copy
40 ss is the element size
41 0 - LONGs
42 1 - WORDs
43 2 - BYTEs
44 cccc is the element count-1
46 Instruction bytes must follow the same alignement restrictions as LONGs,
47 the following elements are aligned to their particular restrictions.
49 A 0 instruction ends the init table.
51 INPUTS
52 initTable - Pointer to init table.
53 memory - Pointer to uninitialized structure.
54 size - Size of memory area to 0 out before decoding or 0
55 for no filling.
57 RESULT
59 NOTES
61 EXAMPLE
63 BUGS
65 SEE ALSO
67 INTERNALS
69 ******************************************************************************/
71 AROS_LIBFUNC_INIT
73 LONG cnt;
74 ULONG offset=0,src;
75 UBYTE *it,*dst;
76 int s,t;
78 /* Clear Memory area fast. Get number of longs and clear them. */
79 cnt=size/sizeof(LONG);
80 size&=(sizeof(LONG)-1);
81 dst=(UBYTE *)memory;
82 if(cnt)
85 *(LONG *)dst=0;
86 dst+=sizeof(LONG);
88 while(--cnt);
90 /* Clear the rest. */
91 cnt=size;
92 if(cnt)
94 *dst++=0;
95 while(--cnt);
97 it =(UBYTE *)initTable;
98 dst=(UBYTE *)memory;
100 /* As long as there's something to do */
101 while(*it!=0)
103 /* What to do. */
104 t=*it>>6&3;
106 /* Element size. */
107 s=*it>>4&3;
109 /* Number of things to do (-1). */
110 cnt=*it&15;
112 /* Depending on the action there may be more information */
113 switch(t)
115 case 0:
116 case 1:
117 /* Skip the action byte */
118 it++;
119 break;
120 case 2:
121 /* Skip the action byte, get the offset */
122 it++;
123 offset=*it++;
124 break;
125 case 3:
127 Get 24bit offset. It's the programmer's responsibility
128 to align the action byte with a LONG instruction before
129 this.
131 #if AROS_BIG_ENDIAN
132 offset=*(ULONG *)it&0xffffff;
133 #else
134 offset=it[1] | ((*(UWORD *)&it[2]) << 8);
135 #endif
136 it+=sizeof(LONG);
137 break;
140 /* Align source and destination pointers */
141 switch(s)
143 case 0:
144 /* Align pointer to LONG requirements */
145 it =(UBYTE *)(((IPTR)it +AROS_LONGALIGN-1)&~(AROS_LONGALIGN-1));
146 dst=(UBYTE *)(((IPTR)dst+AROS_LONGALIGN-1)&~(AROS_LONGALIGN-1));
147 break;
148 case 1:
149 /* Same for WORDs */
150 it =(UBYTE *)(((IPTR)it +AROS_WORDALIGN-1)&~(AROS_WORDALIGN-1));
151 dst=(UBYTE *)(((IPTR)dst+AROS_WORDALIGN-1)&~(AROS_WORDALIGN-1));
152 break;
153 case 2:
154 /* Nothing to do for bytes */
155 break;
156 default:
157 /* And an Alert for nibbles ;-) */
158 Alert(ACPU_AddressErr);
161 Tell the compiler that he doesn't need to
162 care about side effects of Alert()
164 return;
167 /* Switch over action */
168 switch(t)
170 case 2:
171 case 3:
172 /* Action is: Add offset then copy */
173 dst=(BYTE *)memory+offset;
175 /* Fall through */
176 case 0:
177 /* Action is: Copy the next <cnt> elements to the current location */
178 switch(s)
180 case 0:
181 /* Copy loop */
184 *(LONG *)dst=*(LONG *)it;
185 dst+=sizeof(LONG);
186 it +=sizeof(LONG);
187 }while(--cnt>=0);
188 break;
189 case 1:
192 *(WORD *)dst=*(WORD *)it;
193 dst+=sizeof(WORD);
194 it +=sizeof(WORD);
195 }while(--cnt>=0);
196 break;
197 case 2:
199 *dst++=*it++;
200 while(--cnt>=0);
201 break;
203 break;
204 case 1:
205 /* Action is: Repeat the next element <cnt> times */
206 switch(s)
208 case 0:
209 /* Get source */
210 src=*(LONG *)it;
211 it +=sizeof(LONG);
213 /* And write it. */
216 *(LONG *)dst=src;
217 dst+=sizeof(LONG);
218 }while(--cnt>=0);
219 break;
220 case 1:
221 src=*(WORD *)it;
222 it +=sizeof(WORD);
225 *(WORD *)dst=src;
226 dst+=sizeof(WORD);
227 }while(--cnt>=0);
228 break;
229 case 2:
230 src=*it++;
232 *dst++=src;
233 while(--cnt>=0);
234 break;
236 break;
239 /* Align next instruction byte */
240 it=(UBYTE *)(((IPTR)it+AROS_WORDALIGN-1)&~(AROS_WORDALIGN-1));
242 AROS_LIBFUNC_EXIT