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

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

Removed redundant declarations.

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