source: buchla-68k/ram/delpnts.c@ 0c834c5

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

Point of no return.

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