source: buchla-68k/ram/wdfield.c@ 84c0125

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

Work around parser issue.

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