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