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