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

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

Added include files for global functions and variables.

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