[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | librw.c -- MIDAS librarian read / write functions
|
---|
| 4 | Version 22 -- 1988-11-18 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #define DEBUGIT 0
|
---|
| 9 |
|
---|
[b28a12e] | 10 | #include "ram.h"
|
---|
[f40a309] | 11 |
|
---|
| 12 | /*
|
---|
| 13 | =============================================================================
|
---|
| 14 | wrt_asg() -- write an assignment on the disk
|
---|
| 15 | =============================================================================
|
---|
| 16 | */
|
---|
| 17 |
|
---|
[7258c6a] | 18 | int16_t wrt_asg(int16_t slot)
|
---|
[f40a309] | 19 | {
|
---|
| 20 | register FILE *fp;
|
---|
[7258c6a] | 21 | register int16_t i;
|
---|
| 22 | int8_t cstemp[8];
|
---|
[f40a309] | 23 |
|
---|
| 24 | preio(); /* kill LCD backlight */
|
---|
| 25 |
|
---|
| 26 | fp = fopenb(slotnam(slot, FT_ASG), "w");
|
---|
| 27 |
|
---|
| 28 | if ((FILE *)NULL EQ fp) {
|
---|
| 29 |
|
---|
| 30 | ldermsg("Couldn't create a file",
|
---|
[7258c6a] | 31 | " for the assignments", (int8_t *)NULL,
|
---|
[f40a309] | 32 | LD_EMCF, LD_EMCB);
|
---|
| 33 |
|
---|
| 34 | postio(); /* restore LCD backlight */
|
---|
| 35 | streset();
|
---|
| 36 | return(FAILURE);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | makelh(FT_ASG); /* make header */
|
---|
| 40 |
|
---|
| 41 | for (i = 0; i < NASGLIB; i++)
|
---|
[7258c6a] | 42 | lcsum += chksum(&asgtab[i + 1], (int32_t)(sizeof (struct asgent)));
|
---|
[f40a309] | 43 |
|
---|
| 44 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
| 45 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
| 46 |
|
---|
| 47 | #if DEBUGIT
|
---|
| 48 | if (debugsw)
|
---|
| 49 | printf("wrt_asg(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
[fa38804] | 52 |
|
---|
[7258c6a] | 53 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 54 |
|
---|
| 55 | streset();
|
---|
| 56 | return(FAILURE);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | for (i = 0; i < NASGLIB; i++) {
|
---|
| 60 |
|
---|
[7258c6a] | 61 | if (wr_ec(fp, &asgtab[i + 1], (int32_t)(sizeof (struct asgent)))) {
|
---|
[f40a309] | 62 |
|
---|
| 63 | streset();
|
---|
| 64 | return(FAILURE);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | fclose(fp);
|
---|
| 69 | postio(); /* restore LCD backlight */
|
---|
| 70 | return(SUCCESS);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | =============================================================================
|
---|
| 75 | get_asg() -- read an assignment library from the disk
|
---|
| 76 | =============================================================================
|
---|
| 77 | */
|
---|
| 78 |
|
---|
[7258c6a] | 79 | int16_t get_asg(void)
|
---|
[f40a309] | 80 | {
|
---|
| 81 | register FILE *fp;
|
---|
[7258c6a] | 82 | register int16_t i;
|
---|
[f40a309] | 83 |
|
---|
| 84 | preio(); /* kill LCD backlight */
|
---|
| 85 |
|
---|
| 86 | fp = fopenb(slotnam(ldslot, FT_ASG), "r");
|
---|
| 87 |
|
---|
| 88 | if ((FILE *)NULL EQ fp) {
|
---|
| 89 |
|
---|
| 90 | ldermsg("Couldn't open the file",
|
---|
[7258c6a] | 91 | " for the assignments", (int8_t *)NULL,
|
---|
[f40a309] | 92 | LD_EMCF, LD_EMCB);
|
---|
| 93 |
|
---|
| 94 | postio(); /* restore LCD backlight */
|
---|
| 95 | clrlsel();
|
---|
| 96 | return(FAILURE);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | memcpy(ldfile, " ", 8);
|
---|
| 100 | memcpy(ldcmnt, " ", 37);
|
---|
| 101 | ldswin(3);
|
---|
| 102 | ldswin(5);
|
---|
| 103 |
|
---|
[fa38804] | 104 |
|
---|
[7258c6a] | 105 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 106 |
|
---|
| 107 | clrlsel();
|
---|
| 108 | return(FAILURE);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | #if DEBUGIT
|
---|
| 112 | if (debugsw)
|
---|
| 113 | printf("get_asg(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 114 | #endif
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | for (i = 0; i < NASGLIB; i++) {
|
---|
| 118 |
|
---|
[7258c6a] | 119 | if (rd_ec(fp, &asgtab[i + 1], (int32_t)(sizeof (struct asgent)))) {
|
---|
[f40a309] | 120 |
|
---|
| 121 | clrlsel();
|
---|
| 122 | return(FAILURE);
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | clrlsel();
|
---|
| 127 | fclose(fp);
|
---|
| 128 | postio(); /* restore LCD backlight */
|
---|
| 129 | return(SUCCESS);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /*
|
---|
| 133 | =============================================================================
|
---|
| 134 | wrt_orc() -- write an orchestra on the disk
|
---|
| 135 | =============================================================================
|
---|
| 136 | */
|
---|
| 137 |
|
---|
[7258c6a] | 138 | int16_t wrt_orc(int16_t slot, int16_t lorh)
|
---|
[f40a309] | 139 | {
|
---|
| 140 | register FILE *fp;
|
---|
[7258c6a] | 141 | register int16_t i;
|
---|
[f40a309] | 142 | register struct instdef *ip;
|
---|
[7258c6a] | 143 | int8_t cstemp[8];
|
---|
[f40a309] | 144 |
|
---|
| 145 | if (lorh)
|
---|
| 146 | ldbusy(" Writing Hi Orch");
|
---|
| 147 | else
|
---|
| 148 | ldbusy(" Writing Lo Orch");
|
---|
| 149 |
|
---|
| 150 | preio(); /* kill LCD backlight */
|
---|
| 151 |
|
---|
| 152 | fp = fopenb(slotnam(slot, FT_ORC), "w");
|
---|
| 153 |
|
---|
| 154 | if ((FILE *)NULL EQ fp) {
|
---|
| 155 |
|
---|
| 156 | ldermsg("Couldn't create a file",
|
---|
[7258c6a] | 157 | " for the orchestra", (int8_t *)NULL,
|
---|
[f40a309] | 158 | LD_EMCF, LD_EMCB);
|
---|
| 159 |
|
---|
| 160 | postio(); /* restore LCD backlight */
|
---|
| 161 | streset();
|
---|
| 162 | return(FAILURE);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | makelh(FT_ORC); /* make header */
|
---|
| 166 |
|
---|
| 167 | for (i = 0; i < NINORC; i++) {
|
---|
| 168 |
|
---|
| 169 | ip = &idefs[i + 1 + (lorh ? NINORC : 0)];
|
---|
| 170 |
|
---|
[7258c6a] | 171 | lcsum += chksum(ip, (int32_t)OR_LEN1);
|
---|
| 172 | lcsum += chksum(ip->idhwvao, (int32_t)OR_LEN2);
|
---|
| 173 | lcsum += chksum(ip->idhwvbo, (int32_t)OR_LEN2);
|
---|
[f40a309] | 174 | }
|
---|
| 175 |
|
---|
| 176 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
| 177 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
| 178 |
|
---|
| 179 | #if DEBUGIT
|
---|
| 180 | if (debugsw)
|
---|
| 181 | printf("wrt_orc(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 182 | #endif
|
---|
| 183 |
|
---|
[fa38804] | 184 |
|
---|
[7258c6a] | 185 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 186 |
|
---|
| 187 | streset();
|
---|
| 188 | return(FAILURE);
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | for (i = 0; i < NINORC; i++) {
|
---|
| 192 |
|
---|
| 193 | ip = &idefs[i + 1 + (lorh ? NINORC : 0)];
|
---|
| 194 |
|
---|
[7258c6a] | 195 | if (wr_ec(fp, ip, (int32_t)OR_LEN1)) { /* functions */
|
---|
[f40a309] | 196 |
|
---|
| 197 | streset();
|
---|
| 198 | return(FAILURE);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[7258c6a] | 201 | if (wr_ec(fp, ip->idhwvao, (int32_t)OR_LEN2)) { /* WS A */
|
---|
[f40a309] | 202 |
|
---|
| 203 | streset();
|
---|
| 204 | return(FAILURE);
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[7258c6a] | 207 | if (wr_ec(fp, ip->idhwvbo, (int32_t)OR_LEN2)) { /* WS B */
|
---|
[f40a309] | 208 |
|
---|
| 209 | streset();
|
---|
| 210 | return(FAILURE);
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | fclose(fp);
|
---|
| 215 | postio(); /* restore LCD backlight */
|
---|
| 216 | return(SUCCESS);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | /*
|
---|
| 220 | =============================================================================
|
---|
| 221 | get_orc() -- read an orchestra from the disk
|
---|
| 222 | =============================================================================
|
---|
| 223 | */
|
---|
| 224 |
|
---|
[7258c6a] | 225 | int16_t get_orc(int16_t lorh, int16_t kind)
|
---|
[f40a309] | 226 | {
|
---|
| 227 | register FILE *fp;
|
---|
[7258c6a] | 228 | register int16_t i;
|
---|
[f40a309] | 229 | register struct instdef *ip;
|
---|
| 230 |
|
---|
| 231 | if (lorh)
|
---|
| 232 | ldbusy(" Reading Hi Orch");
|
---|
| 233 | else
|
---|
| 234 | ldbusy(" Reading Lo Orch");
|
---|
| 235 |
|
---|
| 236 | preio(); /* kill LCD backlight */
|
---|
| 237 |
|
---|
| 238 | fp = fopenb(slotnam(ldslot, kind), "r");
|
---|
| 239 |
|
---|
| 240 | if ((FILE *)NULL EQ fp) {
|
---|
| 241 |
|
---|
| 242 | ldermsg("Couldn't open the file",
|
---|
[7258c6a] | 243 | " for the orchestra", (int8_t *)NULL,
|
---|
[f40a309] | 244 | LD_EMCF, LD_EMCB);
|
---|
| 245 |
|
---|
| 246 | postio(); /* restore LCD backlight */
|
---|
| 247 | clrlsel();
|
---|
| 248 | return(FAILURE);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | memcpy(ldfile, " ", 8);
|
---|
| 252 | memcpy(ldcmnt, " ", 37);
|
---|
| 253 | ldswin(3);
|
---|
| 254 | ldswin(5);
|
---|
| 255 |
|
---|
[fa38804] | 256 |
|
---|
[7258c6a] | 257 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 258 |
|
---|
| 259 | clrlsel();
|
---|
| 260 | return(FAILURE);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | #if DEBUGIT
|
---|
| 264 | if (debugsw)
|
---|
| 265 | printf("get_orc(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 266 | #endif
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 | for (i = 0; i < NINORC; i++) {
|
---|
| 270 |
|
---|
| 271 | ip = &idefs[i + 1 + (lorh ? NINORC : 0)];
|
---|
| 272 |
|
---|
[7258c6a] | 273 | if (rd_ec(fp, ip, (int32_t)OR_LEN1)) { /* functions */
|
---|
[f40a309] | 274 |
|
---|
| 275 | clrlsel();
|
---|
| 276 | return(FAILURE);
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[7258c6a] | 279 | if (rd_ec(fp, ip->idhwvao, (int32_t)OR_LEN2)) { /* WS A */
|
---|
[f40a309] | 280 |
|
---|
| 281 | clrlsel();
|
---|
| 282 | return(FAILURE);
|
---|
| 283 | }
|
---|
| 284 |
|
---|
[7258c6a] | 285 | if (rd_ec(fp, ip->idhwvbo, (int32_t)OR_LEN2)) { /* WS B */
|
---|
[f40a309] | 286 |
|
---|
| 287 | clrlsel();
|
---|
| 288 | return(FAILURE);
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | /* unpack offsets (and eventually harmonics) into finals */
|
---|
| 292 |
|
---|
| 293 | memcpyw(ip->idhwvaf, ip->idhwvao, NUMWPNT);
|
---|
| 294 | memcpyw(ip->idhwvbf, ip->idhwvbo, NUMWPNT);
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | clrlsel();
|
---|
| 298 | fclose(fp);
|
---|
| 299 | postio(); /* restore LCD backlight */
|
---|
| 300 | return(SUCCESS);
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | /*
|
---|
| 304 | =============================================================================
|
---|
| 305 | wrt_tun() -- write a tuning library on the disk
|
---|
| 306 | =============================================================================
|
---|
| 307 | */
|
---|
| 308 |
|
---|
[7258c6a] | 309 | int16_t wrt_tun(int16_t slot)
|
---|
[f40a309] | 310 | {
|
---|
| 311 | register FILE *fp;
|
---|
[7258c6a] | 312 | register int16_t i;
|
---|
| 313 | int8_t cstemp[8];
|
---|
[f40a309] | 314 |
|
---|
| 315 | preio(); /* kill LCD backlight */
|
---|
| 316 |
|
---|
| 317 | fp = fopenb(slotnam(slot, FT_TUN), "w");
|
---|
| 318 |
|
---|
| 319 | if ((FILE *)NULL EQ fp) {
|
---|
| 320 |
|
---|
| 321 | ldermsg("Couldn't create a file",
|
---|
[7258c6a] | 322 | " for the tunings", (int8_t *)NULL,
|
---|
[f40a309] | 323 | LD_EMCF, LD_EMCB);
|
---|
| 324 |
|
---|
| 325 | postio(); /* restore LCD backlight */
|
---|
| 326 | streset();
|
---|
| 327 | return(FAILURE);
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | makelh(FT_TUN); /* make header */
|
---|
| 331 |
|
---|
| 332 | for (i = 0; i < NTUNSLIB; i++) {
|
---|
| 333 |
|
---|
| 334 | lcsum += chksum(&tunlib[i + 1], 256L);
|
---|
| 335 | lcsum += chksum(&tunname[i + 1], 32L);
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
| 339 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
| 340 |
|
---|
| 341 | #if DEBUGIT
|
---|
| 342 | if (debugsw)
|
---|
| 343 | printf("wrt_tun(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 344 | #endif
|
---|
| 345 |
|
---|
[fa38804] | 346 |
|
---|
[7258c6a] | 347 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 348 |
|
---|
| 349 | streset();
|
---|
| 350 | return(FAILURE);
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | for (i = 0; i < NTUNSLIB; i++) {
|
---|
| 354 |
|
---|
| 355 | if (wr_ec(fp, &tunlib[i + 1], 256L)) {
|
---|
| 356 |
|
---|
| 357 | streset();
|
---|
| 358 | return(FAILURE);
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | if (wr_ec(fp, &tunname[i + 1], 32L)) {
|
---|
| 362 |
|
---|
| 363 | streset();
|
---|
| 364 | return(FAILURE);
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | fclose(fp);
|
---|
| 369 | postio(); /* restore LCD backlight */
|
---|
| 370 | return(SUCCESS);
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | /*
|
---|
| 374 | =============================================================================
|
---|
| 375 | get_tun() -- read a tuning library from the disk
|
---|
| 376 | =============================================================================
|
---|
| 377 | */
|
---|
| 378 |
|
---|
[7258c6a] | 379 | int16_t get_tun(void)
|
---|
[f40a309] | 380 | {
|
---|
| 381 | register FILE *fp;
|
---|
[7258c6a] | 382 | register int16_t i;
|
---|
[f40a309] | 383 |
|
---|
| 384 | preio(); /* kill LCD backlight */
|
---|
| 385 |
|
---|
| 386 | fp = fopenb(slotnam(ldslot, FT_TUN), "r");
|
---|
| 387 |
|
---|
| 388 | if ((FILE *)NULL EQ fp) {
|
---|
| 389 |
|
---|
| 390 | ldermsg("Couldn't open the file",
|
---|
[7258c6a] | 391 | " for the tunings", (int8_t *)NULL,
|
---|
[f40a309] | 392 | LD_EMCF, LD_EMCB);
|
---|
| 393 |
|
---|
| 394 | postio(); /* restore LCD backlight */
|
---|
| 395 | clrlsel();
|
---|
| 396 | return(FAILURE);
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | memcpy(ldfile, " ", 8);
|
---|
| 400 | memcpy(ldcmnt, " ", 37);
|
---|
| 401 | ldswin(3);
|
---|
| 402 | ldswin(5);
|
---|
| 403 |
|
---|
[fa38804] | 404 |
|
---|
[7258c6a] | 405 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 406 |
|
---|
| 407 | clrlsel();
|
---|
| 408 | return(FAILURE);
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | #if DEBUGIT
|
---|
| 412 | if (debugsw)
|
---|
| 413 | printf("get_tun(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 414 | #endif
|
---|
| 415 |
|
---|
| 416 |
|
---|
| 417 | for (i = 0; i < NTUNSLIB; i++) {
|
---|
| 418 |
|
---|
| 419 | if (rd_ec(fp, &tunlib[i + 1], 256L)) {
|
---|
| 420 |
|
---|
| 421 | clrlsel();
|
---|
| 422 | return(FAILURE);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | if (rd_ec(fp, &tunname[i + 1], 32L)) {
|
---|
| 426 |
|
---|
| 427 | clrlsel();
|
---|
| 428 | return(FAILURE);
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | clrlsel();
|
---|
| 433 | fclose(fp);
|
---|
| 434 | postio(); /* restore LCD backlight */
|
---|
| 435 | return(SUCCESS);
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | /*
|
---|
| 439 | =============================================================================
|
---|
| 440 | wrt_pat() -- write a patch file on the disk
|
---|
| 441 | =============================================================================
|
---|
| 442 | */
|
---|
| 443 |
|
---|
[7258c6a] | 444 | int16_t wrt_pat(int16_t slot)
|
---|
[f40a309] | 445 | {
|
---|
| 446 | register FILE *fp;
|
---|
[7258c6a] | 447 | int8_t cstemp[8];
|
---|
[f40a309] | 448 |
|
---|
| 449 | preio(); /* kill LCD backlight */
|
---|
| 450 |
|
---|
| 451 | fp = fopenb(slotnam(slot, FT_PAT), "w");
|
---|
| 452 |
|
---|
| 453 | if ((FILE *)NULL EQ fp) {
|
---|
| 454 |
|
---|
| 455 | ldermsg("Couldn't create a file",
|
---|
[7258c6a] | 456 | " for the patches", (int8_t *)NULL,
|
---|
[f40a309] | 457 | LD_EMCF, LD_EMCB);
|
---|
| 458 |
|
---|
| 459 | postio(); /* restore LCD backlight */
|
---|
| 460 | streset();
|
---|
| 461 | return(FAILURE);
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | makelh(FT_PAT); /* make header */
|
---|
| 465 |
|
---|
| 466 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
| 467 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
| 468 |
|
---|
| 469 | #if DEBUGIT
|
---|
| 470 | if (debugsw)
|
---|
| 471 | printf("wrt_pat(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 472 | #endif
|
---|
| 473 |
|
---|
[fa38804] | 474 |
|
---|
[7258c6a] | 475 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 476 |
|
---|
| 477 | streset();
|
---|
| 478 | return(FAILURE);
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | if (ptwrite(fp)) { /* patches */
|
---|
| 482 |
|
---|
| 483 | streset();
|
---|
| 484 | return(FAILURE);
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 | fclose(fp);
|
---|
| 488 | postio(); /* restore LCD backlight */
|
---|
| 489 | return(SUCCESS);
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | /*
|
---|
| 493 | =============================================================================
|
---|
| 494 | get_pat() -- read a patch file from the disk
|
---|
| 495 | =============================================================================
|
---|
| 496 | */
|
---|
| 497 |
|
---|
[7258c6a] | 498 | int16_t get_pat(void)
|
---|
[f40a309] | 499 | {
|
---|
| 500 | register FILE *fp;
|
---|
| 501 |
|
---|
| 502 | preio(); /* kill LCD backlight */
|
---|
| 503 |
|
---|
| 504 | fp = fopenb(slotnam(ldslot, FT_PAT), "r");
|
---|
| 505 |
|
---|
| 506 | if ((FILE *)NULL EQ fp) {
|
---|
| 507 |
|
---|
| 508 | ldermsg("Couldn't open the file",
|
---|
[7258c6a] | 509 | " for the patches", (int8_t *)NULL,
|
---|
[f40a309] | 510 | LD_EMCF, LD_EMCB);
|
---|
| 511 |
|
---|
| 512 | postio(); /* restore LCD backlight */
|
---|
| 513 | clrlsel();
|
---|
| 514 | return(FAILURE);
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | memcpy(ldfile, " ", 8);
|
---|
| 518 | memcpy(ldcmnt, " ", 37);
|
---|
| 519 | ldswin(3);
|
---|
| 520 | ldswin(5);
|
---|
| 521 |
|
---|
[fa38804] | 522 |
|
---|
[7258c6a] | 523 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 524 |
|
---|
| 525 | clrlsel();
|
---|
| 526 | return(FAILURE);
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | #if DEBUGIT
|
---|
| 530 | if (debugsw)
|
---|
| 531 | printf("get_pat(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 532 | #endif
|
---|
| 533 |
|
---|
| 534 | if (lrasw EQ 0) /* clear all patches if in replace mode */
|
---|
| 535 | initpt();
|
---|
| 536 |
|
---|
| 537 | if (ptread(fp)) {
|
---|
| 538 |
|
---|
| 539 | clrlsel();
|
---|
| 540 | return(FAILURE);
|
---|
| 541 | }
|
---|
| 542 |
|
---|
| 543 | fclose(fp);
|
---|
| 544 | postio(); /* restore LCD backlight */
|
---|
| 545 | clrlsel();
|
---|
| 546 | return(SUCCESS);
|
---|
| 547 | }
|
---|
| 548 |
|
---|
| 549 | /*
|
---|
| 550 | =============================================================================
|
---|
| 551 | wrt_scr() -- write a score file on the disk
|
---|
| 552 | =============================================================================
|
---|
| 553 | */
|
---|
| 554 |
|
---|
[7258c6a] | 555 | int16_t wrt_scr(int16_t slot)
|
---|
[f40a309] | 556 | {
|
---|
| 557 | register FILE *fp;
|
---|
[7258c6a] | 558 | register int16_t i;
|
---|
| 559 | int8_t cstemp[8];
|
---|
[f40a309] | 560 |
|
---|
| 561 | preio(); /* kill LCD backlight */
|
---|
| 562 |
|
---|
| 563 | fp = fopenb(slotnam(slot, FT_SCR), "w");
|
---|
| 564 |
|
---|
| 565 | if ((FILE *)NULL EQ fp) {
|
---|
| 566 |
|
---|
| 567 | ldermsg("Couldn't create a file",
|
---|
[7258c6a] | 568 | " for the scores", (int8_t *)NULL,
|
---|
[f40a309] | 569 | LD_EMCF, LD_EMCB);
|
---|
| 570 |
|
---|
| 571 | postio(); /* restore LCD backlight */
|
---|
| 572 | streset();
|
---|
| 573 | return(FAILURE);
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | makelh(FT_SCR); /* make header */
|
---|
| 577 |
|
---|
| 578 | lcsum += sntlreq;
|
---|
| 579 |
|
---|
| 580 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
| 581 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
| 582 |
|
---|
| 583 | #if DEBUGIT
|
---|
| 584 | if (debugsw)
|
---|
| 585 | printf("wrt_scr(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 586 | #endif
|
---|
| 587 |
|
---|
[fa38804] | 588 |
|
---|
[7258c6a] | 589 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 590 |
|
---|
| 591 | streset();
|
---|
| 592 | return(FAILURE);
|
---|
| 593 | }
|
---|
| 594 |
|
---|
| 595 | if (wr_ec(fp, &sntlreq, 4L)) { /* total longs required */
|
---|
| 596 |
|
---|
| 597 | streset();
|
---|
| 598 | return(FAILURE);
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 | for (i = 0; i < N_SCORES; i++) { /* scores */
|
---|
| 602 |
|
---|
| 603 | if (scwrite(i, fp)) {
|
---|
| 604 |
|
---|
| 605 | streset();
|
---|
| 606 | return(FAILURE);
|
---|
| 607 | }
|
---|
| 608 | }
|
---|
| 609 |
|
---|
| 610 | fclose(fp);
|
---|
| 611 | postio(); /* restore LCD backlight */
|
---|
| 612 | return(SUCCESS);
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | /*
|
---|
| 616 | =============================================================================
|
---|
| 617 | get_scr() -- read a score file from the disk
|
---|
| 618 | =============================================================================
|
---|
| 619 | */
|
---|
| 620 |
|
---|
[7258c6a] | 621 | int16_t get_scr(void)
|
---|
[f40a309] | 622 | {
|
---|
| 623 | register FILE *fp;
|
---|
[7258c6a] | 624 | register int16_t i;
|
---|
| 625 | int32_t tnl;
|
---|
[f40a309] | 626 |
|
---|
| 627 | preio(); /* kill LCD backlight */
|
---|
| 628 |
|
---|
| 629 | fp = fopenb(slotnam(ldslot, FT_SCR), "r");
|
---|
| 630 |
|
---|
| 631 | if ((FILE *)NULL EQ fp) {
|
---|
| 632 |
|
---|
| 633 | ldermsg("Couldn't open the file",
|
---|
[7258c6a] | 634 | " for the scores", (int8_t *)NULL,
|
---|
[f40a309] | 635 | LD_EMCF, LD_EMCB);
|
---|
| 636 |
|
---|
| 637 | postio(); /* restore LCD backlight */
|
---|
| 638 | clrlsel();
|
---|
| 639 | return(FAILURE);
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 | memcpy(ldfile, " ", 8);
|
---|
| 643 | memcpy(ldcmnt, " ", 37);
|
---|
| 644 | ldswin(3);
|
---|
| 645 | ldswin(5);
|
---|
| 646 |
|
---|
[fa38804] | 647 |
|
---|
[7258c6a] | 648 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 649 |
|
---|
| 650 | clrlsel();
|
---|
| 651 | return(FAILURE);
|
---|
| 652 | }
|
---|
| 653 |
|
---|
| 654 | #if DEBUGIT
|
---|
| 655 | if (debugsw)
|
---|
| 656 | printf("get_scr(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 657 | #endif
|
---|
| 658 |
|
---|
| 659 |
|
---|
| 660 | if (rd_ec(fp, &tnl, 4L)) { /* longs required */
|
---|
| 661 |
|
---|
| 662 | clrlsel();
|
---|
| 663 | return(FAILURE);
|
---|
| 664 | }
|
---|
| 665 |
|
---|
| 666 | if (lrasw EQ 0) /* clear all scores if in replace mode */
|
---|
| 667 | scinit();
|
---|
| 668 |
|
---|
| 669 | for (i = 0; i < N_SCORES; i++) { /* read scores */
|
---|
| 670 |
|
---|
| 671 | if (scread(i, fp)) {
|
---|
| 672 |
|
---|
| 673 | clrlsel();
|
---|
| 674 | return(FAILURE);
|
---|
| 675 | }
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | fclose(fp);
|
---|
| 679 | postio(); /* restore LCD backlight */
|
---|
| 680 |
|
---|
| 681 | p_bak = p_cur = p_ctr = p_fwd = scp = E_NULL;
|
---|
| 682 | t_cur = t_ctr = 0L;
|
---|
| 683 | t_bak = t_cur - TO_BAK;
|
---|
| 684 | t_fwd = t_cur + TO_FWD;
|
---|
| 685 |
|
---|
| 686 | selscor(0);
|
---|
| 687 |
|
---|
| 688 | clrlsel();
|
---|
| 689 | return(SUCCESS);
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | /*
|
---|
| 693 | =============================================================================
|
---|
| 694 | wrt_seq() -- write a sequence file on the disk
|
---|
| 695 | =============================================================================
|
---|
| 696 | */
|
---|
| 697 |
|
---|
[7258c6a] | 698 | int16_t wrt_seq(int16_t slot)
|
---|
[f40a309] | 699 | {
|
---|
| 700 | register FILE *fp;
|
---|
[7258c6a] | 701 | int8_t cstemp[8];
|
---|
[f40a309] | 702 |
|
---|
| 703 | preio(); /* kill LCD backlight */
|
---|
| 704 |
|
---|
| 705 | fp = fopenb(slotnam(slot, FT_SEQ), "w");
|
---|
| 706 |
|
---|
| 707 | if ((FILE *)NULL EQ fp) {
|
---|
| 708 |
|
---|
| 709 | ldermsg("Couldn't create a file",
|
---|
[7258c6a] | 710 | " for the sequences", (int8_t *)NULL,
|
---|
[f40a309] | 711 | LD_EMCF, LD_EMCB);
|
---|
| 712 |
|
---|
| 713 | postio(); /* restore LCD backlight */
|
---|
| 714 | streset();
|
---|
| 715 | return(FAILURE);
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | makelh(FT_SEQ); /* make header */
|
---|
| 719 |
|
---|
| 720 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
| 721 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
| 722 |
|
---|
| 723 | #if DEBUGIT
|
---|
| 724 | if (debugsw)
|
---|
| 725 | printf("wrt_seq(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 726 | #endif
|
---|
| 727 |
|
---|
[fa38804] | 728 |
|
---|
[7258c6a] | 729 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 730 |
|
---|
| 731 | streset();
|
---|
| 732 | return(FAILURE);
|
---|
| 733 | }
|
---|
| 734 |
|
---|
| 735 | if (sqwrite(fp)) { /* sequences */
|
---|
| 736 |
|
---|
| 737 | streset();
|
---|
| 738 | return(FAILURE);
|
---|
| 739 | }
|
---|
| 740 |
|
---|
| 741 | fclose(fp);
|
---|
| 742 | postio(); /* restore LCD backlight */
|
---|
| 743 | return(SUCCESS);
|
---|
| 744 | }
|
---|
| 745 |
|
---|
| 746 | /*
|
---|
| 747 | =============================================================================
|
---|
| 748 | get_seq() -- read a sequence file from the disk
|
---|
| 749 | =============================================================================
|
---|
| 750 | */
|
---|
| 751 |
|
---|
[7258c6a] | 752 | int16_t get_seq(void)
|
---|
[f40a309] | 753 | {
|
---|
| 754 | register FILE *fp;
|
---|
| 755 |
|
---|
| 756 | preio(); /* kill LCD backlight */
|
---|
| 757 |
|
---|
| 758 | fp = fopenb(slotnam(ldslot, FT_SEQ), "r");
|
---|
| 759 |
|
---|
| 760 | if ((FILE *)NULL EQ fp) {
|
---|
| 761 |
|
---|
| 762 | ldermsg("Couldn't open the file",
|
---|
[7258c6a] | 763 | " for the sequences", (int8_t *)NULL,
|
---|
[f40a309] | 764 | LD_EMCF, LD_EMCB);
|
---|
| 765 |
|
---|
| 766 | postio(); /* restore LCD backlight */
|
---|
| 767 | clrlsel();
|
---|
| 768 | return(FAILURE);
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | memcpy(ldfile, " ", 8);
|
---|
| 772 | memcpy(ldcmnt, " ", 37);
|
---|
| 773 | ldswin(3);
|
---|
| 774 | ldswin(5);
|
---|
| 775 |
|
---|
[fa38804] | 776 |
|
---|
[7258c6a] | 777 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 778 |
|
---|
| 779 | clrlsel();
|
---|
| 780 | return(FAILURE);
|
---|
| 781 | }
|
---|
| 782 |
|
---|
| 783 | #if DEBUGIT
|
---|
| 784 | if (debugsw)
|
---|
| 785 | printf("get_seq(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 786 | #endif
|
---|
| 787 |
|
---|
| 788 | initsq();
|
---|
| 789 |
|
---|
| 790 | if (sqread(fp)) {
|
---|
| 791 |
|
---|
| 792 | clrlsel();
|
---|
| 793 | return(FAILURE);
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | fclose(fp);
|
---|
| 797 | postio(); /* restore LCD backlight */
|
---|
| 798 | clrlsel();
|
---|
| 799 | return(SUCCESS);
|
---|
| 800 | }
|
---|
| 801 |
|
---|
| 802 | /*
|
---|
| 803 | =============================================================================
|
---|
| 804 | wrt_wav() -- write a waveshape library on the disk
|
---|
| 805 | =============================================================================
|
---|
| 806 | */
|
---|
| 807 |
|
---|
[7258c6a] | 808 | int16_t wrt_wav(int16_t slot)
|
---|
[f40a309] | 809 | {
|
---|
| 810 | register FILE *fp;
|
---|
[7258c6a] | 811 | register int16_t i;
|
---|
| 812 | int8_t cstemp[8];
|
---|
[f40a309] | 813 | register struct wstbl *wp;
|
---|
| 814 |
|
---|
| 815 | preio(); /* kill LCD backlight */
|
---|
| 816 |
|
---|
| 817 | fp = fopenb(slotnam(slot, FT_WAV), "w");
|
---|
| 818 |
|
---|
| 819 | if ((FILE *)NULL EQ fp) {
|
---|
| 820 |
|
---|
| 821 | ldermsg("Couldn't create a file",
|
---|
[7258c6a] | 822 | " for the waveshapes", (int8_t *)NULL,
|
---|
[f40a309] | 823 | LD_EMCF, LD_EMCB);
|
---|
| 824 |
|
---|
| 825 | postio(); /* restore LCD backlight */
|
---|
| 826 | streset();
|
---|
| 827 | return(FAILURE);
|
---|
| 828 | }
|
---|
| 829 |
|
---|
| 830 | makelh(FT_WAV); /* make header */
|
---|
| 831 |
|
---|
| 832 | for (i = 0; i < NUMWAVS; i++) {
|
---|
| 833 |
|
---|
| 834 | wp = &wslib[i];
|
---|
| 835 |
|
---|
[7258c6a] | 836 | lcsum += chksum(wp->offset, (int32_t)(NUMWPNT * 2));
|
---|
| 837 | lcsum += chksum(wp->harmon, (int32_t)(NUMHARM * 2));
|
---|
[f40a309] | 838 | }
|
---|
| 839 |
|
---|
| 840 | sprintf(cstemp, "%08.8lX", lcsum);
|
---|
| 841 | memcpy(ldhead.l_csum, cstemp, 8);
|
---|
| 842 |
|
---|
| 843 | #if DEBUGIT
|
---|
| 844 | if (debugsw)
|
---|
| 845 | printf("wrt_wav(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 846 | #endif
|
---|
| 847 |
|
---|
[fa38804] | 848 |
|
---|
[7258c6a] | 849 | if (wr_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 850 |
|
---|
| 851 | streset();
|
---|
| 852 | return(FAILURE);
|
---|
| 853 | }
|
---|
| 854 |
|
---|
| 855 | for (i = 0; i < NUMWAVS; i++) {
|
---|
| 856 |
|
---|
| 857 | wp = &wslib[i];
|
---|
| 858 |
|
---|
[7258c6a] | 859 | if (wr_ec(fp, wp->offset, (int32_t)(NUMWPNT * 2))) {
|
---|
[f40a309] | 860 |
|
---|
| 861 | streset();
|
---|
| 862 | return(FAILURE);
|
---|
| 863 | }
|
---|
| 864 |
|
---|
[7258c6a] | 865 | if (wr_ec(fp, wp->harmon, (int32_t)(NUMHARM * 2))) {
|
---|
[f40a309] | 866 |
|
---|
| 867 | streset();
|
---|
| 868 | return(FAILURE);
|
---|
| 869 | }
|
---|
| 870 | }
|
---|
| 871 |
|
---|
| 872 | fclose(fp);
|
---|
| 873 | postio(); /* restore LCD backlight */
|
---|
| 874 | return(SUCCESS);
|
---|
| 875 | }
|
---|
| 876 |
|
---|
| 877 | /*
|
---|
| 878 | =============================================================================
|
---|
| 879 | get_wav() -- read a waveshape library from the disk
|
---|
| 880 | =============================================================================
|
---|
| 881 | */
|
---|
| 882 |
|
---|
[7258c6a] | 883 | int16_t get_wav(void)
|
---|
[f40a309] | 884 | {
|
---|
| 885 | register FILE *fp;
|
---|
[7258c6a] | 886 | register int16_t i;
|
---|
[f40a309] | 887 | register struct wstbl *wp;
|
---|
| 888 |
|
---|
| 889 | preio(); /* kill LCD backlight */
|
---|
| 890 |
|
---|
| 891 | fp = fopenb(slotnam(ldslot, FT_WAV), "r");
|
---|
| 892 |
|
---|
| 893 | if ((FILE *)NULL EQ fp) {
|
---|
| 894 |
|
---|
| 895 | ldermsg("Couldn't open the file",
|
---|
[7258c6a] | 896 | " for the waveshapes", (int8_t *)NULL,
|
---|
[f40a309] | 897 | LD_EMCF, LD_EMCB);
|
---|
| 898 |
|
---|
| 899 | postio(); /* restore LCD backlight */
|
---|
| 900 | clrlsel();
|
---|
| 901 | return(FAILURE);
|
---|
| 902 | }
|
---|
| 903 |
|
---|
| 904 | memcpy(ldfile, " ", 8);
|
---|
| 905 | memcpy(ldcmnt, " ", 37);
|
---|
| 906 | ldswin(3);
|
---|
| 907 | ldswin(5);
|
---|
| 908 |
|
---|
[fa38804] | 909 |
|
---|
[7258c6a] | 910 | if (rd_ec(fp, &ldhead, (int32_t)LH_LEN)) { /* header */
|
---|
[f40a309] | 911 |
|
---|
| 912 | clrlsel();
|
---|
| 913 | return(FAILURE);
|
---|
| 914 | }
|
---|
| 915 |
|
---|
| 916 | #if DEBUGIT
|
---|
| 917 | if (debugsw)
|
---|
| 918 | printf("get_wav(): hdr=[%-.56s]\n", &ldhead);
|
---|
| 919 | #endif
|
---|
| 920 |
|
---|
| 921 |
|
---|
| 922 | for (i = 0; i < NUMWAVS; i++) {
|
---|
| 923 |
|
---|
| 924 | wp = &wslib[i];
|
---|
| 925 |
|
---|
[7258c6a] | 926 | if (rd_ec(fp, wp->offset, (int32_t)(NUMWPNT * 2))) {
|
---|
[f40a309] | 927 |
|
---|
| 928 | clrlsel();
|
---|
| 929 | return(FAILURE);
|
---|
| 930 | }
|
---|
| 931 |
|
---|
[7258c6a] | 932 | if (rd_ec(fp, wp->harmon, (int32_t)(NUMHARM * 2))) {
|
---|
[f40a309] | 933 |
|
---|
| 934 | clrlsel();
|
---|
| 935 | return(FAILURE);
|
---|
| 936 | }
|
---|
| 937 |
|
---|
| 938 | /* unpack offsets (and eventually harmonics) into finals */
|
---|
| 939 |
|
---|
| 940 | memcpyw(wp->final, wp->offset, NUMWPNT);
|
---|
| 941 | }
|
---|
| 942 |
|
---|
| 943 | clrlsel();
|
---|
| 944 | fclose(fp);
|
---|
| 945 | postio(); /* restore LCD backlight */
|
---|
| 946 | return(SUCCESS);
|
---|
| 947 | }
|
---|
| 948 |
|
---|
[6262b5c] | 949 |
|
---|