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