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