~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/emu/debug/debugcmt.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
typedef struct _debug_comment debug_comment;
55
55
struct _debug_comment
56
56
{
57
 
        UINT8 is_valid;
58
 
        UINT32 address;
59
 
        char text[DEBUG_COMMENT_MAX_LINE_LENGTH];
60
 
        rgb_t color;
61
 
        UINT32 crc;
 
57
        UINT8                   is_valid;
 
58
        UINT32                  address;
 
59
        char                    text[DEBUG_COMMENT_MAX_LINE_LENGTH];
 
60
        rgb_t                   color;
 
61
        UINT32                  crc;
62
62
};
63
63
 
64
 
typedef struct _comment_group comment_group;
65
 
struct _comment_group
 
64
 
 
65
/* in debugcpu.h -- typedef struct _debug_cpu_comment_group debug_cpu_comment_group; */
 
66
struct _debug_cpu_comment_group
66
67
{
67
 
        int comment_count;
68
 
        UINT32 change_count;
69
 
        debug_comment *comment_info[DEBUG_COMMENT_MAX_NUM];
 
68
        int                     comment_count;
 
69
        UINT32                  change_count;
 
70
        debug_comment * comment_info[DEBUG_COMMENT_MAX_NUM];
70
71
};
71
72
 
72
73
 
73
74
 
74
75
/***************************************************************************
75
 
    GLOBAL VARIABLES
76
 
***************************************************************************/
77
 
 
78
 
static comment_group *debug_comments;
79
 
 
80
 
 
81
 
 
82
 
/***************************************************************************
83
76
    FUNCTION PROTOTYPES
84
77
***************************************************************************/
85
78
 
90
83
 
91
84
 
92
85
/***************************************************************************
93
 
 
94
 
    Initialization
95
 
 
 
86
    INITIALIZATION
96
87
***************************************************************************/
97
88
 
98
89
/*-------------------------------------------------------------------------
102
93
 
103
94
int debug_comment_init(running_machine *machine)
104
95
{
105
 
        int numcpu;
 
96
        const device_config *cpu;
106
97
 
107
 
        for (numcpu = 0; numcpu < ARRAY_LENGTH(machine->cpu); numcpu++)
108
 
                if (machine->cpu[numcpu] == NULL)
109
 
                        break;
110
 
        if (numcpu > 0)
 
98
        /* allocate memory for the comments */
 
99
        for (cpu = machine->firstcpu; cpu != NULL; cpu = cpu_next(cpu))
111
100
        {
112
 
                /* allocate enough comment groups for the total # of cpu's */
113
 
                debug_comments = auto_alloc_array_clear(machine, comment_group, numcpu);
114
 
 
115
 
                /* automatically load em up */
116
 
                debug_comment_load(machine);
117
 
 
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);
119
103
        }
120
104
 
 
105
        /* automatically load em up */
 
106
        debug_comment_load(machine);
 
107
        add_exit_callback(machine, debug_comment_exit);
121
108
        return 1;
122
109
}
123
110
 
130
117
 
131
118
int debug_comment_add(const device_config *device, offs_t addr, const char *comment, rgb_t color, UINT32 c_crc)
132
119
{
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;
 
122
        int match = 0;
134
123
        int i = 0;
135
 
        int insert_point = debug_comments[cpu_num].comment_count;
136
 
        int match = 0;
137
124
 
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);
145
132
 
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++)
148
135
        {
149
 
                if (insert_me->address < debug_comments[cpu_num].comment_info[i]->address)
 
136
                if (insert_me->address < comments->comment_info[i]->address)
150
137
                {
151
138
                        insert_point = i;
152
139
                        break;
153
140
                }
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)
156
143
                {
157
144
                        insert_point = i;
158
145
                        match = 1;
163
150
        /* Got an exact match?  Just replace */
164
151
        if (match == 1)
165
152
        {
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++;
169
156
 
170
157
                /* force an update of disassembly views */
171
158
                debug_view_update_type(device->machine, DVT_DISASSEMBLY);
174
161
 
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];
179
166
 
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++;
184
171
 
185
172
        /* force an update of disassembly views */
186
173
        debug_view_update_type(device->machine, DVT_DISASSEMBLY);
197
184
 
198
185
int debug_comment_remove(const device_config *device, offs_t addr, UINT32 c_crc)
199
186
{
200
 
        int cpu_num = cpu_get_index(device);
201
 
        int i;
 
187
        debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
202
188
        int remove_index = -1;
 
189
        int i;
203
190
 
204
 
        for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
205
 
        {
206
 
                if (debug_comments[cpu_num].comment_info[i]->address == addr)   /* got an address match */
207
 
                {
208
 
                        if (debug_comments[cpu_num].comment_info[i]->crc == c_crc)
209
 
                        {
 
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;
211
 
                        }
212
 
                }
213
 
        }
214
195
 
215
196
        /* The comment doesn't exist? */
216
197
        if (remove_index == -1)
217
198
                return 0;
218
199
 
219
200
        /* Okay, it's there, now remove it */
220
 
        free(debug_comments[cpu_num].comment_info[remove_index]);
221
 
 
222
 
        for (i = remove_index; i < debug_comments[cpu_num].comment_count-1; i++)
223
 
        {
224
 
                debug_comments[cpu_num].comment_info[i] = debug_comments[cpu_num].comment_info[i+1];
225
 
        }
226
 
 
227
 
        debug_comments[cpu_num].comment_count--;
228
 
        debug_comments[cpu_num].change_count++;
 
201
        free(comments->comment_info[remove_index]);
 
202
 
 
203
        for (i = remove_index; i < comments->comment_count-1; i++)
 
204
                comments->comment_info[i] = comments->comment_info[i+1];
 
205
 
 
206
        comments->comment_count--;
 
207
        comments->change_count++;
229
208
 
230
209
        /* force an update of disassembly views */
231
210
        debug_view_update_type(device->machine, DVT_DISASSEMBLY);
242
221
 
243
222
const char *debug_comment_get_text(const device_config *device, offs_t addr, UINT32 c_crc)
244
223
{
245
 
        int cpu_num = cpu_get_index(device);
 
224
        debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
246
225
        int i;
247
226
 
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++)
250
 
        {
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 */
252
230
                {
253
231
                        /* now check the bank information to be sure */
254
 
                        if (debug_comments[cpu_num].comment_info[i]->crc == c_crc)
255
 
                        {
256
 
                                return debug_comments[cpu_num].comment_info[i]->text;
257
 
                        }
 
232
                        if (comments->comment_info[i]->crc == c_crc)
 
233
                                return comments->comment_info[i]->text;
258
234
                }
259
 
        }
260
235
 
261
236
        return 0x00;
262
237
}
269
244
 
270
245
int debug_comment_get_count(const device_config *device)
271
246
{
272
 
        return debug_comments[cpu_get_index(device)].comment_count;
 
247
        debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
 
248
        return comments->comment_count;
273
249
}
274
250
 
275
251
 
280
256
 
281
257
UINT32 debug_comment_get_change_count(const device_config *device)
282
258
{
283
 
        return debug_comments[cpu_get_index(device)].change_count;
 
259
        debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
 
260
        return comments->change_count;
284
261
}
285
262
 
286
263
/*-------------------------------------------------------------------------
290
267
 
291
268
UINT32 debug_comment_all_change_count(running_machine *machine)
292
269
{
293
 
        int i ;
 
270
        const device_config *cpu;
294
271
        UINT32 retVal = 0;
295
272
 
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))
 
274
        {
 
275
                debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
 
276
                retVal += comments->change_count;
 
277
        }
299
278
 
300
279
        return retVal;
301
280
}
342
321
 
343
322
void debug_comment_dump(const device_config *device, offs_t addr)
344
323
{
345
 
        int cpu_num = cpu_get_index(device);
 
324
        debug_cpu_comment_group *comments = cpu_get_debug_data(device)->comments;
346
325
        int i;
347
326
        int ff = 0;
348
327
 
349
328
        if (addr == -1)
350
329
        {
351
 
                for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
352
 
                {
353
 
                        if (debug_comments[cpu_num].comment_info[i]->is_valid)
354
 
                        {
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);
358
 
                        }
359
 
                }
 
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);
360
335
        }
361
336
        else
362
337
        {
363
338
                UINT32 c_crc = debug_comment_get_opcode_crc32(device, addr);
364
339
 
365
 
                for (i = 0; i < debug_comments[cpu_num].comment_count; i++)
366
 
                {
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 */
368
342
                        {
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)
371
345
                                {
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);
376
350
                                        ff = 1;
377
351
                                }
378
352
                        }
379
 
                }
380
353
 
381
354
                if (!ff) logerror("No comment exists for address : 0x%x\n", addr);
382
355
        }
389
362
 
390
363
int debug_comment_save(running_machine *machine)
391
364
{
392
 
        int i, j;
 
365
        int j;
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;
397
371
 
398
372
        /* if we don't have a root, bail */
399
 
        if (!root)
 
373
        if (root == NULL)
400
374
                return 0;
401
375
 
402
376
        /* create a comment node */
403
377
        commentnode = xml_add_child(root, "mamecommentfile", NULL);
404
 
        if (!commentnode)
 
378
        if (commentnode == NULL)
405
379
                goto error;
406
380
        xml_set_attribute_int(commentnode, "version", COMMENT_VERSION);
407
381
 
408
382
        /* create a system node */
409
383
        systemnode = xml_add_child(commentnode, "system", NULL);
410
 
        if (!systemnode)
 
384
        if (systemnode == NULL)
411
385
                goto error;
412
386
        xml_set_attribute(systemnode, "name", machine->gamedrv->name);
413
387
 
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))
 
390
        {
 
391
                debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
 
392
 
 
393
                xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL);
 
394
                if (curnode == NULL)
 
395
                        goto error;
 
396
                xml_set_attribute(curnode, "tag", cpu->tag);
 
397
 
 
398
                for (j = 0; j < comments->comment_count; j++)
417
399
                {
418
 
                        xml_data_node *curnode = xml_add_child(systemnode, "cpu", NULL);
419
 
                        if (!curnode)
 
400
                        xml_data_node *datanode = xml_add_child(curnode, "comment", xml_normalize_string(comments->comment_info[j]->text));
 
401
                        if (datanode == NULL)
420
402
                                goto error;
421
 
                        xml_set_attribute_int(curnode, "num", i);
422
 
 
423
 
                        for (j = 0; j < debug_comments[i].comment_count; j++)
424
 
                        {
425
 
                                xml_data_node *datanode = xml_add_child(curnode, "comment", xml_normalize_string(debug_comments[i].comment_info[j]->text));
426
 
                                if (!datanode)
427
 
                                        goto error;
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);
432
 
                                total_comments++;
433
 
                        }
 
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);
 
407
                        total_comments++;
434
408
                }
 
409
        }
435
410
 
436
411
        /* flush the file */
437
412
        if (total_comments > 0)
484
459
 
485
460
static int debug_comment_load_xml(running_machine *machine, mame_file *fp)
486
461
{
487
 
        int i, j;
 
462
        int j;
488
463
        xml_data_node *root, *commentnode, *systemnode, *cpunode, *datanode;
489
464
        const char *name;
490
465
        int version;
491
466
 
492
467
        /* read the file */
493
468
        root = xml_file_read(mame_core_file(fp), NULL);
494
 
        if (!root)
 
469
        if (root == NULL)
495
470
                goto error;
496
471
 
497
472
        /* find the config node */
498
473
        commentnode = xml_get_sibling(root->child, "mamecommentfile");
499
 
        if (!commentnode)
 
474
        if (commentnode == NULL)
500
475
                goto error;
501
476
 
502
477
        /* validate the config data version */
510
485
        if (strcmp(name, machine->gamedrv->name) != 0)
511
486
                goto error;
512
487
 
513
 
        i = 0;
514
 
 
515
488
        for (cpunode = xml_get_sibling(systemnode->child, "cpu"); cpunode; cpunode = xml_get_sibling(cpunode->next, "cpu"))
516
489
        {
517
 
                j = 0;
518
 
 
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", ""));
 
491
                if (cpu != NULL)
520
492
                {
521
 
                        /* Malloc the comment */
522
 
                        debug_comments[i].comment_info[j] = (debug_comment*) malloc(sizeof(debug_comment));
523
 
 
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;
529
 
 
530
 
                        j++;
 
493
                        debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
 
494
                        j = 0;
 
495
 
 
496
                        for (datanode = xml_get_sibling(cpunode->child, "comment"); datanode; datanode = xml_get_sibling(datanode->next, "comment"))
 
497
                        {
 
498
                                /* Malloc the comment */
 
499
                                comments->comment_info[j] = (debug_comment*) malloc(sizeof(debug_comment));
 
500
 
 
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;
 
506
 
 
507
                                j++;
 
508
                        }
 
509
 
 
510
                        comments->comment_count = j;
531
511
                }
532
 
 
533
 
                debug_comments[i].comment_count = j;
534
 
 
535
 
                i++;
536
512
        }
537
513
 
538
514
        /* free the parser */
564
540
 
565
541
static void debug_comment_free(running_machine *machine)
566
542
{
567
 
        int i, j;
 
543
        const device_config *cpu;
568
544
 
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))
 
546
        {
 
547
                debug_cpu_comment_group *comments = cpu_get_debug_data(cpu)->comments;
 
548
                if (comments != NULL)
571
549
                {
572
 
                        for (j = 0; j < debug_comments[i].comment_count; j++)
573
 
                        {
574
 
                                free(debug_comments[i].comment_info[j]);
575
 
                        }
576
 
 
577
 
                        debug_comments[i].comment_count = 0;
 
550
                        int j;
 
551
 
 
552
                        for (j = 0; j < comments->comment_count; j++)
 
553
                                free(comments->comment_info[j]);
 
554
 
 
555
                        comments->comment_count = 0;
578
556
                }
 
557
        }
579
558
}