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