1 | /*
|
---|
2 | =============================================================================
|
---|
3 | wsdsp.c -- MIDAS waveshape editor display driver
|
---|
4 | Version 35 -- 1988-09-09 -- D.N. Lynx Crowe
|
---|
5 | =============================================================================
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "all.h"
|
---|
9 |
|
---|
10 | /* things defined elsewhere */
|
---|
11 |
|
---|
12 | extern uint16_t exp_c(uint16_t c);
|
---|
13 |
|
---|
14 | extern void (*point)(int16_t x, int16_t y, int16_t pen);
|
---|
15 |
|
---|
16 | extern uint16_t *obj0;
|
---|
17 |
|
---|
18 | extern int8_t bfs[];
|
---|
19 |
|
---|
20 | extern int8_t *wdbxlb0[];
|
---|
21 | extern int8_t *wdbxlb1[];
|
---|
22 |
|
---|
23 | extern int16_t wdbox[][8];
|
---|
24 |
|
---|
25 | extern struct instdef vbufs[];
|
---|
26 |
|
---|
27 | /* |
---|
28 |
|
---|
29 | */
|
---|
30 |
|
---|
31 | extern int16_t curinst;
|
---|
32 | extern int16_t curvce;
|
---|
33 | extern int16_t curwave; /* current waveshape library slot */
|
---|
34 | extern int16_t curwdth; /* current waveshape cursor width */
|
---|
35 | extern int16_t curwfnl; /* current waveshape final value */
|
---|
36 | extern int16_t curwhrm; /* current waveshape harmonic number */
|
---|
37 | extern int16_t curwhrv; /* current waveshape harmonic value */
|
---|
38 | extern int16_t curwpnt; /* current waveshape point number */
|
---|
39 | extern int16_t curwoff; /* current waveshape offset value */
|
---|
40 | extern int16_t curwslt; /* current waveshape instrument slot */
|
---|
41 | extern int16_t cxval;
|
---|
42 | extern int16_t cyval;
|
---|
43 | extern int16_t lstwoff;
|
---|
44 | extern int16_t lstwpnt;
|
---|
45 | extern int16_t stccol;
|
---|
46 | extern int16_t stcrow;
|
---|
47 | extern int16_t wpntsv; /* waveshape point selection state variable */
|
---|
48 | extern int16_t wplast;
|
---|
49 | extern int16_t wvlast;
|
---|
50 |
|
---|
51 | extern int16_t vmtab[NUMHARM]; /* harmonic table */
|
---|
52 | extern int16_t wsbuf[NUMWPCAL]; /* waveshape generation buffer */
|
---|
53 |
|
---|
54 | extern int32_t vknm[NUMHARM][NUMWPCAL]; /* scaled harmonics */
|
---|
55 |
|
---|
56 | extern uint16_t *waveob; /* waveshape display object pointer */
|
---|
57 |
|
---|
58 | extern int16_t wsnmod[12][2]; /* waveshape number or data modified */
|
---|
59 |
|
---|
60 | extern struct wstbl wslib[NUMWAVS]; /* waveshape library */
|
---|
61 |
|
---|
62 | extern struct octent *wdoct; /* object control table pointer */
|
---|
63 |
|
---|
64 | /* forward references */
|
---|
65 |
|
---|
66 | void wdpoint(int16_t x, int16_t y, int16_t pen);
|
---|
67 |
|
---|
68 | extern void arcurs(uint16_t icolor);
|
---|
69 | extern void clrwsa(void);
|
---|
70 | extern void dswap(void);
|
---|
71 | extern void itcini(uint16_t color);
|
---|
72 | extern void itcpos(int16_t row, int16_t col);
|
---|
73 | extern void newws(void);
|
---|
74 | extern void setgc(int16_t xv, int16_t yv);
|
---|
75 | extern void updfpu(void);
|
---|
76 | extern void vsndpal(int16_t pp[16][3]);
|
---|
77 |
|
---|
78 | /* |
---|
79 |
|
---|
80 | */
|
---|
81 |
|
---|
82 | int16_t wavpal[16][3] = { /* waveshape display color palette */
|
---|
83 |
|
---|
84 | {0, 0, 0}, /* 0 */
|
---|
85 | {3, 3, 3}, /* 1 */
|
---|
86 | {2, 2, 2}, /* 2 */
|
---|
87 | {0, 1, 1}, /* 3 (was 0, 1, 0) */
|
---|
88 | {1, 0, 1}, /* 4 */
|
---|
89 | {0, 1, 1}, /* 5 (was 0, 1, 0) */
|
---|
90 | {2, 1, 2}, /* 6 */
|
---|
91 | {0, 3, 0}, /* 7 */
|
---|
92 | {2, 0, 0}, /* 8 */
|
---|
93 | {2, 0, 2}, /* 9 */
|
---|
94 | {0, 0, 0}, /* 10 */
|
---|
95 | {2, 3, 3}, /* 11 */
|
---|
96 | {3, 3, 0}, /* 12 */
|
---|
97 | {3, 0, 0}, /* 13 */
|
---|
98 | {0, 0, 1}, /* 14 (was 0, 0, 2) */
|
---|
99 | {0, 0, 3} /* 15 */
|
---|
100 | };
|
---|
101 |
|
---|
102 | /* |
---|
103 |
|
---|
104 | */
|
---|
105 |
|
---|
106 | /*
|
---|
107 | =============================================================================
|
---|
108 | advwcur() -- advance the waveshape display text cursor
|
---|
109 | =============================================================================
|
---|
110 | */
|
---|
111 |
|
---|
112 | void advwcur(void)
|
---|
113 | {
|
---|
114 | register int16_t newcol;
|
---|
115 |
|
---|
116 | newcol = stccol + 1;
|
---|
117 |
|
---|
118 | if (newcol LE cfetp->frcol)
|
---|
119 | itcpos(stcrow, newcol);
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* |
---|
123 |
|
---|
124 | */
|
---|
125 |
|
---|
126 | /*
|
---|
127 | =============================================================================
|
---|
128 | hdraw(h) -- draw harmonic 'h' for the current waveshape
|
---|
129 | =============================================================================
|
---|
130 | */
|
---|
131 |
|
---|
132 | void hdraw(int16_t *hv, int16_t h)
|
---|
133 | {
|
---|
134 | register int16_t bc, bx, by, j;
|
---|
135 |
|
---|
136 | bx = (h << 4) + 4;
|
---|
137 |
|
---|
138 | if (hv[h] < 0) {
|
---|
139 |
|
---|
140 | by = WBOFF - ((-hv[h] * WBSF1) / WBSF2);
|
---|
141 | bc = WBCN;
|
---|
142 |
|
---|
143 | } else {
|
---|
144 |
|
---|
145 | by = WBOFF - ((hv[h] * WBSF1) / WBSF2);
|
---|
146 | bc = WBCP;
|
---|
147 | }
|
---|
148 |
|
---|
149 | for (j = 0; j < 8; j++) {
|
---|
150 |
|
---|
151 | lseg(bx, WBOFF, bx, by, bc);
|
---|
152 | ++bx;
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | /* |
---|
157 |
|
---|
158 | */
|
---|
159 |
|
---|
160 | /*
|
---|
161 | =============================================================================
|
---|
162 | dsws() -- display the current waveshape
|
---|
163 | =============================================================================
|
---|
164 | */
|
---|
165 |
|
---|
166 | void dsws(int16_t how)
|
---|
167 | {
|
---|
168 | register struct instdef *ip;
|
---|
169 | register int16_t *fv, *hv, *ov;
|
---|
170 | register int16_t i;
|
---|
171 | int16_t cx;
|
---|
172 |
|
---|
173 | cx = exp_c(wdbox[0][0]);
|
---|
174 |
|
---|
175 | ip = &vbufs[curvce];
|
---|
176 | fv = curwslt ? &ip->idhwvbf : &ip->idhwvaf;
|
---|
177 | ov = curwslt ? &ip->idhwvbo : &ip->idhwvao;
|
---|
178 | hv = curwslt ? &ip->idhwvbh : &ip->idhwvah;
|
---|
179 |
|
---|
180 | point = wdpoint;
|
---|
181 |
|
---|
182 | if (v_regs[5] & 0x0180)
|
---|
183 | vbank(0);
|
---|
184 |
|
---|
185 | if (how)
|
---|
186 | vbfill4(waveob, 128, wdbox[0][0], wdbox[0][1],
|
---|
187 | wdbox[0][2], wdbox[0][3], cx);
|
---|
188 |
|
---|
189 | lseg(1, 133, 510, 133, WZBC); /* draw the zero line and ... */
|
---|
190 | lseg(1, (WPOFF << 1), 510, (WPOFF << 1), WZBC); /* ... bottom limit */
|
---|
191 |
|
---|
192 | for (i = 0; i < NUMHARM; i++) /* draw the harmonics */
|
---|
193 | hdraw(hv, i);
|
---|
194 |
|
---|
195 | for (i = 0; i < NUMWPNT; i++) { /* draw the values */
|
---|
196 |
|
---|
197 | /* offset values */
|
---|
198 |
|
---|
199 | wdpoint(((2 * i) + 2),
|
---|
200 | (WPOFF - (((ov[i] >> 5) * WPSF1) / WPSF2)), WOVC);
|
---|
201 |
|
---|
202 | /* final values */
|
---|
203 |
|
---|
204 | wdpoint(((2 * i) + 2),
|
---|
205 | (WPOFF - (((fv[i] >> 5) * WPSF1) / WPSF2)), WFVC);
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | /* |
---|
210 |
|
---|
211 | */
|
---|
212 |
|
---|
213 | /*
|
---|
214 | =============================================================================
|
---|
215 | wdswin() -- display a window
|
---|
216 | =============================================================================
|
---|
217 | */
|
---|
218 |
|
---|
219 | void wdswin(int16_t n)
|
---|
220 | {
|
---|
221 | register int16_t cx, wval;
|
---|
222 | register int8_t wsgn;
|
---|
223 |
|
---|
224 | cx = wdbox[n][5];
|
---|
225 | cx |= cx << 4;
|
---|
226 | cx |= cx << 8;
|
---|
227 |
|
---|
228 | /* first, fill the box with the background color */
|
---|
229 |
|
---|
230 | if (v_regs[5] & 0x0180)
|
---|
231 | vbank(0);
|
---|
232 |
|
---|
233 | vbfill4(waveob, 128, wdbox[n][0], wdbox[n][1], wdbox[n][2],
|
---|
234 | wdbox[n][3], cx);
|
---|
235 |
|
---|
236 | /* put in the box label */
|
---|
237 |
|
---|
238 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6], wdbox[n][7],
|
---|
239 | wdbxlb0[n], 14);
|
---|
240 |
|
---|
241 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1, wdbox[n][7],
|
---|
242 | wdbxlb1[n], 14);
|
---|
243 |
|
---|
244 | /* |
---|
245 |
|
---|
246 | */
|
---|
247 | switch (n) { /* final text - overlays above stuff */
|
---|
248 |
|
---|
249 | case 0: /* points and bars */
|
---|
250 |
|
---|
251 | dsws(0);
|
---|
252 | return;
|
---|
253 |
|
---|
254 | case 2: /* waveshape - voice - instrument - slot */
|
---|
255 |
|
---|
256 | sprintf(bfs, "%02d", curwave + 1);
|
---|
257 | tsplot4(waveob, 64,
|
---|
258 | exp_c(wsnmod[curvce][curwslt] ? WS_CHGC : wdbox[n][4]),
|
---|
259 | wdbox[n][6], wdbox[n][7] + WAVE_OFF, bfs, 14);
|
---|
260 |
|
---|
261 | sprintf(bfs, "%02d", curvce + 1);
|
---|
262 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
|
---|
263 | wdbox[n][7] + WVCE_OFF, bfs, 14);
|
---|
264 |
|
---|
265 | sprintf(bfs, "%02d", curinst);
|
---|
266 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
|
---|
267 | wdbox[n][7] + WINS_OFF, bfs, 14);
|
---|
268 |
|
---|
269 | sprintf(bfs, "%c", curwslt + 'A');
|
---|
270 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
|
---|
271 | wdbox[n][7] + WSLT_OFF, bfs, 14);
|
---|
272 |
|
---|
273 | return;
|
---|
274 |
|
---|
275 | /* |
---|
276 |
|
---|
277 | */
|
---|
278 | case 4: /* point - offset - width - final */
|
---|
279 |
|
---|
280 | sprintf(bfs, "%03d", curwpnt);
|
---|
281 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
|
---|
282 | wdbox[n][7] + WPNT_OFF, bfs, 14);
|
---|
283 |
|
---|
284 | if (curwoff < 0) {
|
---|
285 |
|
---|
286 | wval = - curwoff;
|
---|
287 | wsgn = '-';
|
---|
288 |
|
---|
289 | } else {
|
---|
290 |
|
---|
291 | wval = curwoff;
|
---|
292 | wsgn = '+';
|
---|
293 | }
|
---|
294 |
|
---|
295 | sprintf(bfs, "%c%04d", wsgn, wval);
|
---|
296 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
|
---|
297 | wdbox[n][7] + WOFF_OFF, bfs, 14);
|
---|
298 |
|
---|
299 | if (curwdth EQ NUMWIDS) {
|
---|
300 |
|
---|
301 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
|
---|
302 | wdbox[n][7], "Interp", 14);
|
---|
303 |
|
---|
304 | } else {
|
---|
305 |
|
---|
306 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
|
---|
307 | wdbox[n][7], "Width", 14);
|
---|
308 |
|
---|
309 | sprintf(bfs, "%01d", curwdth);
|
---|
310 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
|
---|
311 | wdbox[n][7] + WDTH_OFF, bfs, 14);
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (curwfnl < 0) {
|
---|
315 |
|
---|
316 | wval = - curwfnl;
|
---|
317 | wsgn = '-';
|
---|
318 |
|
---|
319 | } else {
|
---|
320 |
|
---|
321 | wval = curwfnl;
|
---|
322 | wsgn = '+';
|
---|
323 | }
|
---|
324 |
|
---|
325 | sprintf(bfs, "%c%04d", wsgn, wval);
|
---|
326 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
|
---|
327 | wdbox[n][7] + WFNL_OFF, bfs, 14);
|
---|
328 |
|
---|
329 | return;
|
---|
330 | /* |
---|
331 |
|
---|
332 | */
|
---|
333 | case 5: /* harmonic - value */
|
---|
334 |
|
---|
335 | sprintf(bfs, "%02d", curwhrm + 1);
|
---|
336 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
|
---|
337 | wdbox[n][7] + WHRM_OFF, bfs, 14);
|
---|
338 |
|
---|
339 | if (curwhrv < 0) {
|
---|
340 |
|
---|
341 | wval = - curwhrv;
|
---|
342 | wsgn = '-';
|
---|
343 |
|
---|
344 | } else {
|
---|
345 |
|
---|
346 | wval = curwhrv;
|
---|
347 | wsgn = '+';
|
---|
348 | }
|
---|
349 |
|
---|
350 | sprintf(bfs, "%c%03d", wsgn, wval);
|
---|
351 | tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
|
---|
352 | wdbox[n][7] + WHRV_OFF, bfs, 14);
|
---|
353 |
|
---|
354 | return;
|
---|
355 |
|
---|
356 | }
|
---|
357 | }
|
---|
358 |
|
---|
359 | /* |
---|
360 |
|
---|
361 | */
|
---|
362 |
|
---|
363 | /*
|
---|
364 | =============================================================================
|
---|
365 | wwins() -- display all waveshape editor windows
|
---|
366 | =============================================================================
|
---|
367 | */
|
---|
368 |
|
---|
369 | void wwins(void)
|
---|
370 | {
|
---|
371 | register int16_t i;
|
---|
372 |
|
---|
373 | for (i = 0; i < 6; i++)
|
---|
374 | wdswin(i);
|
---|
375 | }
|
---|
376 |
|
---|
377 | /*
|
---|
378 | =============================================================================
|
---|
379 | wdpoint() -- plot a point for the lseg function
|
---|
380 | =============================================================================
|
---|
381 | */
|
---|
382 |
|
---|
383 | void wdpoint(int16_t x, int16_t y, int16_t pen)
|
---|
384 | {
|
---|
385 | if (v_regs[5] & 0x0180)
|
---|
386 | vbank(0);
|
---|
387 |
|
---|
388 | vputp(wdoct, x, y, pen);
|
---|
389 | }
|
---|
390 |
|
---|
391 | /* |
---|
392 |
|
---|
393 | */
|
---|
394 |
|
---|
395 | /*
|
---|
396 | =============================================================================
|
---|
397 | wdbord() -- draw the border for the waveshape display
|
---|
398 | =============================================================================
|
---|
399 | */
|
---|
400 |
|
---|
401 | void wdbord(void)
|
---|
402 | {
|
---|
403 | point = wdpoint;
|
---|
404 |
|
---|
405 | lseg( 0, 0, 511, 0, WBORD); /* outer border */
|
---|
406 | lseg(511, 0, 511, 349, WBORD);
|
---|
407 | lseg(511, 349, 0, 349, WBORD);
|
---|
408 | lseg( 0, 349, 0, 0, WBORD);
|
---|
409 |
|
---|
410 | lseg( 0, 308, 511, 308, WBORD); /* windows - H lines */
|
---|
411 | lseg(511, 321, 0, 321, WBORD);
|
---|
412 |
|
---|
413 | lseg(175, 322, 175, 349, WBORD); /* windows - V lines */
|
---|
414 | lseg(231, 322, 231, 349, WBORD);
|
---|
415 | lseg(399, 322, 399, 349, WBORD);
|
---|
416 | }
|
---|
417 |
|
---|
418 | /* |
---|
419 |
|
---|
420 | */
|
---|
421 |
|
---|
422 | /*
|
---|
423 | =============================================================================
|
---|
424 | clrws() -- initialize waveshape to null values
|
---|
425 | =============================================================================
|
---|
426 | */
|
---|
427 |
|
---|
428 | void clrws(void)
|
---|
429 | {
|
---|
430 | register struct instdef *ip;
|
---|
431 |
|
---|
432 | ip = &vbufs[curvce];
|
---|
433 |
|
---|
434 | if (curwslt) {
|
---|
435 |
|
---|
436 | memsetw(ip->idhwvbh, 0, NUMHARM);
|
---|
437 | memsetw(ip->idhwvbo, 0, NUMWPNT);
|
---|
438 | memsetw(ip->idhwvbf, 0, NUMWPNT);
|
---|
439 |
|
---|
440 | } else {
|
---|
441 |
|
---|
442 | memsetw(ip->idhwvah, 0, NUMHARM);
|
---|
443 | memsetw(ip->idhwvao, 0, NUMWPNT);
|
---|
444 | memsetw(ip->idhwvaf, 0, NUMWPNT);
|
---|
445 | }
|
---|
446 |
|
---|
447 | clrwsa();
|
---|
448 |
|
---|
449 | lstwpnt = wplast = curwpnt;
|
---|
450 |
|
---|
451 | lstwoff = wvlast = curwfnl = curwoff = 0;
|
---|
452 |
|
---|
453 | curwhrv = 0;
|
---|
454 |
|
---|
455 | updfpu(); /* update the FPU */
|
---|
456 | wsnmod[curvce][curwslt] = TRUE; /* tag WS as modified */
|
---|
457 | }
|
---|
458 |
|
---|
459 | /* |
---|
460 |
|
---|
461 | */
|
---|
462 |
|
---|
463 | /*
|
---|
464 | =============================================================================
|
---|
465 | iniwslb() -- initialize waveshape library
|
---|
466 | =============================================================================
|
---|
467 | */
|
---|
468 |
|
---|
469 | void iniwslb(void)
|
---|
470 | {
|
---|
471 | register int16_t i, j;
|
---|
472 |
|
---|
473 | memsetw(wsnmod, FALSE, (sizeof wsnmod) / 2);
|
---|
474 |
|
---|
475 | for (i = 0; i < NUMWAVS; i++) {
|
---|
476 |
|
---|
477 | for (j = 0; j < NUMWPNT; j++) {
|
---|
478 |
|
---|
479 | wslib[i].final[j] = ((j + 1) << 8) ^ 0x8000;
|
---|
480 | wslib[i].offset[j] = ((j + 1) << 8) ^ 0x8000;
|
---|
481 | }
|
---|
482 |
|
---|
483 | memsetw(wslib[i].harmon, 0, NUMHARM); /* zero harmonics */
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | /* |
---|
488 |
|
---|
489 | */
|
---|
490 |
|
---|
491 | /*
|
---|
492 | =============================================================================
|
---|
493 | wsdsp() -- put up the waveshape display
|
---|
494 | =============================================================================
|
---|
495 | */
|
---|
496 |
|
---|
497 | void wsdsp(void)
|
---|
498 | {
|
---|
499 | waveob = &v_score[0]; /* setup object pointer */
|
---|
500 | obj0 = &v_curs0[0]; /* setup cursor object pointer */
|
---|
501 | wdoct = &v_obtab[WAVEOBJ]; /* setup object control table pointer */
|
---|
502 |
|
---|
503 | wpntsv = 0; /* point selection state = unselected */
|
---|
504 | newws(); /* set editing variables */
|
---|
505 |
|
---|
506 | dswap(); /* initialize display */
|
---|
507 |
|
---|
508 | if (v_regs[5] & 0x0180)
|
---|
509 | vbank(0);
|
---|
510 |
|
---|
511 | memsetw(waveob, 0, 32767);
|
---|
512 | memsetw(waveob+32767L, 0, 12033);
|
---|
513 |
|
---|
514 | SetObj(WAVEOBJ, 0, 0, waveob, 512, 350, 0, 0, WAVEFL, -1);
|
---|
515 | SetObj( 0, 0, 1, obj0, 16, 16, WCURX, WCURY, OBFL_00, -1);
|
---|
516 |
|
---|
517 | arcurs(WDCURS); /* setup arrow cursor object */
|
---|
518 | itcini(WDCURS); /* setup text cursor object */
|
---|
519 |
|
---|
520 | wdbord(); /* draw the border */
|
---|
521 | wwins();
|
---|
522 |
|
---|
523 | SetPri(WAVEOBJ, WAVEPRI);
|
---|
524 | SetPri(0, GCPRI);
|
---|
525 | setgc(WCURX, WCURY); /* display the graphic cursor */
|
---|
526 |
|
---|
527 | vsndpal(wavpal); /* send the palette */
|
---|
528 | }
|
---|
529 |
|
---|