source: buchla-68k/ram/wdfield.c@ 7ecfb7b

Last change on this file since 7ecfb7b was 7ecfb7b, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Unused variables and parameters.

  • Property mode set to 100644
File size: 14.0 KB
Line 
1/*
2 =============================================================================
3 wdfield.c -- waveshape display field processing and cursor motion
4 Version 46 -- 1989-11-15 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DOUBLED 1 /* non-zero for doubled WS outputs */
9
10#include "ram.h"
11
12#define WCSCALE 32768L
13#define WCROUND 16384L
14
15#include "wdcurtb.h" /* int16_t wdcurtb[]; int16_t wdcurct[8][2]; */
16
17int16_t wxrate = 1; /* WS interpolate X movement increment */
18
19struct fet wd_fet1[] = {
20
21 {23, 10, 11, 0x0002, et_wavs, ef_wavs, rd_wavs, nd_wavs},
22 {23, 19, 20, 0x0102, et_wvce, ef_wvce, rd_wvce, nd_wvce},
23 {23, 34, 36, 0x0004, et_wpnt, ef_wpnt, rd_wpnt, nd_wpnt},
24 {23, 44, 48, 0x0104, et_woff, ef_woff, rd_woff, nd_woff},
25 {23, 61, 62, 0x0005, et_whar, ef_whar, rd_whar, nd_whar},
26
27 {24, 20, 20, 0x0302, et_wslt, ef_wslt, rd_wslt, nd_wslt},
28 {24, 57, 60, 0x0105, et_whrv, ef_whrv, rd_whrv, nd_whrv},
29
30 { 0, 0, 0, 0x0000, FN_NULL, FN_NULL, FN_NULL, FN_NULL}
31};
32
33int16_t wdbox[][8] = { /* display box parameters */
34
35 { 1, 1, 510, 307, WCFBX00, WCBBX00, 0, 1}, /* 0 */
36 { 1, 309, 510, 320, WCFBX01, WCBBX01, 22, 0}, /* 1 */
37 { 1, 322, 174, 348, WCFBX02, WCBBX02, 23, 1}, /* 2 */
38 {176, 322, 230, 348, WCFBX03, WCBBX03, 23, 23}, /* 3 */
39 {232, 322, 398, 348, WCFBX04, WCBBX04, 23, 30}, /* 4 */
40 {400, 322, 510, 348, WCFBX05, WCBBX05, 23, 51} /* 5 */
41};
42
43int8_t *wdbxlb0[] = { /* display box labels -- row 0 */
44
45 "", /* 0 */
46
47 "\320\301 \320\303 \320\305 \320\307 \320\311 \
48\321\301 \321\303 \321\305 \321\307 \321\311 \
49\322\301 \322\303 \322\305 \322\307 \322\311 \323\301 ", /* 1 */
50
51 "Waveshpe Voice", /* 2 */
52 "Store", /* 3 */
53 "Pnt Offst", /* 4 */
54 "Harmonic #" /* 5 */
55};
56
57int8_t *wdbxlb1[] = { /* display box labels -- row 1 */
58
59 "", /* 0 */
60 "", /* 1 */
61 "Instrument Slot", /* 2 */
62 "Fetch", /* 3 */
63 " Final", /* 4 */
64 "Value" /* 5 */
65};
66
67struct curpak wd_flds = {
68
69 stdctp1, /* curtype */
70 nokey, /* premove */
71 nokey, /* pstmove */
72 cxkstd, /* cx_key */
73 cykstd, /* cy_key */
74 wdcxupd, /* cx_upd */
75 wdcyupd, /* cy_upd */
76 wdykup, /* xy_up */
77 wdykdn, /* xy_dn */
78 wdxkey, /* x_key */
79 select, /* e_key */
80 stdmkey, /* m_key */
81 stddkey, /* d_key */
82 wdnfld, /* not_fld */
83 wd_fet1, /* curfet */
84 wdboxes, /* csbp */
85 crate1, /* cratex */
86 crate1, /* cratey */
87 CT_GRAF, /* cmtype */
88 WCURX, /* cxval */
89 WCURY /* cyval */
90};
91
92/*
93 =============================================================================
94 updfpu() -- update the FPU with a new waveshape
95 =============================================================================
96*/
97
98void updfpu(void)
99{
100 register int16_t *wsp1, *wsp2;
101
102 /* calculate instrument source and FPU destination pointers */
103
104 wsp1 = io_fpu + FPU_OWST + (curvce << 9) + (curwslt ? 0 : 0x0100) + 1;
105 wsp2 = curwslt ? vbufs[curvce].idhwvbf : vbufs[curvce].idhwvaf;
106
107 memcpyw(wsp1, wsp2, NUMWPNT);
108
109 /* make endpoints track */
110
111 *(wsp1 - 1) = *(wsp2 - 1); /* lowest point */
112 *(wsp1 + NUMWPNT) = *(wsp2 + NUMWPNT - 1); /* highest point */
113
114#if DOUBLED
115
116 /* do outputs again to get around hardware bug */
117
118 memcpyw(wsp1, wsp2, NUMWPNT);
119
120 *(wsp1 - 1) = *(wsp2 - 1); /* lowest point */
121 *(wsp1 + NUMWPNT) = *(wsp2 + NUMWPNT - 1); /* highest point */
122#endif
123
124 curwfnl = wsp2[curwpnt] >> 5; /* udpate final value */
125}
126
127/*
128 =============================================================================
129 wsupd() -- update the instrument definition and FPU for new WS offsets
130 =============================================================================
131*/
132
133void wsupd(void)
134{
135 register int16_t i;
136 register int16_t *wsp1, *wsp2;
137
138 /* update the offsets[] array from the instrument definition */
139
140 wsp2 = curwslt ? vbufs[curvce].idhwvbo : vbufs[curvce].idhwvao;
141
142 for (i = 0; i < NUMWPNT; i++)
143 offsets[i + 1] = wsp2[i] >> 5;
144
145 offsets[0] = offsets[1];
146
147 wscalc(); /* calculate the final values */
148
149 /* update the final values in the instrument definition */
150
151 wsp1 = curwslt ? vbufs[curvce].idhwvbf : vbufs[curvce].idhwvaf;
152
153 for (i = 0; i < NUMWPNT; i++)
154 wsp1[i] = wsbuf[1 + i] << 5;
155
156 updfpu();
157 wsnmod[curvce][curwslt] = TRUE; /* tag WS as modified */
158}
159
160/*
161 =============================================================================
162 whupd() -- update the FPU for new WS harmonics
163 =============================================================================
164*/
165
166void whupd(void)
167{
168 register int16_t i;
169 register int16_t *wsp1;
170
171 /* update the final values in the instrument definition */
172
173 wsp1 = curwslt ? vbufs[curvce].idhwvbf : vbufs[curvce].idhwvaf;
174
175 for (i = 0; i < NUMWPNT; i++)
176 wsp1[i] = wsbuf[i + 1] << 5;
177
178 updfpu(); /* update the FPU */
179 wsnmod[curvce][curwslt] = TRUE; /* tag WS as modified */
180}
181
182/*
183 =============================================================================
184 pntsup() -- update waveshape points with the cursor 'brush'
185 =============================================================================
186*/
187
188void pntsup(void)
189{
190 register struct instdef *ip;
191 int16_t *ov;
192 register int16_t i, j, k, tv, curdif;
193 int16_t cwnp, cwin;
194
195 ip = &vbufs[curvce]; /* instrument definition */
196
197 ov = curwslt ? &ip->idhwvbo /* offsets in definition */
198 : &ip->idhwvao;
199
200 cwnp = wdcurct[curwdth][0]; /* number of points effected */
201
202 cwin = wdcurct[curwdth][1]; /* table increment */
203
204 curdif = lstwoff - curwoff; /* calculate the difference */
205
206
207 for (i = 0 , k = 0; i < cwnp; i++ , k += cwin) {
208
209 if (i EQ 0) { /* first point */
210
211 ov[curwpnt] = curwoff << 5;
212
213 } else { /* subsequent points */
214
215 j = curwpnt + i; /* update point on the right */
216
217 if (j < NUMWPNT) { /* ... if it exists */
218
219 tv = (ov[j] >> 5) -
220 ((((long)curdif * wdcurtb[k])
221 + WCROUND) / WCSCALE);
222
223 if (tv GT 1023)
224 tv = 1023;
225 else if (tv LT -1023)
226 tv = -1023;
227
228 ov[j] = tv << 5;
229 }
230
231 j = curwpnt - i; /* update point on the left */
232
233 if (j GE 0) { /* ... if it exists */
234
235 tv = (ov[j] >> 5) -
236 ((((long)curdif * wdcurtb[k])
237 + WCROUND) / WCSCALE);
238
239 if (tv GT 1023)
240 tv = 1023;
241 else if (tv LT -1023)
242 tv = -1023;
243
244 ov[j] = tv << 5;
245 }
246 }
247 }
248
249 wsupd();
250}
251
252/*
253 =============================================================================
254 wdintp() -- interpolate between waveshape points
255 =============================================================================
256*/
257
258void wdintp(void)
259{
260 register struct instdef *ip;
261 register int16_t *ov;
262 register int16_t i, j, k, n;
263 register long t;
264 int16_t to, from;
265
266 to = curwpnt;
267 from = wplast;
268
269 ip = &vbufs[curvce];
270 ov = curwslt ? &ip->idhwvbo : &ip->idhwvao;
271
272 ov[curwpnt] = curwoff << 5; /* force current point value */
273
274 if (from > to) { /* make 'from' the leftmost point number */
275
276 i = from;
277 from = to;
278 to = i;
279 }
280
281 n = to - from; /* number of points */
282
283 if (n > 1) { /* have to have at least 1 point difference */
284
285 k = ov[from] >> 5;
286 t = ((long)((long)(ov[to] >> 5) - (long)k) << 16) / n;
287 j = 1 + from;
288 --n;
289
290 for (i = 0; i < n; i++)
291 ov[j++] = ((int16_t)((t * (1 + i)) >> 16) + k) << 5;
292 }
293
294 wplast = curwpnt;
295 wvlast = curwoff;
296
297 wsupd();
298}
299
300/*
301 =============================================================================
302 wdykdn() -- cursor y finger down processing
303 =============================================================================
304*/
305
306void wdykdn(void)
307{
308 if (wpntsv EQ 0)
309 return;
310
311 lstwpnt = curwpnt;
312 lstwoff = curwoff;
313}
314
315/*
316 =============================================================================
317 wdykup() -- cursor y finger up processing
318 =============================================================================
319*/
320
321void wdykup(void)
322{
323 if ((wpntsv EQ 0) OR (wdupdfl EQ FALSE))
324 return;
325
326 if (wpntsv EQ 1) { /* offsets */
327
328 if (curwdth EQ NUMWIDS)
329 wdintp(); /* interpolate mode */
330 else
331 pntsup(); /* brush mode */
332
333 } else { /* harmonics */
334
335 adj(curwhrm); /* adjust vknm[curwhrm][] */
336 wscalc(); /* recalculate the waveshape */
337 whupd(); /* update the FPU */
338 }
339
340 wdswin(0); /* display updated waveshape */
341 wdswin(2);
342 wdswin(4);
343
344 wdupdfl = FALSE;
345}
346
347/*
348 =============================================================================
349 wdcyupd() -- update cursor y location
350 =============================================================================
351*/
352
353void wdcyupd(void)
354{
355 register struct instdef *ip;
356 register int16_t *hv;
357 register int8_t wsgn;
358 int16_t wval;
359
360 ip = &vbufs[curvce];
361
362 switch (wpntsv) {
363
364 case 0: /* nothing selected -- just move cursor */
365
366 cyval += cyrate;
367
368 if (cyval GT (CYMAX - 1))
369 cyval = CYMAX - 1;
370 else if (cyval LT 1)
371 cyval = 1;
372
373 return;
374
375 case 1: /* offset selected */
376
377 curwoff -= cyrate;
378
379 if (curwoff GT 1023)
380 curwoff = 1023;
381 else if (curwoff LT -1023)
382 curwoff = -1023;
383
384 cyval = WPOFF - ((curwoff * WPSF1) / WPSF2);
385
386 if (curwoff < 0) {
387
388 wval = - curwoff;
389 wsgn = '-';
390
391 } else {
392
393 wval = curwoff;
394 wsgn = '+';
395 }
396
397 sprintf(bfs, "%c%04d", wsgn, wval);
398
399 if (v_regs[5] & 0x0180)
400 vbank(0);
401
402 vcputsv(waveob, 64, wdbox[4][4], wdbox[4][5], wdbox[4][6],
403 wdbox[4][7] + WOFF_OFF, bfs, 14);
404
405 wdupdfl = TRUE;
406 return;
407
408 case 2: /* harmonic selected */
409
410 hv = curwslt ? &ip->idhwvbh : &ip->idhwvah;
411
412 curwhrv = abs(hv[curwhrm]) - cyrate;
413
414 if (curwhrv > 100)
415 curwhrv = 100;
416 else if (curwhrv < 0)
417 curwhrv = 0;
418
419 curwhrv = (hv[curwhrm] < 0) ? -curwhrv : curwhrv;
420
421 hv[curwhrm] = curwhrv;
422 vmtab[curwhrm] = curwhrv;
423
424 if (curwhrv < 0) {
425
426 wval = -curwhrv;
427 wsgn = '-';
428
429 } else {
430
431 wval = curwhrv;
432 wsgn = '+';
433 }
434
435 if (v_regs[5] & 0x0180)
436 vbank(0);
437
438 sprintf(bfs, "%c%03d", wsgn, wval);
439
440 vcputsv(waveob, 64, wdbox[5][4], wdbox[5][5],
441 wdbox[5][6] + 1, wdbox[5][7] + WHRV_OFF, bfs, 14);
442
443 if (curwhrv < 0)
444 cyval = WBOFF - ((-curwhrv * WBSF1) / WBSF2);
445 else
446 cyval = WBOFF - ((curwhrv * WBSF1) / WBSF2);
447
448 wdupdfl = TRUE;
449 return;
450 }
451}
452
453/*
454 =============================================================================
455 wdcxupd() -- update cursor x location
456 =============================================================================
457*/
458
459void wdcxupd(void)
460{
461 switch (wpntsv) {
462
463 case 0: /* nothing selected - just move cursor */
464
465 cxval += cxrate;
466
467 if (cxval GT (CXMAX - 1))
468 cxval = CXMAX - 1;
469 else if (cxval LT 1)
470 cxval = 1;
471
472 return;
473
474 case 1: /* offset selected - maybe do interpolate move */
475
476 if (curwdth NE NUMWIDS)
477 return;
478
479 curwpnt += sign(cxrate, wxrate);
480
481 if (curwpnt GE NUMWPNT)
482 curwpnt = NUMWPNT - 1;
483 else if (curwpnt < 0)
484 curwpnt = 0;
485
486 cxval = (curwpnt << 1) + 2;
487
488 if (v_regs[5] & 0x0180)
489 vbank(0);
490
491 sprintf(bfs, "%03d", curwpnt);
492 vcputsv(waveob, 64, wdbox[4][4], wdbox[4][5],
493 wdbox[4][6], wdbox[4][7] + WPNT_OFF, bfs, 14);
494 }
495}
496
497/*
498 =============================================================================
499 wdnfld() -- process not-in-field key entry
500 =============================================================================
501*/
502
503int16_t wdnfld(int16_t k)
504{
505 register int16_t *hv;
506 register struct instdef *ip;
507
508 if (astat) {
509
510 if (whatbox()) {
511
512 ip = &vbufs[curvce];
513 hv = curwslt ? &ip->idhwvbh : &ip->idhwvah;
514
515 if (hitbox EQ 0) { /* waveshape area */
516
517 switch (wpntsv) {
518
519 case 0: /* nothing selected */
520
521 if (k EQ 8) { /* - */
522
523 if (--curwdth < 0)
524 curwdth = NUMWIDS;
525
526 wdswin(4);
527 return(SUCCESS);
528
529 } else if (k EQ 9) { /* + */
530
531 if (++curwdth > NUMWIDS)
532 curwdth = 0;
533
534 wdswin(4);
535 return(SUCCESS);
536 }
537
538 return(FAILURE);
539
540 case 1: /* offset selected */
541
542 if (k EQ 8) { /* - */
543
544 if (curwdth EQ NUMWIDS)
545 return(FAILURE);
546
547 if (--curwdth LT 0)
548 curwdth = NUMWIDS - 1;
549
550 wdswin(4);
551 return(SUCCESS);
552
553 } else if (k EQ 9) { /* + */
554
555 if (curwdth EQ NUMWIDS) {
556
557 wdintp();
558 wdswin(0);
559 wdswin(2);
560
561 } else if (++curwdth GE NUMWIDS)
562 curwdth = 0;
563
564 wdswin(4);
565 return(SUCCESS);
566 }
567
568 return(FAILURE);
569
570 case 2: /* harmonic selected */
571
572 if (k EQ 8) { /* - */
573
574 if (hv[curwhrm] > 0)
575 hv[curwhrm] = -hv[curwhrm];
576 else
577 return(FAILURE);
578
579 } else if (k EQ 9) { /* + */
580
581 if (hv[curwhrm] < 0)
582 hv[curwhrm] = -hv[curwhrm];
583 else
584 return(FAILURE);
585
586 } else {
587
588 return(FAILURE);
589 }
590
591 curwhrv = hv[curwhrm];
592 vmtab[curwhrm] = curwhrv;
593 adj(curwhrm);
594 wscalc();
595 whupd();
596 wdswin(0);
597 wdswin(4);
598 wdswin(5);
599 return(SUCCESS);
600 }
601
602 } else
603 return(FAILURE);
604
605 } else if (hitbox EQ 1) { /* harmonic legend */
606
607 if (k EQ 8) { /* - */
608
609 if (hv[curwhrm] > 0)
610 hv[curwhrm] = -hv[curwhrm];
611 else
612 return(FAILURE);
613
614 } else if (k EQ 9) { /* + */
615
616 if (hv[curwhrm] < 0)
617 hv[curwhrm] = -hv[curwhrm];
618 else
619 return(FAILURE);
620
621 } else {
622
623 return(FAILURE);
624 }
625
626 curwhrv = hv[curwhrm];
627 vmtab[curwhrm] = curwhrv;
628 adj(curwhrm);
629 wscalc();
630 whupd();
631 wdswin(0);
632 wdswin(4);
633 wdswin(5);
634 return(SUCCESS);
635 }
636
637 return(FAILURE);
638 }
639
640 return(FAILURE);
641}
642
643/*
644 =============================================================================
645 wdxkey() -- process X key
646 =============================================================================
647*/
648
649void wdxkey(void)
650{
651 if (NOT astat)
652 return; /* FAILURE */
653
654 stcrow = cyval / 14;
655 stccol = cxval >> 3;
656
657 if (stcrow EQ 23) {
658
659 if ((stccol GE 2) OR (stccol LE 8)) {
660
661 clrws();
662
663 } else if ((stccol GE 38) AND (stccol LE 42)) {
664
665 memsetw(curwslt ? vbufs[curvce].idhwvbo
666 : vbufs[curvce].idhwvbo,
667 0, NUMWPNT);
668
669 curwoff = 0;
670 wsupd();
671
672 } else if ((stccol GE 51) AND (stccol LE 58)) {
673
674 memsetw(vmtab, 0, NUMHARM);
675 curwhrv = 0;
676 wadj();
677 wscalc();
678 whupd();
679
680 } else {
681
682 return; /* FAILURE */
683 }
684
685 wsnmod[curvce][curwslt] = TRUE;
686 wwins();
687 return; /* SUCCESS */
688 }
689
690 return; /* FAILURE */
691}
692
693/*
694 =============================================================================
695 wdfield() -- setup field routines for the waveshape editor
696 =============================================================================
697*/
698
699void wdfield(void)
700{
701 curslim = 307;
702
703 curset(&wd_flds);
704}
Note: See TracBrowser for help on using the repository browser.