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