source: buchla-68k/ram/wsdsp.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: 11.2 KB
RevLine 
[f40a309]1/*
2 =============================================================================
3 wsdsp.c -- MIDAS waveshape editor display driver
4 Version 35 -- 1988-09-09 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "stddefs.h"
9#include "memory.h"
10
11#include "fpu.h"
12#include "hwdefs.h"
13#include "vsdd.h"
14#include "vsddsw.h"
15#include "vsddvars.h"
16#include "graphdef.h"
17#include "charset.h"
18#include "fields.h"
19
20#include "midas.h"
21#include "instdsp.h"
22#include "wsdsp.h"
23
[e225e77]24#include "stdio.h"
25
[f40a309]26/* things defined elsewhere */
27
[7258c6a]28extern uint16_t exp_c(uint16_t c);
[f40a309]29
[7258c6a]30extern void (*point)(int16_t x, int16_t y, int16_t pen);
[f40a309]31
[7258c6a]32extern uint16_t *obj0;
[f40a309]33
[7258c6a]34extern int8_t bfs[];
[f40a309]35
[7258c6a]36extern int8_t *wdbxlb0[];
37extern int8_t *wdbxlb1[];
[f40a309]38
[7258c6a]39extern int16_t wdbox[][8];
[f40a309]40
41extern struct instdef vbufs[];
42
43/*
44
45*/
[7258c6a]46
47extern int16_t curinst;
48extern int16_t curvce;
49extern int16_t curwave; /* current waveshape library slot */
50extern int16_t curwdth; /* current waveshape cursor width */
51extern int16_t curwfnl; /* current waveshape final value */
52extern int16_t curwhrm; /* current waveshape harmonic number */
53extern int16_t curwhrv; /* current waveshape harmonic value */
54extern int16_t curwpnt; /* current waveshape point number */
55extern int16_t curwoff; /* current waveshape offset value */
56extern int16_t curwslt; /* current waveshape instrument slot */
57extern int16_t cxval;
58extern int16_t cyval;
59extern int16_t lstwoff;
60extern int16_t lstwpnt;
61extern int16_t stccol;
62extern int16_t stcrow;
63extern int16_t wpntsv; /* waveshape point selection state variable */
64extern int16_t wplast;
65extern int16_t wvlast;
66
67extern int16_t vmtab[NUMHARM]; /* harmonic table */
68extern int16_t wsbuf[NUMWPCAL]; /* waveshape generation buffer */
69
70extern int32_t vknm[NUMHARM][NUMWPCAL]; /* scaled harmonics */
71
72extern uint16_t *waveob; /* waveshape display object pointer */
73
[f40a309]74extern int16_t wsnmod[12][2]; /* waveshape number or data modified */
75
76extern struct wstbl wslib[NUMWAVS]; /* waveshape library */
77
78extern struct octent *wdoct; /* object control table pointer */
79
80/* forward references */
[7258c6a]81
[f40a309]82void wdpoint(int16_t x, int16_t y, int16_t pen);
[e225e77]83
84extern void arcurs(uint16_t icolor);
85extern void clrwsa(void);
86extern void dswap(void);
87extern void itcini(uint16_t color);
88extern void itcpos(int16_t row, int16_t col);
89extern void newws(void);
90extern void setgc(int16_t xv, int16_t yv);
91extern void updfpu(void);
92extern void vsndpal(int16_t pp[16][3]);
[f40a309]93
94/*
95
[7258c6a]96*/
[f40a309]97
98int16_t wavpal[16][3] = { /* waveshape display color palette */
99
100 {0, 0, 0}, /* 0 */
101 {3, 3, 3}, /* 1 */
102 {2, 2, 2}, /* 2 */
103 {0, 1, 1}, /* 3 (was 0, 1, 0) */
104 {1, 0, 1}, /* 4 */
105 {0, 1, 1}, /* 5 (was 0, 1, 0) */
106 {2, 1, 2}, /* 6 */
107 {0, 3, 0}, /* 7 */
108 {2, 0, 0}, /* 8 */
109 {2, 0, 2}, /* 9 */
110 {0, 0, 0}, /* 10 */
111 {2, 3, 3}, /* 11 */
112 {3, 3, 0}, /* 12 */
113 {3, 0, 0}, /* 13 */
114 {0, 0, 1}, /* 14 (was 0, 0, 2) */
115 {0, 0, 3} /* 15 */
116};
117
118/*
119
120*/
121
122/*
123 =============================================================================
124 advwcur() -- advance the waveshape display text cursor
[0580615]125 =============================================================================
[f40a309]126*/
[7258c6a]127
[f40a309]128void advwcur(void)
129{
130 register int16_t newcol;
131
132 newcol = stccol + 1;
133
134 if (newcol LE cfetp->frcol)
135 itcpos(stcrow, newcol);
136}
137
138/*
139
140*/
141
142/*
143 =============================================================================
[7258c6a]144 hdraw(h) -- draw harmonic 'h' for the current waveshape
[f40a309]145 =============================================================================
[7258c6a]146*/
[f40a309]147
148void hdraw(int16_t *hv, int16_t h)
149{
150 register int16_t bc, bx, by, j;
151
152 bx = (h << 4) + 4;
153
154 if (hv[h] < 0) {
155
156 by = WBOFF - ((-hv[h] * WBSF1) / WBSF2);
157 bc = WBCN;
158
159 } else {
160
161 by = WBOFF - ((hv[h] * WBSF1) / WBSF2);
162 bc = WBCP;
163 }
164
165 for (j = 0; j < 8; j++) {
166
167 lseg(bx, WBOFF, bx, by, bc);
168 ++bx;
169 }
170}
171
172/*
173
174*/
175
176/*
[7258c6a]177 =============================================================================
[f40a309]178 dsws() -- display the current waveshape
179 =============================================================================
[7258c6a]180*/
181
182void dsws(int16_t how)
[f40a309]183{
184 register struct instdef *ip;
185 register int16_t *fv, *hv, *ov;
186 register int16_t i;
187 int16_t cx;
188
189 cx = exp_c(wdbox[0][0]);
190
191 ip = &vbufs[curvce];
192 fv = curwslt ? &ip->idhwvbf : &ip->idhwvaf;
193 ov = curwslt ? &ip->idhwvbo : &ip->idhwvao;
194 hv = curwslt ? &ip->idhwvbh : &ip->idhwvah;
195
196 point = wdpoint;
197
198 if (v_regs[5] & 0x0180)
199 vbank(0);
200
201 if (how)
202 vbfill4(waveob, 128, wdbox[0][0], wdbox[0][1],
203 wdbox[0][2], wdbox[0][3], cx);
204
205 lseg(1, 133, 510, 133, WZBC); /* draw the zero line and ... */
206 lseg(1, (WPOFF << 1), 510, (WPOFF << 1), WZBC); /* ... bottom limit */
207
208 for (i = 0; i < NUMHARM; i++) /* draw the harmonics */
209 hdraw(hv, i);
210
211 for (i = 0; i < NUMWPNT; i++) { /* draw the values */
212
213 /* offset values */
214
215 wdpoint(((2 * i) + 2),
216 (WPOFF - (((ov[i] >> 5) * WPSF1) / WPSF2)), WOVC);
217
218 /* final values */
219
220 wdpoint(((2 * i) + 2),
221 (WPOFF - (((fv[i] >> 5) * WPSF1) / WPSF2)), WFVC);
222 }
223}
224
225/*
226
227*/
228
[7258c6a]229/*
[f40a309]230 =============================================================================
[7258c6a]231 wdswin() -- display a window
232 =============================================================================
[f40a309]233*/
234
235void wdswin(int16_t n)
236{
237 register int16_t cx, wval;
238 register int8_t wsgn;
239
240 cx = wdbox[n][5];
241 cx |= cx << 4;
242 cx |= cx << 8;
243
244 /* first, fill the box with the background color */
245
246 if (v_regs[5] & 0x0180)
247 vbank(0);
248
249 vbfill4(waveob, 128, wdbox[n][0], wdbox[n][1], wdbox[n][2],
250 wdbox[n][3], cx);
251
252 /* put in the box label */
253
254 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6], wdbox[n][7],
255 wdbxlb0[n], 14);
256
257 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1, wdbox[n][7],
258 wdbxlb1[n], 14);
259
260/*
261
262*/
263 switch (n) { /* final text - overlays above stuff */
264
265 case 0: /* points and bars */
266
267 dsws(0);
268 return;
269
270 case 2: /* waveshape - voice - instrument - slot */
271
272 sprintf(bfs, "%02d", curwave + 1);
273 tsplot4(waveob, 64,
274 exp_c(wsnmod[curvce][curwslt] ? WS_CHGC : wdbox[n][4]),
275 wdbox[n][6], wdbox[n][7] + WAVE_OFF, bfs, 14);
276
277 sprintf(bfs, "%02d", curvce + 1);
278 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
279 wdbox[n][7] + WVCE_OFF, bfs, 14);
280
281 sprintf(bfs, "%02d", curinst);
282 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
283 wdbox[n][7] + WINS_OFF, bfs, 14);
284
285 sprintf(bfs, "%c", curwslt + 'A');
286 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
287 wdbox[n][7] + WSLT_OFF, bfs, 14);
288
289 return;
290
291/*
292
293*/
294 case 4: /* point - offset - width - final */
295
296 sprintf(bfs, "%03d", curwpnt);
297 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
298 wdbox[n][7] + WPNT_OFF, bfs, 14);
299
300 if (curwoff < 0) {
301
302 wval = - curwoff;
303 wsgn = '-';
304
305 } else {
306
307 wval = curwoff;
308 wsgn = '+';
309 }
310
311 sprintf(bfs, "%c%04d", wsgn, wval);
312 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
313 wdbox[n][7] + WOFF_OFF, bfs, 14);
314
315 if (curwdth EQ NUMWIDS) {
316
317 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
318 wdbox[n][7], "Interp", 14);
319
320 } else {
321
322 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
323 wdbox[n][7], "Width", 14);
324
325 sprintf(bfs, "%01d", curwdth);
326 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
327 wdbox[n][7] + WDTH_OFF, bfs, 14);
328 }
329
330 if (curwfnl < 0) {
331
332 wval = - curwfnl;
333 wsgn = '-';
334
335 } else {
336
337 wval = curwfnl;
338 wsgn = '+';
339 }
340
341 sprintf(bfs, "%c%04d", wsgn, wval);
342 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
343 wdbox[n][7] + WFNL_OFF, bfs, 14);
344
345 return;
346/*
347
348*/
349 case 5: /* harmonic - value */
350
351 sprintf(bfs, "%02d", curwhrm + 1);
352 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6],
353 wdbox[n][7] + WHRM_OFF, bfs, 14);
354
355 if (curwhrv < 0) {
356
357 wval = - curwhrv;
358 wsgn = '-';
359
360 } else {
361
362 wval = curwhrv;
363 wsgn = '+';
364 }
365
366 sprintf(bfs, "%c%03d", wsgn, wval);
367 tsplot4(waveob, 64, wdbox[n][4], wdbox[n][6] + 1,
368 wdbox[n][7] + WHRV_OFF, bfs, 14);
369
370 return;
371
372 }
373}
374
[0580615]375/*
[f40a309]376
[7258c6a]377*/
[f40a309]378
379/*
380 =============================================================================
381 wwins() -- display all waveshape editor windows
382 =============================================================================
383*/
384
385void wwins(void)
386{
387 register int16_t i;
388
[7258c6a]389 for (i = 0; i < 6; i++)
[f40a309]390 wdswin(i);
391}
392
393/*
394 =============================================================================
395 wdpoint() -- plot a point for the lseg function
396 =============================================================================
397*/
398
399void wdpoint(int16_t x, int16_t y, int16_t pen)
400{
401 if (v_regs[5] & 0x0180)
402 vbank(0);
403
404 vputp(wdoct, x, y, pen);
405}
[0580615]406
[f40a309]407/*
408
409*/
410
411/*
412 =============================================================================
413 wdbord() -- draw the border for the waveshape display
414 =============================================================================
415*/
416
417void wdbord(void)
418{
419 point = wdpoint;
420
421 lseg( 0, 0, 511, 0, WBORD); /* outer border */
422 lseg(511, 0, 511, 349, WBORD);
423 lseg(511, 349, 0, 349, WBORD);
424 lseg( 0, 349, 0, 0, WBORD);
425
426 lseg( 0, 308, 511, 308, WBORD); /* windows - H lines */
427 lseg(511, 321, 0, 321, WBORD);
428
429 lseg(175, 322, 175, 349, WBORD); /* windows - V lines */
430 lseg(231, 322, 231, 349, WBORD);
431 lseg(399, 322, 399, 349, WBORD);
[0580615]432}
[f40a309]433
434/*
435
436*/
437
438/*
439 =============================================================================
440 clrws() -- initialize waveshape to null values
441 =============================================================================
442*/
443
444void clrws(void)
445{
446 register struct instdef *ip;
447
448 ip = &vbufs[curvce];
449
450 if (curwslt) {
451
452 memsetw(ip->idhwvbh, 0, NUMHARM);
453 memsetw(ip->idhwvbo, 0, NUMWPNT);
454 memsetw(ip->idhwvbf, 0, NUMWPNT);
455
456 } else {
457
458 memsetw(ip->idhwvah, 0, NUMHARM);
459 memsetw(ip->idhwvao, 0, NUMWPNT);
460 memsetw(ip->idhwvaf, 0, NUMWPNT);
461 }
462
463 clrwsa();
464
465 lstwpnt = wplast = curwpnt;
466
467 lstwoff = wvlast = curwfnl = curwoff = 0;
468
469 curwhrv = 0;
470
471 updfpu(); /* update the FPU */
[0580615]472 wsnmod[curvce][curwslt] = TRUE; /* tag WS as modified */
[f40a309]473}
[7258c6a]474
[f40a309]475/*
476
477*/
478
479/*
480 =============================================================================
481 iniwslb() -- initialize waveshape library
482 =============================================================================
483*/
484
485void iniwslb(void)
486{
487 register int16_t i, j;
488
[9519422]489 memsetw(wsnmod, FALSE, (sizeof wsnmod) / 2);
[f40a309]490
491 for (i = 0; i < NUMWAVS; i++) {
492
493 for (j = 0; j < NUMWPNT; j++) {
494
495 wslib[i].final[j] = ((j + 1) << 8) ^ 0x8000;
496 wslib[i].offset[j] = ((j + 1) << 8) ^ 0x8000;
497 }
498
[0580615]499 memsetw(wslib[i].harmon, 0, NUMHARM); /* zero harmonics */
[f40a309]500 }
501}
502
503/*
504
505*/
506
507/*
508 =============================================================================
509 wsdsp() -- put up the waveshape display
510 =============================================================================
511*/
512
513void wsdsp(void)
514{
515 waveob = &v_score[0]; /* setup object pointer */
516 obj0 = &v_curs0[0]; /* setup cursor object pointer */
517 wdoct = &v_obtab[WAVEOBJ]; /* setup object control table pointer */
518
519 wpntsv = 0; /* point selection state = unselected */
520 newws(); /* set editing variables */
521
522 dswap(); /* initialize display */
523
524 if (v_regs[5] & 0x0180)
525 vbank(0);
526
527 memsetw(waveob, 0, 32767);
528 memsetw(waveob+32767L, 0, 12033);
529
530 SetObj(WAVEOBJ, 0, 0, waveob, 512, 350, 0, 0, WAVEFL, -1);
531 SetObj( 0, 0, 1, obj0, 16, 16, WCURX, WCURY, OBFL_00, -1);
532
533 arcurs(WDCURS); /* setup arrow cursor object */
534 itcini(WDCURS); /* setup text cursor object */
535
536 wdbord(); /* draw the border */
537 wwins();
538
539 SetPri(WAVEOBJ, WAVEPRI);
540 SetPri(0, GCPRI);
541 setgc(WCURX, WCURY); /* display the graphic cursor */
542
543 vsndpal(wavpal); /* send the palette */
544}
Note: See TracBrowser for help on using the repository browser.