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

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

Removed form-feed comments.

  • Property mode set to 100644
File size: 14.1 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 i;
101 register int16_t *wsp1, *wsp2;
102
103 /* calculate instrument source and FPU destination pointers */
104
105 wsp1 = io_fpu + FPU_OWST + (curvce << 9) + (curwslt ? 0 : 0x0100) + 1;
106 wsp2 = curwslt ? vbufs[curvce].idhwvbf : vbufs[curvce].idhwvaf;
107
108 memcpyw(wsp1, wsp2, NUMWPNT);
109
110 /* make endpoints track */
111
112 *(wsp1 - 1) = *(wsp2 - 1); /* lowest point */
113 *(wsp1 + NUMWPNT) = *(wsp2 + NUMWPNT - 1); /* highest point */
114
115#if DOUBLED
116
117 /* do outputs again to get around hardware bug */
118
119 memcpyw(wsp1, wsp2, NUMWPNT);
120
121 *(wsp1 - 1) = *(wsp2 - 1); /* lowest point */
122 *(wsp1 + NUMWPNT) = *(wsp2 + NUMWPNT - 1); /* highest point */
123#endif
124
125 curwfnl = wsp2[curwpnt] >> 5; /* udpate final value */
126}
127
128/*
129 =============================================================================
130 wsupd() -- update the instrument definition and FPU for new WS offsets
131 =============================================================================
132*/
133
134void wsupd(void)
135{
136 register int16_t i;
137 register int16_t *wsp1, *wsp2;
138
139 /* update the offsets[] array from the instrument definition */
140
141 wsp2 = curwslt ? vbufs[curvce].idhwvbo : vbufs[curvce].idhwvao;
142
143 for (i = 0; i < NUMWPNT; i++)
144 offsets[i + 1] = wsp2[i] >> 5;
145
146 offsets[0] = offsets[1];
147
148 wscalc(); /* calculate the final values */
149
150 /* update the final values in the instrument definition */
151
152 wsp1 = curwslt ? vbufs[curvce].idhwvbf : vbufs[curvce].idhwvaf;
153
154 for (i = 0; i < NUMWPNT; i++)
155 wsp1[i] = wsbuf[1 + i] << 5;
156
157 updfpu();
158 wsnmod[curvce][curwslt] = TRUE; /* tag WS as modified */
159}
160
161/*
162 =============================================================================
163 whupd() -- update the FPU for new WS harmonics
164 =============================================================================
165*/
166
167void whupd(void)
168{
169 register int16_t i;
170 register int16_t *wsp1;
171
172 /* update the final values in the instrument definition */
173
174 wsp1 = curwslt ? vbufs[curvce].idhwvbf : vbufs[curvce].idhwvaf;
175
176 for (i = 0; i < NUMWPNT; i++)
177 wsp1[i] = wsbuf[i + 1] << 5;
178
179 updfpu(); /* update the FPU */
180 wsnmod[curvce][curwslt] = TRUE; /* tag WS as modified */
181}
182
183/*
184 =============================================================================
185 pntsup() -- update waveshape points with the cursor 'brush'
186 =============================================================================
187*/
188
189void pntsup(void)
190{
191 register struct instdef *ip;
192 int16_t *ov;
193 register int16_t i, j, k, tv, curdif;
194 int16_t cwnp, cwin;
195
196 ip = &vbufs[curvce]; /* instrument definition */
197
198 ov = curwslt ? &ip->idhwvbo /* offsets in definition */
199 : &ip->idhwvao;
200
201 cwnp = wdcurct[curwdth][0]; /* number of points effected */
202
203 cwin = wdcurct[curwdth][1]; /* table increment */
204
205 curdif = lstwoff - curwoff; /* calculate the difference */
206
207
208 for (i = 0 , k = 0; i < cwnp; i++ , k += cwin) {
209
210 if (i EQ 0) { /* first point */
211
212 ov[curwpnt] = curwoff << 5;
213
214 } else { /* subsequent points */
215
216 j = curwpnt + i; /* update point on the right */
217
218 if (j < NUMWPNT) { /* ... if it exists */
219
220 tv = (ov[j] >> 5) -
221 ((((long)curdif * wdcurtb[k])
222 + WCROUND) / WCSCALE);
223
224 if (tv GT 1023)
225 tv = 1023;
226 else if (tv LT -1023)
227 tv = -1023;
228
229 ov[j] = tv << 5;
230 }
231
232 j = curwpnt - i; /* update point on the left */
233
234 if (j GE 0) { /* ... if it exists */
235
236 tv = (ov[j] >> 5) -
237 ((((long)curdif * wdcurtb[k])
238 + WCROUND) / WCSCALE);
239
240 if (tv GT 1023)
241 tv = 1023;
242 else if (tv LT -1023)
243 tv = -1023;
244
245 ov[j] = tv << 5;
246 }
247 }
248 }
249
250 wsupd();
251}
252
253/*
254 =============================================================================
255 wdintp() -- interpolate between waveshape points
256 =============================================================================
257*/
258
259void wdintp(void)
260{
261 register struct instdef *ip;
262 register int16_t *ov;
263 register int16_t i, j, k, n;
264 register long t;
265 int16_t to, from;
266
267 to = curwpnt;
268 from = wplast;
269
270 ip = &vbufs[curvce];
271 ov = curwslt ? &ip->idhwvbo : &ip->idhwvao;
272
273 ov[curwpnt] = curwoff << 5; /* force current point value */
274
275 if (from > to) { /* make 'from' the leftmost point number */
276
277 i = from;
278 from = to;
279 to = i;
280 }
281
282 n = to - from; /* number of points */
283
284 if (n > 1) { /* have to have at least 1 point difference */
285
286 k = ov[from] >> 5;
287 t = ((long)((long)(ov[to] >> 5) - (long)k) << 16) / n;
288 j = 1 + from;
289 --n;
290
291 for (i = 0; i < n; i++)
292 ov[j++] = ((int16_t)((t * (1 + i)) >> 16) + k) << 5;
293 }
294
295 wplast = curwpnt;
296 wvlast = curwoff;
297
298 wsupd();
299}
300
301/*
302 =============================================================================
303 wdykdn() -- cursor y finger down processing
304 =============================================================================
305*/
306
307void wdykdn(void)
308{
309 if (wpntsv EQ 0)
310 return;
311
312 lstwpnt = curwpnt;
313 lstwoff = curwoff;
314}
315
316/*
317 =============================================================================
318 wdykup() -- cursor y finger up processing
319 =============================================================================
320*/
321
322void wdykup(void)
323{
324 if ((wpntsv EQ 0) OR (wdupdfl EQ FALSE))
325 return;
326
327 if (wpntsv EQ 1) { /* offsets */
328
329 if (curwdth EQ NUMWIDS)
330 wdintp(); /* interpolate mode */
331 else
332 pntsup(); /* brush mode */
333
334 } else { /* harmonics */
335
336 adj(curwhrm); /* adjust vknm[curwhrm][] */
337 wscalc(); /* recalculate the waveshape */
338 whupd(); /* update the FPU */
339 }
340
341 wdswin(0); /* display updated waveshape */
342 wdswin(2);
343 wdswin(4);
344
345 wdupdfl = FALSE;
346}
347
348/*
349 =============================================================================
350 wdcyupd() -- update cursor y location
351 =============================================================================
352*/
353
354void wdcyupd(void)
355{
356 register struct instdef *ip;
357 register int16_t *ov, *hv;
358 register int16_t i, j, k, tv;
359 register int8_t wsgn;
360 int16_t wval, cwnp, cwin;
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.