[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | ptread.c -- librarian - read patch functions
|
---|
| 4 | Version 5 -- 1988-11-18 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #define DEBUGRE 0
|
---|
| 9 | #define DEBUGSP 0
|
---|
| 10 |
|
---|
[b28a12e] | 11 | #include "ram.h"
|
---|
[f40a309] | 12 |
|
---|
| 13 | #if DEBUGSP
|
---|
| 14 | short debugsp = 1;
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 | /*
|
---|
| 18 | =============================================================================
|
---|
| 19 | stashp() -- stash an incoming patch
|
---|
| 20 | =============================================================================
|
---|
| 21 | */
|
---|
| 22 |
|
---|
[7258c6a] | 23 | int16_t stashp(void)
|
---|
[f40a309] | 24 | {
|
---|
[7258c6a] | 25 | register int16_t c;
|
---|
| 26 | register uint16_t np, stim;
|
---|
[f40a309] | 27 |
|
---|
| 28 | c = findpte();
|
---|
| 29 |
|
---|
| 30 | if (c EQ 0) { /* old patch -- just update it */
|
---|
| 31 |
|
---|
| 32 | memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
|
---|
| 33 | patches[ptecpos].paspec |= PE_TBIT; /* define it */
|
---|
| 34 |
|
---|
| 35 | #if DEBUGSP
|
---|
| 36 | if (debugsw AND debugsp) {
|
---|
| 37 |
|
---|
| 38 | printf("stashp(): UPDATED\n");
|
---|
| 39 | SnapPTV("stashp");
|
---|
| 40 | }
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
| 43 | return(SUCCESS);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | /* allocate a patch entry and fill it in */
|
---|
| 47 |
|
---|
| 48 | if (0 EQ (ptecpos = pt_alc())) {
|
---|
| 49 |
|
---|
| 50 | #if DEBUGSP
|
---|
| 51 | if (debugsw AND debugsp)
|
---|
| 52 | printf("stashp(): patch table FULL\n");
|
---|
| 53 | #endif
|
---|
| 54 | return(FAILURE); /* no patch entries left */
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | memcpyw(&patches[ptecpos].defnum, &ptebuf.defnum, 6);
|
---|
| 58 | patches[ptecpos].paspec |= PE_TBIT; /* define it */
|
---|
| 59 | stim = TRG_MASK & ptebuf.stmnum;
|
---|
| 60 |
|
---|
| 61 | if (c EQ 1) { /* new patch -- no STM entry yet */
|
---|
| 62 |
|
---|
| 63 | ptepred = 0;
|
---|
| 64 | stmptr[stim] = ptecpos;
|
---|
| 65 | }
|
---|
[fa38804] | 66 |
|
---|
[f40a309] | 67 | /* put patch in STM chain */
|
---|
| 68 |
|
---|
| 69 | if (ptepred) { /* predecessor exits */
|
---|
| 70 |
|
---|
| 71 | ptesucc = patches[ptepred].nextstm;
|
---|
| 72 |
|
---|
| 73 | patches[ptecpos].nextstm = ptesucc;
|
---|
| 74 | patches[ptecpos].prevstm = ptepred;
|
---|
| 75 |
|
---|
| 76 | patches[ptepred].nextstm = ptecpos;
|
---|
| 77 |
|
---|
| 78 | if (ptesucc)
|
---|
| 79 | patches[ptesucc].prevstm = ptecpos;
|
---|
| 80 |
|
---|
| 81 | } else { /* no predecessor */
|
---|
| 82 |
|
---|
| 83 | patches[ptecpos].prevstm = 0;
|
---|
| 84 |
|
---|
| 85 | if (c EQ -1) {
|
---|
| 86 |
|
---|
| 87 | ptesucc = stmptr[stim];
|
---|
| 88 |
|
---|
| 89 | patches[ptecpos].nextstm = ptesucc;
|
---|
| 90 |
|
---|
| 91 | patches[ptesucc].prevstm = ptecpos;
|
---|
| 92 |
|
---|
| 93 | stmptr[stim] = ptecpos;
|
---|
| 94 |
|
---|
| 95 | } else {
|
---|
| 96 |
|
---|
| 97 | patches[ptecpos].nextstm = 0;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
[fa38804] | 100 |
|
---|
[f40a309] | 101 | /* update DEF table */
|
---|
| 102 |
|
---|
| 103 | if (0 EQ (c = finddpe())) {
|
---|
| 104 |
|
---|
| 105 | #if DEBUGSP
|
---|
| 106 | if (debugsw AND debugsp) {
|
---|
| 107 |
|
---|
| 108 | printf("stashp(): defent already exists -- dpecpos = %d\n",
|
---|
| 109 | dpecpos);
|
---|
| 110 |
|
---|
| 111 | printf("stashp(): ENTERED\n");
|
---|
| 112 | SnapPTV("stashp");
|
---|
| 113 | }
|
---|
| 114 | #endif
|
---|
| 115 | return(SUCCESS); /* defent already exists */
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | if (0 EQ (dpecpos = dt_alc())) {
|
---|
| 119 |
|
---|
| 120 | #if DEBUGSP
|
---|
| 121 | if (debugsw AND debugsp)
|
---|
| 122 | printf("stashp(): defent table FULL\n");
|
---|
| 123 | #endif
|
---|
| 124 | return(FAILURE); /* no defents left */
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | defents[dpecpos].nextdef = 0;
|
---|
| 128 | defents[dpecpos].stm = ptebuf.stmnum;
|
---|
| 129 | defents[dpecpos].adspec = ptebuf.paspec;
|
---|
| 130 | defents[dpecpos].adsuba = ptebuf.pasuba;
|
---|
| 131 | defents[dpecpos].addat1 = ptebuf.padat1;
|
---|
| 132 |
|
---|
| 133 | np = TRG_MASK & ptebuf.defnum;
|
---|
| 134 |
|
---|
| 135 | if (c EQ 1) {
|
---|
| 136 |
|
---|
| 137 | dpepred = 0;
|
---|
| 138 | defptr[np] = dpecpos;
|
---|
| 139 | }
|
---|
[fa38804] | 140 |
|
---|
[f40a309] | 141 | if (dpepred) {
|
---|
| 142 |
|
---|
| 143 | dpesucc = defents[dpepred].nextdef;
|
---|
| 144 | defents[dpecpos].nextdef = dpesucc;
|
---|
| 145 | defents[dpepred].nextdef = dpecpos;
|
---|
| 146 |
|
---|
| 147 | } else {
|
---|
| 148 |
|
---|
| 149 | if (c EQ -1) {
|
---|
| 150 |
|
---|
| 151 | dpesucc = defptr[np];
|
---|
| 152 | defents[dpecpos].nextdef = dpesucc;
|
---|
| 153 | defptr[np] = dpecpos;
|
---|
| 154 |
|
---|
| 155 | } else {
|
---|
| 156 |
|
---|
| 157 | defents[dpecpos].nextdef = 0;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | #if DEBUGSP
|
---|
| 162 | if (debugsw AND debugsp) {
|
---|
| 163 |
|
---|
| 164 | printf("stashp(): new defent created -- dpecpos = %d\n",
|
---|
| 165 | dpecpos);
|
---|
| 166 |
|
---|
| 167 | printf("stashp(): ENTERED\n");
|
---|
| 168 | SnapPTV("stashp");
|
---|
| 169 | }
|
---|
| 170 | #endif
|
---|
| 171 | return(SUCCESS);
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | /*
|
---|
| 175 | =============================================================================
|
---|
| 176 | ptioerr() -- put up an I/O error message
|
---|
| 177 | =============================================================================
|
---|
| 178 | */
|
---|
| 179 |
|
---|
[0580615] | 180 | void ptioerr(void)
|
---|
[f40a309] | 181 | {
|
---|
[7258c6a] | 182 | int8_t erms[40];
|
---|
[f40a309] | 183 |
|
---|
| 184 | clrlsel();
|
---|
| 185 |
|
---|
| 186 | sprintf(erms, " errno = %d", errno);
|
---|
| 187 |
|
---|
| 188 | ldermsg("Couldn't read", " the patch table", erms,
|
---|
| 189 | LD_EMCF, LD_EMCB);
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /*
|
---|
| 193 | =============================================================================
|
---|
| 194 | nopatch() -- give an error message after running out of space
|
---|
| 195 | =============================================================================
|
---|
| 196 | */
|
---|
| 197 |
|
---|
[0580615] | 198 | void nopatch(void)
|
---|
[f40a309] | 199 | {
|
---|
| 200 | clrlsel();
|
---|
| 201 |
|
---|
| 202 | ldermsg("Couldn't read", " the patch table.", " Ran out of space",
|
---|
| 203 | LD_EMCF, LD_EMCB);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | /*
|
---|
| 207 | =============================================================================
|
---|
| 208 | ptread() -- read a patch
|
---|
| 209 | =============================================================================
|
---|
| 210 | */
|
---|
| 211 |
|
---|
[7258c6a] | 212 | int16_t ptread(FILE *fp)
|
---|
[f40a309] | 213 | {
|
---|
[7258c6a] | 214 | int8_t cb;
|
---|
[f40a309] | 215 |
|
---|
[7258c6a] | 216 | ldwmsg(" Busy -- please stand by", (int8_t *)NULL, " Reading patches",
|
---|
[f40a309] | 217 | LCFBX10, LCBBX10);
|
---|
| 218 |
|
---|
| 219 | for (;;) {
|
---|
| 220 |
|
---|
| 221 | voidpb(); /* clear the patch buffer */
|
---|
| 222 |
|
---|
| 223 | ptecpos = ptepred = ptesucc = 0;
|
---|
| 224 |
|
---|
| 225 | #if DEBUGRE
|
---|
| 226 | if (debugsw AND debugre)
|
---|
| 227 | printf("ptread(): reading\n");
|
---|
| 228 | #endif
|
---|
| 229 | if (rd_ec(fp, &cb, 1L)) { /* get control byte */
|
---|
| 230 |
|
---|
| 231 | ptioerr();
|
---|
| 232 | return(FAILURE);
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | if (0 EQ cb) /* if it's 0, we're done */
|
---|
| 236 | break;
|
---|
| 237 |
|
---|
| 238 | ptebuf.paspec = PE_TBIT | (PE_SPEC & cb);
|
---|
| 239 |
|
---|
| 240 | if (rd_ec(fp, &ptebuf.defnum, 4L)) /* DEF and STM */
|
---|
| 241 | return(FAILURE);
|
---|
[fa38804] | 242 |
|
---|
[f40a309] | 243 | switch (cb) {
|
---|
| 244 |
|
---|
| 245 | case PA_KEY:
|
---|
| 246 | case PA_TRG:
|
---|
| 247 |
|
---|
| 248 | if (rd_ec(fp, &ptebuf.pasuba, 2L))
|
---|
| 249 | return(FAILURE);
|
---|
| 250 |
|
---|
[7258c6a] | 251 | if (rd_ec(fp, (int8_t *)&ptebuf.padat2 + 1, 1L))
|
---|
[f40a309] | 252 | return(FAILURE);
|
---|
| 253 |
|
---|
| 254 | break;
|
---|
| 255 |
|
---|
| 256 | case PA_PLS:
|
---|
| 257 | case PA_SCTL:
|
---|
| 258 |
|
---|
[7258c6a] | 259 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
[f40a309] | 260 | return(FAILURE);
|
---|
| 261 |
|
---|
[7258c6a] | 262 | if (rd_ec(fp, (int8_t *)&ptebuf.padat2 + 1, 1L))
|
---|
[f40a309] | 263 | return(FAILURE);
|
---|
| 264 |
|
---|
| 265 | break;
|
---|
| 266 |
|
---|
[fa38804] | 267 |
|
---|
[f40a309] | 268 | case PA_LED:
|
---|
| 269 |
|
---|
[7258c6a] | 270 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
[f40a309] | 271 | return(FAILURE);
|
---|
| 272 |
|
---|
| 273 | if (rd_ec(fp, &ptebuf.padat1, 1L))
|
---|
| 274 | return(FAILURE);
|
---|
| 275 |
|
---|
| 276 | break;
|
---|
| 277 |
|
---|
| 278 | case PA_SLIN:
|
---|
| 279 |
|
---|
[7258c6a] | 280 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
[f40a309] | 281 | return(FAILURE);
|
---|
| 282 |
|
---|
| 283 | if (rd_ec(fp, &ptebuf.padat1, 2L))
|
---|
| 284 | return(FAILURE);
|
---|
| 285 |
|
---|
| 286 | break;
|
---|
| 287 |
|
---|
| 288 | case PA_TUNE:
|
---|
| 289 |
|
---|
[7258c6a] | 290 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
[f40a309] | 291 | return(FAILURE);
|
---|
| 292 |
|
---|
| 293 | break;
|
---|
[fa38804] | 294 |
|
---|
[f40a309] | 295 | case PA_RSET:
|
---|
| 296 | case PA_RADD:
|
---|
| 297 |
|
---|
[7258c6a] | 298 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
[f40a309] | 299 | return(FAILURE);
|
---|
| 300 |
|
---|
[7258c6a] | 301 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
[f40a309] | 302 | return(FAILURE);
|
---|
| 303 |
|
---|
[7258c6a] | 304 | if (rd_ec(fp, (int8_t *)&ptebuf.padat2 + 1, 1L))
|
---|
[f40a309] | 305 | return(FAILURE);
|
---|
| 306 |
|
---|
| 307 | break;
|
---|
| 308 |
|
---|
| 309 | case PA_INST:
|
---|
| 310 | case PA_WAVA:
|
---|
| 311 | case PA_WAVB:
|
---|
| 312 | case PA_CNFG:
|
---|
| 313 |
|
---|
| 314 | if (rd_ec(fp, &ptebuf.pasuba, 1L))
|
---|
| 315 | return(FAILURE);
|
---|
| 316 |
|
---|
[7258c6a] | 317 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
[f40a309] | 318 | return(FAILURE);
|
---|
| 319 |
|
---|
| 320 | break;
|
---|
| 321 |
|
---|
| 322 | case PA_OSC:
|
---|
| 323 | case PA_INDX:
|
---|
| 324 | case PA_FREQ:
|
---|
| 325 |
|
---|
| 326 | if (rd_ec(fp, &ptebuf.pasuba, 2L))
|
---|
| 327 | return(FAILURE);
|
---|
| 328 |
|
---|
[7258c6a] | 329 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
[f40a309] | 330 | return(FAILURE);
|
---|
| 331 |
|
---|
| 332 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
| 333 | return(FAILURE);
|
---|
| 334 |
|
---|
| 335 | break;
|
---|
[fa38804] | 336 |
|
---|
[f40a309] | 337 | case PA_LEVL:
|
---|
| 338 | case PA_FILT:
|
---|
| 339 | case PA_FILQ:
|
---|
| 340 | case PA_LOCN:
|
---|
| 341 | case PA_DYNM:
|
---|
| 342 |
|
---|
| 343 | if (rd_ec(fp, &ptebuf.pasuba, 1L))
|
---|
| 344 | return(FAILURE);
|
---|
| 345 |
|
---|
[7258c6a] | 346 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
[f40a309] | 347 | return(FAILURE);
|
---|
| 348 |
|
---|
| 349 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
| 350 | return(FAILURE);
|
---|
| 351 |
|
---|
| 352 | break;
|
---|
| 353 |
|
---|
| 354 | case PA_AUX:
|
---|
| 355 | case PA_RATE:
|
---|
| 356 | case PA_INTN:
|
---|
| 357 | case PA_DPTH:
|
---|
| 358 |
|
---|
[7258c6a] | 359 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
[f40a309] | 360 | return(FAILURE);
|
---|
| 361 |
|
---|
| 362 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
| 363 | return(FAILURE);
|
---|
| 364 |
|
---|
| 365 | break;
|
---|
| 366 |
|
---|
| 367 | case PA_VOUT:
|
---|
| 368 |
|
---|
[7258c6a] | 369 | if (rd_ec(fp, (int8_t *)&ptebuf.pasuba + 1, 1L))
|
---|
[f40a309] | 370 | return(FAILURE);
|
---|
| 371 |
|
---|
[7258c6a] | 372 | if (rd_ec(fp, (int8_t *)&ptebuf.padat1 + 1, 1L))
|
---|
[f40a309] | 373 | return(FAILURE);
|
---|
| 374 |
|
---|
| 375 | if (rd_ec(fp, &ptebuf.padat2, 2L))
|
---|
| 376 | return(FAILURE);
|
---|
| 377 |
|
---|
| 378 | break;
|
---|
[fa38804] | 379 |
|
---|
[f40a309] | 380 | default:
|
---|
| 381 |
|
---|
| 382 | return(FAILURE);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | #if DEBUGRE
|
---|
| 386 | if (debugsw AND debugre)
|
---|
| 387 | printf("\n\n");
|
---|
| 388 | #endif
|
---|
| 389 |
|
---|
| 390 | if (stashp()) { /* stash the patch */
|
---|
| 391 |
|
---|
[0c834c5] | 392 | nopatch();
|
---|
[f40a309] | 393 | ptecpos = 0;
|
---|
| 394 | voidpb();
|
---|
| 395 | return(FAILURE);
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | #if DEBUGRE
|
---|
| 400 | if (debugsw AND debugre)
|
---|
| 401 | printf("ptread(): terminator read -- end of patch file\n");
|
---|
| 402 | #endif
|
---|
| 403 |
|
---|
| 404 | ptecpos = 0;
|
---|
| 405 | voidpb();
|
---|
| 406 | return(SUCCESS);
|
---|
| 407 | }
|
---|
[6262b5c] | 408 |
|
---|