-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauto_pause_driver_impl.c
70 lines (57 loc) · 1.71 KB
/
auto_pause_driver_impl.c
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
#include "auto_pause_driver_impl.h"
typedef struct auto_pause_driver {
core_t *shared_core;
uint64_t target_frames;
uint64_t target_cpu_cycles;
bool quit_on_pause;
bool pause_on_start;
} auto_pause_driver_t;
void auto_pause_driver_on_ppu_frame(auto_pause_driver_ref self, ppu_ref ppu,
uint64_t frames)
{
if (self->target_frames > 0 && self->target_frames <= frames) {
core_pause(self->shared_core);
auto_pause_driver_detach_ppu_frame(self, self->shared_core);
}
}
void auto_pause_driver_on_cpu_step(auto_pause_driver_ref self, cpu_ref cpu)
{
if (self->target_cpu_cycles > 0 &&
self->target_cpu_cycles <= cpu->shared_counter->cycles) {
core_pause(self->shared_core);
auto_pause_driver_detach_cpu_step(self, self->shared_core);
}
}
void auto_pause_driver_destroy(auto_pause_driver_ref self)
{
if (self) {
FREE(self);
}
}
void auto_pause_driver_on_core_pause(auto_pause_driver_ref self, core_ref core)
{
if (self->quit_on_pause) {
core_quit(core);
}
}
void auto_pause_driver_on_core_start(auto_pause_driver_ref self, core_ref core)
{
if (self->pause_on_start) {
core_pause(core);
}
auto_pause_driver_detach_core_start(self, self->shared_core);
}
auto_pause_driver_ref auto_pause_driver_create(core_t *core, const args_t *args)
{
auto_pause_driver_ref self = NULL;
TALLOC(self);
GUARD(self->shared_core = core);
self->target_frames = args->skip_frames;
self->target_cpu_cycles = args->skip_cycles;
self->quit_on_pause = args->quiet;
self->pause_on_start = args->pause_start;
return self;
error:
auto_pause_driver_destroy(self);
return NULL;
}