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

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

Added missing includes and declarations.

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