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