source: buchla-68k/orig/RAM/DELPNTS.C@ 73dd55f

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

Imported original source code.

  • Property mode set to 100755
File size: 6.7 KB
Line 
1/*
2 =============================================================================
3 delpnts.c -- delete point(s) from (truncate) a function
4 Version 14 -- 1989-12-19 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#define DEBUGIT 0
9
10#define D_INSPNT 0 /* debug inspnt() */
11
12#include "stddefs.h"
13#include "fpu.h"
14#include "graphdef.h"
15#include "hwdefs.h"
16#include "vsdd.h"
17#include "smdefs.h"
18
19#include "midas.h"
20#include "instdsp.h"
21
22#define PT_SIZE (sizeof (struct instpnt))
23
24#if DEBUGIT
25extern short debugsw;
26
27short debugdf = 1;
28#endif
29
30extern short curfunc;
31extern short curvce;
32extern short pntsv;
33extern short subj;
34
35extern short finival[];
36extern short fnoff[];
37
38extern struct instdef vbufs[];
39
40/*
41
42*/
43
44/*
45 =============================================================================
46 delpnts() -- deletes the current point and any points to the right
47 of it in the current function in the current voice.
48 =============================================================================
49*/
50
51short
52delpnts()
53{
54 register struct instpnt *pp;
55 register char *pp1, *pp2;
56 register short np, pt1, i, pif, cf;
57 struct idfnhdr *fp;
58 struct instdef *vp;
59 unsigned *fpu;
60 short pt2, nmv, oldi;
61
62 vp = &vbufs[curvce]; /* voice buffer pointer */
63 fp = &vp->idhfnc[curfunc]; /* function pointer */
64
65 pif = 0x00FF & fp->idfpif; /* number of points in function */
66 np = pif - subj; /* number of points to delete */
67 pt1 = (0x00FF & fp->idfpt1) + subj; /* first point to delete */
68
69#if DEBUGIT
70 if (debugsw AND debugdf) {
71
72 printf("delpnts(): curfunc = %d curvce = %d\n",
73 curfunc, curvce);
74
75 printf("delpnts(): idfpt1=%d, pif=%d, np=%d, pt1=%d, vp=$%lX, fp=$%lX\n",
76 (0x00FF & fp->idfpt1), pif, np, pt1, vp, fp);
77 }
78#endif
79
80 if (np LE 0) /* have to delete at least 1 point */
81 return(FAILURE);
82
83 if (subj GE pif) /* make sure point number is valid */
84 return(FAILURE);
85
86 if ((pif - np) < 0) /* make sure we have enough points */
87 return(FAILURE);
88
89 if ((subj + np) GE (pif + 1)) /* check the span */
90 return(FAILURE);
91
92 pt2 = pt1 + np; /* move from point */
93 nmv = NIPNTS - pt2; /* move count */
94
95#if DEBUGIT
96 if (debugsw AND debugdf) {
97
98 printf("delpnts(): pt2=%d, nmv=%d\n", pt2, nmv);
99
100 printf(" fnc pif\n");
101
102 for (cf = 0; cf < NFINST; cf++)
103 printf(" %3d %3d%s\n",
104 cf, vp->idhfnc[cf].idfpif,
105 (cf EQ curfunc) ? " <-- curfunc" : "");
106
107 printf("\n");
108 }
109#endif
110
111/*
112
113*/
114 oldi = setipl(FPU_DI); /* +++++ disable FPU interrupts +++++ */
115
116 fpu = io_fpu + FPU_OFNC + (curvce << 8); /* get fpu base */
117
118 for (i = 0; i < NFINST; i++) { /* stop all functions for this voice */
119
120 fp = &vp->idhfnc[i]; /* point at the function */
121
122 *(fpu + (fnoff[i] << 4) + FPU_TCTL) =
123 (fp->idftmd = (fp->idftmd & ~3) | 1);
124 }
125
126 fp = &vp->idhfnc[curfunc]; /* point at the function */
127
128 if (subj) { /* deleting trailing points */
129
130 /* move points down */
131
132 pp1 = &vp->idhpnt[pt1];
133 pp2 = &vp->idhpnt[pt2];
134
135 for (i = nmv * PT_SIZE; i > 0; i--)
136 *pp1++ = *pp2++;
137
138 /* adjust total points remaining */
139
140 vp->idhplft += np;
141
142 /* adjust number of points in this function */
143
144 vp->idhfnc[curfunc].idfpif -= np;
145
146 /* adjust starting points in other functions */
147
148 for (cf = curfunc + 1; cf < NFINST; cf++)
149 vp->idhfnc[cf].idfpt1 -= np;
150
151 setipl(oldi); /* +++++ restore interrupts +++++ */
152
153 edfunc(curfunc); /* set new current point */
154 subj -= 1;
155/*
156
157*/
158 } else { /* deleting all points */
159
160 /* reset first point in function */
161
162 pp = &vp->idhpnt[fp->idfpt1];
163
164 pp->iptim = FPU_MINT;
165 pp->ipval = finival[curfunc];
166 pp->ipvmlt = 0;
167 pp->ipvsrc = SM_NONE;
168 pp->ipact = AC_NULL;
169 pp->ippar1 = 0;
170 pp->ippar2 = 0;
171 pp->ippar3 = 0;
172
173 /* adjust functions */
174
175 if (np > 1) { /* if deleting more points than 1 ... */
176
177 --nmv; /* one less point to move */
178 ++pt1; /* start one slot up */
179
180 /* move points down */
181
182 pp1 = &vp->idhpnt[pt1];
183 pp2 = &vp->idhpnt[pt2];
184
185 for (i = nmv * PT_SIZE; i > 0; i--)
186 *pp1++ = *pp2++;
187
188 /* adjust total points remaining */
189
190 vp->idhplft += (np - 1);
191
192 /* adjust number of points in this function */
193
194 vp->idhfnc[curfunc].idfpif -= (np - 1);
195
196 /* adjust starting points in other functions */
197
198 for (cf = curfunc + 1; cf < NFINST; cf++)
199 vp->idhfnc[cf].idfpt1 -= (np - 1);
200 }
201
202 setipl(oldi); /* restore interrupts */
203
204 edfunc(curfunc); /* make point 0 current */
205 subj = 0;
206 }
207
208/*
209
210*/
211#if DEBUGIT
212 if (debugsw AND debugdf) {
213
214 printf("delpnts(): plft = %3d pif = %3d subj = %3d\n",
215 vp->idhplft, vp->idhfnc[curfunc].idfpif, subj);
216
217 printf(" fnc pif\n");
218
219 for (cf = 0; cf < NFINST; cf++)
220 printf(" %3d %3d%s\n",
221 cf, vp->idhfnc[cf].idfpif,
222 (cf EQ curfunc) ? " <-- curfunc" : "");
223
224 printf("\n");
225 }
226#endif
227
228 pntsel();
229 pntsv = 0;
230 showpt(1);
231 modinst();
232
233 return(SUCCESS);
234}
235
236/*
237
238*/
239
240/*
241 =============================================================================
242 inspnt() -- insert a new point into a function
243 =============================================================================
244*/
245
246short
247inspnt(ip, fn, inpnt)
248register struct instdef *ip;
249short fn, inpnt;
250{
251 register char *fp1, *fp2;
252 register short i, j, k, l, npts;
253 short topnt, frompt, oldi;
254
255 if (ip->idhplft EQ 0) /* see if instrument has points left */
256 return(FALSE);
257
258 if (ip->idhfnc[fn].idfpif EQ 99) /* see if function is full */
259 return(FALSE);
260
261 topnt = NIPNTS - ip->idhplft; /* calculate move parameters */
262 frompt = topnt - 1;
263 npts = frompt - inpnt;
264 i = topnt;
265 j = frompt;
266
267#if D_INSPNT
268 if (debugsw)
269 printf("inspnt(): fn=%d, in=%d, to=%d, from=%d, npts=%d, pif=%d\r\n",
270 fn, inpnt, topnt, frompt, npts, ip->idhfnc[fn].idfpif);
271#endif
272
273/*
274
275*/
276 oldi = setipl(FPU_DI); /* disable FPU interrupts */
277
278/* ++++++++++++++++++++++++ FPU interrupts disabled +++++++++++++++++++++++++ */
279
280 for (k = 0; k < npts; k++) { /* move things up */
281
282 fp1 = &ip->idhpnt[i--];
283 fp2 = &ip->idhpnt[j--];
284
285 for (l = 0; l < sizeof (struct instpnt); l++)
286 *fp1++ = *fp2++;
287 }
288
289 for (i = fn + 1; i < NFINST; i++) { /* update point numbers */
290
291 ++ip->idhfnc[i].idfpt1; /* first point */
292 ++ip->idhfnc[i].idfcpt; /* current point */
293 }
294
295 setipl(oldi); /* restore interrupts */
296
297/* ++++++++++++++++++++++++++ Interrupts restored +++++++++++++++++++++++++++ */
298
299 ++ip->idhfnc[fn].idfpif; /* update point totals */
300 --ip->idhplft;
301
302#if D_INSPNT
303 if (debugsw)
304 printf("inspnt(): idfpif=%d, idhplft=%d\r\n",
305 ip->idhfnc[fn].idfpif, ip->idhplft);
306#endif
307
308 return(TRUE);
309}
Note: See TracBrowser for help on using the repository browser.