-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.cpp
79 lines (76 loc) · 1.65 KB
/
event.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <cstdlib> // for malloc()
#include <cstdio> // for printf()
#include "event.h"
#include "cpu.h"
Event::Event(CPU *cpu) {
this->cpu = cpu;
}
void Event::add(s32 clks, void (*func)()) {
struct _event *event, *prev, *next, *last, *tmp;
event = (struct _event *)malloc(sizeof(struct _event));
if (head != NULL) {
for (tmp = head; tmp != NULL; last = tmp, tmp = tmp->next) {
if (clks < tmp->fired_clks) {
event->prev = tmp->prev;
tmp->prev = event;
event->next = tmp;
break;
}
}
if (tmp == NULL) {
event->prev = last;
last->next = event;
event->next = NULL;
}
} else {
head = event;
}
event->now_clks = cpu->clks;
event->fired_clks = cpu->clks - clks;
cpu->exit_clks = event->fired_clks < 0? 0 : cpu->clks - clks;
prev = event->prev;
if (prev) {
event->delta_clks = prev->fired_clks - event->fired_clks;
}
next = event->next;
if (next) {
next->delta_clks = event->fired_clks - next->fired_clks;
}
}
void Event::check0(void) {
if (head == NULL) {
return;
}
if (head->fired_clks < 0) {
head->fired_clks += cpu->remains_clks;
if (head->fired_clks < 0) {
return;
}
cpu->exit_clks = head->fired_clks;
return;
}
printf("xxx check0()\n");
}
void Event::check(void) {
struct _event *event;
if (head == NULL) {
return;
}
for (event = head; event != NULL; event = event->next) {
if (event->fired_clks > 0 && cpu->clks <= event->fired_clks) {
(*event->func)();
// リストから外す
if (event->prev) {
event->prev->next = event->next;
} else {
head = event->next;
}
if (event->next) {
event->next->prev = event->prev;
}
free(event);
} else {
break;
}
}
}