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

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

Unix line breaks.

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