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