[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 |
|
---|
[b28a12e] | 59 | #include "ram.h"
|
---|
[f40a309] | 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 |
|
---|
[7258c6a] | 68 | struct s_entry *ep_adj(struct s_entry *sep, int16_t sdir, int32_t tval)
|
---|
[f40a309] | 69 | {
|
---|
| 70 | register struct s_entry *tep;
|
---|
| 71 |
|
---|
| 72 | #if DEBUGIT
|
---|
| 73 | if (verbose)
|
---|
[9519422] | 74 | printf("epadj($%08lX, %d, %ld): sep->e_time=%ld\n",
|
---|
[f40a309] | 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]);
|
---|
[9519422] | 84 |
|
---|
[f40a309] | 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 | } else { /* find right (latest) end of chain */
|
---|
| 142 |
|
---|
| 143 | if (sep->e_time GT tval) {
|
---|
| 144 |
|
---|
| 145 | while (E_NULL NE (tep = sep->e_bak)) {
|
---|
| 146 |
|
---|
| 147 | #if CHECKP
|
---|
| 148 | Pcheck(tep, "tep - ep_adj() R .5.");
|
---|
| 149 | #endif
|
---|
| 150 |
|
---|
| 151 | #if DEBUGIT
|
---|
| 152 | if (verbose AND testing)
|
---|
| 153 | printf(" .5. sep=$%08lX, tep=$%08lX\n", sep, tep);
|
---|
| 154 | #endif
|
---|
| 155 |
|
---|
| 156 | if ((sep->e_time LE tval) OR
|
---|
| 157 | (sep->e_type EQ EV_SCORE))
|
---|
| 158 | break;
|
---|
| 159 | else
|
---|
| 160 | sep = tep;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | while (E_NULL NE (tep = sep->e_fwd)) {
|
---|
| 165 |
|
---|
| 166 | #if CHECKP
|
---|
| 167 | Pcheck(tep, "tep - ep_adj() R .6.");
|
---|
| 168 | #endif
|
---|
| 169 |
|
---|
| 170 | #if DEBUGIT
|
---|
| 171 | if (verbose AND testing)
|
---|
| 172 | printf(" .6. sep=$%08lX, tep=$%08lX\n", sep, tep);
|
---|
| 173 | #endif
|
---|
| 174 |
|
---|
| 175 | if (tep->e_time GT tval) {
|
---|
[9519422] | 176 |
|
---|
[f40a309] | 177 | #if DEBUGIT
|
---|
| 178 | if (verbose)
|
---|
| 179 | printf(" .7. $%08lX returned\n", sep);
|
---|
| 180 | #endif
|
---|
| 181 | return(sep);
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | sep = tep;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | #if CHECKP
|
---|
| 188 | Pcheck(tep, "tep - ep_adj() R .8.");
|
---|
| 189 | #endif
|
---|
| 190 |
|
---|
| 191 | #if DEBUGIT
|
---|
| 192 | if (verbose)
|
---|
| 193 | printf(" .8. $%08lX returned\n", sep);
|
---|
| 194 | #endif
|
---|
| 195 | return(sep);
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | /*
|
---|
| 200 | =============================================================================
|
---|
| 201 | frfind(tval, sdir) -- Returns a pointer to the event chain
|
---|
| 202 | at the time 'tval' in the current score in the direction 'sdir',
|
---|
| 203 | or E_NULL if the current score is empty.
|
---|
| 204 | =============================================================================
|
---|
| 205 | */
|
---|
| 206 |
|
---|
[7258c6a] | 207 | struct s_entry *frfind(int32_t tval, int16_t sdir)
|
---|
[f40a309] | 208 | {
|
---|
[7258c6a] | 209 | register int16_t i;
|
---|
| 210 | register int32_t t_min, dt;
|
---|
[f40a309] | 211 | register struct s_entry *ep, *sep;
|
---|
| 212 |
|
---|
| 213 | #if DEBUGIT
|
---|
| 214 | if (verbose) {
|
---|
| 215 |
|
---|
| 216 | printf("frfind(%ld, %d): searching\n", tval, sdir);
|
---|
| 217 | }
|
---|
| 218 | #endif
|
---|
| 219 |
|
---|
| 220 | #if CHECKP
|
---|
| 221 | Pcheck(scp, "scp - frfind() - entry");
|
---|
| 222 | Pcheck(p_fwd, "p_fwd - frfind() - entry");
|
---|
| 223 | Pcheck(p_cur, "p_cur - frfind() - entry");
|
---|
| 224 | Pcheck(p_bak, "p_bak - frfind() - entry");
|
---|
| 225 | #endif
|
---|
| 226 |
|
---|
| 227 | if (scp EQ E_NULL) { /* NULL if no score selected */
|
---|
| 228 |
|
---|
| 229 | #if DEBUGIT
|
---|
| 230 | if (verbose)
|
---|
| 231 | printf("frfind(%ld, %d): found scp EQ E_NULL\n", tval, sdir);
|
---|
| 232 | #endif
|
---|
| 233 | return(E_NULL);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | if (tval < 0)
|
---|
| 237 | return(ep_adj(scp, sdir, tval));
|
---|
| 238 |
|
---|
| 239 | if (p_cur->e_time EQ tval) { /* at p_cur ? */
|
---|
| 240 |
|
---|
| 241 | #if DEBUGIT
|
---|
| 242 | if (verbose)
|
---|
| 243 | printf("frfind(): found tval at p_cur\n");
|
---|
| 244 | #endif
|
---|
| 245 | return(ep_adj(p_cur, sdir, tval));
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | if (p_fwd->e_time EQ tval) { /* at p_fwd ? */
|
---|
[9519422] | 249 |
|
---|
[f40a309] | 250 | #if DEBUGIT
|
---|
| 251 | if (verbose)
|
---|
| 252 | printf("frfind(): found tval at p_fwd\n");
|
---|
| 253 | #endif
|
---|
| 254 | return(ep_adj(p_fwd, sdir, tval));
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | if (p_bak->e_time EQ tval) { /* at p_bak ? */
|
---|
| 258 |
|
---|
| 259 | #if DEBUGIT
|
---|
| 260 | if (verbose)
|
---|
| 261 | printf("frfind(): found tval at p_bak\n");
|
---|
| 262 | #endif
|
---|
| 263 | return(ep_adj(p_bak, sdir, tval));
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | t_min = (tval GT p_cur->e_time) ? /* time from p_cur */
|
---|
| 267 | (tval - p_cur->e_time) :
|
---|
| 268 | (p_cur->e_time - tval);
|
---|
| 269 |
|
---|
| 270 | ep = p_cur;
|
---|
| 271 |
|
---|
| 272 | dt = (tval GT p_fwd->e_time) ? /* time from p_fwd */
|
---|
| 273 | (tval - p_fwd->e_time) :
|
---|
| 274 | (p_fwd->e_time - tval);
|
---|
| 275 |
|
---|
| 276 | if (dt LT t_min) { /* select shortest time */
|
---|
| 277 |
|
---|
| 278 | t_min = dt;
|
---|
| 279 | ep = p_fwd;
|
---|
| 280 |
|
---|
| 281 | #if DEBUGIT
|
---|
| 282 | if (verbose)
|
---|
| 283 | printf("frfind(): p_fwd dt=%ld\n", dt);
|
---|
| 284 | #endif
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | dt = (tval GT p_bak->e_time) ? /* time to p_bak */
|
---|
| 288 | (tval - p_bak->e_time) :
|
---|
| 289 | (p_bak->e_time - tval);
|
---|
| 290 |
|
---|
| 291 | if (dt LT t_min) { /* select shortest time */
|
---|
| 292 |
|
---|
| 293 | t_min = dt;
|
---|
| 294 | ep = p_bak;
|
---|
| 295 |
|
---|
| 296 | #if DEBUGIT
|
---|
| 297 | if (verbose)
|
---|
| 298 | printf("frfind(): p_bak dt=%ld\n", dt);
|
---|
| 299 | #endif
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | if (NOT insmode) {
|
---|
| 303 |
|
---|
| 304 | for (i = 0; i < N_SECTS; i++) { /* search section list */
|
---|
| 305 |
|
---|
| 306 | if (E_NULL NE (sep = seclist[curscor][i])) {
|
---|
| 307 |
|
---|
| 308 | dt = (tval GT sep->e_time) ? /* time to section */
|
---|
| 309 | (tval - sep->e_time) :
|
---|
| 310 | (sep->e_time - tval);
|
---|
| 311 |
|
---|
| 312 | if (dt LT t_min) { /* select shortest time */
|
---|
| 313 |
|
---|
| 314 | t_min = dt;
|
---|
| 315 | ep = sep;
|
---|
| 316 |
|
---|
| 317 | #if DEBUGIT
|
---|
| 318 | if (verbose)
|
---|
| 319 | printf("frfind(): section %d dt=%ld\n", i, dt);
|
---|
| 320 | #endif
|
---|
| 321 | }
|
---|
| 322 | }
|
---|
| 323 | }
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | #if CHECKP
|
---|
| 327 | Pcheck(ep, "ep - frfind() - ep_adj()/exiting");
|
---|
| 328 | #endif
|
---|
| 329 |
|
---|
| 330 | return(ep_adj(ep, sdir, tval)); /* adjust the pointer */
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | /*
|
---|
| 334 | =============================================================================
|
---|
| 335 | findev(ep, te, et, d1, d2) -- Searches the event chain
|
---|
| 336 | starting at 'ep' for an event at a time of 'te' with:
|
---|
| 337 | a type of 'et', e_data1 EQ 'd1', and e_data2 EQ 'd2'.
|
---|
| 338 |
|
---|
| 339 | The values of 'd1' or 'd2' may be -1, in which case
|
---|
| 340 | e_data1 or e_data2 will be assumed to match.
|
---|
| 341 |
|
---|
| 342 | Returns a pointer to the desired event if it is found, or
|
---|
| 343 | 'E_NULL' if no event in the chain matches the criteria given.
|
---|
| 344 | =============================================================================
|
---|
| 345 | */
|
---|
| 346 |
|
---|
[7258c6a] | 347 | struct s_entry *findev(struct s_entry *ep, int32_t te, int16_t et, int16_t d1, int16_t d2)
|
---|
[f40a309] | 348 | {
|
---|
| 349 | register struct s_entry *tp;
|
---|
| 350 |
|
---|
| 351 | tp = ep_adj(ep, 1, te); /* search from left end of chain */
|
---|
| 352 |
|
---|
| 353 | while (tp->e_time EQ te) { /* check the time, ... */
|
---|
| 354 |
|
---|
| 355 | if ((tp->e_type EQ et) AND /* ... e_type, */
|
---|
| 356 | ((d1 EQ -1) OR (tp->e_data1 EQ d1)) AND /* ... e_data1, */
|
---|
| 357 | ((d2 EQ -1) OR (tp->e_data2 EQ d2))) /* ... e_data2 */
|
---|
| 358 | return(tp); /* found the event */
|
---|
| 359 |
|
---|
| 360 | tp = tp->e_fwd; /* search forward */
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | return(E_NULL); /* event not found */
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | /*
|
---|
| 367 | =============================================================================
|
---|
| 368 | ehfind(eh, te, d1, d2) -- Searches the event header chain
|
---|
| 369 | for an event at a time of 'te' with: a header type of 'eh',
|
---|
| 370 | e_data1 EQ 'd1', and e_data2 EQ 'd2'.
|
---|
| 371 |
|
---|
| 372 | The value of 'te' may be -1, in which case e_time will
|
---|
| 373 | be assumed to match.
|
---|
| 374 |
|
---|
| 375 | The values of 'd1' or 'd2' may be -1, in which case
|
---|
| 376 | e_data1 or e_data2 will be assumed to match.
|
---|
| 377 |
|
---|
| 378 | Returns a pointer to the desired event if it is found, or
|
---|
| 379 | 'E_NULL' if no event in the chain matches the criteria given.
|
---|
| 380 | =============================================================================
|
---|
| 381 | */
|
---|
| 382 |
|
---|
[7258c6a] | 383 | struct s_entry *ehfind(int16_t eh, int32_t te, int16_t d1, int16_t d2)
|
---|
[f40a309] | 384 | {
|
---|
| 385 | register struct s_entry *tp;
|
---|
| 386 |
|
---|
| 387 | tp = hplist[curscor][eh]; /* get head of chain */
|
---|
| 388 |
|
---|
| 389 | while (E_NULL NE tp) { /* check each event ... */
|
---|
| 390 |
|
---|
| 391 | if (((te EQ -1L) OR (tp->e_time EQ te)) AND /* ... time, */
|
---|
| 392 | ((d1 EQ -1) OR (tp->e_data1 EQ d1)) AND /* ... e_data1, */
|
---|
| 393 | ((d2 EQ -1) OR (tp->e_data2 EQ d2))) /* ... e_data2 */
|
---|
| 394 | return(tp); /* found the event */
|
---|
| 395 |
|
---|
| 396 | tp = tp->e_up; /* search up the chain */
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | return(tp); /* event not found */
|
---|
| 400 | }
|
---|
[6262b5c] | 401 |
|
---|