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

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

Zero redundant declarations.

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