source: buchla-68k/ram/scinit.c@ a4bd34f

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

Unused variables and parameters.

  • Property mode set to 100644
File size: 11.4 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 eh_ins(ne, et)
54 struct s_entry *ne;
55 short et;
56
57 Inserts event 'ne' of type 'et' into score header list
58 "hplist[curscor][et]" along the "up" chain.
59
60 eh_rmv(ev, et)
61 struct s_entry *ev;
62 short et;
63
64 Removes event 'ev' of type 'et' from score header list
65 "hplist[curscor][et]" along the "up" chain.
66
67 sc_clr(ns)
68 short ns;
69
70 Clears score 'ns'.
71
72 short
73 selscor(ns)
74 short ns;
75
76 Selects score 'ns' for use.
77
78 =============================================================================
79*/
80
81#include "ram.h"
82
83/*
84 =============================================================================
85 evleft() -- returns total number of longs left for score storage.
86 =============================================================================
87*/
88
89int32_t evleft(void)
90{
91 return(spcount + (se1_cnt * E_SIZE1) + (se2_cnt * E_SIZE2) +
92 (se3_cnt * E_SIZE3));
93}
94
95/*
96 =============================================================================
97 scinit() -- initializes the score data structures.
98 Returns the number of free storage units.
99 =============================================================================
100*/
101
102int32_t scinit(void)
103{
104 register int32_t i, *cp;
105
106 se1_cnt = 0L; /* fragments */
107 size1 = E_NULL;
108 se2_cnt = 0L;
109 size2 = E_NULL;
110 se3_cnt = 0L;
111 size3 = E_NULL;
112 se_chg = TRUE;
113 frags = 0L;
114
115 spcount = (int32_t)MAX_SE; /* storage pool */
116 pspool = spool;
117 cp = spool;
118
119 for (i = spcount; i-- > 0; )
120 *cp++ = 0L;
121
122 for (i = 0; i < N_SCORES; i++) /* score names */
123 memcpy(scname[i], "{ empty score }", 16);
124
125 memsetw(scores, 0, 2 * N_SCORES); /* score list */
126 memsetw(hplist, 0, 2 * N_SCORES * N_TYPES); /* header lists */
127 memsetw(seclist, 0, 2 * N_SCORES * N_SECTS); /* section lists */
128 memset(stimes, 0, 12 * N_SCORES * N_SECTS); /* section times */
129
130 t_cur = t_ctr = 0L; /* times */
131 t_bak = t_cur - TO_BAK;
132 t_fwd = t_cur + TO_FWD;
133
134 p_bak = E_NULL; /* pointers */
135 p_cur = E_NULL;
136 p_ctr = E_NULL;
137 p_fwd = E_NULL;
138 scp = E_NULL;
139
140 curscor = 0; /* current score */
141 cursect = 0; /* current section */
142
143 return(evleft());
144}
145
146/*
147 =============================================================================
148 e_clr(e1) -- clear the event pointed to by 'e1'. Returns 'e1'.
149 Preserves e_size field, all others set to zero.
150 =============================================================================
151*/
152
153struct s_entry *e_clr(struct s_entry *e1)
154{
155 switch (e1->e_size) {
156
157 case E_SIZE3:
158
159 e1->e_lft = E_NULL;
160 e1->e_rgt = E_NULL;
161
162 case E_SIZE2:
163
164 e1->e_up = E_NULL;
165 e1->e_dn = E_NULL;
166
167 case E_SIZE1:
168
169 e1->e_fwd = E_NULL;
170 e1->e_bak = E_NULL;
171
172 e1->e_time = 0L;
173 e1->e_type = EV_NULL;
174 e1->e_data1 = 0;
175 e1->e_data2 = 0;
176 }
177
178 return(e1);
179}
180
181/*
182 =============================================================================
183 e_ins(e1, e2) -- inserts the event pointed to by 'e1' after the event
184 pointed to by 'e2'. Returns 'e1'.
185 =============================================================================
186*/
187
188struct s_entry *e_ins(struct s_entry *e1, struct s_entry *e2)
189{
190 register struct s_entry *t1;
191
192 t1 = e2->e_fwd;
193 e1->e_fwd = t1;
194 e1->e_bak = e2;
195 e2->e_fwd = e1;
196 t1->e_bak = e1;
197 return(e1);
198}
199
200/*
201 =============================================================================
202 e_rmv(e1) -- removes the event pointed to by 'e1' from the list it's in.
203 Returns 'e1'.
204 =============================================================================
205*/
206
207struct s_entry *e_rmv(struct s_entry *e1)
208{
209 register struct s_entry *t1, *t2;
210
211 t1 = e1->e_bak;
212 t2 = e1->e_fwd;
213 t1->e_fwd = t2;
214 t2->e_bak = t1;
215 e1->e_fwd = E_NULL;
216 e1->e_bak = E_NULL;
217 return(e1);
218}
219
220/*
221 =============================================================================
222 e_alc() -- allocates a new event entry.
223 Returns the event entry address, or E_NULL if none can be allocated.
224 =============================================================================
225*/
226
227struct s_entry *e_alc(int16_t w)
228{
229 register struct s_entry *ex;
230
231 se_chg = TRUE;
232
233 switch (w) {
234
235 case E_SIZE1:
236
237 if (spcount LT E_SIZE1) { /* try raw free pool first */
238
239 if (se1_cnt EQ 0) { /* try for a deleted entry */
240
241 if (se3_cnt) { /* try to split a size3 entry */
242
243 ex = size3;
244 size3 = ex->e_fwd;
245 ++frags;
246 --se3_cnt;
247 ex->e_size = E_SIZE1;
248 ex->e_fwd = E_NULL;
249 return(ex);
250
251 } else {
252
253 if (se2_cnt) { /* try a size2 split */
254
255 ex = size2;
256 size2 = size2->e_fwd;
257 ex->e_size = E_SIZE1;
258 ex->e_fwd = E_NULL;
259 ++frags;
260 --se2_cnt;
261 return(ex);
262
263 } else {
264
265 return(E_NULL); /* no space */
266 }
267 }
268
269 } else { /* deleted entry available */
270
271 ex = size1;
272 size1 = size1->e_fwd;
273 ex->e_fwd = E_NULL;
274 --se1_cnt;
275 return(ex);
276 }
277
278 } else { /* raw storage available */
279
280 ex = (struct s_entry *)pspool;
281 pspool += E_SIZE1;
282 spcount -= E_SIZE1;
283 ex->e_size = E_SIZE1;
284 return(ex);
285 }
286
287 case E_SIZE2:
288
289 if (spcount LT E_SIZE2) { /* try for raw storage */
290
291 if (se2_cnt EQ 0) { /* try for a deleted entry */
292
293 if (se3_cnt) { /* try to split a size3 entry */
294
295 ex = size3;
296 size3 = size3->e_fwd;
297 ex->e_size = E_SIZE2;
298 ex->e_fwd = E_NULL;
299 --se3_cnt;
300 ++frags;
301 return(ex);
302
303 } else {
304
305 return(E_NULL); /* no space */
306 }
307
308 } else { /* deleted entry available */
309
310 ex = size2;
311 size2 = size2->e_fwd;
312 ex->e_fwd = E_NULL;
313 --se2_cnt;
314 return(ex);
315 }
316
317 } else { /* raw storage available */
318
319 ex = (struct s_entry *)pspool;
320 pspool += E_SIZE2;
321 spcount -= E_SIZE2;
322 ex->e_size = E_SIZE2;
323 return(ex);
324
325 }
326
327 case E_SIZE3:
328
329 if (spcount LT E_SIZE3) { /* try for raw storage */
330
331 if (se3_cnt EQ 0) { /* try for a deleted entry */
332
333 return(E_NULL); /* no space left */
334
335 } else { /* deleted entry available */
336
337 ex = size3;
338 size3 = size3->e_fwd;
339 ex->e_fwd = E_NULL;
340 --se3_cnt;
341 return(ex);
342 }
343
344 } else { /* raw storage available */
345
346 ex = (struct s_entry *)pspool;
347 pspool += E_SIZE3;
348 spcount -= E_SIZE3;
349 ex->e_size = E_SIZE3;
350 return(ex);
351 }
352
353 default:
354
355 return(E_NULL); /* invalid request */
356 }
357
358 return(E_NULL); /* something went 'worng' ... */
359}
360
361/*
362 =============================================================================
363 e_del(e1) -- deallocates the event entry pointed to by 'e1'.
364 Returns 0 if successful, 1 if not.
365 =============================================================================
366*/
367
368int16_t e_del(struct s_entry *e1)
369{
370 e_clr(e1);
371
372 switch (e1->e_size) {
373
374 case E_SIZE1:
375
376 e1->e_fwd = size1;
377 size1 = e1;
378 ++se1_cnt;
379 break;
380
381 case E_SIZE2:
382
383 e1->e_fwd = size2;
384 size2 = e1;
385 ++se2_cnt;
386 break;
387
388 case E_SIZE3:
389
390 e1->e_fwd = size3;
391 size3 = e1;
392 ++se3_cnt;
393 break;
394
395 default:
396 return(1);
397 }
398
399 se_chg = TRUE;
400 return(0);
401}
402
403/*
404 =============================================================================
405 eh_ins(ne, et) -- insert event 'ne' of type 'et' into score header list
406 "hplist[curscor][et]" along the "up" chain.
407 =============================================================================
408*/
409
410void eh_ins(struct s_entry *ne, int16_t et)
411{
412 register struct s_entry *hp, *ep;
413
414 hp = hplist[curscor][et]; /* get list pointer */
415
416 if (hp EQ E_NULL) { /* if list was empty */
417
418 hplist[curscor][et] = ne; /* start the list */
419 ne->e_up = E_NULL;
420 ne->e_dn = E_NULL;
421 return;
422 }
423
424 if (hp->e_time GT ne->e_time) { /* if first entry was later */
425
426 hp->e_dn = ne; /* add to start of list */
427 ne->e_up = hp;
428 ne->e_dn = E_NULL;
429 hplist[curscor][et] = ne;
430 return;
431 }
432
433 while (E_NULL NE (ep = hp->e_up)) { /* search forward */
434
435 if (ep->e_time GT ne->e_time) { /* if we find a later event */
436
437 ne->e_up = ep; /* insert into list */
438 ne->e_dn = hp;
439 hp->e_up = ne;
440 ep->e_dn = ne;
441 return;
442 }
443
444 hp = ep;
445 }
446
447 hp->e_up = ne; /* add to end of list */
448 ne->e_up = E_NULL;
449 ne->e_dn = hp;
450 return;
451}
452
453/*
454 =============================================================================
455 eh_rmv(ev, et) -- remove event 'ev' of type 'et' from score header list
456 "hplist[curscor][et]" along the "up" chain.
457 =============================================================================
458*/
459
460void eh_rmv(struct s_entry *ev, int16_t et)
461{
462 if (hplist[curscor][et] EQ ev) /* update hplist */
463 hplist[curscor][et] = ev->e_up;
464
465 if (ev->e_up NE E_NULL) /* update entry above */
466 (ev->e_up)->e_dn = ev->e_dn;
467
468 if (ev->e_dn NE E_NULL) /* update entry below */
469 (ev->e_dn)->e_up = ev->e_up;
470
471 ev->e_up = ev->e_dn = E_NULL; /* update entry itself */
472}
473
474/*
475 =============================================================================
476 sc_clr(ns) -- clear score 'ns'.
477 =============================================================================
478*/
479
480void sc_clr(int16_t ns)
481{
482 register struct s_entry *dsp, *nsp;
483 register int16_t i;
484
485 if (E_NULL NE (nsp = scores[ns])) {
486
487 while (nsp NE (dsp = nsp->e_fwd)) {
488
489 e_del(e_rmv(nsp)); /* delete this one */
490 nsp = dsp; /* point at the next one */
491
492 }
493
494 e_del(nsp); /* delete final entry */
495 }
496
497 for (i = 0; i < N_TYPES; i++) /* clear header list */
498 hplist[ns][i] = E_NULL;
499
500 for (i = 0; i < N_SECTS; i++) { /* clear section lists */
501
502 seclist[ns][i] = E_NULL;
503 memset(stimes[ns], 0, 12);
504 }
505
506 memcpy(scname[ns], "{ empty score }", 16);
507
508 scores[ns] = E_NULL;
509}
510
511/*
512 =============================================================================
513 selscor(ns) -- select score 'ns' for use
514 =============================================================================
515*/
516
517int16_t selscor(int16_t ns)
518{
519 register int16_t oldscor;
520 register struct s_entry *nsp, *ep;
521
522 clkset(0); /* stop the clock */
523 dsclk();
524 fc_val = 0L; /* reset to start of score */
525 sd = D_FWD;
526 oldscor = curscor; /* setup for new score */
527 curscor = ns;
528
529 if (E_NULL EQ (nsp = scores[ns])) { /* initialize score if needed */
530
531 if (E_NULL EQ (nsp = e_alc(E_SIZE1))) { /* score header */
532
533 curscor = oldscor;
534 return(FAILURE);
535 }
536
537 scores[ns] = nsp;
538 nsp->e_fwd = nsp;
539 nsp->e_bak = nsp;
540 nsp->e_type = EV_SCORE;
541 nsp->e_data1 = ns;
542 nsp->e_time = 0L;
543
544 if (E_NULL EQ (ep = e_alc(E_SIZE1))) { /* score end */
545
546 sc_clr(ns);
547 curscor = oldscor;
548 return(FAILURE);
549 }
550
551 ep->e_type = EV_FINI;
552 ep->e_data1 = ns;
553 e_ins(ep, nsp);
554 ep->e_time = 0x7FFFFFFFL;
555 nsp = scores[ns];
556 memcpy(&scname[ns][0], "%%% Untitled %%%", 16);
557 }
558
559 scp = nsp;
560 p_bak = nsp;
561 p_cur = nsp;
562 p_ctr = nsp;
563 p_fwd = nsp;
564 cursect = 0;
565 sc_goto(0L);
566 return(SUCCESS);
567}
568
Note: See TracBrowser for help on using the repository browser.