-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyzer_driver_impl.c
154 lines (128 loc) · 4.56 KB
/
analyzer_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "analyzer_driver_impl.h"
#include "console.h"
#include "debugger.h"
#include "disas.h"
#include "event_logger_driver.h"
typedef struct analyzer_driver {
core_ref shared_core;
debugger_ref debugger;
disas_ref disas;
console_ref console;
event_logger_driver_ref event_logger;
} analyzer_driver_t;
#define _LOG_STR_LEN (24)
void analyzer_driver_destroy(analyzer_driver_ref self)
{
if (self) {
debugger_destroy(self->debugger);
disas_destroy(self->disas);
console_destroy(self->console);
FREE(self);
}
}
analyzer_driver_ref analyzer_driver_create(core_ref core)
{
analyzer_driver_ref self = NULL;
TALLOC(self);
GUARD(self->shared_core = core);
GUARD(self->debugger = debugger_create(core->bus));
GUARD(self->disas = disas_create(core->mapper));
GUARD(self->event_logger = event_logger_driver_plug(self->shared_core));
GUARD(self->console = console_create(core, self->debugger, self->disas,
self->event_logger));
return self;
error:
analyzer_driver_destroy(self);
return NULL;
}
void analyzer_driver_on_cpu_read(analyzer_driver_ref self, cpu_ref cpu,
uint16_t addr, size_t length)
{
if (addr >= 0x8000) {
disas_mark_data_runtime(self->disas, addr, length);
}
}
void analyzer_driver_on_cpu_write(analyzer_driver_ref self, cpu_ref cpu,
uint16_t addr, size_t length)
{
}
void analyzer_driver_on_core_pause(analyzer_driver_ref self, core_ref core)
{
}
void analyzer_driver_on_core_resume(analyzer_driver_ref self, core_ref core)
{
console_set_pause_reason(self->console, CONSOLE_PAUSE_REASON_NONE);
}
static inline void _console_update(analyzer_driver_ref self)
{
debugger_set_step_mode(self->debugger, DEBUGGER_STEP_MODE_NONE);
console_update(self->console);
if (debugger_get_step_mode(self->debugger) != DEBUGGER_STEP_MODE_NONE) {
core_resume(self->shared_core);
}
}
void analyzer_driver_on_core_poll_in_pause(analyzer_driver_ref self,
core_ref core)
{
_console_update(self);
}
void analyzer_driver_on_core_start(analyzer_driver_ref self, core_ref core)
{
disas_mark_from_vectors(self->disas);
_console_update(self);
}
void analyzer_driver_on_ppu_frame(analyzer_driver_ref self, ppu_ref ppu,
uint64_t frames)
{
if (debugger_get_step_mode(self->debugger) == DEBUGGER_STEP_MODE_FRAME) {
core_pause(self->shared_core);
}
_console_update(self);
}
void analyzer_driver_on_ppu_scanline(analyzer_driver_ref self, ppu_ref ppu,
int line, const uint16_t *dots)
{
if (debugger_get_step_mode(self->debugger) == DEBUGGER_STEP_MODE_SCANLINE) {
core_pause(self->shared_core);
}
}
void analyzer_driver_on_cpu_decode(analyzer_driver_ref self, cpu_ref cpu,
uint16_t pc)
{
disas_mark_op_runtime(self->disas, cpu->reg.pc, cpu->last_op == OP_20_JSR);
if (debugger_check_breakpoint_hit(self->debugger, pc)) {
core_pause(self->shared_core);
console_set_pause_reason(self->console,
CONSOLE_PAUSE_REASON_BREAKPOINT);
console_focus_pc(self->console);
}
debugger_check_scanline_before(self->debugger,
self->shared_core->ppu->scanline.x,
self->shared_core->ppu->scanline.y);
}
void analyzer_driver_on_cpu_step(analyzer_driver_ref self, cpu_ref cpu)
{
if (debugger_get_step_mode(self->debugger) ==
DEBUGGER_STEP_MODE_INSTRUCTION) {
core_pause(self->shared_core);
}
if (debugger_check_scanline_after(self->debugger,
self->shared_core->ppu->scanline.x,
self->shared_core->ppu->scanline.y)) {
core_pause(self->shared_core);
console_focus_pc(self->console);
console_set_pause_reason(self->console,
CONSOLE_PAUSE_REASON_SCANLINE_BREAK);
}
}
void analyzer_driver_on_cpu_interrupt(analyzer_driver_ref self, cpu_ref cpu,
interruption_type_t acks)
{
debugger_breakpoint_unhit(self->debugger, cpu->reg.pc);
if (debugger_check_interruption_break(self->debugger, acks)) {
core_pause(self->shared_core);
console_focus_pc(self->console);
console_set_pause_reason(self->console,
CONSOLE_PAUSE_REASON_INTERRUPTION_BREAK);
}
}