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