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

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

Removed form-feed comments.

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