source: buchla-68k/orig/RAM/SCINIT.C@ c93e44d

Last change on this file since c93e44d was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 14.1 KB
Line 
1/*
2 =============================================================================
3 scinit.c -- score list functions
4 Version 33 -- 1988-07-28 -- D.N. Lynx Crowe
5
6 long
7 scinit()
8
9 Initializes the score data structures.
10 Returns the number of free storage units.
11
12 struct s_entry *
13 e_clr(e1)
14 struct s_entry *e1;
15
16 Clears the event pointed to by 'e1'. Returns 'e1'.
17 Preserves e_size field, all others set to zero.
18
19 struct s_entry *
20 e_ins(e1, e2)
21 struct s_entry *e1, *e2;
22
23 Inserts the event pointed to by 'e1' after the event
24 pointed to by 'e2'. Returns 'e1'.
25
26 struct s_entry *
27 e_rmv(e1)
28 struct s_entry *e1;
29
30 Removes the event pointed to by 'e1' from the list it's in.
31 Returns 'e1'.
32
33 struct s_entry *
34 e_alc(w)
35 int w;
36
37 Allocates a new event entry.
38 Returns the event entry address, or E_NULL
39 if none can be allocated.
40
41 short
42 e_del(e1)
43 struct s_entry *e1;
44
45 Deallocates the event entry pointed to by 'e1'.
46 Returns 0 if successful, 1 if not.
47
48 long
49 evleft()
50
51 Returns total number of longs left for score storage.
52
53
54 eh_ins(ne, et)
55 struct s_entry *ne;
56 short et;
57
58 Inserts event 'ne' of type 'et' into score header list
59 "hplist[curscor][et]" along the "up" chain.
60
61 eh_rmv(ev, et)
62 struct s_entry *ev;
63 short et;
64
65 Removes event 'ev' of type 'et' from score header list
66 "hplist[curscor][et]" along the "up" chain.
67
68 sc_clr(ns)
69 short ns;
70
71 Clears score 'ns'.
72
73 short
74 selscor(ns)
75 short ns;
76
77 Selects score 'ns' for use.
78
79 =============================================================================
80*/
81
82#include "stddefs.h"
83#include "hwdefs.h"
84#include "memory.h"
85#include "score.h"
86
87/*
88
89*/
90
91extern short sd; /* Scroll direction */
92extern short curasg; /* Current assgnment table */
93extern short tmpoval; /* Current tempo */
94extern short curtun; /* Current tuning table */
95
96extern BOOL se_chg; /* Score free list changed flag */
97
98extern long spcount; /* Score storage pool free entry count */
99extern long frags; /* Score storage pool fragment count */
100
101extern long se1_cnt; /* Score free list E_SIZE1 entry count */
102extern long se2_cnt; /* Score free list E_SIZE2 entry count */
103extern long se3_cnt; /* Score free list E_SIZE3 entry count */
104
105extern long *pspool; /* Score storage pool pointer */
106
107extern struct s_entry *size1; /* Score E_SIZE1 entry free list pointer */
108extern struct s_entry *size2; /* Score E_SIZE2 entry free list pointer */
109extern struct s_entry *size3; /* Score E_SIZE3 entry free list pointer */
110
111extern struct s_entry *scores[N_SCORES]; /* Score pointer table */
112extern struct s_entry *seclist[N_SCORES][N_SECTS]; /* Section pointer table */
113extern struct s_entry *hplist[N_SCORES][N_TYPES]; /* Score change list pointers */
114
115extern struct s_time stimes[N_SCORES][N_SECTS]; /* section times */
116
117extern char scname[N_SCORES][16]; /* Score names */
118
119extern short curscor; /* Current score number */
120extern short cursect; /* Current section number in score */
121
122extern struct s_entry *scp; /* Current score pointer */
123
124extern long t_bak; /* Time at p_bak */
125extern long t_cur; /* Time at p_cur */
126extern long t_ctr; /* Time at p_ctr */
127extern long t_fwd; /* Time at p_fwd */
128
129extern struct s_entry *p_bak; /* Pointer to entry at left edge of display */
130extern struct s_entry *p_cur; /* Pointer to entry at current execution time */
131extern struct s_entry *p_ctr; /* Pointer to entry at center of display */
132extern struct s_entry *p_fwd; /* Pointer to entry at right edge of display */
133
134extern long spool[]; /* Score storage pool */
135
136/*
137
138*/
139
140/*
141 =============================================================================
142 evleft() -- returns total number of longs left for score storage.
143 =============================================================================
144*/
145
146long
147evleft()
148{
149 return(spcount + (se1_cnt * E_SIZE1) + (se2_cnt * E_SIZE2) +
150 (se3_cnt * E_SIZE3));
151}
152
153/*
154
155*/
156
157/*
158 =============================================================================
159 scinit() -- initializes the score data structures.
160 Returns the number of free storage units.
161 =============================================================================
162*/
163
164long
165scinit()
166{
167 register long i, *cp;
168
169 se1_cnt = 0L; /* fragments */
170 size1 = E_NULL;
171 se2_cnt = 0L;
172 size2 = E_NULL;
173 se3_cnt = 0L;
174 size3 = E_NULL;
175 se_chg = TRUE;
176 frags = 0L;
177
178 spcount = (long)MAX_SE; /* storage pool */
179 pspool = spool;
180 cp = spool;
181
182 for (i = spcount; i-- > 0; )
183 *cp++ = 0L;
184
185 for (i = 0; i < N_SCORES; i++) /* score names */
186 memcpy(scname[i], "{ empty score }", 16);
187
188 memsetw(scores, 0, 2 * N_SCORES); /* score list */
189 memsetw(hplist, 0, 2 * N_SCORES * N_TYPES); /* header lists */
190 memsetw(seclist, 0, 2 * N_SCORES * N_SECTS); /* section lists */
191 memset(stimes, 0, 12 * N_SCORES * N_SECTS); /* section times */
192
193 t_cur = t_ctr = 0L; /* times */
194 t_bak = t_cur - TO_BAK;
195 t_fwd = t_cur + TO_FWD;
196
197 p_bak = E_NULL; /* pointers */
198 p_cur = E_NULL;
199 p_ctr = E_NULL;
200 p_fwd = E_NULL;
201 scp = E_NULL;
202
203 curscor = 0; /* current score */
204 cursect = 0; /* current section */
205
206 return(evleft());
207}
208
209/*
210
211*/
212
213/*
214 =============================================================================
215 e_clr(e1) -- clear the event pointed to by 'e1'. Returns 'e1'.
216 Preserves e_size field, all others set to zero.
217 =============================================================================
218*/
219
220struct s_entry *
221e_clr(e1)
222register struct s_entry *e1;
223{
224 switch (e1->e_size) {
225
226 case E_SIZE3:
227
228 e1->e_lft = E_NULL;
229 e1->e_rgt = E_NULL;
230
231 case E_SIZE2:
232
233 e1->e_up = E_NULL;
234 e1->e_dn = E_NULL;
235
236 case E_SIZE1:
237
238 e1->e_fwd = E_NULL;
239 e1->e_bak = E_NULL;
240
241 e1->e_time = 0L;
242 e1->e_type = EV_NULL;
243 e1->e_data1 = 0;
244 e1->e_data2 = 0;
245 }
246
247 return(e1);
248}
249
250/*
251
252*/
253
254/*
255 =============================================================================
256 e_ins(e1, e2) -- inserts the event pointed to by 'e1' after the event
257 pointed to by 'e2'. Returns 'e1'.
258 =============================================================================
259*/
260
261struct s_entry *
262e_ins(e1, e2)
263register struct s_entry *e1, *e2;
264{
265 register struct s_entry *t1;
266
267 t1 = e2->e_fwd;
268 e1->e_fwd = t1;
269 e1->e_bak = e2;
270 e2->e_fwd = e1;
271 t1->e_bak = e1;
272 return(e1);
273}
274
275/*
276 =============================================================================
277 e_rmv(e1) -- removes the event pointed to by 'e1' from the list it's in.
278 Returns 'e1'.
279 =============================================================================
280*/
281
282struct s_entry *
283e_rmv(e1)
284register struct s_entry *e1;
285{
286 register struct s_entry *t1, *t2;
287
288 t1 = e1->e_bak;
289 t2 = e1->e_fwd;
290 t1->e_fwd = t2;
291 t2->e_bak = t1;
292 e1->e_fwd = E_NULL;
293 e1->e_bak = E_NULL;
294 return(e1);
295}
296
297/*
298
299*/
300
301/*
302 =============================================================================
303 e_alc() -- allocates a new event entry.
304 Returns the event entry address, or E_NULL if none can be allocated.
305 =============================================================================
306*/
307
308struct s_entry *
309e_alc(w)
310short w;
311{
312 register struct s_entry *ev, *ex;
313
314 se_chg = TRUE;
315
316 switch (w) {
317
318 case E_SIZE1:
319
320 if (spcount LT E_SIZE1) { /* try raw free pool first */
321
322 if (se1_cnt EQ 0) { /* try for a deleted entry */
323
324 if (se3_cnt) { /* try to split a size3 entry */
325
326 ex = size3;
327 size3 = ex->e_fwd;
328 ++frags;
329 --se3_cnt;
330 ex->e_size = E_SIZE1;
331 ex->e_fwd = E_NULL;
332 return(ex);
333
334 } else {
335
336 if (se2_cnt) { /* try a size2 split */
337
338 ex = size2;
339 size2 = size2->e_fwd;
340 ex->e_size = E_SIZE1;
341 ex->e_fwd = E_NULL;
342 ++frags;
343 --se2_cnt;
344 return(ex);
345
346 } else {
347
348 return(E_NULL); /* no space */
349 }
350 }
351/*
352
353*/
354 } else { /* deleted entry available */
355
356 ex = size1;
357 size1 = size1->e_fwd;
358 ex->e_fwd = E_NULL;
359 --se1_cnt;
360 return(ex);
361 }
362
363 } else { /* raw storage available */
364
365 ex = (struct s_entry *)pspool;
366 pspool += E_SIZE1;
367 spcount -= E_SIZE1;
368 ex->e_size = E_SIZE1;
369 return(ex);
370 }
371
372/*
373
374*/
375
376 case E_SIZE2:
377
378 if (spcount LT E_SIZE2) { /* try for raw storage */
379
380 if (se2_cnt EQ 0) { /* try for a deleted entry */
381
382 if (se3_cnt) { /* try to split a size3 entry */
383
384 ex = size3;
385 size3 = size3->e_fwd;
386 ex->e_size = E_SIZE2;
387 ex->e_fwd = E_NULL;
388 --se3_cnt;
389 ++frags;
390 return(ex);
391
392 } else {
393
394 return(E_NULL); /* no space */
395 }
396
397 } else { /* deleted entry available */
398
399 ex = size2;
400 size2 = size2->e_fwd;
401 ex->e_fwd = E_NULL;
402 --se2_cnt;
403 return(ex);
404 }
405
406 } else { /* raw storage available */
407
408 ex = (struct s_entry *)pspool;
409 pspool += E_SIZE2;
410 spcount -= E_SIZE2;
411 ex->e_size = E_SIZE2;
412 return(ex);
413
414 }
415
416/*
417
418*/
419
420 case E_SIZE3:
421
422 if (spcount LT E_SIZE3) { /* try for raw storage */
423
424 if (se3_cnt EQ 0) { /* try for a deleted entry */
425
426 return(E_NULL); /* no space left */
427
428 } else { /* deleted entry available */
429
430 ex = size3;
431 size3 = size3->e_fwd;
432 ex->e_fwd = E_NULL;
433 --se3_cnt;
434 return(ex);
435 }
436
437 } else { /* raw storage available */
438
439 ex = (struct s_entry *)pspool;
440 pspool += E_SIZE3;
441 spcount -= E_SIZE3;
442 ex->e_size = E_SIZE3;
443 return(ex);
444 }
445
446 default:
447
448 return(E_NULL); /* invalid request */
449 }
450
451 return(E_NULL); /* something went 'worng' ... */
452}
453
454/*
455
456*/
457
458/*
459 =============================================================================
460 e_del(e1) -- deallocates the event entry pointed to by 'e1'.
461 Returns 0 if successful, 1 if not.
462 =============================================================================
463*/
464
465short
466e_del(e1)
467register struct s_entry *e1;
468{
469 e_clr(e1);
470
471 switch (e1->e_size) {
472
473 case E_SIZE1:
474
475 e1->e_fwd = size1;
476 size1 = e1;
477 ++se1_cnt;
478 break;
479
480 case E_SIZE2:
481
482 e1->e_fwd = size2;
483 size2 = e1;
484 ++se2_cnt;
485 break;
486
487 case E_SIZE3:
488
489 e1->e_fwd = size3;
490 size3 = e1;
491 ++se3_cnt;
492 break;
493
494 default:
495 return(1);
496 }
497
498 se_chg = TRUE;
499 return(0);
500}
501
502/*
503
504*/
505
506/*
507 =============================================================================
508 eh_ins(ne, et) -- insert event 'ne' of type 'et' into score header list
509 "hplist[curscor][et]" along the "up" chain.
510 =============================================================================
511*/
512
513eh_ins(ne, et)
514register struct s_entry *ne;
515short et;
516{
517 register struct s_entry *hp, *ep;
518
519 hp = hplist[curscor][et]; /* get list pointer */
520
521 if (hp EQ E_NULL) { /* if list was empty */
522
523 hplist[curscor][et] = ne; /* start the list */
524 ne->e_up = E_NULL;
525 ne->e_dn = E_NULL;
526 return;
527 }
528
529 if (hp->e_time GT ne->e_time) { /* if first entry was later */
530
531 hp->e_dn = ne; /* add to start of list */
532 ne->e_up = hp;
533 ne->e_dn = E_NULL;
534 hplist[curscor][et] = ne;
535 return;
536 }
537
538 while (E_NULL NE (ep = hp->e_up)) { /* search forward */
539
540 if (ep->e_time GT ne->e_time) { /* if we find a later event */
541
542 ne->e_up = ep; /* insert into list */
543 ne->e_dn = hp;
544 hp->e_up = ne;
545 ep->e_dn = ne;
546 return;
547 }
548
549 hp = ep;
550 }
551
552 hp->e_up = ne; /* add to end of list */
553 ne->e_up = E_NULL;
554 ne->e_dn = hp;
555 return;
556}
557
558/*
559
560*/
561
562/*
563 =============================================================================
564 eh_rmv(ev, et) -- remove event 'ev' of type 'et' from score header list
565 "hplist[curscor][et]" along the "up" chain.
566 =============================================================================
567*/
568
569eh_rmv(ev, et)
570register struct s_entry *ev;
571short et;
572{
573 if (hplist[curscor][et] EQ ev) /* update hplist */
574 hplist[curscor][et] = ev->e_up;
575
576 if (ev->e_up NE E_NULL) /* update entry above */
577 (ev->e_up)->e_dn = ev->e_dn;
578
579 if (ev->e_dn NE E_NULL) /* update entry below */
580 (ev->e_dn)->e_up = ev->e_up;
581
582 ev->e_up = ev->e_dn = E_NULL; /* update entry itself */
583}
584
585/*
586
587*/
588
589/*
590 =============================================================================
591 sc_clr(ns) -- clear score 'ns'.
592 =============================================================================
593*/
594
595sc_clr(ns)
596register short ns;
597{
598 register struct s_entry *dsp, *nsp;
599 register short i;
600
601 if (E_NULL NE (nsp = scores[ns])) {
602
603 while (nsp NE (dsp = nsp->e_fwd)) {
604
605 e_del(e_rmv(nsp)); /* delete this one */
606 nsp = dsp; /* point at the next one */
607
608 }
609
610 e_del(nsp); /* delete final entry */
611 }
612
613 for (i = 0; i < N_TYPES; i++) /* clear header list */
614 hplist[ns][i] = E_NULL;
615
616 for (i = 0; i < N_SECTS; i++) { /* clear section lists */
617
618 seclist[ns][i] = E_NULL;
619 memset(stimes[ns], 0, 12);
620 }
621
622 memcpy(scname[ns], "{ empty score }", 16);
623
624 scores[ns] = E_NULL;
625}
626
627/*
628
629*/
630
631/*
632 =============================================================================
633 selscor(ns) -- select score 'ns' for use
634 =============================================================================
635*/
636
637short
638selscor(ns)
639register short ns;
640{
641 register short oldscor, grp;
642 register struct s_entry *nsp, *ep;
643
644 clkset(0); /* stop the clock */
645 dsclk();
646 fc_val = 0L; /* reset to start of score */
647 sd = D_FWD;
648 oldscor = curscor; /* setup for new score */
649 curscor = ns;
650
651 if (E_NULL EQ (nsp = scores[ns])) { /* initialize score if needed */
652
653 if (E_NULL EQ (nsp = e_alc(E_SIZE1))) { /* score header */
654
655 curscor = oldscor;
656 return(FAILURE);
657 }
658
659 scores[ns] = nsp;
660 nsp->e_fwd = nsp;
661 nsp->e_bak = nsp;
662 nsp->e_type = EV_SCORE;
663 nsp->e_data1 = ns;
664 nsp->e_time = 0L;
665
666 if (E_NULL EQ (ep = e_alc(E_SIZE1))) { /* score end */
667
668 sc_clr(ns);
669 curscor = oldscor;
670 return(FAILURE);
671 }
672
673 ep->e_type = EV_FINI;
674 ep->e_data1 = ns;
675 e_ins(ep, nsp);
676 ep->e_time = 0x7FFFFFFFL;
677 nsp = scores[ns];
678 memcpy(&scname[ns][0], "%%% Untitled %%%", 16);
679 }
680
681 scp = nsp;
682 p_bak = nsp;
683 p_cur = nsp;
684 p_ctr = nsp;
685 p_fwd = nsp;
686 cursect = 0;
687 sc_goto(0L);
688 return(SUCCESS);
689}
Note: See TracBrowser for help on using the repository browser.