7 Event evhblank, evtimer, evenv;
8 extern Event evsamp, chev[4];
9 Event *events[NEVENT] = {&evhblank, &evtimer, &evenv, &evsamp, &chev[0], &chev[1], &chev[2], &chev[3]};
11 static int timshtab[4] = {12, 4, 6, 8}, timsh;
13 Var evvars[] = {VAR(timsh), VAR(timclock), {nil, 0, 0}};
16 addevent(Event *ev, int time)
23 for(p = &elist; (e = *p) != nil; p = &e->next){
40 for(p = &elist; (e = *p) != nil; p = &e->next)
44 e->next->time += e->time;
60 }while((elist->time += t) <= 0);
66 timclock = clock & -(1<<timsh);
67 if((reg[TAC] & 4) != 0){
69 addevent(&evtimer, 0x100 - reg[TIMA] << timsh);// | -clock & (1<<timsh)-1);
74 timertac(u8int n, int t)
76 if((reg[TAC] & 7) == (n & 7) && !t)
78 if((reg[TAC] & 4) != 0){
80 reg[TIMA] += clock - timclock >> timsh;
82 timclock = clock & -(1<<timsh);
83 timsh = timshtab[n & 3];
84 if((mode & TURBO) == 0)
87 addevent(&evtimer, 0x100 - reg[TIMA] << timsh | -clock & (1<<timsh)-1);
93 if((reg[TAC] & 4) == 0)
95 return reg[TIMA] + (clock - timclock >> timsh);
101 reg[TIMA] = reg[TMA];
102 addevent(&evtimer, 0x100 - reg[TIMA] << timsh);
109 extern void hblanktick(void *);
110 extern void envtick(void *);
111 extern void wavetick(void *);
112 extern void chantick(void *);
114 evhblank.f = hblanktick;
115 addevent(&evhblank, 240*4);
116 evtimer.f = timertick;
118 addevent(&evenv, FREQ / 512);
119 chev[0].f = chantick;
120 chev[1].f = chantick;
121 chev[2].f = chantick;
122 chev[3].f = chantick;