| 1 | /*
|
|---|
| 2 | =============================================================================
|
|---|
| 3 | sctrak.c -- advance the score to a given frame
|
|---|
| 4 | Version 28 -- 1988-09-23 -- D.N. Lynx Crowe
|
|---|
| 5 | =============================================================================
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #undef DEBUGGER /* define to enable debug trace */
|
|---|
| 9 |
|
|---|
| 10 | #undef DEBUG_TR /* define for sc_trak() debug */
|
|---|
| 11 |
|
|---|
| 12 | #undef CHECKPTR /* define to check pointers */
|
|---|
| 13 |
|
|---|
| 14 | #include "ram.h"
|
|---|
| 15 |
|
|---|
| 16 | /*
|
|---|
| 17 | =============================================================================
|
|---|
| 18 | sc_trak(tval) -- position score display such that t_ctr EQ 'tval'
|
|---|
| 19 | Assumes that the pointers are correct.
|
|---|
| 20 | =============================================================================
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | int16_t sc_trak(int32_t tval)
|
|---|
| 24 | {
|
|---|
| 25 | register struct s_entry *rpb, *rpc, *rpf;
|
|---|
| 26 | register int32_t rtb, rtc, rtf;
|
|---|
| 27 | register int16_t mod48 = 48;
|
|---|
| 28 | struct gdsel *gdsp;
|
|---|
| 29 |
|
|---|
| 30 | DB_ENTR("sc_trak");
|
|---|
| 31 |
|
|---|
| 32 | if (ndisp NE 2) {
|
|---|
| 33 |
|
|---|
| 34 | DB_EXIT("sc_trak - ndisp NE 2");
|
|---|
| 35 | return(FAILURE);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | #ifdef CHECKPTR
|
|---|
| 39 | Pcheck(p_fwd, "p_fwd - sc_trak - entry");
|
|---|
| 40 | Pcheck(p_ctr, "p_ctr - sc_trak - entry");
|
|---|
| 41 | Pcheck(p_bak, "p_bak - sc_trak - entry");
|
|---|
| 42 | #endif
|
|---|
| 43 |
|
|---|
| 44 | if ((p_fwd EQ E_NULL) OR (p_ctr EQ E_NULL) OR (p_bak EQ E_NULL)) {
|
|---|
| 45 |
|
|---|
| 46 | DB_EXIT("sc_trak - NULL ptr");
|
|---|
| 47 | return(FAILURE);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | if (v_regs[5] & 0x0180) /* setup for VSDD bank 0 */
|
|---|
| 51 | vbank(0);
|
|---|
| 52 |
|
|---|
| 53 | rpf = p_fwd; /* forward event pointer */
|
|---|
| 54 | rtf = t_fwd; /* forward event time */
|
|---|
| 55 |
|
|---|
| 56 | rpc = p_ctr; /* current event pointer */
|
|---|
| 57 | rtc = t_ctr; /* current event time */
|
|---|
| 58 |
|
|---|
| 59 | rpb = p_bak; /* backward event pointer */
|
|---|
| 60 | rtb = t_bak; /* backward event time */
|
|---|
| 61 |
|
|---|
| 62 | #ifdef DEBUG_TR
|
|---|
| 63 | if (debugsw) {
|
|---|
| 64 |
|
|---|
| 65 | printf("\n## sc_trak(%10ld) ENTRY - fc_val=%10ld sd = %s sbase=%d soffset=%d\n",
|
|---|
| 66 | tval, fc_val, sd ? "BAK" : "FWD", sbase, soffset);
|
|---|
| 67 |
|
|---|
| 68 | printf(" p_bak: %08lX p_ctr: %08lX p_fwd: %08lX\n",
|
|---|
| 69 | p_bak, p_ctr, p_fwd);
|
|---|
| 70 |
|
|---|
| 71 | printf(" t_bak: %10ld t_ctr: %10ld t_fwd: %10ld\n",
|
|---|
| 72 | t_bak, t_ctr, t_fwd);
|
|---|
| 73 |
|
|---|
| 74 | printf(" T.bak: %10ld T.ctr: %10ld T.fwd: %10ld\n",
|
|---|
| 75 | p_bak->e_time, p_ctr->e_time, p_fwd->e_time);
|
|---|
| 76 | }
|
|---|
| 77 | #endif
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | DB_CMNT("sc_trak - update loop");
|
|---|
| 81 |
|
|---|
| 82 | if (sd EQ D_FWD) { /* scroll forward */
|
|---|
| 83 |
|
|---|
| 84 | DB_CMNT("sc_trak - forward");
|
|---|
| 85 |
|
|---|
| 86 | while (rtc++ LT tval) { /* advance to tval */
|
|---|
| 87 |
|
|---|
| 88 | sreset(); /* reset highlighting */
|
|---|
| 89 |
|
|---|
| 90 | ++rtb; /* update target time at p_bak */
|
|---|
| 91 | ++rtf; /* update target time at p_fwd */
|
|---|
| 92 |
|
|---|
| 93 | if (rpb->e_type NE EV_FINI) { /* up to end of score */
|
|---|
| 94 |
|
|---|
| 95 | while (rpb->e_time EQ rtb) { /* check event time */
|
|---|
| 96 |
|
|---|
| 97 | se_disp(rpb, D_FWD, gdstbp, 0); /* display event */
|
|---|
| 98 | rpb = rpb->e_fwd; /* point at next event */
|
|---|
| 99 |
|
|---|
| 100 | if (rpb->e_type EQ EV_FINI) /* stop at end of score */
|
|---|
| 101 | break;
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | if (0 EQ (rtb % mod48)) { /* handle beat markers */
|
|---|
| 106 |
|
|---|
| 107 | if ((struct gdsel *)NULL NE (gdsp = gdfsep)) {
|
|---|
| 108 |
|
|---|
| 109 | gdfsep = gdsp->next;
|
|---|
| 110 |
|
|---|
| 111 | gdsp->next = gdstbp[12];
|
|---|
| 112 | gdsp->note = 0x1111;
|
|---|
| 113 | gdsp->code = 1;
|
|---|
| 114 |
|
|---|
| 115 | gdstbp[12] = gdsp;
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | if (rpc->e_type NE EV_FINI) { /* up to end of score */
|
|---|
| 120 |
|
|---|
| 121 | while (rpc->e_time EQ rtc) { /* check event time */
|
|---|
| 122 |
|
|---|
| 123 | se_disp(rpc, D_FWD, gdstbc, 1); /* display event */
|
|---|
| 124 | rpc = rpc->e_fwd; /* point at next event */
|
|---|
| 125 |
|
|---|
| 126 | if (rpc->e_type EQ EV_FINI) /* stop at end of score */
|
|---|
| 127 | break;
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | if (rpf->e_type NE EV_FINI) { /* up to end of score */
|
|---|
| 132 |
|
|---|
| 133 | while (rpf->e_time EQ rtf) { /* check event time */
|
|---|
| 134 |
|
|---|
| 135 | se_disp(rpf, D_FWD, gdstbn, 0); /* display event */
|
|---|
| 136 | rpf = rpf->e_fwd; /* next event pointer */
|
|---|
| 137 |
|
|---|
| 138 | if (rpf->e_type EQ EV_FINI) /* stop at end of score */
|
|---|
| 139 | break;
|
|---|
| 140 | }
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | if (0 EQ (rtf % mod48)) { /* handle beat markers */
|
|---|
| 144 |
|
|---|
| 145 | if ((struct gdsel *)NULL NE (gdsp = gdfsep)) {
|
|---|
| 146 |
|
|---|
| 147 | gdfsep = gdsp->next;
|
|---|
| 148 |
|
|---|
| 149 | gdsp->next = gdstbn[12];
|
|---|
| 150 | gdsp->note = 0x1111;
|
|---|
| 151 | gdsp->code = 1;
|
|---|
| 152 |
|
|---|
| 153 | gdstbn[12] = gdsp;
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | sc_adv(); /* scroll the display */
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | } else { /* scroll backward */
|
|---|
| 162 |
|
|---|
| 163 | DB_CMNT("sc_trak - backward");
|
|---|
| 164 |
|
|---|
| 165 | while (rtc-- GT tval) { /* advance to tval */
|
|---|
| 166 |
|
|---|
| 167 | sreset(); /* reset highlighting */
|
|---|
| 168 |
|
|---|
| 169 | --rtb; /* update target time at p_bak */
|
|---|
| 170 | --rtf; /* update target time at p_fwd */
|
|---|
| 171 |
|
|---|
| 172 | if (rpb->e_type NE EV_SCORE) { /* up to start of score */
|
|---|
| 173 |
|
|---|
| 174 | while (rpb->e_time EQ rtb) { /* check event time */
|
|---|
| 175 |
|
|---|
| 176 | se_disp(rpb, D_BAK, gdstbp, 0);
|
|---|
| 177 | rpb = rpb->e_bak; /* point at next event */
|
|---|
| 178 |
|
|---|
| 179 | if (rpb->e_type EQ EV_SCORE) /* stop at end of score */
|
|---|
| 180 | break;
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | if (0 EQ (rtb % mod48)) { /* handle beat markers */
|
|---|
| 185 |
|
|---|
| 186 | if ((struct gdsel *)NULL NE (gdsp = gdfsep)) {
|
|---|
| 187 |
|
|---|
| 188 | gdfsep = gdsp->next;
|
|---|
| 189 |
|
|---|
| 190 | gdsp->next = gdstbp[12];
|
|---|
| 191 | gdsp->note = 0x1111;
|
|---|
| 192 | gdsp->code = 1;
|
|---|
| 193 |
|
|---|
| 194 | gdstbp[12] = gdsp;
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | if (rpc->e_type NE EV_SCORE) { /* up to start of score */
|
|---|
| 199 |
|
|---|
| 200 | while (rpc->e_time EQ rtc) { /* check event time */
|
|---|
| 201 |
|
|---|
| 202 | se_disp(rpc, D_BAK, gdstbc, 1); /* display event */
|
|---|
| 203 | rpc = rpc->e_bak; /* point at next event */
|
|---|
| 204 |
|
|---|
| 205 | if (rpc->e_type EQ EV_SCORE) /* stop at end of score */
|
|---|
| 206 | break;
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | if (rpf->e_type NE EV_SCORE) { /* up to end of score */
|
|---|
| 211 |
|
|---|
| 212 | while (rpf->e_time EQ rtf) { /* check event time */
|
|---|
| 213 |
|
|---|
| 214 | se_disp(rpf, D_BAK, gdstbn, 0); /* display event */
|
|---|
| 215 | rpf = rpf->e_bak; /* next event pointer */
|
|---|
| 216 |
|
|---|
| 217 | if (rpf->e_type EQ EV_SCORE) /* stop at end of score */
|
|---|
| 218 | break;
|
|---|
| 219 | }
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | if (0 EQ (rtf % mod48)) { /* handle beat markers */
|
|---|
| 223 |
|
|---|
| 224 | if ((struct gdsel *)NULL NE (gdsp = gdfsep)) {
|
|---|
| 225 |
|
|---|
| 226 | gdfsep = gdsp->next;
|
|---|
| 227 |
|
|---|
| 228 | gdsp->next = gdstbn[12];
|
|---|
| 229 | gdsp->note = 0x1111;
|
|---|
| 230 | gdsp->code = 1;
|
|---|
| 231 |
|
|---|
| 232 | gdstbn[12] = gdsp;
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | sc_adv(); /* scroll the display */
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | p_fwd = rpf; /* update p_fwd */
|
|---|
| 241 | t_fwd = tval + TO_FWD; /* update t_fwd */
|
|---|
| 242 |
|
|---|
| 243 | p_ctr = rpc; /* update p_ctr */
|
|---|
| 244 | t_ctr = tval; /* update t_ctr */
|
|---|
| 245 |
|
|---|
| 246 | p_bak = rpb; /* update p_bak */
|
|---|
| 247 | t_bak = tval - TO_BAK; /* update t_bak */
|
|---|
| 248 |
|
|---|
| 249 | DB_CMNT("sc_trak - dslocn");
|
|---|
| 250 | dslocn(); /* display current location */
|
|---|
| 251 |
|
|---|
| 252 | #ifdef DEBUG_TR
|
|---|
| 253 | if (debugsw) {
|
|---|
| 254 |
|
|---|
| 255 | printf("\n## sc_trak(%10ld) EXIT - fc_val=%10ld sbase=%d soffset=%d\n",
|
|---|
| 256 | tval, fc_val, sbase, soffset);
|
|---|
| 257 |
|
|---|
| 258 | printf(" p_bak: %08lX, p_ctr: %08lX, p_fwd: %08lX\n",
|
|---|
| 259 | p_bak, p_ctr, p_fwd);
|
|---|
| 260 |
|
|---|
| 261 | printf(" t_bak: %10ld, t_ctr: %10ld, t_fwd: %10ld\n",
|
|---|
| 262 | t_bak, t_ctr, t_fwd);
|
|---|
| 263 |
|
|---|
| 264 | printf(" T.bak: %10ld T.ctr: %10ld T.fwd: %10ld\n",
|
|---|
| 265 | p_bak->e_time, p_ctr->e_time, p_fwd->e_time);
|
|---|
| 266 | }
|
|---|
| 267 | #endif
|
|---|
| 268 |
|
|---|
| 269 | DB_EXIT("sc_trak");
|
|---|
| 270 | return(SUCCESS);
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | /*
|
|---|
| 274 | =============================================================================
|
|---|
| 275 | sc_trek(tval) -- follow score chain such that t_cur EQ 'tval'
|
|---|
| 276 | =============================================================================
|
|---|
| 277 | */
|
|---|
| 278 |
|
|---|
| 279 | int16_t sc_trek(int32_t tval)
|
|---|
| 280 | {
|
|---|
| 281 | register struct s_entry *rp, *ep;
|
|---|
| 282 | register int32_t rt;
|
|---|
| 283 | register int16_t et, grp;
|
|---|
| 284 |
|
|---|
| 285 | DB_ENTR("sc_trek");
|
|---|
| 286 |
|
|---|
| 287 | #ifdef CHECKPTR
|
|---|
| 288 | Pcheck(p_cur, "p_cur - sc_trek - entry");
|
|---|
| 289 | #endif
|
|---|
| 290 |
|
|---|
| 291 | if (p_cur EQ E_NULL) {
|
|---|
| 292 |
|
|---|
| 293 | DB_EXIT("sc_trek - NULL ptr");
|
|---|
| 294 | return(FAILURE);
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | rp = p_cur; /* current event pointer */
|
|---|
| 298 | rt = t_cur; /* current event time */
|
|---|
| 299 |
|
|---|
| 300 | DB_CMNT("sc_trek - chasing p_cur");
|
|---|
| 301 |
|
|---|
| 302 | #ifdef DEBUGGER
|
|---|
| 303 | if (se EQ D_FWD)
|
|---|
| 304 | DB_CMNT("sc_trek - forward");
|
|---|
| 305 | else
|
|---|
| 306 | DB_CMNT("sc_trek - backward");
|
|---|
| 307 | #endif
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 | while (rt NE tval) { /* track tval */
|
|---|
| 311 |
|
|---|
| 312 | if (se EQ D_FWD)
|
|---|
| 313 | ++rt;
|
|---|
| 314 | else
|
|---|
| 315 | --rt;
|
|---|
| 316 |
|
|---|
| 317 | if (rp->e_type NE EV_FINI) {
|
|---|
| 318 |
|
|---|
| 319 | while (rp->e_time EQ rt) { /* process events a rt */
|
|---|
| 320 |
|
|---|
| 321 | /* "erase head" logic */
|
|---|
| 322 |
|
|---|
| 323 | if (recsw AND (se EQ D_FWD)) {
|
|---|
| 324 |
|
|---|
| 325 | et = 0x007F & rp->e_type;
|
|---|
| 326 |
|
|---|
| 327 | if ((NOT dubsw) AND
|
|---|
| 328 | ((et EQ EV_NBEG) OR (et EQ EV_NEND))) {
|
|---|
| 329 |
|
|---|
| 330 | grp = rp->e_data2;
|
|---|
| 331 |
|
|---|
| 332 | if (grpstat[grp] AND (2 EQ grpmode[grp])) {
|
|---|
| 333 |
|
|---|
| 334 | DB_CMNT("sc_trek - erasing note");
|
|---|
| 335 |
|
|---|
| 336 | /* erasing a note */
|
|---|
| 337 |
|
|---|
| 338 | ep = rp->e_fwd;
|
|---|
| 339 |
|
|---|
| 340 | if (rp EQ p_bak)
|
|---|
| 341 | p_bak = ep;
|
|---|
| 342 |
|
|---|
| 343 | if (rp EQ p_cur)
|
|---|
| 344 | p_cur = ep;
|
|---|
| 345 |
|
|---|
| 346 | if (rp EQ p_ctr)
|
|---|
| 347 | p_ctr = ep;
|
|---|
| 348 |
|
|---|
| 349 | if (rp EQ p_fwd)
|
|---|
| 350 | p_fwd = ep;
|
|---|
| 351 |
|
|---|
| 352 | e_del(e_rmv(rp));
|
|---|
| 353 | rp = ep;
|
|---|
| 354 | goto nextev;
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | } else if (et EQ EV_ANVL) {
|
|---|
| 358 |
|
|---|
| 359 | grp = 0x000F & rp->e_data1;
|
|---|
| 360 |
|
|---|
| 361 | if (grpstat[grp] AND (2 EQ (ancmsw ?
|
|---|
| 362 | varmode[0x000F & (rp->e_data1 >> 4)][grp] :
|
|---|
| 363 | grpmode[grp]))) {
|
|---|
| 364 |
|
|---|
| 365 | DB_CMNT("sc_trek - erasing var");
|
|---|
| 366 |
|
|---|
| 367 | /* erasing an analog variable */
|
|---|
| 368 |
|
|---|
| 369 | ep = rp->e_fwd;
|
|---|
| 370 |
|
|---|
| 371 | if (rp EQ p_bak)
|
|---|
| 372 | p_bak = ep;
|
|---|
| 373 |
|
|---|
| 374 | if (rp EQ p_cur)
|
|---|
| 375 | p_cur = ep;
|
|---|
| 376 |
|
|---|
| 377 | if (rp EQ p_ctr)
|
|---|
| 378 | p_ctr = ep;
|
|---|
| 379 |
|
|---|
| 380 | if (rp EQ p_fwd)
|
|---|
| 381 | p_fwd = ep;
|
|---|
| 382 |
|
|---|
| 383 | e_del(e_rmv(rp));
|
|---|
| 384 | rp = ep;
|
|---|
| 385 | goto nextev;
|
|---|
| 386 | }
|
|---|
| 387 | }
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | if (rp->e_time EQ rt) { /* check event time */
|
|---|
| 391 |
|
|---|
| 392 | se_exec(rp, se); /* execute event */
|
|---|
| 393 |
|
|---|
| 394 | if (se EQ D_FWD)
|
|---|
| 395 | rp = rp->e_fwd; /* point at next event */
|
|---|
| 396 | else
|
|---|
| 397 | rp = rp->e_bak; /* point at next event */
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | nextev:
|
|---|
| 401 | if (((se EQ D_FWD) AND (rp->e_type EQ EV_FINI)) OR
|
|---|
| 402 | ((se EQ D_BAK) AND (rp->e_type EQ EV_SCORE)))
|
|---|
| 403 | break;
|
|---|
| 404 | }
|
|---|
| 405 | }
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | p_cur = rp; /* update p_cur */
|
|---|
| 409 | t_cur = tval; /* update t_cur */
|
|---|
| 410 |
|
|---|
| 411 | DB_EXIT("sc_trek");
|
|---|
| 412 | return(SUCCESS);
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|