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