source: buchla-68k/ram/wdfield.c@ 06f6615

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

Zero redundant declarations.

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