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

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

Code compiles, doesn't link.

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