[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | ptwrite.c -- librarian - write patch functions
|
---|
| 4 | Version 7 -- 1988-11-18 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #define DEBUGWE 0
|
---|
| 9 | #define DEBUGPW 0
|
---|
| 10 |
|
---|
| 11 | #include "stddefs.h"
|
---|
| 12 | #include "stdio.h"
|
---|
| 13 | #include "hwdefs.h"
|
---|
| 14 | #include "graphdef.h"
|
---|
| 15 | #include "vsdd.h"
|
---|
| 16 | #include "patch.h"
|
---|
| 17 |
|
---|
| 18 | #include "midas.h"
|
---|
| 19 | #include "libdsp.h"
|
---|
| 20 |
|
---|
| 21 | #if (DEBUGPW|DEBUGWE)
|
---|
| 22 | extern short debugsw;
|
---|
| 23 | #endif
|
---|
| 24 |
|
---|
| 25 | #if DEBUGPW
|
---|
| 26 | short debugpw = 1;
|
---|
| 27 | #endif
|
---|
| 28 |
|
---|
| 29 | #if DEBUGWE
|
---|
| 30 | extern short debugwe;
|
---|
| 31 | #endif
|
---|
| 32 |
|
---|
[7258c6a] | 33 | extern int32_t chksum(int8_t *area, int32_t len);
|
---|
[f40a309] | 34 |
|
---|
[e225e77] | 35 | extern int16_t find1st(void);
|
---|
| 36 | extern int16_t findnxt(int16_t cp);
|
---|
| 37 | extern int16_t wr_ec(FILE *fp, int8_t *from, int32_t len);
|
---|
| 38 | extern void ldwmsg(int8_t *line1, int8_t *line2, int8_t *line3, uint16_t fgcolor, uint16_t bgcolor);
|
---|
| 39 |
|
---|
[f40a309] | 40 | /* |
---|
| 41 |
|
---|
| 42 | */
|
---|
[7258c6a] | 43 |
|
---|
[f40a309] | 44 | int8_t ptsizes[] = {
|
---|
| 45 |
|
---|
| 46 | 0, /* NULL - end of list */
|
---|
| 47 | 4, /* PA_KEY */
|
---|
| 48 | 4, /* PA_TRG */
|
---|
| 49 | 3, /* PA_PLS */
|
---|
| 50 | 3, /* PA_LED */
|
---|
| 51 | 4, /* PA_SLIN */
|
---|
| 52 | 3, /* PA_SCTL */
|
---|
| 53 | 2, /* PA_TUNE */
|
---|
| 54 | 4, /* PA_RSET */
|
---|
| 55 | 4, /* PA_RADD */
|
---|
| 56 | 3, /* PA_INST */
|
---|
| 57 | 6, /* PA_OSC */
|
---|
| 58 | 3, /* PA_WAVA */
|
---|
| 59 | 3, /* PA_WAVB */
|
---|
| 60 | 3, /* PA_CNFG */
|
---|
| 61 | 5, /* PA_LEVL */
|
---|
| 62 | 6, /* PA_INDX */
|
---|
| 63 | 6, /* PA_FREQ */
|
---|
| 64 | 5, /* PA_FILT */
|
---|
| 65 | 5, /* PA_FILQ */
|
---|
| 66 | 5, /* PA_LOCN */
|
---|
| 67 | 5, /* PA_DYNM */
|
---|
| 68 | 4, /* PA_AUX */
|
---|
| 69 | 4, /* PA_RATE */
|
---|
| 70 | 4, /* PA_INTN */
|
---|
| 71 | 4, /* PA_DPTH */
|
---|
| 72 | 5 /* PA_VOUT */
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | /* |
---|
| 76 |
|
---|
| 77 | */
|
---|
| 78 |
|
---|
| 79 | /*
|
---|
| 80 | =============================================================================
|
---|
| 81 | ptsizer() -- return number of bytes necessary for storing active patches
|
---|
| 82 | =============================================================================
|
---|
[7258c6a] | 83 | */
|
---|
[f40a309] | 84 |
|
---|
[7258c6a] | 85 | int32_t ptsizer(void)
|
---|
| 86 | {
|
---|
[f40a309] | 87 | register int16_t pp;
|
---|
| 88 | register int32_t nb;
|
---|
| 89 |
|
---|
| 90 | nb = 0L;
|
---|
| 91 |
|
---|
| 92 | if (pp = find1st()) {
|
---|
| 93 |
|
---|
| 94 | while (pp) {
|
---|
| 95 |
|
---|
| 96 | nb += (ptsizes[PE_SPEC & patches[pp].paspec] + 4);
|
---|
| 97 | pp = findnxt(pp);
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | if (nb)
|
---|
| 102 | ++nb; /* ... and one for the terminator */
|
---|
| 103 |
|
---|
| 104 | #if DEBUGPW
|
---|
| 105 | if (debugsw AND debugpw)
|
---|
| 106 | printf("ptsizer(): %ld bytes required\n", nb);
|
---|
| 107 | #endif
|
---|
| 108 |
|
---|
| 109 | return(nb);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | /* |
---|
| 113 |
|
---|
| 114 | */
|
---|
| 115 |
|
---|
| 116 | /*
|
---|
| 117 | =============================================================================
|
---|
| 118 | ptwrite() -- store a patch table
|
---|
[7258c6a] | 119 | =============================================================================
|
---|
[f40a309] | 120 | */
|
---|
[7258c6a] | 121 |
|
---|
| 122 | int16_t ptwrite(FILE *fp)
|
---|
[f40a309] | 123 | {
|
---|
| 124 | register int16_t pp;
|
---|
| 125 | int8_t cb, zero;
|
---|
| 126 |
|
---|
| 127 | #if DEBUGPW
|
---|
| 128 | if (debugsw AND debugpw)
|
---|
| 129 | printf("ptwrite($%08lX): entered\n", fp);
|
---|
| 130 | #endif
|
---|
[7258c6a] | 131 |
|
---|
[f40a309] | 132 | zero = '\0';
|
---|
| 133 |
|
---|
| 134 | ldwmsg("Busy -- Please stand by", (int8_t *)0L, " writing patches",
|
---|
| 135 | LCFBX10, LCBBX10);
|
---|
| 136 |
|
---|
| 137 | if (pp = find1st()) {
|
---|
| 138 |
|
---|
| 139 | while (pp) {
|
---|
| 140 |
|
---|
| 141 | #if DEBUGWE
|
---|
| 142 | if (debugsw AND debugwe) {
|
---|
| 143 |
|
---|
| 144 | printf("ptwrite(): %3d %04.4X %04.4X %04.4X %04.4X %04.4X %04.4X\n ",
|
---|
| 145 | pp, patches[pp].defnum, patches[pp].stmnum,
|
---|
| 146 | patches[pp].paspec, patches[pp].pasuba,
|
---|
| 147 | patches[pp].padat1, patches[pp].padat2);
|
---|
| 148 | }
|
---|
| 149 | #endif
|
---|
| 150 |
|
---|
| 151 | switch (cb = (PE_SPEC & patches[pp].paspec)) {
|
---|
| 152 |
|
---|
| 153 | case PA_KEY:
|
---|
| 154 | case PA_TRG:
|
---|
| 155 |
|
---|
| 156 | if (wr_ec(fp, &cb, 1L))
|
---|
| 157 | return(FAILURE);
|
---|
| 158 |
|
---|
| 159 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
| 160 | return(FAILURE);
|
---|
| 161 |
|
---|
[7258c6a] | 162 | if (wr_ec(fp, &patches[pp].pasuba, 2L))
|
---|
[f40a309] | 163 | return(FAILURE);
|
---|
| 164 |
|
---|
| 165 | if (wr_ec(fp, (int8_t *)&patches[pp].padat2 + 1, 1L))
|
---|
| 166 | return(FAILURE);
|
---|
| 167 |
|
---|
| 168 | break;
|
---|
| 169 | /* |
---|
| 170 |
|
---|
| 171 | */
|
---|
| 172 | case PA_PLS:
|
---|
| 173 | case PA_SCTL:
|
---|
| 174 |
|
---|
| 175 | if (wr_ec(fp, &cb, 1L))
|
---|
| 176 | return(FAILURE);
|
---|
[7258c6a] | 177 |
|
---|
[f40a309] | 178 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
| 179 | return(FAILURE);
|
---|
[7258c6a] | 180 |
|
---|
[f40a309] | 181 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
| 182 | return(FAILURE);
|
---|
| 183 |
|
---|
| 184 | if (wr_ec(fp, (int8_t *)&patches[pp].padat2 + 1, 1L))
|
---|
| 185 | return(FAILURE);
|
---|
| 186 |
|
---|
| 187 | break;
|
---|
| 188 |
|
---|
| 189 | case PA_LED:
|
---|
| 190 |
|
---|
| 191 | if (wr_ec(fp, &cb, 1L))
|
---|
| 192 | return(FAILURE);
|
---|
[7258c6a] | 193 |
|
---|
[f40a309] | 194 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
| 195 | return(FAILURE);
|
---|
| 196 |
|
---|
| 197 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
| 198 | return(FAILURE);
|
---|
| 199 |
|
---|
| 200 | if (wr_ec(fp, &patches[pp].padat1, 1L))
|
---|
| 201 | return(FAILURE);
|
---|
| 202 |
|
---|
| 203 | break;
|
---|
| 204 |
|
---|
| 205 | case PA_SLIN:
|
---|
| 206 |
|
---|
| 207 | if (wr_ec(fp, &cb, 1L))
|
---|
| 208 | return(FAILURE);
|
---|
[7258c6a] | 209 |
|
---|
[f40a309] | 210 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
| 211 | return(FAILURE);
|
---|
| 212 |
|
---|
| 213 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
| 214 | return(FAILURE);
|
---|
| 215 |
|
---|
| 216 | if (wr_ec(fp, &patches[pp].padat1, 2L))
|
---|
| 217 | return(FAILURE);
|
---|
| 218 |
|
---|
| 219 | break;
|
---|
| 220 |
|
---|
| 221 | case PA_TUNE:
|
---|
| 222 |
|
---|
| 223 | if (wr_ec(fp, &cb, 1L))
|
---|
| 224 | return(FAILURE);
|
---|
[7258c6a] | 225 |
|
---|
[f40a309] | 226 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
| 227 | return(FAILURE);
|
---|
| 228 |
|
---|
| 229 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
| 230 | return(FAILURE);
|
---|
| 231 |
|
---|
| 232 | break;
|
---|
| 233 | /* |
---|
| 234 |
|
---|
| 235 | */
|
---|
| 236 | case PA_RSET:
|
---|
| 237 | case PA_RADD:
|
---|
| 238 |
|
---|
| 239 | if (wr_ec(fp, &cb, 1L))
|
---|
[7258c6a] | 240 | return(FAILURE);
|
---|
[f40a309] | 241 |
|
---|
| 242 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
[7258c6a] | 243 | return(FAILURE);
|
---|
[f40a309] | 244 |
|
---|
| 245 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
[7258c6a] | 246 | return(FAILURE);
|
---|
[f40a309] | 247 |
|
---|
| 248 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
| 249 | return(FAILURE);
|
---|
| 250 |
|
---|
| 251 | if (wr_ec(fp, (int8_t *)&patches[pp].padat2 + 1, 1L))
|
---|
| 252 | return(FAILURE);
|
---|
| 253 |
|
---|
| 254 | break;
|
---|
| 255 |
|
---|
| 256 | case PA_INST:
|
---|
| 257 | case PA_WAVA:
|
---|
| 258 | case PA_WAVB:
|
---|
| 259 | case PA_CNFG:
|
---|
| 260 |
|
---|
| 261 | if (wr_ec(fp, &cb, 1L))
|
---|
| 262 | return(FAILURE);
|
---|
| 263 |
|
---|
| 264 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
[7258c6a] | 265 | return(FAILURE);
|
---|
[f40a309] | 266 |
|
---|
| 267 | if (wr_ec(fp, &patches[pp].pasuba, 1L))
|
---|
| 268 | return(FAILURE);
|
---|
| 269 |
|
---|
| 270 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
| 271 | return(FAILURE);
|
---|
| 272 |
|
---|
| 273 | break;
|
---|
| 274 |
|
---|
| 275 | case PA_OSC:
|
---|
| 276 | case PA_INDX:
|
---|
| 277 | case PA_FREQ:
|
---|
| 278 |
|
---|
| 279 | if (wr_ec(fp, &cb, 1L))
|
---|
| 280 | return(FAILURE);
|
---|
| 281 |
|
---|
| 282 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
[7258c6a] | 283 | return(FAILURE);
|
---|
[f40a309] | 284 |
|
---|
| 285 | if (wr_ec(fp, &patches[pp].pasuba, 2L))
|
---|
| 286 | return(FAILURE);
|
---|
| 287 |
|
---|
| 288 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
| 289 | return(FAILURE);
|
---|
| 290 |
|
---|
| 291 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
| 292 | return(FAILURE);
|
---|
| 293 |
|
---|
| 294 | break;
|
---|
| 295 | /* |
---|
| 296 |
|
---|
| 297 | */
|
---|
| 298 | case PA_LEVL:
|
---|
| 299 | case PA_FILT:
|
---|
| 300 | case PA_FILQ:
|
---|
| 301 | case PA_LOCN:
|
---|
| 302 | case PA_DYNM:
|
---|
| 303 |
|
---|
| 304 | if (wr_ec(fp, &cb, 1L))
|
---|
| 305 | return(FAILURE);
|
---|
| 306 |
|
---|
[7258c6a] | 307 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
[f40a309] | 308 | return(FAILURE);
|
---|
| 309 |
|
---|
| 310 | if (wr_ec(fp, &patches[pp].pasuba, 1L))
|
---|
| 311 | return(FAILURE);
|
---|
| 312 |
|
---|
| 313 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
| 314 | return(FAILURE);
|
---|
| 315 |
|
---|
| 316 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
| 317 | return(FAILURE);
|
---|
| 318 |
|
---|
| 319 | break;
|
---|
| 320 |
|
---|
| 321 | case PA_AUX:
|
---|
| 322 | case PA_RATE:
|
---|
| 323 | case PA_INTN:
|
---|
| 324 | case PA_DPTH:
|
---|
| 325 |
|
---|
[7258c6a] | 326 | if (wr_ec(fp, &cb, 1L))
|
---|
[f40a309] | 327 | return(FAILURE);
|
---|
| 328 |
|
---|
| 329 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
| 330 | return(FAILURE);
|
---|
| 331 |
|
---|
| 332 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
| 333 | return(FAILURE);
|
---|
| 334 |
|
---|
| 335 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
| 336 | return(FAILURE);
|
---|
| 337 |
|
---|
| 338 | break;
|
---|
| 339 |
|
---|
| 340 | case PA_VOUT:
|
---|
| 341 |
|
---|
[7258c6a] | 342 | if (wr_ec(fp, &cb, 1L))
|
---|
[f40a309] | 343 | return(FAILURE);
|
---|
| 344 |
|
---|
[7258c6a] | 345 | if (wr_ec(fp, &patches[pp].defnum, 4L))
|
---|
[f40a309] | 346 | return(FAILURE);
|
---|
| 347 |
|
---|
| 348 | if (wr_ec(fp, (int8_t *)&patches[pp].pasuba + 1, 1L))
|
---|
| 349 | return(FAILURE);
|
---|
| 350 |
|
---|
| 351 | if (wr_ec(fp, (int8_t *)&patches[pp].padat1 + 1, 1L))
|
---|
| 352 | return(FAILURE);
|
---|
| 353 |
|
---|
| 354 | if (wr_ec(fp, &patches[pp].padat2, 2L))
|
---|
| 355 | return(FAILURE);
|
---|
| 356 |
|
---|
| 357 | break;
|
---|
| 358 | /* |
---|
| 359 |
|
---|
| 360 | */
|
---|
| 361 | default:
|
---|
| 362 |
|
---|
| 363 | return(FAILURE);
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | #if DEBUGWE
|
---|
| 367 | if (debugsw AND debugwe)
|
---|
| 368 | printf("\n\n");
|
---|
| 369 | #endif
|
---|
| 370 |
|
---|
| 371 | pp = findnxt(pp); /* find the next patch */
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | if (wr_ec(fp, &zero, 1L)) /* write the terminator */
|
---|
| 375 | return(FAILURE);
|
---|
| 376 |
|
---|
| 377 | } else {
|
---|
| 378 |
|
---|
| 379 | return(FAILURE); /* no patches to write */
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 | #if DEBUGPW
|
---|
| 383 | if (debugsw AND debugpw)
|
---|
| 384 | printf("ptwrite(): SUCCESS\n");
|
---|
| 385 | #endif
|
---|
| 386 |
|
---|
| 387 | return(SUCCESS);
|
---|
| 388 | }
|
---|