source: buchla-68k/ram/frfind.c@ b28a12e

Last change on this file since b28a12e was b28a12e, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Zero redundant declarations.

  • Property mode set to 100644
File size: 9.1 KB
Line 
1/*
2 =============================================================================
3 frfind.c -- the frame finder, and other pointer pushers
4 Version 17 -- 1988-07-28 -- D.N. Lynx Crowe
5
6 struct s_entry *
7 ep_adj(sep, sdir, tval)
8 struct s_entry *sep;
9 int sdir;
10 long tval;
11
12 Returns a pointer to the event chain at the time 'tval'
13 starting from 'sep' in the direction 'sdir'.
14 The right end of the chain is returned when 'sdir' EQ 0,
15 and the left end is returned when 'sdir' NE 0.
16
17 struct s_entry *
18 frfind(tval, sdir)
19 long tval;
20 int sdir;
21
22 Returns a pointer to the event chain at the time 'tval'
23 in the current score in the direction 'sdir', or E_NULL
24 if the current score is empty.
25 The right end of the chain is returned when 'sdir' EQ 0,
26 and the left end is returned when 'sdir' NE 0.
27
28 struct s_entry *
29 findev(ep, te, et, d1, d2)
30 struct s_entry *ep;
31 long te;
32 short et, d1, d2;
33
34 Searches the event chain starting at 'ep' for an event at
35 a time of 'te' with: a type of 'et', e_data1 EQ 'd1',
36 and e_data2 EQ 'd2'. The values of 'd1' or 'd2' may be -1,
37 in which case e_data1 or e_data2 will be assumed to match.
38 Returns a pointer to the desired event if it is found, or
39 E_NULL if no event in the chain matches the criteria given.
40
41 struct s_entry *
42 ehfind(et, te, d1, d2)
43 short et;
44 long te;
45 short d1, d2;
46
47 Searches the event header chain starting for an event at
48 a time of 'te' with: a type of 'et', e_data1 EQ 'd1',
49 and e_data2 EQ 'd2'. The values of 'd1' or 'd2' may be -1,
50 in which case e_data1 or e_data2 will be assumed to match.
51 Returns a pointer to the desired event if it is found, or
52 E_NULL if no event in the chain matches the criteria given.
53 =============================================================================
54*/
55
56#define DEBUGIT 0
57#define CHECKP 0
58
59#include "ram.h"
60
61/*
62 =============================================================================
63 ep_adj(sep, sdir, tval) -- Returns a pointer to the event chain
64 at the time 'tval' starting from 'sep' in the direction 'sdir'.
65 =============================================================================
66*/
67
68struct s_entry *ep_adj(struct s_entry *sep, int16_t sdir, int32_t tval)
69{
70 register struct s_entry *tep;
71
72#if DEBUGIT
73 if (verbose)
74 printf("epadj($%08lX, %d, %ld): sep->e_time=%ld\n",
75 sep, sdir, tval, sep->e_time);
76#endif
77
78#if CHECKP
79 Pcheck(sep, "sep - ep_adj() entry");
80#endif
81
82 if (tval < 0) /* return start of score for negative times */
83 return(scores[curscor]);
84
85 if (sdir) { /* find left (earliest) end of chain */
86
87 if (sep->e_time LT tval) {
88
89 while (E_NULL NE (tep = sep->e_fwd)) {
90
91#if CHECKP
92 Pcheck(tep, "tep - ep_adj() L .1.");
93#endif
94
95#if DEBUGIT
96 if (verbose AND testing)
97 printf(" .1. sep=$%08lX, tep=$%08lX\n", sep, tep);
98#endif
99
100 if (sep->e_time LT tval)
101 sep = tep;
102 else
103 break;
104 }
105 }
106
107 while (E_NULL NE (tep = sep->e_bak)) {
108
109#if CHECKP
110 Pcheck(tep, "tep - ep_adj() L .2.");
111#endif
112
113#if DEBUGIT
114 if (verbose AND testing)
115 printf(" .2. sep=$%08lX, tep=$%08lX\n", sep, tep);
116#endif
117
118 if ((tep->e_time LT tval) OR
119 (tep->e_type EQ EV_SCORE)) {
120
121#if DEBUGIT
122 if (verbose)
123 printf(" .3. $%08lX returned\n", sep);
124#endif
125 return(sep);
126 }
127
128 sep = tep;
129 }
130
131#if CHECKP
132 Pcheck(tep, "tep - ep_adj() L .4.");
133#endif
134
135#if DEBUGIT
136 if (verbose)
137 printf(" .4. $%08lX returned\n", sep);
138#endif
139 return(sep);
140
141/*
142
143*/
144
145 } else { /* find right (latest) end of chain */
146
147 if (sep->e_time GT tval) {
148
149 while (E_NULL NE (tep = sep->e_bak)) {
150
151#if CHECKP
152 Pcheck(tep, "tep - ep_adj() R .5.");
153#endif
154
155#if DEBUGIT
156 if (verbose AND testing)
157 printf(" .5. sep=$%08lX, tep=$%08lX\n", sep, tep);
158#endif
159
160 if ((sep->e_time LE tval) OR
161 (sep->e_type EQ EV_SCORE))
162 break;
163 else
164 sep = tep;
165 }
166 }
167
168 while (E_NULL NE (tep = sep->e_fwd)) {
169
170#if CHECKP
171 Pcheck(tep, "tep - ep_adj() R .6.");
172#endif
173
174#if DEBUGIT
175 if (verbose AND testing)
176 printf(" .6. sep=$%08lX, tep=$%08lX\n", sep, tep);
177#endif
178
179 if (tep->e_time GT tval) {
180
181#if DEBUGIT
182 if (verbose)
183 printf(" .7. $%08lX returned\n", sep);
184#endif
185 return(sep);
186 }
187
188 sep = tep;
189 }
190
191#if CHECKP
192 Pcheck(tep, "tep - ep_adj() R .8.");
193#endif
194
195#if DEBUGIT
196 if (verbose)
197 printf(" .8. $%08lX returned\n", sep);
198#endif
199 return(sep);
200 }
201}
202
203/*
204
205*/
206
207/*
208 =============================================================================
209 frfind(tval, sdir) -- Returns a pointer to the event chain
210 at the time 'tval' in the current score in the direction 'sdir',
211 or E_NULL if the current score is empty.
212 =============================================================================
213*/
214
215struct s_entry *frfind(int32_t tval, int16_t sdir)
216{
217 register int16_t i;
218 register int32_t t_min, dt;
219 register struct s_entry *ep, *sep;
220
221#if DEBUGIT
222 if (verbose) {
223
224 printf("frfind(%ld, %d): searching\n", tval, sdir);
225 }
226#endif
227
228#if CHECKP
229 Pcheck(scp, "scp - frfind() - entry");
230 Pcheck(p_fwd, "p_fwd - frfind() - entry");
231 Pcheck(p_cur, "p_cur - frfind() - entry");
232 Pcheck(p_bak, "p_bak - frfind() - entry");
233#endif
234
235 if (scp EQ E_NULL) { /* NULL if no score selected */
236
237#if DEBUGIT
238 if (verbose)
239 printf("frfind(%ld, %d): found scp EQ E_NULL\n", tval, sdir);
240#endif
241 return(E_NULL);
242 }
243
244 if (tval < 0)
245 return(ep_adj(scp, sdir, tval));
246
247 if (p_cur->e_time EQ tval) { /* at p_cur ? */
248
249#if DEBUGIT
250 if (verbose)
251 printf("frfind(): found tval at p_cur\n");
252#endif
253 return(ep_adj(p_cur, sdir, tval));
254 }
255
256 if (p_fwd->e_time EQ tval) { /* at p_fwd ? */
257
258#if DEBUGIT
259 if (verbose)
260 printf("frfind(): found tval at p_fwd\n");
261#endif
262 return(ep_adj(p_fwd, sdir, tval));
263 }
264
265 if (p_bak->e_time EQ tval) { /* at p_bak ? */
266
267#if DEBUGIT
268 if (verbose)
269 printf("frfind(): found tval at p_bak\n");
270#endif
271 return(ep_adj(p_bak, sdir, tval));
272 }
273
274 t_min = (tval GT p_cur->e_time) ? /* time from p_cur */
275 (tval - p_cur->e_time) :
276 (p_cur->e_time - tval);
277
278 ep = p_cur;
279
280 dt = (tval GT p_fwd->e_time) ? /* time from p_fwd */
281 (tval - p_fwd->e_time) :
282 (p_fwd->e_time - tval);
283
284 if (dt LT t_min) { /* select shortest time */
285
286 t_min = dt;
287 ep = p_fwd;
288
289#if DEBUGIT
290 if (verbose)
291 printf("frfind(): p_fwd dt=%ld\n", dt);
292#endif
293 }
294
295/*
296
297*/
298
299 dt = (tval GT p_bak->e_time) ? /* time to p_bak */
300 (tval - p_bak->e_time) :
301 (p_bak->e_time - tval);
302
303 if (dt LT t_min) { /* select shortest time */
304
305 t_min = dt;
306 ep = p_bak;
307
308#if DEBUGIT
309 if (verbose)
310 printf("frfind(): p_bak dt=%ld\n", dt);
311#endif
312 }
313
314 if (NOT insmode) {
315
316 for (i = 0; i < N_SECTS; i++) { /* search section list */
317
318 if (E_NULL NE (sep = seclist[curscor][i])) {
319
320 dt = (tval GT sep->e_time) ? /* time to section */
321 (tval - sep->e_time) :
322 (sep->e_time - tval);
323
324 if (dt LT t_min) { /* select shortest time */
325
326 t_min = dt;
327 ep = sep;
328
329#if DEBUGIT
330 if (verbose)
331 printf("frfind(): section %d dt=%ld\n", i, dt);
332#endif
333 }
334 }
335 }
336 }
337
338#if CHECKP
339 Pcheck(ep, "ep - frfind() - ep_adj()/exiting");
340#endif
341
342 return(ep_adj(ep, sdir, tval)); /* adjust the pointer */
343}
344
345/*
346
347*/
348
349/*
350 =============================================================================
351 findev(ep, te, et, d1, d2) -- Searches the event chain
352 starting at 'ep' for an event at a time of 'te' with:
353 a type of 'et', e_data1 EQ 'd1', and e_data2 EQ 'd2'.
354
355 The values of 'd1' or 'd2' may be -1, in which case
356 e_data1 or e_data2 will be assumed to match.
357
358 Returns a pointer to the desired event if it is found, or
359 'E_NULL' if no event in the chain matches the criteria given.
360 =============================================================================
361*/
362
363struct s_entry *findev(struct s_entry *ep, int32_t te, int16_t et, int16_t d1, int16_t d2)
364{
365 register struct s_entry *tp;
366
367 tp = ep_adj(ep, 1, te); /* search from left end of chain */
368
369 while (tp->e_time EQ te) { /* check the time, ... */
370
371 if ((tp->e_type EQ et) AND /* ... e_type, */
372 ((d1 EQ -1) OR (tp->e_data1 EQ d1)) AND /* ... e_data1, */
373 ((d2 EQ -1) OR (tp->e_data2 EQ d2))) /* ... e_data2 */
374 return(tp); /* found the event */
375
376 tp = tp->e_fwd; /* search forward */
377 }
378
379 return(E_NULL); /* event not found */
380}
381
382/*
383
384*/
385
386/*
387 =============================================================================
388 ehfind(eh, te, d1, d2) -- Searches the event header chain
389 for an event at a time of 'te' with: a header type of 'eh',
390 e_data1 EQ 'd1', and e_data2 EQ 'd2'.
391
392 The value of 'te' may be -1, in which case e_time will
393 be assumed to match.
394
395 The values of 'd1' or 'd2' may be -1, in which case
396 e_data1 or e_data2 will be assumed to match.
397
398 Returns a pointer to the desired event if it is found, or
399 'E_NULL' if no event in the chain matches the criteria given.
400 =============================================================================
401*/
402
403struct s_entry *ehfind(int16_t eh, int32_t te, int16_t d1, int16_t d2)
404{
405 register struct s_entry *tp;
406
407 tp = hplist[curscor][eh]; /* get head of chain */
408
409 while (E_NULL NE tp) { /* check each event ... */
410
411 if (((te EQ -1L) OR (tp->e_time EQ te)) AND /* ... time, */
412 ((d1 EQ -1) OR (tp->e_data1 EQ d1)) AND /* ... e_data1, */
413 ((d2 EQ -1) OR (tp->e_data2 EQ d2))) /* ... e_data2 */
414 return(tp); /* found the event */
415
416 tp = tp->e_up; /* search up the chain */
417 }
418
419 return(tp); /* event not found */
420}
421
Note: See TracBrowser for help on using the repository browser.