|
|
1.1 ! root 1: /*----------------------------------------------------------------------*/ ! 2: /* */ ! 3: /* PACMAN for BBN BitGraphs */ ! 4: /* */ ! 5: /* File: sched.c68 */ ! 6: /* Contents: passive real-time-clock-based scheduler */ ! 7: /* Author: Bob Brown (rlb) */ ! 8: /* Purdue CS */ ! 9: /* Date: May, 1982 */ ! 10: /* Description: An event list manager for the scheduling */ ! 11: /* of C procedures after given time delays */ ! 12: /* */ ! 13: /*----------------------------------------------------------------------*/ ! 14: ! 15: #include "style.h" ! 16: #include "pacman.h" ! 17: #define Event PEvent ! 18: ! 19: /* ! 20: ** Beacuse the scheduler calls routines that re-enqueue themselves, ! 21: ** The following constant is needed to prevent elpoll() from starving ! 22: ** the keyboard polling routine when the monsters are running flat-out. ! 23: */ ! 24: ! 25: #define MAXLOOPS 5 ! 26: ! 27: /* ! 28: ** elinit() - initialize the event list to empty. ! 29: ** eladd() - add an event to the event list. ! 30: ** elpoll() - called at in polling loop to run scheduled events. ! 31: */ ! 32: ! 33: /* ! 34: ** MAXEVENTS ... ! 35: ** ! 36: ** 1 for pacman ! 37: ** 4 for monsters ! 38: ** 4 for power pill effects ! 39: ** 1 for bonus fruits ! 40: ** 3 for tone generators ! 41: */ ! 42: ! 43: #define MAXEVENTS 13 ! 44: #define ENULL ((event *) 0) ! 45: ! 46: typedef struct ev { ! 47: struct ev *next; ! 48: int time; ! 49: int (*routine)(); /* procedure to call */ ! 50: char *arg0; /* optional first argument */ ! 51: int arg1; /* optional second argument */ ! 52: } event; ! 53: ! 54: event *Eventfree; ! 55: event *Eventhead; ! 56: event Event[MAXEVENTS]; ! 57: ! 58: extern int clock; ! 59: ! 60: elinit() ! 61: { ! 62: register event *ep; ! 63: Eventfree = ENULL; ! 64: for ( ep=Event ; ep<&Event[MAXEVENTS] ; ep++ ) { ! 65: ep->next = Eventfree; ! 66: Eventfree = ep; ! 67: } ! 68: Eventhead = ENULL; ! 69: clock = 0; ! 70: } ! 71: /* ! 72: ** eladd - add an event to the event list ! 73: */ ! 74: /* VARARGS 2 */ ! 75: eladd(delta,routine,arg0,arg1) ! 76: int delta; ! 77: int (*routine)(); ! 78: char *arg0; ! 79: int arg1; ! 80: { ! 81: int time; ! 82: register event *ep, *pp, *cp; ! 83: ! 84: #ifdef BLIT ! 85: delta = (delta+8)/16; ! 86: #endif ! 87: #ifdef V1_25 ! 88: delta = (delta+5)/10; ! 89: #endif ! 90: ! 91: if ( Eventfree == ENULL ) { ! 92: #ifndef BLIT ! 93: error("Event list overflow"); ! 94: #endif ! 95: return; ! 96: } ! 97: cp = Eventfree; ! 98: Eventfree = Eventfree->next; ! 99: ! 100: time = delta+clock; ! 101: cp->time = time; ! 102: cp->routine = routine; ! 103: cp->arg0 = arg0; ! 104: cp->arg1 = arg1; ! 105: ! 106: ep = Eventhead; ! 107: pp = ENULL; ! 108: while ( ep!=ENULL && time>ep->time ) { ! 109: pp = ep; ! 110: ep = ep->next; ! 111: } ! 112: cp->next = ep; ! 113: if ( pp == ENULL ) ! 114: Eventhead = cp; ! 115: else ! 116: pp->next = cp; ! 117: } ! 118: /* ! 119: ** elpoll - check if anything to schedule ! 120: */ ! 121: elpoll() ! 122: { ! 123: register int maxloops; ! 124: register event *ep; ! 125: maxloops = MAXLOOPS; ! 126: while ( (ep=Eventhead)!=ENULL && ep->time < clock && --maxloops > 0) { ! 127: Eventhead = ep->next; ! 128: (*ep->routine)(ep->arg0,ep->arg1); ! 129: ep->next = Eventfree; ! 130: Eventfree = ep; ! 131: } ! 132: } ! 133: /* ! 134: ** eladjust - adjust the scheduler based on processor delay ! 135: */ ! 136: eladjust(ms) ! 137: register int ms; ! 138: { ! 139: #ifdef BLIT ! 140: ms = (ms+8)/16; ! 141: #endif ! 142: #ifdef V1_25 ! 143: ms = (ms+5)/10; ! 144: #endif ! 145: clock -= ms; ! 146: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.