[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
|
---|
| 17 | short 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] | 27 | int16_t delpnts(void)
|
---|
[f40a309] | 28 | {
|
---|
[8c8b4e5] | 29 | struct instpnt *pp;
|
---|
| 30 | int8_t *pp1, *pp2;
|
---|
| 31 | int16_t np, pt1, i, pif, cf;
|
---|
[f40a309] | 32 | struct idfnhdr *fp;
|
---|
| 33 | struct instdef *vp;
|
---|
[8c8b4e5] | 34 | volatile uint16_t *fpu;
|
---|
[7258c6a] | 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) =
|
---|
[de91266] | 96 | (uint16_t)(fp->idftmd = (fp->idftmd & ~3) | 1);
|
---|
[f40a309] | 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 |
|
---|
[de91266] | 108 | for (i = nmv * (int16_t)PT_SIZE; i > 0; i--)
|
---|
[f40a309] | 109 | *pp1++ = *pp2++;
|
---|
| 110 |
|
---|
| 111 | /* adjust total points remaining */
|
---|
| 112 |
|
---|
[de91266] | 113 | vp->idhplft = (int8_t)(vp->idhplft + np);
|
---|
[f40a309] | 114 |
|
---|
| 115 | /* adjust number of points in this function */
|
---|
| 116 |
|
---|
[de91266] | 117 | vp->idhfnc[curfunc].idfpif =
|
---|
| 118 | (int8_t)(vp->idhfnc[curfunc].idfpif - np);
|
---|
[f40a309] | 119 |
|
---|
| 120 | /* adjust starting points in other functions */
|
---|
| 121 |
|
---|
| 122 | for (cf = curfunc + 1; cf < NFINST; cf++)
|
---|
[de91266] | 123 | vp->idhfnc[cf].idfpt1 =
|
---|
| 124 | (int8_t)(vp->idhfnc[cf].idfpt1 - np);
|
---|
[f40a309] | 125 |
|
---|
| 126 | setipl(oldi); /* +++++ restore interrupts +++++ */
|
---|
| 127 |
|
---|
| 128 | edfunc(curfunc); /* set new current point */
|
---|
| 129 | subj -= 1;
|
---|
[fa38804] | 130 |
|
---|
[f40a309] | 131 | } else { /* deleting all points */
|
---|
| 132 |
|
---|
| 133 | /* reset first point in function */
|
---|
| 134 |
|
---|
| 135 | pp = &vp->idhpnt[fp->idfpt1];
|
---|
| 136 |
|
---|
| 137 | pp->iptim = FPU_MINT;
|
---|
| 138 | pp->ipval = finival[curfunc];
|
---|
| 139 | pp->ipvmlt = 0;
|
---|
| 140 | pp->ipvsrc = SM_NONE;
|
---|
| 141 | pp->ipact = AC_NULL;
|
---|
| 142 | pp->ippar1 = 0;
|
---|
| 143 | pp->ippar2 = 0;
|
---|
| 144 | pp->ippar3 = 0;
|
---|
| 145 |
|
---|
| 146 | /* adjust functions */
|
---|
| 147 |
|
---|
| 148 | if (np > 1) { /* if deleting more points than 1 ... */
|
---|
| 149 |
|
---|
| 150 | --nmv; /* one less point to move */
|
---|
| 151 | ++pt1; /* start one slot up */
|
---|
| 152 |
|
---|
| 153 | /* move points down */
|
---|
| 154 |
|
---|
| 155 | pp1 = &vp->idhpnt[pt1];
|
---|
| 156 | pp2 = &vp->idhpnt[pt2];
|
---|
| 157 |
|
---|
[de91266] | 158 | for (i = nmv * (int16_t)PT_SIZE; i > 0; i--)
|
---|
[f40a309] | 159 | *pp1++ = *pp2++;
|
---|
| 160 |
|
---|
| 161 | /* adjust total points remaining */
|
---|
| 162 |
|
---|
[de91266] | 163 | vp->idhplft = (int8_t)(vp->idhplft + (np - 1));
|
---|
[f40a309] | 164 |
|
---|
| 165 | /* adjust number of points in this function */
|
---|
| 166 |
|
---|
[de91266] | 167 | vp->idhfnc[curfunc].idfpif =
|
---|
| 168 | (int8_t)(vp->idhfnc[curfunc].idfpif - (np - 1));
|
---|
[f40a309] | 169 |
|
---|
| 170 | /* adjust starting points in other functions */
|
---|
| 171 |
|
---|
| 172 | for (cf = curfunc + 1; cf < NFINST; cf++)
|
---|
[de91266] | 173 | vp->idhfnc[cf].idfpt1 =
|
---|
| 174 | (int8_t)(vp->idhfnc[cf].idfpt1 - (np - 1));
|
---|
[f40a309] | 175 | }
|
---|
| 176 |
|
---|
| 177 | setipl(oldi); /* restore interrupts */
|
---|
| 178 |
|
---|
| 179 | edfunc(curfunc); /* make point 0 current */
|
---|
| 180 | subj = 0;
|
---|
[9519422] | 181 | }
|
---|
[f40a309] | 182 |
|
---|
[fa38804] | 183 |
|
---|
[f40a309] | 184 | #if DEBUGIT
|
---|
| 185 | if (debugsw AND debugdf) {
|
---|
| 186 |
|
---|
| 187 | printf("delpnts(): plft = %3d pif = %3d subj = %3d\n",
|
---|
| 188 | vp->idhplft, vp->idhfnc[curfunc].idfpif, subj);
|
---|
| 189 |
|
---|
| 190 | printf(" fnc pif\n");
|
---|
| 191 |
|
---|
| 192 | for (cf = 0; cf < NFINST; cf++)
|
---|
| 193 | printf(" %3d %3d%s\n",
|
---|
| 194 | cf, vp->idhfnc[cf].idfpif,
|
---|
| 195 | (cf EQ curfunc) ? " <-- curfunc" : "");
|
---|
| 196 |
|
---|
| 197 | printf("\n");
|
---|
| 198 | }
|
---|
| 199 | #endif
|
---|
| 200 |
|
---|
| 201 | pntsel();
|
---|
| 202 | pntsv = 0;
|
---|
| 203 | showpt(1);
|
---|
| 204 | modinst();
|
---|
| 205 |
|
---|
| 206 | return(SUCCESS);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | /*
|
---|
| 210 | =============================================================================
|
---|
| 211 | inspnt() -- insert a new point into a function
|
---|
| 212 | =============================================================================
|
---|
| 213 | */
|
---|
| 214 |
|
---|
[7258c6a] | 215 | int16_t inspnt(struct instdef *ip, int16_t fn, int16_t inpnt)
|
---|
[f40a309] | 216 | {
|
---|
[7258c6a] | 217 | register int8_t *fp1, *fp2;
|
---|
| 218 | register int16_t i, j, k, l, npts;
|
---|
| 219 | int16_t topnt, frompt, oldi;
|
---|
[f40a309] | 220 |
|
---|
| 221 | if (ip->idhplft EQ 0) /* see if instrument has points left */
|
---|
| 222 | return(FALSE);
|
---|
| 223 |
|
---|
| 224 | if (ip->idhfnc[fn].idfpif EQ 99) /* see if function is full */
|
---|
| 225 | return(FALSE);
|
---|
| 226 |
|
---|
| 227 | topnt = NIPNTS - ip->idhplft; /* calculate move parameters */
|
---|
| 228 | frompt = topnt - 1;
|
---|
| 229 | npts = frompt - inpnt;
|
---|
| 230 | i = topnt;
|
---|
| 231 | j = frompt;
|
---|
| 232 |
|
---|
| 233 | #if D_INSPNT
|
---|
| 234 | if (debugsw)
|
---|
| 235 | printf("inspnt(): fn=%d, in=%d, to=%d, from=%d, npts=%d, pif=%d\r\n",
|
---|
| 236 | fn, inpnt, topnt, frompt, npts, ip->idhfnc[fn].idfpif);
|
---|
| 237 | #endif
|
---|
| 238 |
|
---|
[fa38804] | 239 |
|
---|
[f40a309] | 240 | oldi = setipl(FPU_DI); /* disable FPU interrupts */
|
---|
| 241 |
|
---|
| 242 | /* ++++++++++++++++++++++++ FPU interrupts disabled +++++++++++++++++++++++++ */
|
---|
| 243 |
|
---|
| 244 | for (k = 0; k < npts; k++) { /* move things up */
|
---|
| 245 |
|
---|
| 246 | fp1 = &ip->idhpnt[i--];
|
---|
| 247 | fp2 = &ip->idhpnt[j--];
|
---|
| 248 |
|
---|
| 249 | for (l = 0; l < sizeof (struct instpnt); l++)
|
---|
| 250 | *fp1++ = *fp2++;
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | for (i = fn + 1; i < NFINST; i++) { /* update point numbers */
|
---|
| 254 |
|
---|
| 255 | ++ip->idhfnc[i].idfpt1; /* first point */
|
---|
| 256 | ++ip->idhfnc[i].idfcpt; /* current point */
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | setipl(oldi); /* restore interrupts */
|
---|
| 260 |
|
---|
| 261 | /* ++++++++++++++++++++++++++ Interrupts restored +++++++++++++++++++++++++++ */
|
---|
| 262 |
|
---|
| 263 | ++ip->idhfnc[fn].idfpif; /* update point totals */
|
---|
| 264 | --ip->idhplft;
|
---|
| 265 |
|
---|
| 266 | #if D_INSPNT
|
---|
| 267 | if (debugsw)
|
---|
| 268 | printf("inspnt(): idfpif=%d, idhplft=%d\r\n",
|
---|
| 269 | ip->idhfnc[fn].idfpif, ip->idhplft);
|
---|
| 270 | #endif
|
---|
| 271 |
|
---|
| 272 | return(TRUE);
|
---|
| 273 | }
|
---|
[6262b5c] | 274 |
|
---|