~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to mess/src/emu/debug/debugvw.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************************
2
 
 
3
 
    debugvw.c
4
 
 
5
 
    Debugger view engine.
6
 
 
7
 
****************************************************************************
8
 
 
9
 
    Copyright Aaron Giles
10
 
    All rights reserved.
11
 
 
12
 
    Redistribution and use in source and binary forms, with or without
13
 
    modification, are permitted provided that the following conditions are
14
 
    met:
15
 
 
16
 
        * Redistributions of source code must retain the above copyright
17
 
          notice, this list of conditions and the following disclaimer.
18
 
        * Redistributions in binary form must reproduce the above copyright
19
 
          notice, this list of conditions and the following disclaimer in
20
 
          the documentation and/or other materials provided with the
21
 
          distribution.
22
 
        * Neither the name 'MAME' nor the names of its contributors may be
23
 
          used to endorse or promote products derived from this software
24
 
          without specific prior written permission.
25
 
 
26
 
    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27
 
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28
 
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
 
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30
 
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
 
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
 
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33
 
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34
 
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35
 
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
 
    POSSIBILITY OF SUCH DAMAGE.
37
 
 
38
 
***************************************************************************/
39
 
 
40
 
#include "emu.h"
41
 
#include "express.h"
42
 
#include "debugvw.h"
43
 
#include "dvtext.h"
44
 
#include "dvstate.h"
45
 
#include "dvdisasm.h"
46
 
#include "dvmemory.h"
47
 
#include "debugcmd.h"
48
 
#include "debugcpu.h"
49
 
#include "debugcon.h"
50
 
#include <ctype.h>
51
 
 
52
 
 
53
 
 
54
 
//**************************************************************************
55
 
//  DEBUG VIEW SOURCE
56
 
//**************************************************************************
57
 
 
58
 
//-------------------------------------------------
59
 
//  debug_view_source - constructor
60
 
//-------------------------------------------------
61
 
 
62
 
debug_view_source::debug_view_source(const char *name, device_t *device)
63
 
        : m_next(NULL),
64
 
          m_name(name),
65
 
          m_device(device)
66
 
{
67
 
}
68
 
 
69
 
 
70
 
//-------------------------------------------------
71
 
//  ~debug_view_source - destructor
72
 
//-------------------------------------------------
73
 
 
74
 
debug_view_source::~debug_view_source()
75
 
{
76
 
}
77
 
 
78
 
 
79
 
 
80
 
//**************************************************************************
81
 
//  DEBUG VIEW SOURCE LIST
82
 
//**************************************************************************
83
 
 
84
 
//-------------------------------------------------
85
 
//  debug_view_source_list - constructor
86
 
//-------------------------------------------------
87
 
 
88
 
debug_view_source_list::debug_view_source_list(running_machine &machine)
89
 
        : m_machine(machine),
90
 
          m_head(NULL),
91
 
          m_tail(NULL),
92
 
          m_count(0)
93
 
{
94
 
}
95
 
 
96
 
 
97
 
//-------------------------------------------------
98
 
//  ~debug_view_source_list - destructor
99
 
//-------------------------------------------------
100
 
 
101
 
debug_view_source_list::~debug_view_source_list()
102
 
{
103
 
        reset();
104
 
}
105
 
 
106
 
 
107
 
//-------------------------------------------------
108
 
//  index - return the index of a source
109
 
//-------------------------------------------------
110
 
 
111
 
int debug_view_source_list::index(const debug_view_source &source) const
112
 
{
113
 
        int result = 0;
114
 
        for (debug_view_source *cursource = m_head; cursource != NULL; cursource = cursource->m_next)
115
 
        {
116
 
                if (cursource == &source)
117
 
                        break;
118
 
                result++;
119
 
        }
120
 
        return result;
121
 
}
122
 
 
123
 
 
124
 
//-------------------------------------------------
125
 
//  by_index - return a source given an index
126
 
//-------------------------------------------------
127
 
 
128
 
const debug_view_source *debug_view_source_list::by_index(int index) const
129
 
{
130
 
        if (m_head == NULL)
131
 
                return NULL;
132
 
        const debug_view_source *result;
133
 
        for (result = m_head; index > 0 && result->m_next != NULL; result = result->m_next)
134
 
                index--;
135
 
        return result;
136
 
}
137
 
 
138
 
 
139
 
//-------------------------------------------------
140
 
//  reset - free all the view_sources
141
 
//-------------------------------------------------
142
 
 
143
 
void debug_view_source_list::reset()
144
 
{
145
 
        // free from the head
146
 
        while (m_head != NULL)
147
 
        {
148
 
                debug_view_source *source = m_head;
149
 
                m_head = source->m_next;
150
 
                auto_free(machine(), source);
151
 
        }
152
 
 
153
 
        // reset the tail pointer and index
154
 
        m_tail = NULL;
155
 
        m_count = 0;
156
 
}
157
 
 
158
 
 
159
 
//-------------------------------------------------
160
 
//  append - add a view_source to the end of the
161
 
//  list
162
 
//-------------------------------------------------
163
 
 
164
 
void debug_view_source_list::append(debug_view_source &source)
165
 
{
166
 
        // set the next and index values
167
 
        source.m_next = NULL;
168
 
 
169
 
        // append to the end
170
 
        if (m_tail == NULL)
171
 
                m_head = m_tail = &source;
172
 
        else
173
 
                m_tail->m_next = &source;
174
 
        m_tail = &source;
175
 
        m_count++;
176
 
}
177
 
 
178
 
 
179
 
//-------------------------------------------------
180
 
//  match_device - find the first view that
181
 
//  matches the given device
182
 
//-------------------------------------------------
183
 
 
184
 
const debug_view_source *debug_view_source_list::match_device(device_t *device) const
185
 
{
186
 
        for (debug_view_source *source = m_head; source != NULL; source = source->m_next)
187
 
                if (device == source->m_device)
188
 
                        return source;
189
 
        return m_head;
190
 
}
191
 
 
192
 
 
193
 
 
194
 
//**************************************************************************
195
 
//  DEBUG VIEW
196
 
//**************************************************************************
197
 
 
198
 
//-------------------------------------------------
199
 
//  debug_view - constructor
200
 
//-------------------------------------------------
201
 
 
202
 
debug_view::debug_view(running_machine &machine, debug_view_type type, debug_view_osd_update_func osdupdate, void *osdprivate)
203
 
        : m_next(NULL),
204
 
          m_type(type),
205
 
          m_source(NULL),
206
 
          m_source_list(machine),
207
 
          m_osdupdate(osdupdate),
208
 
          m_osdprivate(osdprivate),
209
 
          m_visible(10,10),
210
 
          m_total(10,10),
211
 
          m_topleft(0,0),
212
 
          m_cursor(0,0),
213
 
          m_supports_cursor(false),
214
 
          m_cursor_visible(false),
215
 
          m_recompute(true),
216
 
          m_update_level(0),
217
 
          m_update_pending(true),
218
 
          m_osd_update_pending(true),
219
 
          m_viewdata(NULL),
220
 
          m_viewdata_size(0),
221
 
          m_machine(machine)
222
 
{
223
 
        // allocate memory for the buffer
224
 
        m_viewdata_size = m_visible.y * m_visible.x;
225
 
        m_viewdata = auto_alloc_array(machine, debug_view_char, m_viewdata_size);
226
 
}
227
 
 
228
 
 
229
 
//-------------------------------------------------
230
 
//  ~debug_view - destructor
231
 
//-------------------------------------------------
232
 
 
233
 
debug_view::~debug_view()
234
 
{
235
 
}
236
 
 
237
 
 
238
 
//-------------------------------------------------
239
 
//  end_update - bracket a sequence of changes so
240
 
//  that only one update occurs
241
 
//-------------------------------------------------
242
 
 
243
 
void debug_view::end_update()
244
 
{
245
 
        /* if we hit zero, call the update function */
246
 
        if (m_update_level == 1)
247
 
        {
248
 
                while (m_update_pending)
249
 
                {
250
 
                        // no longer pending, but flag for the OSD
251
 
                        m_update_pending = false;
252
 
                        m_osd_update_pending = true;
253
 
 
254
 
                        // resize the viewdata if needed
255
 
                        int size = m_visible.x * m_visible.y;
256
 
                        if (size > m_viewdata_size)
257
 
                        {
258
 
                                m_viewdata_size = size;
259
 
                                auto_free(machine(), m_viewdata);
260
 
                                m_viewdata = auto_alloc_array(machine(), debug_view_char, m_viewdata_size);
261
 
                        }
262
 
 
263
 
                        // update the view
264
 
                        view_update();
265
 
                }
266
 
        }
267
 
 
268
 
        // decrement the level
269
 
        m_update_level--;
270
 
}
271
 
 
272
 
 
273
 
//-------------------------------------------------
274
 
//  flush_osd_updates - notify the OSD of any
275
 
//  pending updates
276
 
//-------------------------------------------------
277
 
 
278
 
void debug_view::flush_osd_updates()
279
 
{
280
 
        if (m_osd_update_pending && m_osdupdate != NULL)
281
 
                (*m_osdupdate)(*this, m_osdprivate);
282
 
        m_osd_update_pending = false;
283
 
}
284
 
 
285
 
 
286
 
//-------------------------------------------------
287
 
//  set_visible_size - set the visible size in
288
 
//  rows and columns
289
 
//-------------------------------------------------*/
290
 
 
291
 
void debug_view::set_visible_size(debug_view_xy size)
292
 
{
293
 
        if (size.x != m_visible.x || size.y != m_visible.y)
294
 
        {
295
 
                begin_update();
296
 
                m_visible = size;
297
 
                m_update_pending = true;
298
 
                view_notify(VIEW_NOTIFY_VISIBLE_CHANGED);
299
 
                end_update();
300
 
        }
301
 
}
302
 
 
303
 
 
304
 
//-------------------------------------------------
305
 
//  set_visible_position - set the top left
306
 
//  position of the visible area in rows and
307
 
//  columns
308
 
//-------------------------------------------------
309
 
 
310
 
void debug_view::set_visible_position(debug_view_xy pos)
311
 
{
312
 
        if (pos.x != m_topleft.x || pos.y != m_topleft.y)
313
 
        {
314
 
                begin_update();
315
 
                m_topleft = pos;
316
 
                m_update_pending = true;
317
 
                view_notify(VIEW_NOTIFY_VISIBLE_CHANGED);
318
 
                end_update();
319
 
        }
320
 
}
321
 
 
322
 
 
323
 
//-------------------------------------------------
324
 
//  set_cursor_position - set the current cursor
325
 
//  position as a row and column
326
 
//-------------------------------------------------
327
 
 
328
 
void debug_view::set_cursor_position(debug_view_xy pos)
329
 
{
330
 
        if (pos.x != m_cursor.x || pos.y != m_cursor.y)
331
 
        {
332
 
                begin_update();
333
 
                m_cursor = pos;
334
 
                m_update_pending = true;
335
 
                view_notify(VIEW_NOTIFY_CURSOR_CHANGED);
336
 
                end_update();
337
 
        }
338
 
}
339
 
 
340
 
 
341
 
//-------------------------------------------------
342
 
//  set_cursor_visible - set the visible state of
343
 
//  the cursor
344
 
//-------------------------------------------------
345
 
 
346
 
void debug_view::set_cursor_visible(bool visible)
347
 
{
348
 
        if (visible != m_cursor_visible)
349
 
        {
350
 
                begin_update();
351
 
                m_cursor_visible = visible;
352
 
                m_update_pending = true;
353
 
                view_notify(VIEW_NOTIFY_CURSOR_CHANGED);
354
 
                end_update();
355
 
        }
356
 
}
357
 
 
358
 
 
359
 
//-------------------------------------------------
360
 
//  set_subview - set the current subview
361
 
//-------------------------------------------------
362
 
 
363
 
void debug_view::set_source(const debug_view_source &source)
364
 
{
365
 
        if (&source != m_source)
366
 
        {
367
 
                begin_update();
368
 
                m_source = &source;
369
 
                m_update_pending = true;
370
 
                view_notify(VIEW_NOTIFY_SOURCE_CHANGED);
371
 
                end_update();
372
 
        }
373
 
}
374
 
 
375
 
 
376
 
//-------------------------------------------------
377
 
//  adjust_visible_x_for_cursor - adjust a view's
378
 
//  visible X position to ensure the cursor is
379
 
//  visible
380
 
//-------------------------------------------------
381
 
 
382
 
void debug_view::adjust_visible_x_for_cursor()
383
 
{
384
 
        if (m_cursor.x < m_topleft.x)
385
 
                m_topleft.x = m_cursor.x;
386
 
        else if (m_cursor.x >= m_topleft.x + m_visible.x - 1)
387
 
                m_topleft.x = m_cursor.x - m_visible.x + 2;
388
 
}
389
 
 
390
 
 
391
 
//-------------------------------------------------
392
 
//  adjust_visible_y_for_cursor - adjust a view's
393
 
//  visible Y position to ensure the cursor is
394
 
//  visible
395
 
//-------------------------------------------------
396
 
 
397
 
void debug_view::adjust_visible_y_for_cursor()
398
 
{
399
 
        if (m_cursor.y < m_topleft.y)
400
 
                m_topleft.y = m_cursor.y;
401
 
        else if (m_cursor.y >= m_topleft.y + m_visible.y - 1)
402
 
                m_topleft.y = m_cursor.y - m_visible.y + 2;
403
 
}
404
 
 
405
 
 
406
 
//-------------------------------------------------
407
 
//  view_notify - handle notification of updates
408
 
//-------------------------------------------------
409
 
 
410
 
void debug_view::view_notify(debug_view_notification type)
411
 
{
412
 
        // default does nothing
413
 
}
414
 
 
415
 
 
416
 
//-------------------------------------------------
417
 
//  view_char - handle a character typed within
418
 
//  the current view
419
 
//-------------------------------------------------
420
 
 
421
 
void debug_view::view_char(int chval)
422
 
{
423
 
        // default does nothing
424
 
}
425
 
 
426
 
 
427
 
 
428
 
//**************************************************************************
429
 
//  DEBUG VIEW MANAGER
430
 
//**************************************************************************
431
 
 
432
 
//-------------------------------------------------
433
 
//  debug_view_manager - constructor
434
 
//-------------------------------------------------
435
 
 
436
 
debug_view_manager::debug_view_manager(running_machine &machine)
437
 
        : m_machine(machine),
438
 
          m_viewlist(NULL)
439
 
{
440
 
}
441
 
 
442
 
 
443
 
//-------------------------------------------------
444
 
//  ~debug_view_manager - destructor
445
 
//-------------------------------------------------
446
 
 
447
 
debug_view_manager::~debug_view_manager()
448
 
{
449
 
        while (m_viewlist != NULL)
450
 
        {
451
 
                debug_view *oldhead = m_viewlist;
452
 
                m_viewlist = oldhead->m_next;
453
 
                auto_free(machine(), oldhead);
454
 
        }
455
 
}
456
 
 
457
 
 
458
 
//-------------------------------------------------
459
 
//  alloc_view - create a new view
460
 
//-------------------------------------------------
461
 
 
462
 
debug_view *debug_view_manager::alloc_view(debug_view_type type, debug_view_osd_update_func osdupdate, void *osdprivate)
463
 
{
464
 
        switch (type)
465
 
        {
466
 
                case DVT_CONSOLE:
467
 
                        return append(auto_alloc(machine(), debug_view_console(machine(), osdupdate, osdprivate)));
468
 
 
469
 
                case DVT_STATE:
470
 
                        return append(auto_alloc(machine(), debug_view_state(machine(), osdupdate, osdprivate)));
471
 
 
472
 
                case DVT_DISASSEMBLY:
473
 
                        return append(auto_alloc(machine(), debug_view_disasm(machine(), osdupdate, osdprivate)));
474
 
 
475
 
                case DVT_MEMORY:
476
 
                        return append(auto_alloc(machine(), debug_view_memory(machine(), osdupdate, osdprivate)));
477
 
 
478
 
                case DVT_LOG:
479
 
                        return append(auto_alloc(machine(), debug_view_log(machine(), osdupdate, osdprivate)));
480
 
 
481
 
                case DVT_TIMERS:
482
 
//          return append(auto_alloc(machine(), debug_view_timers(machine(), osdupdate, osdprivate)));
483
 
 
484
 
                case DVT_ALLOCS:
485
 
//          return append(auto_alloc(machine(), debug_view_allocs(machine(), osdupdate, osdprivate)));
486
 
 
487
 
                default:
488
 
                        fatalerror("Attempt to create invalid debug view type %d\n", type);
489
 
        }
490
 
        return NULL;
491
 
}
492
 
 
493
 
 
494
 
//-------------------------------------------------
495
 
//  free_view - free a view
496
 
//-------------------------------------------------
497
 
 
498
 
void debug_view_manager::free_view(debug_view &view)
499
 
{
500
 
        // free us but only if we're in the list
501
 
        for (debug_view **viewptr = &m_viewlist; *viewptr != NULL; viewptr = &(*viewptr)->m_next)
502
 
                if (*viewptr == &view)
503
 
                {
504
 
                        *viewptr = view.m_next;
505
 
                        auto_free(machine(), &view);
506
 
                        break;
507
 
                }
508
 
}
509
 
 
510
 
 
511
 
//-------------------------------------------------
512
 
//  update_all - force all views to refresh
513
 
//-------------------------------------------------
514
 
 
515
 
void debug_view_manager::update_all(debug_view_type type)
516
 
{
517
 
        // loop over each view and force an update
518
 
        for (debug_view *view = m_viewlist; view != NULL; view = view->next())
519
 
                if (type == DVT_NONE || type == view->type())
520
 
                        view->force_update();
521
 
}
522
 
 
523
 
 
524
 
//-------------------------------------------------
525
 
//  flush_osd_updates - flush all pending OSD
526
 
//  updates
527
 
//-------------------------------------------------
528
 
 
529
 
void debug_view_manager::flush_osd_updates()
530
 
{
531
 
        for (debug_view *view = m_viewlist; view != NULL; view = view->m_next)
532
 
                view->flush_osd_updates();
533
 
}
534
 
 
535
 
 
536
 
//-------------------------------------------------
537
 
//  append - append a view to the end of our list
538
 
//-------------------------------------------------
539
 
 
540
 
debug_view *debug_view_manager::append(debug_view *view)
541
 
{
542
 
        debug_view **viewptr;
543
 
        for (viewptr = &m_viewlist; *viewptr != NULL; viewptr = &(*viewptr)->m_next) ;
544
 
        *viewptr = view;
545
 
        return view;
546
 
}
547
 
 
548
 
 
549
 
 
550
 
//**************************************************************************
551
 
//  DEBUG VIEW EXPRESSION
552
 
//**************************************************************************
553
 
 
554
 
//-------------------------------------------------
555
 
//  debug_view_expression - constructor
556
 
//-------------------------------------------------
557
 
 
558
 
debug_view_expression::debug_view_expression(running_machine &machine)
559
 
        : m_machine(machine),
560
 
          m_dirty(true),
561
 
          m_result(0),
562
 
          m_parsed(debug_cpu_get_global_symtable(machine)),
563
 
          m_string("0")
564
 
{
565
 
}
566
 
 
567
 
 
568
 
//-------------------------------------------------
569
 
//  ~debug_view_expression - destructor
570
 
//-------------------------------------------------
571
 
 
572
 
debug_view_expression::~debug_view_expression()
573
 
{
574
 
}
575
 
 
576
 
 
577
 
//-------------------------------------------------
578
 
//  set_context - set the context for the
579
 
//  expression
580
 
//-------------------------------------------------
581
 
 
582
 
void debug_view_expression::set_context(symbol_table *context)
583
 
{
584
 
        m_parsed.set_symbols((context != NULL) ? context : debug_cpu_get_global_symtable(machine()));
585
 
        m_dirty = true;
586
 
}
587
 
 
588
 
 
589
 
//-------------------------------------------------
590
 
//  recompute - recompute the value of an
591
 
//  expression
592
 
//-------------------------------------------------
593
 
 
594
 
bool debug_view_expression::recompute()
595
 
{
596
 
        bool changed = m_dirty;
597
 
 
598
 
        // if dirty, re-evaluate
599
 
        if (m_dirty)
600
 
        {
601
 
                astring oldstring(m_parsed.original_string());
602
 
                try
603
 
                {
604
 
                        m_parsed.parse(m_string);
605
 
                }
606
 
                catch (expression_error &)
607
 
                {
608
 
                        m_parsed.parse(oldstring);
609
 
                }
610
 
        }
611
 
 
612
 
        // if we have a parsed expression, evalute it
613
 
        if (!m_parsed.is_empty())
614
 
        {
615
 
                // recompute the value of the expression
616
 
                try
617
 
                {
618
 
                        UINT64 newresult = m_parsed.execute();
619
 
                        if (newresult != m_result)
620
 
                        {
621
 
                                m_result = newresult;
622
 
                                changed = true;
623
 
                        }
624
 
                }
625
 
                catch (expression_error &)
626
 
                {
627
 
                }
628
 
        }
629
 
 
630
 
        // expression no longer dirty by definition
631
 
        m_dirty = false;
632
 
        return changed;
633
 
}