54
54
typedef struct _debug_comment debug_comment;
55
55
struct _debug_comment
59
char text[DEBUG_COMMENT_MAX_LINE_LENGTH];
59
char text[DEBUG_COMMENT_MAX_LINE_LENGTH];
64
typedef struct _comment_group comment_group;
65
/* in debugcpu.h -- typedef struct _debug_cpu_comment_group debug_cpu_comment_group; */
66
struct _debug_cpu_comment_group
69
debug_comment *comment_info[DEBUG_COMMENT_MAX_NUM];
70
debug_comment * comment_info[DEBUG_COMMENT_MAX_NUM];
74
75
/***************************************************************************
76
***************************************************************************/
78
static comment_group *debug_comments;
82
/***************************************************************************
83
76
FUNCTION PROTOTYPES
84
77
***************************************************************************/
103
94
int debug_comment_init(running_machine *machine)
96
const device_config *cpu;
107
for (numcpu = 0; numcpu < ARRAY_LENGTH(machine->cpu); numcpu++)
108
if (machine->cpu[numcpu] == NULL)
98
/* allocate memory for the comments */
99
for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu))
112
/* allocate enough comment groups for the total # of cpu's */
113
debug_comments = auto_alloc_array_clear(machine, comment_group, numcpu);
115
/* automatically load em up */
116
debug_comment_load(machine);
118
add_exit_callback(machine, debug_comment_exit);
101
cpu_debug_data *cpudata = cpu_get_debug_data(cpu);
102
cpudata->comments = auto_alloc_clear(machine, debug_cpu_comment_group);
105
/* automatically load em up */
106
debug_comment_load(machine);
107
add_exit_callback(machine, debug_comment_exit);
131
118
int debug_comment_add(const device_config *device, offs_t addr, const char *comment, rgb_t color, UINT32 c_crc)
133
int cpu_num = cpu_get_index(device);
120
debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
121
int insert_point = comments->comment_count;
135
int insert_point = debug_comments[cpu_num].comment_count;
138
125
/* Create a new item to insert into the list */
139
126
debug_comment *insert_me = alloc_or_die(debug_comment);
144
131
strcpy(insert_me->text, comment);
146
133
/* Find the insert point */
147
for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
134
for (i = 0; i < comments->comment_count; i++)
149
if (insert_me->address < debug_comments[cpu_num].comment_info[i]->address)
136
if (insert_me->address < comments->comment_info[i]->address)
151
138
insert_point = i;
154
else if (insert_me->address == debug_comments[cpu_num].comment_info[i]->address &&
155
insert_me->crc == debug_comments[cpu_num].comment_info[i]->crc)
141
else if (insert_me->address == comments->comment_info[i]->address &&
142
insert_me->crc == comments->comment_info[i]->crc)
157
144
insert_point = i;
163
150
/* Got an exact match? Just replace */
166
free(debug_comments[cpu_num].comment_info[insert_point]);
167
debug_comments[cpu_num].comment_info[insert_point] = insert_me;
168
debug_comments[cpu_num].change_count++;
153
free(comments->comment_info[insert_point]);
154
comments->comment_info[insert_point] = insert_me;
155
comments->change_count++;
170
157
/* force an update of disassembly views */
171
158
debug_view_update_type(device->machine, DVT_DISASSEMBLY);
175
162
/* Otherwise insert */
176
163
/* First, shift the list down */
177
for (i = debug_comments[cpu_num].comment_count; i >= insert_point; i--)
178
debug_comments[cpu_num].comment_info[i] = debug_comments[cpu_num].comment_info[i-1];
164
for (i = comments->comment_count; i >= insert_point; i--)
165
comments->comment_info[i] = comments->comment_info[i-1];
180
167
/* do the insertion */
181
debug_comments[cpu_num].comment_info[insert_point] = insert_me;
182
debug_comments[cpu_num].comment_count++;
183
debug_comments[cpu_num].change_count++;
168
comments->comment_info[insert_point] = insert_me;
169
comments->comment_count++;
170
comments->change_count++;
185
172
/* force an update of disassembly views */
186
173
debug_view_update_type(device->machine, DVT_DISASSEMBLY);
198
185
int debug_comment_remove(const device_config *device, offs_t addr, UINT32 c_crc)
200
int cpu_num = cpu_get_index(device);
187
debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
202
188
int remove_index = -1;
204
for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
206
if (debug_comments[cpu_num].comment_info[i]->address == addr) /* got an address match */
208
if (debug_comments[cpu_num].comment_info[i]->crc == c_crc)
191
for (i = 0; i < comments->comment_count; i++)
192
if (comments->comment_info[i]->address == addr) /* got an address match */
193
if (comments->comment_info[i]->crc == c_crc)
210
194
remove_index = i;
215
196
/* The comment doesn't exist? */
216
197
if (remove_index == -1)
219
200
/* Okay, it's there, now remove it */
220
free(debug_comments[cpu_num].comment_info[remove_index]);
222
for (i = remove_index; i < debug_comments[cpu_num].comment_count-1; i++)
224
debug_comments[cpu_num].comment_info[i] = debug_comments[cpu_num].comment_info[i+1];
227
debug_comments[cpu_num].comment_count--;
228
debug_comments[cpu_num].change_count++;
201
free(comments->comment_info[remove_index]);
203
for (i = remove_index; i < comments->comment_count-1; i++)
204
comments->comment_info[i] = comments->comment_info[i+1];
206
comments->comment_count--;
207
comments->change_count++;
230
209
/* force an update of disassembly views */
231
210
debug_view_update_type(device->machine, DVT_DISASSEMBLY);
243
222
const char *debug_comment_get_text(const device_config *device, offs_t addr, UINT32 c_crc)
245
int cpu_num = cpu_get_index(device);
224
debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
248
227
/* inefficient - should use bsearch - but will be a little tricky with multiple comments per addr */
249
for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
251
if (debug_comments[cpu_num].comment_info[i]->address == addr) /* got an address match */
228
for (i = 0; i < comments->comment_count; i++)
229
if (comments->comment_info[i]->address == addr) /* got an address match */
253
231
/* now check the bank information to be sure */
254
if (debug_comments[cpu_num].comment_info[i]->crc == c_crc)
256
return debug_comments[cpu_num].comment_info[i]->text;
232
if (comments->comment_info[i]->crc == c_crc)
233
return comments->comment_info[i]->text;
291
268
UINT32 debug_comment_all_change_count(running_machine *machine)
270
const device_config *cpu;
294
271
UINT32 retVal = 0;
296
for (i = 0; i < ARRAY_LENGTH(machine->cpu); i++)
297
if (machine->cpu[i] != NULL)
298
retVal += debug_comments[i].change_count ;
273
for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu))
275
debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
276
retVal += comments->change_count;
343
322
void debug_comment_dump(const device_config *device, offs_t addr)
345
int cpu_num = cpu_get_index(device);
324
debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
351
for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
353
if (debug_comments[cpu_num].comment_info[i]->is_valid)
355
logerror("%d : %s (%d %d)\n", i, debug_comments[cpu_num].comment_info[i]->text,
356
debug_comments[cpu_num].comment_info[i]->address,
357
debug_comments[cpu_num].comment_info[i]->crc);
330
for (i = 0; i < comments->comment_count; i++)
331
if (comments->comment_info[i]->is_valid)
332
logerror("%d : %s (%d %d)\n", i, comments->comment_info[i]->text,
333
comments->comment_info[i]->address,
334
comments->comment_info[i]->crc);
363
338
UINT32 c_crc = debug_comment_get_opcode_crc32(device, addr);
365
for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
367
if (debug_comments[cpu_num].comment_info[i]->address == addr) /* got an address match */
340
for (i = 0; i < comments->comment_count; i++)
341
if (comments->comment_info[i]->address == addr) /* got an address match */
369
343
/* now check the bank information to be sure */
370
if (debug_comments[cpu_num].comment_info[i]->crc == c_crc)
344
if (comments->comment_info[i]->crc == c_crc)
372
346
logerror("%d : %s (%d %d)\n", addr,
373
debug_comments[cpu_num].comment_info[addr]->text,
374
debug_comments[cpu_num].comment_info[addr]->address,
375
debug_comments[cpu_num].comment_info[addr]->crc);
347
comments->comment_info[addr]->text,
348
comments->comment_info[addr]->address,
349
comments->comment_info[addr]->crc);
381
354
if (!ff) logerror("No comment exists for address : 0x%x\n", addr);
390
363
int debug_comment_save(running_machine *machine)
393
366
char crc_buf[20];
394
367
xml_data_node *root = xml_file_create();
395
368
xml_data_node *commentnode, *systemnode;
396
369
int total_comments = 0;
370
const device_config *cpu;
398
372
/* if we don't have a root, bail */
402
376
/* create a comment node */
403
377
commentnode = xml_add_child(root, "mamecommentfile", NULL);
378
if (commentnode == NULL)
406
380
xml_set_attribute_int(commentnode, "version", COMMENT_VERSION);
408
382
/* create a system node */
409
383
systemnode = xml_add_child(commentnode, "system", NULL);
384
if (systemnode == NULL)
412
386
xml_set_attribute(systemnode, "name", machine->gamedrv->name);
414
388
/* for each cpu */
415
for (i = 0; i < ARRAY_LENGTH(machine->cpu); i++)
416
if (machine->cpu[i] != NULL)
389
for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu))
391
debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
393
xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL);
396
xml_set_attribute(curnode, "tag", cpu->tag);
398
for (j = 0; j < comments->comment_count; j++)
418
xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL);
400
xml_data_node *datanode = xml_add_child(curnode, "comment", xml_normalize_string(comments->comment_info[j]->text));
401
if (datanode == NULL)
421
xml_set_attribute_int(curnode, "num", i);
423
for (j = 0; j < debug_comments[i].comment_count; j++)
425
xml_data_node *datanode = xml_add_child(curnode, "comment", xml_normalize_string(debug_comments[i].comment_info[j]->text));
428
xml_set_attribute_int(datanode, "address", debug_comments[i].comment_info[j]->address);
429
xml_set_attribute_int(datanode, "color", debug_comments[i].comment_info[j]->color);
430
sprintf(crc_buf, "%08X", debug_comments[i].comment_info[j]->crc);
431
xml_set_attribute(datanode, "crc", crc_buf);
403
xml_set_attribute_int(datanode, "address", comments->comment_info[j]->address);
404
xml_set_attribute_int(datanode, "color", comments->comment_info[j]->color);
405
sprintf(crc_buf, "%08X", comments->comment_info[j]->crc);
406
xml_set_attribute(datanode, "crc", crc_buf);
436
411
/* flush the file */
437
412
if (total_comments > 0)
485
460
static int debug_comment_load_xml(running_machine *machine, mame_file *fp)
488
463
xml_data_node *root, *commentnode, *systemnode, *cpunode, *datanode;
489
464
const char *name;
492
467
/* read the file */
493
468
root = xml_file_read(mame_core_file(fp), NULL);
497
472
/* find the config node */
498
473
commentnode = xml_get_sibling(root->child, "mamecommentfile");
474
if (commentnode == NULL)
502
477
/* validate the config data version */
510
485
if (strcmp(name, machine->gamedrv->name) != 0)
515
488
for (cpunode = xml_get_sibling(systemnode->child, "cpu"); cpunode; cpunode = xml_get_sibling(cpunode->next, "cpu"))
519
for (datanode = xml_get_sibling(cpunode->child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment"))
490
const device_config *cpu = cputag_get_cpu(machine, xml_get_attribute_string(cpunode, "tag", ""));
521
/* Malloc the comment */
522
debug_comments[i].comment_info[j] = (debug_comment*) malloc(sizeof(debug_comment));
524
debug_comments[i].comment_info[j]->address = xml_get_attribute_int(datanode, "address", 0);
525
debug_comments[i].comment_info[j]->color = xml_get_attribute_int(datanode, "color", 0);
526
sscanf(xml_get_attribute_string(datanode, "crc", 0), "%08X", &debug_comments[i].comment_info[j]->crc);
527
strcpy(debug_comments[i].comment_info[j]->text, datanode->value);
528
debug_comments[i].comment_info[j]->is_valid = 1;
493
debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
496
for (datanode = xml_get_sibling(cpunode->child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment"))
498
/* Malloc the comment */
499
comments->comment_info[j] = (debug_comment*) malloc(sizeof(debug_comment));
501
comments->comment_info[j]->address = xml_get_attribute_int(datanode, "address", 0);
502
comments->comment_info[j]->color = xml_get_attribute_int(datanode, "color", 0);
503
sscanf(xml_get_attribute_string(datanode, "crc", 0), "%08X", &comments->comment_info[j]->crc);
504
strcpy(comments->comment_info[j]->text, datanode->value);
505
comments->comment_info[j]->is_valid = 1;
510
comments->comment_count = j;
533
debug_comments[i].comment_count = j;
538
514
/* free the parser */
565
541
static void debug_comment_free(running_machine *machine)
543
const device_config *cpu;
569
for (i = 0; i < ARRAY_LENGTH(machine->cpu); i++)
570
if (machine->cpu[i] != NULL)
545
for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu))
547
debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
548
if (comments != NULL)
572
for (j = 0; j < debug_comments[i].comment_count; j++)
574
free(debug_comments[i].comment_info[j]);
577
debug_comments[i].comment_count = 0;
552
for (j = 0; j < comments->comment_count; j++)
553
free(comments->comment_info[j]);
555
comments->comment_count = 0;